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;
8
namespace ICSharpCode.NRefactory.VB.Ast
10
public abstract class LambdaExpression : Expression
12
public static readonly Role<VBModifierToken> ModifierRole = AttributedNode.ModifierRole;
14
public LambdaExpressionModifiers Modifiers {
15
get { return GetModifiers(this); }
16
set { SetModifiers(this, value); }
19
public AstNodeCollection<VBModifierToken> ModifierTokens {
20
get { return GetChildrenByRole (ModifierRole); }
23
internal static LambdaExpressionModifiers GetModifiers(AstNode node)
25
LambdaExpressionModifiers m = 0;
26
foreach (VBModifierToken t in node.GetChildrenByRole (ModifierRole)) {
27
m |= (LambdaExpressionModifiers)t.Modifier;
32
internal static void SetModifiers(AstNode node, LambdaExpressionModifiers newValue)
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) {
40
var newToken = new VBModifierToken(TextLocation.Empty, m);
41
node.InsertChildAfter(insertionPos, newToken, ModifierRole);
42
insertionPos = newToken;
44
// Modifier already exists
45
insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m);
48
if ((m & (Modifiers)oldValue) != 0) {
49
// Modifier was removed
50
node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove();
56
public AstNodeCollection<ParameterDeclaration> Parameters {
57
get { return GetChildrenByRole(Roles.Parameter); }
61
public class SingleLineSubLambdaExpression : LambdaExpression
63
public static readonly Role<Statement> StatementRole = BlockStatement.StatementRole;
65
public Statement EmbeddedStatement {
66
get { return GetChildByRole(StatementRole); }
67
set { SetChildByRole(StatementRole, value); }
70
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
72
throw new NotImplementedException();
75
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
77
return visitor.VisitSingleLineSubLambdaExpression(this, data);
81
public class SingleLineFunctionLambdaExpression : LambdaExpression
83
public Expression EmbeddedExpression {
84
get { return GetChildByRole(Roles.Expression); }
85
set { SetChildByRole(Roles.Expression, value); }
88
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
90
throw new NotImplementedException();
93
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
95
return visitor.VisitSingleLineFunctionLambdaExpression(this, data);
99
public class MultiLineLambdaExpression : LambdaExpression
101
public bool IsSub { get; set; }
103
public BlockStatement Body {
104
get { return GetChildByRole(Roles.Body); }
105
set { SetChildByRole(Roles.Body, value); }
108
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
110
throw new NotImplementedException();
113
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
115
return visitor.VisitMultiLineLambdaExpression(this, data);
119
public enum LambdaExpressionModifiers
121
Async = Modifiers.Async,
122
Iterator = Modifiers.Iterator