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