[vala/staging] Move PostfixExpression transformation into the CCodeTransformer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] Move PostfixExpression transformation into the CCodeTransformer
- Date: Fri, 12 Apr 2019 16:45:59 +0000 (UTC)
commit 395328b0d7fa280658d8ebdc7d9592195729d6c5
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Feb 1 18:37:50 2014 +0100
Move PostfixExpression transformation into the CCodeTransformer
codegen/valaccodebasemodule.vala | 41 ---------------------------------------
codegen/valaccodetransformer.vala | 12 ++++++++++++
2 files changed, 12 insertions(+), 41 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0c00fbceb..4e924887c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4265,47 +4265,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
set_cvalue (expr, generate_instance_cast (get_this_cexpression (),
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 (GenericType 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 ecff4bc8e..82d260df6 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -370,4 +370,16 @@ public class Vala.CCodeTransformer : CodeTransformer {
end_replace_expression (replacement);
}
+
+ public override void visit_postfix_expression (PostfixExpression expr) {
+ begin_replace_expression (expr);
+
+ 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);
+
+ end_replace_expression (replacement);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]