source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/hash.cpp@ 828

Last change on this file since 828 was 828, checked in by イグトランス (egtra), 12 years ago

egtraブランチの内容をマージ。

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