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

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

UserProc/DllProc/ProcPointerクラスをSymbolクラスからの派生にした

File size: 10.7 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 bool IsMacro() const
208 {
209 return isMacro;
210 }
211
212 int GetSecondParmNum() const
213 {
214 return secondParmNum;
215 }
216 const Parameters &RealParams() const
217 {
218 return realParams;
219 }
220 int GetRealSecondParmNum() const
221 {
222 return realSecondParmNum;
223 }
224
225 void ExportOff(){
226 isExport = false;
227 }
228 bool IsExport() const
229 {
230 return isExport;
231 }
232 void ThisIsSystemProc() const
233 {
234 isSystem = true;
235 }
236 bool IsSystem() const
237 {
238 return isSystem;
239 }
240 void ThisIsAutoGenerationProc() const
241 {
242 isAutoGeneration = true;
243 }
244 bool IsAutoGeneration() const
245 {
246 return isAutoGeneration;
247 }
248 void CompleteCompile() const
249 {
250 isCompiled = true;
251 }
252 void KillCompileStatus() const
253 {
254 isCompiled = false;
255 }
256 bool IsCompiled() const
257 {
258 return isCompiled;
259 }
260 bool IsDestructor() const
261 {
262 return ( GetName()[0] == '~' );
263 }
264
265 // バイナリコード位置とサイズ
266 DWORD GetBeginOpAddress() const
267 {
268 return beginOpAddress;
269 }
270 void SetBeginOpAddress( DWORD beginOpAddress ) const
271 {
272 this->beginOpAddress = beginOpAddress;
273 }
274 DWORD GetEndOpAddress() const
275 {
276 return endOpAddress;
277 }
278 void SetEndOpAddress( DWORD endOpAddress ) const
279 {
280 this->endOpAddress = endOpAddress;
281 }
282 int GetCodeSize() const
283 {
284 return endOpAddress - beginOpAddress;
285 }
286
287 virtual const NamespaceScopes &GetNamespaceScopes() const;
288 const NamespaceScopesCollection &GetImportedNamespaces() const;
289
290 Variables &GetLocalVars() const
291 {
292 return localVars;
293 }
294
295 int GetId() const
296 {
297 return id;
298 }
299
300 std::string GetFullName() const;
301
302 virtual bool IsDuplication( const UserProc *pUserProc ) const
303 {
304 if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr()
305 && pUserProc->IsEqualSymbol( *this )
306 && this->Params().Equals( pUserProc->Params() ) )
307 {
308 return true;
309 }
310 return false;
311 }
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 static void CollectUserProcs( const BasicSource &source, UserProcs &userProcs );
397};
398
399class DllProc : public Procedure
400{
401 string dllFileName;
402 string alias;
403 int lookupAddress;
404
405 // XMLシリアライズ用
406private:
407 friend class boost::serialization::access;
408 template<class Archive> void serialize(Archive& ar, const unsigned int version)
409 {
410 trace_for_serialize( "serializing - DllProc" );
411
412 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
413 ar & BOOST_SERIALIZATION_NVP( dllFileName );
414 ar & BOOST_SERIALIZATION_NVP( alias );
415 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
416 }
417
418public:
419 // ハッシュリスト用
420 DllProc *pNextData;
421
422 DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
423 Procedure( namespaceScopes, name, kind, isCdecl ),
424 dllFileName( dllFileName ),
425 alias( alias ),
426 lookupAddress( 0 ),
427 pNextData( NULL )
428 {
429 }
430 ~DllProc(){}
431
432 const string &GetDllFileName() const
433 {
434 return dllFileName;
435 }
436 const string &GetAlias() const
437 {
438 return alias;
439 }
440
441 void SetLookupAddress( int lookupAddress ){
442 this->lookupAddress = lookupAddress;
443 }
444 int GetLookupAddress() const
445 {
446 return lookupAddress;
447 }
448
449 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
450};
451
452class ProcPointer : public Procedure
453{
454 // XMLシリアライズ用
455private:
456 friend class boost::serialization::access;
457 template<class Archive> void serialize(Archive& ar, const unsigned int version)
458 {
459 trace_for_serialize( "serializing - ProcPointer" );
460
461 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
462 }
463
464public:
465 ProcPointer( Kind kind )
466 : Procedure( NamespaceScopes(), std::string(), kind, false )
467 {
468 }
469 ProcPointer()
470 {
471 }
472 ~ProcPointer(){}
473
474 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
475};
476
477class ProcPointers : public vector<ProcPointer *>
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 - ProcPointers" );
485
486 ar & boost::serialization::make_nvp("vector_ProcPointer",
487 boost::serialization::base_object<vector<ProcPointer *>>(*this));
488 }
489
490public:
491 ProcPointers()
492 {
493 }
494 ~ProcPointers()
495 {
496 Clear();
497 }
498
499 virtual int Add( const string &typeExpression );
500 virtual void Clear();
501};
Note: See TracBrowser for help on using the repository browser.