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