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)
5
using System.Collections.Generic;
7
namespace ICSharpCode.NRefactory.VB.Ast
12
public class BlockStatement : Statement, IEnumerable<Statement>
14
public static readonly Role<Statement> StatementRole = new Role<Statement>("Statement", Statement.Null);
17
public static readonly new BlockStatement Null = new NullBlockStatement();
18
sealed class NullBlockStatement : BlockStatement
20
public override bool IsNull {
26
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
31
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
33
return other == null || other.IsNull;
38
#region PatternPlaceholder
39
public static implicit operator BlockStatement(PatternMatching.Pattern pattern)
41
return pattern != null ? new PatternPlaceholder(pattern) : null;
44
sealed class PatternPlaceholder : BlockStatement, PatternMatching.INode
46
readonly PatternMatching.Pattern child;
48
public PatternPlaceholder(PatternMatching.Pattern child)
53
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
55
return visitor.VisitPatternPlaceholder(this, child, data);
58
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
60
return child.DoMatch(other, match);
63
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
65
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
70
public AstNodeCollection<Statement> Statements {
71
get { return GetChildrenByRole (StatementRole); }
74
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
76
return visitor.VisitBlockStatement (this, data);
79
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
81
BlockStatement o = other as BlockStatement;
82
return o != null && !(o is CatchBlock) && !o.IsNull && this.Statements.DoMatch(o.Statements, match);
85
#region Builder methods
86
public void Add(Statement statement)
88
AddChild(statement, StatementRole);
91
public void Add(Expression expression)
93
AddChild(new ExpressionStatement { Expression = expression }, StatementRole);
96
public void AddRange(IEnumerable<Statement> statements)
98
foreach (Statement st in statements)
99
AddChild(st, StatementRole);
102
public void AddAssignment(Expression left, Expression right)
104
Add(new AssignmentExpression(left, AssignmentOperatorType.Assign, right));
107
public void AddReturnStatement(Expression expression)
109
Add(new ReturnStatement { Expression = expression });
113
IEnumerator<Statement> IEnumerable<Statement>.GetEnumerator()
115
return this.Statements.GetEnumerator();
118
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
120
return this.Statements.GetEnumerator();