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

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

インターフェイス実装周りの仕様整備

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