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

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

BOOST_FOREACHを可能なものはVC++ 2005 for eachへ置換(やや速くなる)。

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