24 changed files with 694 additions and 82 deletions
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an ambiguous type resolve result.
|
||||
/// </summary>
|
||||
public class AmbiguousTypeResolveResult : TypeResolveResult |
||||
{ |
||||
public AmbiguousTypeResolveResult(IType type) : base(type) |
||||
{ |
||||
} |
||||
|
||||
public override bool IsError { |
||||
get { return true; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a reference which could point to a type or namespace.
|
||||
/// </summary>
|
||||
public interface ITypeOrNamespaceReference : ITypeReference |
||||
{ |
||||
string ResolveNamespace(ITypeResolveContext context); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
/// <summary>
|
||||
/// Represents that an expression resolved to a namespace.
|
||||
/// </summary>
|
||||
public class NamespaceResolveResult : ResolveResult |
||||
{ |
||||
readonly string namespaceName; |
||||
|
||||
public NamespaceResolveResult(string namespaceName) : base(SharedTypes.UnknownType) |
||||
{ |
||||
this.namespaceName = namespaceName; |
||||
} |
||||
|
||||
public string NamespaceName { |
||||
get { return namespaceName; } |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return "[NamespaceResolveResult " + namespaceName + "]"; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a simple C# name. (a single identifier with an optional list of type arguments)
|
||||
/// </summary>
|
||||
public sealed class SimpleTypeOrNamespaceReference : ITypeOrNamespaceReference |
||||
{ |
||||
readonly IMember parentMember; |
||||
readonly ITypeDefinition parentTypeDefinition; |
||||
readonly UsingScope parentUsingScope; |
||||
readonly string identifier; |
||||
readonly IList<ITypeReference> typeArguments; |
||||
|
||||
public SimpleTypeOrNamespaceReference(string identifier, IList<ITypeReference> typeArguments, IMember parentMember, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope) |
||||
{ |
||||
if (identifier == null) |
||||
throw new ArgumentNullException("identifier"); |
||||
this.identifier = identifier; |
||||
this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance; |
||||
this.parentMember = parentMember; |
||||
this.parentTypeDefinition = parentTypeDefinition; |
||||
this.parentUsingScope = parentUsingScope; |
||||
} |
||||
|
||||
ResolveResult DoResolve(ITypeResolveContext context) |
||||
{ |
||||
CSharpResolver r = new CSharpResolver(context); |
||||
r.CurrentMember = parentMember; |
||||
r.CurrentTypeDefinition = parentTypeDefinition.GetCompoundClass(); |
||||
r.UsingScope = parentUsingScope; |
||||
IType[] typeArgs = new IType[typeArguments.Count]; |
||||
for (int i = 0; i < typeArgs.Length; i++) { |
||||
typeArgs[i] = typeArguments[i].Resolve(context); |
||||
} |
||||
return r.LookupSimpleNamespaceOrTypeName(identifier, typeArgs); |
||||
} |
||||
|
||||
public string ResolveNamespace(ITypeResolveContext context) |
||||
{ |
||||
NamespaceResolveResult nrr = DoResolve(context) as NamespaceResolveResult; |
||||
return nrr != null ? nrr.NamespaceName : null; |
||||
} |
||||
|
||||
public IType Resolve(ITypeResolveContext context) |
||||
{ |
||||
TypeResolveResult rr = DoResolve(context) as TypeResolveResult; |
||||
return rr != null ? rr.Type : SharedTypes.UnknownType; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
/// <summary>
|
||||
/// The resolved expression refers to a type name.
|
||||
/// </summary>
|
||||
public class TypeResolveResult : ResolveResult |
||||
{ |
||||
public TypeResolveResult(IType type) |
||||
: base(type) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,138 @@
@@ -0,0 +1,138 @@
|
||||
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a scope that contains "using" statements.
|
||||
/// This is either the file itself, or a namespace declaration.
|
||||
/// </summary>
|
||||
public class UsingScope : AbstractFreezable |
||||
{ |
||||
readonly IProjectContent projectContent; |
||||
readonly UsingScope parent; |
||||
DomRegion region; |
||||
string namespaceName = ""; |
||||
IList<ITypeOrNamespaceReference> usings; |
||||
IList<KeyValuePair<string, ITypeOrNamespaceReference>> usingAliases; |
||||
IList<string> externAliases; |
||||
//IList<UsingScope> childScopes;
|
||||
|
||||
protected override void FreezeInternal() |
||||
{ |
||||
if (usings == null || usings.Count == 0) |
||||
usings = EmptyList<ITypeOrNamespaceReference>.Instance; |
||||
else |
||||
usings = Array.AsReadOnly(usings.ToArray()); |
||||
|
||||
if (usingAliases == null || usingAliases.Count == 0) |
||||
usingAliases = EmptyList<KeyValuePair<string, ITypeOrNamespaceReference>>.Instance; |
||||
else |
||||
usingAliases = Array.AsReadOnly(usingAliases.ToArray()); |
||||
|
||||
externAliases = FreezeList(externAliases); |
||||
//childScopes = FreezeList(childScopes);
|
||||
|
||||
// In current model (no child scopes), it makes sense to freeze the parent as well
|
||||
// to ensure the whole lookup chain is immutable.
|
||||
// But we probably shouldn't do this if we add back childScopes.
|
||||
if (parent != null) |
||||
parent.Freeze(); |
||||
|
||||
base.FreezeInternal(); |
||||
} |
||||
|
||||
public UsingScope(IProjectContent projectContent) |
||||
{ |
||||
if (projectContent == null) |
||||
throw new ArgumentNullException("projectContent"); |
||||
this.projectContent = projectContent; |
||||
} |
||||
|
||||
public UsingScope(UsingScope parent, string namespaceName) |
||||
{ |
||||
if (parent == null) |
||||
throw new ArgumentNullException("parent"); |
||||
if (namespaceName == null) |
||||
throw new ArgumentNullException("namespaceName"); |
||||
this.parent = parent; |
||||
this.projectContent = parent.projectContent; |
||||
this.namespaceName = namespaceName; |
||||
} |
||||
|
||||
public UsingScope Parent { |
||||
get { return parent; } |
||||
} |
||||
|
||||
public DomRegion Region { |
||||
get { return region; } |
||||
set { |
||||
CheckBeforeMutation(); |
||||
region = value; |
||||
} |
||||
} |
||||
|
||||
public string NamespaceName { |
||||
get { return namespaceName; } |
||||
set { |
||||
if (value == null) |
||||
throw new ArgumentNullException("NamespaceName"); |
||||
CheckBeforeMutation(); |
||||
namespaceName = value; |
||||
} |
||||
} |
||||
|
||||
public IList<ITypeOrNamespaceReference> Usings { |
||||
get { |
||||
if (usings == null) |
||||
usings = new List<ITypeOrNamespaceReference>(); |
||||
return usings; |
||||
} |
||||
} |
||||
|
||||
public IList<KeyValuePair<string, ITypeOrNamespaceReference>> UsingAliases { |
||||
get { |
||||
if (usingAliases == null) |
||||
usingAliases = new List<KeyValuePair<string, ITypeOrNamespaceReference>>(); |
||||
return usingAliases; |
||||
} |
||||
} |
||||
|
||||
public IList<string> ExternAliases { |
||||
get { |
||||
if (externAliases == null) |
||||
externAliases = new List<string>(); |
||||
return externAliases; |
||||
} |
||||
} |
||||
|
||||
// public IList<UsingScope> ChildScopes {
|
||||
// get {
|
||||
// if (childScopes == null)
|
||||
// childScopes = new List<UsingScope>();
|
||||
// return childScopes;
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this using scope has an alias (either using or extern)
|
||||
/// with the specified name.
|
||||
/// </summary>
|
||||
public bool HasAlias(string identifier) |
||||
{ |
||||
if (usingAliases != null) { |
||||
foreach (var pair in usingAliases) { |
||||
if (pair.Key == identifier) |
||||
return true; |
||||
} |
||||
} |
||||
return externAliases != null && externAliases.Contains(identifier); |
||||
} |
||||
} |
||||
} |
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.NRefactory.TypeSystem |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an ambiguous type (same type found in multiple locations).
|
||||
/// </summary>
|
||||
public class AmbiguousType : AbstractType |
||||
{ |
||||
readonly string name; |
||||
|
||||
public AmbiguousType(string name) |
||||
{ |
||||
if (name == null) |
||||
throw new ArgumentNullException("name"); |
||||
this.name = name; |
||||
} |
||||
|
||||
public override string Name { |
||||
get { return name; } |
||||
} |
||||
|
||||
public override bool? IsReferenceType { |
||||
get { return null; } |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return name.GetHashCode() ^ 12661218; |
||||
} |
||||
|
||||
public override bool Equals(IType other) |
||||
{ |
||||
AmbiguousType at = other as AmbiguousType; |
||||
return at != null && name == at.name; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue