示例#1
0
static boolean canCoaxVAStartSym( PTREE *parg )
{
    PTREE orig_arg;
    PTREE arg;

    /*
        The reason we need this complexity is that there exists C++ code
        that uses class templates instantiated on reference types but the
        class contains member functions that have ", T v0, ... )" so we
        have to forge ahead generating (possibly incorrect code) because
        the inline function must be compiled but will never be called!
        see COOL\PROPERTY.CPP
    */
    orig_arg = PTreeOp( parg );
    arg = orig_arg;
    if( NodeIsUnaryOp( arg, CO_FETCH ) ) {
        arg = arg->u.subtree[0];
    }
    if( NodeIsUnaryOp( arg, CO_RARG_FETCH ) ) {
        arg = arg->u.subtree[0];
    }
    if( arg->op != PT_SYMBOL ) {
        return( FALSE );
    }
    *parg = NodeComma( orig_arg, PTreeAssign( NULL, arg ) );
    return( TRUE );
}
示例#2
0
static void buildDiagInfo(      // BUILD DIAG_INFO FOR ARGUMENT
    DIAG_INFO *diag,            // - diagnostic information
    PTREE arg,                  // - expression for argument
    int bad_parm,               // - index of erroneous parameter
    SYMBOL fun )                // - function for argument
{
    arg_list* alist;            // - function args
    unsigned num_args;          // - # args

    diag->bad_parm = bad_parm + 1;
    alist = SymFuncArgList( fun );
    num_args = alist->num_args;
    if( bad_parm >= num_args ) {
        TYPE last_arg = alist->type_list[ num_args - 1 ];
        if( last_arg->id == TYP_DOT_DOT_DOT ) {
            diag->bad_tgt = last_arg;
        } else {
            diag->bad_tgt = NULL;
        }
    } else {
        diag->bad_tgt = alist->type_list[ bad_parm ];
    }
    PTreeExtractLocn( arg, &diag->location );
    if( PointerToFuncEquivalent( arg->type ) ) {
        PTREE operand;  // - argument operand
        operand = arg;
        if( NodeIsUnaryOp( operand, CO_ADDR_OF ) ) {
            operand = PTreeOpLeft( operand );
        }
        if( operand->op == PT_SYMBOL ) {
            diag->bad_fn = operand->u.symcg.symbol;
            if( IsActualOverloadedFunc( diag->bad_fn
                                      , operand->u.symcg.result ) ) {
                diag->bad_src = NULL;
            } else {
                diag->bad_fn = NULL;
                diag->bad_src = NodeType( arg );
            }
        } else {
            diag->bad_fn = NULL;
            diag->bad_src = NodeType( arg );
        }
    } else {
        diag->bad_fn = NULL;
        diag->bad_src = NodeType( arg );
    }
}
示例#3
0
static PTREE addPtIc(           // DECORATE TREE WITH PT_IC NODE
    PTREE tree,                 // - tree
    PTREE node )                // - IC node
{
    PTREE *a_expr;              // - expression for side-effect

    if( tree == NULL ) {
        CgFrontCodePtr( node->u.ic.opcode, node->u.ic.value.pvalue );
        CgFrontCode( IC_EXPR_TRASH );
        PTreeFree( node );
        tree = NULL;
    } else {
        PTREE dup = tree;
        if( NodeIsUnaryOp( tree, CO_EXPR_DONE ) ) {
            a_expr = &dup->u.subtree[0];
        } else {
            a_expr = &dup;
        }
        *a_expr = NodeAddSideEffect( node, *a_expr );
        tree = dup;
    }
    return tree;
}
示例#4
0
static void checkAutoReturn(    // CHECK IF AUTOMATIC BEING RETURNED
    PTREE node,                 // - node to be checked
    TYPE ret_type )             // - return type
{
    TYPE func_ret;              // - type of function return
    SYMBOL func;                // - function called
    SYMBOL comped;              // - function being compiled
    PTREE expr;                 // - node for error
    TYPE refed;                 // - NULL ==> not reference

    comped = ScopeFunctionInProgress();
    if( SymIsGenedFunc( comped ) ) {
        return;
    }
    expr = node;
    refed = TypeReference( ret_type );
    for( ; ; ) {
        node = NodeRemoveCastsCommas( node );
        if( ( node->op == PT_SYMBOL )
          &&( SymIsAutomatic( node->u.symcg.symbol ) ) ) {
            if( NULL == refed ) {
                PTreeWarnExpr( expr, WARN_RET_ADDR_OF_AUTO );
            } else {
                PTreeErrorExpr( expr, ERR_RET_AUTO_REF );
            }
            break;
        } else if( NodeIsBinaryOp( node, CO_DOT )
                || NodeIsBinaryOp( node, CO_DOT_STAR ) ) {
            node = PTreeOpLeft( node );
        } else if( NodeIsUnaryOp( node, CO_ADDR_OF ) ) {
            node = PTreeOpLeft( node );
        } else if( NULL != refed ) {
            if( NodeIsBinaryOp( node, CO_DTOR ) ) {
                node = PTreeOpRight( node );
            } else if( NodeIsBinaryOp( node, CO_CALL_EXEC ) ) {
                node = PTreeOpLeft( PTreeOpLeft( node ) );
                if( node->op == PT_SYMBOL ) {
                    func = node->u.symcg.symbol;
                    if( SymIsCtor( func ) ) {
                        PTreeErrorExpr( expr, ERR_RET_AUTO_REF );
                    } else {
                        func_ret = SymFuncReturnType( func );
                        if( NULL != StructType( func_ret ) ) {
                            PTreeErrorExpr( expr, ERR_RET_AUTO_REF );
                        }
                    }
                }
                break;
            } else if( NodeIsBinaryOp( node, CO_CALL_EXEC_IND ) ) {
                func_ret = TypeFunctionCalled( NodeFuncForCall( node )->type );
                func_ret = func_ret->of;
                if( NULL != StructType( func_ret ) ) {
                    PTreeErrorExpr( expr, ERR_RET_AUTO_REF );
                }
                break;
            } else {
                break;
            }
        } else {
            break;
        }
    }
}