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