Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/Statements/GotoStatement.cs

Last change on this file was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 5.0 KB
Line 
1//
2// GotoStatement.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
27namespace ICSharpCode.NRefactory.CSharp
28{
29  /// <summary>
30  /// "goto Label;"
31  /// </summary>
32  public class GotoStatement : Statement
33  {
34    public static readonly TokenRole GotoKeywordRole = new TokenRole ("goto");
35   
36    public GotoStatement ()
37    {
38    }
39   
40    public GotoStatement (string label)
41    {
42      this.Label = label;
43    }
44   
45    public CSharpTokenNode GotoToken {
46      get { return GetChildByRole (GotoKeywordRole); }
47    }
48   
49    public string Label {
50      get {
51        return GetChildByRole (Roles.Identifier).Name;
52      }
53      set {
54        if (string.IsNullOrEmpty(value))
55          SetChildByRole(Roles.Identifier, null);
56        else
57          SetChildByRole(Roles.Identifier, Identifier.Create (value));
58      }
59    }
60   
61    public CSharpTokenNode SemicolonToken {
62      get { return GetChildByRole (Roles.Semicolon); }
63    }
64   
65    public override void AcceptVisitor (IAstVisitor visitor)
66    {
67      visitor.VisitGotoStatement (this);
68    }
69     
70    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
71    {
72      return visitor.VisitGotoStatement (this);
73    }
74
75    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
76    {
77      return visitor.VisitGotoStatement (this, data);
78    }
79   
80    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
81    {
82      GotoStatement o = other as GotoStatement;
83      return o != null && MatchString(this.Label, o.Label);
84    }
85  }
86 
87  /// <summary>
88  /// or "goto case LabelExpression;"
89  /// </summary>
90  public class GotoCaseStatement : Statement
91  {
92    public static readonly TokenRole GotoKeywordRole = new TokenRole ("goto");
93    public static readonly TokenRole CaseKeywordRole = new TokenRole ("case");
94   
95    public CSharpTokenNode GotoToken {
96      get { return GetChildByRole (GotoKeywordRole); }
97    }
98   
99    public CSharpTokenNode CaseToken {
100      get { return GetChildByRole (CaseKeywordRole); }
101    }
102   
103    /// <summary>
104    /// Used for "goto case LabelExpression;"
105    /// </summary>
106    public Expression LabelExpression {
107      get { return GetChildByRole (Roles.Expression); }
108      set { SetChildByRole (Roles.Expression, value); }
109    }
110   
111    public CSharpTokenNode SemicolonToken {
112      get { return GetChildByRole (Roles.Semicolon); }
113    }
114   
115    public override void AcceptVisitor (IAstVisitor visitor)
116    {
117      visitor.VisitGotoCaseStatement (this);
118    }
119     
120    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
121    {
122      return visitor.VisitGotoCaseStatement (this);
123    }
124   
125    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
126    {
127      return visitor.VisitGotoCaseStatement (this, data);
128    }
129   
130    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
131    {
132      GotoCaseStatement o = other as GotoCaseStatement;
133      return o != null && this.LabelExpression.DoMatch(o.LabelExpression, match);
134    }
135  }
136 
137  /// <summary>
138  /// or "goto default;"
139  /// </summary>
140  public class GotoDefaultStatement : Statement
141  {
142    public static readonly TokenRole GotoKeywordRole = new TokenRole ("goto");
143    public static readonly TokenRole DefaultKeywordRole = new TokenRole ("default");
144   
145    public CSharpTokenNode GotoToken {
146      get { return GetChildByRole (GotoKeywordRole); }
147    }
148   
149    public CSharpTokenNode DefaultToken {
150      get { return GetChildByRole (DefaultKeywordRole); }
151    }
152   
153    public CSharpTokenNode SemicolonToken {
154      get { return GetChildByRole (Roles.Semicolon); }
155    }
156   
157    public override void AcceptVisitor (IAstVisitor visitor)
158    {
159      visitor.VisitGotoDefaultStatement (this);
160    }
161     
162    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
163    {
164      return visitor.VisitGotoDefaultStatement (this);
165    }
166   
167    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
168    {
169      return visitor.VisitGotoDefaultStatement (this, data);
170    }
171   
172    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
173    {
174      GotoDefaultStatement o = other as GotoDefaultStatement;
175      return o != null;
176    }
177  }
178}
Note: See TracBrowser for help on using the repository browser.