source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/Procedure.h@ 524

Last change on this file since 524 was 524, checked in by dai_9181, 16 years ago

ヘッダファイルを整理中

File size: 12.3 KB
Line 
1#pragma once
2
3class CClass;
4class Interface;
5class CMethod;
6
7class Procedure : public Symbol
8{
9public:
10 // 種類
11 enum Kind{
12 Sub,
13 Function,
14 };
15
16private:
17 Kind kind;
18
19 bool isCdecl;
20 mutable bool isUsing;
21
22protected:
23
24 // パラメータ
25 Parameters params;
26
27 // 戻り値の型
28 Type returnType;
29
30 // ソースコードの位置
31 int codePos;
32
33 // XMLシリアライズ用
34private:
35 friend class boost::serialization::access;
36 template<class Archive> void serialize(Archive& ar, const unsigned int version)
37 {
38 trace_for_serialize( "serializing - Procedure" );
39
40 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Symbol );
41 ar & BOOST_SERIALIZATION_NVP( kind );
42 ar & BOOST_SERIALIZATION_NVP( isCdecl );
43 ar & BOOST_SERIALIZATION_NVP( isUsing );
44 ar & BOOST_SERIALIZATION_NVP( params );
45 ar & BOOST_SERIALIZATION_NVP( returnType );
46 ar & BOOST_SERIALIZATION_NVP( codePos );
47 }
48
49public:
50 Procedure( const NamespaceScopes &namespaceScopes, const std::string &name, Kind kind, bool isCdecl )
51 : Symbol( namespaceScopes, name )
52 , kind( kind )
53 , isCdecl( isCdecl )
54 , isUsing( false )
55 , codePos( -1 )
56 {
57 }
58 Procedure()
59 {
60 }
61 ~Procedure(){
62 BOOST_FOREACH( Parameter *pParam, params ){
63 delete pParam;
64 }
65 }
66
67 bool IsSub() const
68 {
69 return ( kind == Sub );
70 }
71 bool IsFunction() const
72 {
73 return ( kind == Function );
74 }
75
76 bool IsCdecl() const
77 {
78 return isCdecl;
79 }
80 void Using() const
81 {
82 isUsing = true;
83 }
84 bool IsUsing() const
85 {
86 return isUsing;
87 }
88
89 int GetCodePos() const
90 {
91 return codePos;
92 }
93
94 const Parameters &Params() const
95 {
96 return params;
97 }
98 const Type &ReturnType() const
99 {
100 return returnType;
101 }
102};
103
104class UserProc : public Procedure, public Jenga::Common::ObjectInHashmap<UserProc>
105{
106public:
107 std::string _paramStr;
108
109private:
110 NamespaceScopesCollection importedNamespaces;
111
112 // 親クラスと対応するメソッド
113 const CClass *pParentClass;
114 const Interface *pInterface;
115 CMethod *pMethod;
116
117 bool isMacro;
118
119 // パラメータの追加情報
120 int secondParmNum;
121 Parameters realParams;
122 int realSecondParmNum;
123
124 // 各種フラグ
125 bool isExport;
126 mutable bool isSystem;
127 mutable bool isAutoGeneration;
128 mutable bool isCompiled;
129
130 mutable DWORD beginOpAddress;
131 mutable DWORD endOpAddress;
132
133 // ローカル変数
134 mutable Variables localVars;
135
136 // 識別ID
137 int id;
138
139 // ネイティブコード
140 NativeCode nativeCode;
141
142 // XMLシリアライズ用
143private:
144 friend class boost::serialization::access;
145 template<class Archive> void serialize(Archive& ar, const unsigned int version)
146 {
147 trace_for_serialize( "serializing - UserProc" );
148
149 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
150 ar & BOOST_SERIALIZATION_NVP( _paramStr );
151 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
152 ar & boost::serialization::make_nvp("pParentClass", const_cast<CClass *&>(pParentClass) );
153 ar & boost::serialization::make_nvp("pInterface", const_cast<Interface *&>(pInterface) );
154 ar & BOOST_SERIALIZATION_NVP( pMethod );
155 ar & BOOST_SERIALIZATION_NVP( isMacro );
156 ar & BOOST_SERIALIZATION_NVP( secondParmNum );
157 ar & BOOST_SERIALIZATION_NVP( realParams );
158 ar & BOOST_SERIALIZATION_NVP( realSecondParmNum );
159 ar & BOOST_SERIALIZATION_NVP( isExport );
160 ar & BOOST_SERIALIZATION_NVP( isSystem );
161 ar & BOOST_SERIALIZATION_NVP( isAutoGeneration );
162 ar & BOOST_SERIALIZATION_NVP( isCompiled );
163 ar & BOOST_SERIALIZATION_NVP( beginOpAddress );
164 ar & BOOST_SERIALIZATION_NVP( endOpAddress );
165 ar & BOOST_SERIALIZATION_NVP( localVars );
166 ar & BOOST_SERIALIZATION_NVP( id );
167 ar & BOOST_SERIALIZATION_NVP( nativeCode );
168 }
169
170public:
171
172 UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const std::string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport )
173 : Procedure( namespaceScopes, name, kind, isCdecl )
174 , importedNamespaces( importedNamespaces )
175 , pParentClass( NULL )
176 , pInterface( NULL )
177 , pMethod( NULL )
178 , isMacro( isMacro )
179 , secondParmNum( 0 )
180 , realSecondParmNum( 1 )
181 , isExport( isExport )
182 , isSystem( false )
183 , isAutoGeneration( false )
184 , isCompiled( false )
185 , beginOpAddress( 0 )
186 , endOpAddress( 0 )
187 {
188 static int id_base=0;
189 id = ( id_base ++ );
190 }
191 UserProc()
192 {
193 }
194 ~UserProc()
195 {
196 BOOST_FOREACH( Parameter *pParam, realParams ){
197 delete pParam;
198 }
199 }
200
201 void SetReturnType( const Type &newReturnType )
202 {
203 returnType = newReturnType;
204 }
205
206 virtual const std::string &GetKeyName() const
207 {
208 return GetName();
209 }
210
211 virtual bool IsDuplication( const UserProc *pUserProc ) const
212 {
213 if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr() // 親クラスが等しい
214 && this->pInterface == pUserProc->pInterface // インターフェイスが等しい
215 && pUserProc->IsEqualSymbol( *this ) // 名前空間及び名前が等しい
216 && this->Params().Equals( pUserProc->Params() ) // パラメータが等しい
217 && this->returnType.Equals( pUserProc->returnType ) ) // 戻り値が等しい
218 {
219 return true;
220 }
221 return false;
222 }
223
224 /*!
225 @brief オーバーライド用に関数同士が等しいかどうかをチェックする
226 @param actualTypeParametersForThisProc thisオブジェクトで保有するメソッドを対象とした実型パラメータ
227 pUserProc 照らし合わせる関数
228 */
229 bool IsEqualForOverride( const Types &actualTypeParametersForThisProc, const UserProc *pUserProc ) const;
230
231 bool IsMacro() const
232 {
233 return isMacro;
234 }
235
236 int GetSecondParmNum() const
237 {
238 return secondParmNum;
239 }
240 const Parameters &RealParams() const
241 {
242 return realParams;
243 }
244 void SetRealParams( const Parameters &params )
245 {
246 realParams = params;
247 }
248 int GetRealSecondParmNum() const
249 {
250 return realSecondParmNum;
251 }
252
253 void ExportOff(){
254 isExport = false;
255 }
256 bool IsExport() const
257 {
258 return isExport;
259 }
260 void ThisIsSystemProc() const
261 {
262 isSystem = true;
263 }
264 bool IsSystem() const
265 {
266 return isSystem;
267 }
268 void ThisIsAutoGenerationProc() const
269 {
270 isAutoGeneration = true;
271 }
272 bool IsAutoGeneration() const
273 {
274 return isAutoGeneration;
275 }
276 void CompleteCompile() const
277 {
278 isCompiled = true;
279 }
280 void KillCompileStatus() const
281 {
282 isCompiled = false;
283 }
284 bool IsCompiled() const
285 {
286 return isCompiled;
287 }
288 bool IsDestructor() const
289 {
290 return ( GetName()[0] == '~' );
291 }
292
293 // バイナリコード位置とサイズ
294 DWORD GetBeginOpAddress() const
295 {
296 return beginOpAddress;
297 }
298 void SetBeginOpAddress( DWORD beginOpAddress ) const
299 {
300 this->beginOpAddress = beginOpAddress;
301 }
302 DWORD GetEndOpAddress() const
303 {
304 return endOpAddress;
305 }
306 void SetEndOpAddress( DWORD endOpAddress ) const
307 {
308 this->endOpAddress = endOpAddress;
309 }
310 int GetCodeSize() const
311 {
312 return endOpAddress - beginOpAddress;
313 }
314
315 virtual const NamespaceScopes &GetNamespaceScopes() const;
316 const NamespaceScopesCollection &GetImportedNamespaces() const;
317
318 Variables &GetLocalVars() const
319 {
320 return localVars;
321 }
322
323 int GetId() const
324 {
325 return id;
326 }
327
328 const NativeCode &GetNativeCode() const
329 {
330 return nativeCode;
331 }
332 NativeCode &GetNativeCode()
333 {
334 return nativeCode;
335 }
336
337 std::string GetFullName() const;
338 bool IsCastOperator() const;
339
340 bool IsVirtual() const;
341
342 void SetParentClass( const CClass *pParentClass ){
343 this->pParentClass = pParentClass;
344 }
345 const CClass *GetParentClassPtr() const
346 {
347 return pParentClass;
348 }
349 const CClass &GetParentClass() const
350 {
351 return *pParentClass;
352 }
353 bool HasParentClass() const
354 {
355 return ( pParentClass != NULL );
356 }
357 bool IsGlobalProcedure() const
358 {
359 return ( pParentClass == NULL );
360 }
361 void SetInterface( const Interface *pInterface )
362 {
363 this->pInterface = pInterface;
364 }
365 void SetMethod( CMethod *pMethod ){
366 this->pMethod = pMethod;
367 }
368 const CMethod &GetMethod() const;
369
370 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
371
372
373
374 /////////////////////////////////////////////////////////////////
375 // コンパイル中の関数を管理
376 /////////////////////////////////////////////////////////////////
377private:
378 static const UserProc *pCompilingUserProc;
379public:
380 static const UserProc *pGlobalProc;
381 static void CompileStartForGlobalArea(){
382 pCompilingUserProc = NULL;
383 }
384 static void CompileStartForUserProc( const UserProc *pUserProc ){
385 pCompilingUserProc = pUserProc;
386 }
387 static bool IsGlobalAreaCompiling(){
388 return ( pCompilingUserProc == NULL );
389 }
390 static bool IsLocalAreaCompiling(){
391 return ( pCompilingUserProc != NULL );
392 }
393 static const UserProc &CompilingUserProc(){
394 return *pCompilingUserProc;
395 }
396};
397
398class UserProcs : public Jenga::Common::Hashmap<UserProc>
399{
400 // XMLシリアライズ用
401private:
402 friend class boost::serialization::access;
403 template<class Archive> void serialize(Archive& ar, const unsigned int version)
404 {
405 trace_for_serialize( "serializing - UserProcs" );
406
407 ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
408 boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
409 }
410
411
412public:
413 UserProcs()
414 {
415 }
416 ~UserProcs()
417 {
418 }
419
420 bool Insert( UserProc *pUserProc, int nowLine );
421
422 void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
423};
424
425class DllProc : public Procedure, public Jenga::Common::ObjectInHashmap<DllProc>
426{
427 std::string dllFileName;
428 std::string alias;
429 int lookupAddress;
430
431 // XMLシリアライズ用
432private:
433 friend class boost::serialization::access;
434 template<class Archive> void serialize(Archive& ar, const unsigned int version)
435 {
436 trace_for_serialize( "serializing - DllProc" );
437
438 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
439 ar & BOOST_SERIALIZATION_NVP( dllFileName );
440 ar & BOOST_SERIALIZATION_NVP( alias );
441 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
442 }
443
444public:
445 DllProc( const NamespaceScopes &namespaceScopes, const std::string &name, Kind kind, bool isCdecl, const std::string &dllFileName, const std::string &alias )
446 : Procedure( namespaceScopes, name, kind, isCdecl )
447 , dllFileName( dllFileName )
448 , alias( alias )
449 , lookupAddress( 0 )
450 {
451 }
452 DllProc()
453 {
454 }
455 ~DllProc()
456 {
457 }
458
459 virtual const std::string &GetKeyName() const
460 {
461 return GetName();
462 }
463
464 virtual bool IsDuplication( const DllProc *pDllProc ) const
465 {
466 if( pDllProc->IsEqualSymbol( *this )
467 && this->Params().Equals( pDllProc->Params() ) )
468 {
469 return true;
470 }
471 return false;
472 }
473
474 const std::string &GetDllFileName() const
475 {
476 return dllFileName;
477 }
478 const std::string &GetAlias() const
479 {
480 return alias;
481 }
482
483 void SetLookupAddress( int lookupAddress ){
484 this->lookupAddress = lookupAddress;
485 }
486 int GetLookupAddress() const
487 {
488 return lookupAddress;
489 }
490
491 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
492};
493class DllProcs : public Jenga::Common::Hashmap<DllProc>
494{
495 // XMLシリアライズ用
496private:
497 friend class boost::serialization::access;
498 template<class Archive> void serialize(Archive& ar, const unsigned int version)
499 {
500 trace_for_serialize( "serializing - DllProcs" );
501
502 ar & boost::serialization::make_nvp("Hashmap_DllProc",
503 boost::serialization::base_object<Jenga::Common::Hashmap<DllProc>>(*this));
504 }
505
506public:
507 void Add(const NamespaceScopes &namespaceScopes, char *buffer,int nowLine);
508};
509
510class ProcPointer : public Procedure
511{
512 // XMLシリアライズ用
513private:
514 friend class boost::serialization::access;
515 template<class Archive> void serialize(Archive& ar, const unsigned int version)
516 {
517 trace_for_serialize( "serializing - ProcPointer" );
518
519 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
520 }
521
522public:
523 ProcPointer( Kind kind )
524 : Procedure( NamespaceScopes(), std::string(), kind, false )
525 {
526 }
527 ProcPointer()
528 {
529 }
530 ~ProcPointer(){}
531
532 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
533};
534
535class ProcPointers : public std::vector<ProcPointer *>
536{
537 // XMLシリアライズ用
538private:
539 friend class boost::serialization::access;
540 template<class Archive> void serialize(Archive& ar, const unsigned int version)
541 {
542 trace_for_serialize( "serializing - ProcPointers" );
543
544 ar & boost::serialization::make_nvp("vector_ProcPointer",
545 boost::serialization::base_object<vector<ProcPointer *>>(*this));
546 }
547
548public:
549 ProcPointers()
550 {
551 }
552 ~ProcPointers()
553 {
554 Clear();
555 }
556
557 int Add( const std::string &typeExpression );
558 void Clear();
559 void PullOutAll()
560 {
561 clear();
562 }
563};
Note: See TracBrowser for help on using the repository browser.