Example #1
0
void CgDeclParms(               // DEFINE ARGS FOR CURRENT FN IN CORRECT ORDER
    FN_CTL *fctl,               // - current function control pointer
    SCOPE scope )               // - argument scope
{
    SYMBOL curr;
    SYMBOL stop;
    SYMBOL *psym;               // - addr[ parameter symbol ]
    TYPE fn_type;
    auto VSTK_CTL sym_stack;
    SYMBOL ret_sym;
    NAME ret_name;

    fn_type = FunctionDeclarationType( fctl->func->sym_type );
    VstkOpen( &sym_stack, sizeof( SYMBOL ), 16 );
    stop = ScopeOrderedStart( scope );
    ret_name = CppSpecialName( SPECIAL_RETURN_VALUE );
    ret_sym = NULL;
    curr = NULL;
    for(;;) {
        curr = ScopeOrderedNext( stop, curr );
        if( curr == NULL ) break;
        if( ( curr->name != NULL ) && ( ret_name == curr->name->name ) ) {
            ret_sym = curr;
        } else {
            psym = VstkPush( &sym_stack );
            *psym = curr;
        }
    }
    IbpDefineParms();
    declareParameter( fctl->this_sym );
    declareParameter( fctl->cdtor_sym );
    declareParameter( ret_sym );
    switch( PcCallImpl( fn_type ) ) {
      case CALL_IMPL_REV_CPP :
      case CALL_IMPL_REV_C :
        for(;;) {
            psym = VstkPop( &sym_stack );
            if( psym == NULL ) break;
            declareParameter( *psym );
        }
        break;
      case CALL_IMPL_CPP :
      case CALL_IMPL_C :
      case CALL_IMPL_ELL_CPP :
      case CALL_IMPL_ELL_C :
      { unsigned index;             // - parameter index
        unsigned max_parms;         // - # parameters
        SYMBOL *psym1;              // - addr[ parameter symbol ]
        max_parms = VstkDimension( &sym_stack );
        for( index = 0; index < max_parms; ++index ) {
            psym1 = VstkIndex( &sym_stack, index );
            declareParameter( *psym1 );
        }
      } break;
    }
    VstkClose( &sym_stack );
    CGLastParm();
}
Example #2
0
void FormatTemplateParmScope( VBUF *parms, SCOPE parm_scope )
/***********************************************************/
{
    SYMBOL stop;
    SYMBOL curr;
    SYMBOL sym;
    const char *delim;
    TYPE type;
    auto VBUF sym_parm;
    auto VBUF type_parm_prefix;
    auto VBUF type_parm_suffix;

    VbufInit( parms );
    if( parm_scope == NULL ) {
        makeUnknownTemplate( parms );
        return;
    }
    delim = templateParmStart;
    curr = NULL;
    stop = ScopeOrderedStart( parm_scope );
    for(;;) {
        curr = ScopeOrderedNext( stop, curr );
        if( curr == NULL ) break;
        VbufConcStr( parms, delim );
        type = curr->sym_type;
        if( SymIsConstantInt( curr ) ) {
            if( UnsignedIntType( type ) ) {
                VbufConcDecimal( parms, curr->u.uval );
            } else {
                VbufConcInteger( parms, curr->u.sval );
            }
        } else if( SymIsTypedef( curr ) ) {
            FormatType( type, &type_parm_prefix, &type_parm_suffix );
            VbufTruncWhite( &type_parm_prefix );
            VbufTruncWhite( &type_parm_suffix );
            VbufConcVbuf( parms, &type_parm_prefix );
            VbufConcVbuf( parms, &type_parm_suffix );
            VbufFree( &type_parm_prefix );
            VbufFree( &type_parm_suffix );
        } else {
            sym = SymAddressOf( curr );
            if( sym != NULL ) {
                FormatSym( sym, &sym_parm );
                VbufConcVbuf( parms, &sym_parm );
                VbufFree( &sym_parm );
            }
        }
        delim = templateParmNext;
    }
    if( delim == templateParmStart ) {
        VbufConcStr( parms, templateParmStart );
    }
    VbufConcStr( parms, templateParmStop );
}
Example #3
0
static PTREE transformVaStart   // TRANSFORM TO CO_VASTART OPCODE
    ( PTREE expr )              // - va_start expression
{
    SYMBOL pre_ellipsis_sym;
    SYMBOL stop;
    SYMBOL curr;
    SYMBOL fn;
    SCOPE caller_arg_scope;
    unsigned offset;
    target_size_t arg_size;
    PTREE arg1;
    PTREE arg2;
    PTREE arg3;
    PTREE valist;

    // second argument -- must be pre-... parameter
    arg1 = expr->u.subtree[1];
    arg2 = arg1->u.subtree[0];
    arg3 = arg2->u.subtree[0];
    pre_ellipsis_sym = PTreeOp( &arg2->u.subtree[1] )->u.symcg.symbol;
    caller_arg_scope = ScopeFunctionScopeInProgress();
    fn = ScopeFunction( caller_arg_scope );
    offset = 0;
    if( ObjModelFunctionReturn( fn->sym_type ) == OMR_CLASS_VAL ) {
        offset += TARGET_PACKING;
    }
    if( SymIsThisMember( fn ) ) {
        offset += TARGET_PACKING;
        if( SymCDtorExtraParm( fn ) ) {
            offset += TARGET_PACKING;
        }
    }
    stop = ScopeOrderedStart( caller_arg_scope );
    curr = NULL;
    for(;;) {
        curr = ScopeOrderedNext( stop, curr );
        if( curr == NULL ) {
            PTreeErrorExpr( expr, ERR_INVALID_VASTART_SYMBOL );
            return( expr );
        }
        if( ObjModelArgument( curr->sym_type ) == OMR_CLASS_REF ) {
            arg_size = TARGET_PACKING;
        } else {
            arg_size = CgMemorySize( curr->sym_type );
            arg_size += TARGET_PACKING - 1;
            arg_size &= ~( TARGET_PACKING - 1 );
        }
        offset += arg_size;
        if( curr == pre_ellipsis_sym ) break;
    }
    if( ScopeOrderedNext( stop, curr ) != NULL ) {
        PTreeErrorExpr( expr, ERR_INVALID_VASTART_SYMBOL );
        return( expr );
    }
    // third argument -- va_list symbol
    valist = arg1->u.subtree[1];
    arg1->u.subtree[1] = NULL;
    if( arg3->u.subtree[1]->u.int_constant == 0 ) {
        // compensate for "void *__alist;" arg in <varargs.h>
        offset -= TARGET_PACKING;
    }
    NodeFreeDupedExpr( expr );
    expr = NodeBinary( CO_VASTART, valist, NodeOffset( offset ) );
    return expr;
}