Add support for async signal handlers
[vala-lang.git] / vala / valatemplate.vala
blobd11c0c87cec37d43014f853d4eb6b47759ccb6e1
1 /* valatemplate.vala
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
19 * Author:
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 () {
50 return false;
53 Expression stringify (Expression expr) {
54 if (expr is StringLiteral) {
55 return expr;
56 } else {
57 return new MethodCall (new MemberAccess (expr, "to_string", expr.source_reference), expr.source_reference);
61 public override bool check (CodeContext context) {
62 if (checked) {
63 return !error;
66 checked = true;
68 Expression expr;
70 if (expression_list.size == 0) {
71 expr = new StringLiteral ("\"\"", source_reference);
72 } else {
73 expr = stringify (expression_list[0]);
74 if (expression_list.size > 1) {
75 if (context.profile == Profile.DOVA) {
76 // varargs concat not yet supported
77 for (int i = 1; i < expression_list.size; i++) {
78 expr = new BinaryExpression (BinaryOperator.PLUS, expr, stringify (expression_list[i]), source_reference);
80 } else {
81 var concat = new MethodCall (new MemberAccess (expr, "concat", source_reference), source_reference);
82 for (int i = 1; i < expression_list.size; i++) {
83 concat.add_argument (stringify (expression_list[i]));
85 expr = concat;
89 expr.target_type = target_type;
91 context.analyzer.replaced_nodes.add (this);
92 parent_node.replace_expression (this, expr);
93 return expr.check (context);