source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/Procedure.h@ 572

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

ParseDllProc/SetParamsAndReturnTypeForUserProcを実装。

File size: 11.9 KB
Line 
1#pragma once
2
3class CClass;
4class Interface;
5class CMethod;
6
7class Procedure : public Symbol
8{
9public:
10 // 種類
11 enum Kind{
12 Sub,
13 Function,
14 };
15
16private:
17 Kind kind;
18
19 bool isCdecl;
20 mutable bool isUsing;
21
22 // パラメータ
23 Parameters params;
24
25protected:
26
27 // 戻り値の型
28 Type returnType;
29
30 // ソースコードの位置
31 int codePos;
32
33 // XMLシリアライズ用
34private:
35 friend class boost::serialization::access;
36 template<class Archive> void serialize(Archive& ar, const unsigned int version)
37 {
38 trace_for_serialize( "serializing - Procedure" );
39
40 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Symbol );
41 ar & BOOST_SERIALIZATION_NVP( kind );
42 ar & BOOST_SERIALIZATION_NVP( isCdecl );
43 ar & BOOST_SERIALIZATION_NVP( isUsing );
44 ar & BOOST_SERIALIZATION_NVP( params );
45 ar & BOOST_SERIALIZATION_NVP( returnType );
46 ar & BOOST_SERIALIZATION_NVP( codePos );
47 }
48
49public:
50 Procedure( const NamespaceScopes &namespaceScopes, const std::string &name, Kind kind, bool isCdecl )
51 : Symbol( namespaceScopes, name )
52 , kind( kind )
53 , isCdecl( isCdecl )
54 , isUsing( false )
55 , codePos( -1 )
56 {
57 }
58 Procedure()
59 {
60 }
61 ~Procedure(){
62 BOOST_FOREACH( Parameter *pParam, params ){
63 delete pParam;
64 }
65 }
66
67 bool IsSub() const
68 {
69 return ( kind == Sub );
70 }
71 bool IsFunction() const
72 {
73 return ( kind == Function );
74 }
75
76 bool IsCdecl() const
77 {
78 return isCdecl;
79 }
80 void Using() const
81 {
82 isUsing = true;
83 }
84 bool IsUsing() const
85 {
86 return isUsing;
87 }
88
89 int GetCodePos() const
90 {
91 return codePos;
92 }
93 void SetCodePos( int codePos )
94 {
95 this->codePos = codePos;
96 }
97
98 const Parameters &Params() const
99 {
100 return params;
101 }
102 Parameters &GetParameters()
103 {
104 return params;
105 }
106 const Type &ReturnType() const
107 {
108 return returnType;
109 }
110 Type &ReturnType()
111 {
112 return returnType;
113 }
114};
115
116class UserProc : public Procedure, public Jenga::Common::ObjectInHashmap<UserProc>
117{
118public:
119 std::string _paramStr;
120
121private:
122 NamespaceScopesCollection importedNamespaces;
123
124 // 親クラスと対応するメソッド
125 const CClass *pParentClass;
126 const Interface *pInterface;
127 CMethod *pMethod;
128
129 bool isMacro;
130
131 // パラメータの追加情報
132 int secondParmNum;
133 Parameters realParams;
134 int realSecondParmNum;
135
136 // 各種フラグ
137 bool isExport;
138 mutable bool isSystem;
139 mutable bool isAutoGeneration;
140 mutable bool isCompiled;
141
142 mutable DWORD beginOpAddress;
143 mutable DWORD endOpAddress;
144
145 // ローカル変数
146 mutable Variables localVars;
147
148 // 識別ID
149 int id;
150
151 // ネイティブコード
152 NativeCode nativeCode;
153
154 // XMLシリアライズ用
155private:
156 friend class boost::serialization::access;
157 template<class Archive> void serialize(Archive& ar, const unsigned int version)
158 {
159 trace_for_serialize( "serializing - UserProc" );
160
161 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
162 ar & BOOST_SERIALIZATION_NVP( _paramStr );
163 ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
164 ar & boost::serialization::make_nvp("pParentClass", const_cast<CClass *&>(pParentClass) );
165 ar & boost::serialization::make_nvp("pInterface", const_cast<Interface *&>(pInterface) );
166 ar & BOOST_SERIALIZATION_NVP( pMethod );
167 ar & BOOST_SERIALIZATION_NVP( isMacro );
168 ar & BOOST_SERIALIZATION_NVP( secondParmNum );
169 ar & BOOST_SERIALIZATION_NVP( realParams );
170 ar & BOOST_SERIALIZATION_NVP( realSecondParmNum );
171 ar & BOOST_SERIALIZATION_NVP( isExport );
172 ar & BOOST_SERIALIZATION_NVP( isSystem );
173 ar & BOOST_SERIALIZATION_NVP( isAutoGeneration );
174 ar & BOOST_SERIALIZATION_NVP( isCompiled );
175 ar & BOOST_SERIALIZATION_NVP( beginOpAddress );
176 ar & BOOST_SERIALIZATION_NVP( endOpAddress );
177 ar & BOOST_SERIALIZATION_NVP( localVars );
178 ar & BOOST_SERIALIZATION_NVP( id );
179 ar & BOOST_SERIALIZATION_NVP( nativeCode );
180 }
181
182public:
183
184 UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const std::string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport )
185 : Procedure( namespaceScopes, name, kind, isCdecl )
186 , importedNamespaces( importedNamespaces )
187 , pParentClass( NULL )
188 , pInterface( NULL )
189 , pMethod( NULL )
190 , isMacro( isMacro )
191 , secondParmNum( 0 )
192 , realSecondParmNum( 1 )
193 , isExport( isExport )
194 , isSystem( false )
195 , isAutoGeneration( false )
196 , isCompiled( false )
197 , beginOpAddress( 0 )
198 , endOpAddress( 0 )
199 {
200 static int id_base=0;
201 id = ( id_base ++ );
202 }
203 UserProc()
204 {
205 }
206 ~UserProc()
207 {
208 BOOST_FOREACH( Parameter *pParam, realParams ){
209 delete pParam;
210 }
211 }
212
213 void SetReturnType( const Type &newReturnType )
214 {
215 returnType = newReturnType;
216 }
217
218 virtual const std::string &GetKeyName() const
219 {
220 return GetName();
221 }
222
223 virtual bool IsDuplication( const UserProc *pUserProc ) const
224 {
225 if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr() // 親クラスが等しい
226 && this->pInterface == pUserProc->pInterface // インターフェイスが等しい
227 && pUserProc->IsEqualSymbol( *this ) // 名前空間及び名前が等しい
228 && this->Params().Equals( pUserProc->Params() ) // パラメータが等しい
229 && this->returnType.Equals( pUserProc->returnType ) ) // 戻り値が等しい
230 {
231 return true;
232 }
233 return false;
234 }
235
236 /*!
237 @brief オーバーライド用に関数同士が等しいかどうかをチェックする
238 @param actualTypeParametersForThisProc thisオブジェクトで保有するメソッドを対象とした実型パラメータ
239 pUserProc 照らし合わせる関数
240 */
241 bool IsEqualForOverride( const Types &actualTypeParametersForThisProc, const UserProc *pUserProc ) const;
242
243 bool IsMacro() const
244 {
245 return isMacro;
246 }
247
248 int GetSecondParmNum() const
249 {
250 return secondParmNum;
251 }
252 void SetSecondParmNum( int secondParmNum )
253 {
254 this->secondParmNum = secondParmNum;
255 }
256 const Parameters &RealParams() const
257 {
258 return realParams;
259 }
260 Parameters &RealParams()
261 {
262 return realParams;
263 }
264 void SetRealParams( const Parameters &params )
265 {
266 realParams = params;
267 }
268 int GetRealSecondParmNum() const
269 {
270 return realSecondParmNum;
271 }
272
273 void ExportOff(){
274 isExport = false;
275 }
276 bool IsExport() const
277 {
278 return isExport;
279 }
280 void ThisIsSystemProc() const
281 {
282 isSystem = true;
283 }
284 bool IsSystem() const
285 {
286 return isSystem;
287 }
288 void ThisIsAutoGenerationProc() const
289 {
290 isAutoGeneration = true;
291 }
292 bool IsAutoGeneration() const
293 {
294 return isAutoGeneration;
295 }
296 void CompleteCompile() const
297 {
298 isCompiled = true;
299 }
300 void KillCompileStatus() const
301 {
302 isCompiled = false;
303 }
304 bool IsCompiled() const
305 {
306 return isCompiled;
307 }
308 bool IsDestructor() const
309 {
310 return ( GetName()[0] == '~' );
311 }
312
313 // バイナリコード位置とサイズ
314 DWORD GetBeginOpAddress() const
315 {
316 return beginOpAddress;
317 }
318 void SetBeginOpAddress( DWORD beginOpAddress ) const
319 {
320 this->beginOpAddress = beginOpAddress;
321 }
322 DWORD GetEndOpAddress() const
323 {
324 return endOpAddress;
325 }
326 void SetEndOpAddress( DWORD endOpAddress ) const
327 {
328 this->endOpAddress = endOpAddress;
329 }
330 int GetCodeSize() const
331 {
332 return endOpAddress - beginOpAddress;
333 }
334
335 virtual const NamespaceScopes &GetNamespaceScopes() const;
336 const NamespaceScopesCollection &GetImportedNamespaces() const;
337
338 Variables &GetLocalVars() const
339 {
340 return localVars;
341 }
342
343 int GetId() const
344 {
345 return id;
346 }
347
348 const NativeCode &GetNativeCode() const
349 {
350 return nativeCode;
351 }
352 NativeCode &GetNativeCode()
353 {
354 return nativeCode;
355 }
356
357 std::string GetFullName() const;
358 bool IsCastOperator() const;
359
360 bool IsVirtual() const;
361
362 void SetParentClass( const CClass *pParentClass ){
363 this->pParentClass = pParentClass;
364 }
365 const CClass *GetParentClassPtr() const
366 {
367 return pParentClass;
368 }
369 const CClass &GetParentClass() const
370 {
371 return *pParentClass;
372 }
373 bool HasParentClass() const
374 {
375 return ( pParentClass != NULL );
376 }
377 bool IsGlobalProcedure() const
378 {
379 return ( pParentClass == NULL );
380 }
381 void SetInterface( const Interface *pInterface )
382 {
383 this->pInterface = pInterface;
384 }
385 void SetMethod( CMethod *pMethod ){
386 this->pMethod = pMethod;
387 }
388 const CMethod &GetMethod() const;
389
390 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
391
392
393 static const UserProc *pGlobalProc;
394};
395
396class UserProcs : public Jenga::Common::Hashmap<UserProc>
397{
398 // XMLシリアライズ用
399private:
400 friend class boost::serialization::access;
401 template<class Archive> void serialize(Archive& ar, const unsigned int version)
402 {
403 trace_for_serialize( "serializing - UserProcs" );
404
405 ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
406 boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
407 }
408
409
410public:
411 UserProcs()
412 {
413 }
414 ~UserProcs()
415 {
416 }
417
418 bool Insert( UserProc *pUserProc, int nowLine );
419
420 void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
421};
422
423class DllProc : public Procedure, public Jenga::Common::ObjectInHashmap<DllProc>
424{
425 std::string dllFileName;
426 std::string alias;
427 int lookupAddress;
428
429 // XMLシリアライズ用
430private:
431 friend class boost::serialization::access;
432 template<class Archive> void serialize(Archive& ar, const unsigned int version)
433 {
434 trace_for_serialize( "serializing - DllProc" );
435
436 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
437 ar & BOOST_SERIALIZATION_NVP( dllFileName );
438 ar & BOOST_SERIALIZATION_NVP( alias );
439 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
440 }
441
442public:
443 DllProc( const NamespaceScopes &namespaceScopes, const std::string &name, Kind kind, bool isCdecl, const std::string &dllFileName, const std::string &alias )
444 : Procedure( namespaceScopes, name, kind, isCdecl )
445 , dllFileName( dllFileName )
446 , alias( alias )
447 , lookupAddress( 0 )
448 {
449 }
450 DllProc()
451 {
452 }
453 ~DllProc()
454 {
455 }
456
457 virtual const std::string &GetKeyName() const
458 {
459 return GetName();
460 }
461
462 virtual bool IsDuplication( const DllProc *pDllProc ) const
463 {
464 if( pDllProc->IsEqualSymbol( *this )
465 && this->Params().Equals( pDllProc->Params() ) )
466 {
467 return true;
468 }
469 return false;
470 }
471
472 const std::string &GetDllFileName() const
473 {
474 return dllFileName;
475 }
476 const std::string &GetAlias() const
477 {
478 return alias;
479 }
480
481 void SetLookupAddress( int lookupAddress ){
482 this->lookupAddress = lookupAddress;
483 }
484 int GetLookupAddress() const
485 {
486 return lookupAddress;
487 }
488
489 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
490};
491class DllProcs : public Jenga::Common::Hashmap<DllProc>
492{
493 // XMLシリアライズ用
494private:
495 friend class boost::serialization::access;
496 template<class Archive> void serialize(Archive& ar, const unsigned int version)
497 {
498 trace_for_serialize( "serializing - DllProcs" );
499
500 ar & boost::serialization::make_nvp("Hashmap_DllProc",
501 boost::serialization::base_object<Jenga::Common::Hashmap<DllProc>>(*this));
502 }
503};
504
505class ProcPointer : public Procedure
506{
507 // XMLシリアライズ用
508private:
509 friend class boost::serialization::access;
510 template<class Archive> void serialize(Archive& ar, const unsigned int version)
511 {
512 trace_for_serialize( "serializing - ProcPointer" );
513
514 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
515 }
516
517public:
518 ProcPointer( Kind kind )
519 : Procedure( NamespaceScopes(), std::string(), kind, false )
520 {
521 }
522 ProcPointer()
523 {
524 }
525 ~ProcPointer(){}
526
527 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
528};
529
530class ProcPointers : public std::vector<ProcPointer *>
531{
532 // XMLシリアライズ用
533private:
534 friend class boost::serialization::access;
535 template<class Archive> void serialize(Archive& ar, const unsigned int version)
536 {
537 trace_for_serialize( "serializing - ProcPointers" );
538
539 ar & boost::serialization::make_nvp("vector_ProcPointer",
540 boost::serialization::base_object<vector<ProcPointer *>>(*this));
541 }
542
543public:
544 ProcPointers()
545 {
546 }
547 ~ProcPointers()
548 {
549 Clear();
550 }
551
552 int Add( const std::string &typeExpression );
553 void Clear();
554 void PullOutAll()
555 {
556 clear();
557 }
558};
Note: See TracBrowser for help on using the repository browser.