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

Last change on this file since 258 was 257, checked in by dai_9181, 17 years ago
File size: 11.8 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
379class UserProcs : public Jenga::Common::Hashmap<UserProc>
380{
381 std::vector<std::string> macroNames;
382
383 // XMLシリアライズ用
384private:
385 friend class boost::serialization::access;
386 template<class Archive> void serialize(Archive& ar, const unsigned int version)
387 {
388 trace_for_serialize( "serializing - UserProcs" );
389
390 ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
391 boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
392 ar & BOOST_SERIALIZATION_NVP( macroNames );
393 }
394
395
396public:
397 UserProcs()
398 {
399 }
400 ~UserProcs()
401 {
402 }
403
404 bool Insert( UserProc *pUserProc, int nowLine );
405
406 UserProc *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic);
407
408 void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
409};
410
411class DllProc : public Procedure, public Jenga::Common::ObjectInHashmap<DllProc>
412{
413 string dllFileName;
414 string alias;
415 int lookupAddress;
416
417 // XMLシリアライズ用
418private:
419 friend class boost::serialization::access;
420 template<class Archive> void serialize(Archive& ar, const unsigned int version)
421 {
422 trace_for_serialize( "serializing - DllProc" );
423
424 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
425 ar & BOOST_SERIALIZATION_NVP( dllFileName );
426 ar & BOOST_SERIALIZATION_NVP( alias );
427 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
428 }
429
430public:
431 // ハッシュリスト用
432 DllProc *pNextData;
433
434 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias )
435 : Procedure( namespaceScopes, name, kind, isCdecl )
436 , dllFileName( dllFileName )
437 , alias( alias )
438 , lookupAddress( 0 )
439 , pNextData( NULL )
440 {
441 }
442 DllProc()
443 {
444 }
445 ~DllProc()
446 {
447 }
448
449 virtual const std::string &GetKeyName() const
450 {
451 return GetName();
452 }
453
454 virtual bool IsDuplication( const DllProc *pDllProc ) const
455 {
456 if( pDllProc->IsEqualSymbol( *this )
457 && this->Params().Equals( pDllProc->Params() ) )
458 {
459 return true;
460 }
461 return false;
462 }
463
464 const string &GetDllFileName() const
465 {
466 return dllFileName;
467 }
468 const string &GetAlias() const
469 {
470 return alias;
471 }
472
473 void SetLookupAddress( int lookupAddress ){
474 this->lookupAddress = lookupAddress;
475 }
476 int GetLookupAddress() const
477 {
478 return lookupAddress;
479 }
480
481 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
482};
483class DllProcs : public Jenga::Common::Hashmap<DllProc>
484{
485 // XMLシリアライズ用
486private:
487 friend class boost::serialization::access;
488 template<class Archive> void serialize(Archive& ar, const unsigned int version)
489 {
490 trace_for_serialize( "serializing - DllProcs" );
491
492 ar & boost::serialization::make_nvp("Hashmap_DllProc",
493 boost::serialization::base_object<Jenga::Common::Hashmap<DllProc>>(*this));
494 }
495
496public:
497 void Add(const NamespaceScopes &namespaceScopes, char *buffer,int nowLine);
498};
499
500void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs );
501
502class ProcPointer : public Procedure
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 - ProcPointer" );
510
511 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
512 }
513
514public:
515 ProcPointer( Kind kind )
516 : Procedure( NamespaceScopes(), std::string(), kind, false )
517 {
518 }
519 ProcPointer()
520 {
521 }
522 ~ProcPointer(){}
523
524 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
525};
526
527class ProcPointers : public vector<ProcPointer *>
528{
529 // XMLシリアライズ用
530private:
531 friend class boost::serialization::access;
532 template<class Archive> void serialize(Archive& ar, const unsigned int version)
533 {
534 trace_for_serialize( "serializing - ProcPointers" );
535
536 ar & boost::serialization::make_nvp("vector_ProcPointer",
537 boost::serialization::base_object<vector<ProcPointer *>>(*this));
538 }
539
540public:
541 ProcPointers()
542 {
543 }
544 ~ProcPointers()
545 {
546 Clear();
547 }
548
549 virtual int Add( const string &typeExpression );
550 virtual void Clear();
551};
Note: See TracBrowser for help on using the repository browser.