valacastexpression.vala 1.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/* valacastexpression.vala
 *
 * Copyright (C) 2006  Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 */

using GLib;

25 26 27 28 29
/**
 * Represents a type cast in the source code.
 */
public class Vala.CastExpression : Expression {
	/**
30
	 * The expression to be cast.
31
	 */
32 33 34 35 36 37 38 39 40
	public Expression! inner {
		get {
			return _inner;
		}
		set construct {
			_inner = value;
			_inner.parent_node = this;
		}
	}
41 42 43 44 45
	
	/**
	 * The target type.
	 */
	public TypeReference! type_reference { get; set construct; }
46

47 48
	private Expression! _inner;

49 50 51
	/**
	 * Creates a new cast expression.
	 *
52
	 * @param inner expression to be cast
53 54 55
	 * @param type  target type
	 * @return      newly created cast expression
	 */
56
	public CastExpression (Expression! _inner, TypeReference! type, SourceReference source) {
57 58 59
		inner = _inner;
		type_reference = type;
		source_reference = source;
60 61
	}
	
62
	public override void accept (CodeVisitor! visitor) {
63 64
		inner.accept (visitor);
		type_reference.accept (visitor);
65

66
		visitor.visit_cast_expression (this);
67
	}
68 69 70

	public override void replace (CodeNode! old_node, CodeNode! new_node) {
		if (inner == old_node) {
Jürg Billeter's avatar
Jürg Billeter committed
71
			inner = (Expression) new_node;
72 73
		}
	}
74
}