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

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

DllProcsクラスを追加。

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