source: dev/BasicCompiler_Common/hash.cpp@ 100

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