source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/Procedure.h@ 639

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

静的リンクリンカの依存関係解決モジュールを製作中

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