[vala/wip/transform-ast: 18/25] Move UnaryExpression tranformation into code transformer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform-ast: 18/25] Move UnaryExpression tranformation into code transformer
- Date: Wed, 1 Apr 2020 08:19:59 +0000 (UTC)
commit e6622c6f80f861c12d37eb7382317064c21c49df
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Feb 25 21:25:57 2012 +0100
Move UnaryExpression tranformation into code transformer
codegen/valaccodetransformer.vala | 26 ++++++++++++++++++++++++++
vala/valaunaryexpression.vala | 9 +--------
2 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 916478952..56c18643d 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -299,6 +299,32 @@ public class Vala.CCodeTransformer : CodeTransformer {
}
}
+ public override void visit_unary_expression (UnaryExpression expr) {
+ var parent_statement = expr.parent_statement;
+ if (parent_statement == null) {
+ base.visit_unary_expression (expr);
+ return;
+ }
+
+ if (expr.operator == UnaryOperator.INCREMENT || expr.operator == UnaryOperator.DECREMENT) {
+ var target_type = copy_type (expr.target_type);
+ begin_replace_expression (expr);
+
+ Expression replacement;
+ if (expr.operator == UnaryOperator.INCREMENT) {
+ replacement = expression (@"$(expr.inner) = $(expr.inner) + 1");
+ } else {
+ replacement = expression (@"$(expr.inner) = $(expr.inner) - 1");
+ }
+ replacement.target_type = target_type;
+
+ end_replace_expression (replacement);
+ return;
+ }
+
+ base.visit_unary_expression (expr);
+ }
+
public override void visit_object_creation_expression (ObjectCreationExpression expr) {
if (expr.tree_can_fail) {
if (expr.parent_node is LocalVariable || expr.parent_node is ExpressionStatement) {
diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala
index 488cef8e9..bd60b2ecf 100644
--- a/vala/valaunaryexpression.vala
+++ b/vala/valaunaryexpression.vala
@@ -214,14 +214,7 @@ public class Vala.UnaryExpression : Expression {
return false;
}
- var old_value = new MemberAccess (ma.inner, ma.member_name, inner.source_reference);
- var bin = new BinaryExpression (operator == UnaryOperator.INCREMENT ?
BinaryOperator.PLUS : BinaryOperator.MINUS, old_value, new IntegerLiteral ("1"), source_reference);
-
- var assignment = new Assignment (ma, bin, AssignmentOperator.SIMPLE,
source_reference);
- assignment.target_type = target_type;
- context.analyzer.replaced_nodes.add (this);
- parent_node.replace_expression (this, assignment);
- assignment.check (context);
+ value_type = inner.value_type.copy ();
return true;
case UnaryOperator.REF:
case UnaryOperator.OUT:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]