1
ļ»æ// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
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:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
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.
20
using System.Collections.Generic;
21
using System.Globalization;
23
using ICSharpCode.NRefactory.Utils;
25
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
28
/// Default implementation of <see cref="IUnresolvedTypeParameter"/>.
31
public class DefaultUnresolvedTypeParameter : IUnresolvedTypeParameter, IFreezable
34
IList<IUnresolvedAttribute> attributes;
35
IList<ITypeReference> constraints;
40
VarianceModifier variance;
42
const ushort FlagFrozen = 0x0001;
43
const ushort FlagReferenceTypeConstraint = 0x0002;
44
const ushort FlagValueTypeConstraint = 0x0004;
45
const ushort FlagDefaultConstructorConstraint = 0x0008;
49
if (!flags[FlagFrozen]) {
51
flags[FlagFrozen] = true;
55
protected virtual void FreezeInternal()
57
attributes = FreezableHelper.FreezeListAndElements(attributes);
60
public DefaultUnresolvedTypeParameter(EntityType ownerType, int index, string name = null)
62
this.ownerType = ownerType;
64
this.name = name ?? ((ownerType == EntityType.Method ? "!!" : "!") + index.ToString(CultureInfo.InvariantCulture));
67
public EntityType OwnerType {
68
get { return ownerType; }
75
public bool IsFrozen {
76
get { return flags[FlagFrozen]; }
82
FreezableHelper.ThrowIfFrozen(this);
87
string INamedElement.FullName {
91
string INamedElement.Namespace {
92
get { return string.Empty; }
95
string INamedElement.ReflectionName {
97
if (ownerType == EntityType.Method)
98
return "``" + index.ToString(CultureInfo.InvariantCulture);
100
return "`" + index.ToString(CultureInfo.InvariantCulture);
104
public IList<IUnresolvedAttribute> Attributes {
106
if (attributes == null)
107
attributes = new List<IUnresolvedAttribute>();
112
public IList<ITypeReference> Constraints {
114
if (constraints == null)
115
constraints = new List<ITypeReference>();
120
public VarianceModifier Variance {
121
get { return variance; }
123
FreezableHelper.ThrowIfFrozen(this);
128
public DomRegion Region {
129
get { return region; }
131
FreezableHelper.ThrowIfFrozen(this);
136
public bool HasDefaultConstructorConstraint {
137
get { return flags[FlagDefaultConstructorConstraint]; }
139
FreezableHelper.ThrowIfFrozen(this);
140
flags[FlagDefaultConstructorConstraint] = value;
144
public bool HasReferenceTypeConstraint {
145
get { return flags[FlagReferenceTypeConstraint]; }
147
FreezableHelper.ThrowIfFrozen(this);
148
flags[FlagReferenceTypeConstraint] = value;
152
public bool HasValueTypeConstraint {
153
get { return flags[FlagValueTypeConstraint]; }
155
FreezableHelper.ThrowIfFrozen(this);
156
flags[FlagValueTypeConstraint] = value;
161
/// Uses the specified interning provider to intern
162
/// strings and lists in this entity.
163
/// This method does not test arbitrary objects to see if they implement ISupportsInterning;
164
/// instead we assume that those are interned immediately when they are created (before they are added to this entity).
166
public virtual void ApplyInterningProvider(InterningProvider provider)
168
if (provider == null)
169
throw new ArgumentNullException("provider");
170
FreezableHelper.ThrowIfFrozen(this);
171
name = provider.Intern(name);
172
attributes = provider.InternList(attributes);
173
constraints = provider.InternList(constraints);
176
public virtual ITypeParameter CreateResolvedTypeParameter(ITypeResolveContext context)
178
IEntity owner = null;
179
if (this.OwnerType == EntityType.Method) {
180
owner = context.CurrentMember as IMethod;
181
} else if (this.OwnerType == EntityType.TypeDefinition) {
182
owner = context.CurrentTypeDefinition;
185
throw new InvalidOperationException("Could not determine the type parameter's owner.");
186
return new DefaultTypeParameter(
187
owner, index, name, variance,
188
this.Attributes.CreateResolvedAttributes(context), this.Region,
189
this.HasValueTypeConstraint, this.HasReferenceTypeConstraint, this.HasDefaultConstructorConstraint, this.Constraints.Resolve(context)