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

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory.CSharp/Ast/AstType.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
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
 
 
19
 
using System;
20
 
using System.Collections.Generic;
21
 
using ICSharpCode.NRefactory.CSharp.Resolver;
22
 
using ICSharpCode.NRefactory.TypeSystem;
23
 
 
24
 
namespace ICSharpCode.NRefactory.CSharp
25
 
{
26
 
        /// <summary>
27
 
        /// A type reference in the C# AST.
28
 
        /// </summary>
29
 
        public abstract class AstType : AstNode
30
 
        {
31
 
                #region Null
32
 
                public new static readonly AstType Null = new NullAstType ();
33
 
                
34
 
                sealed class NullAstType : AstType
35
 
                {
36
 
                        public override bool IsNull {
37
 
                                get {
38
 
                                        return true;
39
 
                                }
40
 
                        }
41
 
                        
42
 
                        public override void AcceptVisitor (IAstVisitor visitor)
43
 
                        {
44
 
                        }
45
 
                        
46
 
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
47
 
                        {
48
 
                                return default (T);
49
 
                        }
50
 
                        
51
 
                        public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
52
 
                        {
53
 
                                return default (S);
54
 
                        }
55
 
                        
56
 
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
57
 
                        {
58
 
                                return other == null || other.IsNull;
59
 
                        }
60
 
                        
61
 
                        public override ITypeReference ToTypeReference(NameLookupMode lookupMode)
62
 
                        {
63
 
                                return SpecialType.UnknownType;
64
 
                        }
65
 
                }
66
 
                #endregion
67
 
                
68
 
                #region PatternPlaceholder
69
 
                public static implicit operator AstType(PatternMatching.Pattern pattern)
70
 
                {
71
 
                        return pattern != null ? new PatternPlaceholder(pattern) : null;
72
 
                }
73
 
                
74
 
                sealed class PatternPlaceholder : AstType, PatternMatching.INode
75
 
                {
76
 
                        readonly PatternMatching.Pattern child;
77
 
                        
78
 
                        public PatternPlaceholder(PatternMatching.Pattern child)
79
 
                        {
80
 
                                this.child = child;
81
 
                        }
82
 
                        
83
 
                        public override NodeType NodeType {
84
 
                                get { return NodeType.Pattern; }
85
 
                        }
86
 
                        
87
 
                        public override void AcceptVisitor (IAstVisitor visitor)
88
 
                        {
89
 
                                visitor.VisitPatternPlaceholder (this, child);
90
 
                        }
91
 
                        
92
 
                        public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
93
 
                        {
94
 
                                return visitor.VisitPatternPlaceholder (this, child);
95
 
                        }
96
 
                        
97
 
                        public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
98
 
                        {
99
 
                                return visitor.VisitPatternPlaceholder (this, child, data);
100
 
                        }
101
 
                        
102
 
                        public override ITypeReference ToTypeReference(NameLookupMode lookupMode)
103
 
                        {
104
 
                                throw new NotSupportedException();
105
 
                        }
106
 
                        
107
 
                        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
108
 
                        {
109
 
                                return child.DoMatch(other, match);
110
 
                        }
111
 
                        
112
 
                        bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
113
 
                        {
114
 
                                return child.DoMatchCollection(role, pos, match, backtrackingInfo);
115
 
                        }
116
 
                }
117
 
                #endregion
118
 
                
119
 
                public override NodeType NodeType {
120
 
                        get { return NodeType.TypeReference; }
121
 
                }
122
 
                
123
 
                public new AstType Clone()
124
 
                {
125
 
                        return (AstType)base.Clone();
126
 
                }
127
 
                
128
 
                /// <summary>
129
 
                /// Create an ITypeReference for this AstType.
130
 
                /// </summary>
131
 
                /// <remarks>
132
 
                /// The resulting type reference will read the context information from the
133
 
                /// <see cref="ITypeResolveContext"/>:
134
 
                /// For resolving type parameters, the CurrentTypeDefinition/CurrentMember is used.
135
 
                /// For resolving simple names, the current namespace and usings from the CurrentUsingScope
136
 
                /// (on CSharpTypeResolveContext only) is used.
137
 
                /// </remarks>
138
 
                public abstract ITypeReference ToTypeReference(NameLookupMode lookupMode = NameLookupMode.Type);
139
 
                
140
 
                /// <summary>
141
 
                /// Creates a pointer type from this type by nesting it in a <see cref="ComposedType"/>.
142
 
                /// If this type already is a pointer type, this method just increases the PointerRank of the existing pointer type.
143
 
                /// </summary>
144
 
                public virtual AstType MakePointerType()
145
 
                {
146
 
                        return new ComposedType { BaseType = this }.MakePointerType();
147
 
                }
148
 
                
149
 
                /// <summary>
150
 
                /// Creates an array type from this type by nesting it in a <see cref="ComposedType"/>.
151
 
                /// If this type already is an array type, the additional rank is prepended to the existing array specifier list.
152
 
                /// Thus, <c>new SimpleType("T").MakeArrayType(1).MakeArrayType(2)</c> will result in "T[,][]".
153
 
                /// </summary>
154
 
                public virtual AstType MakeArrayType(int rank = 1)
155
 
                {
156
 
                        return new ComposedType { BaseType = this }.MakeArrayType(rank);
157
 
                }
158
 
                
159
 
                /// <summary>
160
 
                /// Creates a nullable type from this type by nesting it in a <see cref="ComposedType"/>.
161
 
                /// </summary>
162
 
                public AstType MakeNullableType()
163
 
                {
164
 
                        return new ComposedType { BaseType = this, HasNullableSpecifier = true };
165
 
                }
166
 
                
167
 
                /// <summary>
168
 
                /// Builds an expression that can be used to access a static member on this type.
169
 
                /// </summary>
170
 
                public MemberReferenceExpression Member(string memberName)
171
 
                {
172
 
                        return new TypeReferenceExpression { Type = this }.Member(memberName);
173
 
                }
174
 
                
175
 
                /// <summary>
176
 
                /// Builds an expression that can be used to access a static member on this type.
177
 
                /// </summary>
178
 
                public MemberType MemberType(string memberName, params AstType[] typeArguments)
179
 
                {
180
 
                        var memberType = new MemberType(this, memberName);
181
 
                        memberType.TypeArguments.AddRange(typeArguments);
182
 
                        return memberType;
183
 
                }
184
 
                
185
 
                /// <summary>
186
 
                /// Builds an expression that can be used to access a static member on this type.
187
 
                /// </summary>
188
 
                public MemberType MemberType(string memberName, IEnumerable<AstType> typeArguments)
189
 
                {
190
 
                        var memberType = new MemberType(this, memberName);
191
 
                        memberType.TypeArguments.AddRange(typeArguments);
192
 
                        return memberType;
193
 
                }
194
 
                
195
 
                /// <summary>
196
 
                /// Builds an invocation expression using this type as target.
197
 
                /// </summary>
198
 
                public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments)
199
 
                {
200
 
                        return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
201
 
                }
202
 
                
203
 
                /// <summary>
204
 
                /// Builds an invocation expression using this type as target.
205
 
                /// </summary>
206
 
                public InvocationExpression Invoke(string methodName, params Expression[] arguments)
207
 
                {
208
 
                        return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments);
209
 
                }
210
 
                
211
 
                /// <summary>
212
 
                /// Builds an invocation expression using this type as target.
213
 
                /// </summary>
214
 
                public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments)
215
 
                {
216
 
                        return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments);
217
 
                }
218
 
        }
219
 
}