Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RemoveBackwardsCompatibility/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/Statements/BlockStatement.cs

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

#2077: created branch and added first version

File size: 4.7 KB
Line 
1//
2// BlockStatement.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
27using System.Collections.Generic;
28
29namespace ICSharpCode.NRefactory.CSharp
30{
31  /// <summary>
32  /// { Statements }
33  /// </summary>
34  public class BlockStatement : Statement, IEnumerable<Statement>
35  {
36    public static readonly Role<Statement> StatementRole = new Role<Statement>("Statement", Statement.Null);
37   
38    #region Null
39    public static readonly new BlockStatement Null = new NullBlockStatement ();
40    sealed class NullBlockStatement : BlockStatement
41    {
42      public override bool IsNull {
43        get {
44          return true;
45        }
46      }
47     
48      public override void AcceptVisitor (IAstVisitor visitor)
49      {
50        visitor.VisitNullNode(this);
51      }
52     
53      public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
54      {
55        return visitor.VisitNullNode(this);
56      }
57     
58      public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
59      {
60        return visitor.VisitNullNode(this, data);
61      }
62     
63      protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
64      {
65        return other == null || other.IsNull;
66      }
67    }
68    #endregion
69   
70    #region PatternPlaceholder
71    public static implicit operator BlockStatement(PatternMatching.Pattern pattern)
72    {
73      return pattern != null ? new PatternPlaceholder(pattern) : null;
74    }
75   
76    sealed class PatternPlaceholder : BlockStatement, PatternMatching.INode
77    {
78      readonly PatternMatching.Pattern child;
79     
80      public PatternPlaceholder(PatternMatching.Pattern child)
81      {
82        this.child = child;
83      }
84     
85      public override NodeType NodeType {
86        get { return NodeType.Pattern; }
87      }
88     
89      public override void AcceptVisitor (IAstVisitor visitor)
90      {
91        visitor.VisitPatternPlaceholder(this, child);
92      }
93       
94      public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
95      {
96        return visitor.VisitPatternPlaceholder(this, child);
97      }
98     
99      public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
100      {
101        return visitor.VisitPatternPlaceholder(this, child, data);
102      }
103     
104      protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
105      {
106        return child.DoMatch(other, match);
107      }
108     
109      bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
110      {
111        return child.DoMatchCollection(role, pos, match, backtrackingInfo);
112      }
113    }
114    #endregion
115   
116    public CSharpTokenNode LBraceToken {
117      get { return GetChildByRole (Roles.LBrace); }
118    }
119   
120    public AstNodeCollection<Statement> Statements {
121      get { return GetChildrenByRole (StatementRole); }
122    }
123   
124    public CSharpTokenNode RBraceToken {
125      get { return GetChildByRole (Roles.RBrace); }
126    }
127   
128    public override void AcceptVisitor (IAstVisitor visitor)
129    {
130      visitor.VisitBlockStatement (this);
131    }
132     
133    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
134    {
135      return visitor.VisitBlockStatement (this);
136    }
137   
138    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
139    {
140      return visitor.VisitBlockStatement (this, data);
141    }
142   
143    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
144    {
145      BlockStatement o = other as BlockStatement;
146      return o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match);
147    }
148   
149    public void Add(Statement statement)
150    {
151      AddChild(statement, StatementRole);
152    }
153   
154    IEnumerator<Statement> IEnumerable<Statement>.GetEnumerator()
155    {
156      return this.Statements.GetEnumerator();
157    }
158   
159    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
160    {
161      return this.Statements.GetEnumerator();
162    }
163  }
164}
Note: See TracBrowser for help on using the repository browser.