ptreedec.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,078 行 · 第 1/3 页

C
1,078
字号
    }
    return expr;
}


static PTREE dtorDecorate       // DTOR DECORATION
    ( PTREE expr                // - expression
    , SYMBOL dtor               // - destructor
    , PTD_KIND kind )           // - decorative kind
{
    if( dtor != NULL ) {
        FunctionHasRegistration();
        expr = FunctionCalled( expr, dtor );
        expr = ptdSymbol( expr, dtor, kind );
    }
    return expr;
}


PTREE PtdCtoredComponent        // CTORED COMPONENT (BASE OR ELEMENT)
    ( PTREE expr                // - expression
    , TYPE type )               // - type of component
{
    return dtorDecorate( expr, dtorForType( type ), PTD_CTORED_COMP );
}


PTREE PtdDtorScopeSym           // DTOR OF SCOPE (SYMBOL)
    ( PTREE expr                // - expression
    , SYMBOL dtor )             // - destructor
{
    return dtorDecorate( expr, dtor, PTD_DTOR_SCOPE );
}


PTREE PtdDtorScopeType          // DTOR OF SCOPE (TYPE)
    ( PTREE expr                // - expression
    , TYPE type )               // - type dtored
{
    return PtdDtorScopeSym( expr, dtorForType( type ) );
}


PTREE PtdScopeCall              // SCOPE-CALL RECORDING
    ( PTREE expr                // - expression
    , SYMBOL fun )              // - function/ctor called
{
    if( fun != NULL && ! ( fun->flag & SF_NO_LONGJUMP ) ) {
        expr = ptdSymbol( expr, fun, PTD_SCOPE_CALL );
    }
    return expr;
}


static PTREE exprCtoring        // EXPRESSION CTORING
    ( PTREE expr                // - expression
    , SYMBOL ctor               // - ctor used
    , TYPE cl_type              // - class type
    , PTD_KIND kind )           // - kind of dtoring
{
    boolean ctor_called;        // - TRUE ==> CTOR-call already present
    boolean dtor_decorated;     // - TRUE ==> DTOR decoration present
    PTD* ptd;                   // - current decoration
    SYMBOL dtor;                // - dtor for type

    dtor = dtorForType( cl_type );
    if( dtor != NULL || ctor != NULL ) {
        ctor_called = FALSE;
        dtor_decorated = FALSE;
        RingIterBeg( expr->decor, ptd ) {
          switch( ptd->base.kind ) {
            case PTD_SCOPE_CALL :
              if( ptd->symbol.sym == ctor ) {
                  ctor_called = TRUE;
              }
              break;
            case PTD_DTOR_EXPR :
              DbgVerify( dtor == ptd->symbol.sym
                       , "exprCtoring -- dtor mismatch" );
              ptd->base.kind = kind;
              dtor_decorated = TRUE;
              break;
            case PTD_DTOR_SCOPE :
            case PTD_CTORED_COMP :
              DbgVerify( dtor == ptd->symbol.sym
                       , "exprCtoring -- dtor mismatch" );
              DbgVerify( kind == PTD_DTOR_EXPR
                       , "exprCtoring -- not PTD_EXPR" );
              dtor_decorated = TRUE;
              break;
          }
        } RingIterEnd( ptd );
        if( ! ctor_called ) {
            expr = PtdScopeCall( expr, ctor );
        }
        if( ! dtor_decorated ) {
            expr = dtorDecorate( expr, dtor, kind );
        }
    }
    return expr;
}


PTREE PtdCtoredExprType         // DECORATE TEMP AFTER CTORING
    ( PTREE expr                // - expression
    , SYMBOL ctor               // - ctor used
    , TYPE cl_type )            // - class type
{
    return exprCtoring( expr, ctor, cl_type, PTD_DTOR_EXPR );
}


PTREE PtdCtoredScopeType        // DECORATE AUTO AFTER CTORING
    ( PTREE expr                // - expression
    , SYMBOL ctor               // - ctor used
    , TYPE cl_type )            // - class type
{
    return exprCtoring( expr, ctor, cl_type, PTD_DTOR_SCOPE );
}


PTREE PtdThrow                  // DECORATE TO INDICATE THROW (OR EQUIVALENT)
    ( PTREE expr )              // - expression
{
    return ptdBase( expr, PTD_THROW );
}


PTREE PtdExprConst              // DECORATE A CONSTANT EXPRESSION
    ( PTREE expr )              // - expression
{
    return ptdBase( expr, PTD_EXPR_CONST );
}


static void emitDone            // EMIT CGDONE
    ( void )
{
    CgFrontCode( IC_EXPR_DONE );
}


static void emitCode            // EMIT STAND-ALONE OPCODE
    ( unsigned opcode )         // - opcode
{
    CgFrontCode( opcode );
    emitDone();
}


static void emitCodeUint        // EMIT STAND-ALONE OPCODE + UNSIGNED
    ( unsigned opcode           // - opcode
    , unsigned value )          // - value
{
    CgFrontCodeUint( opcode, value );
    emitDone();
}


PTREE PtdCompCtored             // DECORATE INDICATING COMPONENT CTORED
    ( PTREE expr                // - expression
    , target_offset_t offset    // - offset
    , unsigned dtc_kind )       // - kind of component
{
    if( NULL == expr ) {
        CgFrontCodeUint( IC_DTOR_KIND, dtc_kind );
        emitCodeUint( IC_COMPCTOR_BEG, offset );
        emitCodeUint( IC_COMPCTOR_END, offset );
    } else {
        expr = ptdOffset( expr, dtc_kind, PTD_DTOR_KIND );
        expr = ptdOffset( expr, offset, PTD_CTORCOMP );
    }
    return expr;
}


PTREE PtdObjPush                // DECORATE FOR START OF DTORABLE OBJECT
    ( PTREE expr                // - expression
    , TYPE type                 // - type of object
    , SYMBOL sym                // - NULL or symbol
    , target_offset_t offset )  // - offset
{
    if( NULL == expr ) {
        CgFrontCodePtr( IC_DTOBJ_PUSH, type );
        if( NULL != sym ) {
            CgFrontCodePtr( IC_DTOBJ_SYM, sym );
        }
        emitCodeUint( IC_DTOBJ_OFF, offset );
    } else {
        expr = ptdType( expr, type, PTD_OBJ_PUSH );
        if( NULL != sym ) {
            expr = ptdSymbol( expr, sym, PTD_OBJ_SYM );
        }
        expr = ptdOffset( expr, offset, PTD_OBJ_OFFSET );
    }
    return expr;
}


PTREE PtdObjPop                 // DECORATE FOR END OF DTORABLE OBJECT
    ( PTREE expr )              // - expression
{
    if( NULL == expr ) {
        emitCode( IC_DTOBJ_POP );
    } else {
        expr = ptdBase( expr, PTD_OBJ_POP );
    }
    return expr;
}


PTREE PtdInitSymEnd             // DECORATE FOR END OF SYMBOL INITIALIZATION
    ( PTREE expr                // - expression
    , SYMBOL sym )              // - symbol
{
    if( NULL == expr ) {
        boolean br = CgFrontRetnOptVar( sym );
        CgFrontCodePtr( IC_INIT_SYM_END, sym );
        if( br ) {
            CgFrontRetnOptEnd();
        }
    } else {
        expr = ptdSymbol( expr, sym, PTD_INIT_SYM_END );
    }
    return expr;
}


PTREE PtdNewAlloc               // DECORATE NEW ALLOCATION
    ( PTREE expr )              // - expression
{
    return ptdBase( expr, PTD_NEW_ALLOC );
}


PTREE PtdNewCtor                // DECORATE FOR CTORING NEW'ED EXPRESSION
    ( PTREE expr                // - expression
    , TYPE type )               // - class type
{
    return ptdType( expr, type, PTD_NEW_CTOR );
}


PTREE PtdVfunAccess             // ACCESS VIRTUAL FUNCTION
    ( PTREE expr                // - expression
    , target_offset_t vf_index  // - index into VF table
    , target_offset_t vf_offset // - offset to VF table ptr
    , SYMBOL baser )            // - basing "this" symbol
{
    expr = ptdOffset( expr, vf_index, PTD_VF_INDEX );
    expr = ptdOffset( expr, vf_offset, PTD_VF_OFFSET );
    expr = ptdSymbol( expr, baser, PTD_VF_SYM );
    return expr;
}


PTREE PtdVbaseFetch             // FETCH OF VIRTUAL BASE
    ( PTREE expr                // - expression
    , target_offset_t vb_offset // - virtual base offset
    , target_offset_t vb_index  // - virtual base index
    , target_offset_t vb_delta  // - virtual base delta
    , target_offset_t vb_exact )// - virtual base exact offset
{
    expr = ptdOffset( expr, vb_offset, PTD_VB_OFFSET );
    expr = ptdOffset( expr, vb_index,  PTD_VB_INDEX  );
    expr = ptdOffset( expr, vb_delta,  PTD_VB_DELTA  );
    expr = ptdOffset( expr, vb_exact,  PTD_VB_EXACT  );
    return expr;
}


static target_offset_t getOffset // SEARCH FOR OFFSET IN DECORATION
    ( PTREE expr                // - expression
    , PTD_KIND kind )           // - decoration kind
{
#ifndef NDEBUG
    boolean found = FALSE;      // - checks for found
#endif
    PTD* ptd;                   // - current entry
    target_offset_t retn;       // - offset in decoration

    RingIterBeg( expr->decor, ptd ) {
        if( kind == ptd->base.kind ) {
            retn = ptd->off.offset;
#ifndef NDEBUG
            DbgVerify( ! found, "Ptd::getOffset -- two decorations" );
            found = TRUE;
#else
            break;
#endif
        }
    } RingIterEnd( ptd );
    DbgVerify( found, "Ptd::getOffset -- no offset" );
    return retn;
}


target_offset_t PtdGetVbExact   // GET VBASE EXACT DECORATION
    ( PTREE expr )              // - expression
{
    return getOffset( expr, PTD_VB_EXACT );
}


target_offset_t PtdGetVbOffset  // GET VBASE OFFSET DECORATION
    ( PTREE expr )              // - expression
{
    return getOffset( expr, PTD_VB_OFFSET );
}


PTREE PtdDltDtorArr             // DECORATE FOR DELETE OF DTORABLE-ARRAY
    ( PTREE expr                // - expression
    , SYMBOL del )              // - operator delete
{
    return ptdSymbol( expr, del, PTD_DEL_DTOR_ARR );
}


PTREE PtdDltDtorElm             // DECORATE FOR DELETE OF DTORABLE-ELEMENT
    ( PTREE expr                // - expression
    , SYMBOL del )              // - operator delete
{
    return ptdSymbol( expr, del, PTD_DEL_DTOR_ELM );
}


PTREE PtdDltDtorSize            // DECORATE FOR SIZE OF DTORABLE-ELEMENT
    ( PTREE expr                // - expression
    , target_size_t size )      // - size
{
    return ptdSize( expr, size, PTD_DEL_DTOR_SIZE );
}


PTREE PtdDltDtorEnd             // DECORATE FOR END OF DTORABLE-ELEMENT ON DEL
    ( PTREE expr )              // - expression
{
    ScopeKeep( GetCurrScope() );
    FunctionHasRegistration();
    return ptdBase( expr, PTD_DEL_DTORED );
}


PTREE PtdDtorKind               // SPECIFY KIND OF DTOR ENTRY
    ( PTREE expr                // - expression
    , target_offset_t kind )    // - kind (DTC_COMP_...)
{
//    return ptdOffset( expr, kind, PTD_DTOR_KIND );
    kind = kind;
    return expr;
}


PTREE PtdOffsetofExpr           // DECORATE FOR OFFSETOF EXPR
    ( PTREE expr                // - expression
    , PTREE tree )              // - operator delete
{
    return ptdPTree( expr, tree, PTD_OFFSETOF_EXPR );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?