3 * Copyright (C) 2006-2010 Jürg Billeter
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.1 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>
26 * Represents a fixed-length sequence of expressions in the source code.
28 public class Vala
.Tuple
: Expression
{
29 private List
<Expression
> expression_list
= new ArrayList
<Expression
> ();
31 public Tuple (SourceReference? source_reference
= null) {
32 this
.source_reference
= source_reference
;
35 public override void accept_children (CodeVisitor visitor
) {
36 foreach (Expression expr
in expression_list
) {
37 expr
.accept (visitor
);
41 public override void accept (CodeVisitor visitor
) {
42 visitor
.visit_tuple (this
);
44 visitor
.visit_expression (this
);
47 public void add_expression (Expression expr
) {
48 expression_list
.add (expr
);
51 public List
<Expression
> get_expressions () {
52 return expression_list
;
55 public override bool is_pure () {
59 public override void replace_expression (Expression old_node
, Expression new_node
) {
60 for (int i
= 0; i
< expression_list
.size
; i
++) {
61 if (expression_list
[i
] == old_node
) {
62 expression_list
[i
] = new_node
;
67 public override bool check (SemanticAnalyzer analyzer
) {
74 if (analyzer
.context
.profile
!= Profile
.DOVA
) {
75 Report
.error (source_reference
, "tuples are not supported");
80 value_type
= new
ObjectType ((Class
) analyzer
.context
.root
.scope
.lookup ("Dova").scope
.lookup ("Tuple"));
81 value_type
.value_owned
= true;
83 foreach (var expr
in expression_list
) {
84 if (!expr
.check (analyzer
)) {
87 value_type
.add_type_argument (expr
.value_type
.copy ());
93 public override void emit (CodeGenerator codegen
) {
94 foreach (Expression expr
in expression_list
) {
98 codegen
.visit_tuple (this
);
100 codegen
.visit_expression (this
);