source: dev/trunk/abdev/BasicCompiler_Common/Procedure.h@ 163

Last change on this file since 163 was 140, checked in by dai_9181, 17 years ago

traceログ機能を搭載
動的メンバをstl::vectorにまとめた
シンボルをクラス化した

File size: 6.9 KB
Line 
1#pragma once
2
3#include <Namespace.h>
4#include "Parameter.h"
5#include "Variable.h"
6
7class CClass;
8class CMethod;
9
10class Procedure{
11public:
12 // 種類
13 enum Kind{
14 Sub,
15 Function,
16 };
17
18private:
19 const string name; // プロシージャ名
20
21 Kind kind;
22
23 bool isCdecl;
24 bool isUsing;
25
26protected:
27
28 // パラメータ
29 Parameters params;
30
31 // 戻り値の型
32 Type returnType;
33
34 // ソースコードの位置
35 int codePos;
36
37public:
38 Procedure( const string &name, Kind kind, bool isCdecl ):
39 name( name ),
40 kind( kind ),
41 isCdecl( isCdecl ),
42 isUsing( false ),
43 codePos( -1 )
44 {}
45 ~Procedure(){
46 foreach( Parameter *pParam, params ){
47 delete pParam;
48 }
49 }
50
51 const string &GetName() const
52 {
53 return name;
54 }
55
56 bool IsSub() const
57 {
58 return ( kind == Sub );
59 }
60 bool IsFunction() const
61 {
62 return ( kind == Function );
63 }
64
65 bool IsCdecl() const
66 {
67 return isCdecl;
68 }
69 void Using(){
70 isUsing = true;
71 }
72 bool IsUsing() const
73 {
74 return isUsing;
75 }
76
77 int GetCodePos() const
78 {
79 return codePos;
80 }
81
82 const Parameters &Params() const
83 {
84 return params;
85 }
86 const Type &ReturnType() const
87 {
88 return returnType;
89 }
90};
91
92class UserProc : public Procedure
93{
94public:
95 string _paramStr;
96
97private:
98 bool isMacro;
99
100 // パラメータの追加情報
101 int secondParmNum;
102 Parameters realParams;
103 int realSecondParmNum;
104
105 // 親クラスと対応するメソッド
106 const CClass *pParentClass;
107 CMethod *pMethod;
108
109 // 各種フラグ
110 bool isExport;
111 bool isSystem;
112 bool isAutoGeneration;
113 bool isCompiled;
114
115public:
116
117 UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
118 Procedure( name, kind, isCdecl ),
119 isMacro( isMacro ),
120 pParentClass( NULL ),
121 pMethod( NULL ),
122 isExport( isExport ),
123 isSystem( false ),
124 isAutoGeneration( false ),
125 isCompiled( false ),
126 beginOpAddress( 0 ),
127 endOpAddress( 0 )
128 {
129 }
130 ~UserProc(){
131 foreach( Parameter *pParam, realParams ){
132 delete pParam;
133 }
134 }
135
136 string GetFullName() const;
137
138 bool IsMacro() const
139 {
140 return isMacro;
141 }
142
143 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
144
145 int GetSecondParmNum() const
146 {
147 return secondParmNum;
148 }
149 const Parameters &RealParams() const
150 {
151 return realParams;
152 }
153 int GetRealSecondParmNum() const
154 {
155 return realSecondParmNum;
156 }
157
158 void SetParentClass( const CClass *pParentClass ){
159 this->pParentClass = pParentClass;
160 }
161 const CClass *GetParentClassPtr() const
162 {
163 return pParentClass;
164 }
165 const CClass &GetParentClass() const
166 {
167 return *pParentClass;
168 }
169 bool HasParentClass() const
170 {
171 return ( pParentClass != NULL );
172 }
173 void SetMethod( CMethod *pMethod ){
174 this->pMethod = pMethod;
175 }
176
177 void ExportOff(){
178 isExport = false;
179 }
180 bool IsExport() const
181 {
182 return isExport;
183 }
184 void ThisIsSystemProc(){
185 isSystem = true;
186 }
187 bool IsSystem() const
188 {
189 return isSystem;
190 }
191 void ThisIsAutoGenerationProc(){
192 isAutoGeneration = true;
193 }
194 bool IsAutoGeneration(){
195 return isAutoGeneration;
196 }
197 void CompleteCompile(){
198 isCompiled = true;
199 }
200 void KillCompileStatus(){
201 isCompiled = false;
202 }
203 bool IsCompiled() const
204 {
205 return isCompiled;
206 }
207 bool IsDestructor() const
208 {
209 return ( GetName()[0] == '~' );
210 }
211 bool IsVirtual() const;
212
213 // バイナリコードの位置
214 DWORD beginOpAddress;
215 DWORD endOpAddress;
216 int GetCodeSize() const
217 {
218 return endOpAddress - beginOpAddress;
219 }
220
221 virtual const NamespaceScopes &GetNamespaceScopes() const;
222 virtual const NamespaceScopesCollection &GetImportedNamespaces() const;
223 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
224
225 // ローカル変数
226 Variables localVars;
227
228 // TODO: 適切なコードへ直す
229 long id;
230
231
232 /////////////////////////////////////////////////////////////////
233 // コンパイル中の関数を管理
234 /////////////////////////////////////////////////////////////////
235private:
236 static UserProc *pCompilingUserProc;
237public:
238 static void CompileStartForGlobalArea(){
239 pCompilingUserProc = NULL;
240 }
241 static void CompileStartForUserProc( UserProc *pUserProc ){
242 pCompilingUserProc = pUserProc;
243 }
244 static bool IsGlobalAreaCompiling(){
245 return ( pCompilingUserProc == NULL );
246 }
247 static bool IsLocalAreaCompiling(){
248 return ( pCompilingUserProc != NULL );
249 }
250 static UserProc &CompilingUserProc(){
251 return *pCompilingUserProc;
252 }
253};
254
255class GlobalProc : public UserProc
256{
257 const NamespaceScopes namespaceScopes;
258 const NamespaceScopesCollection importedNamespaces;
259public:
260 // ハッシュリスト用
261 GlobalProc *pNextData;
262
263 GlobalProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
264 UserProc( name, kind, isMacro, isCdecl, isExport ),
265 namespaceScopes( namespaceScopes ),
266 importedNamespaces( importedNamespaces ),
267 pNextData( NULL )
268 {}
269 ~GlobalProc(){}
270/*
271 GlobalProc *Create( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
272 bool AddGlobalProc( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
273*/
274 virtual const NamespaceScopes &GetNamespaceScopes() const;
275 virtual const NamespaceScopesCollection &GetImportedNamespaces() const
276 {
277 return importedNamespaces;
278 }
279
280 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
281 virtual bool IsEqualSymbol( const GlobalProc &globalProc ) const;
282 virtual bool IsEqualSymbol( const string &name ) const;
283};
284
285class DllProc : public Procedure
286{
287 const NamespaceScopes namespaceScopes;
288
289 const string dllFileName;
290 const string alias;
291 int lookupAddress;
292
293public:
294 // ハッシュリスト用
295 DllProc *pNextData;
296
297 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
298 Procedure( name, kind, isCdecl ),
299 namespaceScopes( namespaceScopes ),
300 dllFileName( dllFileName ),
301 alias( alias ),
302 lookupAddress( 0 ),
303 pNextData( NULL )
304 {
305 }
306 ~DllProc(){}
307
308 bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
309 bool IsEqualSymbol( const string &name ) const;
310
311 const NamespaceScopes &GetNamespaceScopes() const
312 {
313 return namespaceScopes;
314 }
315
316 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
317
318 const string &GetDllFileName() const
319 {
320 return dllFileName;
321 }
322 const string &GetAlias() const
323 {
324 return alias;
325 }
326
327 void SetLookupAddress( int lookupAddress ){
328 this->lookupAddress = lookupAddress;
329 }
330 int GetLookupAddress() const
331 {
332 return lookupAddress;
333 }
334
335};
336
337class ProcPointer : public Procedure
338{
339public:
340 ProcPointer( Kind kind ):
341 Procedure( "", kind, false )
342 {
343 }
344 ~ProcPointer(){}
345
346 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
347};
Note: See TracBrowser for help on using the repository browser.