[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | #include <Class.h>
|
---|
| 4 |
|
---|
| 5 |
|
---|
[558] | 6 | DynamicMethod::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 |
|
---|
| 35 | StaticMethod::StaticMethod( const StaticMethod &staticMethod )
|
---|
| 36 | {
|
---|
| 37 | // 静的メソッドがコピーコンストラトされることは想定しない
|
---|
[465] | 38 | compiler.errorMessenger.OutputFatalError();
|
---|
[351] | 39 | }
|
---|
| 40 |
|
---|
[206] | 41 | Methods::Methods()
|
---|
| 42 | {
|
---|
| 43 | }
|
---|
[351] | 44 |
|
---|
| 45 | // コピーコンストラクタ
|
---|
| 46 | Methods::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] | 54 | Methods::~Methods()
|
---|
| 55 | {
|
---|
| 56 | Methods &methods = *this;
|
---|
[351] | 57 | BOOST_FOREACH( CMethod *pMethod, methods )
|
---|
| 58 | {
|
---|
[206] | 59 | delete pMethod;
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | void 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 | }
|
---|
| 68 | void 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] | 74 | DynamicMethod *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] | 88 | const 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 | }
|
---|
| 98 | bool 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] | 106 | void 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] | 117 | void 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 |
|
---|
| 133 | int 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 | }
|
---|
| 146 |
|
---|
| 147 | void Methods::GenerateVTablePart( long &vtableDataTableOffset ) const
|
---|
| 148 | {
|
---|
| 149 | const UserProc **ppsi = (const UserProc **)malloc(GetVtblNum()*sizeof(UserProc *));
|
---|
| 150 |
|
---|
| 151 | //関数テーブルに値をセット
|
---|
| 152 | int i2 = 0;
|
---|
| 153 | const Methods &methods = *this;
|
---|
| 154 | BOOST_FOREACH( const CMethod *pMethod, methods ){
|
---|
| 155 | if(pMethod->IsVirtual()){
|
---|
| 156 | if( !pMethod->GetUserProc().IsUsing() )
|
---|
| 157 | {
|
---|
[370] | 158 | //ts((char *)pMethod->GetUserProc().GetFullName().c_str());
|
---|
[347] | 159 | }
|
---|
| 160 | pMethod->GetUserProc().Using();
|
---|
| 161 |
|
---|
| 162 | if(pMethod->IsAbstract()){
|
---|
[465] | 163 | compiler.errorMessenger.OutputFatalError();
|
---|
[347] | 164 |
|
---|
| 165 | ppsi[i2]=0;
|
---|
| 166 | }
|
---|
| 167 | else{
|
---|
| 168 | ppsi[i2]=&pMethod->GetUserProc();
|
---|
| 169 | }
|
---|
| 170 | i2++;
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | vtableDataTableOffset = compiler.GetObjectModule().dataTable.AddBinary( (void *)ppsi, GetVtblNum()*sizeof(LONG_PTR) );
|
---|
| 175 |
|
---|
| 176 | for( int i=0; i < GetVtblNum(); i++ ){
|
---|
| 177 | pobj_Reloc->AddSchedule_DataSection(static_cast<DWORD>(vtableDataTableOffset+i*sizeof(LONG_PTR)));
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | free(ppsi);
|
---|
| 181 | }
|
---|