Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/XamlX.IL.Cecil/XamlX.IL.Cecil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Mono.Cecil" Version="0.10.3" />
<PackageReference Include="Mono.Cecil" Version="0.11.3" />
</ItemGroup>

</Project>
46 changes: 25 additions & 21 deletions src/XamlX/IL/SreTypeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SreTypeSystem : IXamlTypeSystem
{
private List<IXamlAssembly> _assemblies = new List<IXamlAssembly>();
public IReadOnlyList<IXamlAssembly> Assemblies => _assemblies;

private Dictionary<Type, SreType> _typeDic = new Dictionary<Type, SreType>();

public SreTypeSystem()
Expand All @@ -34,7 +34,7 @@ public SreTypeSystem()
//
}
}

public IXamlAssembly FindAssembly(string name)
{
return Assemblies.FirstOrDefault(a => a.Name.ToLowerInvariant() == name.ToLowerInvariant());
Expand Down Expand Up @@ -98,7 +98,7 @@ public SreAssembly(SreTypeSystem system, Assembly asm)
public bool Equals(IXamlAssembly other) => Assembly == ((SreAssembly) other)?.Assembly;

public string Name => Assembly.GetName().Name;

public IReadOnlyList<IXamlType> Types { get; private set; }
private Dictionary<string, SreType> _typeDic = new Dictionary<string, SreType>();

Expand All @@ -115,7 +115,11 @@ public IXamlType FindType(string fullName)

public void Init()
{
var types = Assembly.GetExportedTypes().Select(t => _system.ResolveType(t)).ToList();
// PYREX NOTE: GetTypes() is not exactly right -- we want GetExportedTypes if the assembly is not friendly to us
// and _specifically_ the internal and visible types if the assembly is
//
// However, this is the hack I gave Dr. Smugleaf
var types = Assembly.GetTypes().Select(t => _system.ResolveType(t)).ToList();
Types = types;
_typeDic = types.ToDictionary(t => t.Type.FullName);
}
Expand All @@ -138,7 +142,7 @@ public IReadOnlyList<IXamlCustomAttribute> CustomAttributes
(_customAttributes = _member.GetCustomAttributesData().Select(a => new SreCustomAttribute(System,
a, System.ResolveType(a.AttributeType))).ToList());
}

[DebuggerDisplay("{" + nameof(Type) + "}")]
class SreType : SreMemberInfo, IXamlType
{
Expand Down Expand Up @@ -272,7 +276,7 @@ public SreCustomAttribute(SreTypeSystem system, CustomAttributeData data, IXamlT
Properties = data.NamedArguments?.ToDictionary(x => x.MemberName, x => x.TypedValue.Value) ??
new Dictionary<string, object>();
}

public bool Equals(IXamlCustomAttribute other)
{
return ((SreCustomAttribute) other)?._data.Equals(_data) == true;
Expand Down Expand Up @@ -301,7 +305,7 @@ public SreMethodBase(SreTypeSystem system, MethodBase method) : base(system, met

public override string ToString() => _method.DeclaringType?.FullName + " " + _method;
}

[DebuggerDisplay("{Method}")]
class SreMethod : SreMethodBase, IXamlMethod
{
Expand Down Expand Up @@ -333,7 +337,7 @@ public SreConstructor(SreTypeSystem system, ConstructorInfo ctor) : base(system,
Constuctor = ctor;
}

public bool Equals(IXamlConstructor other)
public bool Equals(IXamlConstructor other)
=> ((SreConstructor) other)?.Constuctor.Equals(Constuctor) == true;
}

Expand Down Expand Up @@ -381,7 +385,7 @@ public SreEvent(SreTypeSystem system, EventInfo ev) : base(system, ev)
public bool Equals(IXamlEventInfo other) => (other as SreEvent)?.Event.Equals(Event) == true;
public override string ToString() => Event.ToString();
}

class SreField : SreMemberInfo, IXamlField
{
public FieldInfo Field { get; }
Expand Down Expand Up @@ -464,13 +468,13 @@ public IXamlILEmitter Emit(OpCode code, long arg)
_ilg.Emit(code, arg);
return this;
}

public IXamlILEmitter Emit(OpCode code, float arg)
{
_ilg.Emit(code, arg);
return this;
}

public IXamlILEmitter Emit(OpCode code, double arg)
{
_ilg.Emit(code, arg);
Expand Down Expand Up @@ -517,8 +521,8 @@ public IXamlILEmitter Emit(OpCode code, IXamlType type)
_ilg.Emit(code, ((SreType) type).Type);
return this;
}


public IXamlILEmitter Emit(OpCode code, IXamlField field)
{
_ilg.Emit(code, ((SreField) field).Field);
Expand All @@ -534,7 +538,7 @@ public SreLabel(Label label)
Label = label;
}
}

class SreLocal : IXamlLocal
{
public LocalBuilder Local { get; }
Expand All @@ -556,7 +560,7 @@ public SreTypeBuilder(SreTypeSystem system, TypeBuilder tb) : base(system,null,
_system = system;
_tb = tb;
}

public IXamlField DefineField(IXamlType type, string name, bool isPublic, bool isStatic)
{
var f = _tb.DefineField(name, ((SreType) type).Type,
Expand Down Expand Up @@ -589,15 +593,15 @@ public void EmitClosure(IEnumerable<IXamlType> fields)
throw new NotImplementedException();
}
}

public IXamlMethodBuilder<IXamlILEmitter> DefineMethod(IXamlType returnType, IEnumerable<IXamlType> args, string name,
bool isPublic, bool isStatic,
bool isInterfaceImpl, IXamlMethod overrideMethod)
{
var ret = ((SreType) returnType).Type;
var largs = (IReadOnlyList<IXamlType>)(args?.ToList()) ?? Array.Empty<IXamlType>();
var argTypes = largs.Cast<SreType>().Select(t => t.Type);
var m = _tb.DefineMethod(name,
var m = _tb.DefineMethod(name,
(isPublic ? MethodAttributes.Public : MethodAttributes.Private)
|(isStatic ? MethodAttributes.Static : default(MethodAttributes))
|(isInterfaceImpl ? MethodAttributes.Virtual|MethodAttributes.NewSlot : default(MethodAttributes))
Expand Down Expand Up @@ -628,7 +632,7 @@ public SreConstructorBuilder(SreTypeSystem system, ConstructorBuilder ctor) : ba
public IXamlILEmitter Generator { get; }
}


public IXamlConstructorBuilder<IXamlILEmitter> DefineConstructor(bool isStatic, params IXamlType[] args)
{
var attrs = MethodAttributes.Public;
Expand All @@ -639,7 +643,7 @@ public IXamlConstructorBuilder<IXamlILEmitter> DefineConstructor(bool isStatic,
args.Cast<SreType>().Select(t => t.Type).ToArray());
return new SreConstructorBuilder(_system, ctor);
}

public IXamlType CreateType() => new SreType(_system, null, _tb.CreateTypeInfo());
public IXamlTypeBuilder<IXamlILEmitter> DefineSubType(IXamlType baseType, string name, bool isPublic)
{
Expand All @@ -648,10 +652,10 @@ public IXamlTypeBuilder<IXamlILEmitter> DefineSubType(IXamlType baseType, string
attrs |= TypeAttributes.NestedPublic;
else
attrs |= TypeAttributes.NestedPrivate;

var builder = _tb.DefineNestedType(name, attrs,
((SreType) baseType).Type);

return new SreTypeBuilder(_system, builder);
}

Expand Down