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