+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
namespace Vala {
public class CCodeBinaryExpression : CCodeExpression {
+ public CCodeBinaryOperator operator { get; construct; }
public CCodeExpression left { get; construct; }
public CCodeExpression right { get; construct; }
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
+ }
}
--- /dev/null
+/* 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
+ }
+}
}
| 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
;
SHIFT_RIGHT,
LESS_THAN,
GREATER_THAN,
- LESS,
- GREATER,
+ LESS_THAN_OR_EQUAL,
+ GREATER_THAN_OR_EQUAL,
EQUALITY,
INEQUALITY,
BITWISE_AND,
}
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) {
}
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) {