|
|
|
@ -44,7 +44,7 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
TypeStorage typeStorage = new TypeStorage(); |
|
|
|
TypeStorage typeStorage = new TypeStorage(); |
|
|
|
CecilProjectContent pc = new CecilProjectContent(typeStorage, assemblyDefinition.Name.FullName, assemblyAttributes.AsReadOnly()); |
|
|
|
CecilProjectContent pc = new CecilProjectContent(typeStorage, assemblyDefinition.Name.FullName, assemblyAttributes.AsReadOnly()); |
|
|
|
|
|
|
|
|
|
|
|
this.EarlyBindContext = MultiTypeResolveContext.Combine(pc, this.EarlyBindContext); |
|
|
|
this.EarlyBindContext = AggregateTypeResolveContext.Combine(pc, this.EarlyBindContext); |
|
|
|
List<CecilTypeDefinition> types = new List<CecilTypeDefinition>(); |
|
|
|
List<CecilTypeDefinition> types = new List<CecilTypeDefinition>(); |
|
|
|
foreach (ModuleDefinition module in assemblyDefinition.Modules) { |
|
|
|
foreach (ModuleDefinition module in assemblyDefinition.Modules) { |
|
|
|
foreach (TypeDefinition td in module.Types) { |
|
|
|
foreach (TypeDefinition td in module.Types) { |
|
|
|
@ -223,7 +223,7 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
string name = type.FullName; |
|
|
|
string name = type.FullName; |
|
|
|
if (name == null) |
|
|
|
if (name == null) |
|
|
|
throw new ApplicationException("type.FullName returned null. Type: " + type.ToString()); |
|
|
|
throw new InvalidOperationException("type.FullName returned null. Type: " + type.ToString()); |
|
|
|
|
|
|
|
|
|
|
|
if (name.IndexOf('/') > 0) { |
|
|
|
if (name.IndexOf('/') > 0) { |
|
|
|
string[] nameparts = name.Split('/'); |
|
|
|
string[] nameparts = name.Split('/'); |
|
|
|
@ -310,68 +310,33 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IAttribute ReadAttribute(CustomAttribute cecilAttribute) |
|
|
|
public IAttribute ReadAttribute(CustomAttribute attribute) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (cecilAttribute == null) |
|
|
|
if (attribute == null) |
|
|
|
throw new ArgumentNullException("cecilAttribute"); |
|
|
|
throw new ArgumentNullException("attribute"); |
|
|
|
return new CecilAttribute(cecilAttribute, this); |
|
|
|
DefaultAttribute a = new DefaultAttribute(ReadTypeReference(attribute.AttributeType)); |
|
|
|
} |
|
|
|
try { |
|
|
|
|
|
|
|
if (attribute.HasConstructorArguments) { |
|
|
|
sealed class CecilAttribute : Immutable, IAttribute |
|
|
|
foreach (var arg in attribute.ConstructorArguments) { |
|
|
|
{ |
|
|
|
a.PositionalArguments.Add(ReadConstantValue(arg)); |
|
|
|
readonly ITypeReference attributeType; |
|
|
|
|
|
|
|
readonly IList<IConstantValue> positionalArguments; |
|
|
|
|
|
|
|
readonly IList<KeyValuePair<string, IConstantValue>> namedArguments; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CecilAttribute(CustomAttribute ca, CecilLoader loader) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this.attributeType = loader.ReadTypeReference(ca.AttributeType); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (ca.HasConstructorArguments) { |
|
|
|
|
|
|
|
var posArgs = new List<IConstantValue>(); |
|
|
|
|
|
|
|
foreach (var arg in ca.ConstructorArguments) { |
|
|
|
|
|
|
|
posArgs.Add(loader.ReadConstantValue(arg)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.positionalArguments = posArgs.AsReadOnly(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.positionalArguments = EmptyList<IConstantValue>.Instance; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (InvalidOperationException) { |
|
|
|
|
|
|
|
this.positionalArguments = EmptyList<IConstantValue>.Instance; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
} catch (InvalidOperationException) { |
|
|
|
if (ca.HasFields || ca.HasProperties) { |
|
|
|
// occurs when Cecil can't decode an argument
|
|
|
|
var namedArgs = new List<KeyValuePair<string, IConstantValue>>(); |
|
|
|
} |
|
|
|
foreach (var arg in ca.Fields) { |
|
|
|
try { |
|
|
|
namedArgs.Add(new KeyValuePair<string, IConstantValue>(arg.Name, loader.ReadConstantValue(arg.Argument))); |
|
|
|
if (attribute.HasFields || attribute.HasProperties) { |
|
|
|
} |
|
|
|
foreach (var arg in attribute.Fields) { |
|
|
|
foreach (var arg in ca.Properties) { |
|
|
|
a.NamedArguments.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument))); |
|
|
|
namedArgs.Add(new KeyValuePair<string, IConstantValue>(arg.Name, loader.ReadConstantValue(arg.Argument))); |
|
|
|
} |
|
|
|
} |
|
|
|
foreach (var arg in attribute.Properties) { |
|
|
|
this.namedArguments = namedArgs.AsReadOnly(); |
|
|
|
a.NamedArguments.Add(new KeyValuePair<string, IConstantValue>(arg.Name, ReadConstantValue(arg.Argument))); |
|
|
|
} else { |
|
|
|
|
|
|
|
this.namedArguments = EmptyList<KeyValuePair<string, IConstantValue>>.Instance; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (InvalidOperationException) { |
|
|
|
|
|
|
|
this.namedArguments = EmptyList<KeyValuePair<string, IConstantValue>>.Instance; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (InvalidOperationException) { |
|
|
|
|
|
|
|
// occurs when Cecil can't decode an argument
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return a; |
|
|
|
public DomRegion Region { |
|
|
|
|
|
|
|
get { return DomRegion.Empty; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ITypeReference AttributeType { |
|
|
|
|
|
|
|
get { return attributeType; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IList<IConstantValue> PositionalArguments { |
|
|
|
|
|
|
|
get { return positionalArguments; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IList<KeyValuePair<string, IConstantValue>> NamedArguments { |
|
|
|
|
|
|
|
get { return namedArguments; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
@ -555,6 +520,29 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeDefinition.HasFields) { |
|
|
|
|
|
|
|
foreach (FieldDefinition field in typeDefinition.Fields) { |
|
|
|
|
|
|
|
if (loader.IsVisible(field.Attributes)) { |
|
|
|
|
|
|
|
this.Fields.Add(loader.ReadField(field, this)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (typeDefinition.HasProperties) { |
|
|
|
|
|
|
|
foreach (PropertyDefinition property in typeDefinition.Properties) { |
|
|
|
|
|
|
|
bool getterVisible = property.GetMethod != null && loader.IsVisible(property.GetMethod.Attributes); |
|
|
|
|
|
|
|
bool setterVisible = property.SetMethod != null && loader.IsVisible(property.SetMethod.Attributes); |
|
|
|
|
|
|
|
if (getterVisible || setterVisible) { |
|
|
|
|
|
|
|
this.Properties.Add(loader.ReadProperty(property, this)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (typeDefinition.HasEvents) { |
|
|
|
|
|
|
|
foreach (EventDefinition ev in typeDefinition.Events) { |
|
|
|
|
|
|
|
if (ev.AddMethod != null && loader.IsVisible(ev.AddMethod.Attributes)) { |
|
|
|
|
|
|
|
this.Events.Add(loader.ReadEvent(ev, this)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
@ -584,13 +572,7 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
AddAttributes(method, m.Attributes); |
|
|
|
AddAttributes(method, m.Attributes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (parentType.ClassType == ClassType.Interface) { |
|
|
|
TranslateModifiers(method, m); |
|
|
|
// interface members don't have modifiers, but we want to handle them as "public abstract"
|
|
|
|
|
|
|
|
m.Accessibility = Accessibility.Public; |
|
|
|
|
|
|
|
m.IsAbstract = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
TranslateModifiers(method, m); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (method.HasParameters) { |
|
|
|
if (method.HasParameters) { |
|
|
|
foreach (ParameterDefinition p in method.Parameters) { |
|
|
|
foreach (ParameterDefinition p in method.Parameters) { |
|
|
|
@ -620,11 +602,11 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
|| att == MethodAttributes.FamORAssem; |
|
|
|
|| att == MethodAttributes.FamORAssem; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Accessibility GetAccessibility(MethodAttributes attr) |
|
|
|
static Accessibility GetAccessibility(MethodAttributes attr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (attr & MethodAttributes.MemberAccessMask) { |
|
|
|
switch (attr & MethodAttributes.MemberAccessMask) { |
|
|
|
case MethodAttributes.Private: |
|
|
|
case MethodAttributes.Public: |
|
|
|
return Accessibility.Private; |
|
|
|
return Accessibility.Public; |
|
|
|
case MethodAttributes.FamANDAssem: |
|
|
|
case MethodAttributes.FamANDAssem: |
|
|
|
return Accessibility.ProtectedAndInternal; |
|
|
|
return Accessibility.ProtectedAndInternal; |
|
|
|
case MethodAttributes.Assem: |
|
|
|
case MethodAttributes.Assem: |
|
|
|
@ -634,19 +616,25 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
case MethodAttributes.FamORAssem: |
|
|
|
case MethodAttributes.FamORAssem: |
|
|
|
return Accessibility.ProtectedOrInternal; |
|
|
|
return Accessibility.ProtectedOrInternal; |
|
|
|
default: |
|
|
|
default: |
|
|
|
return Accessibility.Public; |
|
|
|
return Accessibility.Private; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TranslateModifiers(MethodDefinition method, AbstractMember member) |
|
|
|
void TranslateModifiers(MethodDefinition method, AbstractMember m) |
|
|
|
{ |
|
|
|
{ |
|
|
|
member.Accessibility = GetAccessibility(method.Attributes); |
|
|
|
if (m.DeclaringTypeDefinition.ClassType == ClassType.Interface) { |
|
|
|
if (method.IsAbstract) |
|
|
|
// interface members don't have modifiers, but we want to handle them as "public abstract"
|
|
|
|
member.IsAbstract = true; |
|
|
|
m.Accessibility = Accessibility.Public; |
|
|
|
else if (method.IsFinal) |
|
|
|
m.IsAbstract = true; |
|
|
|
member.IsSealed = true; |
|
|
|
} else { |
|
|
|
else if (method.IsVirtual) |
|
|
|
m.Accessibility = GetAccessibility(method.Attributes); |
|
|
|
member.IsVirtual = true; |
|
|
|
if (method.IsAbstract) |
|
|
|
|
|
|
|
m.IsAbstract = true; |
|
|
|
|
|
|
|
else if (method.IsFinal) |
|
|
|
|
|
|
|
m.IsSealed = true; |
|
|
|
|
|
|
|
else if (method.IsVirtual) |
|
|
|
|
|
|
|
m.IsVirtual = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
@ -695,6 +683,11 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
|| att == FieldAttributes.Family |
|
|
|
|| att == FieldAttributes.Family |
|
|
|
|| att == FieldAttributes.FamORAssem; |
|
|
|
|| att == FieldAttributes.FamORAssem; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IField ReadField(FieldDefinition field, ITypeDefinition parentType) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
void AddExplicitInterfaceImplementations(MethodDefinition method, AbstractMember targetMember) |
|
|
|
void AddExplicitInterfaceImplementations(MethodDefinition method, AbstractMember targetMember) |
|
|
|
@ -727,5 +720,43 @@ namespace ICSharpCode.NRefactory.TypeSystem |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Read Property
|
|
|
|
|
|
|
|
public IProperty ReadProperty(PropertyDefinition property, ITypeDefinition parentType) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (property == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("property"); |
|
|
|
|
|
|
|
if (parentType == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("parentType"); |
|
|
|
|
|
|
|
DefaultProperty p = new DefaultProperty(parentType, property.Name); |
|
|
|
|
|
|
|
TranslateModifiers(property.GetMethod ?? property.SetMethod, p); |
|
|
|
|
|
|
|
p.ReturnType = ReadTypeReference(property.PropertyType, typeAttributes: property, entity: p); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.CanGet = property.GetMethod != null && IsVisible(property.GetMethod.Attributes); |
|
|
|
|
|
|
|
p.CanSet = property.SetMethod != null && IsVisible(property.SetMethod.Attributes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (p.CanGet) |
|
|
|
|
|
|
|
p.GetterAccessibility = GetAccessibility(property.GetMethod.Attributes); |
|
|
|
|
|
|
|
if (p.CanSet) |
|
|
|
|
|
|
|
p.SetterAccessibility = GetAccessibility(property.SetMethod.Attributes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (property.HasParameters) { |
|
|
|
|
|
|
|
foreach (ParameterDefinition par in property.Parameters) { |
|
|
|
|
|
|
|
p.Parameters.Add(ReadParameter(par, parentMember: p)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (property.HasCustomAttributes) |
|
|
|
|
|
|
|
AddAttributes(property, p.Attributes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Read Event
|
|
|
|
|
|
|
|
public IEvent ReadEvent(EventDefinition ev, ITypeDefinition parentType) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|