| 1 | #include "stdafx.h"
|
|---|
| 2 |
|
|---|
| 3 | #include <Class.h>
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | Methods::Methods()
|
|---|
| 7 | {
|
|---|
| 8 | }
|
|---|
| 9 | Methods::~Methods()
|
|---|
| 10 | {
|
|---|
| 11 | Methods &methods = *this;
|
|---|
| 12 | BOOST_FOREACH( CMethod *pMethod, methods ){
|
|---|
| 13 | delete pMethod;
|
|---|
| 14 | }
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | void Methods::Add( UserProc *pUserProc,Prototype::Accessibility accessibility, bool isConst, bool isAbstract, bool isVirtual ){
|
|---|
| 18 | CMethod *pMethod = new DynamicMethod( pUserProc, accessibility, isAbstract, isVirtual, isConst );
|
|---|
| 19 | this->push_back( pMethod );
|
|---|
| 20 | pUserProc->SetMethod( pMethod );
|
|---|
| 21 | }
|
|---|
| 22 | void Methods::AddStatic(UserProc *pUserProc, Prototype::Accessibility accessibility ){
|
|---|
| 23 | CMethod *pMethod = new StaticMethod( pUserProc, accessibility );
|
|---|
| 24 | this->push_back( pMethod );
|
|---|
| 25 | pUserProc->SetMethod( pMethod );
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | bool Methods::Override( UserProc *pUserProc, Prototype::Accessibility accessibility )
|
|---|
| 29 | {
|
|---|
| 30 | //メソッドのオーバーライド
|
|---|
| 31 | Methods &methods = *this;
|
|---|
| 32 | BOOST_FOREACH( CMethod *pMethod, methods )
|
|---|
| 33 | {
|
|---|
| 34 | if( pMethod->GetUserProc().GetName() == pUserProc->GetName() )
|
|---|
| 35 | {
|
|---|
| 36 | if( pMethod->GetUserProc().Params().Equals( pUserProc->Params() )
|
|---|
| 37 | && pMethod->GetUserProc().ReturnType().Equals( pUserProc->ReturnType() ) )
|
|---|
| 38 | {
|
|---|
| 39 | //メンバ関数を上書き
|
|---|
| 40 | pMethod->SetUserProcPtr( pUserProc );
|
|---|
| 41 | pMethod->Override();
|
|---|
| 42 |
|
|---|
| 43 | if( !pMethod->IsVirtual() )
|
|---|
| 44 | {
|
|---|
| 45 | // オーバーライドミス
|
|---|
| 46 | SetError(136,NULL,cp);
|
|---|
| 47 | }
|
|---|
| 48 | if(pMethod->GetAccessibility() != accessibility )
|
|---|
| 49 | {
|
|---|
| 50 | SetError(128,NULL,cp);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | pUserProc->SetMethod( pMethod );
|
|---|
| 54 | return true;
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | return false;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | const CMethod *Methods::GetMethodPtr( const UserProc *pUserProc ) const
|
|---|
| 62 | {
|
|---|
| 63 | const Methods &methods = *this;
|
|---|
| 64 | for( int i=(int)methods.size()-1; i>=0; i-- ){
|
|---|
| 65 | if( pUserProc == &methods[i]->GetUserProc() ){
|
|---|
| 66 | return methods[i];
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 | return NULL;
|
|---|
| 70 | }
|
|---|
| 71 | bool Methods::IsExist( const char *name ) const
|
|---|
| 72 | {
|
|---|
| 73 | const Methods &methods = *this;
|
|---|
| 74 | BOOST_FOREACH( const CMethod *pMethod, methods ){
|
|---|
| 75 | if( pMethod->GetUserProc().GetName() == name ) return true;
|
|---|
| 76 | }
|
|---|
| 77 | return false;
|
|---|
| 78 | }
|
|---|
| 79 | void Methods::Enum( const char *methodName, vector<const UserProc *> &subs ) const
|
|---|
| 80 | {
|
|---|
| 81 | //オブジェクトのメンバ関数の場合
|
|---|
| 82 | //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
|
|---|
| 83 | const Methods &methods = *this;
|
|---|
| 84 | for( int i=(int)methods.size()-1; i>=0; i-- ){
|
|---|
| 85 | if( methods[i]->GetUserProc().GetName() == methodName ){
|
|---|
| 86 | subs.push_back( &methods[i]->GetUserProc() );
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | void Methods::Enum( BYTE idOperatorCalc, vector<const UserProc *> &subs ) const
|
|---|
| 91 | {
|
|---|
| 92 | //オブジェクトのメンバ関数の場合
|
|---|
| 93 | //※オーバーライドされた関数を先にサーチする必要があるため、バックサーチを行う
|
|---|
| 94 | const Methods &methods = *this;
|
|---|
| 95 | for( int i=(int)methods.size()-1; i>=0; i-- ){
|
|---|
| 96 | const UserProc &userProc = methods[i]->GetUserProc();
|
|---|
| 97 | const char *temp = userProc.GetName().c_str();
|
|---|
| 98 | if(temp[0]==1&&temp[1]==ESC_OPERATOR){
|
|---|
| 99 | if((BYTE)temp[2]==idOperatorCalc){
|
|---|
| 100 | subs.push_back( &userProc );
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | int Methods::GetVtblNum() const
|
|---|
| 107 | {
|
|---|
| 108 | int count = 0;
|
|---|
| 109 | const Methods &methods = *this;
|
|---|
| 110 | BOOST_FOREACH( const CMethod *pMethod, methods )
|
|---|
| 111 | {
|
|---|
| 112 | if( pMethod->IsVirtual() )
|
|---|
| 113 | {
|
|---|
| 114 | count++;
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| 117 | return count;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | void Methods::GenerateVTablePart( long &vtableDataTableOffset ) const
|
|---|
| 121 | {
|
|---|
| 122 | const UserProc **ppsi = (const UserProc **)malloc(GetVtblNum()*sizeof(UserProc *));
|
|---|
| 123 |
|
|---|
| 124 | //関数テーブルに値をセット
|
|---|
| 125 | int i2 = 0;
|
|---|
| 126 | const Methods &methods = *this;
|
|---|
| 127 | BOOST_FOREACH( const CMethod *pMethod, methods ){
|
|---|
| 128 | if(pMethod->IsVirtual()){
|
|---|
| 129 | if( !pMethod->GetUserProc().IsUsing() )
|
|---|
| 130 | {
|
|---|
| 131 | ts((char *)pMethod->GetUserProc().GetFullName().c_str());
|
|---|
| 132 | }
|
|---|
| 133 | pMethod->GetUserProc().Using();
|
|---|
| 134 |
|
|---|
| 135 | if(pMethod->IsAbstract()){
|
|---|
| 136 | SetError();
|
|---|
| 137 |
|
|---|
| 138 | ppsi[i2]=0;
|
|---|
| 139 | }
|
|---|
| 140 | else{
|
|---|
| 141 | ppsi[i2]=&pMethod->GetUserProc();
|
|---|
| 142 | }
|
|---|
| 143 | i2++;
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | vtableDataTableOffset = compiler.GetObjectModule().dataTable.AddBinary( (void *)ppsi, GetVtblNum()*sizeof(LONG_PTR) );
|
|---|
| 148 |
|
|---|
| 149 | for( int i=0; i < GetVtblNum(); i++ ){
|
|---|
| 150 | pobj_Reloc->AddSchedule_DataSection(static_cast<DWORD>(vtableDataTableOffset+i*sizeof(LONG_PTR)));
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | free(ppsi);
|
|---|
| 154 | }
|
|---|