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

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

Throw→Catch間のパラメータ引渡しに対応。
グローバル領域でのTryスコープを可能にした。これで例外処理機構実装完了。
エディタの補間機能にTry/Catch/Finally/EndTryを追加。

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 const UserProc *pGlobalProc;
385 static void CompileStartForGlobalArea(){
386 pCompilingUserProc = NULL;
387 }
388 static void CompileStartForUserProc( const UserProc *pUserProc ){
389 pCompilingUserProc = pUserProc;
390 }
391 static bool IsGlobalAreaCompiling(){
392 return ( pCompilingUserProc == NULL );
393 }
394 static bool IsLocalAreaCompiling(){
395 return ( pCompilingUserProc != NULL );
396 }
397 static const UserProc &CompilingUserProc(){
398 return *pCompilingUserProc;
399 }
400};
401
402class UserProcs : public Jenga::Common::Hashmap<UserProc>
403{
404 std::vector<std::string> macroNames;
405
406 // XMLシリアライズ用
407private:
408 friend class boost::serialization::access;
409 template<class Archive> void serialize(Archive& ar, const unsigned int version)
410 {
411 trace_for_serialize( "serializing - UserProcs" );
412
413 ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
414 boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
415 ar & BOOST_SERIALIZATION_NVP( macroNames );
416 }
417
418
419public:
420 UserProcs()
421 {
422 }
423 ~UserProcs()
424 {
425 }
426
427 bool Insert( UserProc *pUserProc, int nowLine );
428
429 UserProc *AddUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName = NULL );
430
431 void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
432};
433
434class DllProc : public Procedure, public Jenga::Common::ObjectInHashmap<DllProc>
435{
436 string dllFileName;
437 string alias;
438 int lookupAddress;
439
440 // XMLシリアライズ用
441private:
442 friend class boost::serialization::access;
443 template<class Archive> void serialize(Archive& ar, const unsigned int version)
444 {
445 trace_for_serialize( "serializing - DllProc" );
446
447 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
448 ar & BOOST_SERIALIZATION_NVP( dllFileName );
449 ar & BOOST_SERIALIZATION_NVP( alias );
450 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
451 }
452
453public:
454 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias )
455 : Procedure( namespaceScopes, name, 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 string &GetDllFileName() const
484 {
485 return dllFileName;
486 }
487 const 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 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
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
515public:
516 void Add(const NamespaceScopes &namespaceScopes, char *buffer,int nowLine);
517};
518
519void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs );
520
521class ProcPointer : public Procedure
522{
523 // XMLシリアライズ用
524private:
525 friend class boost::serialization::access;
526 template<class Archive> void serialize(Archive& ar, const unsigned int version)
527 {
528 trace_for_serialize( "serializing - ProcPointer" );
529
530 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
531 }
532
533public:
534 ProcPointer( Kind kind )
535 : Procedure( NamespaceScopes(), std::string(), kind, false )
536 {
537 }
538 ProcPointer()
539 {
540 }
541 ~ProcPointer(){}
542
543 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
544};
545
546class ProcPointers : public vector<ProcPointer *>
547{
548 // XMLシリアライズ用
549private:
550 friend class boost::serialization::access;
551 template<class Archive> void serialize(Archive& ar, const unsigned int version)
552 {
553 trace_for_serialize( "serializing - ProcPointers" );
554
555 ar & boost::serialization::make_nvp("vector_ProcPointer",
556 boost::serialization::base_object<vector<ProcPointer *>>(*this));
557 }
558
559public:
560 ProcPointers()
561 {
562 }
563 ~ProcPointers()
564 {
565 Clear();
566 }
567
568 int Add( const string &typeExpression );
569 void Clear();
570 void PullOutAll()
571 {
572 clear();
573 }
574};
Note: See TracBrowser for help on using the repository browser.