source: dev/BasicCompiler_Common/Parameter.h@ 120

Last change on this file since 120 was 120, checked in by dai_9181, 17 years ago

Parameter::Equals静的メソッドを廃止し、Parameters::Equalsメソッドを用意。
ポインタに要するサイズよりも一回り大きなアラインメントが指定されているときに、呼び出し側のオフセットズレを考慮するよう、修正

File size: 2.0 KB
RevLine 
[78]1#pragma once
2
[71]3#include "Type.h"
4
5class Parameter : public Type
6{
7 string varName;
8 bool isRef;
9 bool isArray;
10 int subScripts[MAX_ARRAYDIM];
11
[77]12 const string initValue;
13
[71]14public:
[77]15 Parameter( const string &varName, const Type &type, bool isRef = false, const string initValue = "" ):
[73]16 Type( type ),
17 varName( varName ),
18 isRef( isRef ),
[77]19 isArray( false ),
20 initValue( initValue )
[71]21 {
[73]22 subScripts[0] = -1;
[71]23 }
[73]24 Parameter( const Parameter &param ):
25 Type( param ),
26 varName( param.varName ),
27 isRef( param.isRef ),
[77]28 isArray( false ),
29 initValue( param.initValue )
[73]30 {
31 subScripts[0] = -1;
32 if( param.isArray ){
33 SetArray( param.subScripts );
34 }
35 }
[71]36 ~Parameter(){}
37
38 void SetArray( const int *pSubScripts ){
39 isArray = true;
40 memcpy( this->subScripts, pSubScripts, sizeof(int) * MAX_ARRAYDIM );
41 }
42
[73]43 const string &GetVarName() const
44 {
45 return varName;
46 }
47
[75]48 bool IsRef() const
49 {
[71]50 return isRef;
51 }
52 bool IsArray(){
53 return isArray;
54 }
55 int *GetSubScriptsPtr(){
56 return subScripts;
57 }
58
[77]59 const string &GetInitValue() const
60 {
61 return initValue;
62 }
63
[71]64 bool Equals( const Parameter &param ) const
65 {
66 if( Type::Equals( param ) ){
67 return true;
68 }
69 else{
70
[73]71 if( this->isRef && this->GetBasicType() == DEF_ANY &&
[71]72 param.isRef == false && param.IsPointer()
73 ||
74 this->isRef == false && this->IsPointer() &&
[73]75 param.isRef && param.GetBasicType() == DEF_ANY ){
[71]76 /* ByRef var As Any
77
78 var As VoidPtr
79 は同等
80 */
81 return true;
82 }
83 }
84
85 return false;
86 }
[120]87};
[71]88
[120]89class Parameters : public vector<Parameter *>
90{
91public:
[71]92
[120]93 bool Equals( const Parameters &params ) const
94 {
95 if( this->size() != params.size() ){
[71]96 return false;
97 }
98
[120]99 int max = (int)this->size();
[71]100 for( int i=0; i<max; i++ ){
[120]101 if( !(*this)[i]->Equals( *params[i] ) ){
[71]102 return false;
103 }
104 }
105
106 return true;
107 }
[120]108
109 int GetMemorySize() const
110 {
111 return (int)this->size() * PTR_SIZE;
112 }
[71]113};
Note: See TracBrowser for help on using the repository browser.