source: dev/BasicCompiler_Common/Parameter.h@ 77

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

デフォルトパラメータに対応。

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