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