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

Last change on this file was 829, checked in by イグトランス (egtra), 12 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

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