adapt to BinaryOperator enum changes add operators to unary and binary
authorJürg Billeter <j@bitron.ch>
Thu, 18 May 2006 13:22:42 +0000 (13:22 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 18 May 2006 13:22:42 +0000 (13:22 +0000)
2006-05-18  Jürg Billeter  <j@bitron.ch>

* vala/parser.y: adapt to BinaryOperator enum changes
* vala/valacodegenerator.vala: add operators to unary and binary
  expressions
* vala/valabinaryexpression.vala: correct enum value names
* ccode/valaccodebinaryexpression.vala: add operator
* ccode/valaccodeunaryexpression.vala

svn path=/trunk/; revision=25

vala/ChangeLog
vala/ccode/valaccodebinaryexpression.vala
vala/ccode/valaccodeunaryexpression.vala [new file with mode: 0644]
vala/vala/parser.y
vala/vala/valabinaryexpression.vala
vala/vala/valacodegenerator.vala

index 0d357ba..c709911 100644 (file)
@@ -1,5 +1,14 @@
 2006-05-18  Jürg Billeter  <j@bitron.ch>
 
+       * vala/parser.y: adapt to BinaryOperator enum changes
+       * vala/valacodegenerator.vala: add operators to unary and binary
+         expressions
+       * vala/valabinaryexpression.vala: correct enum value names
+       * ccode/valaccodebinaryexpression.vala: add operator
+       * ccode/valaccodeunaryexpression.vala
+
+2006-05-18  Jürg Billeter  <j@bitron.ch>
+
        * vala/parser.y: support namespace attributes
        * vala/valaattributeprocessor.vala: process namespace and class
          attributes
index 0667e85..a733abf 100644 (file)
@@ -24,6 +24,7 @@ using GLib;
 
 namespace Vala {
        public class CCodeBinaryExpression : CCodeExpression {
+               public CCodeBinaryOperator operator { get; construct; }
                public CCodeExpression left { get; construct; }
                public CCodeExpression right { get; construct; }
                
@@ -31,9 +32,69 @@ namespace Vala {
                        if (left != null) {
                                left.write (writer);
                        }
+                       writer.write_string (" ");
+                       if (operator == CCodeBinaryOperator.PLUS) {
+                               writer.write_string ("+");
+                       } else if (operator == CCodeBinaryOperator.MINUS) {
+                               writer.write_string ("-");
+                       } else if (operator == CCodeBinaryOperator.MUL) {
+                               writer.write_string ("*");
+                       } else if (operator == CCodeBinaryOperator.DIV) {
+                               writer.write_string ("/");
+                       } else if (operator == CCodeBinaryOperator.MOD) {
+                               writer.write_string ("%");
+                       } else if (operator == CCodeBinaryOperator.SHIFT_LEFT) {
+                               writer.write_string ("<<");
+                       } else if (operator == CCodeBinaryOperator.SHIFT_RIGHT) {
+                               writer.write_string (">>");
+                       } else if (operator == CCodeBinaryOperator.LESS_THAN) {
+                               writer.write_string ("<");
+                       } else if (operator == CCodeBinaryOperator.GREATER_THAN) {
+                               writer.write_string (">");
+                       } else if (operator == CCodeBinaryOperator.LESS_THAN_OR_EQUAL) {
+                               writer.write_string ("<=");
+                       } else if (operator == CCodeBinaryOperator.GREATER_THAN_OR_EQUAL) {
+                               writer.write_string (">=");
+                       } else if (operator == CCodeBinaryOperator.EQUALITY) {
+                               writer.write_string ("==");
+                       } else if (operator == CCodeBinaryOperator.INEQUALITY) {
+                               writer.write_string ("!=");
+                       } else if (operator == CCodeBinaryOperator.BITWISE_AND) {
+                               writer.write_string ("&");
+                       } else if (operator == CCodeBinaryOperator.BITWISE_OR) {
+                               writer.write_string ("|");
+                       } else if (operator == CCodeBinaryOperator.BITWISE_XOR) {
+                               writer.write_string ("^");
+                       } else if (operator == CCodeBinaryOperator.AND) {
+                               writer.write_string ("&&");
+                       } else if (operator == CCodeBinaryOperator.OR) {
+                               writer.write_string ("||");
+                       }
+                       writer.write_string (" ");
                        if (right != null) {
                                right.write (writer);
                        }
                }
        }
+       
+       public enum CCodeBinaryOperator {
+               PLUS,
+               MINUS,
+               MUL,
+               DIV,
+               MOD,
+               SHIFT_LEFT,
+               SHIFT_RIGHT,
+               LESS_THAN,
+               GREATER_THAN,
+               LESS_THAN_OR_EQUAL,
+               GREATER_THAN_OR_EQUAL,
+               EQUALITY,
+               INEQUALITY,
+               BITWISE_AND,
+               BITWISE_OR,
+               BITWISE_XOR,
+               AND,
+               OR
+       }
 }
diff --git a/vala/ccode/valaccodeunaryexpression.vala b/vala/ccode/valaccodeunaryexpression.vala
new file mode 100644 (file)
index 0000000..df25949
--- /dev/null
@@ -0,0 +1,54 @@
+/* valaccodeunaryexpression.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 CCodeUnaryExpression : CCodeExpression {
+               public CCodeUnaryOperator operator { get; construct; }
+               public CCodeExpression inner { get; construct; }
+               
+               public override void write (CCodeWriter writer) {
+                       if (operator == CCodeUnaryOperator.PLUS) {
+                               writer.write_string ("+");
+                       } else if (operator == CCodeUnaryOperator.MINUS) {
+                               writer.write_string ("-");
+                       } else if (operator == CCodeUnaryOperator.LOGICAL_NEGATION) {
+                               writer.write_string ("!");
+                       } else if (operator == CCodeUnaryOperator.BITWISE_COMPLEMENT) {
+                               writer.write_string ("~");
+                       } else if (operator == CCodeUnaryOperator.ADDRESS_OF) {
+                               writer.write_string ("&");
+                       }
+
+                       inner.write (writer);
+               }
+       }
+       
+       public enum CCodeUnaryOperator {
+               PLUS,
+               MINUS,
+               LOGICAL_NEGATION,
+               BITWISE_COMPLEMENT,
+               ADDRESS_OF
+       }
+}
index ed10b46..8325bdd 100644 (file)
@@ -546,11 +546,11 @@ relational_expression
          }
        | relational_expression OP_LE shift_expression
          {
-               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_LESS, $1, $3, src (@2)));
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_LESS_THAN_OR_EQUAL, $1, $3, src (@2)));
          }
        | relational_expression OP_GE shift_expression
          {
-               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_GREATER, $1, $3, src (@2)));
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_GREATER_THAN_OR_EQUAL, $1, $3, src (@2)));
          }
        | relational_expression IS type
        ;
index ff5821e..8037d63 100644 (file)
@@ -51,8 +51,8 @@ namespace Vala {
                SHIFT_RIGHT,
                LESS_THAN,
                GREATER_THAN,
-               LESS,
-               GREATER,
+               LESS_THAN_OR_EQUAL,
+               GREATER_THAN_OR_EQUAL,
                EQUALITY,
                INEQUALITY,
                BITWISE_AND,
index 4b0e03c..1806b76 100644 (file)
@@ -293,7 +293,21 @@ namespace Vala {
                }
 
                public override void visit_unary_expression (UnaryExpression expr) {
-                       expr.ccodenode = expr.inner.ccodenode;
+                       CCodeUnaryOperator op;
+                       if (expr.operator == UnaryOperator.PLUS) {
+                               op = CCodeUnaryOperator.PLUS;
+                       } else if (expr.operator == UnaryOperator.MINUS) {
+                               op = CCodeUnaryOperator.MINUS;
+                       } else if (expr.operator == UnaryOperator.LOGICAL_NEGATION) {
+                               op = CCodeUnaryOperator.LOGICAL_NEGATION;
+                       } else if (expr.operator == UnaryOperator.BITWISE_COMPLEMENT) {
+                               op = CCodeUnaryOperator.BITWISE_COMPLEMENT;
+                       } else if (expr.operator == UnaryOperator.REF) {
+                               op = CCodeUnaryOperator.ADDRESS_OF;
+                       } else if (expr.operator == UnaryOperator.OUT) {
+                               op = CCodeUnaryOperator.ADDRESS_OF;
+                       }
+                       expr.ccodenode = new CCodeUnaryExpression (operator = op, inner = expr.inner.ccodenode);
                }
 
                public override void visit_cast_expression (CastExpression expr) {
@@ -301,7 +315,7 @@ namespace Vala {
                }
 
                public override void visit_binary_expression (BinaryExpression expr) {
-                       expr.ccodenode = new CCodeBinaryExpression (left = expr.left.ccodenode, right = expr.right.ccodenode);
+                       expr.ccodenode = new CCodeBinaryExpression (operator = expr.operator, left = expr.left.ccodenode, right = expr.right.ccodenode);
                }
 
                public override void visit_assignment (Assignment a) {