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

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

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

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