PageRenderTime 55ms CodeModel.GetById 44ms app.highlight 4ms RepoModel.GetById 5ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.VB/Ast/Statements/BlockStatement.cs

http://github.com/icsharpcode/ILSpy
C# | 123 lines | 97 code | 21 blank | 5 comment | 7 complexity | bc967ec1e21d5ee4698da15f60692695 MD5 | raw file
  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)
  3
  4using System;
  5using System.Collections.Generic;
  6
  7namespace ICSharpCode.NRefactory.VB.Ast
  8{
  9	/// <summary>
 10	/// { Statements }
 11	/// </summary>
 12	public class BlockStatement : Statement, IEnumerable<Statement>
 13	{
 14		public static readonly Role<Statement> StatementRole = new Role<Statement>("Statement", Statement.Null);
 15		
 16		#region Null
 17		public static readonly new BlockStatement Null = new NullBlockStatement();
 18		sealed class NullBlockStatement : BlockStatement
 19		{
 20			public override bool IsNull {
 21				get {
 22					return true;
 23				}
 24			}
 25			
 26			public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 27			{
 28				return default(S);
 29			}
 30			
 31			protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 32			{
 33				return other == null || other.IsNull;
 34			}
 35		}
 36		#endregion
 37		
 38		#region PatternPlaceholder
 39		public static implicit operator BlockStatement(PatternMatching.Pattern pattern)
 40		{
 41			return pattern != null ? new PatternPlaceholder(pattern) : null;
 42		}
 43		
 44		sealed class PatternPlaceholder : BlockStatement, PatternMatching.INode
 45		{
 46			readonly PatternMatching.Pattern child;
 47			
 48			public PatternPlaceholder(PatternMatching.Pattern child)
 49			{
 50				this.child = child;
 51			}
 52			
 53			public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
 54			{
 55				return visitor.VisitPatternPlaceholder(this, child, data);
 56			}
 57			
 58			protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 59			{
 60				return child.DoMatch(other, match);
 61			}
 62			
 63			bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
 64			{
 65				return child.DoMatchCollection(role, pos, match, backtrackingInfo);
 66			}
 67		}
 68		#endregion
 69		
 70		public AstNodeCollection<Statement> Statements {
 71			get { return GetChildrenByRole (StatementRole); }
 72		}
 73		
 74		public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 75		{
 76			return visitor.VisitBlockStatement (this, data);
 77		}
 78		
 79		protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 80		{
 81			BlockStatement o = other as BlockStatement;
 82			return o != null && !(o is CatchBlock) && !o.IsNull && this.Statements.DoMatch(o.Statements, match);
 83		}
 84		
 85		#region Builder methods
 86		public void Add(Statement statement)
 87		{
 88			AddChild(statement, StatementRole);
 89		}
 90		
 91		public void Add(Expression expression)
 92		{
 93			AddChild(new ExpressionStatement { Expression = expression }, StatementRole);
 94		}
 95		
 96		public void AddRange(IEnumerable<Statement> statements)
 97		{
 98			foreach (Statement st in statements)
 99				AddChild(st, StatementRole);
100		}
101		
102		public void AddAssignment(Expression left, Expression right)
103		{
104			Add(new AssignmentExpression(left, AssignmentOperatorType.Assign, right));
105		}
106		
107		public void AddReturnStatement(Expression expression)
108		{
109			Add(new ReturnStatement { Expression = expression });
110		}
111		#endregion
112		
113		IEnumerator<Statement> IEnumerable<Statement>.GetEnumerator()
114		{
115			return this.Statements.GetEnumerator();
116		}
117		
118		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
119		{
120			return this.Statements.GetEnumerator();
121		}
122	}
123}