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

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