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/Statement.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.0 KB
Line 
1// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20
21namespace ICSharpCode.NRefactory.CSharp
22{
23  /// <summary>
24  /// Base class for statements.
25  /// </summary>
26  /// <remarks>
27  /// This class is useful even though it doesn't provide any additional functionality:
28  /// It can be used to communicate more information in APIs, e.g. "this subnode will always be a statement"
29  /// </remarks>
30  public abstract class Statement : AstNode
31  {
32    #region Null
33    public new static readonly Statement Null = new NullStatement ();
34   
35    sealed class NullStatement : Statement
36    {
37      public override bool IsNull {
38        get {
39          return true;
40        }
41      }
42     
43      public override void AcceptVisitor (IAstVisitor visitor)
44      {
45        visitor.VisitNullNode(this);
46      }
47     
48      public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
49      {
50        return visitor.VisitNullNode(this);
51      }
52     
53      public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
54      {
55        return visitor.VisitNullNode(this, data);
56      }
57     
58      protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
59      {
60        return other == null || other.IsNull;
61      }
62    }
63    #endregion
64   
65    #region PatternPlaceholder
66    public static implicit operator Statement(PatternMatching.Pattern pattern)
67    {
68      return pattern != null ? new PatternPlaceholder(pattern) : null;
69    }
70   
71    sealed class PatternPlaceholder : Statement, PatternMatching.INode
72    {
73      readonly PatternMatching.Pattern child;
74     
75      public PatternPlaceholder(PatternMatching.Pattern child)
76      {
77        this.child = child;
78      }
79     
80      public override NodeType NodeType {
81        get { return NodeType.Pattern; }
82      }
83     
84      public override void AcceptVisitor (IAstVisitor visitor)
85      {
86        visitor.VisitPatternPlaceholder(this, child);
87      }
88       
89      public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
90      {
91        return visitor.VisitPatternPlaceholder(this, child);
92      }
93
94      public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
95      {
96        return visitor.VisitPatternPlaceholder(this, child, data);
97      }
98     
99      protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
100      {
101        return child.DoMatch(other, match);
102      }
103     
104      bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
105      {
106        return child.DoMatchCollection(role, pos, match, backtrackingInfo);
107      }
108    }
109    #endregion
110   
111    public new Statement Clone()
112    {
113      return (Statement)base.Clone();
114    }
115   
116    public Statement ReplaceWith(Func<Statement, Statement> replaceFunction)
117    {
118      if (replaceFunction == null)
119        throw new ArgumentNullException("replaceFunction");
120      return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node));
121    }
122   
123    public override NodeType NodeType {
124      get { return NodeType.Statement; }
125    }
126
127    public static implicit operator Statement (Expression type)
128    {
129      return new ExpressionStatement(type);
130    }
131  }
132}
Note: See TracBrowser for help on using the repository browser.