allow pointer arithmetic
authorJuerg Billeter <j@bitron.ch>
Thu, 7 Feb 2008 17:36:38 +0000 (17:36 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 7 Feb 2008 17:36:38 +0000 (17:36 +0000)
2008-02-07  Juerg Billeter  <j@bitron.ch>

* vala/valasemanticanalyzer.vala: allow pointer arithmetic

svn path=/trunk/; revision=991

ChangeLog
vala/valasemanticanalyzer.vala

index fda8edb..d3f9268 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-02-07  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valasemanticanalyzer.vala: allow pointer arithmetic
+
+2008-02-07  Jürg Billeter  <j@bitron.ch>
+
        * vapi/packages/gtk+-2.0/gtk+-2.0.metadata: fix
          gtk_tree_model_iter_nth_child binding, fixes bug 514869
 
index b386ad9..89b21e0 100644 (file)
@@ -2453,7 +2453,21 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                           || expr.operator == BinaryOperator.MINUS
                           || expr.operator == BinaryOperator.MUL
                           || expr.operator == BinaryOperator.DIV) {
-                       expr.static_type = get_arithmetic_result_type (expr.left.static_type, expr.right.static_type);
+                       // check for pointer arithmetic
+                       if (expr.left.static_type is PointerType) {
+                               var offset_type = expr.right.static_type.data_type as Struct;
+                               if (offset_type != null && offset_type.is_integer_type ()) {
+                                       if (expr.operator == BinaryOperator.PLUS
+                                           || expr.operator == BinaryOperator.MINUS) {
+                                               // pointer arithmetic
+                                               expr.static_type = expr.left.static_type.copy ();
+                                       }
+                               }
+                       }
+
+                       if (expr.static_type == null) {
+                               expr.static_type = get_arithmetic_result_type (expr.left.static_type, expr.right.static_type);
+                       }
 
                        if (expr.static_type == null) {
                                expr.error = true;