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

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

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

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