source: dev/trunk/jenga/include/smoothie/Procedure.h@ 170

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

ベースを作成中...

File size: 6.8 KB
Line 
1#pragma once
2
3#include "Parameter.h"
4#include "Variable.h"
5
6class CClass;
7class CMethod;
8
9class Procedure{
10public:
11 // 種類
12 enum Kind{
13 Sub,
14 Function,
15 };
16
17private:
18 const string name; // プロシージャ名
19
20 Kind kind;
21
22 bool isCdecl;
23 bool isUsing;
24
25protected:
26
27 // パラメータ
28 Parameters params;
29
30 // 戻り値の型
31 Type returnType;
32
33 // ソースコードの位置
34 int codePos;
35
36public:
37 Procedure( const string &name, Kind kind, bool isCdecl ):
38 name( name ),
39 kind( kind ),
40 isCdecl( isCdecl ),
41 isUsing( false ),
42 codePos( -1 )
43 {}
44 ~Procedure(){
45 BOOST_FOREACH( Parameter *pParam, params ){
46 delete pParam;
47 }
48 }
49
50 const string &GetName() const
51 {
52 return name;
53 }
54
55 bool IsSub() const
56 {
57 return ( kind == Sub );
58 }
59 bool IsFunction() const
60 {
61 return ( kind == Function );
62 }
63
64 bool IsCdecl() const
65 {
66 return isCdecl;
67 }
68 void Using(){
69 isUsing = true;
70 }
71 bool IsUsing() const
72 {
73 return isUsing;
74 }
75
76 int GetCodePos() const
77 {
78 return codePos;
79 }
80
81 const Parameters &Params() const
82 {
83 return params;
84 }
85 const Type &ReturnType() const
86 {
87 return returnType;
88 }
89};
90
91class UserProc : public Procedure
92{
93public:
94 string _paramStr;
95
96private:
97 bool isMacro;
98
99 // パラメータの追加情報
100 int secondParmNum;
101 Parameters realParams;
102 int realSecondParmNum;
103
104 // 親クラスと対応するメソッド
105 const CClass *pParentClass;
106 CMethod *pMethod;
107
108 // 各種フラグ
109 bool isExport;
110 bool isSystem;
111 bool isAutoGeneration;
112 bool isCompiled;
113
114public:
115
116 UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
117 Procedure( name, kind, isCdecl ),
118 isMacro( isMacro ),
119 pParentClass( NULL ),
120 pMethod( NULL ),
121 isExport( isExport ),
122 isSystem( false ),
123 isAutoGeneration( false ),
124 isCompiled( false ),
125 beginOpAddress( 0 ),
126 endOpAddress( 0 )
127 {
128 }
129 ~UserProc();
130
131 string GetFullName() const;
132
133 bool IsMacro() const
134 {
135 return isMacro;
136 }
137
138 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
139
140 int GetSecondParmNum() const
141 {
142 return secondParmNum;
143 }
144 const Parameters &RealParams() const
145 {
146 return realParams;
147 }
148 int GetRealSecondParmNum() const
149 {
150 return realSecondParmNum;
151 }
152
153 void SetParentClass( const CClass *pParentClass ){
154 this->pParentClass = pParentClass;
155 }
156 const CClass *GetParentClassPtr() const
157 {
158 return pParentClass;
159 }
160 const CClass &GetParentClass() const
161 {
162 return *pParentClass;
163 }
164 bool HasParentClass() const
165 {
166 return ( pParentClass != NULL );
167 }
168 void SetMethod( CMethod *pMethod ){
169 this->pMethod = pMethod;
170 }
171
172 void ExportOff(){
173 isExport = false;
174 }
175 bool IsExport() const
176 {
177 return isExport;
178 }
179 void ThisIsSystemProc(){
180 isSystem = true;
181 }
182 bool IsSystem() const
183 {
184 return isSystem;
185 }
186 void ThisIsAutoGenerationProc(){
187 isAutoGeneration = true;
188 }
189 bool IsAutoGeneration(){
190 return isAutoGeneration;
191 }
192 void CompleteCompile(){
193 isCompiled = true;
194 }
195 void KillCompileStatus(){
196 isCompiled = false;
197 }
198 bool IsCompiled() const
199 {
200 return isCompiled;
201 }
202 bool IsDestructor() const
203 {
204 return ( GetName()[0] == '~' );
205 }
206 bool IsVirtual() const;
207
208 // バイナリコードの位置
209 DWORD beginOpAddress;
210 DWORD endOpAddress;
211 int GetCodeSize() const
212 {
213 return endOpAddress - beginOpAddress;
214 }
215
216 virtual const NamespaceScopes &GetNamespaceScopes() const;
217 virtual const NamespaceScopesCollection &GetImportedNamespaces() const;
218 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
219
220 // ローカル変数
221 Variables localVars;
222
223 // TODO: 適切なコードへ直す
224 long id;
225
226
227 /////////////////////////////////////////////////////////////////
228 // コンパイル中の関数を管理
229 /////////////////////////////////////////////////////////////////
230private:
231 static UserProc *pCompilingUserProc;
232public:
233 static void CompileStartForGlobalArea(){
234 pCompilingUserProc = NULL;
235 }
236 static void CompileStartForUserProc( UserProc *pUserProc ){
237 pCompilingUserProc = pUserProc;
238 }
239 static bool IsGlobalAreaCompiling(){
240 return ( pCompilingUserProc == NULL );
241 }
242 static bool IsLocalAreaCompiling(){
243 return ( pCompilingUserProc != NULL );
244 }
245 static UserProc &CompilingUserProc(){
246 return *pCompilingUserProc;
247 }
248};
249
250class GlobalProc : public UserProc
251{
252 const NamespaceScopes namespaceScopes;
253 const NamespaceScopesCollection importedNamespaces;
254public:
255 // ハッシュリスト用
256 GlobalProc *pNextData;
257
258 GlobalProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
259 UserProc( name, kind, isMacro, isCdecl, isExport ),
260 namespaceScopes( namespaceScopes ),
261 importedNamespaces( importedNamespaces ),
262 pNextData( NULL )
263 {}
264 ~GlobalProc(){}
265/*
266 GlobalProc *Create( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
267 bool AddGlobalProc( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine );
268*/
269 virtual const NamespaceScopes &GetNamespaceScopes() const;
270 virtual const NamespaceScopesCollection &GetImportedNamespaces() const
271 {
272 return importedNamespaces;
273 }
274
275 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
276 virtual bool IsEqualSymbol( const GlobalProc &globalProc ) const;
277 virtual bool IsEqualSymbol( const string &name ) const;
278};
279
280class DllProc : public Procedure
281{
282 const NamespaceScopes namespaceScopes;
283
284 const string dllFileName;
285 const string alias;
286 int lookupAddress;
287
288public:
289 // ハッシュリスト用
290 DllProc *pNextData;
291
292 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
293 Procedure( name, kind, isCdecl ),
294 namespaceScopes( namespaceScopes ),
295 dllFileName( dllFileName ),
296 alias( alias ),
297 lookupAddress( 0 ),
298 pNextData( NULL )
299 {
300 }
301 ~DllProc(){}
302
303 bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
304 bool IsEqualSymbol( const string &name ) const;
305
306 const NamespaceScopes &GetNamespaceScopes() const
307 {
308 return namespaceScopes;
309 }
310
311 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
312
313 const string &GetDllFileName() const
314 {
315 return dllFileName;
316 }
317 const string &GetAlias() const
318 {
319 return alias;
320 }
321
322 void SetLookupAddress( int lookupAddress ){
323 this->lookupAddress = lookupAddress;
324 }
325 int GetLookupAddress() const
326 {
327 return lookupAddress;
328 }
329
330};
331
332class ProcPointer : public Procedure
333{
334public:
335 ProcPointer( Kind kind ):
336 Procedure( "", kind, false )
337 {
338 }
339 ~ProcPointer(){}
340
341 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
342};
Note: See TracBrowser for help on using the repository browser.