1 /* valainvocationexpression.vala
3 * Copyright (C) 2006-2007 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 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 an invocation expression in the source code.
28 public class Vala
.InvocationExpression
: Expression
{
32 public Expression
! call
{
38 _call
.parent_node
= this
;
42 public Expression
! _call
;
44 private List
<Expression
> argument_list
;
45 private List
<CCodeExpression
> array_sizes
;
48 * Creates a new invocation expression.
50 * @param call method to call
51 * @param source reference to source code
52 * @return newly created invocation expression
54 public InvocationExpression (Expression
! _call
, SourceReference source
= null) {
56 source_reference
= source
;
60 * Appends the specified expression to the list of arguments.
62 * @param arg an argument
64 public void add_argument (Expression
! arg
) {
65 argument_list
.append (arg
);
66 arg
.parent_node
= this
;
70 * Returns a copy of the argument list.
72 * @return argument list
74 public List
<weak Expression
> get_argument_list () {
75 return argument_list
.copy ();
79 * Add an array size C code expression.
81 public void append_array_size (CCodeExpression
! size
) {
82 array_sizes
.append (size
);
86 * Get the C code expression for array sizes for all dimensions
87 * ascending from left to right.
89 public List
<weak CCodeExpression
> get_array_sizes () {
90 return array_sizes
.copy ();
93 public override void accept (CodeVisitor
! visitor
) {
94 call
.accept (visitor
);
96 visitor
.visit_begin_invocation_expression (this
);
98 // iterate over list copy as list may change in loop body
99 foreach (Expression expr
in argument_list
.copy ()) {
100 expr
.accept (visitor
);
103 visitor
.visit_end_invocation_expression (this
);
106 public override void replace (CodeNode
! old_node
, CodeNode
! new_node
) {
107 if (call
== old_node
) {
108 call
= (Expression
) new_node
;
111 weak List
<Expression
> l
= argument_list
.find (old_node
);
113 if (new_node
.parent_node
!= null) {
117 argument_list
.insert_before (l
, new_node
);
118 argument_list
.remove_link (l
);
119 new_node
.parent_node
= this
;