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

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

Procedureクラスインスタンスを対象としたLexicalAnalyzer::SetParamsAndReturnTypeメソッドを実装。

File size: 11.7 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 bool Insert( UserProc *pUserProc, int nowLine );
417
418 void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
419};
420
421class DllProc : public Procedure, public Jenga::Common::ObjectInHashmap<DllProc>
422{
423 std::string dllFileName;
424 std::string alias;
425 int lookupAddress;
426
427 // XMLシリアライズ用
428private:
429 friend class boost::serialization::access;
430 template<class Archive> void serialize(Archive& ar, const unsigned int version)
431 {
432 trace_for_serialize( "serializing - DllProc" );
433
434 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
435 ar & BOOST_SERIALIZATION_NVP( dllFileName );
436 ar & BOOST_SERIALIZATION_NVP( alias );
437 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
438 }
439
440public:
441 DllProc( const NamespaceScopes &namespaceScopes, const std::string &name, Kind kind, bool isCdecl, const std::string &dllFileName, const std::string &alias )
442 : Procedure( namespaceScopes, name, kind, isCdecl )
443 , dllFileName( dllFileName )
444 , alias( alias )
445 , lookupAddress( 0 )
446 {
447 }
448 DllProc()
449 {
450 }
451 ~DllProc()
452 {
453 }
454
455 virtual const std::string &GetKeyName() const
456 {
457 return GetName();
458 }
459
460 virtual bool IsDuplication( const DllProc *pDllProc ) const
461 {
462 if( pDllProc->IsEqualSymbol( *this )
463 && this->Params().Equals( pDllProc->Params() ) )
464 {
465 return true;
466 }
467 return false;
468 }
469
470 const std::string &GetDllFileName() const
471 {
472 return dllFileName;
473 }
474 const std::string &GetAlias() const
475 {
476 return alias;
477 }
478
479 void SetLookupAddress( int lookupAddress ){
480 this->lookupAddress = lookupAddress;
481 }
482 int GetLookupAddress() const
483 {
484 return lookupAddress;
485 }
486};
487class DllProcs : public Jenga::Common::Hashmap<DllProc>
488{
489 // XMLシリアライズ用
490private:
491 friend class boost::serialization::access;
492 template<class Archive> void serialize(Archive& ar, const unsigned int version)
493 {
494 trace_for_serialize( "serializing - DllProcs" );
495
496 ar & boost::serialization::make_nvp("Hashmap_DllProc",
497 boost::serialization::base_object<Jenga::Common::Hashmap<DllProc>>(*this));
498 }
499};
500
501class ProcPointer : 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( NamespaceScopes(), std::string(), kind, false )
516 {
517 }
518 ProcPointer()
519 {
520 }
521 ~ProcPointer(){}
522};
523
524class ProcPointers : public std::vector<ProcPointer *>
525{
526 // XMLシリアライズ用
527private:
528 friend class boost::serialization::access;
529 template<class Archive> void serialize(Archive& ar, const unsigned int version)
530 {
531 trace_for_serialize( "serializing - ProcPointers" );
532
533 ar & boost::serialization::make_nvp("vector_ProcPointer",
534 boost::serialization::base_object<vector<ProcPointer *>>(*this));
535 }
536
537public:
538 ProcPointers()
539 {
540 }
541 ~ProcPointers()
542 {
543 Clear();
544 }
545
546 int Add( const std::string &typeExpression );
547 void Clear();
548 void PullOutAll()
549 {
550 clear();
551 }
552};
Note: See TracBrowser for help on using the repository browser.