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