[vala/staging: 1/3] Simplify determining the type of conditional expressions
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 1/3] Simplify determining the type of conditional expressions
- Date: Sat, 17 Sep 2016 18:58:54 +0000 (UTC)
commit 4a1aa7fdf6cc1b178fc35528636a70e5b51a1e57
Author: Luca Bruno <lucabru src gnome org>
Date: Fri May 27 15:10:54 2011 +0200
Simplify determining the type of conditional expressions
https://bugzilla.gnome.org/show_bug.cgi?id=639990
vala/valaconditionalexpression.vala | 62 +++++++++++++++-------------------
1 files changed, 27 insertions(+), 35 deletions(-)
---
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 3ae003c..a0151db 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -100,6 +100,16 @@ public class Vala.ConditionalExpression : Expression {
return condition.is_pure () && true_expression.is_pure () && false_expression.is_pure ();
}
+ public override void replace_expression (Expression old_node, Expression new_node) {
+ if (condition == old_node) {
+ condition = new_node;
+ } else if (true_expression == old_node) {
+ true_expression = new_node;
+ } else if (false_expression == old_node) {
+ false_expression = new_node;
+ }
+ }
+
public override bool check (CodeContext context) {
if (checked) {
return !error;
@@ -118,38 +128,11 @@ public class Vala.ConditionalExpression : Expression {
string temp_name = get_temp_name ();
- true_expression.target_type = target_type;
- false_expression.target_type = target_type;
-
- var local = new LocalVariable (null, temp_name, null, source_reference);
- var decl = new DeclarationStatement (local, source_reference);
-
- var true_local = new LocalVariable (null, temp_name, true_expression,
true_expression.source_reference);
- var true_block = new Block (true_expression.source_reference);
- var true_decl = new DeclarationStatement (true_local, true_expression.source_reference);
- true_block.add_statement (true_decl);
-
- var false_local = new LocalVariable (null, temp_name, false_expression,
false_expression.source_reference);
- var false_block = new Block (false_expression.source_reference);
- var false_decl = new DeclarationStatement (false_local, false_expression.source_reference);
- false_block.add_statement (false_decl);
-
- var if_stmt = new IfStatement (condition, true_block, false_block, source_reference);
-
- insert_statement (context.analyzer.insert_block, decl);
- insert_statement (context.analyzer.insert_block, if_stmt);
-
- if (!if_stmt.check (context) || true_expression.error || false_expression.error) {
+ if (!true_expression.check (context) || !false_expression.check (context)) {
error = true;
return false;
}
- true_expression = true_local.initializer;
- false_expression = false_local.initializer;
-
- true_block.remove_local_variable (true_local);
- false_block.remove_local_variable (false_local);
-
if (false_expression.value_type.compatible (true_expression.value_type)) {
value_type = true_expression.value_type.copy ();
} else if (true_expression.value_type.compatible (false_expression.value_type)) {
@@ -162,20 +145,29 @@ public class Vala.ConditionalExpression : Expression {
value_type.value_owned = (true_expression.value_type.value_owned ||
false_expression.value_type.value_owned);
- local.variable_type = value_type;
- decl.check (context);
-
true_expression.target_type = value_type;
false_expression.target_type = value_type;
+ var local = new LocalVariable (value_type, temp_name, null, source_reference);
+ var decl = new DeclarationStatement (local, source_reference);
+
+ var true_block = new Block (true_expression.source_reference);
var true_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name,
true_expression.source_reference), true_expression, AssignmentOperator.SIMPLE,
true_expression.source_reference), true_expression.source_reference);
- true_stmt.check (context);
+ true_block.add_statement (true_stmt);
+ var false_block = new Block (false_expression.source_reference);
var false_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple
(local.name, false_expression.source_reference), false_expression, AssignmentOperator.SIMPLE,
false_expression.source_reference), false_expression.source_reference);
- false_stmt.check (context);
+ false_block.add_statement (false_stmt);
- true_block.replace_statement (true_decl, true_stmt);
- false_block.replace_statement (false_decl, false_stmt);
+ var if_stmt = new IfStatement (condition, true_block, false_block, source_reference);
+
+ insert_statement (context.analyzer.insert_block, decl);
+ insert_statement (context.analyzer.insert_block, if_stmt);
+
+ if (!decl.check (context) || !if_stmt.check (context)) {
+ error = true;
+ return false;
+ }
var ma = new MemberAccess.simple (local.name, source_reference);
ma.formal_target_type = formal_target_type;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]