Exemplo n.º 1
0
stmt_ty *
stmt_if_alloc(blob_list_ty *condition, stmt_ty *then_clause,
    stmt_ty *else_clause)
{
    stmt_if_ty      *result;
    blob_list_ty    *c2;
    table_ty        *tp;

    trace(("stmt_if_alloc()\n{\n"));
    result = (stmt_if_ty *)stmt_alloc(&method);

    assert(condition->length >= 1);
    for (tp = table; tp < ENDOF(table); ++tp)
    {
        if (!tp->fast)
            tp->fast = str_from_c(tp->name);
        if (str_equal(condition->list[0]->text, tp->fast))
            break;
    }
    assert(tp < ENDOF(table));
    if (tp >= ENDOF(table))
        tp = &table[0];
    c2 = tp->rewrite(condition, &result->ref);
    blob_list_free(condition);

    result->condition = c2;
    result->then_clause = then_clause;
    result->else_clause = else_clause;

    stmt_variable_merge((stmt_ty *)result, then_clause);
    if (else_clause)
        stmt_variable_merge((stmt_ty *)result, else_clause);
    trace(("}\n"));
    return (stmt_ty *)result;
}
Exemplo n.º 2
0
WsStatement *ws_stmt_return(WsCompilerPtr compiler, WsUInt32 line,
                            WsExpression *expr)
{
    WsStatement *stmt = stmt_alloc(compiler, WS_STMT_RETURN, line, line);

    if (stmt)
        stmt->u.expr = expr;

    return stmt;
}
Exemplo n.º 3
0
WsStatement *ws_stmt_expr(WsCompiler *compiler, WsUInt32 line,
                          WsExpression *expr)
{
    WsStatement *stmt = stmt_alloc(compiler, WS_STMT_EXPR, line, line);

    if (stmt)
        stmt->u.expr = expr;

    return stmt;
}
Exemplo n.º 4
0
WsStatement *ws_stmt_variable(WsCompilerPtr compiler, WsUInt32 line,
                              WsList *variables)
{
    WsStatement *stmt = stmt_alloc(compiler, WS_STMT_VARIABLE, line, line);

    if (stmt)
        stmt->u.var = variables;

    return stmt;
}
Exemplo n.º 5
0
WsStatement *ws_stmt_block(WsCompiler *compiler, WsUInt32 fline,
                           WsUInt32 lline, WsList *block)
{
    WsStatement *stmt = stmt_alloc(compiler, WS_STMT_BLOCK, fline, lline);

    if (stmt)
        stmt->u.block = block;

    return stmt;
}
Exemplo n.º 6
0
WsStatement *ws_stmt_while(WsCompiler *compiler, WsUInt32 line,
                           WsExpression *expr, WsStatement *stmt_arg)
{
    WsStatement *stmt = stmt_alloc(compiler, WS_STMT_WHILE, line, line);

    if (stmt) {
        stmt->u.s_while.expr = expr;
        stmt->u.s_while.stmt = stmt_arg;
    }

    return stmt;
}
Exemplo n.º 7
0
WsStatement *ws_stmt_if(WsCompiler *compiler, WsUInt32 line,
                        WsExpression *expr, WsStatement *s_then,
                        WsStatement *s_else)
{
    WsStatement *stmt = stmt_alloc(compiler, WS_STMT_IF, line, line);

    if (stmt) {
        stmt->u.s_if.expr = expr;
        stmt->u.s_if.s_then = s_then;
        stmt->u.s_if.s_else = s_else;
    }

    return stmt;
}
Exemplo n.º 8
0
WsStatement *ws_stmt_for(WsCompilerPtr compiler, WsUInt32 line, WsList *init,
                         WsExpression *e1, WsExpression *e2, WsExpression *e3,
                         WsStatement *stmt_body)
{
    WsStatement *stmt = stmt_alloc(compiler, WS_STMT_FOR, line, line);

    if (stmt) {
        stmt->u.s_for.init = init;
        stmt->u.s_for.e1 = e1;
        stmt->u.s_for.e2 = e2;
        stmt->u.s_for.e3 = e3;
        stmt->u.s_for.stmt = stmt_body;
    }

    return stmt;
}
Exemplo n.º 9
0
WsStatement *ws_stmt_break(WsCompiler *compiler, WsUInt32 line)
{
    return stmt_alloc(compiler, WS_STMT_BREAK, line, line);
}
Exemplo n.º 10
0
WsStatement *ws_stmt_continue(WsCompiler *compiler, WsUInt32 line)
{
    return stmt_alloc(compiler, WS_STMT_CONTINUE, line, line);
}
Exemplo n.º 11
0
WsStatement *ws_stmt_empty(WsCompiler *compiler, WsUInt32 line)
{
    return stmt_alloc(compiler, WS_STMT_EMPTY, line, line);
}
Exemplo n.º 12
0
struct stmt *stmt_print(struct expr const *expr) {
    struct stmt *stmt = stmt_alloc(STMT_PRINT);
    stmt->print = expr_copy(expr);
    return stmt;
}
Exemplo n.º 13
0
struct stmt *stmt_assign(char const *identifier, struct expr const *expr) {
    struct stmt *stmt = stmt_alloc(STMT_ASSIGN);
    stmt->assign.identifier = strdup(identifier);
    stmt->assign.value = expr_copy(expr);
    return stmt;
}
Exemplo n.º 14
0
stmt_ty *
stmt_compound_alloc(void)
{
    return stmt_alloc(&method);
}