source: dev/trunk/abdev/BasicCompiler_Common/hash.cpp@ 193

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