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

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

静的リンクリンカの依存関係解決モジュールを製作中

File size: 5.0 KB
RevLine 
[206]1#include "stdafx.h"
2
[640]3bool CMethod::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
[639]4{
[640]5 if( this->pUserProc )
[639]6 {
[640]7 if( this->pUserProc->IsNeedResolve() )
[639]8 {
[640]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 }
[639]18 }
19 }
20 return true;
21}
22
[558]23DynamicMethod::OverrideResult::EnumType DynamicMethod::Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier )
[351]24{
[558]25 bool isAbstractBefore = this->IsAbstract();
[351]26
27 //メンバ関数を上書き
28 this->SetUserProcPtr( pUserProc );
29 this->SetAbstractMark( false );
30
[558]31 if( this->IsVirtual() )
[351]32 {
[558]33 if( !isAbstractBefore && isOverrideModifier == false )
34 {
35 return OverrideResult::NotUseOverrideModifier;
36 }
[351]37 }
[558]38 else
[351]39 {
[558]40 return OverrideResult::NotVirtual;
[351]41 }
42
[558]43 if( this->GetAccessibility() != accessibility )
44 {
45 return OverrideResult::DifferentAccesibility;
46 }
47
48 return OverrideResult::Successful;
[351]49}
50
[640]51bool DynamicMethod::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
[639]52{
[640]53 CMethod::Resolve( resolver, resolveErrors );
[351]54
[639]55 if( this->pInheritsClass )
56 {
57 if( this->pInheritsClass->IsNeedResolve() )
58 {
[640]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 }
[639]68 }
69 }
70
71 return true;
72}
73
[351]74StaticMethod::StaticMethod( const StaticMethod &staticMethod )
75{
76 // 静的メソッドがコピーコンストラトされることは想定しない
[559]77 throw;
[351]78}
79
[640]80bool StaticMethod::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
[639]81{
[640]82 CMethod::Resolve( resolver, resolveErrors );
[639]83 return true;
84}
85
86
[206]87Methods::Methods()
88{
89}
[351]90
91// コピーコンストラクタ
92Methods::Methods( const Methods &methods )
93{
94 BOOST_FOREACH( CMethod *pMethod, methods )
95 {
96 this->push_back( new DynamicMethod( dynamic_cast<DynamicMethod &>(*pMethod) ) );
97 }
98}
99
[206]100Methods::~Methods()
101{
102 Methods &methods = *this;
[351]103 BOOST_FOREACH( CMethod *pMethod, methods )
104 {
[206]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
[558]120DynamicMethod *Methods::FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc )
[346]121{
122 //メソッドのオーバーライド
123 Methods &methods = *this;
124 BOOST_FOREACH( CMethod *pMethod, methods )
125 {
[382]126 if( !pMethod->IsNotUse() && pMethod->GetUserProc().IsEqualForOverride( actualTypeParametersForThisMethods, pUserProc ) )
[346]127 {
[558]128 return dynamic_cast<DynamicMethod *>(pMethod);
[346]129 }
130 }
[351]131 return NULL;
[346]132}
133
[206]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 BOOST_FOREACH( const CMethod *pMethod, methods ){
148 if( pMethod->GetUserProc().GetName() == name ) return true;
149 }
150 return false;
151}
[523]152void Methods::Enum( const char *methodName, std::vector<const UserProc *> &subs ) const
[206]153{
154 //オブジェクトのメンバ関数の場合
155 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
156 const Methods &methods = *this;
157 for( int i=(int)methods.size()-1; i>=0; i-- ){
[352]158 if( methods[i]->GetUserProc().GetName() == methodName && methods[i]->IsNotUse() == false ){
[206]159 subs.push_back( &methods[i]->GetUserProc() );
160 }
161 }
162}
[523]163void Methods::Enum( BYTE idOperatorCalc, std::vector<const UserProc *> &subs ) const
[206]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}
[347]178
179int Methods::GetVtblNum() const
180{
181 int count = 0;
182 const Methods &methods = *this;
183 BOOST_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.