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