source: dev/branches/egtra/ab5.0/abdev/ab_common/src/Lexical/Method.cpp@ 816

Last change on this file since 816 was 816, checked in by イグトランス (egtra), 13 years ago

ab_commonにおいて、各クラスのコピー禁止を明確化、ならびにコピー可能なものにムーブコンストラクタ・ムーブ代入演算子を追加

File size: 5.0 KB
Line 
1#include "stdafx.h"
2#include <stdexcept>
3
4bool CMethod::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
5{
6 if( this->pUserProc )
7 {
8 if( this->pUserProc->IsNeedResolve() )
9 {
10 const UserProc *pTempUserProc = resolver.meta.GetUserProcs().FindLike( this->pUserProc );
11 if( pTempUserProc )
12 {
13 this->pUserProc = pTempUserProc;
14 }
15 else
16 {
17 resolveErrors.Add( ResolveError( this->pUserProc->GetRelationalObjectModuleIndex(), this->pUserProc->GetFullName() ) );
18 }
19 }
20 }
21 return true;
22}
23
24DynamicMethod::OverrideResult::EnumType DynamicMethod::Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier )
25{
26 bool isAbstractBefore = this->IsAbstract();
27
28 //メンバ関数を上書き
29 this->SetUserProcPtr( pUserProc );
30 this->SetAbstractMark( false );
31
32 if( this->IsVirtual() )
33 {
34 if( !isAbstractBefore && isOverrideModifier == false )
35 {
36 return OverrideResult::NotUseOverrideModifier;
37 }
38 }
39 else
40 {
41 return OverrideResult::NotVirtual;
42 }
43
44 if( this->GetAccessibility() != accessibility )
45 {
46 return OverrideResult::DifferentAccesibility;
47 }
48
49 return OverrideResult::Successful;
50}
51
52bool DynamicMethod::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
53{
54 CMethod::Resolve( resolver, resolveErrors );
55
56 if( this->pInheritsClass )
57 {
58 if( this->pInheritsClass->IsNeedResolve() )
59 {
60 const CClass *pTempClass = resolver.meta.GetClasses().FindLike( pInheritsClass );
61 if( pTempClass )
62 {
63 this->pInheritsClass = pTempClass;
64 }
65 else
66 {
67 resolveErrors.Add( ResolveError( this->pInheritsClass->GetRelationalObjectModuleIndex(), this->pInheritsClass->GetFullName() ) );
68 }
69 }
70 }
71
72 return true;
73}
74
75StaticMethod::StaticMethod( const StaticMethod &staticMethod )
76{
77 // 静的メソッドがコピーコンストラトされることは想定しない
78 throw std::domain_error("静的メソッドのコピー構築に対応していない");
79}
80
81bool StaticMethod::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
82{
83 CMethod::Resolve( resolver, resolveErrors );
84 return true;
85}
86
87
88Methods::Methods()
89{
90}
91
92// コピーコンストラクタ
93Methods::Methods( const Methods &methods )
94{
95 foreach( CMethod *pMethod, methods )
96 {
97 this->push_back( new DynamicMethod( dynamic_cast<DynamicMethod &>(*pMethod) ) );
98 }
99}
100
101Methods::~Methods()
102{
103 Methods &methods = *this;
104 foreach( CMethod *pMethod, methods )
105 {
106 delete pMethod;
107 }
108}
109
110void Methods::Add( UserProc *pUserProc,Prototype::Accessibility accessibility, bool isConst, bool isAbstract, bool isVirtual ){
111 CMethod *pMethod = new DynamicMethod( pUserProc, accessibility, isAbstract, isVirtual, isConst );
112 this->push_back( pMethod );
113 pUserProc->SetMethod( pMethod );
114}
115void Methods::AddStatic(UserProc *pUserProc, Prototype::Accessibility accessibility ){
116 CMethod *pMethod = new StaticMethod( pUserProc, accessibility );
117 this->push_back( pMethod );
118 pUserProc->SetMethod( pMethod );
119}
120
121DynamicMethod *Methods::FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc )
122{
123 //メソッドのオーバーライド
124 Methods &methods = *this;
125 foreach( CMethod *pMethod, methods )
126 {
127 if( !pMethod->IsNotUse() && pMethod->GetUserProc().IsEqualForOverride( actualTypeParametersForThisMethods, pUserProc ) )
128 {
129 return dynamic_cast<DynamicMethod *>(pMethod);
130 }
131 }
132 return NULL;
133}
134
135const CMethod *Methods::GetMethodPtr( const UserProc *pUserProc ) const
136{
137 const Methods &methods = *this;
138 for( int i=(int)methods.size()-1; i>=0; i-- ){
139 if( pUserProc == &methods[i]->GetUserProc() ){
140 return methods[i];
141 }
142 }
143 return NULL;
144}
145bool Methods::IsExist( const char *name ) const
146{
147 const Methods &methods = *this;
148 foreach( const CMethod *pMethod, methods ){
149 if( pMethod->GetUserProc().GetName() == name ) return true;
150 }
151 return false;
152}
153void Methods::Enum( const char *methodName, std::vector<const UserProc *> &subs ) const
154{
155 //オブジェクトのメンバ関数の場合
156 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
157 const Methods &methods = *this;
158 for( int i=(int)methods.size()-1; i>=0; i-- ){
159 if( methods[i]->GetUserProc().GetName() == methodName && methods[i]->IsNotUse() == false ){
160 subs.push_back( &methods[i]->GetUserProc() );
161 }
162 }
163}
164void Methods::Enum( BYTE idOperatorCalc, std::vector<const UserProc *> &subs ) const
165{
166 //オブジェクトのメンバ関数の場合
167 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
168 const Methods &methods = *this;
169 for( int i=(int)methods.size()-1; i>=0; i-- ){
170 const UserProc &userProc = methods[i]->GetUserProc();
171 const char *temp = userProc.GetName().c_str();
172 if(temp[0]==1&&temp[1]==ESC_OPERATOR){
173 if((BYTE)temp[2]==idOperatorCalc){
174 subs.push_back( &userProc );
175 }
176 }
177 }
178}
179
180int Methods::GetVtblNum() const
181{
182 int count = 0;
183 const Methods &methods = *this;
184 foreach( const CMethod *pMethod, methods )
185 {
186 if( pMethod->IsVirtual() )
187 {
188 count++;
189 }
190 }
191 return count;
192}
Note: See TracBrowser for help on using the repository browser.