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

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

ジェネリッククラスの型パラメータに値型が指定されたときに限り、テンプレート展開を行うようにした。

TODO: libファイルを跨ってテンプレート展開ができていないため、ソースコード管理部分に手を加える必要あり。

File size: 11.2 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
26private:
27 // ソースコードの位置
28 SourceCodePosition sourceCodePosition;
29
30 // XMLシリアライズ用
31private:
32 friend class boost::serialization::access;
33 template<class Archive> void serialize(Archive& ar, const unsigned int version)
34 {
35 trace_for_serialize( "serializing - Procedure" );
36
37 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Symbol );
38 ar & BOOST_SERIALIZATION_NVP( kind );
39 ar & BOOST_SERIALIZATION_NVP( isCdecl );
40 ar & BOOST_SERIALIZATION_NVP( isUsing );
41 ar & BOOST_SERIALIZATION_NVP( params );
42 ar & BOOST_SERIALIZATION_NVP( returnType );
43 ar & BOOST_SERIALIZATION_NVP( sourceCodePosition );
44 }
45
46public:
47 Procedure( const NamespaceScopes &namespaceScopes, const std::string &name, Kind kind, bool isCdecl )
48 : Symbol( namespaceScopes, name )
49 , kind( kind )
50 , isCdecl( isCdecl )
51 , isUsing( false )
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 const SourceCodePosition &GetSourceCodePosition() const
86 {
87 return sourceCodePosition;
88 }
89 void SetSourceCodePosition( const SourceCodePosition &sourceCodePosition )
90 {
91 this->sourceCodePosition = sourceCodePosition;
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 UserProc( const UserProc &userProc, const CClass *pParentClass );
182 UserProc();
183 ~UserProc();
184
185 void SetReturnType( const Type &newReturnType )
186 {
187 returnType = newReturnType;
188 }
189
190 virtual const std::string &GetKeyName() const
191 {
192 return GetName();
193 }
194
195 virtual bool IsDuplication( const UserProc *pUserProc ) const
196 {
197 if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr() // 親クラスが等しい
198 && this->pInterface == pUserProc->pInterface // インターフェイスが等しい
199 && pUserProc->IsEqualSymbol( *this ) // 名前空間及び名前が等しい
200 && this->Params().Equals( pUserProc->Params() ) // パラメータが等しい
201 && this->returnType.Equals( pUserProc->returnType ) ) // 戻り値が等しい
202 {
203 return true;
204 }
205 return false;
206 }
207
208 /*!
209 @brief オーバーライド用に関数同士が等しいかどうかをチェックする
210 @param actualTypeParametersForThisProc thisオブジェクトで保有するメソッドを対象とした実型パラメータ
211 pUserProc 照らし合わせる関数
212 */
213 bool IsEqualForOverride( const Types &actualTypeParametersForThisProc, const UserProc *pUserProc ) const;
214
215 bool IsMacro() const
216 {
217 return isMacro;
218 }
219
220 int GetSecondParmNum() const
221 {
222 return secondParmNum;
223 }
224 void SetSecondParmNum( int secondParmNum )
225 {
226 this->secondParmNum = secondParmNum;
227 }
228 const Parameters &RealParams() const
229 {
230 return realParams;
231 }
232 Parameters &RealParams()
233 {
234 return realParams;
235 }
236 void SetRealParams( const Parameters &params )
237 {
238 realParams = params;
239 }
240 int GetRealSecondParmNum() const
241 {
242 return realSecondParmNum;
243 }
244
245 void ExportOff(){
246 isExport = false;
247 }
248 bool IsExport() const
249 {
250 return isExport;
251 }
252 void ThisIsSystemProc() const
253 {
254 isSystem = true;
255 }
256 bool IsSystem() const
257 {
258 return isSystem;
259 }
260 void ThisIsAutoGenerationProc() const
261 {
262 isAutoGeneration = true;
263 }
264 bool IsAutoGeneration() const
265 {
266 return isAutoGeneration;
267 }
268 void CompleteCompile() const
269 {
270 isCompiled = true;
271 }
272 void KillCompileStatus() const
273 {
274 isCompiled = false;
275 }
276 bool IsCompiled() const
277 {
278 return isCompiled;
279 }
280 bool IsDestructor() const
281 {
282 return ( GetName()[0] == '~' );
283 }
284
285 // バイナリコード位置とサイズ
286 DWORD GetBeginOpAddress() const
287 {
288 return beginOpAddress;
289 }
290 void SetBeginOpAddress( DWORD beginOpAddress ) const
291 {
292 this->beginOpAddress = beginOpAddress;
293 }
294 DWORD GetEndOpAddress() const
295 {
296 return endOpAddress;
297 }
298 void SetEndOpAddress( DWORD endOpAddress ) const
299 {
300 this->endOpAddress = endOpAddress;
301 }
302 int GetCodeSize() const
303 {
304 return endOpAddress - beginOpAddress;
305 }
306
307 virtual const NamespaceScopes &GetNamespaceScopes() const;
308 const NamespaceScopesCollection &GetImportedNamespaces() const;
309
310 Variables &GetLocalVars() const
311 {
312 return localVars;
313 }
314
315 int GetId() const
316 {
317 return id;
318 }
319
320 const NativeCode &GetNativeCode() const
321 {
322 return nativeCode;
323 }
324 NativeCode &GetNativeCode()
325 {
326 return nativeCode;
327 }
328
329 std::string GetFullName() const;
330 bool IsCastOperator() const;
331
332 bool IsVirtual() const;
333
334 void SetParentClass( const CClass *pParentClass ){
335 this->pParentClass = pParentClass;
336 }
337 const CClass *GetParentClassPtr() const
338 {
339 return pParentClass;
340 }
341 const CClass &GetParentClass() const
342 {
343 return *pParentClass;
344 }
345 bool HasParentClass() const
346 {
347 return ( pParentClass != NULL );
348 }
349 bool IsGlobalProcedure() const
350 {
351 return ( pParentClass == NULL );
352 }
353 void SetInterface( const Interface *pInterface )
354 {
355 this->pInterface = pInterface;
356 }
357 void SetMethod( CMethod *pMethod ){
358 this->pMethod = pMethod;
359 }
360 const CMethod &GetMethod() const;
361
362
363 static const UserProc *pGlobalProc;
364};
365
366class UserProcs : public Jenga::Common::Hashmap<UserProc>
367{
368 // XMLシリアライズ用
369private:
370 friend class boost::serialization::access;
371 template<class Archive> void serialize(Archive& ar, const unsigned int version)
372 {
373 trace_for_serialize( "serializing - UserProcs" );
374
375 ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
376 boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
377 }
378
379
380public:
381 UserProcs()
382 {
383 }
384 ~UserProcs()
385 {
386 }
387
388 void EnumGlobalProcs( const char *simpleName, const Symbol &localSymbol, std::vector<const UserProc *> &subs );
389};
390
391class DllProc : public Procedure, public Jenga::Common::ObjectInHashmap<DllProc>
392{
393 std::string dllFileName;
394 std::string alias;
395 int lookupAddress;
396
397 // XMLシリアライズ用
398private:
399 friend class boost::serialization::access;
400 template<class Archive> void serialize(Archive& ar, const unsigned int version)
401 {
402 trace_for_serialize( "serializing - DllProc" );
403
404 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
405 ar & BOOST_SERIALIZATION_NVP( dllFileName );
406 ar & BOOST_SERIALIZATION_NVP( alias );
407 ar & BOOST_SERIALIZATION_NVP( lookupAddress );
408 }
409
410public:
411 DllProc( const NamespaceScopes &namespaceScopes, const std::string &name, Kind kind, bool isCdecl, const std::string &dllFileName, const std::string &alias )
412 : Procedure( namespaceScopes, name, kind, isCdecl )
413 , dllFileName( dllFileName )
414 , alias( alias )
415 , lookupAddress( 0 )
416 {
417 }
418 DllProc()
419 {
420 }
421 ~DllProc()
422 {
423 }
424
425 virtual const std::string &GetKeyName() const
426 {
427 return GetName();
428 }
429
430 virtual bool IsDuplication( const DllProc *pDllProc ) const
431 {
432 if( pDllProc->IsEqualSymbol( *this )
433 && this->Params().Equals( pDllProc->Params() ) )
434 {
435 return true;
436 }
437 return false;
438 }
439
440 const std::string &GetDllFileName() const
441 {
442 return dllFileName;
443 }
444 const std::string &GetAlias() const
445 {
446 return alias;
447 }
448
449 void SetLookupAddress( int lookupAddress ){
450 this->lookupAddress = lookupAddress;
451 }
452 int GetLookupAddress() const
453 {
454 return lookupAddress;
455 }
456};
457class DllProcs : public Jenga::Common::Hashmap<DllProc>
458{
459 // XMLシリアライズ用
460private:
461 friend class boost::serialization::access;
462 template<class Archive> void serialize(Archive& ar, const unsigned int version)
463 {
464 trace_for_serialize( "serializing - DllProcs" );
465
466 ar & boost::serialization::make_nvp("Hashmap_DllProc",
467 boost::serialization::base_object<Jenga::Common::Hashmap<DllProc>>(*this));
468 }
469};
470
471class ProcPointer : public Procedure
472{
473 // XMLシリアライズ用
474private:
475 friend class boost::serialization::access;
476 template<class Archive> void serialize(Archive& ar, const unsigned int version)
477 {
478 trace_for_serialize( "serializing - ProcPointer" );
479
480 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
481 }
482
483public:
484 ProcPointer( Kind kind )
485 : Procedure( NamespaceScopes(), std::string(), kind, false )
486 {
487 }
488 ProcPointer()
489 {
490 }
491 ~ProcPointer(){}
492};
493
494class ProcPointers : public std::vector<ProcPointer *>
495{
496 // XMLシリアライズ用
497private:
498 friend class boost::serialization::access;
499 template<class Archive> void serialize(Archive& ar, const unsigned int version)
500 {
501 trace_for_serialize( "serializing - ProcPointers" );
502
503 ar & boost::serialization::make_nvp("vector_ProcPointer",
504 boost::serialization::base_object<vector<ProcPointer *>>(*this));
505 }
506
507public:
508 ProcPointers()
509 {
510 }
511 ~ProcPointers()
512 {
513 Clear();
514 }
515
516 void Clear();
517 void PullOutAll()
518 {
519 clear();
520 }
521};
Note: See TracBrowser for help on using the repository browser.