source: dev/BasicCompiler_Common/Procedure.h@ 113

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

TypeDef、Declareの名前空間対応を行った。
TypeDef、Declareをローカル領域で使用した際、エラーを表示するようにした。

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 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 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 {
278 return namespaceScopes;
279 }
280 virtual const NamespaceScopesCollection &GetImportedNamespaces() const
281 {
282 return importedNamespaces;
283 }
284
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;
288};
289
290class DllProc : public Procedure
291{
292 const NamespaceScopes namespaceScopes;
293
294 const string dllFileName;
295 const string alias;
296 int lookupAddress;
297
298public:
299 // ハッシュリスト用
300 DllProc *pNextData;
301
302 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
303 Procedure( name, kind, isCdecl ),
304 namespaceScopes( namespaceScopes ),
305 dllFileName( dllFileName ),
306 alias( alias ),
307 lookupAddress( 0 ),
308 pNextData( NULL )
309 {
310 }
311 ~DllProc(){}
312
313 bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
314 bool IsEqualSymbol( const string &name ) const;
315
316 const NamespaceScopes &GetNamespaceScopes() const
317 {
318 return namespaceScopes;
319 }
320
321 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
322
323 const string &GetDllFileName() const
324 {
325 return dllFileName;
326 }
327 const string &GetAlias() const
328 {
329 return alias;
330 }
331
332 void SetLookupAddress( int lookupAddress ){
333 this->lookupAddress = lookupAddress;
334 }
335 int GetLookupAddress() const
336 {
337 return lookupAddress;
338 }
339
340};
341
342class ProcPointer : public Procedure
343{
344public:
345 ProcPointer( Kind kind ):
346 Procedure( "", kind, false )
347 {
348 }
349 ~ProcPointer(){}
350
351 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
352};
Note: See TracBrowser for help on using the repository browser.