PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/NRefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs

http://github.com/icsharpcode/ILSpy
C# | 124 lines | 100 code | 19 blank | 5 comment | 10 complexity | 12a0bf52d4cfb72c4a6f3a611e255da2 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;
  6using System.Linq;
  7
  8namespace ICSharpCode.NRefactory.VB.Ast
  9{
 10	public abstract class LambdaExpression : Expression
 11	{
 12		public static readonly Role<VBModifierToken> ModifierRole = AttributedNode.ModifierRole;
 13		
 14		public LambdaExpressionModifiers Modifiers {
 15			get { return GetModifiers(this); }
 16			set { SetModifiers(this, value); }
 17		}
 18		
 19		public AstNodeCollection<VBModifierToken> ModifierTokens {
 20			get { return GetChildrenByRole (ModifierRole); }
 21		}
 22		
 23		internal static LambdaExpressionModifiers GetModifiers(AstNode node)
 24		{
 25			LambdaExpressionModifiers m = 0;
 26			foreach (VBModifierToken t in node.GetChildrenByRole (ModifierRole)) {
 27				m |= (LambdaExpressionModifiers)t.Modifier;
 28			}
 29			return m;
 30		}
 31		
 32		internal static void SetModifiers(AstNode node, LambdaExpressionModifiers newValue)
 33		{
 34			LambdaExpressionModifiers oldValue = GetModifiers(node);
 35			AstNode insertionPos = null;
 36			foreach (Modifiers m in VBModifierToken.AllModifiers) {
 37				if ((m & (Modifiers)newValue) != 0) {
 38					if ((m & (Modifiers)oldValue) == 0) {
 39						// Modifier was added
 40						var newToken = new VBModifierToken(TextLocation.Empty, m);
 41						node.InsertChildAfter(insertionPos, newToken, ModifierRole);
 42						insertionPos = newToken;
 43					} else {
 44						// Modifier already exists
 45						insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m);
 46					}
 47				} else {
 48					if ((m & (Modifiers)oldValue) != 0) {
 49						// Modifier was removed
 50						node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove();
 51					}
 52				}
 53			}
 54		}
 55		
 56		public AstNodeCollection<ParameterDeclaration> Parameters {
 57			get { return GetChildrenByRole(Roles.Parameter); }
 58		}
 59	}
 60	
 61	public class SingleLineSubLambdaExpression : LambdaExpression
 62	{
 63		public static readonly Role<Statement> StatementRole = BlockStatement.StatementRole;
 64		
 65		public Statement EmbeddedStatement {
 66			get { return GetChildByRole(StatementRole); }
 67			set { SetChildByRole(StatementRole, value); }
 68		}
 69		
 70		protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
 71		{
 72			throw new NotImplementedException();
 73		}
 74		
 75		public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
 76		{
 77			return visitor.VisitSingleLineSubLambdaExpression(this, data);
 78		}
 79	}
 80	
 81	public class SingleLineFunctionLambdaExpression : LambdaExpression
 82	{
 83		public Expression EmbeddedExpression {
 84			get { return GetChildByRole(Roles.Expression); }
 85			set { SetChildByRole(Roles.Expression, value); }
 86		}
 87		
 88		protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
 89		{
 90			throw new NotImplementedException();
 91		}
 92		
 93		public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
 94		{
 95			return visitor.VisitSingleLineFunctionLambdaExpression(this, data);
 96		}
 97	}
 98	
 99	public class MultiLineLambdaExpression : LambdaExpression
100	{
101		public bool IsSub { get; set; }
102		
103		public BlockStatement Body {
104			get { return GetChildByRole(Roles.Body); }
105			set { SetChildByRole(Roles.Body, value); }
106		}
107		
108		protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
109		{
110			throw new NotImplementedException();
111		}
112		
113		public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
114		{
115			return visitor.VisitMultiLineLambdaExpression(this, data);
116		}
117	}
118	
119	public enum LambdaExpressionModifiers
120	{
121		Async = Modifiers.Async,
122		Iterator = Modifiers.Iterator
123	}
124}