[vala/wip/transform: 74/87] Use statements() parsing
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 74/87] Use statements() parsing
- Date: Thu, 25 Oct 2018 07:03:23 +0000 (UTC)
commit 11c28140a8ef247d117b8aae0ecec1c2dc166a9b
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Feb 2 23:32:35 2014 +0100
Use statements() parsing
codegen/valaccodetransformer.vala | 16 +++++++---------
vala/valacodebuilder.vala | 4 ++++
vala/valacodetransformer.vala | 4 ++++
3 files changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index cca398826..a6e4f9b57 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -223,13 +223,11 @@ public class Vala.CCodeTransformer : CodeTransformer {
b.add_expression (it_expr);
}
b.add_else ();
- b.add_assignment (expression (notfirst), expression ("true"));
+ statements (@"$notfirst = true;");
b.close ();
if (stmt.condition != null && !always_true (stmt.condition)) {
- b.open_if (new UnaryExpression (UnaryOperator.LOGICAL_NEGATION,
stmt.condition, stmt.source_reference));
- b.add_break ();
- b.close ();
+ statements (@"if (!$(stmt.condition)) break;");
}
b.add_statement (stmt.body);
@@ -373,11 +371,11 @@ public class Vala.CCodeTransformer : CodeTransformer {
begin_replace_expression (expr);
var result = b.add_temp_declaration (expr.value_type);
- b.open_if (expr.condition);
- b.add_assignment (expression (result), expr.true_expression);
- b.add_else ();
- b.add_assignment (expression (result), expr.false_expression);
- b.close ();
+ statements (@"if ($(expr.condition)) {
+ $result = $(expr.true_expression);
+ } else {
+ $result = $(expr.false_expression);
+ }");
replacement = return_temp_access (result, expr.value_type, target_type, formal_target_type);
end_replace_expression (replacement);
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index ab174ffb9..036303cb9 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -272,6 +272,10 @@ public class Vala.CodeBuilder {
return new Parser().parse_expression_string (str, source_reference);
}
+ public void statements (string str) {
+ new Parser().parse_statements_string (str, current_block, source_reference);
+ }
+
// only qualified types, will slightly simplify the work of SymbolResolver
public static Symbol? symbol_from_string (string symbol_string, Symbol? parent_symbol = null) {
Symbol sym = parent_symbol != null ? parent_symbol : CodeContext.get().root;
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index b7b829737..f6444b8e9 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -184,6 +184,10 @@ public class Vala.CodeTransformer : CodeVisitor {
return b.expression (str);
}
+ public void statements (string str) {
+ b.statements (str);
+ }
+
public void check (CodeNode node) {
var sym = context.analyzer.get_current_symbol (node);
if (sym != null) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]