]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Simplify &(*foo) and *(&foo) to foo
authorJürg Billeter <j@bitron.ch>
Tue, 22 Sep 2009 21:09:03 +0000 (23:09 +0200)
committerJürg Billeter <j@bitron.ch>
Tue, 22 Sep 2009 21:09:03 +0000 (23:09 +0200)
ccode/valaccodeunaryexpression.vala
codegen/valaccodememberaccessmodule.vala

index 0f33478afe1334f576332257930a1cd11cc2b9d9..7f2b89b232316ad4eec66f6018ec0ca2f7724731 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodeunaryexpression.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2009  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -51,8 +51,20 @@ public class Vala.CCodeUnaryExpression : CCodeExpression {
                } else if (operator == CCodeUnaryOperator.BITWISE_COMPLEMENT) {
                        writer.write_string ("~");
                } else if (operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
+                       var inner_unary = inner as CCodeUnaryExpression;
+                       if (inner_unary != null && inner_unary.operator == CCodeUnaryOperator.ADDRESS_OF) {
+                               // simplify expression
+                               inner_unary.inner.write (writer);
+                               return;
+                       }
                        writer.write_string ("*");
                } else if (operator == CCodeUnaryOperator.ADDRESS_OF) {
+                       var inner_unary = inner as CCodeUnaryExpression;
+                       if (inner_unary != null && inner_unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
+                               // simplify expression
+                               inner_unary.inner.write (writer);
+                               return;
+                       }
                        writer.write_string ("&");
                } else if (operator == CCodeUnaryOperator.PREFIX_INCREMENT) {
                        writer.write_string ("++");
index cd537bcbc1ae5f29c8ad56895883a07914fdf749..3768b3b2dfc4af7c0118a5babe5b2294a41bd556 100644 (file)
@@ -377,7 +377,7 @@ internal class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                        var type_as_struct = p.parameter_type.data_type as Struct;
                                        if (p.direction != ParameterDirection.IN
                                            || (type_as_struct != null && !type_as_struct.is_simple_type () && !p.parameter_type.nullable)) {
-                                               expr.ccodenode = new CCodeIdentifier ("(*%s)".printf (get_variable_cname (p.name)));
+                                               expr.ccodenode = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_variable_cname (p.name)));
                                        } else {
                                                // Property setters of non simple structs shall replace all occurences
                                                // of the "value" formal parameter with a dereferencing version of that
@@ -387,7 +387,7 @@ internal class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                                    current_property_accessor.value_parameter == p &&
                                                    current_property_accessor.prop.property_type.is_real_struct_type () &&
                                                    !current_property_accessor.prop.property_type.nullable) {
-                                                       expr.ccodenode = new CCodeIdentifier ("(*value)");
+                                                       expr.ccodenode = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("value"));
                                                } else {
                                                        expr.ccodenode = get_variable_cexpression (p.name);
                                                }