source: dev/BasicCompiler_Common/hash.cpp@ 102

Last change on this file since 102 was 102, checked in by dai_9181, 17 years ago

名前空間機能をクラスに適用。

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