~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.VB/Ast/Expressions/LambdaExpression.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using System.Linq;
 
7
 
 
8
namespace 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
}