public override void visit_while_statement (WhileStatement stmt) {
// convert to simple loop
+ push_builder (new CodeBuilder (context, stmt, stmt.source_reference));
- if (always_true (stmt.condition)) {
- // do not generate if block if condition is always true
- } else if (always_false (stmt.condition)) {
- // do not generate if block if condition is always false
- stmt.body.insert_statement (0, new BreakStatement (stmt.condition.source_reference));
- } else {
- var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, stmt.condition, stmt.condition.source_reference);
- var true_block = new Block (stmt.condition.source_reference);
- true_block.add_statement (new BreakStatement (stmt.condition.source_reference));
- var if_stmt = new IfStatement (if_condition, true_block, null, stmt.condition.source_reference);
- stmt.body.insert_statement (0, if_stmt);
+ if (!always_false (stmt.condition)) {
+ b.open_loop ();
+ if (!always_true (stmt.condition)) {
+ b.open_if (new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, stmt.condition, stmt.condition.source_reference));
+ b.add_break ();
+ b.close ();
+ b.add_statement (stmt.body);
+ }
+ b.close ();
}
- var loop = new Loop (stmt.body, stmt.source_reference);
-
- var parent_block = (Block) stmt.parent_node;
+ var parent_block = context.analyzer.get_current_block (stmt);
context.analyzer.replaced_nodes.add (stmt);
- parent_block.replace_statement (stmt, loop);
+ parent_block.replace_statement (stmt, new EmptyStatement (stmt.source_reference));
stmt.body.checked = false;
- check (loop);
+ b.check (this);
+ pop_builder ();
}
public override void visit_do_statement (DoStatement stmt) {
string fd_list = null;
foreach (var param in m.get_parameters ()) {
if (param.direction == ParameterDirection.IN) {
- string? type_name = null;
if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") {
cancellable = param.name;
}
*/
public class Vala.GVariantModule : GAsyncModule {
- struct BasicTypeInfo {
- public unowned string signature;
- public unowned string type_name;
- public bool is_string;
- }
-
- const BasicTypeInfo[] basic_types = {
- { "y", "byte", false },
- { "b", "boolean", false },
- { "n", "int16", false },
- { "q", "uint16", false },
- { "i", "int32", false },
- { "u", "uint32", false },
- { "x", "int64", false },
- { "t", "uint64", false },
- { "d", "double", false },
- { "s", "string", true },
- { "o", "object_path", true },
- { "g", "signature", true }
- };
-
static bool is_string_marshalled_enum (TypeSymbol? symbol) {
if (symbol != null && symbol is Enum) {
return symbol.get_attribute_bool ("DBus", "use_string_marshalling");
statement_stack.add (stmt);
}
+ public void open_loop () {
+ statement_stack.add (current_block);
+ var parent_block = current_block;
+
+ current_block = new Block (source_reference);
+
+ var stmt = new Loop (current_block, source_reference);
+ parent_block.add_statement (stmt);
+ }
+
public void open_while (Expression condition) {
statement_stack.add (current_block);
var parent_block = current_block;