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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
WsStatement *ws_stmt_break(WsCompiler *compiler, WsUInt32 line) { return stmt_alloc(compiler, WS_STMT_BREAK, line, line); }
WsStatement *ws_stmt_continue(WsCompiler *compiler, WsUInt32 line) { return stmt_alloc(compiler, WS_STMT_CONTINUE, line, line); }
WsStatement *ws_stmt_empty(WsCompiler *compiler, WsUInt32 line) { return stmt_alloc(compiler, WS_STMT_EMPTY, line, line); }
struct stmt *stmt_print(struct expr const *expr) { struct stmt *stmt = stmt_alloc(STMT_PRINT); stmt->print = expr_copy(expr); return stmt; }
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; }
stmt_ty * stmt_compound_alloc(void) { return stmt_alloc(&method); }