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