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

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory.CSharp/Ast/Statements/Statement.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
 
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
 
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
3
 
 
4
 
using System;
5
 
 
6
 
namespace ICSharpCode.NRefactory.CSharp
7
 
{
8
 
        /// <summary>
9
 
        /// Base class for statements.
10
 
        /// </summary>
11
 
        /// <remarks>
12
 
        /// This class is useful even though it doesn't provide any additional functionality:
13
 
        /// It can be used to communicate more information in APIs, e.g. "this subnode will always be a statement"
14
 
        /// </remarks>
15
 
        public abstract class Statement : AstNode
16
 
        {
17
 
                #region Null
18
 
                public new static readonly Statement Null = new NullStatement ();
19
 
                
20
 
                sealed class NullStatement : Statement
21
 
                {
22
 
                        public override bool IsNull {
23
 
                                get {
24
 
                                        return true;
25
 
                                }
26
 
                        }
27
 
                        
28
 
                        public override void AcceptVisitor (IAstVisitor visitor)
29
 
                        {
30
 
                        }
31
 
                                
32
 
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
33
 
                        {
34
 
                                return default (T);
35
 
                        }
36
 
 
37
 
                        public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
38
 
                        {
39
 
                                return default (S);
40
 
                        }
41
 
                        
42
 
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
43
 
                        {
44
 
                                return other == null || other.IsNull;
45
 
                        }
46
 
                }
47
 
                #endregion
48
 
                
49
 
                #region PatternPlaceholder
50
 
                public static implicit operator Statement(PatternMatching.Pattern pattern)
51
 
                {
52
 
                        return pattern != null ? new PatternPlaceholder(pattern) : null;
53
 
                }
54
 
                
55
 
                sealed class PatternPlaceholder : Statement, PatternMatching.INode
56
 
                {
57
 
                        readonly PatternMatching.Pattern child;
58
 
                        
59
 
                        public PatternPlaceholder(PatternMatching.Pattern child)
60
 
                        {
61
 
                                this.child = child;
62
 
                        }
63
 
                        
64
 
                        public override NodeType NodeType {
65
 
                                get { return NodeType.Pattern; }
66
 
                        }
67
 
                        
68
 
                        public override void AcceptVisitor (IAstVisitor visitor)
69
 
                        {
70
 
                                visitor.VisitPatternPlaceholder(this, child);
71
 
                        }
72
 
                                
73
 
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
74
 
                        {
75
 
                                return visitor.VisitPatternPlaceholder(this, child);
76
 
                        }
77
 
 
78
 
                        public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
79
 
                        {
80
 
                                return visitor.VisitPatternPlaceholder(this, child, data);
81
 
                        }
82
 
                        
83
 
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
84
 
                        {
85
 
                                return child.DoMatch(other, match);
86
 
                        }
87
 
                        
88
 
                        bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
89
 
                        {
90
 
                                return child.DoMatchCollection(role, pos, match, backtrackingInfo);
91
 
                        }
92
 
                }
93
 
                #endregion
94
 
                
95
 
                public new Statement Clone()
96
 
                {
97
 
                        return (Statement)base.Clone();
98
 
                }
99
 
                
100
 
                public Statement ReplaceWith(Func<Statement, Statement> replaceFunction)
101
 
                {
102
 
                        if (replaceFunction == null)
103
 
                                throw new ArgumentNullException("replaceFunction");
104
 
                        return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node));
105
 
                }
106
 
                
107
 
                public override NodeType NodeType {
108
 
                        get { return NodeType.Statement; }
109
 
                }
110
 
                
111
 
                // Make debugging easier by giving Statements a ToString() implementation
112
 
                public override string ToString()
113
 
                {
114
 
                        return DebugToString();
115
 
                }
116
 
        }
117
 
}