source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/Method.cpp@ 573

Last change on this file since 573 was 559, checked in by dai_9181, 17 years ago

VtblGeneratorクラスを追加。Classes/CClassクラスのvtbl生成関連の実装をVtblGeneratorクラスに移動した。

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