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

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

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

File size: 3.8 KB
RevLine 
[206]1#include "stdafx.h"
2
3#include <Class.h>
4
5
[558]6DynamicMethod::OverrideResult::EnumType DynamicMethod::Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier )
[351]7{
[558]8 bool isAbstractBefore = this->IsAbstract();
[351]9
10 //メンバ関数を上書き
11 this->SetUserProcPtr( pUserProc );
12 this->SetAbstractMark( false );
13
[558]14 if( this->IsVirtual() )
[351]15 {
[558]16 if( !isAbstractBefore && isOverrideModifier == false )
17 {
18 return OverrideResult::NotUseOverrideModifier;
19 }
[351]20 }
[558]21 else
[351]22 {
[558]23 return OverrideResult::NotVirtual;
[351]24 }
25
[558]26 if( this->GetAccessibility() != accessibility )
27 {
28 return OverrideResult::DifferentAccesibility;
29 }
30
31 return OverrideResult::Successful;
[351]32}
33
34
35StaticMethod::StaticMethod( const StaticMethod &staticMethod )
36{
37 // 静的メソッドがコピーコンストラトされることは想定しない
[559]38 throw;
[351]39}
40
[206]41Methods::Methods()
42{
43}
[351]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
[206]54Methods::~Methods()
55{
56 Methods &methods = *this;
[351]57 BOOST_FOREACH( CMethod *pMethod, methods )
58 {
[206]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
[558]74DynamicMethod *Methods::FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc )
[346]75{
76 //メソッドのオーバーライド
77 Methods &methods = *this;
78 BOOST_FOREACH( CMethod *pMethod, methods )
79 {
[382]80 if( !pMethod->IsNotUse() && pMethod->GetUserProc().IsEqualForOverride( actualTypeParametersForThisMethods, pUserProc ) )
[346]81 {
[558]82 return dynamic_cast<DynamicMethod *>(pMethod);
[346]83 }
84 }
[351]85 return NULL;
[346]86}
87
[206]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}
[523]106void Methods::Enum( const char *methodName, std::vector<const UserProc *> &subs ) const
[206]107{
108 //オブジェクトのメンバ関数の場合
109 //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
110 const Methods &methods = *this;
111 for( int i=(int)methods.size()-1; i>=0; i-- ){
[352]112 if( methods[i]->GetUserProc().GetName() == methodName && methods[i]->IsNotUse() == false ){
[206]113 subs.push_back( &methods[i]->GetUserProc() );
114 }
115 }
116}
[523]117void Methods::Enum( BYTE idOperatorCalc, std::vector<const UserProc *> &subs ) const
[206]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}
[347]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.