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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.CSharp/Ast/Statements/TryCatchStatement.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
// TryCatchStatement.cs
 
3
//
 
4
// Author:
 
5
//       Mike Krüger <mkrueger@novell.com>
 
6
// 
 
7
// Copyright (c) 2009 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
using System.Linq;
 
29
 
 
30
namespace ICSharpCode.NRefactory.CSharp
 
31
{
 
32
        /// <summary>
 
33
        /// try TryBlock CatchClauses finally FinallyBlock
 
34
        /// </summary>
 
35
        public class TryCatchStatement : Statement
 
36
        {
 
37
                public static readonly TokenRole TryKeywordRole = new TokenRole ("try");
 
38
                public static readonly Role<BlockStatement> TryBlockRole = new Role<BlockStatement>("TryBlock", BlockStatement.Null);
 
39
                public static readonly Role<CatchClause> CatchClauseRole = new Role<CatchClause>("CatchClause", CatchClause.Null);
 
40
                public static readonly TokenRole FinallyKeywordRole = new TokenRole ("finally");
 
41
                public static readonly Role<BlockStatement> FinallyBlockRole = new Role<BlockStatement>("FinallyBlock", BlockStatement.Null);
 
42
                
 
43
                public CSharpTokenNode TryToken {
 
44
                        get { return GetChildByRole (TryKeywordRole); }
 
45
                }
 
46
                
 
47
                public BlockStatement TryBlock {
 
48
                        get { return GetChildByRole (TryBlockRole); }
 
49
                        set { SetChildByRole (TryBlockRole, value); }
 
50
                }
 
51
                
 
52
                public AstNodeCollection<CatchClause> CatchClauses {
 
53
                        get { return GetChildrenByRole (CatchClauseRole); }
 
54
                }
 
55
                
 
56
                public CSharpTokenNode FinallyToken {
 
57
                        get { return GetChildByRole (FinallyKeywordRole); }
 
58
                }
 
59
                
 
60
                public BlockStatement FinallyBlock {
 
61
                        get { return GetChildByRole (FinallyBlockRole); }
 
62
                        set { SetChildByRole (FinallyBlockRole, value); }
 
63
                }
 
64
                
 
65
                public override void AcceptVisitor (IAstVisitor visitor)
 
66
                {
 
67
                        visitor.VisitTryCatchStatement (this);
 
68
                }
 
69
                        
 
70
                public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
71
                {
 
72
                        return visitor.VisitTryCatchStatement (this);
 
73
                }
 
74
                
 
75
                public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
76
                {
 
77
                        return visitor.VisitTryCatchStatement (this, data);
 
78
                }
 
79
                
 
80
                protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
81
                {
 
82
                        TryCatchStatement o = other as TryCatchStatement;
 
83
                        return o != null && this.TryBlock.DoMatch(o.TryBlock, match) && this.CatchClauses.DoMatch(o.CatchClauses, match) && this.FinallyBlock.DoMatch(o.FinallyBlock, match);
 
84
                }
 
85
        }
 
86
        
 
87
        /// <summary>
 
88
        /// catch (Type VariableName) { Body }
 
89
        /// </summary>
 
90
        public class CatchClause : AstNode
 
91
        {
 
92
                public static readonly TokenRole CatchKeywordRole = new TokenRole ("catch");
 
93
 
 
94
                #region Null
 
95
                public new static readonly CatchClause Null = new NullCatchClause ();
 
96
                
 
97
                sealed class NullCatchClause : CatchClause
 
98
                {
 
99
                        public override bool IsNull {
 
100
                                get {
 
101
                                        return true;
 
102
                                }
 
103
                        }
 
104
                        
 
105
                        public override void AcceptVisitor (IAstVisitor visitor)
 
106
                        {
 
107
                        }
 
108
                        
 
109
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
110
                        {
 
111
                                return default (T);
 
112
                        }
 
113
                        
 
114
                        public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
115
                        {
 
116
                                return default (S);
 
117
                        }
 
118
                        
 
119
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
120
                        {
 
121
                                return other == null || other.IsNull;
 
122
                        }
 
123
                }
 
124
                #endregion
 
125
 
 
126
                #region PatternPlaceholder
 
127
                public static implicit operator CatchClause(PatternMatching.Pattern pattern)
 
128
                {
 
129
                        return pattern != null ? new PatternPlaceholder(pattern) : null;
 
130
                }
 
131
                
 
132
                sealed class PatternPlaceholder : CatchClause, PatternMatching.INode
 
133
                {
 
134
                        readonly PatternMatching.Pattern child;
 
135
                        
 
136
                        public PatternPlaceholder(PatternMatching.Pattern child)
 
137
                        {
 
138
                                this.child = child;
 
139
                        }
 
140
                        
 
141
                        public override NodeType NodeType {
 
142
                                get { return NodeType.Pattern; }
 
143
                        }
 
144
                        
 
145
                        public override void AcceptVisitor (IAstVisitor visitor)
 
146
                        {
 
147
                                visitor.VisitPatternPlaceholder(this, child);
 
148
                        }
 
149
                                
 
150
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
151
                        {
 
152
                                return visitor.VisitPatternPlaceholder(this, child);
 
153
                        }
 
154
 
 
155
                        public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
 
156
                        {
 
157
                                return visitor.VisitPatternPlaceholder(this, child, data);
 
158
                        }
 
159
                        
 
160
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
161
                        {
 
162
                                return child.DoMatch(other, match);
 
163
                        }
 
164
                        
 
165
                        bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
 
166
                        {
 
167
                                return child.DoMatchCollection(role, pos, match, backtrackingInfo);
 
168
                        }
 
169
                }
 
170
                #endregion
 
171
                
 
172
                public override NodeType NodeType {
 
173
                        get {
 
174
                                return NodeType.Unknown;
 
175
                        }
 
176
                }
 
177
                
 
178
                public CSharpTokenNode CatchToken {
 
179
                        get { return GetChildByRole (CatchKeywordRole); }
 
180
                }
 
181
                
 
182
                public CSharpTokenNode LParToken {
 
183
                        get { return GetChildByRole (Roles.LPar); }
 
184
                }
 
185
                
 
186
                public AstType Type {
 
187
                        get { return GetChildByRole (Roles.Type); }
 
188
                        set { SetChildByRole (Roles.Type, value); }
 
189
                }
 
190
                
 
191
                public string VariableName {
 
192
                        get { return GetChildByRole (Roles.Identifier).Name; }
 
193
                        set {
 
194
                                if (string.IsNullOrEmpty(value))
 
195
                                        SetChildByRole (Roles.Identifier, null);
 
196
                                else
 
197
                                        SetChildByRole (Roles.Identifier, Identifier.Create (value));
 
198
                        }
 
199
                }
 
200
                
 
201
                public Identifier VariableNameToken {
 
202
                        get {
 
203
                                return GetChildByRole (Roles.Identifier);
 
204
                        }
 
205
                        set {
 
206
                                SetChildByRole(Roles.Identifier, value);
 
207
                        }
 
208
                }
 
209
                
 
210
                public CSharpTokenNode RParToken {
 
211
                        get { return GetChildByRole (Roles.RPar); }
 
212
                }
 
213
                
 
214
                public BlockStatement Body {
 
215
                        get { return GetChildByRole (Roles.Body); }
 
216
                        set { SetChildByRole (Roles.Body, value); }
 
217
                }
 
218
                
 
219
                public override void AcceptVisitor (IAstVisitor visitor)
 
220
                {
 
221
                        visitor.VisitCatchClause (this);
 
222
                }
 
223
                        
 
224
                public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
 
225
                {
 
226
                        return visitor.VisitCatchClause (this);
 
227
                }
 
228
                
 
229
                public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
 
230
                {
 
231
                        return visitor.VisitCatchClause (this, data);
 
232
                }
 
233
                
 
234
                protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 
235
                {
 
236
                        CatchClause o = other as CatchClause;
 
237
                        return o != null && this.Type.DoMatch(o.Type, match) && MatchString(this.VariableName, o.VariableName) && this.Body.DoMatch(o.Body, match);
 
238
                }
 
239
        }
 
240
}