source: dev/branches/egtra/ab5.0/abdev/BasicCompiler_Common/hash.cpp@ 803

Last change on this file since 803 was 803, checked in by イグトランス (egtra), 13 years ago

Hashmapの実装にunorderedを用いるよう変更

File size: 4.3 KB
RevLine 
[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
[509]13using namespace ActiveBasic::Compiler;
14
[75]15int hash_default(const char *name){
[4]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
[209]25DllProc *GetDeclareHash(const char *fullName){
26 char namespaceStr[VN_SIZE]; //オブジェクト変数
27 char simpleName[VN_SIZE]; //入れ子メンバ
28 bool isObjectMember = SplitMemberName( fullName, namespaceStr, simpleName );
[113]29
[209]30 ///////////////////////////
31 // グローバル関数を検索
32 ///////////////////////////
[4]33
[209]34 // ハッシュ値を取得
[803]35 foreach (auto pDllProc, compiler.GetObjectModule().meta.GetDllProcs().GetHashArrayElement(simpleName))
36 {
[509]37 if( pDllProc->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( fullName ) ) ){
[209]38 return pDllProc;
[75]39 }
[4]40 }
41
[209]42 return NULL;
[4]43}
44
[206]45void 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 //クラスメンバ関数内から基底クラスの呼び出し
[536]66 pobj_c=&compiler.GetCompilingClass().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 {
[598]82 pobj_c = compiler.GetObjectModule().meta.FindClassSupportedTypeDef(
83 LexicalAnalyzer::FullNameToSymbol( ObjName )
84 );
[47]85 if( pobj_c ){
86 isStatic = true;
87 }
[28]88 }
[4]89 }
90
[101]91 if( pobj_c && pobj_c != (CClass *)-1 ){
[100]92 if( isStatic ){
93 // 静的メソッドから列挙
[136]94 pobj_c->GetStaticMethods().Enum( NestMember, subs );
[100]95 }
96 else{
97 //動的メソッドから列挙
[350]98 pobj_c->EnumDynamicMethodsOrInterfaceMethods( NestMember, subs );
[100]99 }
[304]100
[100]101 return;
[4]102 }
103 }
104
105
[536]106 if( compiler.IsCompilingClass() ){
[100]107 //自身のオブジェクトのメンバ関数を検索
[4]108
[100]109 // 静的メソッド
[536]110 compiler.GetCompilingClass().GetStaticMethods().Enum( name, subs );
[4]111
[100]112 // 動的メソッド
[536]113 compiler.GetCompilingClass().EnumDynamicMethodsOrInterfaceMethods( name, subs );
[100]114 }
[27]115
116
[100]117 // グローバル関数を検索
[576]118 compiler.GetObjectModule().meta.GetUserProcs().EnumGlobalProcs( NestMember, LexicalAnalyzer::FullNameToSymbol( name ), subs );
[4]119}
120
121//オーバーロードされていない関数を取得(昔のコンパイラソースコードとの互換性保持)
[206]122const UserProc *GetSubHash(const char *lpszName,BOOL bError){
123 std::vector<const UserProc *> subs;
[50]124 GetOverloadSubHash(lpszName,subs);
[4]125
126 //関数が存在しないとき
[50]127 if(subs.size() == 0){
[75]128 if(bError){
[465]129 compiler.errorMessenger.Output(3,lpszName,cp);
[75]130 }
[4]131 return 0;
132 }
133
134 //一つ以上の関数が存在するときは内部エラー(デバッグ用)
[50]135 if(subs.size() > 1){
[465]136 if(bError) compiler.errorMessenger.Output(300,NULL,cp);
[4]137 }
138
[206]139 const UserProc *pUserProc = subs[0];
[4]140
[75]141 return pUserProc;
[5]142}
[206]143const UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError){
[5]144 char temporary[VN_SIZE];
145 sprintf(temporary,"%s.%s",ObjectName,MethodName);
146
[206]147 std::vector<const UserProc *> subs;
[50]148 GetOverloadSubHash(temporary,subs);
[5]149
150 //関数が存在しないとき
[50]151 if(subs.size() == 0){
[5]152 return 0;
153 }
154
155 //オーバーロードを解決
[206]156 const UserProc *pUserProc = OverloadSolutionWithStrParam(temporary,subs,Parameter,ObjectName);
[5]157
[75]158 return pUserProc;
[5]159}
[95]160
[206]161const UserProc *GetClassMethod( const char *className, const char *methodName ){
[598]162 const CClass *pClass = compiler.GetObjectModule().meta.FindClassSupportedTypeDef(
163 LexicalAnalyzer::FullNameToSymbol( className )
164 );
[95]165 if( pClass ){
[523]166 std::vector<const UserProc *> userProcs;
[350]167 pClass->EnumDynamicMethodsOrInterfaceMethods( methodName, userProcs );
[95]168 if( userProcs.size() == 1 ){
169 return userProcs[0];
170 }
171 }
172
173 char temporary[VN_SIZE];
174 sprintf( temporary, "%s.%s", className, methodName );
[465]175 compiler.errorMessenger.Output(3, temporary, -1 );
[95]176
177 return NULL;
178}
Note: See TracBrowser for help on using the repository browser.