support logical AND and OR expressions, conditional expressions,
authorJürg Billeter <j@bitron.ch>
Tue, 16 May 2006 08:52:23 +0000 (08:52 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 16 May 2006 08:52:23 +0000 (08:52 +0000)
2006-05-16  Jürg Billeter  <j@bitron.ch>

* vala/parser.y: support logical AND and OR expressions, conditional
  expressions, assignments, constants, method parameters, and properties
* vala/valacodevisitor.vala: add constant and property visits
* vala/valaassignment.vala
* vala/valabinaryexpression.vala: add bitwise xor, AND, and OR
* vala/valaconditionalexpression.vala
* vala/valaconstant.vala
* vala/valaformalparameter.vala
* vala/valainitializerlist.vala
* vala/valamemberaccess.vala: add source_reference
* vala/valamethod.vala: add parameters
* vala/valaproperty.vala
* vala/vala.h: update

svn path=/trunk/; revision=18

13 files changed:
vala/ChangeLog
vala/vala/parser.y
vala/vala/vala.h
vala/vala/valaassignment.vala [new file with mode: 0644]
vala/vala/valabinaryexpression.vala
vala/vala/valacodevisitor.vala
vala/vala/valaconditionalexpression.vala [new file with mode: 0644]
vala/vala/valaconstant.vala [new file with mode: 0644]
vala/vala/valaformalparameter.vala [new file with mode: 0644]
vala/vala/valainitializerlist.vala [new file with mode: 0644]
vala/vala/valamemberaccess.vala
vala/vala/valamethod.vala
vala/vala/valaproperty.vala [new file with mode: 0644]

index e4d5537..a5a65a5 100644 (file)
@@ -1,5 +1,21 @@
 2006-05-16  Jürg Billeter  <j@bitron.ch>
 
+       * vala/parser.y: support logical AND and OR expressions, conditional
+         expressions, assignments, constants, method parameters, and properties
+       * vala/valacodevisitor.vala: add constant and property visits
+       * vala/valaassignment.vala
+       * vala/valabinaryexpression.vala: add bitwise xor, AND, and OR
+       * vala/valaconditionalexpression.vala
+       * vala/valaconstant.vala
+       * vala/valaformalparameter.vala
+       * vala/valainitializerlist.vala
+       * vala/valamemberaccess.vala: add source_reference
+       * vala/valamethod.vala: add parameters
+       * vala/valaproperty.vala
+       * vala/vala.h: update
+
+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
index 500e2be..30d489f 100644 (file)
@@ -64,8 +64,11 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
        ValaClass *class;
        ValaStruct *struct_;
        ValaEnum *enum_;
+       ValaConstant *constant;
        ValaField *field;
        ValaMethod *method;
+       ValaFormalParameter *formal_parameter;
+       ValaProperty *property;
        ValaLocalVariableDeclaration *local_variable_declaration;
        ValaVariableDeclarator *variable_declarator;
        ValaTypeParameter *type_parameter;
@@ -220,9 +223,12 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <statement> return_statement
 %type <namespace> namespace_declaration
 %type <class> class_declaration
+%type <property> property_declaration
 %type <struct_> struct_declaration
 %type <struct_> struct_header
 %type <enum_> enum_declaration
+%type <constant> constant_declaration
+%type <variable_declarator> constant_declarator
 %type <field> field_declaration
 %type <list> variable_declarators
 %type <variable_declarator> variable_declarator
@@ -231,6 +237,10 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
 %type <method> method_declaration
 %type <method> method_header
 %type <statement> method_body
+%type <list> opt_formal_parameter_list
+%type <list> formal_parameter_list
+%type <list> fixed_parameters
+%type <formal_parameter> fixed_parameter
 %type <list> opt_attributes
 %type <list> attributes
 %type <list> attribute_sections
@@ -566,6 +576,9 @@ and_expression
 exclusive_or_expression
        : and_expression
        | exclusive_or_expression CARRET and_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_BITWISE_XOR, $1, $3, src (@2)));
+         }
        ;
 
 inclusive_or_expression
@@ -579,20 +592,32 @@ inclusive_or_expression
 conditional_and_expression
        : inclusive_or_expression
        | conditional_and_expression OP_AND inclusive_or_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_AND, $1, $3, src (@2)));
+         }
        ;
 
 conditional_or_expression
        : conditional_and_expression
        | conditional_or_expression OP_OR conditional_and_expression
+         {
+               $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_OR, $1, $3, src (@2)));
+         }
        ;
 
 conditional_expression
        : conditional_or_expression
        | conditional_or_expression INTERR expression COLON expression
+         {
+               $$ = VALA_EXPRESSION (vala_conditional_expression_new ($1, $3, $5, src (@2)));
+         }
        ;
 
 assignment
        : unary_expression assignment_operator expression
+         {
+               $$ = VALA_EXPRESSION (vala_assignment_new ($1, $3, src (@2)));
+         }
        ;
 
 assignment_operator
@@ -959,16 +984,17 @@ class_member_declaration
        ;
 
 constant_declaration
-       : comment opt_attributes opt_access_modifier CONST type constant_declarators SEMICOLON
-       ;
-
-constant_declarators
-       : constant_declarator
-       | constant_declarators COMMA constant_declarator
+       : comment opt_attributes opt_access_modifier CONST type constant_declarator SEMICOLON
+         {
+               $$ = vala_constant_new (vala_variable_declarator_get_name ($6), $5, vala_variable_declarator_get_initializer ($6), src_com (@5, $1));
+         }
        ;
 
 constant_declarator
        : IDENTIFIER ASSIGN initializer
+         {
+               $$ = vala_variable_declarator_new ($1, $3, src(@1));
+         }
        ;
 
 field_declaration
@@ -1022,7 +1048,7 @@ initializer
        : expression
        | OPEN_BRACE initializer_list CLOSE_BRACE
          {
-               $$ = $2;
+               $$ = VALA_EXPRESSION (vala_initializer_list_new ($2, src (@1)));
          }
        ;
 
@@ -1041,8 +1067,14 @@ method_declaration
 method_header
        : comment opt_attributes opt_access_modifier opt_modifiers opt_ref type identifier_or_new OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
+               GList *l;
+               
                $$ = vala_method_new ($7, src_com (@7, $1));
                VALA_CODE_NODE($$)->attributes = $2;
+               
+               for (l = $9; l != NULL; l = l->next) {
+                       vala_method_add_parameter ($$, l->data);
+               }       
          }
        ;
 
@@ -1056,6 +1088,9 @@ method_body
 
 opt_formal_parameter_list
        : /* empty */
+         {
+               $$ = NULL;
+         }
        | formal_parameter_list
        ;
 
@@ -1065,11 +1100,20 @@ formal_parameter_list
 
 fixed_parameters
        : fixed_parameter
+         {
+               $$ = g_list_append (NULL, $1);
+         }
        | fixed_parameters COMMA fixed_parameter
+         {
+               $$ = g_list_append ($1, $3);
+         }
        ;
 
 fixed_parameter
        : opt_attributes opt_parameter_modifier type IDENTIFIER
+         {
+               $$ = vala_formal_parameter_new ($4, $3, src (@3));
+         }
        ;
 
 opt_parameter_modifier
@@ -1084,6 +1128,9 @@ parameter_modifier
 
 property_declaration
        : comment opt_attributes opt_access_modifier opt_modifiers opt_ref type IDENTIFIER OPEN_BRACE accessor_declarations CLOSE_BRACE
+         {
+               $$ = vala_property_new ($7, $6, src_com (@6, $1));
+         }
        ;
 
 accessor_declarations
index cce4501..63f145d 100644 (file)
@@ -1,3 +1,4 @@
+#include <vala/valaassignment.h>
 #include <vala/valaattribute.h>
 #include <vala/valabinaryexpression.h>
 #include <vala/valablock.h>
@@ -6,6 +7,8 @@
 #include <vala/valacharacterliteral.h>
 #include <vala/valaclass.h>
 #include <vala/valacodecontext.h>
+#include <vala/valaconditionalexpression.h>
+#include <vala/valaconstant.h>
 #include <vala/valadeclarationstatement.h>
 #include <vala/valaemptystatement.h>
 #include <vala/valaenum.h>
 #include <vala/valaexpressionstatement.h>
 #include <vala/valafield.h>
 #include <vala/valaforeachstatement.h>
+#include <vala/valaformalparameter.h>
 #include <vala/valaforstatement.h>
 #include <vala/valaifstatement.h>
+#include <vala/valainitializerlist.h>
 #include <vala/valaintegerliteral.h>
 #include <vala/valainvocationexpression.h>
 #include <vala/valaliteral.h>
 #include <vala/valaliteralexpression.h>
 #include <vala/valalocalvariabledeclaration.h>
+#include <vala/valamemberaccess.h>
 #include <vala/valamethod.h>
 #include <vala/valanamedargument.h>
 #include <vala/valanamespace.h>
@@ -29,6 +35,7 @@
 #include <vala/valaparenthesizedexpression.h>
 #include <vala/valaparser.h>
 #include <vala/valapostfixexpression.h>
+#include <vala/valaproperty.h>
 #include <vala/valareturnstatement.h>
 #include <vala/valasimplename.h>
 #include <vala/valasourcefile.h>
diff --git a/vala/vala/valaassignment.vala b/vala/vala/valaassignment.vala
new file mode 100644 (file)
index 0000000..120beb9
--- /dev/null
@@ -0,0 +1,35 @@
+/* valaassignment.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 Assignment : Expression {
+               public readonly ref Expression left;
+               public readonly ref Expression right;
+               public readonly ref SourceReference source_reference;
+               
+               public static ref Assignment new (Expression left, Expression right, SourceReference source) {
+                       return (new Assignment (left = left, right = right, source_reference = source));
+               }
+       }
+}
index d86c680..bd9943f 100644 (file)
@@ -49,6 +49,9 @@ namespace Vala {
                EQUALITY,
                INEQUALITY,
                BITWISE_AND,
-               BITWISE_OR
+               BITWISE_OR,
+               BITWISE_XOR,
+               AND,
+               OR
        }
 }
index e340b5a..ecc16d5 100644 (file)
@@ -51,12 +51,18 @@ namespace Vala {
                public virtual void visit_enum (Enum en) {
                }
 
+               public virtual void visit_constant (Constant c) {
+               }
+
                public virtual void visit_field (Field f) {
                }
 
                public virtual void visit_method (Method m) {
                }
 
+               public virtual void visit_property (Property prop) {
+               }
+
                public virtual void visit_type_parameter (TypeParameter p) {
                }
 
diff --git a/vala/vala/valaconditionalexpression.vala b/vala/vala/valaconditionalexpression.vala
new file mode 100644 (file)
index 0000000..a112751
--- /dev/null
@@ -0,0 +1,36 @@
+/* valaconditionalexpression.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 ConditionalExpression : Expression {
+               public readonly ref Expression condition;
+               public readonly ref Expression true_expression;
+               public readonly ref Expression false_expression;
+               public readonly ref SourceReference source_reference;
+               
+               public static ref ConditionalExpression new (Expression cond, Expression true_expr, Expression false_expr, SourceReference source) {
+                       return (new ConditionalExpression (condition = cond, true_expression = true_expr, false_expression = false_expr, source_reference = source));
+               }
+       }
+}
diff --git a/vala/vala/valaconstant.vala b/vala/vala/valaconstant.vala
new file mode 100644 (file)
index 0000000..a8cb339
--- /dev/null
@@ -0,0 +1,43 @@
+/* valaconstant.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 Constant : CodeNode {
+               public readonly string# name;
+               public readonly TypeReference# type_reference;
+               public readonly Expression# initializer;
+               public readonly SourceReference# source_reference;
+               public CodeNode parent_type;
+               
+               public static ref Constant new (string name, TypeReference type, Expression init, SourceReference source) {
+                       return (new Constant (name = name, type_reference = type, initializer = init, source_reference = source));
+               }
+               
+               public override void accept (CodeVisitor visitor) {
+                       visitor.visit_constant (this);
+                       
+                       type_reference.accept (visitor);
+               }
+       }
+}
diff --git a/vala/vala/valaformalparameter.vala b/vala/vala/valaformalparameter.vala
new file mode 100644 (file)
index 0000000..8e63547
--- /dev/null
@@ -0,0 +1,35 @@
+/* valaformalparameter.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 FormalParameter : CodeNode {
+               public readonly ref string name;
+               public readonly ref TypeReference type_reference;
+               public readonly ref SourceReference source_reference;
+               
+               public static ref FormalParameter new (string name, TypeReference type, SourceReference source) {
+                       return (new FormalParameter (name = name, type_reference = type, source_reference = source));
+               }
+       }
+}
diff --git a/vala/vala/valainitializerlist.vala b/vala/vala/valainitializerlist.vala
new file mode 100644 (file)
index 0000000..f0baaa5
--- /dev/null
@@ -0,0 +1,34 @@
+/* valainitializerlist.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 InitializerList : Expression {
+               public readonly ref List<ref Expression> initializers;
+               public readonly ref SourceReference source_reference;
+               
+               public static ref InitializerList new (List<Expression> initializers, SourceReference source) {
+                       return (new InitializerList (initializers = initializers, source_reference = source));
+               }
+       }
+}
index 4147d24..b1df971 100644 (file)
@@ -26,9 +26,10 @@ namespace Vala {
        public class MemberAccess : Expression {
                public readonly ref Expression inner;
                public readonly ref string member_name;
+               public readonly ref SourceReference source_reference;
                
-               public static ref MemberAccess new (Expression inner, string member) {
-                       return new MemberAccess (inner = inner, member_name = member);
+               public static ref MemberAccess new (Expression inner, string member, SourceReference source) {
+                       return new MemberAccess (inner = inner, member_name = member, source_reference = source);
                }
        }
 }
index f56a8d5..c7992e9 100644 (file)
@@ -38,11 +38,16 @@ namespace Vala {
                }
                public MemberAccessibility access;
                public bool instance = true;
+               ref List<ref FormalParameter> parameters;
                
                public static Method# @new (string name, SourceReference source) {
                        return (new Method (name = name, source_reference = source));
                }
                
+               public void add_parameter (FormalParameter param) {
+                       parameters.append (param);
+               }
+               
                public override void accept (CodeVisitor visitor) {
                        visitor.visit_method (this);
                }
diff --git a/vala/vala/valaproperty.vala b/vala/vala/valaproperty.vala
new file mode 100644 (file)
index 0000000..f3d5267
--- /dev/null
@@ -0,0 +1,41 @@
+/* valaproperty.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 Property : CodeNode {
+               public readonly ref string name;
+               public readonly ref TypeReference type_reference;
+               public readonly ref SourceReference source_reference;
+               public CodeNode parent_type;
+               public MemberAccessibility access;
+               
+               public static ref Property new (string name, TypeReference type, SourceReference source) {
+                       return (new Property (name = name, type_reference = type, source_reference = source));
+               }
+               
+               public override void accept (CodeVisitor visitor) {
+                       visitor.visit_property (this);
+               }
+       }
+}