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

Last change on this file since 797 was 750, checked in by イグトランス (egtra), 16 years ago

BOOST_FOREACHを可能なものはVC++ 2005 for eachへ置換(やや速くなる)。

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