3 * Copyright (C) 2009 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>
24 public class Vala
.Template
: Expression
{
25 private List
<Expression
> expression_list
= new ArrayList
<Expression
> ();
30 public void add_expression (Expression expr
) {
31 expression_list
.add (expr
);
34 public List
<Expression
> get_expressions () {
35 return expression_list
;
38 public override bool is_pure () {
42 Expression
stringify (Expression expr
) {
43 if (expr is StringLiteral
) {
46 return new
MethodCall (new
MemberAccess (expr
, "to_string", expr
.source_reference
), expr
.source_reference
);
50 public override bool check (SemanticAnalyzer analyzer
) {
59 if (expression_list
.size
== 0) {
60 expr
= new
StringLiteral ("\"\"", source_reference
);
62 expr
= stringify (expression_list
[0]);
63 if (expression_list
.size
> 1) {
64 var concat
= new
MethodCall (new
MemberAccess (expr
, "concat", source_reference
), source_reference
);
65 for (int i
= 1; i
< expression_list
.size
; i
++) {
66 concat
.add_argument (stringify (expression_list
[i
]));
71 expr
.target_type
= target_type
;
73 analyzer
.replaced_nodes
.add (this
);
74 parent_node
.replace_expression (this
, expr
);
75 return expr
.check (analyzer
);