source: dev/BasicCompiler_Common/Procedure.h@ 116

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

暗黙的なアップキャストを可能にした

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{
94#ifdef _DEBUG
95public:
96 string _paramStr;
97#endif
98
99private:
100 bool isMacro;
101
102 // パラメータの追加情報
103 int secondParmNum;
104 Parameters realParams;
105 int realSecondParmNum;
106
107 // 親クラスと対応するメソッド
108 const CClass *pParentClass;
109 CMethod *pMethod;
110
111 // 各種フラグ
112 bool isExport;
113 bool isSystem;
114 bool isAutoGeneration;
115 bool isCompiled;
116
117public:
118
119 UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
120 Procedure( name, kind, isCdecl ),
121 isMacro( isMacro ),
122 pParentClass( NULL ),
123 pMethod( NULL ),
124 isExport( isExport ),
125 isSystem( false ),
126 isAutoGeneration( false ),
127 isCompiled( false ),
128 beginOpAddress( 0 ),
129 endOpAddress( 0 )
130 {
131 }
132 ~UserProc(){
133 foreach( Parameter *pParam, realParams ){
134 delete pParam;
135 }
136 }
137
138 string GetFullName() const;
139
140 bool IsMacro() const
141 {
142 return isMacro;
143 }
144
145 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
146
147 int GetSecondParmNum() const
148 {
149 return secondParmNum;
150 }
151 const Parameters &RealParams() const
152 {
153 return realParams;
154 }
155 int GetRealSecondParmNum() const
156 {
157 return realSecondParmNum;
158 }
159
160 void SetParentClass( const CClass *pParentClass ){
161 this->pParentClass = pParentClass;
162 }
163 const CClass *GetParentClassPtr() const
164 {
165 return pParentClass;
166 }
167 const CClass &GetParentClass() const
168 {
169 return *pParentClass;
170 }
171 bool HasParentClass() const
172 {
173 return ( pParentClass != NULL );
174 }
175 void SetMethod( CMethod *pMethod ){
176 this->pMethod = pMethod;
177 }
178
179 void ExportOff(){
180 isExport = false;
181 }
182 bool IsExport() const
183 {
184 return isExport;
185 }
186 void ThisIsSystemProc(){
187 isSystem = true;
188 }
189 bool IsSystem() const
190 {
191 return isSystem;
192 }
193 void ThisIsAutoGenerationProc(){
194 isAutoGeneration = true;
195 }
196 bool IsAutoGeneration(){
197 return isAutoGeneration;
198 }
199 void CompleteCompile(){
200 isCompiled = true;
201 }
202 void KillCompileStatus(){
203 isCompiled = false;
204 }
205 bool IsCompiled() const
206 {
207 return isCompiled;
208 }
209 bool IsDestructor() const
210 {
211 return ( GetName()[0] == '~' );
212 }
213 bool IsVirtual() const;
214
215 // バイナリコードの位置
216 DWORD beginOpAddress;
217 DWORD endOpAddress;
218 int GetCodeSize() const
219 {
220 return endOpAddress - beginOpAddress;
221 }
222
223 virtual const NamespaceScopes &GetNamespaceScopes() const;
224 virtual const NamespaceScopesCollection &GetImportedNamespaces() const;
225 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
226
227 // ローカル変数
228 Variables localVars;
229
230 // TODO: 適切なコードへ直す
231 long id;
232
233
234 /////////////////////////////////////////////////////////////////
235 // コンパイル中の関数を管理
236 /////////////////////////////////////////////////////////////////
237private:
238 static UserProc *pCompilingUserProc;
239public:
240 static void CompileStartForGlobalArea(){
241 pCompilingUserProc = NULL;
242 }
243 static void CompileStartForUserProc( UserProc *pUserProc ){
244 pCompilingUserProc = pUserProc;
245 }
246 static bool IsGlobalAreaCompiling(){
247 return ( pCompilingUserProc == NULL );
248 }
249 static bool IsLocalAreaCompiling(){
250 return ( pCompilingUserProc != NULL );
251 }
252 static UserProc &CompilingUserProc(){
253 return *pCompilingUserProc;
254 }
255};
256
257class GlobalProc : public UserProc
258{
259 const NamespaceScopes namespaceScopes;
260 const NamespaceScopesCollection importedNamespaces;
261public:
262 // ハッシュリスト用
263 GlobalProc *pNextData;
264
265 GlobalProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
266 UserProc( name, kind, isMacro, isCdecl, isExport ),
267 namespaceScopes( namespaceScopes ),
268 importedNamespaces( importedNamespaces ),
269 pNextData( NULL )
270 {}
271 ~GlobalProc(){}
272/*
273 GlobalProc *Create( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
274 bool AddGlobalProc( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
275*/
276 virtual const NamespaceScopes &GetNamespaceScopes() const;
277 virtual const NamespaceScopesCollection &GetImportedNamespaces() const
278 {
279 return importedNamespaces;
280 }
281
282 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
283 virtual bool IsEqualSymbol( const GlobalProc &globalProc ) const;
284 virtual bool IsEqualSymbol( const string &name ) const;
285};
286
287class DllProc : public Procedure
288{
289 const NamespaceScopes namespaceScopes;
290
291 const string dllFileName;
292 const string alias;
293 int lookupAddress;
294
295public:
296 // ハッシュリスト用
297 DllProc *pNextData;
298
299 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
300 Procedure( name, kind, isCdecl ),
301 namespaceScopes( namespaceScopes ),
302 dllFileName( dllFileName ),
303 alias( alias ),
304 lookupAddress( 0 ),
305 pNextData( NULL )
306 {
307 }
308 ~DllProc(){}
309
310 bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
311 bool IsEqualSymbol( const string &name ) const;
312
313 const NamespaceScopes &GetNamespaceScopes() const
314 {
315 return namespaceScopes;
316 }
317
318 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
319
320 const string &GetDllFileName() const
321 {
322 return dllFileName;
323 }
324 const string &GetAlias() const
325 {
326 return alias;
327 }
328
329 void SetLookupAddress( int lookupAddress ){
330 this->lookupAddress = lookupAddress;
331 }
332 int GetLookupAddress() const
333 {
334 return lookupAddress;
335 }
336
337};
338
339class ProcPointer : public Procedure
340{
341public:
342 ProcPointer( Kind kind ):
343 Procedure( "", kind, false )
344 {
345 }
346 ~ProcPointer(){}
347
348 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
349};
Note: See TracBrowser for help on using the repository browser.