[vala] Simplify &(*foo) and *(&foo) to foo
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Simplify &(*foo) and *(&foo) to foo
- Date: Tue, 22 Sep 2009 21:10:12 +0000 (UTC)
commit 363f6c8a3475c2221cb08700cb1c785685281892
Author: Jürg Billeter <j bitron ch>
Date: Tue Sep 22 23:09:03 2009 +0200
Simplify &(*foo) and *(&foo) to foo
ccode/valaccodeunaryexpression.vala | 14 +++++++++++++-
codegen/valaccodememberaccessmodule.vala | 4 ++--
2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/ccode/valaccodeunaryexpression.vala b/ccode/valaccodeunaryexpression.vala
index 0f33478..7f2b89b 100644
--- a/ccode/valaccodeunaryexpression.vala
+++ b/ccode/valaccodeunaryexpression.vala
@@ -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 ("++");
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index cd537bc..3768b3b 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]