support delegate keyword and optional modifiers to declare callbacks
[vala-lang.git] / vala / parser.y
blobdd3f6c22dc239f009ec59d40014e4103e8632169
1 /* parser.y
3 * Copyright (C) 2006-2007 Jürg Billeter, Raffaele Sandrini
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
21 * Raffaele Sandrini <rasa@gmx.ch>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include <glib.h>
31 #include "vala.h"
32 #include "parser.h"
34 #define src(l) (vala_source_reference_new (current_source_file, l.first_line, l.first_column, l.last_line, l.last_column))
36 #define src_com(l,c) (vala_source_reference_new_with_comment (current_source_file, l.first_line, l.first_column, l.last_line, l.last_column, c))
38 static ValaSourceFile *current_source_file;
39 static ValaNamespace *current_namespace;
40 static gboolean current_namespace_implicit;
41 static ValaClass *current_class;
42 static ValaStruct *current_struct;
43 static ValaInterface *current_interface;
44 static ValaEnum *current_enum;
46 typedef enum {
47 VALA_MODIFIER_NONE,
48 VALA_MODIFIER_ABSTRACT = 1 << 0,
49 VALA_MODIFIER_OVERRIDE = 1 << 1,
50 VALA_MODIFIER_STATIC = 1 << 2,
51 VALA_MODIFIER_VIRTUAL = 1 << 3
52 } ValaModifier;
54 int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param, ValaParser *parser);
55 static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg);
58 %defines
59 %locations
60 %pure-parser
61 %parse-param {ValaParser *parser}
62 %lex-param {ValaParser *parser}
63 %error-verbose
64 %union {
65 int num;
66 char *str;
67 GList *list;
68 ValaLiteral *literal;
69 ValaTypeReference *type_reference;
70 ValaExpression *expression;
71 ValaStatement *statement;
72 ValaNamespace *namespace;
73 ValaClass *class;
74 ValaStruct *struct_;
75 ValaInterface *interface;
76 ValaEnum *enum_;
77 ValaEnumValue *enum_value;
78 ValaFlags *flags;
79 ValaFlagsValue *flags_value;
80 ValaCallback *callback;
81 ValaConstant *constant;
82 ValaField *field;
83 ValaMethod *method;
84 ValaFormalParameter *formal_parameter;
85 ValaProperty *property;
86 ValaPropertyAccessor *property_accessor;
87 ValaSignal *signal;
88 ValaConstructor *constructor;
89 ValaDestructor *destructor;
90 ValaLocalVariableDeclaration *local_variable_declaration;
91 ValaVariableDeclarator *variable_declarator;
92 ValaTypeParameter *type_parameter;
93 ValaAttribute *attribute;
94 ValaNamedArgument *named_argument;
95 ValaSwitchSection *switch_section;
96 ValaSwitchLabel *switch_label;
97 ValaCatchClause *catch_clause;
100 %token OPEN_BRACE "{"
101 %token CLOSE_BRACE "}"
102 %token OPEN_PARENS "("
103 %token OPEN_CAST_PARENS "cast ("
104 %token CLOSE_PARENS ")"
105 %token BRACKET_PAIR "[]"
106 %token OPEN_BRACKET "["
107 %token CLOSE_BRACKET "]"
108 %token ELLIPSIS "..."
109 %token DOT "."
110 %token COLON ":"
111 %token COMMA ","
112 %token SEMICOLON ";"
113 %token HASH "#"
114 %token INTERR "?"
116 %token ASSIGN_BITWISE_OR "|="
117 %token ASSIGN_BITWISE_AND "&="
118 %token ASSIGN_BITWISE_XOR "^="
119 %token ASSIGN_ADD "+="
120 %token ASSIGN_SUB "-="
121 %token ASSIGN_MUL "*="
122 %token ASSIGN_DIV "/="
123 %token ASSIGN_PERCENT "%="
124 %token ASSIGN_SHIFT_LEFT "<<="
125 %token ASSIGN_SHIFT_RIGHT ">>="
127 %token OP_INC "++"
128 %token OP_DEC "--"
129 %token OP_EQ "=="
130 %token OP_NE "!="
131 %token OP_SHIFT_LEFT "<<"
132 %token OP_SHIFT_RIGHT ">>"
133 %token OP_LE "<="
134 %token OP_GE ">="
135 %token LAMBDA "=>"
136 %token GENERIC_LT "generic <"
137 %token OP_LT "<"
138 %token OP_GT ">"
139 %token OP_NEG "!"
140 %token CARRET "^"
141 %token BITWISE_OR "|"
142 %token BITWISE_AND "&"
143 %token OP_OR "||"
144 %token OP_AND "&&"
145 %token TILDE "~"
147 %token ASSIGN "="
148 %token PLUS "+"
149 %token MINUS "-"
150 %token STAR "*"
151 %token DIV "/"
152 %token PERCENT "%"
154 %token ABSTRACT "abstract"
155 %token BASE "base"
156 %token BREAK "break"
157 %token CALLBACK "callback"
158 %token CASE "case"
159 %token CATCH "catch"
160 %token CLASS "class"
161 %token CONST "const"
162 %token CONSTRUCT "construct"
163 %token CONTINUE "continue"
164 %token DEFAULT "default"
165 %token DELEGATE "delegate"
166 %token DO "do"
167 %token ELSE "else"
168 %token ENUM "enum"
169 %token VALA_FALSE "false"
170 %token FINALLY "finally"
171 %token FLAGS "flags"
172 %token FOR "for"
173 %token FOREACH "foreach"
174 %token GET "get"
175 %token IF "if"
176 %token IN "in"
177 %token INTERFACE "interface"
178 %token IS "is"
179 %token LOCK "lock"
180 %token NAMESPACE "namespace"
181 %token NEW "new"
182 %token VALA_NULL "null"
183 %token OUT "out"
184 %token OVERRIDE "override"
185 %token PRIVATE "private"
186 %token PROTECTED "protected"
187 %token PUBLIC "public"
188 %token REF "ref"
189 %token RETURN "return"
190 %token SET "set"
191 %token SIGNAL "signal"
192 %token SIZEOF "sizeof"
193 %token STATIC "static"
194 %token STRUCT "struct"
195 %token SWITCH "switch"
196 %token THIS "this"
197 %token THROW "throw"
198 %token THROWS "throws"
199 %token VALA_TRUE "true"
200 %token TRY "try"
201 %token TYPEOF "typeof"
202 %token USING "using"
203 %token VAR "var"
204 %token VIRTUAL "virtual"
205 %token WEAK "weak"
206 %token WHILE "while"
208 %token <str> IDENTIFIER "identifier"
209 %token <str> INTEGER_LITERAL "integer"
210 %token <str> REAL_LITERAL "real"
211 %token <str> CHARACTER_LITERAL "character"
212 %token <str> STRING_LITERAL "string"
214 %type <str> comment
215 %type <str> identifier
216 %type <literal> literal
217 %type <literal> boolean_literal
218 %type <num> stars
219 %type <type_reference> type_name
220 %type <type_reference> type
221 %type <list> opt_argument_list
222 %type <list> argument_list
223 %type <expression> argument
224 %type <expression> primary_expression
225 %type <expression> array_creation_expression
226 %type <list> size_specifier_list
227 %type <expression> opt_initializer
228 %type <num> opt_rank_specifier
229 %type <num> rank_specifier
230 %type <num> opt_bracket_pair
231 %type <num> bracket_pair
232 %type <num> opt_comma_list
233 %type <num> comma_list
234 %type <expression> primary_no_array_creation_expression
235 %type <expression> simple_name
236 %type <expression> parenthesized_expression
237 %type <expression> member_access
238 %type <expression> invocation_expression
239 %type <expression> element_access
240 %type <list> expression_list
241 %type <expression> this_access
242 %type <expression> base_access
243 %type <expression> post_increment_expression
244 %type <expression> post_decrement_expression
245 %type <expression> object_creation_expression
246 %type <expression> sizeof_expression
247 %type <expression> typeof_expression
248 %type <expression> unary_expression
249 %type <expression> pre_increment_expression
250 %type <expression> pre_decrement_expression
251 %type <expression> cast_expression
252 %type <expression> pointer_indirection_expression
253 %type <expression> addressof_expression
254 %type <expression> multiplicative_expression
255 %type <expression> additive_expression
256 %type <expression> shift_expression
257 %type <expression> relational_expression
258 %type <expression> equality_expression
259 %type <expression> and_expression
260 %type <expression> exclusive_or_expression
261 %type <expression> inclusive_or_expression
262 %type <expression> conditional_and_expression
263 %type <expression> conditional_or_expression
264 %type <expression> conditional_expression
265 %type <expression> lambda_expression
266 %type <list> opt_lambda_parameter_list
267 %type <list> lambda_parameter_list
268 %type <expression> assignment
269 %type <num> assignment_operator
270 %type <expression> opt_expression
271 %type <expression> expression
272 %type <statement> statement
273 %type <statement> embedded_statement
274 %type <statement> block
275 %type <list> opt_statement_list
276 %type <list> statement_list
277 %type <statement> empty_statement
278 %type <statement> declaration_statement
279 %type <local_variable_declaration> local_variable_declaration
280 %type <type_reference> local_variable_type
281 %type <num> opt_op_neg
282 %type <statement> expression_statement
283 %type <expression> statement_expression
284 %type <statement> selection_statement
285 %type <statement> if_statement
286 %type <statement> switch_statement
287 %type <list> switch_block
288 %type <list> opt_switch_sections
289 %type <list> switch_sections
290 %type <switch_section> switch_section
291 %type <list> switch_labels
292 %type <switch_label> switch_label
293 %type <statement> iteration_statement
294 %type <statement> while_statement
295 %type <statement> do_statement
296 %type <statement> for_statement
297 %type <list> opt_statement_expression_list
298 %type <list> statement_expression_list
299 %type <statement> foreach_statement
300 %type <statement> jump_statement
301 %type <statement> break_statement
302 %type <statement> continue_statement
303 %type <statement> return_statement
304 %type <statement> throw_statement
305 %type <statement> try_statement
306 %type <list> catch_clauses
307 %type <list> specific_catch_clauses
308 %type <catch_clause> specific_catch_clause
309 %type <catch_clause> opt_general_catch_clause
310 %type <catch_clause> general_catch_clause
311 %type <statement> opt_finally_clause
312 %type <statement> finally_clause
313 %type <statement> lock_statement
314 %type <namespace> namespace_declaration
315 %type <str> opt_name_specifier
316 %type <str> name_specifier
317 %type <class> class_declaration
318 %type <num> opt_access_modifier
319 %type <num> access_modifier
320 %type <num> opt_modifiers
321 %type <num> modifiers
322 %type <num> modifier
323 %type <list> opt_class_base
324 %type <list> class_base
325 %type <list> type_list
326 %type <property> property_declaration
327 %type <property_accessor> get_accessor_declaration
328 %type <property_accessor> opt_set_accessor_declaration
329 %type <property_accessor> set_accessor_declaration
330 %type <struct_> struct_declaration
331 %type <struct_> struct_header
332 %type <interface> interface_declaration
333 %type <enum_> enum_declaration
334 %type <flags> flags_declaration
335 %type <list> flags_body
336 %type <list> opt_flags_member_declarations
337 %type <list> flags_member_declarations
338 %type <flags_value> flags_member_declaration
339 %type <callback> callback_declaration
340 %type <constant> constant_declaration
341 %type <field> field_declaration
342 %type <list> variable_declarators
343 %type <variable_declarator> variable_declarator
344 %type <expression> initializer
345 %type <list> opt_variable_initializer_list
346 %type <list> variable_initializer_list
347 %type <expression> variable_initializer
348 %type <method> method_declaration
349 %type <method> method_header
350 %type <statement> method_body
351 %type <list> opt_formal_parameter_list
352 %type <list> formal_parameter_list
353 %type <num> opt_construct
354 %type <list> fixed_parameters
355 %type <formal_parameter> fixed_parameter
356 %type <list> opt_throws_declaration
357 %type <list> throws_declaration
358 %type <signal> signal_declaration
359 %type <constructor> constructor_declaration
360 %type <destructor> destructor_declaration
361 %type <list> opt_attributes
362 %type <list> attributes
363 %type <list> attribute_sections
364 %type <list> attribute_section
365 %type <list> attribute_list
366 %type <attribute> attribute
367 %type <str> attribute_name
368 %type <list> opt_named_argument_list
369 %type <list> named_argument_list
370 %type <named_argument> named_argument
371 %type <list> opt_type_parameter_list
372 %type <list> type_parameter_list
373 %type <list> type_parameters
374 %type <type_parameter> type_parameter
375 %type <list> opt_type_argument_list
376 %type <list> type_argument_list
377 %type <list> type_arguments
378 %type <type_reference> type_argument
379 %type <expression> member_name
381 /* expect shift/reduce conflict on if/else */
382 %expect 1
384 %start compilation_unit
388 opt_comma
389 : /* empty */
390 | COMMA
393 /* identifiers never conflict with context-specific keywords get or set */
394 identifier
395 : IDENTIFIER
396 | GET
398 $$ = g_strdup ("get");
400 | SET
402 $$ = g_strdup ("set");
406 literal
407 : boolean_literal
408 | INTEGER_LITERAL
410 ValaSourceReference *src = src(@1);
411 $$ = VALA_LITERAL (vala_integer_literal_new ($1, src));
412 g_object_unref (src);
413 g_free ($1);
415 | REAL_LITERAL
417 ValaSourceReference *src = src(@1);
418 $$ = VALA_LITERAL (vala_real_literal_new ($1, src));
419 g_free ($1);
420 g_object_unref (src);
422 | CHARACTER_LITERAL
424 ValaSourceReference *src = src(@1);
425 $$ = VALA_LITERAL (vala_character_literal_new ($1, src));
426 g_object_unref (src);
427 g_free ($1);
429 | STRING_LITERAL
431 ValaSourceReference *src = src(@1);
432 $$ = VALA_LITERAL (vala_string_literal_new ($1, src));
433 g_object_unref (src);
434 g_free ($1);
436 | VALA_NULL
438 ValaSourceReference *src = src(@1);
439 $$ = VALA_LITERAL (vala_null_literal_new (src));
440 g_object_unref (src);
444 boolean_literal
445 : VALA_TRUE
447 ValaSourceReference *src = src(@1);
448 $$ = VALA_LITERAL (vala_boolean_literal_new (TRUE, src));
449 g_object_unref (src);
451 | VALA_FALSE
453 ValaSourceReference *src = src(@1);
454 $$ = VALA_LITERAL (vala_boolean_literal_new (FALSE, src));
455 g_object_unref (src);
459 compilation_unit
460 : opt_using_directives opt_outer_declarations
463 type_name
464 : identifier opt_type_argument_list
466 GList *l;
467 ValaSourceReference *src = src(@1);
468 $$ = vala_type_reference_new_from_name (NULL, $1, src);
469 g_free ($1);
470 g_object_unref (src);
471 for (l = $2; l != NULL; l = l->next) {
472 vala_type_reference_add_type_argument ($$, l->data);
473 g_object_unref (l->data);
475 g_list_free ($2);
477 | identifier DOT identifier opt_type_argument_list
479 GList *l;
480 ValaSourceReference *src = src(@1);
481 $$ = vala_type_reference_new_from_name ($1, $3, src);
482 g_free ($1);
483 g_free ($3);
484 g_object_unref (src);
485 for (l = $4; l != NULL; l = l->next) {
486 vala_type_reference_add_type_argument ($$, l->data);
487 g_object_unref (l->data);
489 g_list_free ($4);
493 stars
494 : STAR
496 $$ = 1;
498 | stars STAR
500 $$ = $1 + 1;
504 type
505 : type_name opt_rank_specifier opt_op_neg
507 $$ = $1;
508 vala_type_reference_set_array_rank ($$, $2);
509 if ($3) {
510 vala_type_reference_set_non_null ($$, TRUE);
513 | type_name opt_rank_specifier opt_op_neg HASH
515 $$ = $1;
516 vala_type_reference_set_is_ref ($$, TRUE);
517 vala_type_reference_set_array_rank ($$, $2);
518 if ($3) {
519 vala_type_reference_set_non_null ($$, TRUE);
522 | REF type_name opt_rank_specifier opt_op_neg
524 $$ = $2;
525 vala_type_reference_set_is_ref ($$, TRUE);
526 vala_type_reference_set_array_rank ($$, $3);
527 if ($4) {
528 vala_type_reference_set_non_null ($$, TRUE);
531 | WEAK type_name opt_rank_specifier opt_op_neg
533 $$ = $2;
534 vala_type_reference_set_is_weak ($$, TRUE);
535 vala_type_reference_set_array_rank ($$, $3);
536 if ($4) {
537 vala_type_reference_set_non_null ($$, TRUE);
540 | OUT type_name opt_rank_specifier opt_op_neg
542 $$ = $2;
543 vala_type_reference_set_is_out ($$, TRUE);
544 vala_type_reference_set_array_rank ($$, $3);
545 if ($4) {
546 vala_type_reference_set_non_null ($$, TRUE);
549 | OUT REF type_name opt_rank_specifier opt_op_neg
551 $$ = $3;
552 vala_type_reference_set_is_ref ($$, TRUE);
553 vala_type_reference_set_is_out ($$, TRUE);
554 vala_type_reference_set_array_rank ($$, $4);
555 if ($5) {
556 vala_type_reference_set_non_null ($$, TRUE);
559 | type_name stars opt_rank_specifier opt_op_neg
561 $$ = $1;
562 vala_type_reference_set_pointer_level ($$, $2);
563 vala_type_reference_set_array_rank ($$, $3);
564 if ($4) {
565 vala_type_reference_set_non_null ($$, TRUE);
570 opt_argument_list
571 : /* empty */
573 $$ = NULL;
575 | argument_list
578 argument_list
579 : argument
581 $$ = g_list_append (NULL, $1);
583 | argument_list COMMA argument
585 $$ = g_list_append ($1, $3);
589 argument
590 : expression
593 primary_expression
594 : primary_no_array_creation_expression
595 | array_creation_expression
598 array_creation_expression
599 : NEW member_name size_specifier_list opt_initializer
601 GList *l;
602 ValaSourceReference *src = src(@2);
603 ValaTypeReference *t = vala_type_reference_new_from_expression (VALA_EXPRESSION ($2));
604 $$ = VALA_EXPRESSION (vala_array_creation_expression_new (t, g_list_length ($3), VALA_INITIALIZER_LIST ($4), src));
605 g_object_unref (t);
606 for (l = $3; l != NULL; l = l->next) {
607 vala_array_creation_expression_append_size (VALA_ARRAY_CREATION_EXPRESSION ($$), VALA_EXPRESSION (l->data));
608 g_object_unref (l->data);
610 g_list_free ($3);
611 g_object_unref (src);
612 g_object_unref ($2);
613 if ($4 != NULL) {
614 g_object_unref ($4);
617 | NEW member_name rank_specifier initializer
619 ValaSourceReference *src = src(@2);
620 ValaTypeReference *t = vala_type_reference_new_from_expression (VALA_EXPRESSION ($2));
621 $$ = VALA_EXPRESSION (vala_array_creation_expression_new (t, $3, VALA_INITIALIZER_LIST ($4), src));
622 g_object_unref (t);
623 g_object_unref (src);
624 g_object_unref ($2);
625 g_object_unref ($4);
629 size_specifier_list
630 : OPEN_BRACKET expression_list CLOSE_BRACKET
632 $$ = $2;
636 opt_initializer
637 : /* empty */
639 $$ = NULL;
641 | initializer
644 opt_rank_specifier
645 : /* empty */
647 $$ = 0;
649 | rank_specifier
652 rank_specifier
653 : OPEN_BRACKET opt_comma_list CLOSE_BRACKET
655 $$ = $2;
657 | bracket_pair
660 opt_bracket_pair
661 : /* empty */
663 $$ = 0;
665 | bracket_pair
668 bracket_pair
669 : BRACKET_PAIR
671 $$ = 1;
675 opt_comma_list
676 : /* empty */
678 $$ = 1;
680 | comma_list
683 comma_list
684 : COMMA
686 $$ = 1;
688 | comma_list COMMA
690 $$ = $1 + 1;
694 primary_no_array_creation_expression
695 : literal
697 ValaSourceReference *src = src(@1);
698 $$ = VALA_EXPRESSION (vala_literal_expression_new ($1, src));
699 g_object_unref (src);
700 g_object_unref ($1);
702 | simple_name
703 | parenthesized_expression
704 | member_access
705 | invocation_expression
706 | element_access
707 | this_access
708 | base_access
709 | post_increment_expression
710 | post_decrement_expression
711 | object_creation_expression
712 | sizeof_expression
713 | typeof_expression
716 simple_name
717 : identifier opt_type_argument_list
719 ValaSourceReference *src = src(@1);
720 $$ = VALA_EXPRESSION (vala_member_access_new (NULL, $1, src));
721 g_free ($1);
722 g_object_unref (src);
724 if ($2 != NULL) {
725 GList *l;
726 for (l = $2; l != NULL; l = l->next) {
727 vala_member_access_add_type_argument (VALA_MEMBER_ACCESS ($$), l->data);
728 g_object_unref (l->data);
730 g_list_free ($2);
735 parenthesized_expression
736 : OPEN_PARENS expression CLOSE_PARENS
738 ValaSourceReference *src = src(@2);
739 $$ = VALA_EXPRESSION (vala_parenthesized_expression_new ($2, src));
740 g_object_unref (src);
741 g_object_unref ($2);
745 member_access
746 : primary_expression DOT identifier opt_type_argument_list
748 ValaSourceReference *src = src(@3);
749 $$ = VALA_EXPRESSION (vala_member_access_new ($1, $3, src));
750 g_object_unref ($1);
751 g_free ($3);
752 g_object_unref (src);
754 if ($4 != NULL) {
755 GList *l;
756 for (l = $4; l != NULL; l = l->next) {
757 vala_member_access_add_type_argument (VALA_MEMBER_ACCESS ($$), l->data);
758 g_object_unref (l->data);
760 g_list_free ($4);
765 invocation_expression
766 : primary_expression open_parens opt_argument_list CLOSE_PARENS
768 ValaSourceReference *src = src(@1);
769 $$ = VALA_EXPRESSION (vala_invocation_expression_new ($1, src));
770 g_object_unref ($1);
771 g_object_unref (src);
773 if ($3 != NULL) {
774 GList *l;
775 for (l = $3; l != NULL; l = l->next) {
776 vala_invocation_expression_add_argument (VALA_INVOCATION_EXPRESSION ($$), l->data);
777 g_object_unref (l->data);
779 g_list_free ($3);
784 element_access
785 : primary_no_array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
787 GList *l;
788 ValaSourceReference *src = src(@1);
789 $$ = VALA_EXPRESSION (vala_element_access_new ($1, src));
790 for (l = $3; l != NULL; l = l->next) {
791 vala_element_access_append_index (VALA_ELEMENT_ACCESS ($$), VALA_EXPRESSION (l->data));
792 g_object_unref (l->data);
794 g_list_free ($3);
795 g_object_unref ($1);
796 g_object_unref (src);
800 expression_list
801 : expression
803 $$ = g_list_append (NULL, $1);
805 | expression_list COMMA expression
807 $$ = g_list_append ($1, $3);
811 this_access
812 : THIS
814 ValaSourceReference *src = src(@1);
815 $$ = VALA_EXPRESSION (vala_member_access_new (NULL, "this", src));
816 g_object_unref (src);
820 base_access
821 : BASE
823 ValaSourceReference *src = src(@1);
824 $$ = VALA_EXPRESSION (vala_base_access_new (src));
825 g_object_unref (src);
829 post_increment_expression
830 : primary_expression OP_INC
832 ValaSourceReference *src = src(@1);
833 $$ = VALA_EXPRESSION (vala_postfix_expression_new ($1, TRUE, src));
834 g_object_unref (src);
835 g_object_unref ($1);
839 post_decrement_expression
840 : primary_expression OP_DEC
842 ValaSourceReference *src = src(@1);
843 $$ = VALA_EXPRESSION (vala_postfix_expression_new ($1, FALSE, src));
844 g_object_unref (src);
845 g_object_unref ($1);
849 object_creation_expression
850 : NEW member_name open_parens opt_argument_list CLOSE_PARENS
852 ValaSourceReference *src = src(@2);
853 ValaObjectCreationExpression *expr = vala_object_creation_expression_new (VALA_MEMBER_ACCESS ($2), src);
854 g_object_unref ($2);
855 g_object_unref (src);
857 if ($4 != NULL) {
858 GList *l;
859 for (l = $4; l != NULL; l = l->next) {
860 vala_object_creation_expression_add_argument (expr, l->data);
861 g_object_unref (l->data);
863 g_list_free ($4);
866 $$ = VALA_EXPRESSION (expr);
870 sizeof_expression
871 : SIZEOF open_parens type_name CLOSE_PARENS
873 ValaSourceReference *src = src(@1);
874 $$ = VALA_EXPRESSION (vala_sizeof_expression_new ($3, src));
875 g_object_unref ($3);
876 g_object_unref (src);
879 typeof_expression
880 : TYPEOF open_parens type_name CLOSE_PARENS
882 ValaSourceReference *src = src(@1);
883 $$ = VALA_EXPRESSION (vala_typeof_expression_new ($3, src));
884 g_object_unref ($3);
885 g_object_unref (src);
888 unary_expression
889 : primary_expression
890 | PLUS unary_expression
892 ValaSourceReference *src = src(@1);
893 $$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_PLUS, $2, src));
894 g_object_unref (src);
895 g_object_unref ($2);
897 | MINUS unary_expression
899 ValaSourceReference *src = src(@1);
900 $$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_MINUS, $2, src));
901 g_object_unref (src);
902 g_object_unref ($2);
904 | OP_NEG unary_expression
906 ValaSourceReference *src = src(@1);
907 $$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_LOGICAL_NEGATION, $2, src));
908 g_object_unref (src);
909 g_object_unref ($2);
911 | TILDE unary_expression
913 ValaSourceReference *src = src(@1);
914 $$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_BITWISE_COMPLEMENT, $2, src));
915 g_object_unref (src);
916 g_object_unref ($2);
918 | pre_increment_expression
919 | pre_decrement_expression
920 | REF unary_expression
922 ValaSourceReference *src = src(@1);
923 $$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_REF, $2, src));
924 g_object_unref (src);
925 g_object_unref ($2);
927 | OUT unary_expression
929 ValaSourceReference *src = src(@1);
930 $$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_OUT, $2, src));
931 g_object_unref (src);
932 g_object_unref ($2);
934 | HASH unary_expression
936 ValaSourceReference *src = src(@1);
937 $$ = VALA_EXPRESSION (vala_reference_transfer_expression_new ($2, src));
938 g_object_unref (src);
939 g_object_unref ($2);
941 | cast_expression
942 | pointer_indirection_expression
943 | addressof_expression
946 pre_increment_expression
947 : OP_INC unary_expression
949 ValaSourceReference *src = src(@1);
950 $$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_INCREMENT, $2, src));
951 g_object_unref ($2);
952 g_object_unref (src);
956 pre_decrement_expression
957 : OP_DEC unary_expression
959 ValaSourceReference *src = src(@1);
960 $$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_DECREMENT, $2, src));
961 g_object_unref ($2);
962 g_object_unref (src);
966 cast_expression
967 : OPEN_CAST_PARENS type CLOSE_PARENS unary_expression
969 ValaSourceReference *src = src(@1);
970 $$ = VALA_EXPRESSION (vala_cast_expression_new ($4, $2, src));
971 g_object_unref (src);
972 g_object_unref ($2);
973 g_object_unref ($4);
977 pointer_indirection_expression
978 : STAR unary_expression
980 ValaSourceReference *src = src(@1);
981 $$ = VALA_EXPRESSION (vala_pointer_indirection_new ($2, src));
982 g_object_unref (src);
983 g_object_unref ($2);
987 addressof_expression
988 : BITWISE_AND unary_expression
990 ValaSourceReference *src = src(@1);
991 $$ = VALA_EXPRESSION (vala_addressof_expression_new ($2, src));
992 g_object_unref (src);
993 g_object_unref ($2);
997 multiplicative_expression
998 : unary_expression
999 | multiplicative_expression STAR unary_expression
1001 ValaSourceReference *src = src(@2);
1002 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_MUL, $1, $3, src));
1003 g_object_unref (src);
1004 g_object_unref ($1);
1005 g_object_unref ($3);
1007 | multiplicative_expression DIV unary_expression
1009 ValaSourceReference *src = src(@2);
1010 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_DIV, $1, $3, src));
1011 g_object_unref (src);
1012 g_object_unref ($1);
1013 g_object_unref ($3);
1015 | multiplicative_expression PERCENT unary_expression
1017 ValaSourceReference *src = src(@2);
1018 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_MOD, $1, $3, src));
1019 g_object_unref (src);
1020 g_object_unref ($1);
1021 g_object_unref ($3);
1025 additive_expression
1026 : multiplicative_expression
1027 | additive_expression PLUS multiplicative_expression
1029 ValaSourceReference *src = src(@2);
1030 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_PLUS, $1, $3, src));
1031 g_object_unref (src);
1032 g_object_unref ($1);
1033 g_object_unref ($3);
1035 | additive_expression MINUS multiplicative_expression
1037 ValaSourceReference *src = src(@2);
1038 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_MINUS, $1, $3, src));
1039 g_object_unref (src);
1040 g_object_unref ($1);
1041 g_object_unref ($3);
1045 shift_expression
1046 : additive_expression
1047 | shift_expression OP_SHIFT_LEFT additive_expression
1049 ValaSourceReference *src = src(@2);
1050 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_SHIFT_LEFT, $1, $3, src));
1051 g_object_unref (src);
1052 g_object_unref ($1);
1053 g_object_unref ($3);
1055 /* don't use two OP_GT due to resolve parse conflicts
1056 * stacked generics won't be that common in vala */
1057 | shift_expression OP_SHIFT_RIGHT additive_expression
1059 ValaSourceReference *src = src(@2);
1060 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_SHIFT_RIGHT, $1, $3, src));
1061 g_object_unref (src);
1062 g_object_unref ($1);
1063 g_object_unref ($3);
1067 relational_expression
1068 : shift_expression
1069 | relational_expression OP_LT shift_expression
1071 ValaSourceReference *src = src(@2);
1072 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_LESS_THAN, $1, $3, src));
1073 g_object_unref (src);
1074 g_object_unref ($1);
1075 g_object_unref ($3);
1077 | relational_expression OP_GT shift_expression
1079 ValaSourceReference *src = src(@2);
1080 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_GREATER_THAN, $1, $3, src));
1081 g_object_unref (src);
1082 g_object_unref ($1);
1083 g_object_unref ($3);
1085 | relational_expression OP_LE shift_expression
1087 ValaSourceReference *src = src(@2);
1088 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_LESS_THAN_OR_EQUAL, $1, $3, src));
1089 g_object_unref (src);
1090 g_object_unref ($1);
1091 g_object_unref ($3);
1093 | relational_expression OP_GE shift_expression
1095 ValaSourceReference *src = src(@2);
1096 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_GREATER_THAN_OR_EQUAL, $1, $3, src));
1097 g_object_unref (src);
1098 g_object_unref ($1);
1099 g_object_unref ($3);
1101 | relational_expression IS type
1103 ValaSourceReference *src = src(@2);
1104 $$ = VALA_EXPRESSION (vala_type_check_new ($1, $3, src));
1105 g_object_unref (src);
1106 g_object_unref ($1);
1107 g_object_unref ($3);
1111 equality_expression
1112 : relational_expression
1113 | equality_expression OP_EQ relational_expression
1115 ValaSourceReference *src = src(@2);
1116 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_EQUALITY, $1, $3, src));
1117 g_object_unref (src);
1118 g_object_unref ($1);
1119 g_object_unref ($3);
1121 | equality_expression OP_NE relational_expression
1123 ValaSourceReference *src = src(@2);
1124 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_INEQUALITY, $1, $3, src));
1125 g_object_unref (src);
1126 g_object_unref ($1);
1127 g_object_unref ($3);
1131 and_expression
1132 : equality_expression
1133 | and_expression BITWISE_AND equality_expression
1135 ValaSourceReference *src = src(@2);
1136 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_BITWISE_AND, $1, $3, src));
1137 g_object_unref (src);
1138 g_object_unref ($1);
1139 g_object_unref ($3);
1143 exclusive_or_expression
1144 : and_expression
1145 | exclusive_or_expression CARRET and_expression
1147 ValaSourceReference *src = src(@2);
1148 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_BITWISE_XOR, $1, $3, src));
1149 g_object_unref (src);
1150 g_object_unref ($1);
1151 g_object_unref ($3);
1155 inclusive_or_expression
1156 : exclusive_or_expression
1157 | inclusive_or_expression BITWISE_OR exclusive_or_expression
1159 ValaSourceReference *src = src(@2);
1160 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_BITWISE_OR, $1, $3, src));
1161 g_object_unref (src);
1162 g_object_unref ($1);
1163 g_object_unref ($3);
1167 conditional_and_expression
1168 : inclusive_or_expression
1169 | conditional_and_expression OP_AND inclusive_or_expression
1171 ValaSourceReference *src = src(@2);
1172 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_AND, $1, $3, src));
1173 g_object_unref (src);
1174 g_object_unref ($1);
1175 g_object_unref ($3);
1179 conditional_or_expression
1180 : conditional_and_expression
1181 | conditional_or_expression OP_OR conditional_and_expression
1183 ValaSourceReference *src = src(@2);
1184 $$ = VALA_EXPRESSION (vala_binary_expression_new (VALA_BINARY_OPERATOR_OR, $1, $3, src));
1185 g_object_unref (src);
1186 g_object_unref ($1);
1187 g_object_unref ($3);
1191 conditional_expression
1192 : conditional_or_expression
1193 | conditional_or_expression INTERR expression COLON expression
1195 ValaSourceReference *src = src(@2);
1196 $$ = VALA_EXPRESSION (vala_conditional_expression_new ($1, $3, $5, src));
1197 g_object_unref (src);
1198 g_object_unref ($1);
1199 g_object_unref ($3);
1200 g_object_unref ($5);
1204 lambda_expression
1205 : OPEN_PARENS opt_lambda_parameter_list CLOSE_PARENS LAMBDA expression
1207 ValaSourceReference *src = src(@4);
1208 $$ = VALA_EXPRESSION (vala_lambda_expression_new ($5, src));
1209 if ($2 != NULL) {
1210 GList *l;
1211 for (l = $2; l != NULL; l = l->next) {
1212 vala_lambda_expression_add_parameter (VALA_LAMBDA_EXPRESSION ($$), l->data);
1213 g_free (l->data);
1215 g_list_free ($2);
1217 g_object_unref ($5);
1218 g_object_unref (src);
1220 | identifier LAMBDA expression
1222 ValaSourceReference *src = src(@2);
1223 $$ = VALA_EXPRESSION (vala_lambda_expression_new ($3, src));
1224 g_object_unref ($3);
1225 g_object_unref (src);
1226 vala_lambda_expression_add_parameter (VALA_LAMBDA_EXPRESSION ($$), $1);
1227 g_free ($1);
1229 | OPEN_PARENS opt_lambda_parameter_list CLOSE_PARENS LAMBDA block
1231 ValaSourceReference *src = src(@4);
1232 $$ = VALA_EXPRESSION (vala_lambda_expression_new_with_statement_body (VALA_BLOCK ($5), src));
1233 if ($2 != NULL) {
1234 GList *l;
1235 for (l = $2; l != NULL; l = l->next) {
1236 vala_lambda_expression_add_parameter (VALA_LAMBDA_EXPRESSION ($$), l->data);
1237 g_free (l->data);
1239 g_list_free ($2);
1241 g_object_unref ($5);
1242 g_object_unref (src);
1244 | identifier LAMBDA block
1246 ValaSourceReference *src = src(@2);
1247 $$ = VALA_EXPRESSION (vala_lambda_expression_new_with_statement_body (VALA_BLOCK ($3), src));
1248 g_object_unref ($3);
1249 g_object_unref (src);
1250 vala_lambda_expression_add_parameter (VALA_LAMBDA_EXPRESSION ($$), $1);
1251 g_free ($1);
1255 opt_lambda_parameter_list
1256 : /* empty */
1258 $$ = NULL;
1260 | lambda_parameter_list
1263 lambda_parameter_list
1264 : identifier COMMA identifier
1266 $$ = g_list_append (NULL, $1);
1267 $$ = g_list_append ($$, $3);
1269 | lambda_parameter_list COMMA identifier
1271 $$ = g_list_append ($1, $3);
1275 assignment
1276 : unary_expression assignment_operator expression
1278 ValaSourceReference *src = src(@2);
1279 $$ = VALA_EXPRESSION (vala_assignment_new ($1, $3, $2, src));
1280 g_object_unref (src);
1281 g_object_unref ($1);
1282 g_object_unref ($3);
1286 assignment_operator
1287 : ASSIGN
1289 $$ = VALA_ASSIGNMENT_OPERATOR_SIMPLE;
1291 | ASSIGN_BITWISE_OR
1293 $$ = VALA_ASSIGNMENT_OPERATOR_BITWISE_OR;
1295 | ASSIGN_BITWISE_AND
1297 $$ = VALA_ASSIGNMENT_OPERATOR_BITWISE_AND;
1299 | ASSIGN_BITWISE_XOR
1301 $$ = VALA_ASSIGNMENT_OPERATOR_BITWISE_XOR;
1303 | ASSIGN_ADD
1305 $$ = VALA_ASSIGNMENT_OPERATOR_ADD;
1307 | ASSIGN_SUB
1309 $$ = VALA_ASSIGNMENT_OPERATOR_SUB;
1311 | ASSIGN_MUL
1313 $$ = VALA_ASSIGNMENT_OPERATOR_MUL;
1315 | ASSIGN_DIV
1317 $$ = VALA_ASSIGNMENT_OPERATOR_DIV;
1319 | ASSIGN_PERCENT
1321 $$ = VALA_ASSIGNMENT_OPERATOR_PERCENT;
1323 | ASSIGN_SHIFT_LEFT
1325 $$ = VALA_ASSIGNMENT_OPERATOR_SHIFT_LEFT;
1327 | ASSIGN_SHIFT_RIGHT
1329 $$ = VALA_ASSIGNMENT_OPERATOR_SHIFT_RIGHT;
1333 opt_expression
1334 : /* empty */
1336 $$ = NULL;
1338 | expression
1341 expression
1342 : conditional_expression
1343 | lambda_expression
1344 | assignment
1345 | error
1347 $$ = NULL;
1351 statement
1352 : declaration_statement
1353 | block
1354 | empty_statement
1355 | expression_statement
1356 | selection_statement
1357 | iteration_statement
1358 | jump_statement
1359 | try_statement
1360 | lock_statement
1363 embedded_statement
1364 : block
1365 | empty_statement
1367 ValaSourceReference *src = src(@1);
1368 $$ = VALA_STATEMENT (vala_block_new (src));
1369 vala_block_add_statement (VALA_BLOCK ($$), $1);
1370 g_object_unref ($1);
1371 g_object_unref (src);
1373 | expression_statement
1375 ValaSourceReference *src = src(@1);
1376 $$ = VALA_STATEMENT (vala_block_new (src));
1377 vala_block_add_statement (VALA_BLOCK ($$), $1);
1378 g_object_unref ($1);
1379 g_object_unref (src);
1381 | selection_statement
1383 ValaSourceReference *src = src(@1);
1384 $$ = VALA_STATEMENT (vala_block_new (src));
1385 vala_block_add_statement (VALA_BLOCK ($$), $1);
1386 g_object_unref ($1);
1387 g_object_unref (src);
1389 | iteration_statement
1391 ValaSourceReference *src = src(@1);
1392 $$ = VALA_STATEMENT (vala_block_new (src));
1393 vala_block_add_statement (VALA_BLOCK ($$), $1);
1394 g_object_unref ($1);
1395 g_object_unref (src);
1397 | jump_statement
1399 ValaSourceReference *src = src(@1);
1400 $$ = VALA_STATEMENT (vala_block_new (src));
1401 vala_block_add_statement (VALA_BLOCK ($$), $1);
1402 g_object_unref ($1);
1403 g_object_unref (src);
1405 | try_statement
1407 ValaSourceReference *src = src(@1);
1408 $$ = VALA_STATEMENT (vala_block_new (src));
1409 vala_block_add_statement (VALA_BLOCK ($$), $1);
1410 g_object_unref ($1);
1411 g_object_unref (src);
1413 | lock_statement
1415 ValaSourceReference *src = src(@1);
1416 $$ = VALA_STATEMENT (vala_block_new (src));
1417 vala_block_add_statement (VALA_BLOCK ($$), $1);
1418 g_object_unref ($1);
1419 g_object_unref (src);
1423 block
1424 : OPEN_BRACE opt_statement_list CLOSE_BRACE
1426 ValaSourceReference *src = src(@1);
1427 $$ = VALA_STATEMENT (vala_block_new (src));
1428 if ($2 != NULL) {
1429 GList *l;
1430 for (l = $2; l != NULL; l = l->next) {
1431 vala_block_add_statement (VALA_BLOCK ($$), l->data);
1432 g_object_unref (l->data);
1434 g_list_free ($2);
1436 g_object_unref (src);
1440 opt_statement_list
1441 : /* empty */
1443 $$ = NULL;
1445 | statement_list
1448 statement_list
1449 : statement
1451 $$ = g_list_append (NULL, $1);
1453 | statement_list statement
1455 $$ = g_list_append ($1, $2);
1459 empty_statement
1460 : SEMICOLON
1462 ValaSourceReference *src = src(@1);
1463 $$ = VALA_STATEMENT (vala_empty_statement_new (src));
1464 g_object_unref (src);
1468 declaration_statement
1469 : comment local_variable_declaration SEMICOLON
1471 ValaSourceReference *src = src_com(@2, $1);
1472 $$ = VALA_STATEMENT (vala_declaration_statement_new ($2, src));
1473 g_object_unref (src);
1474 g_object_unref ($2);
1478 local_variable_declaration
1479 : local_variable_type variable_declarators
1481 GList *l;
1482 ValaSourceReference *src = src(@2);
1483 $$ = vala_local_variable_declaration_new ($1, src);
1484 g_object_unref (src);
1485 for (l = $2; l != NULL; l = l->next) {
1486 ValaVariableDeclarator *decl = l->data;
1487 ValaTypeReference *type = vala_type_reference_copy ($1);
1488 vala_variable_declarator_set_type_reference (decl, type);
1489 g_object_unref (type);
1490 vala_local_variable_declaration_add_declarator ($$, decl);
1491 g_object_unref (decl);
1493 g_list_free ($2);
1494 g_object_unref ($1);
1496 | VAR variable_declarators
1498 GList *l;
1499 ValaSourceReference *src = src(@2);
1500 $$ = vala_local_variable_declaration_new_var_type (src);
1501 g_object_unref (src);
1502 for (l = $2; l != NULL; l = l->next) {
1503 vala_local_variable_declaration_add_declarator ($$, l->data);
1504 g_object_unref (l->data);
1506 g_list_free ($2);
1510 /* don't use type to prevent reduce/reduce conflict */
1511 local_variable_type
1512 : primary_expression opt_bracket_pair opt_op_neg
1514 ValaSourceReference *src = src(@1);
1515 $$ = vala_type_reference_new_from_expression ($1);
1516 g_object_unref ($1);
1517 g_object_unref (src);
1518 vala_type_reference_set_takes_ownership ($$, TRUE);
1519 vala_type_reference_set_array_rank ($$, $2);
1520 if ($3) {
1521 vala_type_reference_set_non_null ($$, TRUE);
1524 | primary_expression stars
1526 ValaSourceReference *src = src(@1);
1527 $$ = vala_type_reference_new_from_expression ($1);
1528 g_object_unref ($1);
1529 g_object_unref (src);
1530 vala_type_reference_set_pointer_level ($$, $2);
1532 | REF primary_expression opt_bracket_pair opt_op_neg
1534 ValaSourceReference *src = src(@2);
1535 $$ = vala_type_reference_new_from_expression ($2);
1536 g_object_unref ($2);
1537 g_object_unref (src);
1538 vala_type_reference_set_takes_ownership ($$, TRUE);
1539 vala_type_reference_set_array_rank ($$, $3);
1540 if ($4) {
1541 vala_type_reference_set_non_null ($$, TRUE);
1544 | WEAK primary_expression opt_bracket_pair opt_op_neg
1546 ValaSourceReference *src = src(@2);
1547 $$ = vala_type_reference_new_from_expression ($2);
1548 g_object_unref ($2);
1549 g_object_unref (src);
1550 vala_type_reference_set_array_rank ($$, $3);
1551 if ($4) {
1552 vala_type_reference_set_non_null ($$, TRUE);
1557 opt_op_neg
1558 : /* empty */
1560 $$ = FALSE;
1562 | OP_NEG
1564 $$ = TRUE;
1568 expression_statement
1569 : comment statement_expression SEMICOLON
1571 ValaSourceReference *src = src_com(@2, $1);
1572 $$ = VALA_STATEMENT (vala_expression_statement_new ($2, src));
1573 g_object_unref (src);
1574 g_object_unref ($2);
1578 statement_expression
1579 : invocation_expression
1580 | object_creation_expression
1581 | assignment
1582 | post_increment_expression
1583 | post_decrement_expression
1584 | pre_increment_expression
1585 | pre_decrement_expression
1588 selection_statement
1589 : if_statement
1590 | switch_statement
1593 if_statement
1594 : comment IF open_parens expression CLOSE_PARENS embedded_statement
1596 ValaBlock *true_block;
1597 ValaSourceReference *src;
1599 if (VALA_IS_BLOCK ($6)) {
1600 true_block = VALA_BLOCK ($6);
1601 } else {
1602 true_block = vala_block_new (vala_code_node_get_source_reference (VALA_CODE_NODE ($6)));
1603 vala_block_add_statement (true_block, $6);
1604 g_object_unref ($6);
1607 src = src_com(@4, $1);
1608 $$ = VALA_STATEMENT (vala_if_statement_new ($4, true_block, NULL, src));
1609 g_object_unref (src);
1610 g_object_unref ($4);
1611 g_object_unref (true_block);
1613 | comment IF open_parens expression CLOSE_PARENS embedded_statement ELSE embedded_statement
1615 ValaBlock *true_block;
1616 ValaBlock *false_block;
1617 ValaSourceReference *src;
1619 if (VALA_IS_BLOCK ($6)) {
1620 true_block = VALA_BLOCK ($6);
1621 } else {
1622 true_block = vala_block_new (vala_code_node_get_source_reference (VALA_CODE_NODE ($6)));
1623 vala_block_add_statement (true_block, $6);
1624 g_object_unref ($6);
1627 if (VALA_IS_BLOCK ($8)) {
1628 false_block = VALA_BLOCK ($8);
1629 } else {
1630 false_block = vala_block_new (vala_code_node_get_source_reference (VALA_CODE_NODE ($8)));
1631 vala_block_add_statement (false_block, $8);
1632 g_object_unref ($8);
1635 src = src_com(@4, $1);
1636 $$ = VALA_STATEMENT (vala_if_statement_new ($4, true_block, false_block, src));
1637 g_object_unref (src);
1638 g_object_unref ($4);
1639 g_object_unref (true_block);
1640 g_object_unref (false_block);
1644 switch_statement
1645 : comment SWITCH open_parens expression CLOSE_PARENS switch_block
1647 ValaSourceReference *src = src_com(@4, $1);
1648 $$ = VALA_STATEMENT (vala_switch_statement_new ($4, src));
1649 g_object_unref ($4);
1650 g_object_unref (src);
1652 if ($6 != NULL) {
1653 GList *l;
1654 for (l = $6; l != NULL; l = l->next) {
1655 vala_switch_statement_add_section (VALA_SWITCH_STATEMENT ($$), l->data);
1656 g_object_unref (l->data);
1658 g_list_free ($6);
1663 switch_block
1664 : OPEN_BRACE opt_switch_sections CLOSE_BRACE
1666 $$ = $2;
1670 opt_switch_sections
1671 : /* empty */
1673 $$ = NULL;
1675 | switch_sections
1678 switch_sections
1679 : switch_section
1681 $$ = g_list_append (NULL, $1);
1683 | switch_sections switch_section
1685 $$ = g_list_append ($1, $2);
1689 switch_section
1690 : comment switch_labels statement_list
1692 GList *l;
1693 ValaSourceReference *src = src_com(@2, $1);
1694 $$ = vala_switch_section_new (src);
1695 g_object_unref (src);
1697 for (l = $2; l != NULL; l = l->next) {
1698 vala_switch_section_add_label ($$, l->data);
1699 g_object_unref (l->data);
1701 g_list_free ($2);
1702 for (l = $3; l != NULL; l = l->next) {
1703 vala_switch_section_add_statement ($$, l->data);
1704 g_object_unref (l->data);
1706 g_list_free ($3);
1710 switch_labels
1711 : switch_label
1713 $$ = g_list_append (NULL, $1);
1715 | switch_labels switch_label
1717 $$ = g_list_append ($1, $2);
1721 switch_label
1722 : CASE expression COLON
1724 ValaSourceReference *src = src(@2);
1725 $$ = vala_switch_label_new ($2, src);
1726 g_object_unref ($2);
1727 g_object_unref (src);
1729 | DEFAULT COLON
1731 ValaSourceReference *src = src(@1);
1732 $$ = vala_switch_label_new_with_default (src);
1733 g_object_unref (src);
1737 iteration_statement
1738 : while_statement
1739 | do_statement
1740 | for_statement
1741 | foreach_statement
1744 while_statement
1745 : WHILE open_parens expression CLOSE_PARENS embedded_statement
1747 ValaSourceReference *src = src(@1);
1748 $$ = VALA_STATEMENT (vala_while_statement_new ($3, $5, src));
1749 g_object_unref (src);
1750 g_object_unref ($3);
1751 g_object_unref ($5);
1755 do_statement
1756 : DO embedded_statement WHILE open_parens expression CLOSE_PARENS SEMICOLON
1758 ValaSourceReference *src = src(@1);
1759 $$ = VALA_STATEMENT (vala_do_statement_new ($2, $5, src));
1760 g_object_unref ($2);
1761 g_object_unref ($5);
1762 g_object_unref (src);
1766 for_statement
1767 : FOR OPEN_PARENS opt_statement_expression_list SEMICOLON opt_expression SEMICOLON opt_statement_expression_list CLOSE_PARENS embedded_statement
1769 GList *l;
1770 ValaSourceReference *src = src(@1);
1771 $$ = VALA_STATEMENT (vala_for_statement_new ($5, $9, src));
1772 if ($5 != NULL) {
1773 g_object_unref ($5);
1775 g_object_unref ($9);
1776 g_object_unref (src);
1778 if ($3 != NULL) {
1779 for (l = $3; l != NULL; l = l->next) {
1780 vala_for_statement_add_initializer (VALA_FOR_STATEMENT ($$), l->data);
1781 g_object_unref (l->data);
1783 g_list_free ($3);
1785 if ($7 != NULL) {
1786 for (l = $7; l != NULL; l = l->next) {
1787 vala_for_statement_add_iterator (VALA_FOR_STATEMENT ($$), l->data);
1788 g_object_unref (l->data);
1790 g_list_free ($7);
1793 | FOR OPEN_PARENS local_variable_declaration SEMICOLON opt_expression SEMICOLON opt_statement_expression_list CLOSE_PARENS embedded_statement
1795 GList *l;
1796 GList *decls;
1798 ValaDeclarationStatement *decl_statement;
1800 ValaSourceReference *src = src(@1);
1802 ValaBlock *block = vala_block_new (src);
1804 ValaForStatement *for_statement = vala_for_statement_new ($5, $9, src);
1805 if ($5 != NULL) {
1806 g_object_unref ($5);
1808 g_object_unref ($9);
1811 decls = vala_local_variable_declaration_get_variable_declarators ($3);
1812 for (l = decls; l != NULL; l = l->next) {
1813 ValaVariableDeclarator *decl = l->data;
1814 ValaExpression *init = vala_variable_declarator_get_initializer (decl);
1816 if (init != NULL) {
1817 ValaSourceReference *decl_src = vala_code_node_get_source_reference (VALA_CODE_NODE (decl));
1818 ValaMemberAccess *lhs = vala_member_access_new (NULL, vala_variable_declarator_get_name (decl), decl_src);
1819 ValaAssignment *assign = vala_assignment_new (VALA_EXPRESSION (lhs), init, VALA_ASSIGNMENT_OPERATOR_SIMPLE, decl_src);
1820 g_object_unref (lhs);
1821 vala_for_statement_add_initializer (for_statement, VALA_EXPRESSION (assign));
1822 g_object_unref (assign);
1824 vala_variable_declarator_set_initializer (decl, NULL);
1827 g_list_free (decls);
1829 decl_statement = vala_declaration_statement_new ($3, src);
1830 g_object_unref ($3);
1831 g_object_unref (src);
1832 vala_block_add_statement (block, VALA_STATEMENT (decl_statement));
1833 g_object_unref (decl_statement);
1835 if ($7 != NULL) {
1836 for (l = $7; l != NULL; l = l->next) {
1837 vala_for_statement_add_iterator (for_statement, l->data);
1838 g_object_unref (l->data);
1840 g_list_free ($7);
1843 vala_block_add_statement (block, VALA_STATEMENT (for_statement));
1845 $$ = VALA_STATEMENT (block);
1849 opt_statement_expression_list
1850 : /* empty */
1852 $$ = NULL;
1854 | statement_expression_list
1857 statement_expression_list
1858 : statement_expression
1860 $$ = g_list_append (NULL, $1);
1862 | statement_expression_list COMMA statement_expression
1864 $$ = g_list_append ($1, $3);
1868 foreach_statement
1869 : FOREACH OPEN_PARENS type identifier IN expression CLOSE_PARENS embedded_statement
1871 ValaSourceReference *src = src(@3);
1872 $$ = VALA_STATEMENT (vala_foreach_statement_new ($3, $4, $6, $8, src));
1873 g_object_unref ($3);
1874 g_free ($4);
1875 g_object_unref ($6);
1876 g_object_unref ($8);
1877 g_object_unref (src);
1881 jump_statement
1882 : break_statement
1883 | continue_statement
1884 | return_statement
1885 | throw_statement
1888 break_statement
1889 : BREAK SEMICOLON
1891 ValaSourceReference *src = src(@1);
1892 $$ = VALA_STATEMENT (vala_break_statement_new (src));
1893 g_object_unref (src);
1897 continue_statement
1898 : CONTINUE SEMICOLON
1900 ValaSourceReference *src = src(@1);
1901 $$ = VALA_STATEMENT (vala_continue_statement_new (src));
1902 g_object_unref (src);
1906 return_statement
1907 : RETURN opt_expression SEMICOLON
1909 ValaSourceReference *src = src(@1);
1910 $$ = VALA_STATEMENT (vala_return_statement_new ($2, src));
1911 g_object_unref (src);
1912 if ($2 != NULL) {
1913 g_object_unref ($2);
1918 throw_statement
1919 : THROW expression SEMICOLON
1921 ValaSourceReference *src = src(@1);
1922 $$ = VALA_STATEMENT (vala_throw_statement_new ($2, src));
1923 g_object_unref (src);
1924 if ($2 != NULL) {
1925 g_object_unref ($2);
1930 try_statement
1931 : TRY block catch_clauses opt_finally_clause
1933 GList *l;
1934 ValaSourceReference *src = src(@1);
1935 $$ = VALA_STATEMENT (vala_try_statement_new (VALA_BLOCK ($2), VALA_BLOCK ($4), src));
1936 g_object_unref ($2);
1937 if ($4 != NULL) {
1938 g_object_unref ($4);
1940 g_object_unref (src);
1942 for (l = $3; l != NULL; l = l->next) {
1943 vala_try_statement_add_catch_clause (VALA_TRY_STATEMENT ($$), l->data);
1944 g_object_unref (l->data);
1946 g_list_free ($3);
1948 | TRY block finally_clause
1950 ValaSourceReference *src = src(@1);
1951 $$ = VALA_STATEMENT (vala_try_statement_new (VALA_BLOCK ($2), VALA_BLOCK ($3), src));
1952 g_object_unref ($2);
1953 g_object_unref ($3);
1954 g_object_unref (src);
1958 catch_clauses
1959 : specific_catch_clauses opt_general_catch_clause
1961 if ($2 != NULL) {
1962 $$ = g_list_append ($1, $2);
1963 } else {
1964 $$ = $1;
1967 | general_catch_clause
1969 $$ = g_list_append (NULL, $1);
1973 specific_catch_clauses
1974 : specific_catch_clause
1976 $$ = g_list_append (NULL, $1);
1978 | specific_catch_clauses specific_catch_clause
1980 $$ = g_list_append ($1, $2);
1984 specific_catch_clause
1985 : CATCH OPEN_PARENS type identifier CLOSE_PARENS block
1987 ValaSourceReference *src = src(@1);
1988 $$ = vala_catch_clause_new ($3, $4, VALA_BLOCK ($6), src);
1989 g_object_unref ($3);
1990 g_free ($4);
1991 g_object_unref ($6);
1992 g_object_unref (src);
1996 opt_general_catch_clause
1997 : /* empty */
1999 $$ = NULL;
2001 | general_catch_clause
2004 general_catch_clause
2005 : CATCH block
2007 ValaSourceReference *src = src(@1);
2008 $$ = vala_catch_clause_new (NULL, NULL, VALA_BLOCK ($2), src);
2009 g_object_unref ($2);
2010 g_object_unref (src);
2013 opt_finally_clause
2014 : /* empty */
2016 $$ = NULL;
2018 | finally_clause
2022 finally_clause
2023 : FINALLY block
2025 $$ = $2;
2029 lock_statement
2030 : comment LOCK OPEN_PARENS expression CLOSE_PARENS embedded_statement
2032 ValaSourceReference *src = src_com(@4, $1);
2033 $$ = VALA_STATEMENT (vala_lock_statement_new ($4, $6, src));
2034 g_object_unref (src);
2035 g_object_unref ($4);
2036 g_object_unref ($6);
2039 namespace_declaration
2040 : comment opt_attributes NAMESPACE identifier
2042 ValaSourceReference *src = src_com(@4, $1);
2043 current_namespace = vala_namespace_new ($4, src);
2044 g_object_unref (src);
2045 VALA_CODE_NODE(current_namespace)->attributes = $2;
2046 g_free ($4);
2048 namespace_body
2050 $$ = current_namespace;
2051 current_namespace = vala_source_file_get_global_namespace (current_source_file);
2055 namespace_body
2056 : OPEN_BRACE opt_namespace_member_declarations CLOSE_BRACE
2057 | OPEN_BRACE error CLOSE_BRACE
2060 opt_name_specifier
2061 : /* empty */
2063 $$ = NULL;
2065 | name_specifier
2068 name_specifier
2069 : DOT identifier
2071 $$ = $2;
2075 opt_using_directives
2076 : /* empty */
2077 | using_directives
2080 using_directives
2081 : using_directive
2082 | using_directives using_directive
2085 using_directive
2086 : USING identifier SEMICOLON
2088 ValaSourceReference *src = src(@2);
2089 ValaNamespaceReference *ns_ref = vala_namespace_reference_new ($2, src);
2090 g_object_unref (src);
2091 g_free ($2);
2092 vala_source_file_add_using_directive (current_source_file, ns_ref);
2093 g_object_unref (ns_ref);
2097 opt_outer_declarations
2098 : /* empty */
2099 | outer_declarations
2102 outer_declarations
2103 : outer_declaration
2104 | outer_declarations outer_declaration
2107 outer_declaration
2108 : namespace_declaration
2110 vala_source_file_add_namespace (current_source_file, $1);
2111 g_object_unref ($1);
2113 | namespace_member_declaration
2116 opt_namespace_member_declarations
2117 : /* empty */
2118 | namespace_member_declarations
2121 namespace_member_declarations
2122 : namespace_member_declaration
2123 | namespace_member_declarations namespace_member_declaration
2126 namespace_member_declaration
2127 : class_declaration
2129 /* skip declarations with errors */
2130 if ($1 != NULL) {
2131 vala_namespace_add_class (current_namespace, $1);
2132 g_object_unref ($1);
2135 if (current_namespace_implicit) {
2136 /* current namespace has been declared implicitly */
2137 current_namespace = vala_source_file_get_global_namespace (current_source_file);
2138 current_namespace_implicit = FALSE;
2141 | struct_declaration
2143 /* skip declarations with errors */
2144 if ($1 != NULL) {
2145 vala_namespace_add_struct (current_namespace, $1);
2146 g_object_unref ($1);
2149 if (current_namespace_implicit) {
2150 /* current namespace has been declared implicitly */
2151 current_namespace = vala_source_file_get_global_namespace (current_source_file);
2152 current_namespace_implicit = FALSE;
2155 | interface_declaration
2157 /* skip declarations with errors */
2158 if ($1 != NULL) {
2159 vala_namespace_add_interface (current_namespace, $1);
2160 g_object_unref ($1);
2163 if (current_namespace_implicit) {
2164 /* current namespace has been declared implicitly */
2165 current_namespace = vala_source_file_get_global_namespace (current_source_file);
2166 current_namespace_implicit = FALSE;
2169 | enum_declaration
2171 /* skip declarations with errors */
2172 if ($1 != NULL) {
2173 vala_namespace_add_enum (current_namespace, $1);
2174 g_object_unref ($1);
2177 if (current_namespace_implicit) {
2178 /* current namespace has been declared implicitly */
2179 current_namespace = vala_source_file_get_global_namespace (current_source_file);
2180 current_namespace_implicit = FALSE;
2183 | flags_declaration
2185 /* skip declarations with errors */
2186 if ($1 != NULL) {
2187 vala_namespace_add_flags (current_namespace, $1);
2188 g_object_unref ($1);
2191 if (current_namespace_implicit) {
2192 /* current namespace has been declared implicitly */
2193 current_namespace = vala_source_file_get_global_namespace (current_source_file);
2194 current_namespace_implicit = FALSE;
2197 | callback_declaration
2199 /* skip declarations with errors */
2200 if ($1 != NULL) {
2201 vala_namespace_add_callback (current_namespace, $1);
2202 g_object_unref ($1);
2205 if (current_namespace_implicit) {
2206 /* current namespace has been declared implicitly */
2207 current_namespace = vala_source_file_get_global_namespace (current_source_file);
2208 current_namespace_implicit = FALSE;
2211 | constant_declaration
2213 /* skip declarations with errors */
2214 if ($1 != NULL) {
2215 vala_namespace_add_constant (current_namespace, $1);
2216 g_object_unref ($1);
2219 | field_declaration
2221 /* skip declarations with errors */
2222 if ($1 != NULL) {
2223 /* field must be static, don't require developer
2224 * to explicitly state it */
2225 vala_field_set_instance ($1, FALSE);
2227 vala_namespace_add_field (current_namespace, $1);
2228 g_object_unref ($1);
2231 | method_declaration
2233 /* skip declarations with errors */
2234 if ($1 != NULL) {
2235 /* method must be static, don't require developer
2236 * to explicitly state it */
2237 vala_method_set_instance ($1, FALSE);
2239 vala_namespace_add_method (current_namespace, $1);
2240 g_object_unref ($1);
2245 class_declaration
2246 : comment opt_attributes opt_access_modifier opt_modifiers CLASS identifier opt_name_specifier opt_type_parameter_list opt_class_base
2248 GList *l;
2249 ValaSourceReference *src;
2251 char *name = $6;
2253 if ($7 != NULL) {
2254 ValaSourceReference *ns_src = src(@6);
2255 current_namespace = vala_namespace_new ($6, ns_src);
2256 g_free ($6);
2257 g_object_unref (ns_src);
2258 current_namespace_implicit = TRUE;
2260 vala_source_file_add_namespace (current_source_file, current_namespace);
2261 g_object_unref (current_namespace);
2263 name = $7;
2266 src = src_com(@6, $1);
2267 current_class = vala_class_new (name, src);
2268 g_free (name);
2269 g_object_unref (src);
2271 VALA_CODE_NODE(current_class)->attributes = $2;
2272 if ($3 != 0) {
2273 VALA_DATA_TYPE(current_class)->access = $3;
2275 if (($4 & VALA_MODIFIER_ABSTRACT) == VALA_MODIFIER_ABSTRACT) {
2276 vala_class_set_is_abstract (current_class, TRUE);
2278 if (($4 & VALA_MODIFIER_STATIC) == VALA_MODIFIER_STATIC) {
2279 vala_class_set_is_static (current_class, TRUE);
2281 if ($8 != NULL) {
2282 for (l = $8; l != NULL; l = l->next) {
2283 vala_class_add_type_parameter (current_class, l->data);
2284 g_object_unref (l->data);
2286 g_list_free ($8);
2288 if ($9 != NULL) {
2289 for (l = $9; l != NULL; l = l->next) {
2290 vala_class_add_base_type (current_class, l->data);
2291 g_object_unref (l->data);
2293 g_list_free ($9);
2296 class_body
2298 $$ = current_class;
2299 current_class = NULL;
2303 opt_access_modifier
2304 : /* empty */
2306 $$ = 0;
2308 | access_modifier
2311 access_modifier
2312 : PUBLIC
2314 $$ = VALA_MEMBER_ACCESSIBILITY_PUBLIC;
2316 | PROTECTED
2318 $$ = VALA_MEMBER_ACCESSIBILITY_PROTECTED;
2320 | PRIVATE
2322 $$ = VALA_MEMBER_ACCESSIBILITY_PRIVATE;
2326 opt_modifiers
2327 : /* empty */
2329 $$ = VALA_MODIFIER_NONE;
2331 | modifiers
2334 modifiers
2335 : modifier
2336 | modifiers modifier
2338 if (($1 & $2) == $2) {
2339 ValaSourceReference *src = src(@2);
2340 vala_report_error (src, "Modifier may only be specified once.");
2341 g_object_unref (src);
2343 $$ = $1 | $2;
2347 modifier
2348 : ABSTRACT
2350 $$ = VALA_MODIFIER_ABSTRACT;
2352 | OVERRIDE
2354 $$ = VALA_MODIFIER_OVERRIDE;
2356 | STATIC
2358 $$ = VALA_MODIFIER_STATIC;
2360 | VIRTUAL
2362 $$ = VALA_MODIFIER_VIRTUAL;
2366 opt_class_base
2367 : /* empty */
2369 $$ = NULL;
2371 | class_base
2374 class_base
2375 : COLON type_list
2377 $$ = $2;
2381 type_list
2382 : type_name
2384 $$ = g_list_append (NULL, $1);
2386 | type_list COMMA type_name
2388 $$ = g_list_append ($1, $3);
2392 class_body
2393 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
2396 opt_class_member_declarations
2397 : /* empty */
2398 | class_member_declarations
2401 class_member_declarations
2402 : class_member_declaration
2403 | class_member_declarations class_member_declaration
2406 class_member_declaration
2407 : constant_declaration
2409 /* skip declarations with errors */
2410 if ($1 != NULL) {
2411 vala_class_add_constant (current_class, $1);
2412 g_object_unref ($1);
2415 | field_declaration
2417 /* skip declarations with errors */
2418 if ($1 != NULL) {
2419 vala_class_add_field (current_class, $1);
2420 g_object_unref ($1);
2423 | method_declaration
2425 /* skip declarations with errors */
2426 if ($1 != NULL) {
2427 vala_class_add_method (current_class, $1);
2428 g_object_unref ($1);
2431 | property_declaration
2433 /* skip declarations with errors */
2434 if ($1 != NULL) {
2435 vala_class_add_property (current_class, $1, FALSE);
2436 g_object_unref ($1);
2439 | signal_declaration
2441 /* skip declarations with errors */
2442 if ($1 != NULL) {
2443 vala_class_add_signal (current_class, $1);
2444 g_object_unref ($1);
2447 | constructor_declaration
2449 /* skip declarations with errors */
2450 if ($1 != NULL) {
2451 vala_class_set_constructor (current_class, $1);
2452 g_object_unref ($1);
2455 | destructor_declaration
2457 /* skip declarations with errors */
2458 if ($1 != NULL) {
2459 vala_class_set_destructor (current_class, $1);
2460 g_object_unref ($1);
2465 constant_declaration
2466 : comment opt_attributes opt_access_modifier CONST type variable_declarator SEMICOLON
2468 ValaSourceReference *src = src_com(@5, $1);
2469 $$ = vala_constant_new (vala_variable_declarator_get_name ($6), $5, vala_variable_declarator_get_initializer ($6), src);
2470 g_object_unref (src);
2471 g_object_unref ($5);
2472 g_object_unref ($6);
2473 if ($3 != 0) {
2474 $$->access = $3;
2479 field_declaration
2480 : comment opt_attributes opt_access_modifier opt_modifiers type variable_declarator SEMICOLON
2482 ValaSourceReference *src;
2484 if (!vala_type_reference_get_is_weak ($5)) {
2485 vala_type_reference_set_takes_ownership ($5, TRUE);
2487 vala_type_reference_set_is_ref ($5, FALSE);
2489 src = src_com(@5, $1);
2490 $$ = vala_field_new (vala_variable_declarator_get_name ($6), $5, vala_variable_declarator_get_initializer ($6), src);
2491 g_object_unref (src);
2492 if ($3 != 0) {
2493 $$->access = $3;
2495 if (($4 & VALA_MODIFIER_STATIC) == VALA_MODIFIER_STATIC) {
2496 vala_field_set_instance ($$, FALSE);
2498 VALA_CODE_NODE($$)->attributes = $2;
2499 g_object_unref ($5);
2500 g_object_unref ($6);
2504 comment
2507 $$ = vala_parser_pop_comment (parser);
2511 variable_declarators
2512 : variable_declarator
2514 $$ = g_list_append (NULL, $1);
2516 | variable_declarators COMMA variable_declarator
2518 $$ = g_list_append ($1, $3);
2522 variable_declarator
2523 : identifier
2525 ValaSourceReference *src = src(@1);
2526 $$ = vala_variable_declarator_new ($1, NULL, src);
2527 g_object_unref (src);
2528 g_free ($1);
2530 | identifier ASSIGN variable_initializer
2532 ValaSourceReference *src = src(@1);
2533 $$ = vala_variable_declarator_new ($1, $3, src);
2534 g_object_unref (src);
2535 g_free ($1);
2536 g_object_unref ($3);
2540 initializer
2541 : OPEN_BRACE opt_variable_initializer_list CLOSE_BRACE
2543 ValaSourceReference *src = src(@1);
2544 $$ = VALA_EXPRESSION (vala_initializer_list_new (src));
2545 g_object_unref (src);
2547 if ($2 != NULL) {
2548 GList *l;
2549 for (l = $2; l != NULL; l = l->next) {
2550 vala_initializer_list_append (VALA_INITIALIZER_LIST ($$), l->data);
2551 g_object_unref (l->data);
2557 opt_variable_initializer_list
2558 : /* empty */
2560 $$ = NULL;
2562 | variable_initializer_list
2565 variable_initializer_list
2566 : variable_initializer
2568 $$ = g_list_append (NULL, $1);
2570 | variable_initializer_list COMMA variable_initializer
2572 $$ = g_list_append ($1, $3);
2576 variable_initializer
2577 : expression
2578 | initializer
2581 method_declaration
2582 : method_header method_body
2584 $$ = $1;
2585 vala_method_set_body ($$, VALA_BLOCK($2));
2586 if ($2 != NULL) {
2587 g_object_unref ($2);
2590 | error method_body
2592 $$ = NULL;
2596 method_header
2597 : comment opt_attributes opt_access_modifier opt_modifiers type identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS opt_throws_declaration
2599 GList *l;
2600 ValaSourceReference *src;
2601 ValaModifier vmodifiers;
2603 if (!vala_type_reference_get_is_weak ($5)) {
2604 vala_type_reference_set_transfers_ownership ($5, TRUE);
2607 src = src_com(@6, $1);
2608 $$ = vala_method_new ($6, $5, src);
2609 g_object_unref (src);
2610 if ($3 != 0) {
2611 $$->access = $3;
2613 if (($4 & VALA_MODIFIER_STATIC) == VALA_MODIFIER_STATIC) {
2614 vala_method_set_instance ($$, FALSE);
2616 vmodifiers = $4 & (VALA_MODIFIER_ABSTRACT | VALA_MODIFIER_VIRTUAL | VALA_MODIFIER_OVERRIDE);
2617 if (vmodifiers == 0) {
2618 } else if (vmodifiers == VALA_MODIFIER_ABSTRACT) {
2619 vala_method_set_is_abstract ($$, TRUE);
2620 } else if (vmodifiers == VALA_MODIFIER_VIRTUAL) {
2621 vala_method_set_is_virtual ($$, TRUE);
2622 } else if (vmodifiers == VALA_MODIFIER_OVERRIDE) {
2623 vala_method_set_overrides ($$, TRUE);
2624 } else {
2625 vala_report_error (vala_code_node_get_source_reference (VALA_CODE_NODE ($$)), "Only one of `abstract', `virtual', and `override' may be specified.");
2626 vala_code_node_set_error (VALA_CODE_NODE ($$), TRUE);
2628 VALA_CODE_NODE($$)->attributes = $2;
2630 for (l = $8; l != NULL; l = l->next) {
2631 vala_method_add_parameter ($$, l->data);
2632 g_object_unref (l->data);
2634 if ($8 != NULL) {
2635 g_list_free ($8);
2638 g_object_unref ($5);
2639 g_free ($6);
2641 | comment opt_attributes opt_access_modifier opt_modifiers identifier opt_name_specifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2643 GList *l;
2645 ValaSourceReference *src = src_com(@5, $1);
2646 $$ = VALA_METHOD (vala_creation_method_new ($6, src));
2647 g_free ($5);
2648 g_free ($6);
2649 g_object_unref (src);
2650 vala_method_set_instance ($$, FALSE);
2651 if ($3 != 0) {
2652 $$->access = $3;
2654 VALA_CODE_NODE($$)->attributes = $2;
2656 if ($8 != NULL) {
2657 for (l = $8; l != NULL; l = l->next) {
2658 vala_method_add_parameter ($$, l->data);
2659 g_object_unref (l->data);
2661 g_list_free ($8);
2666 method_body
2667 : block
2668 | SEMICOLON
2670 $$ = NULL;
2674 opt_formal_parameter_list
2675 : /* empty */
2677 $$ = NULL;
2679 | formal_parameter_list
2682 formal_parameter_list
2683 : fixed_parameters
2684 | fixed_parameters COMMA ELLIPSIS
2686 ValaSourceReference *src = src(@3);
2687 $$ = g_list_append ($1, vala_formal_parameter_new_with_ellipsis (src));
2688 g_object_unref (src);
2690 | ELLIPSIS
2692 ValaSourceReference *src = src(@1);
2693 $$ = g_list_append (NULL, vala_formal_parameter_new_with_ellipsis (src));
2694 g_object_unref (src);
2698 fixed_parameters
2699 : fixed_parameter
2701 $$ = g_list_append (NULL, $1);
2703 | fixed_parameters COMMA fixed_parameter
2705 $$ = g_list_append ($1, $3);
2709 opt_construct
2710 : /* empty */
2712 $$ = FALSE;
2714 | CONSTRUCT
2716 $$ = TRUE;
2720 fixed_parameter
2721 : opt_attributes opt_construct type identifier
2723 ValaSourceReference *src;
2725 if (vala_type_reference_get_is_ref ($3) && vala_type_reference_get_is_out ($3)) {
2726 vala_type_reference_set_takes_ownership ($3, TRUE);
2727 vala_type_reference_set_is_ref ($3, FALSE);
2730 src = src(@3);
2731 $$ = vala_formal_parameter_new ($4, $3, src);
2732 g_object_unref (src);
2733 vala_formal_parameter_set_construct_parameter ($$, $2);
2734 g_object_unref ($3);
2735 g_free ($4);
2737 | opt_attributes opt_construct type identifier ASSIGN expression
2739 ValaSourceReference *src;
2741 if (vala_type_reference_get_is_ref ($3) && vala_type_reference_get_is_out ($3)) {
2742 vala_type_reference_set_takes_ownership ($3, TRUE);
2743 vala_type_reference_set_is_ref ($3, FALSE);
2746 src = src(@3);
2747 $$ = vala_formal_parameter_new ($4, $3, src);
2748 g_object_unref (src);
2749 vala_formal_parameter_set_default_expression ($$, $6);
2750 vala_formal_parameter_set_construct_parameter ($$, $2);
2751 g_object_unref ($3);
2752 g_free ($4);
2753 g_object_unref ($6);
2757 opt_throws_declaration
2758 : /* empty */
2760 $$ = NULL;
2762 | throws_declaration
2765 throws_declaration
2766 : THROWS type_list
2768 $$ = $2;
2772 property_declaration
2773 : comment opt_attributes opt_access_modifier opt_modifiers type identifier OPEN_BRACE get_accessor_declaration opt_set_accessor_declaration CLOSE_BRACE
2775 ValaSourceReference *src;
2777 if (!vala_type_reference_get_is_weak ($5)) {
2778 vala_type_reference_set_takes_ownership ($5, TRUE);
2781 src = src_com(@5, $1);
2782 $$ = vala_property_new ($6, $5, $8, $9, src);
2783 g_object_unref (src);
2785 VALA_CODE_NODE($$)->attributes = $2;
2787 g_object_unref ($5);
2788 g_free ($6);
2789 g_object_unref ($8);
2790 if ($9 != NULL) {
2791 g_object_unref ($9);
2794 if (($4 & VALA_MODIFIER_ABSTRACT) == VALA_MODIFIER_ABSTRACT) {
2795 vala_property_set_is_abstract ($$, TRUE);
2797 if (($4 & VALA_MODIFIER_VIRTUAL) == VALA_MODIFIER_VIRTUAL) {
2798 vala_property_set_is_virtual ($$, TRUE);
2800 if (($4 & VALA_MODIFIER_OVERRIDE) == VALA_MODIFIER_OVERRIDE) {
2801 vala_property_set_overrides ($$, TRUE);
2804 | comment opt_attributes opt_access_modifier opt_modifiers type identifier OPEN_BRACE set_accessor_declaration CLOSE_BRACE
2806 ValaSourceReference *src;
2808 if (!vala_type_reference_get_is_weak ($5)) {
2809 vala_type_reference_set_takes_ownership ($5, TRUE);
2812 src = src_com(@5, $1);
2813 $$ = vala_property_new ($6, $5, NULL, $8, src);
2814 g_object_unref (src);
2816 VALA_CODE_NODE($$)->attributes = $2;
2818 g_object_unref ($5);
2819 g_free ($6);
2820 g_object_unref ($8);
2822 if (($4 & VALA_MODIFIER_ABSTRACT) == VALA_MODIFIER_ABSTRACT) {
2823 vala_property_set_is_abstract ($$, TRUE);
2825 if (($4 & VALA_MODIFIER_VIRTUAL) == VALA_MODIFIER_VIRTUAL) {
2826 vala_property_set_is_virtual ($$, TRUE);
2828 if (($4 & VALA_MODIFIER_OVERRIDE) == VALA_MODIFIER_OVERRIDE) {
2829 vala_property_set_overrides ($$, TRUE);
2834 get_accessor_declaration
2835 : opt_attributes GET method_body
2837 ValaSourceReference *src = src(@2);
2838 $$ = vala_property_accessor_new (TRUE, FALSE, FALSE, $3, src);
2839 g_object_unref (src);
2841 if ($3 != NULL) {
2842 g_object_unref ($3);
2847 opt_set_accessor_declaration
2848 : /* empty */
2850 $$ = NULL;
2852 | set_accessor_declaration
2855 set_accessor_declaration
2856 : opt_attributes SET method_body
2858 ValaSourceReference *src = src(@2);
2859 $$ = vala_property_accessor_new (FALSE, TRUE, FALSE, $3, src);
2860 g_object_unref (src);
2861 if ($3 != NULL) {
2862 g_object_unref ($3);
2865 | opt_attributes SET CONSTRUCT method_body
2867 ValaSourceReference *src = src(@2);
2868 $$ = vala_property_accessor_new (FALSE, TRUE, TRUE, $4, src);
2869 g_object_unref (src);
2870 if ($4 != NULL) {
2871 g_object_unref ($4);
2874 | opt_attributes CONSTRUCT method_body
2876 ValaSourceReference *src = src(@2);
2877 $$ = vala_property_accessor_new (FALSE, FALSE, TRUE, $3, src);
2878 g_object_unref (src);
2879 if ($3 != NULL) {
2880 g_object_unref ($3);
2885 signal_declaration
2886 : comment opt_attributes opt_access_modifier SIGNAL type identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
2888 GList *l;
2890 ValaSourceReference *src = src_com(@6, $1);
2891 $$ = vala_signal_new ($6, $5, src);
2892 g_object_unref (src);
2893 if ($3 != 0) {
2894 vala_signal_set_access ($$, $3);
2896 VALA_CODE_NODE($$)->attributes = $2;
2898 for (l = $8; l != NULL; l = l->next) {
2899 vala_signal_add_parameter ($$, l->data);
2900 g_object_unref (l->data);
2902 if ($8 != NULL) {
2903 g_list_free ($8);
2906 g_object_unref ($5);
2907 g_free ($6);
2911 constructor_declaration
2912 : comment opt_attributes CONSTRUCT block
2914 ValaSourceReference *src = src_com(@3, $1);
2915 $$ = vala_constructor_new (src);
2916 g_object_unref (src);
2917 vala_constructor_set_body ($$, $4);
2918 g_object_unref ($4);
2922 destructor_declaration
2923 : comment opt_attributes opt_access_modifier opt_modifiers TILDE identifier OPEN_PARENS CLOSE_PARENS block
2925 ValaSourceReference *src = src_com(@6, $1);
2926 $$ = vala_destructor_new (src);
2927 g_object_unref (src);
2928 vala_destructor_set_body ($$, $9);
2930 g_free ($6);
2931 g_object_unref ($9);
2935 struct_declaration
2936 : struct_header
2938 current_struct = $1;
2940 struct_body
2942 $$ = current_struct;
2943 current_struct = NULL;
2947 struct_header
2948 : comment opt_attributes opt_access_modifier STRUCT identifier opt_name_specifier opt_type_parameter_list opt_class_base
2950 GList *l;
2951 ValaSourceReference *src;
2953 char *name = $5;
2955 if ($6 != NULL) {
2956 ValaSourceReference *ns_src = src(@5);
2957 current_namespace = vala_namespace_new ($5, ns_src);
2958 g_free ($5);
2959 g_object_unref (ns_src);
2960 current_namespace_implicit = TRUE;
2962 vala_source_file_add_namespace (current_source_file, current_namespace);
2963 g_object_unref (current_namespace);
2965 name = $6;
2968 src = src_com(@5, $1);
2969 $$ = vala_struct_new (name, src);
2970 g_free (name);
2971 g_object_unref (src);
2972 for (l = $7; l != NULL; l = l->next) {
2973 vala_struct_add_type_parameter ($$, l->data);
2975 VALA_CODE_NODE($$)->attributes = $2;
2976 if ($3 != 0) {
2977 VALA_DATA_TYPE($$)->access = $3;
2979 if ($8 != NULL) {
2980 for (l = $8; l != NULL; l = l->next) {
2981 vala_struct_add_base_type ($$, l->data);
2982 g_object_unref (l->data);
2984 g_list_free ($8);
2989 struct_body
2990 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
2993 opt_struct_member_declarations
2994 : /* empty */
2995 | struct_member_declarations
2998 struct_member_declarations
2999 : struct_member_declaration
3000 | struct_member_declarations struct_member_declaration
3003 struct_member_declaration
3004 : field_declaration
3006 /* skip declarations with errors */
3007 if ($1 != NULL) {
3008 vala_struct_add_field (current_struct, $1);
3009 g_object_unref ($1);
3012 | method_declaration
3014 /* skip declarations with errors */
3015 if ($1 != NULL) {
3016 vala_struct_add_method (current_struct, $1);
3017 g_object_unref ($1);
3022 interface_declaration
3023 : comment opt_attributes opt_access_modifier opt_modifiers INTERFACE identifier opt_name_specifier opt_type_parameter_list opt_class_base
3025 ValaSourceReference *src;
3026 char *name = $6;
3028 if ($7 != NULL) {
3029 ValaSourceReference *ns_src = src(@6);
3030 current_namespace = vala_namespace_new ($6, ns_src);
3031 g_free ($6);
3032 g_object_unref (ns_src);
3033 current_namespace_implicit = TRUE;
3035 vala_source_file_add_namespace (current_source_file, current_namespace);
3036 g_object_unref (current_namespace);
3038 name = $7;
3041 src = src_com(@6, $1);
3042 current_interface = vala_interface_new (name, src);
3043 g_free (name);
3044 g_object_unref (src);
3046 VALA_CODE_NODE(current_interface)->attributes = $2;
3047 if ($3 != 0) {
3048 VALA_DATA_TYPE(current_interface)->access = $3;
3050 if (($4 & VALA_MODIFIER_STATIC) == VALA_MODIFIER_STATIC) {
3051 vala_interface_set_is_static (current_interface, TRUE);
3053 if ($8 != NULL) {
3054 GList *l;
3055 for (l = $8; l != NULL; l = l->next) {
3056 vala_interface_add_type_parameter (current_interface, l->data);
3057 g_object_unref (l->data);
3059 g_list_free ($8);
3061 if ($9 != NULL) {
3062 GList *l;
3063 for (l = $9; l != NULL; l = l->next) {
3064 vala_interface_add_prerequisite (current_interface, l->data);
3065 g_object_unref (l->data);
3067 g_list_free ($9);
3070 interface_body
3072 $$ = current_interface;
3076 interface_body
3077 : OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
3080 opt_interface_member_declarations
3081 : /* empty */
3082 | interface_member_declarations
3085 interface_member_declarations
3086 : interface_member_declaration
3087 | interface_member_declarations interface_member_declaration
3090 interface_member_declaration
3091 : method_declaration
3093 /* skip declarations with errors */
3094 if ($1 != NULL) {
3095 vala_interface_add_method (current_interface, $1);
3096 g_object_unref ($1);
3099 | property_declaration
3101 /* skip declarations with errors */
3102 if ($1 != NULL) {
3103 vala_interface_add_property (current_interface, $1);
3104 g_object_unref ($1);
3107 | signal_declaration
3109 /* skip declarations with errors */
3110 if ($1 != NULL) {
3111 vala_interface_add_signal (current_interface, $1);
3112 g_object_unref ($1);
3117 enum_declaration
3118 : comment opt_attributes opt_access_modifier ENUM identifier opt_name_specifier
3120 GList *l;
3121 ValaSourceReference *src;
3123 char *name = $5;
3125 if ($6 != NULL) {
3126 ValaSourceReference *ns_src = src(@5);
3127 current_namespace = vala_namespace_new ($5, ns_src);
3128 g_free ($5);
3129 g_object_unref (ns_src);
3130 current_namespace_implicit = TRUE;
3132 vala_source_file_add_namespace (current_source_file, current_namespace);
3133 g_object_unref (current_namespace);
3135 name = $6;
3138 src = src_com(@5, $1);
3139 current_enum = vala_enum_new (name, src);
3140 g_free (name);
3141 g_object_unref (src);
3143 VALA_CODE_NODE(current_enum)->attributes = $2;
3145 if ($3 != 0) {
3146 VALA_DATA_TYPE(current_enum)->access = $3;
3149 enum_body
3151 $$ = current_enum;
3152 current_enum = NULL;
3156 enum_body
3157 : OPEN_BRACE opt_enum_member_declarations opt_enum_method_declarations CLOSE_BRACE
3160 opt_enum_member_declarations
3161 : /* empty */
3162 | enum_member_declarations opt_comma
3165 enum_member_declarations
3166 : enum_member_declaration
3167 | enum_member_declarations COMMA enum_member_declaration
3170 enum_member_declaration
3171 : opt_attributes identifier
3173 ValaEnumValue *ev = vala_enum_value_new ($2);
3174 g_free ($2);
3175 vala_enum_add_value (current_enum, ev);
3176 g_object_unref (ev);
3178 | opt_attributes identifier ASSIGN expression
3180 ValaEnumValue *ev = vala_enum_value_new_with_value ($2, $4);
3181 g_free ($2);
3182 g_object_unref ($4);
3183 vala_enum_add_value (current_enum, ev);
3184 g_object_unref (ev);
3188 opt_enum_method_declarations
3189 : /* empty */
3190 | enum_method_declarations
3193 enum_method_declarations
3194 : SEMICOLON enum_method_declaration
3195 | enum_method_declarations enum_method_declaration
3198 enum_method_declaration
3199 : method_declaration
3201 /* skip declarations with errors */
3202 if ($1 != NULL) {
3203 vala_enum_add_method (current_enum, $1);
3204 g_object_unref ($1);
3209 flags_declaration
3210 : comment opt_attributes opt_access_modifier FLAGS identifier opt_name_specifier flags_body
3212 GList *l;
3213 ValaSourceReference *src;
3215 char *name = $5;
3217 if ($6 != NULL) {
3218 ValaSourceReference *ns_src = src(@5);
3219 current_namespace = vala_namespace_new ($5, ns_src);
3220 g_free ($5);
3221 g_object_unref (ns_src);
3222 current_namespace_implicit = TRUE;
3224 vala_source_file_add_namespace (current_source_file, current_namespace);
3225 g_object_unref (current_namespace);
3227 name = $6;
3230 src = src_com(@5, $1);
3231 $$ = vala_flags_new (name, src);
3232 g_free (name);
3233 g_object_unref (src);
3235 VALA_CODE_NODE($$)->attributes = $2;
3237 if ($3 != 0) {
3238 VALA_DATA_TYPE($$)->access = $3;
3240 for (l = $7; l != NULL; l = l->next) {
3241 vala_flags_add_value ($$, l->data);
3242 g_object_unref (l->data);
3247 flags_body
3248 : OPEN_BRACE opt_flags_member_declarations CLOSE_BRACE
3250 $$ = $2;
3254 opt_flags_member_declarations
3255 : /* empty */
3257 $$ = NULL;
3259 | flags_member_declarations opt_comma
3262 flags_member_declarations
3263 : flags_member_declaration
3265 $$ = g_list_append (NULL, $1);
3267 | flags_member_declarations COMMA flags_member_declaration
3269 $$ = g_list_append ($1, $3);
3273 flags_member_declaration
3274 : opt_attributes identifier
3276 $$ = vala_flags_value_new ($2);
3277 g_free ($2);
3279 | opt_attributes identifier ASSIGN expression
3281 $$ = vala_flags_value_new_with_value ($2, $4);
3282 g_free ($2);
3283 g_object_unref ($4);
3287 callback_declaration
3288 : comment opt_attributes opt_access_modifier CALLBACK type identifier opt_name_specifier opt_type_parameter_list OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
3290 ValaSourceReference *src;
3291 GList *l;
3292 char *name = $6;
3294 if ($7 != NULL) {
3295 ValaSourceReference *ns_src = src(@6);
3296 current_namespace = vala_namespace_new ($6, ns_src);
3297 g_free ($6);
3298 g_object_unref (ns_src);
3299 current_namespace_implicit = TRUE;
3301 vala_source_file_add_namespace (current_source_file, current_namespace);
3302 g_object_unref (current_namespace);
3304 name = $7;
3307 src = src_com(@6, $1);
3308 $$ = vala_callback_new (name, $5, src);
3309 g_free (name);
3310 g_object_unref ($5);
3311 g_object_unref (src);
3312 if ($3 != 0) {
3313 VALA_DATA_TYPE($$)->access = $3;
3315 VALA_CODE_NODE($$)->attributes = $2;
3317 if ($8 != NULL) {
3318 for (l = $8; l != NULL; l = l->next) {
3319 vala_callback_add_type_parameter ($$, l->data);
3320 g_object_unref (l->data);
3322 g_list_free ($8);
3324 if ($10 != NULL) {
3325 for (l = $10; l != NULL; l = l->next) {
3326 vala_callback_add_parameter ($$, l->data);
3327 g_object_unref (l->data);
3329 g_list_free ($10);
3332 | comment opt_attributes opt_access_modifier opt_modifiers DELEGATE type identifier opt_name_specifier opt_type_parameter_list OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
3334 ValaSourceReference *src;
3335 GList *l;
3336 char *name = $7;
3338 if ($8 != NULL) {
3339 ValaSourceReference *ns_src = src(@7);
3340 current_namespace = vala_namespace_new ($7, ns_src);
3341 g_free ($7);
3342 g_object_unref (ns_src);
3343 current_namespace_implicit = TRUE;
3345 vala_source_file_add_namespace (current_source_file, current_namespace);
3346 g_object_unref (current_namespace);
3348 name = $8;
3351 src = src_com(@7, $1);
3352 $$ = vala_callback_new (name, $6, src);
3353 g_free (name);
3354 g_object_unref ($6);
3355 g_object_unref (src);
3356 if ($3 != 0) {
3357 VALA_DATA_TYPE($$)->access = $3;
3359 VALA_CODE_NODE($$)->attributes = $2;
3361 if ($9 != NULL) {
3362 for (l = $9; l != NULL; l = l->next) {
3363 vala_callback_add_type_parameter ($$, l->data);
3364 g_object_unref (l->data);
3366 g_list_free ($9);
3368 if ($11 != NULL) {
3369 for (l = $11; l != NULL; l = l->next) {
3370 vala_callback_add_parameter ($$, l->data);
3371 g_object_unref (l->data);
3373 g_list_free ($11);
3378 opt_attributes
3379 : /* empty */
3381 $$ = NULL;
3383 | attributes
3386 attributes
3387 : attribute_sections
3390 attribute_sections
3391 : attribute_section
3392 | attribute_sections attribute_section
3394 $$ = g_list_concat ($1, $2);
3398 attribute_section
3399 : OPEN_BRACKET attribute_list CLOSE_BRACKET
3401 $$ = $2;
3403 | OPEN_BRACKET error CLOSE_BRACKET
3405 $$ = NULL;
3409 attribute_list
3410 : attribute
3412 $$ = g_list_append (NULL, $1);
3414 | attribute_list COMMA attribute
3416 $$ = g_list_append ($1, $3);
3420 attribute
3421 : attribute_name
3423 ValaSourceReference *src = src(@1);
3424 $$ = vala_attribute_new ($1, src);
3425 g_free ($1);
3426 g_object_unref (src);
3428 | attribute_name OPEN_PARENS opt_named_argument_list CLOSE_PARENS
3430 GList *l;
3432 ValaSourceReference *src = src(@1);
3433 $$ = vala_attribute_new ($1, src);
3434 g_object_unref (src);
3436 for (l = $3; l != NULL; l = l->next) {
3437 vala_attribute_add_argument ($$, l->data);
3438 g_object_unref (l->data);
3440 if ($3 != NULL) {
3441 g_list_free ($3);
3444 g_free ($1);
3448 attribute_name
3449 : identifier
3452 opt_named_argument_list
3453 : /* empty */
3455 $$ = NULL;
3457 | named_argument_list
3460 named_argument_list
3461 : named_argument
3463 $$ = g_list_append (NULL, $1);
3465 | named_argument_list COMMA named_argument
3467 $$ = g_list_append ($1, $3);
3471 named_argument
3472 : identifier ASSIGN expression
3474 ValaSourceReference *src = src(@1);
3475 $$ = vala_named_argument_new ($1, $3, src);
3476 g_object_unref (src);
3478 g_free ($1);
3479 g_object_unref ($3);
3483 opt_type_parameter_list
3484 : /* empty */
3486 $$ = NULL;
3488 | type_parameter_list
3491 type_parameter_list
3492 : GENERIC_LT type_parameters OP_GT
3494 $$ = $2;
3498 type_parameters
3499 : type_parameter
3501 $$ = g_list_append (NULL, $1);
3503 | type_parameters COMMA type_parameter
3505 $$ = g_list_append ($1, $3);
3509 type_parameter
3510 : identifier
3512 ValaSourceReference *src = src(@1);
3513 $$ = vala_type_parameter_new ($1, src);
3514 g_object_unref (src);
3515 g_free ($1);
3519 opt_type_argument_list
3520 : /* empty */
3522 $$ = NULL;
3524 | type_argument_list
3527 type_argument_list
3528 : GENERIC_LT type_arguments OP_GT
3530 $$ = $2;
3534 type_arguments
3535 : type_argument
3537 $$ = g_list_append (NULL, $1);
3539 | type_arguments COMMA type_argument
3541 $$ = g_list_append ($1, $3);
3545 type_argument
3546 : type
3548 $$ = $1;
3549 if (!vala_type_reference_get_is_weak ($$)) {
3550 vala_type_reference_set_takes_ownership ($$, TRUE);
3555 open_parens
3556 : OPEN_PARENS
3557 | OPEN_CAST_PARENS
3560 member_name
3561 : identifier opt_type_argument_list
3563 ValaSourceReference *src = src(@1);
3564 $$ = VALA_EXPRESSION (vala_member_access_new (NULL, $1, src));
3565 g_free ($1);
3566 g_object_unref (src);
3568 if ($2 != NULL) {
3569 GList *l;
3570 for (l = $2; l != NULL; l = l->next) {
3571 vala_member_access_add_type_argument (VALA_MEMBER_ACCESS ($$), l->data);
3572 g_object_unref (l->data);
3574 g_list_free ($2);
3577 | member_name DOT identifier opt_type_argument_list
3579 ValaSourceReference *src = src(@1);
3580 $$ = VALA_EXPRESSION (vala_member_access_new ($1, $3, src));
3581 g_object_unref ($1);
3582 g_free ($3);
3583 g_object_unref (src);
3585 if ($4 != NULL) {
3586 GList *l;
3587 for (l = $4; l != NULL; l = l->next) {
3588 vala_member_access_add_type_argument (VALA_MEMBER_ACCESS ($$), l->data);
3589 g_object_unref (l->data);
3591 g_list_free ($4);
3598 extern FILE *yyin;
3599 extern int yylineno;
3601 static void
3602 yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg)
3604 ValaSourceReference *source_reference = vala_source_reference_new (current_source_file, locp->first_line, locp->first_column, locp->last_line, locp->last_column);
3605 vala_report_error (source_reference, (char *) msg);
3608 void
3609 vala_parser_parse_file (ValaParser *parser, ValaSourceFile *source_file)
3611 current_source_file = source_file;
3612 current_namespace = vala_source_file_get_global_namespace (source_file);
3613 yyin = fopen (vala_source_file_get_filename (current_source_file), "r");
3614 if (yyin == NULL) {
3615 printf ("Couldn't open source file: %s.\n", vala_source_file_get_filename (current_source_file));
3616 return;
3619 /* restart line counter on each file */
3620 yylineno = 1;
3622 yyparse (parser);
3623 fclose (yyin);
3624 yyin = NULL;