source: dev/trunk/ab5.0/abdev/ab_common/src/Lexical/Method.cpp@ 603

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

ObjectModuleに関連するクラス一式をab_commonプロジェクトに移動した。

File size: 3.8 KB
Line 
1#include "stdafx.h"
2
3DynamicMethod::OverrideResult::EnumType DynamicMethod::Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier )
4{
5 bool isAbstractBefore = this->IsAbstract();
6
7 //メンバ関数を上書き
8 this->SetUserProcPtr( pUserProc );
9 this->SetAbstractMark( false );
10
11 if( this->IsVirtual() )
12 {
13 if( !isAbstractBefore && isOverrideModifier == false )
14 {
15 return OverrideResult::NotUseOverrideModifier;
16 }
17 }
18 else
19 {
20 return OverrideResult::NotVirtual;
21 }
22
23 if( this->GetAccessibility() != accessibility )
24 {
25 return OverrideResult::DifferentAccesibility;
26 }
27
28 return OverrideResult::Successful;
29}
30
31
32StaticMethod::StaticMethod( const StaticMethod &staticMethod )
33{
34 // 静的メソッドがコピーコンストラトされることは想定しない
35 throw;
36}
37
38Methods::Methods()
39{
40}
41
42// コピーコンストラクタ
43Methods::Methods( const Methods &methods )
44{
45 BOOST_FOREACH( CMethod *pMethod, methods )
46 {
47 this->push_back( new DynamicMethod( dynamic_cast<DynamicMethod &>(*pMethod) ) );
48 }
49}
50
51Methods::~Methods()
52{
53 Methods &methods = *this;
54 BOOST_FOREACH( CMethod *pMethod, methods )
55 {
56 delete pMethod;
57 }
58}
59
60void Methods::Add( UserProc *pUserProc,Prototype::Accessibility accessibility, bool isConst, bool isAbstract, bool isVirtual ){
61 CMethod *pMethod = new DynamicMethod( pUserProc, accessibility, isAbstract, isVirtual, isConst );
62 this->push_back( pMethod );
63 pUserProc->SetMethod( pMethod );
64}
65void Methods::AddStatic(UserProc *pUserProc, Prototype::Accessibility accessibility ){
66 CMethod *pMethod = new StaticMethod( pUserProc, accessibility );
67 this->push_back( pMethod );
68 pUserProc->SetMethod( pMethod );
69}
70
71DynamicMethod *Methods::FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc )
72{
73 //メソッドのオーバーライド
74 Methods &methods = *this;
75 BOOST_FOREACH( CMethod *pMethod, methods )
76 {
77 if( !pMethod->IsNotUse() && pMethod->GetUserProc().IsEqualForOverride( actualTypeParametersForThisMethods, pUserProc ) )
78 {
79 return dynamic_cast<DynamicMethod *>(pMethod);
80 }
81 }
82 return NULL;
83}
84
85const CMethod *Methods::GetMethodPtr( const UserProc *pUserProc ) const
86{
87 const Methods &methods = *this;
88 for( int i=(int)methods.size()-1; i>=0; i-- ){
89 if( pUserProc == &methods[i]->GetUserProc() ){
90 return methods[i];
91 }
92 }
93 return NULL;
94}
95bool Methods::IsExist( const char *name ) const
96{
97 const Methods &methods = *this;
98 BOOST_FOREACH( const CMethod *pMethod, methods ){
99 if( pMethod->GetUserProc().GetName() == name ) return true;
100 }
101 return false;
102}
103void Methods::Enum( const char *methodName, std::vector<const UserProc *> &subs ) const
104{
105 //オブジェクトのメンバ関数の場合
106 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
107 const Methods &methods = *this;
108 for( int i=(int)methods.size()-1; i>=0; i-- ){
109 if( methods[i]->GetUserProc().GetName() == methodName && methods[i]->IsNotUse() == false ){
110 subs.push_back( &methods[i]->GetUserProc() );
111 }
112 }
113}
114void Methods::Enum( BYTE idOperatorCalc, std::vector<const UserProc *> &subs ) const
115{
116 //オブジェクトのメンバ関数の場合
117 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
118 const Methods &methods = *this;
119 for( int i=(int)methods.size()-1; i>=0; i-- ){
120 const UserProc &userProc = methods[i]->GetUserProc();
121 const char *temp = userProc.GetName().c_str();
122 if(temp[0]==1&&temp[1]==ESC_OPERATOR){
123 if((BYTE)temp[2]==idOperatorCalc){
124 subs.push_back( &userProc );
125 }
126 }
127 }
128}
129
130int Methods::GetVtblNum() const
131{
132 int count = 0;
133 const Methods &methods = *this;
134 BOOST_FOREACH( const CMethod *pMethod, methods )
135 {
136 if( pMethod->IsVirtual() )
137 {
138 count++;
139 }
140 }
141 return count;
142}
Note: See TracBrowser for help on using the repository browser.