source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/Procedure.h@ 604

Last change on this file since 604 was 604, checked in by dai_9181, 16 years ago

不要なクラスのプロトタイプ宣言を排除。

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