#include "stdafx.h" #include #include "../BasicCompiler_Common/common.h" #ifdef _AMD64_ #include "../compiler_x64/opcode.h" #else #include "../compiler_x86/opcode.h" #endif using namespace ActiveBasic::Compiler; int hash_default(const char *name){ int key; for(key=0;*name!='\0';name++){ key=((key<<8)+ *name )%MAX_HASH; } return key; } DllProc *GetDeclareHash(const char *fullName){ char namespaceStr[VN_SIZE]; //オブジェクト変数 char simpleName[VN_SIZE]; //入れ子メンバ bool isObjectMember = SplitMemberName( fullName, namespaceStr, simpleName ); /////////////////////////// // グローバル関数を検索 /////////////////////////// // ハッシュ値を取得 DllProc *pDllProc = compiler.GetObjectModule().meta.GetDllProcs().GetHashArrayElement( simpleName ); while(pDllProc){ if( pDllProc->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( fullName ) ) ){ return pDllProc; } pDllProc=pDllProc->GetChainNext(); } return NULL; } void GetOverloadSubHash( const char *lpszName, std::vector &subs ){ char name[VN_SIZE]; if(lpszName[0]=='.'){ GetWithName(name); lstrcat(name,lpszName); } else lstrcpy(name,lpszName); char ObjName[VN_SIZE]; //オブジェクト変数 char NestMember[VN_SIZE]; //入れ子メンバ bool isObjectMember = SplitMemberName( name, ObjName, NestMember ); if(isObjectMember){ //オブジェクトのメンバ関数の場合 bool isStatic = false; const CClass *pobj_c = NULL; if(lstrcmpi(ObjName,"Super")==0) { //クラスメンバ関数内から基底クラスの呼び出し pobj_c=&compiler.GetCompilingClass().GetSuperClass(); } else { //"->"によってオブジェクトを指定する通常のメンバ関数呼び出し Type type; if( GetTermType(ObjName,type) ) { if( type.IsObject() ) { pobj_c = &type.GetClass(); } } if( !pobj_c ) { pobj_c = compiler.GetObjectModule().meta.FindClassSupportedTypeDef( LexicalAnalyzer::FullNameToSymbol( ObjName ) ); if( pobj_c ){ isStatic = true; } } } if( pobj_c && pobj_c != (CClass *)-1 ){ if( isStatic ){ // 静的メソッドから列挙 pobj_c->GetStaticMethods().Enum( NestMember, subs ); } else{ //動的メソッドから列挙 pobj_c->EnumDynamicMethodsOrInterfaceMethods( NestMember, subs ); } return; } } if( compiler.IsCompilingClass() ){ //自身のオブジェクトのメンバ関数を検索 // 静的メソッド compiler.GetCompilingClass().GetStaticMethods().Enum( name, subs ); // 動的メソッド compiler.GetCompilingClass().EnumDynamicMethodsOrInterfaceMethods( name, subs ); } // グローバル関数を検索 compiler.GetObjectModule().meta.GetUserProcs().EnumGlobalProcs( NestMember, LexicalAnalyzer::FullNameToSymbol( name ), subs ); } //オーバーロードされていない関数を取得(昔のコンパイラソースコードとの互換性保持) const UserProc *GetSubHash(const char *lpszName,BOOL bError){ std::vector subs; GetOverloadSubHash(lpszName,subs); //関数が存在しないとき if(subs.size() == 0){ if(bError){ compiler.errorMessenger.Output(3,lpszName,cp); } return 0; } //一つ以上の関数が存在するときは内部エラー(デバッグ用) if(subs.size() > 1){ if(bError) compiler.errorMessenger.Output(300,NULL,cp); } const UserProc *pUserProc = subs[0]; return pUserProc; } const UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError){ char temporary[VN_SIZE]; sprintf(temporary,"%s.%s",ObjectName,MethodName); std::vector subs; GetOverloadSubHash(temporary,subs); //関数が存在しないとき if(subs.size() == 0){ return 0; } //オーバーロードを解決 const UserProc *pUserProc = OverloadSolutionWithStrParam(temporary,subs,Parameter,ObjectName); return pUserProc; } const UserProc *GetClassMethod( const char *className, const char *methodName ){ const CClass *pClass = compiler.GetObjectModule().meta.FindClassSupportedTypeDef( LexicalAnalyzer::FullNameToSymbol( className ) ); if( pClass ){ std::vector userProcs; pClass->EnumDynamicMethodsOrInterfaceMethods( methodName, userProcs ); if( userProcs.size() == 1 ){ return userProcs[0]; } } char temporary[VN_SIZE]; sprintf( temporary, "%s.%s", className, methodName ); compiler.errorMessenger.Output(3, temporary, -1 ); return NULL; }