Changeset 332 in dev


Ignore:
Timestamp:
Sep 27, 2007, 3:37:06 AM (17 years ago)
Author:
dai_9181
Message:
 
Location:
trunk/abdev
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler32/Compile_CallProc.cpp

    r325 r332  
    427427void Opcode_CallDelegate( const Delegate &dg, const char *methodPtrValueStr, const char *objPtrValueStr, const char *params )
    428428{
     429    extern BOOL bDebugCompile;
     430    extern BOOL bDebugSupportProc;
     431    if(bDebugCompile&&bDebugSupportProc==0)
     432        Call_DebugSys_SaveContext();
     433
     434
    429435    ///////////////////////////////////////////////////////////////
    430436    // _System_LocalThisのダミーをセット
  • trunk/abdev/BasicCompiler32/Compile_Func.cpp

    r331 r332  
    221221    compiler.codeGenerator.op_mov_RV( REG_EAX, typeSize );
    222222}
    223 void Opcode_Func_AddressOf( const char *name, const Type &baseType ){
    224     extern int cp;
    225     const UserProc *pUserProc;
    226 
    227     if( baseType.IsProcPtr() )
    228     {
    229         //左辺の型にのっとり、オーバーロードを解決
    230 
    231         std::vector<const UserProc *> subs;
    232         GetOverloadSubHash( name, subs );
    233         if( subs.size() == 0 ){
    234             SetError(27,name,cp);
    235             return;
    236         }
    237 
    238         //オーバーロードを解決
    239         pUserProc=OverloadSolution(name,subs,compiler.GetObjectModule().meta.GetProcPointers()[baseType.GetIndex()]->Params(), Type() );
    240 
    241         if(!pUserProc){
    242             SetError(27,name,cp);
    243             return;
    244         }
    245     }
    246     else{
    247         pUserProc=GetSubHash(name);
    248         if(!pUserProc){
    249             SetError(27,name,cp);
    250             return;
    251         }
    252     }
    253 
    254     if( pUserProc->IsVirtual() ){
     223
     224void _Opcode_Func_AddressOf( const char *methodInstanceName, const UserProc &userProc )
     225{
     226    if( userProc.IsVirtual() ){
    255227        ///////////////////////////////
    256228        // 仮想関数の場合
     
    262234        char ObjectName[VN_SIZE];
    263235        ReferenceKind referenceKind;
    264         SplitObjectName(name,ObjectName, referenceKind );
     236        SplitObjectName( methodInstanceName, ObjectName, referenceKind );
    265237
    266238        if(ObjectName[0]){
     
    305277        compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EDX, REG_ECX, 0, MOD_BASE );
    306278
    307         int i2 = pobj_c->GetFuncNumInVtbl( pUserProc );
     279        int i2 = pobj_c->GetFuncNumInVtbl( &userProc );
    308280
    309281        //mov eax,dword ptr[edx+func_index]
     
    319291
    320292        //mov eax,ProcAddr
    321         compiler.codeGenerator.op_addressof( REG_EAX, pUserProc );
    322     }
    323 
    324     pUserProc->Using();
     293        compiler.codeGenerator.op_addressof( REG_EAX, &userProc );
     294    }
     295
     296    userProc.Using();
     297}
     298void Opcode_CreateSimpleDelegate( const char *methodInstanceName, const UserProc &userProc )
     299{
     300    /////////////////////////////////////////////////////////////////
     301    // 関数ポインタをpush
     302    /////////////////////////////////////////////////////////////////
     303
     304    //push AddressOf(userProc)
     305    _Opcode_Func_AddressOf( methodInstanceName, userProc );
     306    compiler.codeGenerator.op_push( REG_EAX );
     307
     308
     309    /////////////////////////////////////////////////////////////////
     310    // オブジェクト ポインタをpush
     311    /////////////////////////////////////////////////////////////////
     312
     313    // オブジェクト名を取得
     314    char objectName[VN_SIZE];
     315    char memberName[VN_SIZE];
     316    char *thisPtrName = "This";
     317    Type type;
     318    if( SplitMemberName( methodInstanceName, objectName, memberName ) )
     319    {
     320        if( GetVarType( objectName, type, false ) )
     321        {
     322            thisPtrName = objectName;
     323        }
     324    }
     325
     326    // オブジェクト ポインタを取得
     327    RELATIVE_VAR relativeVar;
     328    GetVarOffsetReadOnly( thisPtrName, &relativeVar, type );
     329    if( !type.IsObject() )
     330    {
     331        extern int cp;
     332        SetError(1,NULL,cp);
     333        return;
     334    }
     335
     336    SetVarPtrToEax( &relativeVar );
     337
     338    //mov eax,dword ptr[eax]
     339    compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EAX, 0, MOD_BASE );
     340
     341    //push this
     342    compiler.codeGenerator.op_push( REG_EAX );
     343
     344
     345    /////////////////////////////////////////////////////////////////
     346    // call _System_CreateSimpleDynamicDelegate
     347    /////////////////////////////////////////////////////////////////
     348
     349    // call _System_CreateSimpleDynamicDelegate
     350    extern const UserProc *pSub_System_CreateSimpleDynamicDelegate;
     351    compiler.codeGenerator.op_call( pSub_System_CreateSimpleDynamicDelegate );
     352}
     353void Opcode_Func_AddressOf( const char *name, const Type &baseType, bool isCallOn, Type &resultType ){
     354    extern int cp;
     355    const UserProc *pUserProc;
     356
     357    const Parameters *pBaseParams = NULL;
     358    bool isDelegate = false;
     359    if( baseType.IsProcPtr() )
     360    {
     361        // 左辺で関数ポインタを要求されているとき
     362        pBaseParams = &compiler.GetObjectModule().meta.GetProcPointers()[baseType.GetIndex()]->Params();
     363    }
     364    else if( baseType.IsObject() && baseType.GetClass().GetName() == "_SimpleDelegate" )
     365    {
     366        extern const Delegate *pConstructingDelegate;
     367        if( !pConstructingDelegate )
     368        {
     369            SetError();
     370        }
     371        // 左辺でデリゲートを要求されているとき
     372        pBaseParams = &pConstructingDelegate->Params();
     373
     374        isDelegate = true;
     375    }
     376
     377    if( pBaseParams )
     378    {
     379        //左辺の型にのっとり、オーバーロードを解決
     380
     381        std::vector<const UserProc *> subs;
     382        GetOverloadSubHash( name, subs );
     383        if( subs.size() == 0 ){
     384            SetError(27,name,cp);
     385            return;
     386        }
     387
     388        //オーバーロードを解決
     389        pUserProc=OverloadSolution( name, subs, *pBaseParams, Type() );
     390
     391        if(!pUserProc){
     392            SetError(27,name,cp);
     393            return;
     394        }
     395    }
     396    else{
     397        pUserProc=GetSubHash(name);
     398        if(!pUserProc){
     399            SetError(27,name,cp);
     400            return;
     401        }
     402    }
     403
     404    if( isDelegate )
     405    {
     406        if( isCallOn )
     407        {
     408            // デリゲートのとき
     409            Opcode_CreateSimpleDelegate( name, *pUserProc );
     410        }
     411        resultType = baseType;
     412    }
     413    else
     414    {
     415        if( isCallOn )
     416        {
     417            // 関数ポインタのとき
     418            _Opcode_Func_AddressOf( name, *pUserProc );
     419        }
     420        resultType.SetBasicType( DEF_PTR_VOID );
     421    }
    325422}
    326423void Opcode_Func_SizeOf( const string &typeName ){
     
    493590            break;
    494591        case FUNC_ADDRESSOF:
    495             if( isCallOn ) Opcode_Func_AddressOf( Parameter, baseType );
    496             resultType.SetBasicType( DEF_PTR_VOID );
     592            Opcode_Func_AddressOf( Parameter, baseType, isCallOn, resultType );
    497593            break;
    498594        case FUNC_SIZEOF:
  • trunk/abdev/BasicCompiler32/Compile_Object.cpp

    r319 r332  
    1616    //をセットしておかなければならない
    1717
     18
     19    const Delegate *pBackConstructingDelegate;
     20    if( pobj_c->IsDelegate() )
     21    {
     22        // デリゲートの場合はオーバーロード解決用のグローバル変数をセットする
     23        extern const Delegate *pConstructingDelegate;
     24        pBackConstructingDelegate = pConstructingDelegate;
     25        pConstructingDelegate = &pobj_c->GetDelegate();
     26    }
     27
     28
    1829/*  //jnzのジャンプ先番地
    1930    extern int obp;
     
    95106        */
    96107    }
     108
     109    if( pobj_c->IsDelegate() )
     110    {
     111        // デリゲートの場合はオーバーロード解決用のグローバル変数を元に戻す
     112        extern const Delegate *pConstructingDelegate;
     113        pConstructingDelegate = pBackConstructingDelegate;
     114    }
    97115}
    98116void Operator_New( const CClass &classObj, const char *objectSizeStr, const char *parameter, const Type &baseType ){
  • trunk/abdev/BasicCompiler32/MakePeHdr.cpp

    r322 r332  
    4242    *pSub_System_GC_free_for_SweepingDelete,
    4343    *pSubStaticMethod_System_TypeBase_InitializeUserTypes,
     44    *pSub_System_CreateSimpleDynamicDelegate,
    4445
    4546    *pSub_allrem,
     
    283284        pSubStaticMethod_System_TypeBase_InitializeUserTypes->ThisIsAutoGenerationProc();
    284285    }
     286
     287    pSub_System_CreateSimpleDynamicDelegate = GetSubHash( "_System_CreateSimpleDynamicDelegate", TRUE );
    285288
    286289    if( pUserProc_System_CGarbageCollection_RegisterGlobalRoots = GetClassMethod( "_System_CGarbageCollection", "RegisterGlobalRoots" ) ){
  • trunk/abdev/BasicCompiler_Common/BasicCompiler.h

    r331 r332  
    6161
    6262
     63//デリゲートのベース タイプ インデックス(コンストラクトされるデリゲートのパラメータを参考に、オーバーロードを解決)
     64const Delegate *pConstructingDelegate;
     65
     66
    6367int cp;
    6468
  • trunk/abdev/BasicCompiler_Common/Intermediate_Step1.cpp

    r327 r332  
    88#include "../BasicCompiler_Common/common.h"
    99
    10 void ChangeReturnCode(char *buffer){
     10void ChangeReturnCode(char *buffer)
     11{
     12    int i;
     13
     14    bool isMustChange = false;
     15    for( i=0; ; i++ ){
     16        if( buffer[i] == '\0' ){
     17            break;
     18        }
     19        if( buffer[i]=='\n' )
     20        {
     21            if( i>0 )
     22            {
     23                if( buffer[i-1] == '\r' )
     24                {
     25                    isMustChange = true;
     26                }
     27            }
     28        }
     29    }
     30
     31    if( !isMustChange )
     32    {
     33        // 改行コードの変換は必要ない
     34        return;
     35    }
    1136
    1237#ifdef _DEBUG
  • trunk/abdev/BasicCompiler_Common/Subroutine.cpp

    r331 r332  
    7777    }
    7878
    79     if( type.IsObject() && type.GetClass().IsDelegate() )
     79    if( type.IsDelegate() )
    8080    {
    8181        // デリゲート
  • trunk/abdev/BasicCompiler_Common/include/Type.h

    r301 r332  
    188188    bool IsVoidPtr() const;
    189189    bool IsAny() const;
     190    bool IsDelegate() const;
    190191
    191192    // オブジェクトや構造体など、メンバを持つ型かどうかを判別する
  • trunk/abdev/BasicCompiler_Common/src/Type.cpp

    r316 r332  
    442442    }
    443443    return false;
     444}
     445
     446bool Type::IsDelegate() const
     447{
     448    return ( IsObject() && GetClass().IsDelegate() );
    444449}
    445450
Note: See TracChangeset for help on using the changeset viewer.