source: dev/BasicCompiler_Common/hash.cpp@ 136

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

EnumStaticメソッドを廃止

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