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
20 * Jürg Billeter <j@bitron.ch>
21 * Raffaele Sandrini <rasa@gmx.ch>
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
;
48 VALA_MODIFIER_ABSTRACT
= 1 << 0,
49 VALA_MODIFIER_OVERRIDE
= 1 << 1,
50 VALA_MODIFIER_STATIC
= 1 << 2,
51 VALA_MODIFIER_VIRTUAL
= 1 << 3
54 int yylex (YYSTYPE *yylval_param
, YYLTYPE *yylloc_param
, ValaParser
*parser
);
55 static void yyerror (YYLTYPE *locp
, ValaParser
*parser
, const char *msg
);
61 %parse
-param
{ValaParser
*parser
}
62 %lex
-param
{ValaParser
*parser
}
69 ValaTypeReference
*type_reference
;
70 ValaExpression
*expression
;
71 ValaStatement
*statement
;
72 ValaNamespace
*namespace
;
75 ValaInterface
*interface
;
77 ValaEnumValue
*enum_value
;
79 ValaFlagsValue
*flags_value
;
80 ValaCallback
*callback
;
81 ValaConstant
*constant
;
84 ValaFormalParameter
*formal_parameter
;
85 ValaProperty
*property
;
86 ValaPropertyAccessor
*property_accessor
;
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
"..."
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
">>="
131 %token OP_SHIFT_LEFT
"<<"
132 %token OP_SHIFT_RIGHT
">>"
136 %token GENERIC_LT
"generic <"
141 %token BITWISE_OR
"|"
142 %token BITWISE_AND
"&"
154 %token ABSTRACT
"abstract"
157 %token CALLBACK
"callback"
162 %token CONSTRUCT
"construct"
163 %token CONTINUE
"continue"
164 %token DEFAULT
"default"
165 %token DELEGATE
"delegate"
169 %token VALA_FALSE
"false"
170 %token FINALLY
"finally"
173 %token FOREACH
"foreach"
177 %token INTERFACE
"interface"
180 %token NAMESPACE
"namespace"
182 %token VALA_NULL
"null"
184 %token OVERRIDE
"override"
185 %token PRIVATE
"private"
186 %token PROTECTED
"protected"
187 %token PUBLIC
"public"
189 %token RETURN
"return"
191 %token SIGNAL
"signal"
192 %token SIZEOF
"sizeof"
193 %token STATIC
"static"
194 %token STRUCT
"struct"
195 %token SWITCH
"switch"
198 %token THROWS
"throws"
199 %token VALA_TRUE
"true"
201 %token TYPEOF
"typeof"
204 %token VIRTUAL
"virtual"
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"
215 %type
<str
> identifier
216 %type
<literal
> literal
217 %type
<literal
> boolean_literal
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
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 */
384 %start compilation_unit
393 /* identifiers never conflict with context-specific keywords get or set */
398 $$
= g_strdup
("get");
402 $$
= g_strdup
("set");
410 ValaSourceReference
*src
= src
(@
1);
411 $$
= VALA_LITERAL
(vala_integer_literal_new
($1, src
));
412 g_object_unref
(src
);
417 ValaSourceReference
*src
= src
(@
1);
418 $$
= VALA_LITERAL
(vala_real_literal_new
($1, src
));
420 g_object_unref
(src
);
424 ValaSourceReference
*src
= src
(@
1);
425 $$
= VALA_LITERAL
(vala_character_literal_new
($1, src
));
426 g_object_unref
(src
);
431 ValaSourceReference
*src
= src
(@
1);
432 $$
= VALA_LITERAL
(vala_string_literal_new
($1, src
));
433 g_object_unref
(src
);
438 ValaSourceReference
*src
= src
(@
1);
439 $$
= VALA_LITERAL
(vala_null_literal_new
(src
));
440 g_object_unref
(src
);
447 ValaSourceReference
*src
= src
(@
1);
448 $$
= VALA_LITERAL
(vala_boolean_literal_new
(TRUE
, src
));
449 g_object_unref
(src
);
453 ValaSourceReference
*src
= src
(@
1);
454 $$
= VALA_LITERAL
(vala_boolean_literal_new
(FALSE
, src
));
455 g_object_unref
(src
);
460 : opt_using_directives opt_outer_declarations
464 : identifier opt_type_argument_list
467 ValaSourceReference
*src
= src
(@
1);
468 $$
= vala_type_reference_new_from_name
(NULL
, $1, src
);
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
);
477 | identifier DOT identifier opt_type_argument_list
480 ValaSourceReference
*src
= src
(@
1);
481 $$
= vala_type_reference_new_from_name
($1, $3, src
);
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
);
505 : type_name opt_rank_specifier opt_op_neg
508 vala_type_reference_set_array_rank
($$
, $2);
510 vala_type_reference_set_non_null
($$
, TRUE
);
513 | type_name opt_rank_specifier opt_op_neg HASH
516 vala_type_reference_set_is_ref
($$
, TRUE
);
517 vala_type_reference_set_array_rank
($$
, $2);
519 vala_type_reference_set_non_null
($$
, TRUE
);
522 | REF type_name opt_rank_specifier opt_op_neg
525 vala_type_reference_set_is_ref
($$
, TRUE
);
526 vala_type_reference_set_array_rank
($$
, $3);
528 vala_type_reference_set_non_null
($$
, TRUE
);
531 | WEAK type_name opt_rank_specifier opt_op_neg
534 vala_type_reference_set_is_weak
($$
, TRUE
);
535 vala_type_reference_set_array_rank
($$
, $3);
537 vala_type_reference_set_non_null
($$
, TRUE
);
540 | OUT type_name opt_rank_specifier opt_op_neg
543 vala_type_reference_set_is_out
($$
, TRUE
);
544 vala_type_reference_set_array_rank
($$
, $3);
546 vala_type_reference_set_non_null
($$
, TRUE
);
549 | OUT REF type_name opt_rank_specifier opt_op_neg
552 vala_type_reference_set_is_ref
($$
, TRUE
);
553 vala_type_reference_set_is_out
($$
, TRUE
);
554 vala_type_reference_set_array_rank
($$
, $4);
556 vala_type_reference_set_non_null
($$
, TRUE
);
559 | type_name stars opt_rank_specifier opt_op_neg
562 vala_type_reference_set_pointer_level
($$
, $2);
563 vala_type_reference_set_array_rank
($$
, $3);
565 vala_type_reference_set_non_null
($$
, TRUE
);
581 $$
= g_list_append
(NULL
, $1);
583 | argument_list COMMA argument
585 $$
= g_list_append
($1, $3);
594 : primary_no_array_creation_expression
595 | array_creation_expression
598 array_creation_expression
599 : NEW member_name size_specifier_list opt_initializer
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
));
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
);
611 g_object_unref
(src
);
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
));
623 g_object_unref
(src
);
630 : OPEN_BRACKET expression_list CLOSE_BRACKET
653 : OPEN_BRACKET opt_comma_list CLOSE_BRACKET
694 primary_no_array_creation_expression
697 ValaSourceReference
*src
= src
(@
1);
698 $$
= VALA_EXPRESSION
(vala_literal_expression_new
($1, src
));
699 g_object_unref
(src
);
703 | parenthesized_expression
705 | invocation_expression
709 | post_increment_expression
710 | post_decrement_expression
711 | object_creation_expression
717 : identifier opt_type_argument_list
719 ValaSourceReference
*src
= src
(@
1);
720 $$
= VALA_EXPRESSION
(vala_member_access_new
(NULL
, $1, src
));
722 g_object_unref
(src
);
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
);
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
);
746 : primary_expression DOT identifier opt_type_argument_list
748 ValaSourceReference
*src
= src
(@
3);
749 $$
= VALA_EXPRESSION
(vala_member_access_new
($1, $3, src
));
752 g_object_unref
(src
);
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
);
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
));
771 g_object_unref
(src
);
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
);
785 : primary_no_array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
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
);
796 g_object_unref
(src
);
803 $$
= g_list_append
(NULL
, $1);
805 | expression_list COMMA expression
807 $$
= g_list_append
($1, $3);
814 ValaSourceReference
*src
= src
(@
1);
815 $$
= VALA_EXPRESSION
(vala_member_access_new
(NULL
, "this", src
));
816 g_object_unref
(src
);
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
);
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
);
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
);
855 g_object_unref
(src
);
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
);
866 $$
= VALA_EXPRESSION
(expr
);
871 : SIZEOF open_parens type_name CLOSE_PARENS
873 ValaSourceReference
*src
= src
(@
1);
874 $$
= VALA_EXPRESSION
(vala_sizeof_expression_new
($3, src
));
876 g_object_unref
(src
);
880 : TYPEOF open_parens type_name CLOSE_PARENS
882 ValaSourceReference
*src
= src
(@
1);
883 $$
= VALA_EXPRESSION
(vala_typeof_expression_new
($3, src
));
885 g_object_unref
(src
);
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
);
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
);
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
);
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
);
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
);
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
);
934 | HASH unary_expression
936 ValaSourceReference
*src
= src
(@
1);
937 $$
= VALA_EXPRESSION
(vala_reference_transfer_expression_new
($2, src
));
938 g_object_unref
(src
);
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
));
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
));
962 g_object_unref
(src
);
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
);
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
);
988 : BITWISE_AND unary_expression
990 ValaSourceReference
*src
= src
(@
1);
991 $$
= VALA_EXPRESSION
(vala_addressof_expression_new
($2, src
));
992 g_object_unref
(src
);
997 multiplicative_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);
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);
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
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);
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);
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
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);
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
));
1211 for
(l
= $2; l
!= NULL
; l
= l
->next
) {
1212 vala_lambda_expression_add_parameter
(VALA_LAMBDA_EXPRESSION
($$
), l
->data
);
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);
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
));
1235 for
(l
= $2; l
!= NULL
; l
= l
->next
) {
1236 vala_lambda_expression_add_parameter
(VALA_LAMBDA_EXPRESSION
($$
), l
->data
);
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);
1255 opt_lambda_parameter_list
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);
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);
1289 $$
= VALA_ASSIGNMENT_OPERATOR_SIMPLE
;
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
;
1305 $$
= VALA_ASSIGNMENT_OPERATOR_ADD
;
1309 $$
= VALA_ASSIGNMENT_OPERATOR_SUB
;
1313 $$
= VALA_ASSIGNMENT_OPERATOR_MUL
;
1317 $$
= VALA_ASSIGNMENT_OPERATOR_DIV
;
1321 $$
= VALA_ASSIGNMENT_OPERATOR_PERCENT
;
1325 $$
= VALA_ASSIGNMENT_OPERATOR_SHIFT_LEFT
;
1327 | ASSIGN_SHIFT_RIGHT
1329 $$
= VALA_ASSIGNMENT_OPERATOR_SHIFT_RIGHT
;
1342 : conditional_expression
1352 : declaration_statement
1355 | expression_statement
1356 | selection_statement
1357 | iteration_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
);
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
);
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
);
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
);
1424 : OPEN_BRACE opt_statement_list CLOSE_BRACE
1426 ValaSourceReference
*src
= src
(@
1);
1427 $$
= VALA_STATEMENT
(vala_block_new
(src
));
1430 for
(l
= $2; l
!= NULL
; l
= l
->next
) {
1431 vala_block_add_statement
(VALA_BLOCK
($$
), l
->data
);
1432 g_object_unref
(l
->data
);
1436 g_object_unref
(src
);
1451 $$
= g_list_append
(NULL
, $1);
1453 | statement_list statement
1455 $$
= g_list_append
($1, $2);
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
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
);
1494 g_object_unref
($1);
1496 | VAR variable_declarators
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
);
1510 /* don't use type to prevent reduce/reduce conflict */
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);
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);
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);
1552 vala_type_reference_set_non_null
($$
, 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
1582 | post_increment_expression
1583 | post_decrement_expression
1584 | pre_increment_expression
1585 | pre_decrement_expression
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);
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);
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);
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
);
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
);
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
);
1664 : OPEN_BRACE opt_switch_sections CLOSE_BRACE
1681 $$
= g_list_append
(NULL
, $1);
1683 | switch_sections switch_section
1685 $$
= g_list_append
($1, $2);
1690 : comment switch_labels statement_list
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
);
1702 for
(l
= $3; l
!= NULL
; l
= l
->next
) {
1703 vala_switch_section_add_statement
($$
, l
->data
);
1704 g_object_unref
(l
->data
);
1713 $$
= g_list_append
(NULL
, $1);
1715 | switch_labels switch_label
1717 $$
= g_list_append
($1, $2);
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
);
1731 ValaSourceReference
*src
= src
(@
1);
1732 $$
= vala_switch_label_new_with_default
(src
);
1733 g_object_unref
(src
);
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);
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
);
1767 : FOR OPEN_PARENS opt_statement_expression_list SEMICOLON opt_expression SEMICOLON opt_statement_expression_list CLOSE_PARENS embedded_statement
1770 ValaSourceReference
*src
= src
(@
1);
1771 $$
= VALA_STATEMENT
(vala_for_statement_new
($5, $9, src
));
1773 g_object_unref
($5);
1775 g_object_unref
($9);
1776 g_object_unref
(src
);
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
);
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
);
1793 | FOR OPEN_PARENS local_variable_declaration SEMICOLON opt_expression SEMICOLON opt_statement_expression_list CLOSE_PARENS embedded_statement
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
);
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
);
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
);
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
);
1843 vala_block_add_statement
(block
, VALA_STATEMENT
(for_statement
));
1845 $$
= VALA_STATEMENT
(block
);
1849 opt_statement_expression_list
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);
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);
1875 g_object_unref
($6);
1876 g_object_unref
($8);
1877 g_object_unref
(src
);
1883 | continue_statement
1891 ValaSourceReference
*src
= src
(@
1);
1892 $$
= VALA_STATEMENT
(vala_break_statement_new
(src
));
1893 g_object_unref
(src
);
1898 : CONTINUE SEMICOLON
1900 ValaSourceReference
*src
= src
(@
1);
1901 $$
= VALA_STATEMENT
(vala_continue_statement_new
(src
));
1902 g_object_unref
(src
);
1907 : RETURN opt_expression SEMICOLON
1909 ValaSourceReference
*src
= src
(@
1);
1910 $$
= VALA_STATEMENT
(vala_return_statement_new
($2, src
));
1911 g_object_unref
(src
);
1913 g_object_unref
($2);
1919 : THROW expression SEMICOLON
1921 ValaSourceReference
*src
= src
(@
1);
1922 $$
= VALA_STATEMENT
(vala_throw_statement_new
($2, src
));
1923 g_object_unref
(src
);
1925 g_object_unref
($2);
1931 : TRY block catch_clauses opt_finally_clause
1934 ValaSourceReference
*src
= src
(@
1);
1935 $$
= VALA_STATEMENT
(vala_try_statement_new
(VALA_BLOCK
($2), VALA_BLOCK
($4), src
));
1936 g_object_unref
($2);
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
);
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
);
1959 : specific_catch_clauses opt_general_catch_clause
1962 $$
= g_list_append
($1, $2);
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);
1991 g_object_unref
($6);
1992 g_object_unref
(src
);
1996 opt_general_catch_clause
2001 | general_catch_clause
2004 general_catch_clause
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
);
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;
2050 $$
= current_namespace
;
2051 current_namespace
= vala_source_file_get_global_namespace
(current_source_file
);
2056 : OPEN_BRACE opt_namespace_member_declarations CLOSE_BRACE
2057 | OPEN_BRACE
error CLOSE_BRACE
2075 opt_using_directives
2082 | using_directives 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
);
2092 vala_source_file_add_using_directive
(current_source_file
, ns_ref
);
2093 g_object_unref
(ns_ref
);
2097 opt_outer_declarations
2099 | outer_declarations
2104 | outer_declarations 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
2118 | namespace_member_declarations
2121 namespace_member_declarations
2122 : namespace_member_declaration
2123 | namespace_member_declarations namespace_member_declaration
2126 namespace_member_declaration
2129 /* skip declarations with errors */
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 */
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 */
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
;
2171 /* skip declarations with errors */
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
;
2185 /* skip declarations with errors */
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 */
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 */
2215 vala_namespace_add_constant
(current_namespace
, $1);
2216 g_object_unref
($1);
2221 /* skip declarations with errors */
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 */
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);
2246 : comment opt_attributes opt_access_modifier opt_modifiers CLASS identifier opt_name_specifier opt_type_parameter_list opt_class_base
2249 ValaSourceReference
*src
;
2254 ValaSourceReference
*ns_src
= src
(@
6);
2255 current_namespace
= vala_namespace_new
($6, ns_src
);
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
);
2266 src
= src_com
(@
6, $1);
2267 current_class
= vala_class_new
(name
, src
);
2269 g_object_unref
(src
);
2271 VALA_CODE_NODE
(current_class
)->attributes
= $2;
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
);
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
);
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
);
2299 current_class
= NULL
;
2314 $$
= VALA_MEMBER_ACCESSIBILITY_PUBLIC
;
2318 $$
= VALA_MEMBER_ACCESSIBILITY_PROTECTED
;
2322 $$
= VALA_MEMBER_ACCESSIBILITY_PRIVATE
;
2329 $$
= VALA_MODIFIER_NONE
;
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
);
2350 $$
= VALA_MODIFIER_ABSTRACT
;
2354 $$
= VALA_MODIFIER_OVERRIDE
;
2358 $$
= VALA_MODIFIER_STATIC
;
2362 $$
= VALA_MODIFIER_VIRTUAL
;
2384 $$
= g_list_append
(NULL
, $1);
2386 | type_list COMMA type_name
2388 $$
= g_list_append
($1, $3);
2393 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
2396 opt_class_member_declarations
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 */
2411 vala_class_add_constant
(current_class
, $1);
2412 g_object_unref
($1);
2417 /* skip declarations with errors */
2419 vala_class_add_field
(current_class
, $1);
2420 g_object_unref
($1);
2423 | method_declaration
2425 /* skip declarations with errors */
2427 vala_class_add_method
(current_class
, $1);
2428 g_object_unref
($1);
2431 | property_declaration
2433 /* skip declarations with errors */
2435 vala_class_add_property
(current_class
, $1, FALSE
);
2436 g_object_unref
($1);
2439 | signal_declaration
2441 /* skip declarations with errors */
2443 vala_class_add_signal
(current_class
, $1);
2444 g_object_unref
($1);
2447 | constructor_declaration
2449 /* skip declarations with errors */
2451 vala_class_set_constructor
(current_class
, $1);
2452 g_object_unref
($1);
2455 | destructor_declaration
2457 /* skip declarations with errors */
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);
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
);
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);
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);
2525 ValaSourceReference
*src
= src
(@
1);
2526 $$
= vala_variable_declarator_new
($1, NULL
, src
);
2527 g_object_unref
(src
);
2530 | identifier ASSIGN variable_initializer
2532 ValaSourceReference
*src
= src
(@
1);
2533 $$
= vala_variable_declarator_new
($1, $3, src
);
2534 g_object_unref
(src
);
2536 g_object_unref
($3);
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
);
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
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
2582 : method_header method_body
2585 vala_method_set_body
($$
, VALA_BLOCK
($2));
2587 g_object_unref
($2);
2597 : comment opt_attributes opt_access_modifier opt_modifiers type identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS opt_throws_declaration
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
);
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
);
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
);
2638 g_object_unref
($5);
2641 | comment opt_attributes opt_access_modifier opt_modifiers identifier opt_name_specifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2645 ValaSourceReference
*src
= src_com
(@
5, $1);
2646 $$
= VALA_METHOD
(vala_creation_method_new
($6, src
));
2649 g_object_unref
(src
);
2650 vala_method_set_instance
($$
, FALSE
);
2654 VALA_CODE_NODE
($$
)->attributes
= $2;
2657 for
(l
= $8; l
!= NULL
; l
= l
->next
) {
2658 vala_method_add_parameter
($$
, l
->data
);
2659 g_object_unref
(l
->data
);
2674 opt_formal_parameter_list
2679 | formal_parameter_list
2682 formal_parameter_list
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
);
2692 ValaSourceReference
*src
= src
(@
1);
2693 $$
= g_list_append
(NULL
, vala_formal_parameter_new_with_ellipsis
(src
));
2694 g_object_unref
(src
);
2701 $$
= g_list_append
(NULL
, $1);
2703 | fixed_parameters COMMA fixed_parameter
2705 $$
= g_list_append
($1, $3);
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
);
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);
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
);
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);
2753 g_object_unref
($6);
2757 opt_throws_declaration
2762 | throws_declaration
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);
2789 g_object_unref
($8);
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);
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
);
2842 g_object_unref
($3);
2847 opt_set_accessor_declaration
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
);
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
);
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
);
2880 g_object_unref
($3);
2886 : comment opt_attributes opt_access_modifier SIGNAL type identifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS SEMICOLON
2890 ValaSourceReference
*src
= src_com
(@
6, $1);
2891 $$
= vala_signal_new
($6, $5, src
);
2892 g_object_unref
(src
);
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
);
2906 g_object_unref
($5);
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);
2931 g_object_unref
($9);
2938 current_struct
= $1;
2942 $$
= current_struct
;
2943 current_struct
= NULL
;
2948 : comment opt_attributes opt_access_modifier STRUCT identifier opt_name_specifier opt_type_parameter_list opt_class_base
2951 ValaSourceReference
*src
;
2956 ValaSourceReference
*ns_src
= src
(@
5);
2957 current_namespace
= vala_namespace_new
($5, ns_src
);
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
);
2968 src
= src_com
(@
5, $1);
2969 $$
= vala_struct_new
(name
, src
);
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;
2977 VALA_DATA_TYPE
($$
)->access
= $3;
2980 for
(l
= $8; l
!= NULL
; l
= l
->next
) {
2981 vala_struct_add_base_type
($$
, l
->data
);
2982 g_object_unref
(l
->data
);
2990 : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
2993 opt_struct_member_declarations
2995 | struct_member_declarations
2998 struct_member_declarations
2999 : struct_member_declaration
3000 | struct_member_declarations struct_member_declaration
3003 struct_member_declaration
3006 /* skip declarations with errors */
3008 vala_struct_add_field
(current_struct
, $1);
3009 g_object_unref
($1);
3012 | method_declaration
3014 /* skip declarations with errors */
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
;
3029 ValaSourceReference
*ns_src
= src
(@
6);
3030 current_namespace
= vala_namespace_new
($6, ns_src
);
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
);
3041 src
= src_com
(@
6, $1);
3042 current_interface
= vala_interface_new
(name
, src
);
3044 g_object_unref
(src
);
3046 VALA_CODE_NODE
(current_interface
)->attributes
= $2;
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
);
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
);
3063 for
(l
= $9; l
!= NULL
; l
= l
->next
) {
3064 vala_interface_add_prerequisite
(current_interface
, l
->data
);
3065 g_object_unref
(l
->data
);
3072 $$
= current_interface
;
3077 : OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
3080 opt_interface_member_declarations
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 */
3095 vala_interface_add_method
(current_interface
, $1);
3096 g_object_unref
($1);
3099 | property_declaration
3101 /* skip declarations with errors */
3103 vala_interface_add_property
(current_interface
, $1);
3104 g_object_unref
($1);
3107 | signal_declaration
3109 /* skip declarations with errors */
3111 vala_interface_add_signal
(current_interface
, $1);
3112 g_object_unref
($1);
3118 : comment opt_attributes opt_access_modifier ENUM identifier opt_name_specifier
3121 ValaSourceReference
*src
;
3126 ValaSourceReference
*ns_src
= src
(@
5);
3127 current_namespace
= vala_namespace_new
($5, ns_src
);
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
);
3138 src
= src_com
(@
5, $1);
3139 current_enum
= vala_enum_new
(name
, src
);
3141 g_object_unref
(src
);
3143 VALA_CODE_NODE
(current_enum
)->attributes
= $2;
3146 VALA_DATA_TYPE
(current_enum
)->access
= $3;
3152 current_enum
= NULL
;
3157 : OPEN_BRACE opt_enum_member_declarations opt_enum_method_declarations CLOSE_BRACE
3160 opt_enum_member_declarations
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);
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);
3182 g_object_unref
($4);
3183 vala_enum_add_value
(current_enum
, ev
);
3184 g_object_unref
(ev
);
3188 opt_enum_method_declarations
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 */
3203 vala_enum_add_method
(current_enum
, $1);
3204 g_object_unref
($1);
3210 : comment opt_attributes opt_access_modifier FLAGS identifier opt_name_specifier flags_body
3213 ValaSourceReference
*src
;
3218 ValaSourceReference
*ns_src
= src
(@
5);
3219 current_namespace
= vala_namespace_new
($5, ns_src
);
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
);
3230 src
= src_com
(@
5, $1);
3231 $$
= vala_flags_new
(name
, src
);
3233 g_object_unref
(src
);
3235 VALA_CODE_NODE
($$
)->attributes
= $2;
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
);
3248 : OPEN_BRACE opt_flags_member_declarations CLOSE_BRACE
3254 opt_flags_member_declarations
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);
3279 | opt_attributes identifier ASSIGN expression
3281 $$
= vala_flags_value_new_with_value
($2, $4);
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
;
3295 ValaSourceReference
*ns_src
= src
(@
6);
3296 current_namespace
= vala_namespace_new
($6, ns_src
);
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
);
3307 src
= src_com
(@
6, $1);
3308 $$
= vala_callback_new
(name
, $5, src
);
3310 g_object_unref
($5);
3311 g_object_unref
(src
);
3313 VALA_DATA_TYPE
($$
)->access
= $3;
3315 VALA_CODE_NODE
($$
)->attributes
= $2;
3318 for
(l
= $8; l
!= NULL
; l
= l
->next
) {
3319 vala_callback_add_type_parameter
($$
, l
->data
);
3320 g_object_unref
(l
->data
);
3325 for
(l
= $10; l
!= NULL
; l
= l
->next
) {
3326 vala_callback_add_parameter
($$
, l
->data
);
3327 g_object_unref
(l
->data
);
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
;
3339 ValaSourceReference
*ns_src
= src
(@
7);
3340 current_namespace
= vala_namespace_new
($7, ns_src
);
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
);
3351 src
= src_com
(@
7, $1);
3352 $$
= vala_callback_new
(name
, $6, src
);
3354 g_object_unref
($6);
3355 g_object_unref
(src
);
3357 VALA_DATA_TYPE
($$
)->access
= $3;
3359 VALA_CODE_NODE
($$
)->attributes
= $2;
3362 for
(l
= $9; l
!= NULL
; l
= l
->next
) {
3363 vala_callback_add_type_parameter
($$
, l
->data
);
3364 g_object_unref
(l
->data
);
3369 for
(l
= $11; l
!= NULL
; l
= l
->next
) {
3370 vala_callback_add_parameter
($$
, l
->data
);
3371 g_object_unref
(l
->data
);
3387 : attribute_sections
3392 | attribute_sections attribute_section
3394 $$
= g_list_concat
($1, $2);
3399 : OPEN_BRACKET attribute_list CLOSE_BRACKET
3403 | OPEN_BRACKET
error CLOSE_BRACKET
3412 $$
= g_list_append
(NULL
, $1);
3414 | attribute_list COMMA attribute
3416 $$
= g_list_append
($1, $3);
3423 ValaSourceReference
*src
= src
(@
1);
3424 $$
= vala_attribute_new
($1, src
);
3426 g_object_unref
(src
);
3428 | attribute_name OPEN_PARENS opt_named_argument_list CLOSE_PARENS
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
);
3452 opt_named_argument_list
3457 | named_argument_list
3463 $$
= g_list_append
(NULL
, $1);
3465 | named_argument_list COMMA named_argument
3467 $$
= g_list_append
($1, $3);
3472 : identifier ASSIGN expression
3474 ValaSourceReference
*src
= src
(@
1);
3475 $$
= vala_named_argument_new
($1, $3, src
);
3476 g_object_unref
(src
);
3479 g_object_unref
($3);
3483 opt_type_parameter_list
3488 | type_parameter_list
3492 : GENERIC_LT type_parameters OP_GT
3501 $$
= g_list_append
(NULL
, $1);
3503 | type_parameters COMMA type_parameter
3505 $$
= g_list_append
($1, $3);
3512 ValaSourceReference
*src
= src
(@
1);
3513 $$
= vala_type_parameter_new
($1, src
);
3514 g_object_unref
(src
);
3519 opt_type_argument_list
3524 | type_argument_list
3528 : GENERIC_LT type_arguments OP_GT
3537 $$
= g_list_append
(NULL
, $1);
3539 | type_arguments COMMA type_argument
3541 $$
= g_list_append
($1, $3);
3549 if
(!vala_type_reference_get_is_weak
($$
)) {
3550 vala_type_reference_set_takes_ownership
($$
, TRUE
);
3561 : identifier opt_type_argument_list
3563 ValaSourceReference
*src
= src
(@
1);
3564 $$
= VALA_EXPRESSION
(vala_member_access_new
(NULL
, $1, src
));
3566 g_object_unref
(src
);
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
);
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);
3583 g_object_unref
(src
);
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
);
3599 extern
int yylineno
;
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
);
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");
3615 printf
("Couldn't open source file: %s.\n", vala_source_file_get_filename
(current_source_file
));
3619 /* restart line counter on each file */