source: dev/BasicCompiler_Common/Procedure.h@ 100

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

名前空間機能をグローバル関数に適用。

File size: 6.1 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
223 // ローカル変数
224 Variables localVars;
225
226 // TODO: 適切なコードへ直す
227 long id;
228
229
230 /////////////////////////////////////////////////////////////////
231 // コンパイル中の関数を管理
232 /////////////////////////////////////////////////////////////////
233private:
234 static UserProc *pCompilingUserProc;
235public:
236 static void CompileStartForGlobalArea(){
237 pCompilingUserProc = NULL;
238 }
239 static void CompileStartForUserProc( UserProc *pUserProc ){
240 pCompilingUserProc = pUserProc;
241 }
242 static bool IsGlobalAreaCompiling(){
243 return ( pCompilingUserProc == NULL );
244 }
245 static bool IsLocalAreaCompiling(){
246 return ( pCompilingUserProc != NULL );
247 }
248 static UserProc &CompilingUserProc(){
249 return *pCompilingUserProc;
250 }
[100]251
252 virtual bool EqualName( const string &name ) const;
[74]253};
[75]254
[100]255class GlobalProc : public UserProc
256{
257 const NamespaceScopes namespaceScopes;
258public:
259 // ハッシュリスト用
260 GlobalProc *pNextData;
261
262 GlobalProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
263 UserProc( name, kind, isMacro, isCdecl, isExport ),
264 namespaceScopes( namespaceScopes ),
265 pNextData( NULL )
266 {}
267 ~GlobalProc(){}
268
269 GlobalProc *Create( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
270 bool AddGlobalProc( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
271
272 const NamespaceScopes &GetNamespaceScopes() const
273 {
274 return namespaceScopes;
275 }
276
277 virtual bool EqualName( const string &name ) const;
278};
279
[75]280class DllProc : public Procedure
281{
[100]282 const NamespaceScopes namespaceScopes;
283
[75]284 const string dllFileName;
285 const string alias;
286 int lookupAddress;
287
288public:
289 // ハッシュリスト用
290 DllProc *pNextData;
291
[100]292 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
[75]293 Procedure( name, kind, isCdecl ),
[100]294 namespaceScopes( namespaceScopes ),
[75]295 dllFileName( dllFileName ),
296 alias( alias ),
297 lookupAddress( 0 ),
298 pNextData( NULL )
299 {
300 }
301 ~DllProc(){}
302
303 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
304
305 const string &GetDllFileName() const
306 {
307 return dllFileName;
308 }
309 const string &GetAlias() const
310 {
311 return alias;
312 }
313
314 void SetLookupAddress( int lookupAddress ){
315 this->lookupAddress = lookupAddress;
316 }
317 int GetLookupAddress() const
318 {
319 return lookupAddress;
320 }
321
322};
323
324class ProcPointer : public Procedure
325{
326public:
327 ProcPointer( Kind kind ):
328 Procedure( "", kind, false )
329 {
330 }
331 ~ProcPointer(){}
332
333 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
334};
Note: See TracBrowser for help on using the repository browser.