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

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