source: dev/BasicCompiler_Common/hash.cpp@ 75

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

TYPEINFO→Typeへのリファクタリングを実施。64bitはほぼ完了。32bitが全般的に未完成。

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