Ejemplo n.º 1
0
Expression *CallExp::inlineScan(InlineScanState *iss, Expression *eret)
{
    Expression *e = this;

    //printf("CallExp::inlineScan()\n");
    e1 = e1->inlineScan(iss);
    arrayInlineScan(iss, arguments);

    if (e1->op == TOKvar)
    {
        VarExp *ve = (VarExp *)e1;
        FuncDeclaration *fd = ve->var->isFuncDeclaration();

        if (fd && fd != iss->fd && fd->canInline(0, 0, 0))
        {
            Expression *ex = fd->expandInline(iss, eret, NULL, arguments, NULL);
            if (ex)
                e = ex;
        }
    }
    else if (e1->op == TOKdotvar)
    {
        DotVarExp *dve = (DotVarExp *)e1;
        FuncDeclaration *fd = dve->var->isFuncDeclaration();

        if (fd && fd != iss->fd && fd->canInline(1, 0, 0))
        {
            if (dve->e1->op == TOKcall &&
                dve->e1->type->toBasetype()->ty == Tstruct)
            {
                /* To create ethis, we'll need to take the address
                 * of dve->e1, but this won't work if dve->e1 is
                 * a function call.
                 */
                ;
            }
            else
            {
                Expression *ex = fd->expandInline(iss, eret, dve->e1, arguments, NULL);
                if (ex)
                    e = ex;
            }
        }
    }

    if (e && type->ty != Tvoid &&
        !type->equals(e->type) &&
        e->type->hasWild() && !type->hasWild())
    {
        e = e->copy();
        e->type = type;
    }
    return e;
}
Ejemplo n.º 2
0
Statement *ExpStatement::inlineScan(InlineScanState *iss)
{
#if LOG
    printf("ExpStatement::inlineScan(%s)\n", toChars());
#endif
    if (exp)
    {
        exp = exp->inlineScan(iss);

        /* See if we can inline as a statement rather than as
         * an Expression.
         */
        if (exp && exp->op == TOKcall)
        {
            CallExp *ce = (CallExp *)exp;
            if (ce->e1->op == TOKvar)
            {
                VarExp *ve = (VarExp *)ce->e1;
                FuncDeclaration *fd = ve->var->isFuncDeclaration();

                if (fd && fd != iss->fd && fd->canInline(0, 0, 1))
                {
                    Statement *s;
                    fd->expandInline(iss, NULL, NULL, ce->arguments, &s);
                    return s;
                }
            }
        }
    }
    return this;
}