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

Last change on this file since 197 was 192, checked in by dai_9181, 17 years ago
File size: 6.0 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
96protected:
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 void Serialize( bool isRead )
117 {
118
119 }
120
121 UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
122 Procedure( name, kind, isCdecl ),
123 isMacro( isMacro ),
124 pParentClass( NULL ),
125 pMethod( NULL ),
126 isExport( isExport ),
127 isSystem( false ),
128 isAutoGeneration( false ),
129 isCompiled( false ),
130 beginOpAddress( 0 ),
131 endOpAddress( 0 )
132 {
133 }
134 ~UserProc()
135 {
136 BOOST_FOREACH( Parameter *pParam, realParams ){
137 delete pParam;
138 }
139 }
140
141 string GetFullName() const;
142
143 bool IsMacro() const
144 {
145 return isMacro;
146 }
147
148 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic ) = 0;
149
150 int GetSecondParmNum() const
151 {
152 return secondParmNum;
153 }
154 const Parameters &RealParams() const
155 {
156 return realParams;
157 }
158 int GetRealSecondParmNum() const
159 {
160 return realSecondParmNum;
161 }
162
163 void SetParentClass( const CClass *pParentClass ){
164 this->pParentClass = pParentClass;
165 }
166 const CClass *GetParentClassPtr() const
167 {
168 return pParentClass;
169 }
170 const CClass &GetParentClass() const
171 {
172 return *pParentClass;
173 }
174 bool HasParentClass() const
175 {
176 return ( pParentClass != NULL );
177 }
178 void SetMethod( CMethod *pMethod ){
179 this->pMethod = pMethod;
180 }
181
182 void ExportOff(){
183 isExport = false;
184 }
185 bool IsExport() const
186 {
187 return isExport;
188 }
189 void ThisIsSystemProc(){
190 isSystem = true;
191 }
192 bool IsSystem() const
193 {
194 return isSystem;
195 }
196 void ThisIsAutoGenerationProc(){
197 isAutoGeneration = true;
198 }
199 bool IsAutoGeneration(){
200 return isAutoGeneration;
201 }
202 void CompleteCompile(){
203 isCompiled = true;
204 }
205 void KillCompileStatus(){
206 isCompiled = false;
207 }
208 bool IsCompiled() const
209 {
210 return isCompiled;
211 }
212 bool IsDestructor() const
213 {
214 return ( GetName()[0] == '~' );
215 }
216 bool IsVirtual() const;
217
218 // バイナリコードの位置
219 DWORD beginOpAddress;
220 DWORD endOpAddress;
221 int GetCodeSize() const
222 {
223 return endOpAddress - beginOpAddress;
224 }
225
226 virtual const NamespaceScopes &GetNamespaceScopes() const;
227 virtual const NamespaceScopesCollection &GetImportedNamespaces() const;
228 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
229
230 // ローカル変数
231 Variables localVars;
232
233 // TODO: 適切なコードへ直す
234 long id;
235
236
237 /////////////////////////////////////////////////////////////////
238 // コンパイル中の関数を管理
239 /////////////////////////////////////////////////////////////////
240private:
241 static UserProc *pCompilingUserProc;
242public:
243 static void CompileStartForGlobalArea(){
244 pCompilingUserProc = NULL;
245 }
246 static void CompileStartForUserProc( UserProc *pUserProc ){
247 pCompilingUserProc = pUserProc;
248 }
249 static bool IsGlobalAreaCompiling(){
250 return ( pCompilingUserProc == NULL );
251 }
252 static bool IsLocalAreaCompiling(){
253 return ( pCompilingUserProc != NULL );
254 }
255 static UserProc &CompilingUserProc(){
256 return *pCompilingUserProc;
257 }
258};
259
260class DllProc : public Procedure
261{
262 const NamespaceScopes namespaceScopes;
263
264 const string dllFileName;
265 const string alias;
266 int lookupAddress;
267
268public:
269 // ハッシュリスト用
270 DllProc *pNextData;
271
272 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
273 Procedure( name, kind, isCdecl ),
274 namespaceScopes( namespaceScopes ),
275 dllFileName( dllFileName ),
276 alias( alias ),
277 lookupAddress( 0 ),
278 pNextData( NULL )
279 {
280 }
281 ~DllProc(){}
282
283 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const = 0;
284 bool IsEqualSymbol( const string &name ) const;
285
286 const NamespaceScopes &GetNamespaceScopes() const
287 {
288 return namespaceScopes;
289 }
290
291 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine ) = 0;
292
293 const string &GetDllFileName() const
294 {
295 return dllFileName;
296 }
297 const string &GetAlias() const
298 {
299 return alias;
300 }
301
302 void SetLookupAddress( int lookupAddress ){
303 this->lookupAddress = lookupAddress;
304 }
305 int GetLookupAddress() const
306 {
307 return lookupAddress;
308 }
309
310};
311
312class ProcPointer : public Procedure
313{
314public:
315 ProcPointer( Kind kind ):
316 Procedure( "", kind, false )
317 {
318 }
319 ~ProcPointer(){}
320
321 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine ) = 0;
322};
323class ProcPointers : public vector<ProcPointer *>
324{
325public:
326 ProcPointers()
327 {
328 }
329 ~ProcPointers()
330 {
331 }
332
333 virtual int Add( const string &typeExpression ) = 0;
334};
Note: See TracBrowser for help on using the repository browser.