source: dev/branches/egtra/ab5.0/abdev/BasicCompiler_Common/hash.cpp@ 806

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

コンパイラのstdafx.h, .cppを32/64ビットで共通化。Windows SDKに含まれるライブラリ・ヘッダの除去。VC++ 2010 Express with WDKのATL環境で_SECURE_ATLがエラーを起こす問題の修正。4996警告の抑制pragmaを削除。ほか。

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