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

Last change on this file since 306 was 277, checked in by dai_9181, 17 years ago

DllProc::pNextDataを排除した

File size: 11.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 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 CMethod *pMethod;
125
126 bool isMacro;
127
128 // パラメータの追加情報
129 int secondParmNum;
130 Parameters realParams;
131 int realSecondParmNum;
132
133 // 各種フラグ
134 bool isExport;
135 mutable bool isSystem;
136 mutable bool isAutoGeneration;
137 mutable bool isCompiled;
138
139 mutable DWORD beginOpAddress;
140 mutable DWORD endOpAddress;
141
142 // ローカル変数
143 mutable Variables localVars;
144
145 // 識別ID
146 int id;
147
148 // ネイティブコード
149 NativeCode nativeCode;
150
151 // XMLシリアライズ用
152private:
153 friend class boost::serialization::access;
154 template<class Archive> void serialize(Archive& ar, const unsigned int version)
155 {
156 trace_for_serialize( "serializing - UserProc" );
157
158 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
159 ar & BOOST_SERIALIZATION_NVP( _paramStr );
160 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
161 ar & boost::serialization::make_nvp("pParentClass", const_cast<CClass *&>(pParentClass) );
162 ar & BOOST_SERIALIZATION_NVP( pMethod );
163 ar & BOOST_SERIALIZATION_NVP( isMacro );
164 ar & BOOST_SERIALIZATION_NVP( secondParmNum );
165 ar & BOOST_SERIALIZATION_NVP( realParams );
166 ar & BOOST_SERIALIZATION_NVP( realSecondParmNum );
167 ar & BOOST_SERIALIZATION_NVP( isExport );
168 ar & BOOST_SERIALIZATION_NVP( isSystem );
169 ar & BOOST_SERIALIZATION_NVP( isAutoGeneration );
170 ar & BOOST_SERIALIZATION_NVP( isCompiled );
171 ar & BOOST_SERIALIZATION_NVP( beginOpAddress );
172 ar & BOOST_SERIALIZATION_NVP( endOpAddress );
173 ar & BOOST_SERIALIZATION_NVP( localVars );
174 ar & BOOST_SERIALIZATION_NVP( id );
175 ar & BOOST_SERIALIZATION_NVP( nativeCode );
176 }
177
178public:
179
180 UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport, int id )
181 : Procedure( namespaceScopes, name, kind, isCdecl )
182 , importedNamespaces( importedNamespaces )
183 , pParentClass( NULL )
184 , pMethod( NULL )
185 , isMacro( isMacro )
186 , isExport( isExport )
187 , isSystem( false )
188 , isAutoGeneration( false )
189 , isCompiled( false )
190 , beginOpAddress( 0 )
191 , endOpAddress( 0 )
192 , id( id )
193 {
194 }
195 UserProc()
196 {
197 }
198 ~UserProc()
199 {
200 BOOST_FOREACH( Parameter *pParam, realParams ){
201 delete pParam;
202 }
203 }
204
205 virtual const std::string &GetKeyName() const
206 {
207 return GetName();
208 }
209
210 virtual bool IsDuplication( const UserProc *pUserProc ) const
211 {
212 if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr()
213 && pUserProc->IsEqualSymbol( *this )
214 && this->Params().Equals( pUserProc->Params() ) )
215 {
216 return true;
217 }
218 return false;
219 }
220
221 bool IsMacro() const
222 {
223 return isMacro;
224 }
225
226 int GetSecondParmNum() const
227 {
228 return secondParmNum;
229 }
230 const Parameters &RealParams() const
231 {
232 return realParams;
233 }
234 int GetRealSecondParmNum() const
235 {
236 return realSecondParmNum;
237 }
238
239 void ExportOff(){
240 isExport = false;
241 }
242 bool IsExport() const
243 {
244 return isExport;
245 }
246 void ThisIsSystemProc() const
247 {
248 isSystem = true;
249 }
250 bool IsSystem() const
251 {
252 return isSystem;
253 }
254 void ThisIsAutoGenerationProc() const
255 {
256 isAutoGeneration = true;
257 }
258 bool IsAutoGeneration() const
259 {
260 return isAutoGeneration;
261 }
262 void CompleteCompile() const
263 {
264 isCompiled = true;
265 }
266 void KillCompileStatus() const
267 {
268 isCompiled = false;
269 }
270 bool IsCompiled() const
271 {
272 return isCompiled;
273 }
274 bool IsDestructor() const
275 {
276 return ( GetName()[0] == '~' );
277 }
278
279 // バイナリコード位置とサイズ
280 DWORD GetBeginOpAddress() const
281 {
282 return beginOpAddress;
283 }
284 void SetBeginOpAddress( DWORD beginOpAddress ) const
285 {
286 this->beginOpAddress = beginOpAddress;
287 }
288 DWORD GetEndOpAddress() const
289 {
290 return endOpAddress;
291 }
292 void SetEndOpAddress( DWORD endOpAddress ) const
293 {
294 this->endOpAddress = endOpAddress;
295 }
296 int GetCodeSize() const
297 {
298 return endOpAddress - beginOpAddress;
299 }
300
301 virtual const NamespaceScopes &GetNamespaceScopes() const;
302 const NamespaceScopesCollection &GetImportedNamespaces() const;
303
304 Variables &GetLocalVars() const
305 {
306 return localVars;
307 }
308
309 int GetId() const
310 {
311 return id;
312 }
313
314 const NativeCode &GetNativeCode() const
315 {
316 return nativeCode;
317 }
318 NativeCode &GetNativeCode()
319 {
320 return nativeCode;
321 }
322
323 std::string GetFullName() const;
324
325 bool IsVirtual() const;
326
327 void SetParentClass( const CClass *pParentClass ){
328 this->pParentClass = pParentClass;
329 }
330 const CClass *GetParentClassPtr() const
331 {
332 return pParentClass;
333 }
334 const CClass &GetParentClass() const
335 {
336 return *pParentClass;
337 }
338 bool HasParentClass() const
339 {
340 return ( pParentClass != NULL );
341 }
342 bool IsGlobalProcedure() const
343 {
344 return ( pParentClass == NULL );
345 }
346 void SetMethod( CMethod *pMethod ){
347 this->pMethod = pMethod;
348 }
349
350 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
351
352
353
354 /////////////////////////////////////////////////////////////////
355 // コンパイル中の関数を管理
356 /////////////////////////////////////////////////////////////////
357private:
358 static const UserProc *pCompilingUserProc;
359public:
360 static void CompileStartForGlobalArea(){
361 pCompilingUserProc = NULL;
362 }
363 static void CompileStartForUserProc( const UserProc *pUserProc ){
364 pCompilingUserProc = pUserProc;
365 }
366 static bool IsGlobalAreaCompiling(){
367 return ( pCompilingUserProc == NULL );
368 }
369 static bool IsLocalAreaCompiling(){
370 return ( pCompilingUserProc != NULL );
371 }
372 static const UserProc &CompilingUserProc(){
373 return *pCompilingUserProc;
374 }
375};
376
377class UserProcs : public Jenga::Common::Hashmap<UserProc>
378{
379 std::vector<std::string> macroNames;
380
381 // XMLシリアライズ用
382private:
383 friend class boost::serialization::access;
384 template<class Archive> void serialize(Archive& ar, const unsigned int version)
385 {
386 trace_for_serialize( "serializing - UserProcs" );
387
388 ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
389 boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
390 ar & BOOST_SERIALIZATION_NVP( macroNames );
391 }
392
393
394public:
395 UserProcs()
396 {
397 }
398 ~UserProcs()
399 {
400 }
401
402 bool Insert( UserProc *pUserProc, int nowLine );
403
404 UserProc *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic);
405
406 void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
407};
408
409class DllProc : public Procedure, public Jenga::Common::ObjectInHashmap<DllProc>
410{
411 string dllFileName;
412 string alias;
413 int lookupAddress;
414
415 // XMLシリアライズ用
416private:
417 friend class boost::serialization::access;
418 template<class Archive> void serialize(Archive& ar, const unsigned int version)
419 {
420 trace_for_serialize( "serializing - DllProc" );
421
422 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
423 ar & BOOST_SERIALIZATION_NVP( dllFileName );
424 ar & BOOST_SERIALIZATION_NVP( alias );
425 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
426 }
427
428public:
429 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias )
430 : Procedure( namespaceScopes, name, kind, isCdecl )
431 , dllFileName( dllFileName )
432 , alias( alias )
433 , lookupAddress( 0 )
434 {
435 }
436 DllProc()
437 {
438 }
439 ~DllProc()
440 {
441 }
442
443 virtual const std::string &GetKeyName() const
444 {
445 return GetName();
446 }
447
448 virtual bool IsDuplication( const DllProc *pDllProc ) const
449 {
450 if( pDllProc->IsEqualSymbol( *this )
451 && this->Params().Equals( pDllProc->Params() ) )
452 {
453 return true;
454 }
455 return false;
456 }
457
458 const string &GetDllFileName() const
459 {
460 return dllFileName;
461 }
462 const string &GetAlias() const
463 {
464 return alias;
465 }
466
467 void SetLookupAddress( int lookupAddress ){
468 this->lookupAddress = lookupAddress;
469 }
470 int GetLookupAddress() const
471 {
472 return lookupAddress;
473 }
474
475 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
476};
477class DllProcs : public Jenga::Common::Hashmap<DllProc>
478{
479 // XMLシリアライズ用
480private:
481 friend class boost::serialization::access;
482 template<class Archive> void serialize(Archive& ar, const unsigned int version)
483 {
484 trace_for_serialize( "serializing - DllProcs" );
485
486 ar & boost::serialization::make_nvp("Hashmap_DllProc",
487 boost::serialization::base_object<Jenga::Common::Hashmap<DllProc>>(*this));
488 }
489
490public:
491 void Add(const NamespaceScopes &namespaceScopes, char *buffer,int nowLine);
492};
493
494void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs );
495
496class ProcPointer : public Procedure
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 - ProcPointer" );
504
505 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
506 }
507
508public:
509 ProcPointer( Kind kind )
510 : Procedure( NamespaceScopes(), std::string(), kind, false )
511 {
512 }
513 ProcPointer()
514 {
515 }
516 ~ProcPointer(){}
517
518 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
519};
520
521class ProcPointers : public vector<ProcPointer *>
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 - ProcPointers" );
529
530 ar & boost::serialization::make_nvp("vector_ProcPointer",
531 boost::serialization::base_object<vector<ProcPointer *>>(*this));
532 }
533
534public:
535 ProcPointers()
536 {
537 }
538 ~ProcPointers()
539 {
540 Clear();
541 }
542
543 int Add( const string &typeExpression );
544 void Clear();
545 void PullOutAll()
546 {
547 clear();
548 }
549};
Note: See TracBrowser for help on using the repository browser.