Rewrite nested types

Fixes zero-RVA exception for OpenGL extensions (e.g. GL.Ext etc)
This commit is contained in:
Stefanos A. 2013-11-27 08:28:22 +01:00
parent c369bfc75e
commit 6bde1beb91

View file

@ -127,31 +127,14 @@ namespace OpenTK.Rewrite
var entry_points = type.Fields.FirstOrDefault(f => f.Name == "EntryPoints");
if (entry_points != null)
{
// Build list of entry point signatures and slots
var native_signatures = new List<MethodDefinition>();
native_signatures.AddRange(type.Methods
// Build list of entry point signatures (one per entry point)
var entry_signatures = new List<MethodDefinition>();
entry_signatures.AddRange(type.Methods
.Where(t => t.CustomAttributes.Any(a => a.AttributeType.Name == "SlotAttribute")));
// Rewrite all wrapper methods
var wrapper_signatures = new List<MethodDefinition>();
wrapper_signatures.AddRange(type.Methods
.Where(m => m.IsPublic && m.CustomAttributes.Any(a => a.AttributeType.Name == "AutoGeneratedAttribute")));
Rewrite(type, entry_points, entry_signatures);
foreach (var wrapper in wrapper_signatures)
{
var signature_name = (string)wrapper.CustomAttributes
.First(a => a.AttributeType.Name == "AutoGeneratedAttribute")
.Fields.First(f => f.Name == "EntryPoint").Argument.Value;
var signature = native_signatures.First(s => s.Name == signature_name);
var slot = (int)signature.CustomAttributes
.First(a => a.AttributeType.Name == "SlotAttribute")
.ConstructorArguments[0].Value;
ProcessMethod(wrapper, signature, slot, entry_points);
}
RemoveNativeSignatures(type, native_signatures);
RemoveSupportingAttributes(type);
RemoveNativeSignatures(type, entry_signatures);
}
if (type.Name == "RewrittenAttribute")
@ -162,6 +145,42 @@ namespace OpenTK.Rewrite
}
}
void Rewrite(TypeDefinition type, FieldDefinition entry_points,
List<MethodDefinition> entry_signatures)
{
// Rewrite all wrapper methods
var wrapper_signatures = new List<MethodDefinition>();
wrapper_signatures.AddRange(type.Methods
.Where(m => m.IsPublic && m.CustomAttributes.Any(a => a.AttributeType.Name == "AutoGeneratedAttribute")));
foreach (var wrapper in wrapper_signatures)
{
var autogenerated = wrapper.CustomAttributes
.Where(a => a.AttributeType.Name == "AutoGeneratedAttribute");
if (autogenerated.Count() > 0)
{
var signature_name = (string)autogenerated.First()
.Fields.First(f => f.Name == "EntryPoint").Argument.Value;
var signature = entry_signatures.First(s => s.Name == signature_name);
var slot = (int)signature.CustomAttributes
.First(a => a.AttributeType.Name == "SlotAttribute")
.ConstructorArguments[0].Value;
ProcessMethod(wrapper, signature, slot, entry_points);
}
}
RemoveSupportingAttributes(type);
if (type.NestedTypes.Count > 0)
{
foreach (var nested_type in type.NestedTypes)
{
Rewrite(nested_type, entry_points, entry_signatures);
}
}
}
void RemoveNativeSignatures(TypeDefinition type, List<MethodDefinition> methods)
{
while (methods.Count > 0)