[vala/wip/transform: 124/139] Move postfix transformation from the codegen to the transformer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 124/139] Move postfix transformation from the codegen to the transformer
- Date: Mon, 17 Oct 2016 20:15:56 +0000 (UTC)
commit c93f864cf68411dd3cae9ab9bb27750bc3831b05
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Feb 1 18:37:50 2014 +0100
Move postfix transformation from the codegen to the transformer
codegen/valaccodebasemodule.vala | 41 -------------------------------------
codegen/valaccodetransformer.vala | 17 +++++++++++++++
vala/valapostfixexpression.vala | 5 ++++
3 files changed, 22 insertions(+), 41 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 52c493f..fb35125 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4015,47 +4015,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
set_cvalue (expr, generate_instance_cast (this_access, expr.value_type.data_type));
}
- public override void visit_postfix_expression (PostfixExpression expr) {
- MemberAccess ma = find_property_access (expr.inner);
- if (ma != null) {
- // property postfix expression
- var prop = (Property) ma.symbol_reference;
-
- // increment/decrement property
- var op = expr.increment ? CCodeBinaryOperator.PLUS : CCodeBinaryOperator.MINUS;
- var cexpr = new CCodeBinaryExpression (op, get_cvalue (expr.inner), new CCodeConstant
("1"));
- store_property (prop, ma.inner, new GLibValue (expr.value_type, cexpr));
-
- // return previous value
- expr.target_value = expr.inner.target_value;
- return;
- }
-
- // assign current value to temp variable
- var temp_value = store_temp_value (expr.inner.target_value, expr);
-
- // increment/decrement variable
- var op = expr.increment ? CCodeBinaryOperator.PLUS : CCodeBinaryOperator.MINUS;
- var cexpr = new CCodeBinaryExpression (op, get_cvalue_ (temp_value), new CCodeConstant ("1"));
- ccode.add_assignment (get_cvalue (expr.inner), cexpr);
-
- // return previous value
- expr.target_value = temp_value;
- }
-
- private MemberAccess? find_property_access (Expression expr) {
- if (!(expr is MemberAccess)) {
- return null;
- }
-
- var ma = (MemberAccess) expr;
- if (ma.symbol_reference is Property) {
- return ma;
- }
-
- return null;
- }
-
bool is_limited_generic_type (DataType type) {
var cl = type.type_parameter.parent_symbol as Class;
var st = type.type_parameter.parent_symbol as Struct;
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 795e4f7..1bfc968 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -560,6 +560,23 @@ public class Vala.CCodeTransformer : CodeTransformer {
pop_builder ();
check (replacement);
}
+
+ public override void visit_postfix_expression (PostfixExpression expr) {
+ push_builder (new CodeBuilder (context, expr.parent_statement, expr.source_reference));
+
+ var result = b.add_temp_declaration (copy_type (expr.value_type), expr.inner);
+ var op = expr.increment ? "+ 1" : "- 1";
+ b.add_expression (expression (@"$(expr.inner) = $result $op"));
+
+ var replacement = return_temp_access (result, expr.value_type, expr.target_type);
+
+ context.analyzer.replaced_nodes.add (expr);
+ expr.parent_node.replace_expression (expr, replacement);
+ b.check (this);
+ pop_builder ();
+ check (replacement);
+
+ }
public override void visit_assignment (Assignment a) {
a.accept_children (this);
diff --git a/vala/valapostfixexpression.vala b/vala/valapostfixexpression.vala
index 65303eb..63b4442 100644
--- a/vala/valapostfixexpression.vala
+++ b/vala/valapostfixexpression.vala
@@ -154,4 +154,9 @@ public class Vala.PostfixExpression : Expression {
codegen.visit_expression (this);
}
+
+ public override string to_string () {
+ var op = increment ? "++" : "--";
+ return @"($inner$op)";
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]