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

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

EnumGlobalProcsメソッドの第二パラメータを "const char *" から "const Symbol &" に変更した。

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