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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ArrayInitializerExpression.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
// 
 
2
// ArrayInitializerExpression.cs
 
3
//
 
4
// Author:
 
5
//       Mike Krüger <mkrueger@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System.Collections.Generic;
 
28
 
 
29
namespace ICSharpCode.NRefactory.CSharp
 
30
{
 
31
        /// <summary>
 
32
        /// { Elements }
 
33
        /// </summary>
 
34
        public class ArrayInitializerExpression : Expression
 
35
        {
 
36
                /// <summary>
 
37
                /// For ease of use purposes in the resolver the ast representation
 
38
                /// of { a, b, c }  is { {a}, {b}, {c} }.
 
39
                /// If IsSingleElement is true then this array initializer expression is a generated one.
 
40
                /// That has no meaning in the source code (and contains no brace tokens).
 
41
                /// </summary>
 
42
                public virtual bool IsSingleElement {
 
43
                        get {
 
44
                                return false;
 
45
                        }
 
46
                }
 
47
 
 
48
                public ArrayInitializerExpression()
 
49
                {
 
50
                }
 
51
                
 
52
                public ArrayInitializerExpression(IEnumerable<Expression> elements)
 
53
                {
 
54
                        this.Elements.AddRange(elements);
 
55
                }
 
56
                
 
57
                public ArrayInitializerExpression(params Expression[] elements)
 
58
                {
 
59
                        this.Elements.AddRange(elements);
 
60
                }
 
61
                
 
62
                #region Null
 
63
                public new static readonly ArrayInitializerExpression Null = new NullArrayInitializerExpression ();
 
64
                
 
65
                sealed class NullArrayInitializerExpression : ArrayInitializerExpression
 
66
                {
 
67
                        public override bool IsNull {
 
68
                                get {
 
69
                                        return true;
 
70
                                }
 
71
                        }
 
72
                        
 
73
                        public override void AcceptVisitor (IAstVisitor visitor)
 
74
                        {
 
75
                        }
 
76
                        
 
77
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
78
                        {
 
79
                                return default (T);
 
80
                        }
 
81
                        
 
82
                        public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
83
                        {
 
84
                                return default (S);
 
85
                        }
 
86
                        
 
87
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
88
                        {
 
89
                                return other == null || other.IsNull;
 
90
                        }
 
91
                }
 
92
                #endregion
 
93
                
 
94
                public CSharpTokenNode LBraceToken {
 
95
                        get { return GetChildByRole (Roles.LBrace); }
 
96
                }
 
97
                
 
98
                public AstNodeCollection<Expression> Elements {
 
99
                        get { return GetChildrenByRole(Roles.Expression); }
 
100
                }
 
101
                
 
102
                public CSharpTokenNode RBraceToken {
 
103
                        get { return GetChildByRole (Roles.RBrace); }
 
104
                }
 
105
                
 
106
                public override void AcceptVisitor (IAstVisitor visitor)
 
107
                {
 
108
                        visitor.VisitArrayInitializerExpression (this);
 
109
                }
 
110
                
 
111
                public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
112
                {
 
113
                        return visitor.VisitArrayInitializerExpression (this);
 
114
                }
 
115
                
 
116
                public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
117
                {
 
118
                        return visitor.VisitArrayInitializerExpression (this, data);
 
119
                }
 
120
                
 
121
                protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
122
                {
 
123
                        ArrayInitializerExpression o = other as ArrayInitializerExpression;
 
124
                        return o != null && this.Elements.DoMatch(o.Elements, match);
 
125
                }
 
126
 
 
127
                public static ArrayInitializerExpression CreateSingleElementInitializer ()
 
128
                {
 
129
                        return new SingleArrayInitializerExpression();
 
130
                }
 
131
                /// <summary>
 
132
                /// Single elements in array initializers are represented with this special class.
 
133
                /// </summary>
 
134
                class SingleArrayInitializerExpression : ArrayInitializerExpression
 
135
                {
 
136
                        public override bool IsSingleElement {
 
137
                                get {
 
138
                                        return true;
 
139
                                }
 
140
                        }
 
141
                        
 
142
                }
 
143
                
 
144
                #region PatternPlaceholder
 
145
                public static implicit operator ArrayInitializerExpression(PatternMatching.Pattern pattern)
 
146
                {
 
147
                        return pattern != null ? new PatternPlaceholder(pattern) : null;
 
148
                }
 
149
                
 
150
                sealed class PatternPlaceholder : ArrayInitializerExpression, PatternMatching.INode
 
151
                {
 
152
                        readonly PatternMatching.Pattern child;
 
153
                        
 
154
                        public PatternPlaceholder(PatternMatching.Pattern child)
 
155
                        {
 
156
                                this.child = child;
 
157
                        }
 
158
                        
 
159
                        public override NodeType NodeType {
 
160
                                get { return NodeType.Pattern; }
 
161
                        }
 
162
                        
 
163
                        public override void AcceptVisitor (IAstVisitor visitor)
 
164
                        {
 
165
                                visitor.VisitPatternPlaceholder(this, child);
 
166
                        }
 
167
                        
 
168
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
169
                        {
 
170
                                return visitor.VisitPatternPlaceholder(this, child);
 
171
                        }
 
172
 
 
173
                        public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
 
174
                        {
 
175
                                return visitor.VisitPatternPlaceholder(this, child, data);
 
176
                        }
 
177
                        
 
178
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
179
                        {
 
180
                                return child.DoMatch(other, match);
 
181
                        }
 
182
                        
 
183
                        bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
 
184
                        {
 
185
                                return child.DoMatchCollection(role, pos, match, backtrackingInfo);
 
186
                        }
 
187
                }
 
188
                #endregion
 
189
        }
 
190
}
 
191