From f0c3a37f2a7c50b451cc7905efe4b3e78791e70c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Tue, 16 May 2006 08:52:23 +0000 Subject: [PATCH] support logical AND and OR expressions, conditional expressions, MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-05-16 Jürg Billeter * 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 --- vala/ChangeLog | 16 +++++++++ vala/vala/parser.y | 61 ++++++++++++++++++++++++++++---- vala/vala/vala.h | 7 ++++ vala/vala/valaassignment.vala | 35 ++++++++++++++++++ vala/vala/valabinaryexpression.vala | 5 ++- vala/vala/valacodevisitor.vala | 6 ++++ vala/vala/valaconditionalexpression.vala | 36 +++++++++++++++++++ vala/vala/valaconstant.vala | 43 ++++++++++++++++++++++ vala/vala/valaformalparameter.vala | 35 ++++++++++++++++++ vala/vala/valainitializerlist.vala | 34 ++++++++++++++++++ vala/vala/valamemberaccess.vala | 5 +-- vala/vala/valamethod.vala | 5 +++ vala/vala/valaproperty.vala | 41 +++++++++++++++++++++ 13 files changed, 319 insertions(+), 10 deletions(-) create mode 100644 vala/vala/valaassignment.vala create mode 100644 vala/vala/valaconditionalexpression.vala create mode 100644 vala/vala/valaconstant.vala create mode 100644 vala/vala/valaformalparameter.vala create mode 100644 vala/vala/valainitializerlist.vala create mode 100644 vala/vala/valaproperty.vala diff --git a/vala/ChangeLog b/vala/ChangeLog index e4d5537..a5a65a5 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,5 +1,21 @@ 2006-05-16 Jürg Billeter + * 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 + * vala/parser.y: support member access, multiplicative, additive, shift, equality, relational, and bitwise expressions * vala/valabinaryexpression.vala diff --git a/vala/vala/parser.y b/vala/vala/parser.y index 500e2be..30d489f 100644 --- a/vala/vala/parser.y +++ b/vala/vala/parser.y @@ -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 return_statement %type namespace_declaration %type class_declaration +%type property_declaration %type struct_declaration %type struct_header %type enum_declaration +%type constant_declaration +%type constant_declarator %type field_declaration %type variable_declarators %type variable_declarator @@ -231,6 +237,10 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %type method_declaration %type method_header %type method_body +%type opt_formal_parameter_list +%type formal_parameter_list +%type fixed_parameters +%type fixed_parameter %type opt_attributes %type attributes %type 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 diff --git a/vala/vala/vala.h b/vala/vala/vala.h index cce4501..63f145d 100644 --- a/vala/vala/vala.h +++ b/vala/vala/vala.h @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -13,13 +16,16 @@ #include #include #include +#include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -29,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/vala/vala/valaassignment.vala b/vala/vala/valaassignment.vala new file mode 100644 index 0000000..120beb9 --- /dev/null +++ b/vala/vala/valaassignment.vala @@ -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 + */ + +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)); + } + } +} diff --git a/vala/vala/valabinaryexpression.vala b/vala/vala/valabinaryexpression.vala index d86c680..bd9943f 100644 --- a/vala/vala/valabinaryexpression.vala +++ b/vala/vala/valabinaryexpression.vala @@ -49,6 +49,9 @@ namespace Vala { EQUALITY, INEQUALITY, BITWISE_AND, - BITWISE_OR + BITWISE_OR, + BITWISE_XOR, + AND, + OR } } diff --git a/vala/vala/valacodevisitor.vala b/vala/vala/valacodevisitor.vala index e340b5a..ecc16d5 100644 --- a/vala/vala/valacodevisitor.vala +++ b/vala/vala/valacodevisitor.vala @@ -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 index 0000000..a112751 --- /dev/null +++ b/vala/vala/valaconditionalexpression.vala @@ -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 + */ + +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 index 0000000..a8cb339 --- /dev/null +++ b/vala/vala/valaconstant.vala @@ -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 + */ + +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 index 0000000..8e63547 --- /dev/null +++ b/vala/vala/valaformalparameter.vala @@ -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 + */ + +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 index 0000000..f0baaa5 --- /dev/null +++ b/vala/vala/valainitializerlist.vala @@ -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 + */ + +using GLib; + +namespace Vala { + public class InitializerList : Expression { + public readonly ref List initializers; + public readonly ref SourceReference source_reference; + + public static ref InitializerList new (List initializers, SourceReference source) { + return (new InitializerList (initializers = initializers, source_reference = source)); + } + } +} diff --git a/vala/vala/valamemberaccess.vala b/vala/vala/valamemberaccess.vala index 4147d24..b1df971 100644 --- a/vala/vala/valamemberaccess.vala +++ b/vala/vala/valamemberaccess.vala @@ -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); } } } diff --git a/vala/vala/valamethod.vala b/vala/vala/valamethod.vala index f56a8d5..c7992e9 100644 --- a/vala/vala/valamethod.vala +++ b/vala/vala/valamethod.vala @@ -38,11 +38,16 @@ namespace Vala { } public MemberAccessibility access; public bool instance = true; + ref List 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 index 0000000..f3d5267 --- /dev/null +++ b/vala/vala/valaproperty.vala @@ -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 + */ + +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); + } + } +} -- 2.7.4