source: dev/BasicCompiler_Common/Parameter.h@ 144

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

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

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