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

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

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

File size: 11.7 KB
Line 
1#pragma once
2
3class Procedure
4 : public RelationalObjectModuleItem
5{
6public:
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
22protected:
23
24 // 戻り値の型
25 Type returnType;
26
27private:
28 // ソースコードの位置
29 SourceCodePosition sourceCodePosition;
30
31 // XMLシリアライズ用
32private:
33 friend class boost::serialization::access;
34 template<class Archive> void serialize(Archive& ar, const unsigned int version)
35 {
36 trace_for_serialize( "serializing - Procedure" );
37
38 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( RelationalObjectModuleItem );
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 );
44 ar & BOOST_SERIALIZATION_NVP( sourceCodePosition );
45 }
46
47public:
48 Procedure( const Symbol &symbol, Kind kind, bool isCdecl )
49 : RelationalObjectModuleItem( symbol )
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
86 const SourceCodePosition &GetSourceCodePosition() const
87 {
88 return sourceCodePosition;
89 }
90 void SetSourceCodePosition( const SourceCodePosition &sourceCodePosition )
91 {
92 this->sourceCodePosition = sourceCodePosition;
93 }
94 virtual void ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable );
95
96 const Parameters &Params() const
97 {
98 return params;
99 }
100 Parameters &GetParameters()
101 {
102 return params;
103 }
104 const Type &ReturnType() const
105 {
106 return returnType;
107 }
108 Type &ReturnType()
109 {
110 return returnType;
111 }
112};
113
114class UserProc : public Procedure, public Jenga::Common::ObjectInHashmap<UserProc>
115{
116public:
117 std::string _paramStr;
118
119private:
120 NamespaceScopesCollection importedNamespaces;
121
122 // 親クラスと対応するメソッド
123 const CClass *pParentClass;
124 const Interface *pInterface;
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
149 // ネイティブコード
150 NativeCode nativeCode;
151
152 // XMLシリアライズ用
153private:
154 friend class boost::serialization::access;
155 template<class Archive> void serialize(Archive& ar, const unsigned int version)
156 {
157 trace_for_serialize( "serializing - UserProc" );
158
159 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
160
161 if( ActiveBasic::Common::Environment::IsRemoveExternal() )
162 {
163 if( this->IsExternal() )
164 {
165 this->NeedResolve();
166 return;
167 }
168 }
169
170 ar & BOOST_SERIALIZATION_NVP( _paramStr );
171 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
172 ar & boost::serialization::make_nvp("pParentClass", const_cast<CClass *&>(pParentClass) );
173 ar & boost::serialization::make_nvp("pInterface", const_cast<Interface *&>(pInterface) );
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 );
187 ar & BOOST_SERIALIZATION_NVP( nativeCode );
188 }
189
190public:
191
192 UserProc( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces, Kind kind, bool isMacro, bool isCdecl, bool isExport );
193 UserProc( const UserProc &userProc, const CClass *pParentClass );
194 UserProc();
195 ~UserProc();
196
197 void SetReturnType( const Type &newReturnType )
198 {
199 returnType = newReturnType;
200 }
201
202 virtual const std::string &GetKeyName() const
203 {
204 return GetName();
205 }
206
207 virtual bool IsDuplication( const UserProc *pUserProc ) const
208 {
209 if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr() // 親クラスが等しい
210 && this->pInterface == pUserProc->pInterface // インターフェイスが等しい
211 && pUserProc->IsEqualSymbol( *this ) // 名前空間及び名前が等しい
212 && this->Params().Equals( pUserProc->Params() ) // パラメータが等しい
213 && this->returnType.Equals( pUserProc->returnType ) ) // 戻り値が等しい
214 {
215 return true;
216 }
217 return false;
218 }
219
220 virtual void ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable );
221
222 /*!
223 @brief オーバーライド用に関数同士が等しいかどうかをチェックする
224 @param actualTypeParametersForThisProc thisオブジェクトで保有するメソッドを対象とした実型パラメータ
225 pUserProc 照らし合わせる関数
226 */
227 bool IsEqualForOverride( const Types &actualTypeParametersForThisProc, const UserProc *pUserProc ) const;
228
229 bool IsMacro() const
230 {
231 return isMacro;
232 }
233
234 int GetSecondParmNum() const
235 {
236 return secondParmNum;
237 }
238 void SetSecondParmNum( int secondParmNum )
239 {
240 this->secondParmNum = secondParmNum;
241 }
242 const Parameters &RealParams() const
243 {
244 return realParams;
245 }
246 Parameters &RealParams()
247 {
248 return realParams;
249 }
250 void SetRealParams( const Parameters &params )
251 {
252 realParams = params;
253 }
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
321 virtual const NamespaceScopes &GetNamespaceScopes() const;
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
334 const NativeCode &GetNativeCode() const
335 {
336 return nativeCode;
337 }
338 NativeCode &GetNativeCode()
339 {
340 return nativeCode;
341 }
342
343 std::string GetFullName() const;
344 bool IsCastOperator() const;
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 }
363 bool IsGlobalProcedure() const
364 {
365 return ( pParentClass == NULL );
366 }
367 void SetInterface( const Interface *pInterface )
368 {
369 this->pInterface = pInterface;
370 }
371 void SetMethod( CMethod *pMethod ){
372 this->pMethod = pMethod;
373 }
374 const CMethod &GetMethod() const;
375
376 virtual bool Resolve();
377
378 static const UserProc *pGlobalProc;
379};
380
381class UserProcs : public Jenga::Common::Hashmap<UserProc>
382{
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
395public:
396 UserProcs()
397 {
398 }
399 ~UserProcs()
400 {
401 }
402
403 void EnumGlobalProcs( const char *simpleName, const Symbol &localSymbol, std::vector<const UserProc *> &subs );
404};
405
406class DllProc
407 : public Procedure
408 , public Jenga::Common::ObjectInHashmap<DllProc>
409{
410 std::string dllFileName;
411 std::string alias;
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 );
422
423 if( ActiveBasic::Common::Environment::IsRemoveExternal() )
424 {
425 if( this->IsExternal() )
426 {
427 this->NeedResolve();
428 return;
429 }
430 }
431
432 ar & BOOST_SERIALIZATION_NVP( dllFileName );
433 ar & BOOST_SERIALIZATION_NVP( alias );
434 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
435 }
436
437public:
438 DllProc( const Symbol &symbol, Kind kind, bool isCdecl, const std::string &dllFileName, const std::string &alias )
439 : Procedure( symbol, kind, isCdecl )
440 , dllFileName( dllFileName )
441 , alias( alias )
442 , lookupAddress( 0 )
443 {
444 }
445 DllProc()
446 {
447 }
448 ~DllProc()
449 {
450 }
451
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
467 const std::string &GetDllFileName() const
468 {
469 return dllFileName;
470 }
471 const std::string &GetAlias() const
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 }
483
484 virtual bool Resolve();
485};
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" );
494
495 ar & boost::serialization::make_nvp("Hashmap_DllProc",
496 boost::serialization::base_object<Jenga::Common::Hashmap<DllProc>>(*this));
497 }
498};
499
500class ProcPointer
501 : public Procedure
502{
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
513public:
514 ProcPointer( Kind kind )
515 : Procedure( Symbol( NamespaceScopes(), std::string() ), kind, false )
516 {
517 }
518 ProcPointer()
519 {
520 }
521 ~ProcPointer()
522 {
523 }
524
525 virtual bool Resolve();
526};
527
528class ProcPointers : public std::vector<ProcPointer *>
529{
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
541public:
542 ProcPointers()
543 {
544 }
545 ~ProcPointers()
546 {
547 Clear();
548 }
549
550 void Clear();
551 void PullOutAll()
552 {
553 clear();
554 }
555};
Note: See TracBrowser for help on using the repository browser.