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