2
// ConditionalExpression.cs
5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
namespace ICSharpCode.NRefactory.CSharp
30
/// Condition ? TrueExpression : FalseExpression
32
public class ConditionalExpression : Expression
34
public readonly static Role<Expression> ConditionRole = Roles.Condition;
35
public readonly static TokenRole QuestionMarkRole = new TokenRole("?");
36
public readonly static Role<Expression> TrueRole = new Role<Expression>("True", Expression.Null);
37
public readonly static TokenRole ColonRole = Roles.Colon;
38
public readonly static Role<Expression> FalseRole = new Role<Expression>("False", Expression.Null);
40
public Expression Condition {
41
get { return GetChildByRole(ConditionRole); }
42
set { SetChildByRole(ConditionRole, value); }
45
public CSharpTokenNode QuestionMarkToken {
46
get { return GetChildByRole (QuestionMarkRole); }
49
public Expression TrueExpression {
50
get { return GetChildByRole(TrueRole); }
51
set { SetChildByRole(TrueRole, value); }
54
public CSharpTokenNode ColonToken {
55
get { return GetChildByRole (ColonRole); }
58
public Expression FalseExpression {
59
get { return GetChildByRole(FalseRole); }
60
set { SetChildByRole(FalseRole, value); }
63
public ConditionalExpression ()
67
public ConditionalExpression (Expression condition, Expression trueExpression, Expression falseExpression)
69
AddChild (condition, ConditionRole);
70
AddChild (trueExpression, TrueRole);
71
AddChild (falseExpression, FalseRole);
74
public override void AcceptVisitor (IAstVisitor visitor)
76
visitor.VisitConditionalExpression (this);
79
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
81
return visitor.VisitConditionalExpression (this);
84
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
86
return visitor.VisitConditionalExpression (this, data);
89
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
91
ConditionalExpression o = other as ConditionalExpression;
92
return o != null && this.Condition.DoMatch(o.Condition, match) && this.TrueExpression.DoMatch(o.TrueExpression, match) && this.FalseExpression.DoMatch(o.FalseExpression, match);