3 * Copyright (C) 2009-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>
24 public class Vala
.Template
: Expression
{
25 private List
<Expression
> expression_list
= new ArrayList
<Expression
> ();
27 public Template (SourceReference? source_reference
= null) {
28 this
.source_reference
= source_reference
;
31 public override void accept (CodeVisitor visitor
) {
32 visitor
.visit_template (this
);
35 public override void accept_children (CodeVisitor visitor
) {
36 foreach (var expr
in expression_list
) {
37 expr
.accept (visitor
);
41 public void add_expression (Expression expr
) {
42 expression_list
.add (expr
);
45 public List
<Expression
> get_expressions () {
46 return expression_list
;
49 public override bool is_pure () {
53 Expression
stringify (Expression expr
) {
54 if (expr is StringLiteral
) {
57 return new
MethodCall (new
MemberAccess (expr
, "to_string", expr
.source_reference
), expr
.source_reference
);
61 public override bool check (CodeContext context
) {
70 if (expression_list
.size
== 0) {
71 expr
= new
StringLiteral ("\"\"", source_reference
);
73 expr
= stringify (expression_list
[0]);
74 if (expression_list
.size
> 1) {
75 var concat
= new
MethodCall (new
MemberAccess (expr
, "concat", source_reference
), source_reference
);
76 for (int i
= 1; i
< expression_list
.size
; i
++) {
77 concat
.add_argument (stringify (expression_list
[i
]));
82 expr
.target_type
= target_type
;
84 context
.analyzer
.replaced_nodes
.add (this
);
85 parent_node
.replace_expression (this
, expr
);
86 return expr
.check (context
);