source: dev/BasicCompiler_Common/Procedure.h@ 108

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

関数、クラスメソッドにImports機構を適用。

File size: 6.7 KB
RevLine 
[78]1#pragma once
[74]2
[100]3#include <Namespace.h>
4#include "Parameter.h"
5#include "Variable.h"
6
7class CClass;
8class CMethod;
9
[75]10class Procedure{
[74]11public:
[75]12 // 種類
13 enum Kind{
14 Sub,
15 Function,
16 };
[74]17
[75]18private:
[100]19 const string name; // プロシージャ名
[74]20
[75]21 Kind kind;
[74]22
[75]23 bool isCdecl;
24 bool isUsing;
[74]25
[75]26protected:
[74]27
[75]28 // パラメータ
[74]29 Parameters params;
[75]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{
[97]94#ifdef _DEBUG
95public:
96 string _paramStr;
97#endif
[75]98
99private:
100 bool isMacro;
101
102 // パラメータの追加情報
103 int secondParmNum;
[74]104 Parameters realParams;
[75]105 int realSecondParmNum;
[74]106
[75]107 // 親クラスと対応するメソッド
108 CClass *pParentClass;
109 CMethod *pMethod;
[74]110
[75]111 // 各種フラグ
112 bool isExport;
113 bool isSystem;
[90]114 bool isAutoGeneration;
[75]115 bool isCompiled;
[74]116
[75]117public:
[74]118
[75]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 ),
[90]126 isAutoGeneration( false ),
[75]127 isCompiled( false ),
[92]128 beginOpAddress( 0 ),
129 endOpAddress( 0 )
[75]130 {
131 }
132 ~UserProc(){
133 foreach( Parameter *pParam, realParams ){
134 delete pParam;
135 }
136 }
137
[100]138 string GetFullName() const;
[91]139
[75]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( CClass *pParentClass ){
161 this->pParentClass = pParentClass;
162 }
163 CClass *GetParentClassPtr()
164 {
165 return pParentClass;
166 }
167 const CClass &GetParentClass() const
168 {
169 return *pParentClass;
170 }
[89]171 bool HasParentClass() const
172 {
173 return ( pParentClass != NULL );
174 }
[75]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 }
[90]193 void ThisIsAutoGenerationProc(){
194 isAutoGeneration = true;
195 }
196 bool IsAutoGeneration(){
197 return isAutoGeneration;
198 }
[75]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 }
[100]213 bool IsVirtual() const;
[75]214
215 // バイナリコードの位置
216 DWORD beginOpAddress;
217 DWORD endOpAddress;
[91]218 int GetCodeSize() const
219 {
220 return endOpAddress - beginOpAddress;
221 }
[75]222
[101]223 virtual const NamespaceScopes &GetNamespaceScopes() const;
[108]224 virtual const NamespaceScopesCollection &GetImportedNamespaces() const;
[101]225 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
226
[75]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 }
[74]255};
[75]256
[100]257class GlobalProc : public UserProc
258{
259 const NamespaceScopes namespaceScopes;
[108]260 const NamespaceScopesCollection importedNamespaces;
[100]261public:
262 // ハッシュリスト用
263 GlobalProc *pNextData;
264
[108]265 GlobalProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
[100]266 UserProc( name, kind, isMacro, isCdecl, isExport ),
267 namespaceScopes( namespaceScopes ),
[108]268 importedNamespaces( importedNamespaces ),
[100]269 pNextData( NULL )
270 {}
271 ~GlobalProc(){}
[108]272/*
[100]273 GlobalProc *Create( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
274 bool AddGlobalProc( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
[108]275*/
[101]276 virtual const NamespaceScopes &GetNamespaceScopes() const
[100]277 {
278 return namespaceScopes;
279 }
[108]280 virtual const NamespaceScopesCollection &GetImportedNamespaces() const
281 {
282 return importedNamespaces;
283 }
[100]284
[101]285 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
286 virtual bool IsEqualSymbol( const GlobalProc &globalProc ) const;
287 virtual bool IsEqualSymbol( const string &name ) const;
[100]288};
289
[75]290class DllProc : public Procedure
291{
[100]292 const NamespaceScopes namespaceScopes;
293
[75]294 const string dllFileName;
295 const string alias;
296 int lookupAddress;
297
298public:
299 // ハッシュリスト用
300 DllProc *pNextData;
301
[100]302 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
[75]303 Procedure( name, kind, isCdecl ),
[100]304 namespaceScopes( namespaceScopes ),
[75]305 dllFileName( dllFileName ),
306 alias( alias ),
307 lookupAddress( 0 ),
308 pNextData( NULL )
309 {
310 }
311 ~DllProc(){}
312
313 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
314
315 const string &GetDllFileName() const
316 {
317 return dllFileName;
318 }
319 const string &GetAlias() const
320 {
321 return alias;
322 }
323
324 void SetLookupAddress( int lookupAddress ){
325 this->lookupAddress = lookupAddress;
326 }
327 int GetLookupAddress() const
328 {
329 return lookupAddress;
330 }
331
332};
333
334class ProcPointer : public Procedure
335{
336public:
337 ProcPointer( Kind kind ):
338 Procedure( "", kind, false )
339 {
340 }
341 ~ProcPointer(){}
342
343 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
344};
Note: See TracBrowser for help on using the repository browser.