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
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;
%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
%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
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
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
;
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
: expression
| OPEN_BRACE initializer_list CLOSE_BRACE
{
- $$ = $2;
+ $$ = VALA_EXPRESSION (vala_initializer_list_new ($2, src (@1)));
}
;
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);
+ }
}
;
opt_formal_parameter_list
: /* empty */
+ {
+ $$ = NULL;
+ }
| 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
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
+#include <vala/valaassignment.h>
#include <vala/valaattribute.h>
#include <vala/valabinaryexpression.h>
#include <vala/valablock.h>
#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>
#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>
--- /dev/null
+/* 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));
+ }
+ }
+}
EQUALITY,
INEQUALITY,
BITWISE_AND,
- BITWISE_OR
+ BITWISE_OR,
+ BITWISE_XOR,
+ AND,
+ OR
}
}
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) {
}
--- /dev/null
+/* 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));
+ }
+ }
+}
--- /dev/null
+/* 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);
+ }
+ }
+}
--- /dev/null
+/* 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));
+ }
+ }
+}
--- /dev/null
+/* 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));
+ }
+ }
+}
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);
}
}
}
}
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);
}
--- /dev/null
+/* 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);
+ }
+ }
+}