source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/Procedure.h@ 589

Last change on this file since 589 was 576, checked in by dai_9181, 17 years ago

EnumGlobalProcsメソッドの第二パラメータを "const char *" から "const Symbol &" に変更した。

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