1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
6
namespace ICSharpCode.NRefactory.CSharp
9
/// Base class for statements.
12
/// This class is useful even though it doesn't provide any additional functionality:
13
/// It can be used to communicate more information in APIs, e.g. "this subnode will always be a statement"
15
public abstract class Statement : AstNode
18
public new static readonly Statement Null = new NullStatement ();
20
sealed class NullStatement : Statement
22
public override bool IsNull {
28
public override void AcceptVisitor (IAstVisitor visitor)
32
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
37
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
42
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
44
return other == null || other.IsNull;
49
#region PatternPlaceholder
50
public static implicit operator Statement(PatternMatching.Pattern pattern)
52
return pattern != null ? new PatternPlaceholder(pattern) : null;
55
sealed class PatternPlaceholder : Statement, PatternMatching.INode
57
readonly PatternMatching.Pattern child;
59
public PatternPlaceholder(PatternMatching.Pattern child)
64
public override NodeType NodeType {
65
get { return NodeType.Pattern; }
68
public override void AcceptVisitor (IAstVisitor visitor)
70
visitor.VisitPatternPlaceholder(this, child);
73
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
75
return visitor.VisitPatternPlaceholder(this, child);
78
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
80
return visitor.VisitPatternPlaceholder(this, child, data);
83
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
85
return child.DoMatch(other, match);
88
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
90
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
95
public new Statement Clone()
97
return (Statement)base.Clone();
100
public Statement ReplaceWith(Func<Statement, Statement> replaceFunction)
102
if (replaceFunction == null)
103
throw new ArgumentNullException("replaceFunction");
104
return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node));
107
public override NodeType NodeType {
108
get { return NodeType.Statement; }
111
// Make debugging easier by giving Statements a ToString() implementation
112
public override string ToString()
114
return DebugToString();