]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
support member access, multiplicative, additive, shift, equality,
authorJürg Billeter <j@bitron.ch>
Tue, 16 May 2006 07:22:45 +0000 (07:22 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 16 May 2006 07:22:45 +0000 (07:22 +0000)
2006-05-16  Jürg Billeter  <j@bitron.ch>

* vala/parser.y: support member access, multiplicative, additive, shift,
  equality, relational, and bitwise expressions
* vala/valabinaryexpression.vala
* vala/valamemberaccess.vala: add constructor
* vala/vala.h: update

svn path=/trunk/; revision=17

vala/ChangeLog
vala/vala/parser.y
vala/vala/vala.h
vala/vala/valabinaryexpression.vala [new file with mode: 0644]
vala/vala/valamemberaccess.vala

index 8fff9ec5032a1938eca93d26f916811f6347e38c..e4d553731c75e096c760b8f97f3b3144b423eeaa 100644 (file)
@@ -1,3 +1,11 @@
+2006-05-16  Jürg Billeter  <j@bitron.ch>
+
+       * vala/parser.y: support member access, multiplicative, additive, shift,
+         equality, relational, and bitwise expressions
+       * vala/valabinaryexpression.vala
+       * vala/valamemberaccess.vala: add constructor
+       * vala/vala.h: update
+
 2006-05-15  Jürg Billeter  <j@bitron.ch>
 
        * vala/scanner.l: support assign operators
index 79b31ad654c86470e365f674a5f75af213994486..500e2be5181273911e51be2837d5aac6d0dfc375 100644 (file)
@@ -407,6 +407,9 @@ parenthesized_expression
 
 member_access
        : primary_expression DOT identifier_or_new opt_type_argument_list
+         {
+               $$ = VALA_EXPRESSION (vala_member_access_new ($1, $3, src (@3)));
+         }
        ;
 
 identifier_or_new
@@ -480,42 +483,84 @@ cast_expression
 multiplicative_expression
        : unary_expression
        | multiplicative_expression STAR unary_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_MUL, $1, $3, src (@2)));
+         }
        | multiplicative_expression DIV unary_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_DIV, $1, $3, src (@2)));
+         }
        | multiplicative_expression PERCENT unary_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_MOD, $1, $3, src (@2)));
+         }
        ;
 
 additive_expression
        : multiplicative_expression
        | additive_expression PLUS multiplicative_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_PLUS, $1, $3, src (@2)));
+         }
        | additive_expression MINUS multiplicative_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_MINUS, $1, $3, src (@2)));
+         }
        ;
 
 shift_expression
        : additive_expression
        | shift_expression OP_SHIFT_LEFT additive_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_SHIFT_LEFT, $1, $3, src (@2)));
+         }
        /* don't use two OP_GT due to resolve parse conflicts
         * stacked generics won't be that common in vala */
        | shift_expression OP_SHIFT_RIGHT additive_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_SHIFT_RIGHT, $1, $3, src (@2)));
+         }
        ;
 
 relational_expression
        : shift_expression
        | relational_expression OP_LT shift_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_LESS_THAN, $1, $3, src (@2)));
+         }
        | relational_expression OP_GT shift_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_GREATER_THAN, $1, $3, src (@2)));
+         }
        | relational_expression OP_LE shift_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_LESS, $1, $3, src (@2)));
+         }
        | relational_expression OP_GE shift_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_GREATER, $1, $3, src (@2)));
+         }
        | relational_expression IS type
        ;
 
 equality_expression
        : relational_expression
        | equality_expression OP_EQ relational_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_EQUALITY, $1, $3, src (@2)));
+         }
        | equality_expression OP_NE relational_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_INEQUALITY, $1, $3, src (@2)));
+         }
        ;
 
 and_expression
        : equality_expression
        | and_expression BITWISE_AND equality_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_BITWISE_AND, $1, $3, src (@2)));
+         }
        ;
 
 exclusive_or_expression
@@ -526,6 +571,9 @@ exclusive_or_expression
 inclusive_or_expression
        : exclusive_or_expression
        | inclusive_or_expression BITWISE_OR exclusive_or_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_BITWISE_OR, $1, $3, src (@2)));
+         }
        ;
 
 conditional_and_expression
index 6ca922710b36395251550cb9c6816f40449c7d13..cce450110f1949c4aaac0e2db90650bb495c1374 100644 (file)
@@ -1,4 +1,5 @@
 #include <vala/valaattribute.h>
+#include <vala/valabinaryexpression.h>
 #include <vala/valablock.h>
 #include <vala/valabooleanliteral.h>
 #include <vala/valacastexpression.h>
diff --git a/vala/vala/valabinaryexpression.vala b/vala/vala/valabinaryexpression.vala
new file mode 100644 (file)
index 0000000..d86c680
--- /dev/null
@@ -0,0 +1,54 @@
+/* valabinaryexpression.vala
+ *
+ * Copyright (C) 2006  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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+       public class BinaryExpression : Expression {
+               public readonly ref BinaryOperator operator;
+               public readonly ref Expression left;
+               public readonly ref Expression right;
+               public readonly ref SourceReference source_reference;
+               
+               public static ref BinaryExpression new (BinaryOperator op, Expression left, Expression right, SourceReference source) {
+                       return (new BinaryExpression (operator = op, left = left, right = right, source_reference = source));
+               }
+       }
+       
+       public enum BinaryOperator {
+               PLUS,
+               MINUS,
+               MUL,
+               DIV,
+               MOD,
+               SHIFT_LEFT,
+               SHIFT_RIGHT,
+               LESS_THAN,
+               GREATER_THAN,
+               LESS,
+               GREATER,
+               EQUALITY,
+               INEQUALITY,
+               BITWISE_AND,
+               BITWISE_OR
+       }
+}
index 4cf44fe9a9aa566174571b6de2e6d8154a6584b5..4147d2478c4386fa224428dda0a3be434676b54f 100644 (file)
@@ -24,7 +24,11 @@ using GLib;
 
 namespace Vala {
        public class MemberAccess : Expression {
-               public ref Expression inner;
-               public ref Literal member_name;
+               public readonly ref Expression inner;
+               public readonly ref string member_name;
+               
+               public static ref MemberAccess new (Expression inner, string member) {
+                       return new MemberAccess (inner = inner, member_name = member);
+               }
        }
 }