source: dev/BasicCompiler_Common/Procedure.h@ 101

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

名前空間機能をグローバル関数に適用(作業完了)。

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