Changeset 436 in dev


Ignore:
Timestamp:
Mar 15, 2008, 3:33:36 PM (16 years ago)
Author:
dai_9181
Message:

関数の戻り値の構造体など、一時メモリに保持された構造体のメンバに直接アクセスした場合、その一時メモリの解放が正常に行われないバグを修正(64bit版も修正した)。

Location:
trunk/abdev
Files:
15 edited

Legend:

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

    r435 r436  
    6565                //変数ではないとき
    6666                Type calcType;
    67                 BOOL bUseHeap;
    68                 NumOpe( Parms[i2], dummyType, calcType, &bUseHeap );
     67                bool isNeedHeapFreeStructure;
     68                NumOpe( Parms[i2], dummyType, calcType, &isNeedHeapFreeStructure );
    6969                //↑ここでスタックに積む
    7070
     
    8686                    i2);
    8787
    88                 if( result && bUseHeap ){
     88                if( result )
     89                {
    8990                    useTempParameters[i2] = true;
     91                    isNeedFreeStructures[i2] = true;
    9092                    useTempObject = true;
    9193
     
    107109    for(int i2=ParmsNum-1;i2>=0;i2--){
    108110        if( useTempParameters[i2] ){
    109             if( types[i2].IsStruct() ){
     111            if( types[i2].IsStruct() )
     112            {
    110113                // 構造体の一時メモリ
    111114
    112                 //メモリを解放する
    113 
    114                 //call free
    115                 extern const UserProc *pSub_free;
    116                 compiler.codeGenerator.op_call(pSub_free);
    117             }
    118             else{
    119                 if( types[i2].Is64() ){
     115                if( isNeedFreeStructures[i2] )
     116                {
     117                    //メモリを解放する
     118
     119                    //call free
     120                    extern const UserProc *pSub_free;
     121                    compiler.codeGenerator.op_call(pSub_free);
     122                }
     123                else
     124                {
     125                    //pop ... 参照を消す
     126                    compiler.codeGenerator.op_add_esp( PTR_SIZE );
     127                }
     128            }
     129            else
     130            {
     131                if( types[i2].Is64() )
     132                {
    120133                    //pop ... 参照を消す
    121134                    //pop ... 上位32ビット
     
    123136                    compiler.codeGenerator.op_add_esp( PTR_SIZE * 3 );
    124137                }
    125                 else{
     138                else
     139                {
    126140                    //pop ... 参照を消す
    127141                    //pop ... 値を消す
     
    150164
    151165    Type calcType;
    152     BOOL bUseHeap;
     166    bool isNeedHeapFreeStructure;
    153167    NumOpe( expression,
    154168        baseType,
    155169        calcType,
    156         &bUseHeap );
     170        &isNeedHeapFreeStructure );
    157171
    158172    // ※スタックにある二つのデータ(コピー先、コピー元)の値を必要とする
    159     SetStructVariable( baseType, calcType, bUseHeap );
     173    SetStructVariable( baseType, calcType, isNeedHeapFreeStructure );
    160174}
    161175
     
    234248            }
    235249
    236             BOOL bCalcUseHeap;
    237250            Type calcType;
    238             if( !NumOpe( Parms[i2], dummyType, calcType, &bCalcUseHeap ) ){
     251            bool isNeedHeapFreeStructure;
     252            if( !NumOpe( Parms[i2], dummyType, calcType, &isNeedHeapFreeStructure ) )
     253            {
    239254                break;
    240255            }
    241256
    242             if( calcType.IsObject() ){
     257            if( calcType.IsObject() )
     258            {
    243259                if( !dummyType.IsObject()
    244260                    ||
    245261                    dummyType.IsObject() &&
    246                     !dummyType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) ){
     262                    !dummyType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) )
     263                {
    247264                        //キャスト演算子のオーバーロードに対応する
    248                         CallCastOperatorProc( calcType, bCalcUseHeap,dummyType );
     265                        CallCastOperatorProc( calcType, isNeedHeapFreeStructure,dummyType );
    249266                }
    250267            }
  • trunk/abdev/BasicCompiler32/Compile_Calc.cpp

    r435 r436  
    573573
    574574    //NumOpe...(スタックに答えが格納される)
    575     BOOL bCalcUseHeap;
    576575    Type calcType;
    577     if( !NumOpe(Command+i+1,varType,calcType,&bCalcUseHeap) ){
     576    bool isNeedHeapFreeStructure;
     577    if( !NumOpe(Command+i+1,varType,calcType,&isNeedHeapFreeStructure) ){
    578578        return;
    579579    }
     
    588588        if( !isUpCast ){
    589589            //キャスト演算子のオーバーロードに対応する
    590             CallCastOperatorProc(calcType,bCalcUseHeap,varType);
     590            CallCastOperatorProc(calcType,isNeedHeapFreeStructure,varType);
    591591        }
    592592    }
     
    606606    if( varType.IsStruct() ){
    607607        //構造体インスタンスへの代入
    608         SetStructVariable(varType,calcType,bCalcUseHeap);
     608        SetStructVariable(varType,calcType,isNeedHeapFreeStructure);
    609609        return;
    610610    }
  • trunk/abdev/BasicCompiler32/Compile_Var.cpp

    r424 r436  
    116116    for(i=i3-1;i>=0;i--){
    117117        Type tempType;
    118         BOOL bUseHeap;
    119         NumOpe( pParm[i], Type( DEF_LONG ), tempType, &bUseHeap );
    120         if( tempType.IsObject() ){
     118        bool isNeedHeapFreeStructure;
     119        NumOpe( pParm[i], Type( DEF_LONG ), tempType, &isNeedHeapFreeStructure );
     120        if( tempType.IsObject() )
     121        {
    121122            //キャスト演算子のオーバーロードに対応する
    122123            CallCastOperatorProc(
    123124                tempType,
    124                 bUseHeap, Type(DEF_LONG) );
     125                isNeedHeapFreeStructure, Type(DEF_LONG) );
    125126            tempType.SetBasicType( DEF_LONG );
    126127        }
     
    130131        compiler.codeGenerator.op_pop(REG_EAX);
    131132
    132         for(i2=i+1,i4=1;i2<i3;i2++) i4*=subscripts[i2]+1;
     133        for( i2=i+1, i4=1; i2<i3; i2++ )
     134        {
     135            i4*=subscripts[i2]+1;
     136        }
    133137
    134138        //imul eax,i4
  • trunk/abdev/BasicCompiler32/NumOpe.cpp

    r435 r436  
    671671            const Type &baseType,
    672672            Type &resultType,
    673             BOOL *pbUseHeap ){
    674 
    675     if( !NumOpe( expression, baseType, resultType, pbUseHeap ) ){
     673            bool *pbIsNeedHeapFreeStructure ){
     674
     675    if( !NumOpe( expression, baseType, resultType, pbIsNeedHeapFreeStructure ) )
     676    {
    676677        return false;
    677678    }
     
    703704            const Type &baseType,
    704705            Type &resultType,
    705             BOOL *pbUseHeap )
     706            bool *pbIsNeedHeapFreeStructure )
    706707{
    707708    int i,i2,i3;
     
    12741275    }
    12751276
    1276     if(pbUseHeap) *pbUseHeap = isNeedHeapFreeStructureStack[0];
     1277    if(pbIsNeedHeapFreeStructure)
     1278    {
     1279        *pbIsNeedHeapFreeStructure = isNeedHeapFreeStructureStack[0];
     1280    }
    12771281
    12781282    resultType.SetType( type_stack[0], index_stack[0] );
  • trunk/abdev/BasicCompiler32/Opcode.h

    r435 r436  
    7373            const Type &baseType,
    7474            Type &resultType,
    75             BOOL *pbUseHeap = NULL );
     75            bool *pbIsNeedHeapFreeStructure = NULL );
    7676bool NumOpe( const char *Command,
    7777           const Type &baseType,
    7878           Type &resultType,
    79            BOOL *pbUseHeap = NULL );
     79           bool *pbIsNeedHeapFreeStructure = NULL );
    8080
    8181//NumOpe_Arithmetic.cpp
     
    177177    bool useTempObject;
    178178    bool useTempParameters[255];
     179    bool isNeedFreeStructures[255];
    179180    int nCountOfTempObjects;
    180181
  • trunk/abdev/BasicCompiler64/CParameter.cpp

    r331 r436  
    6565                int reg = REG_RAX;
    6666                Type calcType;
    67                 NumOpe( &reg, Parms[i2], dummyType, calcType );
     67                bool isNeedHeapFreeStructure;
     68                NumOpe( &reg, Parms[i2], dummyType, calcType, &isNeedHeapFreeStructure );
    6869
    6970                if( !calcType.IsStruct() ){
     
    8687                    i2);
    8788
    88                 if( result ){
     89                if( result )
     90                {
    8991                    useTempParameters[i2] = true;
     92                    isNeedFreeStructures[i2] = isNeedHeapFreeStructure;
    9093                    useTempObject = true;
    9194
     
    109112                // 構造体の一時メモリ
    110113
    111                 //メモリを解放する
    112 
    113                 pobj_sf->pop( REG_RCX );
    114 
    115                 //call free
    116                 extern const UserProc *pSub_free;
    117                 compiler.codeGenerator.op_call(pSub_free);
    118             }
    119             else{
     114                if( isNeedFreeStructures[i2] )
     115                {
     116                    //メモリを解放する
     117
     118                    pobj_sf->pop( REG_RCX );
     119
     120                    //call free
     121                    extern const UserProc *pSub_free;
     122                    compiler.codeGenerator.op_call(pSub_free);
     123                }
     124                else
     125                {
     126                    pobj_sf->pop();
     127                }
     128            }
     129            else
     130            {
    120131                pobj_sf->pop();
    121132                pobj_sf->pop();
     
    148159
    149160        Type calcType;
    150         BOOL bUseHeap;
     161        bool isNeedHeapFreeStructure;
    151162        int temp_reg=REG_RAX;
    152163        NumOpe( &temp_reg,
     
    154165            baseType,
    155166            calcType,
    156             &bUseHeap );
     167            &isNeedHeapFreeStructure );
    157168
    158169
     
    169180            baseType,
    170181            calcType,
    171             &RelativeVar,bUseHeap);
     182            &RelativeVar,isNeedHeapFreeStructure);
    172183
    173184
     
    282293            temp_reg=reg;
    283294
    284             BOOL bCalcUseHeap;
    285295            Type calcType;
    286             if( !NumOpe( &temp_reg, Parms[i2], dummyType, calcType, &bCalcUseHeap ) ){
     296            bool isNeedHeapFreeStructure;
     297            if( !NumOpe( &temp_reg, Parms[i2], dummyType, calcType, &isNeedHeapFreeStructure ) ){
    287298                break;
    288299            }
     
    294305                    !dummyType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) ){
    295306                        //キャスト演算子のオーバーロードに対応する
    296                         CallCastOperatorProc( reg, calcType, bCalcUseHeap,dummyType );
     307                        CallCastOperatorProc( reg, calcType, isNeedHeapFreeStructure,dummyType );
    297308                }
    298309            }
  • trunk/abdev/BasicCompiler64/Compile_Calc.cpp

    r417 r436  
    190190    //NumOpe...(rax、またはxmm0に答えが格納される)
    191191    int reg=REG_RAX;
    192     BOOL bCalcUseHeap;
    193192    Type calcType;
    194     if( !NumOpe(&reg,Command+i+1,varType,calcType,&bCalcUseHeap) ){
     193    bool isNeedHeapFreeStructure;
     194    if( !NumOpe(&reg,Command+i+1,varType,calcType,&isNeedHeapFreeStructure) ){
    195195        return;
    196196    }
     
    222222    if( varType.IsStruct() ){
    223223        //構造体インスタンスへの代入
    224         SetStructVariableFromRax(varType,calcType,&VarRelativeVar,bCalcUseHeap);
     224        SetStructVariableFromRax(varType,calcType,&VarRelativeVar,isNeedHeapFreeStructure);
    225225        return;
    226226    }
     
    235235        if( !isUpCast ){
    236236            //キャスト演算子のオーバーロードに対応する
    237             CallCastOperatorProc(REG_RAX,calcType,bCalcUseHeap,varType);
     237            CallCastOperatorProc(REG_RAX,calcType,isNeedHeapFreeStructure,varType);
    238238        }
    239239    }
     
    269269    /////////////////////////////////////////////////
    270270    SetVariableFromRax(varType,calcType.GetBasicType(),&VarRelativeVar);
     271
     272
     273    // コード生成過程で発生した構造体の一時メモリを破棄する
     274    compiler.codeGenerator.op_FreeTempStructure();
    271275}
  • trunk/abdev/BasicCompiler64/Compile_CallProc.cpp

    r420 r436  
    322322            if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember;
    323323            else{
    324                 bool isLiteral;
     324                bool isLiteral, isNeedHeapFreeStructure = false;
    325325                Type baseType( DEF_OBJECT, *pUserProc->GetParentClassPtr() ) , resultType;
    326                 if( !TermOpe( ObjectName, baseType, resultType, isLiteral, NULL, NULL, false, !pMethod->IsConst() ) )
     326                if( !TermOpe( ObjectName, baseType, resultType, isLiteral, isNeedHeapFreeStructure, NULL, false, !pMethod->IsConst() ) )
    327327                {
    328328                    return false;
     329                }
     330                if( !resultType.IsObject() )
     331                {
     332                    SetError();
    329333                }
    330334
  • trunk/abdev/BasicCompiler64/Compile_Statement.cpp

    r425 r436  
    9595
    9696    Type resultType;
    97     bool isLiteral;
    98     BOOL bUseHeap;
    99     bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, NULL, true );
     97    bool isLiteral, isNeedHeapFreeStructure = false;
     98    bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, isNeedHeapFreeStructure, NULL, true );
    10099
    101100    delete pobj_reg;
  • trunk/abdev/BasicCompiler64/Compile_Var.cpp

    r425 r436  
    142142        int reg=REG_NON;
    143143        Type type;
    144         BOOL bUseHeap;
    145         NumOpe( &reg, pParm[i], Type( DEF_LONG ), type, &bUseHeap );
    146         if( type.IsObject() ){
     144        bool isNeedHeapFreeStructure;
     145        NumOpe( &reg, pParm[i], Type( DEF_LONG ), type, &isNeedHeapFreeStructure );
     146        if( type.IsObject() )
     147        {
    147148            //キャスト演算子のオーバーロードに対応する
    148149            CallCastOperatorProc(reg,
    149150                type,
    150                 bUseHeap, Type(DEF_LONG) );
     151                isNeedHeapFreeStructure, Type(DEF_LONG) );
    151152            type.SetBasicType( DEF_LONG );
    152153        }
    153154
    154         if( !type.IsWhole() ){
     155        if( !type.IsWhole() )
     156        {
    155157            SetError(46,NULL,cp);
    156158        }
  • trunk/abdev/BasicCompiler64/MakePeHdr.cpp

    r423 r436  
    3333    *pSub_System_GC_malloc_ForObjectPtr,
    3434    *pSub_System_GC_free_for_SweepingDelete,
     35    *pSub_System_AddNeedFreeTempStructure,
     36    *pSub_System_FreeTempStructure,
    3537    *pSubStaticMethod_System_TypeBase_InitializeUserTypes,
    3638    *pSubStaticMethod_System_TypeBase_InitializeUserTypesForBaseType;
     
    266268    if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) )
    267269        pSub_System_GC_free_for_SweepingDelete->Using();
     270
     271    if( pSub_System_AddNeedFreeTempStructure = GetSubHash( "_System_AddNeedFreeTempStructure",1 ) )
     272    {
     273        pSub_System_AddNeedFreeTempStructure->Using();
     274    }
     275    if( pSub_System_FreeTempStructure = GetSubHash( "_System_FreeTempStructure",1 ) )
     276    {
     277        pSub_System_FreeTempStructure->Using();
     278    }
    268279
    269280    if( pSubStaticMethod_System_TypeBase_InitializeUserTypes = GetSubHash( "ActiveBasic.Core._System_TypeBase.InitializeUserTypes",1 ) ){
  • trunk/abdev/BasicCompiler64/NumOpe.cpp

    r430 r436  
    130130    return true;
    131131}
    132 bool TermMemberOpe( const Type &leftType, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar )
     132bool TermMemberOpe( const Type &leftType, bool &isNeedHeapFreeStructure, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar )
    133133{
    134134    const CClass &objClass = leftType.GetClass();
     
    218218        // メンバが見つかったとき
    219219
     220        if( isNeedHeapFreeStructure )
     221        {
     222            if( !leftType.IsStruct() )
     223            {
     224                SetError();
     225            }
     226
     227            pobj_reg->LockReg();
     228
     229            // 親となる構造体が一時メモリに存在していた場合、後ほど解放する必要がある
     230            compiler.codeGenerator.op_AddNeedFreeTempStructure( useReg );
     231            isNeedHeapFreeStructure = false;
     232
     233            pobj_reg->UnlockReg();
     234        }
     235
    220236        //オブジェクトポインタをr11にコピー
    221237        compiler.codeGenerator.op_mov_RR( REG_R11, useReg );
     
    267283                bool dummyIsVariable;
    268284                RELATIVE_VAR dummyRelativeVar;
    269                 TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar );
     285                TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar );
    270286
    271287                // 戻り値のオブジェクトインスタンスのインデクサを呼び出す
     
    274290                sprintf( temp2, "%s.%s", termLeft, methodName );
    275291                Type classType = resultType;
    276                 return TermMemberOpe( classType, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar );
     292                return TermMemberOpe( classType, isNeedHeapFreeStructure, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar );
    277293            }
    278294
     
    344360    return false;
    345361}
    346 bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess )
     362bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess )
    347363{
    348364    char parameter[VN_SIZE];
     
    385401        }
    386402
    387         if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){
     403        if( !TermOpe( termLeft, baseType, leftType, isLiteral, isNeedHeapFreeStructure, &isClassName ) ){
    388404            goto globalArea;
    389405        }
     
    403419        }
    404420
    405         return TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar );
     421        return TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar );
    406422    }
    407423globalArea:
     
    500516            }////////////////////////////////////////////
    501517
    502             if(resultType.IsStruct()){
     518            if(resultType.IsStruct())
     519            {
    503520                //構造体が戻ったときはヒープ領域にインスタンスが格納されている
    504521                //※後にfreeする必要あり
    505522                // TODO: 解放はGCに任せる
    506                 *pbUseHeap = 1;
     523                isNeedHeapFreeStructure = true;
    507524            }
    508525
     
    628645        }////////////////////////////////////////////
    629646
    630         if(resultType.IsStruct()){
     647        if(resultType.IsStruct())
     648        {
    631649            //構造体が戻ったときはヒープ領域にインスタンスが格納されている
    632650            //※後にfreeする必要あり
    633651            // TODO: 解放はGCに任せる
    634             *pbUseHeap = 1;
     652            isNeedHeapFreeStructure = true;
    635653        }
    636654
     
    648666}
    649667
    650 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess )
     668bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess )
    651669{
    652670    bool isInitRegSwitch = false;
     
    665683    RELATIVE_VAR relativeVar;
    666684    bool isVariable = false;
    667     bool result = _TermOpe( term, baseType, resultType, isLiteral, pbUseHeap, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess );
     685    bool result = _TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructure, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess );
    668686
    669687    if( isVariable )
     
    705723    pobj_reg = new CRegister( REG_NON );
    706724
    707     bool isLiteral, isVariable = false;
    708     bool result = _TermOpe( term, Type(), resultType, isLiteral, NULL, NULL, false, isVariable, relativeVar, isWriteAccess );
     725    bool isLiteral, isVariable = false, isNeedHeapFreeStructure = false;
     726    bool result = _TermOpe( term, Type(), resultType, isLiteral, isNeedHeapFreeStructure, NULL, false, isVariable, relativeVar, isWriteAccess );
    709727
    710728    if( !isVariable )
     
    731749            const Type &baseType,
    732750            Type &resultType,
    733             BOOL *pbUseHeap )
     751            bool *pbIsNeedHeapFreeStructure )
    734752{
    735753    int i,i2,i3;
     
    892910    LONG_PTR index_stack[255];
    893911    bool isNothing_stack[255];
    894     BOOL bUseHeap[255];
     912    bool isNeedHeapFreeStructureStack[255];
    895913    _int64 i64data;
    896914    int UseReg,XmmReg;
     
    916934                else{
    917935                    //オーバーロードされたオペレータを呼び出す
    918                     i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,bUseHeap,sp);
     936                    i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,isNeedHeapFreeStructureStack,sp);
    919937                    if(i2==0){
    920938                        if(idCalc==CALC_EQUAL) lstrcpy(temp2,"==");
     
    938956                index_stack[sp]=-1;
    939957                isNothing_stack[sp] = false;
    940                 bUseHeap[sp]=0;
     958                isNeedHeapFreeStructureStack[sp] = false;
    941959
    942960                UseReg=pobj_reg->GetNextReg();
     
    10411059
    10421060                    bool isLiteral;
    1043                     if( TermOpe( term, baseType, resultType, isLiteral, &bUseHeap[sp] ) ){
     1061                    if( TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructureStack[sp] ) ){
    10441062                        if(resultType.IsNull()){
    10451063                            //戻り値が存在しないとき
     
    13461364    }
    13471365
    1348     if(pbUseHeap) *pbUseHeap=bUseHeap[0];
     1366    if( pbIsNeedHeapFreeStructure )
     1367    {
     1368        *pbIsNeedHeapFreeStructure = isNeedHeapFreeStructureStack[0];
     1369    }
    13491370
    13501371    if(IsRealNumberType(type_stack[0]))
     
    13861407            const Type &baseType,
    13871408            Type &resultType,
    1388             BOOL *pbUseHeap )
     1409            bool *pbIsNeedHeapFreeStructure )
    13891410{
    13901411    bool isInitRegSwitch = false;
     
    14031424
    14041425
    1405     bool result = _numope( pReg, expression, baseType, resultType, pbUseHeap );
     1426    bool result = _numope( pReg, expression, baseType, resultType, pbIsNeedHeapFreeStructure );
    14061427
    14071428
  • trunk/abdev/BasicCompiler64/Opcode.h

    r425 r436  
    191191             Type &resultType,
    192192             bool &isLiteral,
    193              BOOL *pbUseHeap,
     193             bool &isNeedHeapFreeStructure,
    194194             bool *pIsClassName = NULL,
    195195             bool isProcedureCallOnly = false,
     
    199199           const Type &baseType,
    200200           Type &resultType,
    201            BOOL *pbUseHeap = NULL );
     201           bool *pbIsNeedHeapFreeStructure = NULL );
    202202
    203203//NumOpe_Arithmetic.cpp
     
    276276    bool useTempObject;
    277277    bool useTempParameters[255];
     278    bool isNeedFreeStructures[255];
    278279    int StackOffsetOfTempObject[255];
    279280
     
    337338//OperatorProc.cpp
    338339void FreeTempObject(int reg,const CClass *pobj_c);
    339 int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp);
     340int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,bool isNeedHeapFreeStructureStack[],int &sp);
    340341void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType);
    341342void CallIndexerGetterProc(int reg, const Type &classType, const char *ObjectName,char *Parameter,Type &resultType, DWORD dwProcFlags = 0 );
  • trunk/abdev/BasicCompiler64/OperatorProc.cpp

    r425 r436  
    3131}
    3232
    33 int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,BOOL *bUseHeap,int &sp)
     33int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,bool isNeedHeapFreeStructureStack[],int &sp)
    3434{
    3535    Type leftType( type_stack[sp-2], index_stack[sp-2] );
     
    101101        if( pUserProc->RealParams()[1]->IsStruct() &&pUserProc->RealParams()[1]->IsRef() == false ){
    102102            //一時オブジェクトはメソッド内で破棄される
    103             bUseHeap[sp-1]=0;
     103            isNeedHeapFreeStructureStack[sp-1] = false;
    104104        }
    105105    }
     
    153153
    154154    //ヒープ解放用に退避
    155     if(bUseHeap[sp-1]){
     155    if(isNeedHeapFreeStructureStack[sp-1]){
    156156        //mov qword ptr[rsp+offset],reg2     ※スタックフレームを利用
    157157        pobj_sf->push(reg2);
    158158    }
    159     if(bUseHeap[sp-2]){
     159    if(isNeedHeapFreeStructureStack[sp-2]){
    160160        //mov qword ptr[rsp+offset],reg1     ※スタックフレームを利用
    161161        pobj_sf->push(reg1);
     
    213213
    214214
    215     if(bUseHeap[sp-2]||bUseHeap[sp-1]){
    216 
     215    if( isNeedHeapFreeStructureStack[sp-2] || isNeedHeapFreeStructureStack[sp-1] )
     216    {
    217217        //////////////////////////////////////////////////////
    218218        /////    レジスタ資源のバックアップ
     
    220220        //////////////////////////////////////////////////////
    221221
    222             if(bUseHeap[sp-2]){
     222            if( isNeedHeapFreeStructureStack[sp-2] )
     223            {
    223224                //mov r14,qword ptr[rsp+offset]     ※スタックフレームを利用
    224225                pobj_sf->pop(REG_R14);
     
    226227                FreeTempObject(REG_R14,(CClass *)index_stack[sp-2]);
    227228            }
    228             if(bUseHeap[sp-1]){
     229            if( isNeedHeapFreeStructureStack[sp-1] )
     230            {
    229231                //mov r14,qword ptr[rsp+offset]     ※スタックフレームを利用
    230232                pobj_sf->pop(REG_R14);
     
    258260    index_stack[sp-1]=pUserProc->ReturnType().GetIndex();
    259261
    260     if( pUserProc->ReturnType().IsStruct() ){
     262    if( pUserProc->ReturnType().IsStruct() )
     263    {
    261264        //構造体が戻ったときはヒープ領域にインスタンスが格納されている
    262265        //※後にfreeする必要あり
    263         bUseHeap[sp-1]=1;
    264     }
    265     else bUseHeap[sp-1]=0;
     266        isNeedHeapFreeStructureStack[sp-1] = true;
     267    }
     268    else
     269    {
     270        isNeedHeapFreeStructureStack[sp-1] = false;
     271    }
    266272
    267273    return 1;
     
    271277    int type_stack[10];
    272278    LONG_PTR index_stack[10];
    273     BOOL array_bUseHeap[10];
     279    bool array_bUseHeap[10];
    274280    int sp=2;
    275281    int iRet;
  • trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp

    r435 r436  
    22
    33#include <CodeGenerator.h>
     4
     5#ifdef _AMD64_
     6#include "../../BasicCompiler64/opcode.h"
     7#else
     8#include "../../BasicCompiler32/opcode.h"
     9#endif
    410
    511
     
    313319    //////////////////////////////////////////////////////
    314320
    315     //mov rcx,reg
    316     compiler.codeGenerator.op_mov_RR( REG_RCX, reg );
    317 
    318     //call _System_AddNeedFreeTempStructure
    319     extern const UserProc *pSub_System_AddNeedFreeTempStructure;
    320     compiler.codeGenerator.op_call( pSub_System_AddNeedFreeTempStructure );
     321        //mov rcx,reg
     322        op_mov_RR( REG_RCX, reg );
     323
     324        //call _System_AddNeedFreeTempStructure
     325        extern const UserProc *pSub_System_AddNeedFreeTempStructure;
     326        op_call( pSub_System_AddNeedFreeTempStructure );
    321327
    322328    /////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.