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

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

コード全体のリファクタリングを実施

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