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

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

jengaライブラリに一通りserializeメソッドを仕込んだ

File size: 8.1 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 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
36 // XMLシリアライズ用
37private:
38 friend class boost::serialization::access;
39 template<class Archive> void serialize(Archive& ar, const unsigned int version)
40 {
41 ar & BOOST_SERIALIZATION_NVP( name );
42 ar & BOOST_SERIALIZATION_NVP( kind );
43 ar & BOOST_SERIALIZATION_NVP( isCdecl );
44 ar & BOOST_SERIALIZATION_NVP( isUsing );
45 ar & BOOST_SERIALIZATION_NVP( params );
46 ar & BOOST_SERIALIZATION_NVP( returnType );
47 ar & BOOST_SERIALIZATION_NVP( codePos );
48 }
49
50public:
51 Procedure( const string &name, Kind kind, bool isCdecl ):
52 name( name ),
53 kind( kind ),
54 isCdecl( isCdecl ),
55 isUsing( false ),
56 codePos( -1 )
57 {}
58 ~Procedure(){
59 BOOST_FOREACH( Parameter *pParam, params ){
60 delete pParam;
61 }
62 }
63
64 const string &GetName() const
65 {
66 return name;
67 }
68
69 bool IsSub() const
70 {
71 return ( kind == Sub );
72 }
73 bool IsFunction() const
74 {
75 return ( kind == Function );
76 }
77
78 bool IsCdecl() const
79 {
80 return isCdecl;
81 }
82 void Using(){
83 isUsing = true;
84 }
85 bool IsUsing() const
86 {
87 return isUsing;
88 }
89
90 int GetCodePos() const
91 {
92 return codePos;
93 }
94
95 const Parameters &Params() const
96 {
97 return params;
98 }
99 const Type &ReturnType() const
100 {
101 return returnType;
102 }
103};
104
105class UserProc : public Procedure
106{
107public:
108 string _paramStr;
109
110protected:
111 bool isMacro;
112
113 // パラメータの追加情報
114 int secondParmNum;
115 Parameters realParams;
116 int realSecondParmNum;
117
118 // 親クラスと対応するメソッド
119 const CClass *pParentClass;
120 CMethod *pMethod;
121
122 // 各種フラグ
123 bool isExport;
124 bool isSystem;
125 bool isAutoGeneration;
126 bool isCompiled;
127
128 // XMLシリアライズ用
129 // TODO: xml実装(publicなクラスが残っている)
130private:
131 friend class boost::serialization::access;
132 template<class Archive> void serialize(Archive& ar, const unsigned int version)
133 {
134 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
135 ar & BOOST_SERIALIZATION_NVP( _paramStr );
136 ar & BOOST_SERIALIZATION_NVP( secondParmNum );
137 ar & BOOST_SERIALIZATION_NVP( realParams );
138 ar & BOOST_SERIALIZATION_NVP( realSecondParmNum );
139 ar & BOOST_SERIALIZATION_NVP( pParentClass );
140 ar & BOOST_SERIALIZATION_NVP( pMethod );
141 ar & BOOST_SERIALIZATION_NVP( isExport );
142 ar & BOOST_SERIALIZATION_NVP( isSystem );
143 ar & BOOST_SERIALIZATION_NVP( isAutoGeneration );
144 ar & BOOST_SERIALIZATION_NVP( isCompiled );
145 }
146
147public:
148
149 UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
150 Procedure( name, kind, isCdecl ),
151 isMacro( isMacro ),
152 pParentClass( NULL ),
153 pMethod( NULL ),
154 isExport( isExport ),
155 isSystem( false ),
156 isAutoGeneration( false ),
157 isCompiled( false ),
158 beginOpAddress( 0 ),
159 endOpAddress( 0 )
160 {
161 }
162 ~UserProc()
163 {
164 BOOST_FOREACH( Parameter *pParam, realParams ){
165 delete pParam;
166 }
167 }
168
169 string GetFullName() const;
170
171 bool IsMacro() const
172 {
173 return isMacro;
174 }
175
176 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic ) = 0;
177
178 int GetSecondParmNum() const
179 {
180 return secondParmNum;
181 }
182 const Parameters &RealParams() const
183 {
184 return realParams;
185 }
186 int GetRealSecondParmNum() const
187 {
188 return realSecondParmNum;
189 }
190
191 void SetParentClass( const CClass *pParentClass ){
192 this->pParentClass = pParentClass;
193 }
194 const CClass *GetParentClassPtr() const
195 {
196 return pParentClass;
197 }
198 const CClass &GetParentClass() const
199 {
200 return *pParentClass;
201 }
202 bool HasParentClass() const
203 {
204 return ( pParentClass != NULL );
205 }
206 void SetMethod( CMethod *pMethod ){
207 this->pMethod = pMethod;
208 }
209
210 void ExportOff(){
211 isExport = false;
212 }
213 bool IsExport() const
214 {
215 return isExport;
216 }
217 void ThisIsSystemProc(){
218 isSystem = true;
219 }
220 bool IsSystem() const
221 {
222 return isSystem;
223 }
224 void ThisIsAutoGenerationProc(){
225 isAutoGeneration = true;
226 }
227 bool IsAutoGeneration(){
228 return isAutoGeneration;
229 }
230 void CompleteCompile(){
231 isCompiled = true;
232 }
233 void KillCompileStatus(){
234 isCompiled = false;
235 }
236 bool IsCompiled() const
237 {
238 return isCompiled;
239 }
240 bool IsDestructor() const
241 {
242 return ( GetName()[0] == '~' );
243 }
244 bool IsVirtual() const;
245
246 // バイナリコードの位置
247 DWORD beginOpAddress;
248 DWORD endOpAddress;
249 int GetCodeSize() const
250 {
251 return endOpAddress - beginOpAddress;
252 }
253
254 virtual const NamespaceScopes &GetNamespaceScopes() const;
255 virtual const NamespaceScopesCollection &GetImportedNamespaces() const;
256 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
257
258 // ローカル変数
259 Variables localVars;
260
261 // TODO: 適切なコードへ直す
262 long id;
263
264
265 /////////////////////////////////////////////////////////////////
266 // コンパイル中の関数を管理
267 /////////////////////////////////////////////////////////////////
268private:
269 static UserProc *pCompilingUserProc;
270public:
271 static void CompileStartForGlobalArea(){
272 pCompilingUserProc = NULL;
273 }
274 static void CompileStartForUserProc( UserProc *pUserProc ){
275 pCompilingUserProc = pUserProc;
276 }
277 static bool IsGlobalAreaCompiling(){
278 return ( pCompilingUserProc == NULL );
279 }
280 static bool IsLocalAreaCompiling(){
281 return ( pCompilingUserProc != NULL );
282 }
283 static UserProc &CompilingUserProc(){
284 return *pCompilingUserProc;
285 }
286};
287
288class DllProc : public Procedure
289{
290 NamespaceScopes namespaceScopes;
291
292 string dllFileName;
293 string alias;
294 int lookupAddress;
295
296 // XMLシリアライズ用
297private:
298 friend class boost::serialization::access;
299 template<class Archive> void serialize(Archive& ar, const unsigned int version)
300 {
301 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
302 ar & BOOST_SERIALIZATION_NVP( namespaceScopes );
303 ar & BOOST_SERIALIZATION_NVP( dllFileName );
304 ar & BOOST_SERIALIZATION_NVP( alias );
305 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
306 }
307
308public:
309 // ハッシュリスト用
310 DllProc *pNextData;
311
312 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
313 Procedure( name, kind, isCdecl ),
314 namespaceScopes( namespaceScopes ),
315 dllFileName( dllFileName ),
316 alias( alias ),
317 lookupAddress( 0 ),
318 pNextData( NULL )
319 {
320 }
321 ~DllProc(){}
322
323 virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const = 0;
324 bool IsEqualSymbol( const string &name ) const;
325
326 const NamespaceScopes &GetNamespaceScopes() const
327 {
328 return namespaceScopes;
329 }
330
331 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine ) = 0;
332
333 const string &GetDllFileName() const
334 {
335 return dllFileName;
336 }
337 const string &GetAlias() const
338 {
339 return alias;
340 }
341
342 void SetLookupAddress( int lookupAddress ){
343 this->lookupAddress = lookupAddress;
344 }
345 int GetLookupAddress() const
346 {
347 return lookupAddress;
348 }
349
350};
351
352class ProcPointer : public Procedure
353{
354 // XMLシリアライズ用
355private:
356 friend class boost::serialization::access;
357 template<class Archive> void serialize(Archive& ar, const unsigned int version)
358 {
359 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
360 }
361
362public:
363 ProcPointer( Kind kind ):
364 Procedure( "", kind, false )
365 {
366 }
367 ~ProcPointer(){}
368
369 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine ) = 0;
370};
371class ProcPointers : public vector<ProcPointer *>
372{
373 // XMLシリアライズ用
374private:
375 friend class boost::serialization::access;
376 template<class Archive> void serialize(Archive& ar, const unsigned int version)
377 {
378 ar & boost::serialization::make_nvp("vector_ProcPointer", boost::serialization::base_object<vector<ProcPointer *>>(*this));
379 }
380
381public:
382 ProcPointers()
383 {
384 }
385 ~ProcPointers()
386 {
387 }
388
389 virtual int Add( const string &typeExpression ) = 0;
390};
Note: See TracBrowser for help on using the repository browser.