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

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

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

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