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
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 *name){
38 //ハッシュ値を取得
39 int key;
40 key=hash_default(name);
41
42 //格納位置を取得
43 extern DllProc **ppDeclareHash;
44 DllProc *pDllProc;
45 pDllProc=ppDeclareHash[key];
46 while(pDllProc){
47 if( pDllProc->GetName() == name ){
48 break;
49 }
50
51 pDllProc=pDllProc->pNextData;
52 }
53
54 return pDllProc;
55}
56
57void GetOverloadSubHash( const char *lpszName, std::vector<UserProc *> &subs ){
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]; //入れ子メンバ
68 bool isObjectMember = SplitMemberName( name, ObjName, NestMember );
69
70 if(isObjectMember){
71 //オブジェクトのメンバ関数の場合
72
73 bool isStatic = false;
74 const CClass *pobj_c = NULL;
75 if(lstrcmpi(ObjName,"Super")==0){
76 //クラスメンバ関数内から基底クラスの呼び出し
77 pobj_c=pobj_CompilingClass;
78 }
79 else{
80 //"->"によってオブジェクトを指定する通常のメンバ関数呼び出し
81 Type type;
82 if( GetVarType(ObjName,type,0) ){
83 pobj_c = &type.GetClass();
84 }
85 else{
86 pobj_c=pobj_DBClass->Find(ObjName);
87 if( pobj_c ){
88 isStatic = true;
89 }
90 }
91 }
92
93 if( pobj_c && pobj_c != (CClass *)-1 ){
94 if( isStatic ){
95 // 静的メソッドから列挙
96 pobj_c->EnumStaticMethod( NestMember, subs );
97 }
98 else{
99 //動的メソッドから列挙
100 pobj_c->EnumMethod( NestMember, subs );
101 }
102 return;
103 }
104 }
105
106
107 if(pobj_CompilingClass){
108 //自身のオブジェクトのメンバ関数を検索
109
110 // 静的メソッド
111 pobj_CompilingClass->EnumStaticMethod( name, subs );
112
113 // 動的メソッド
114 pobj_CompilingClass->EnumMethod( name, subs );
115 }
116
117
118 ///////////////////////////
119 // グローバル関数を検索
120 ///////////////////////////
121
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()){
132 if( pUserProc->IsEqualSymbol( name ) ){
133 subs.push_back( pUserProc );
134 }
135 }
136
137 pUserProc=pUserProc->pNextData;
138 }
139}
140
141//オーバーロードされていない関数を取得(昔のコンパイラソースコードとの互換性保持)
142UserProc *GetSubHash(const char *lpszName,BOOL bError){
143 std::vector<UserProc *> subs;
144 GetOverloadSubHash(lpszName,subs);
145
146 //関数が存在しないとき
147 if(subs.size() == 0){
148 if(bError){
149 SetError(3,lpszName,cp);
150 }
151 return 0;
152 }
153
154 //一つ以上の関数が存在するときは内部エラー(デバッグ用)
155 if(subs.size() > 1){
156 if(bError) SetError(300,NULL,cp);
157 }
158
159 UserProc *pUserProc;
160 pUserProc = subs[0];
161
162 return pUserProc;
163}
164UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError){
165 char temporary[VN_SIZE];
166 sprintf(temporary,"%s.%s",ObjectName,MethodName);
167
168 std::vector<UserProc *> subs;
169 UserProc *pUserProc;
170 GetOverloadSubHash(temporary,subs);
171
172 //関数が存在しないとき
173 if(subs.size() == 0){
174 return 0;
175 }
176
177 //オーバーロードを解決
178 pUserProc=OverloadSolutionWithStrParam(temporary,subs,Parameter,ObjectName);
179
180 return pUserProc;
181}
182
183UserProc *GetClassMethod( const char *className, const char *methodName ){
184 CClass *pClass = pobj_DBClass->Find( className );
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.