source: dev/trunk/abdev/BasicCompiler_Common/include/Procedure.h@ 404

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

ジェネリクスインターフェイス実装時のオーバーロード解決ロジックを改良。(型パラメータを戻り値に持つメソッドのオーバーロードをミスしてしまうバグを修正)

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