Reworked class lookup to be called from all methods.

This commit is contained in:
Joao Matos 2016-08-09 12:55:25 +01:00
Родитель da16104e3d
Коммит 2d2e3ee679
1 изменённых файлов: 16 добавлений и 5 удалений

Просмотреть файл

@ -68,6 +68,8 @@ namespace MonoManagedToNative.Generators
WriteLine("};"); WriteLine("};");
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
GenerateClassLookup(@class);
VisitDeclContext(@class); VisitDeclContext(@class);
return true; return true;
@ -79,7 +81,8 @@ namespace MonoManagedToNative.Generators
WriteLine("static void {0}()", GeneratedIdentifier("initialize_mono")); WriteLine("static void {0}()", GeneratedIdentifier("initialize_mono"));
WriteStartBraceIndent(); WriteStartBraceIndent();
WriteLine("if ({0})", GeneratedIdentifier("mono_initialized")); var initializedId = GeneratedIdentifier("mono_initialized");
WriteLine("if ({0})", initializedId);
WriteLineIndent("return;"); WriteLineIndent("return;");
WriteLine("mono_config_parse(NULL);"); WriteLine("mono_config_parse(NULL);");
@ -88,6 +91,7 @@ namespace MonoManagedToNative.Generators
var version = "v4.0.30319"; var version = "v4.0.30319";
WriteLine("{0} = mono_jit_init_version(\"{1}\", \"{2}\");", WriteLine("{0} = mono_jit_init_version(\"{1}\", \"{2}\");",
GeneratedIdentifier("mono_domain"), domainName, version); GeneratedIdentifier("mono_domain"), domainName, version);
WriteLine("{0} = true;", initializedId);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
@ -118,11 +122,15 @@ namespace MonoManagedToNative.Generators
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
public void GenerateClassLookup(Method method) public void GenerateClassLookup(Class @class)
{ {
PushBlock(); PushBlock();
var @class = method.Namespace as Class; var classLookupId = GeneratedIdentifier(string.Format("lookup_class_{0}",
@class.QualifiedName.Replace('.', '_')));
WriteLine("static void {0}()", classLookupId);
WriteStartBraceIndent();
var classId = string.Format("{0}_class", @class.QualifiedName); var classId = string.Format("{0}_class", @class.QualifiedName);
WriteLine("if ({0} == 0)", classId); WriteLine("if ({0} == 0)", classId);
@ -143,6 +151,7 @@ namespace MonoManagedToNative.Generators
WriteLine("{0} = mono_class_from_name({1}, \"{2}\", \"{3}\");", WriteLine("{0} = mono_class_from_name({1}, \"{2}\", \"{3}\");",
classId, monoImageName, @namespace, @class.OriginalName); classId, monoImageName, @namespace, @class.OriginalName);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
@ -250,8 +259,10 @@ namespace MonoManagedToNative.Generators
NewLine(); NewLine();
WriteStartBraceIndent(); WriteStartBraceIndent();
if (method.IsConstructor) var @class = method.Namespace as Class;
GenerateClassLookup(method); var classLookupId = GeneratedIdentifier(string.Format("lookup_class_{0}",
@class.QualifiedName.Replace('.', '_')));
WriteLine("{0}();", classLookupId);
GenerateMethodLookup(method); GenerateMethodLookup(method);