[4] | 1 | #include "../BasicCompiler_Common/common.h"
|
---|
| 2 |
|
---|
| 3 | #ifdef _AMD64_
|
---|
| 4 | #include "../BasicCompiler64/opcode.h"
|
---|
| 5 | #else
|
---|
[5] | 6 | #include "../BasicCompiler32/opcode.h"
|
---|
[4] | 7 | #endif
|
---|
| 8 |
|
---|
[75] | 9 | int hash_default(const char *name){
|
---|
[4] | 10 | int key;
|
---|
| 11 |
|
---|
| 12 | for(key=0;*name!='\0';name++){
|
---|
| 13 | key=((key<<8)+ *name )%MAX_HASH;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | return key;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
[97] | 19 | CONSTINFO *GetConstHash(const char *name){
|
---|
[4] | 20 | //ハッシュ値を取得
|
---|
| 21 | int key;
|
---|
| 22 | key=hash_default(name);
|
---|
| 23 |
|
---|
| 24 | //格納位置を取得
|
---|
| 25 | extern CONSTINFO **ppConstHash;
|
---|
| 26 | CONSTINFO *pci;
|
---|
| 27 | pci=ppConstHash[key];
|
---|
| 28 | while(pci){
|
---|
| 29 | if(lstrcmp(pci->name,name)==0) break;
|
---|
| 30 |
|
---|
| 31 | pci=pci->pNextData;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | return pci;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[113] | 37 | DllProc *GetDeclareHash(char *fullName){
|
---|
| 38 | char ObjName[VN_SIZE]; //オブジェクト変数
|
---|
| 39 | char NestMember[VN_SIZE]; //入れ子メンバ
|
---|
| 40 | bool isObjectMember = SplitMemberName( fullName, ObjName, NestMember );
|
---|
| 41 |
|
---|
[4] | 42 | //ハッシュ値を取得
|
---|
| 43 | int key;
|
---|
[113] | 44 | key=hash_default(NestMember);
|
---|
[4] | 45 |
|
---|
| 46 | //格納位置を取得
|
---|
[75] | 47 | extern DllProc **ppDeclareHash;
|
---|
| 48 | DllProc *pDllProc;
|
---|
| 49 | pDllProc=ppDeclareHash[key];
|
---|
| 50 | while(pDllProc){
|
---|
[113] | 51 | // TODO: Declare名前空間対応
|
---|
| 52 | if( pDllProc->IsEqualSymbol( fullName ) ){
|
---|
[75] | 53 | break;
|
---|
| 54 | }
|
---|
[4] | 55 |
|
---|
[75] | 56 | pDllProc=pDllProc->pNextData;
|
---|
[4] | 57 | }
|
---|
| 58 |
|
---|
[75] | 59 | return pDllProc;
|
---|
[4] | 60 | }
|
---|
| 61 |
|
---|
[75] | 62 | void GetOverloadSubHash( const char *lpszName, std::vector<UserProc *> &subs ){
|
---|
[4] | 63 | char name[VN_SIZE];
|
---|
| 64 |
|
---|
| 65 | if(lpszName[0]=='.'){
|
---|
| 66 | GetWithName(name);
|
---|
| 67 | lstrcat(name,lpszName);
|
---|
| 68 | }
|
---|
| 69 | else lstrcpy(name,lpszName);
|
---|
| 70 |
|
---|
| 71 | char ObjName[VN_SIZE]; //オブジェクト変数
|
---|
| 72 | char NestMember[VN_SIZE]; //入れ子メンバ
|
---|
[28] | 73 | bool isObjectMember = SplitMemberName( name, ObjName, NestMember );
|
---|
[4] | 74 |
|
---|
[28] | 75 | if(isObjectMember){
|
---|
[4] | 76 | //オブジェクトのメンバ関数の場合
|
---|
| 77 |
|
---|
[27] | 78 | bool isStatic = false;
|
---|
[75] | 79 | const CClass *pobj_c = NULL;
|
---|
[4] | 80 | if(lstrcmpi(ObjName,"Super")==0){
|
---|
[27] | 81 | //クラスメンバ関数内から基底クラスの呼び出し
|
---|
| 82 | pobj_c=pobj_CompilingClass;
|
---|
| 83 | }
|
---|
| 84 | else{
|
---|
[47] | 85 | //"->"によってオブジェクトを指定する通常のメンバ関数呼び出し
|
---|
[75] | 86 | Type type;
|
---|
[100] | 87 | if( GetVarType(ObjName,type,0) ){
|
---|
| 88 | pobj_c = &type.GetClass();
|
---|
| 89 | }
|
---|
| 90 | else{
|
---|
[102] | 91 | pobj_c=pobj_DBClass->Find(ObjName);
|
---|
[47] | 92 | if( pobj_c ){
|
---|
| 93 | isStatic = true;
|
---|
| 94 | }
|
---|
[28] | 95 | }
|
---|
[4] | 96 | }
|
---|
| 97 |
|
---|
[101] | 98 | if( pobj_c && pobj_c != (CClass *)-1 ){
|
---|
[100] | 99 | if( isStatic ){
|
---|
| 100 | // 静的メソッドから列挙
|
---|
[136] | 101 | pobj_c->GetStaticMethods().Enum( NestMember, subs );
|
---|
[100] | 102 | }
|
---|
| 103 | else{
|
---|
| 104 | //動的メソッドから列挙
|
---|
[135] | 105 | pobj_c->GetMethods().Enum( NestMember, subs );
|
---|
[100] | 106 | }
|
---|
| 107 | return;
|
---|
[4] | 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
[100] | 112 | if(pobj_CompilingClass){
|
---|
| 113 | //自身のオブジェクトのメンバ関数を検索
|
---|
[4] | 114 |
|
---|
[100] | 115 | // 静的メソッド
|
---|
[136] | 116 | pobj_CompilingClass->GetStaticMethods().Enum( name, subs );
|
---|
[4] | 117 |
|
---|
[100] | 118 | // 動的メソッド
|
---|
[135] | 119 | pobj_CompilingClass->GetMethods().Enum( name, subs );
|
---|
[100] | 120 | }
|
---|
[27] | 121 |
|
---|
| 122 |
|
---|
[100] | 123 | ///////////////////////////
|
---|
| 124 | // グローバル関数を検索
|
---|
| 125 | ///////////////////////////
|
---|
[4] | 126 |
|
---|
[100] | 127 | //ハッシュ値を取得
|
---|
| 128 | int key;
|
---|
| 129 | key=hash_default(NestMember);
|
---|
| 130 |
|
---|
| 131 | //格納位置を取得
|
---|
| 132 | extern GlobalProc **ppSubHash;
|
---|
| 133 | GlobalProc *pUserProc;
|
---|
| 134 | pUserProc=ppSubHash[key];
|
---|
| 135 | while(pUserProc){
|
---|
| 136 | if(!pUserProc->GetParentClassPtr()){
|
---|
[101] | 137 | if( pUserProc->IsEqualSymbol( name ) ){
|
---|
[100] | 138 | subs.push_back( pUserProc );
|
---|
[4] | 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[100] | 142 | pUserProc=pUserProc->pNextData;
|
---|
[4] | 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | //オーバーロードされていない関数を取得(昔のコンパイラソースコードとの互換性保持)
|
---|
[75] | 147 | UserProc *GetSubHash(const char *lpszName,BOOL bError){
|
---|
| 148 | std::vector<UserProc *> subs;
|
---|
[50] | 149 | GetOverloadSubHash(lpszName,subs);
|
---|
[4] | 150 |
|
---|
| 151 | //関数が存在しないとき
|
---|
[50] | 152 | if(subs.size() == 0){
|
---|
[75] | 153 | if(bError){
|
---|
| 154 | SetError(3,lpszName,cp);
|
---|
| 155 | }
|
---|
[4] | 156 | return 0;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | //一つ以上の関数が存在するときは内部エラー(デバッグ用)
|
---|
[50] | 160 | if(subs.size() > 1){
|
---|
[5] | 161 | if(bError) SetError(300,NULL,cp);
|
---|
[4] | 162 | }
|
---|
| 163 |
|
---|
[75] | 164 | UserProc *pUserProc;
|
---|
| 165 | pUserProc = subs[0];
|
---|
[4] | 166 |
|
---|
[75] | 167 | return pUserProc;
|
---|
[5] | 168 | }
|
---|
[75] | 169 | UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError){
|
---|
[5] | 170 | char temporary[VN_SIZE];
|
---|
| 171 | sprintf(temporary,"%s.%s",ObjectName,MethodName);
|
---|
| 172 |
|
---|
[75] | 173 | std::vector<UserProc *> subs;
|
---|
| 174 | UserProc *pUserProc;
|
---|
[50] | 175 | GetOverloadSubHash(temporary,subs);
|
---|
[5] | 176 |
|
---|
| 177 | //関数が存在しないとき
|
---|
[50] | 178 | if(subs.size() == 0){
|
---|
[5] | 179 | return 0;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | //オーバーロードを解決
|
---|
[75] | 183 | pUserProc=OverloadSolutionWithStrParam(temporary,subs,Parameter,ObjectName);
|
---|
[5] | 184 |
|
---|
[75] | 185 | return pUserProc;
|
---|
[5] | 186 | }
|
---|
[95] | 187 |
|
---|
| 188 | UserProc *GetClassMethod( const char *className, const char *methodName ){
|
---|
[114] | 189 | const CClass *pClass = pobj_DBClass->Find( className );
|
---|
[95] | 190 | if( pClass ){
|
---|
| 191 | vector<UserProc *> userProcs;
|
---|
[135] | 192 | pClass->GetMethods().Enum( methodName, userProcs );
|
---|
[95] | 193 | if( userProcs.size() == 1 ){
|
---|
| 194 | return userProcs[0];
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | char temporary[VN_SIZE];
|
---|
| 199 | sprintf( temporary, "%s.%s", className, methodName );
|
---|
| 200 | SetError(3, temporary, -1 );
|
---|
| 201 |
|
---|
| 202 | return NULL;
|
---|
| 203 | }
|
---|