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

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

ヘッダファイルを整理中

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