source: dev/BasicCompiler_Common/hash.cpp@ 101

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

名前空間機能をグローバル関数に適用(作業完了)。

File size: 4.2 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 if( (string)lpszName == "Test2.Proc3" ){
67 int test=0;
68 }
69
70 char ObjName[VN_SIZE]; //オブジェクト変数
71 char NestMember[VN_SIZE]; //入れ子メンバ
72 bool isObjectMember = SplitMemberName( name, ObjName, NestMember );
73
74 if(isObjectMember){
75 //オブジェクトのメンバ関数の場合
76
77 bool isStatic = false;
78 const CClass *pobj_c = NULL;
79 if(lstrcmpi(ObjName,"Super")==0){
80 //クラスメンバ関数内から基底クラスの呼び出し
81 pobj_c=pobj_CompilingClass;
82 }
83 else{
84 //"->"によってオブジェクトを指定する通常のメンバ関数呼び出し
85 Type type;
86 if( GetVarType(ObjName,type,0) ){
87 pobj_c = &type.GetClass();
88 }
89 else{
90 pobj_c=pobj_DBClass->check(ObjName);
91 if( pobj_c ){
92 isStatic = true;
93 }
94 }
95 }
96
97 if( pobj_c && pobj_c != (CClass *)-1 ){
98 if( isStatic ){
99 // 静的メソッドから列挙
100 pobj_c->EnumStaticMethod( NestMember, subs );
101 }
102 else{
103 //動的メソッドから列挙
104 pobj_c->EnumMethod( NestMember, subs );
105 }
106 return;
107 }
108 }
109
110
111 if(pobj_CompilingClass){
112 //自身のオブジェクトのメンバ関数を検索
113
114 // 静的メソッド
115 pobj_CompilingClass->EnumStaticMethod( name, subs );
116
117 // 動的メソッド
118 pobj_CompilingClass->EnumMethod( name, subs );
119 }
120
121
122 ///////////////////////////
123 // グローバル関数を検索
124 ///////////////////////////
125
126 //ハッシュ値を取得
127 int key;
128 key=hash_default(NestMember);
129
130 //格納位置を取得
131 extern GlobalProc **ppSubHash;
132 GlobalProc *pUserProc;
133 pUserProc=ppSubHash[key];
134 while(pUserProc){
135 if(!pUserProc->GetParentClassPtr()){
136 if( pUserProc->IsEqualSymbol( name ) ){
137 subs.push_back( pUserProc );
138 }
139 }
140
141 pUserProc=pUserProc->pNextData;
142 }
143}
144
145//オーバーロードされていない関数を取得(昔のコンパイラソースコードとの互換性保持)
146UserProc *GetSubHash(const char *lpszName,BOOL bError){
147 std::vector<UserProc *> subs;
148 GetOverloadSubHash(lpszName,subs);
149
150 //関数が存在しないとき
151 if(subs.size() == 0){
152 if(bError){
153 SetError(3,lpszName,cp);
154 }
155 return 0;
156 }
157
158 //一つ以上の関数が存在するときは内部エラー(デバッグ用)
159 if(subs.size() > 1){
160 if(bError) SetError(300,NULL,cp);
161 }
162
163 UserProc *pUserProc;
164 pUserProc = subs[0];
165
166 return pUserProc;
167}
168UserProc *GetMethodHash(const char *ObjectName,const char *MethodName,const char *Parameter,BOOL bError){
169 char temporary[VN_SIZE];
170 sprintf(temporary,"%s.%s",ObjectName,MethodName);
171
172 std::vector<UserProc *> subs;
173 UserProc *pUserProc;
174 GetOverloadSubHash(temporary,subs);
175
176 //関数が存在しないとき
177 if(subs.size() == 0){
178 return 0;
179 }
180
181 //オーバーロードを解決
182 pUserProc=OverloadSolutionWithStrParam(temporary,subs,Parameter,ObjectName);
183
184 return pUserProc;
185}
186
187UserProc *GetClassMethod( const char *className, const char *methodName ){
188 CClass *pClass = pobj_DBClass->check( className );
189 if( pClass ){
190 vector<UserProc *> userProcs;
191 pClass->EnumMethod( methodName, userProcs );
192 if( userProcs.size() == 1 ){
193 return userProcs[0];
194 }
195 }
196
197 char temporary[VN_SIZE];
198 sprintf( temporary, "%s.%s", className, methodName );
199 SetError(3, temporary, -1 );
200
201 return NULL;
202}
Note: See TracBrowser for help on using the repository browser.