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