[71] | 1 | #include "Type.h"
|
---|
| 2 |
|
---|
| 3 | #ifndef _ACTIVEBASIC_COMPILER_PARAMETER_H
|
---|
| 4 | #define _ACTIVEBASIC_COMPILER_PARAMETER_H
|
---|
| 5 |
|
---|
| 6 | class Parameter;
|
---|
[73] | 7 | typedef vector<Parameter *> Parameters;
|
---|
[71] | 8 |
|
---|
| 9 | class Parameter : public Type
|
---|
| 10 | {
|
---|
| 11 | string varName;
|
---|
| 12 | bool isRef;
|
---|
| 13 | bool isArray;
|
---|
| 14 | int subScripts[MAX_ARRAYDIM];
|
---|
| 15 |
|
---|
[77] | 16 | const string initValue;
|
---|
| 17 |
|
---|
[71] | 18 | public:
|
---|
[77] | 19 | Parameter( const string &varName, const Type &type, bool isRef = false, const string initValue = "" ):
|
---|
[73] | 20 | Type( type ),
|
---|
| 21 | varName( varName ),
|
---|
| 22 | isRef( isRef ),
|
---|
[77] | 23 | isArray( false ),
|
---|
| 24 | initValue( initValue )
|
---|
[71] | 25 | {
|
---|
[73] | 26 | subScripts[0] = -1;
|
---|
[71] | 27 | }
|
---|
[73] | 28 | Parameter( const Parameter ¶m ):
|
---|
| 29 | Type( param ),
|
---|
| 30 | varName( param.varName ),
|
---|
| 31 | isRef( param.isRef ),
|
---|
[77] | 32 | isArray( false ),
|
---|
| 33 | initValue( param.initValue )
|
---|
[73] | 34 | {
|
---|
| 35 | subScripts[0] = -1;
|
---|
| 36 | if( param.isArray ){
|
---|
| 37 | SetArray( param.subScripts );
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
[71] | 40 | ~Parameter(){}
|
---|
| 41 |
|
---|
| 42 | void SetArray( const int *pSubScripts ){
|
---|
| 43 | isArray = true;
|
---|
| 44 | memcpy( this->subScripts, pSubScripts, sizeof(int) * MAX_ARRAYDIM );
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[73] | 47 | const string &GetVarName() const
|
---|
| 48 | {
|
---|
| 49 | return varName;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[75] | 52 | bool IsRef() const
|
---|
| 53 | {
|
---|
[71] | 54 | return isRef;
|
---|
| 55 | }
|
---|
| 56 | bool IsArray(){
|
---|
| 57 | return isArray;
|
---|
| 58 | }
|
---|
| 59 | int *GetSubScriptsPtr(){
|
---|
| 60 | return subScripts;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[77] | 63 | const string &GetInitValue() const
|
---|
| 64 | {
|
---|
| 65 | return initValue;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[71] | 68 | bool Equals( const Parameter ¶m ) const
|
---|
| 69 | {
|
---|
| 70 | if( Type::Equals( param ) ){
|
---|
| 71 | return true;
|
---|
| 72 | }
|
---|
| 73 | else{
|
---|
| 74 |
|
---|
[73] | 75 | if( this->isRef && this->GetBasicType() == DEF_ANY &&
|
---|
[71] | 76 | param.isRef == false && param.IsPointer()
|
---|
| 77 | ||
|
---|
| 78 | this->isRef == false && this->IsPointer() &&
|
---|
[73] | 79 | param.isRef && param.GetBasicType() == DEF_ANY ){
|
---|
[71] | 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 ¶msA, 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++ ){
|
---|
[73] | 100 | if( !paramsA[i]->Equals( *paramsB[i] ) ){
|
---|
[71] | 101 | return false;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | return true;
|
---|
| 106 | }
|
---|
| 107 | };
|
---|
| 108 |
|
---|
[73] | 109 | #endif //_ACTIVEBASIC_COMPILER_PARAMETER_H
|
---|