Skip to content

Commit

Permalink
[change] 解决AOTGenericReference生成不稳定的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
walon committed Jun 27, 2023
1 parent 4492449 commit 768512b
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions Editor/AOT/GenericReferenceWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,49 @@ public void Write(List<GenericClass> types, List<GenericMethod> methods, string

codes.Add("");
codes.Add("\t// {{ AOT generic types");

types.Sort((a, b) => a.Type.FullName.CompareTo(b.Type.FullName));
foreach(var type in types)

List<string> typeNames = types.Select(t => PrettifyTypeSig(t.ToTypeSig().ToString())).ToList();
typeNames.Sort(string.CompareOrdinal);
foreach(var typeName in typeNames)
{
codes.Add($"\t// {PrettifyTypeSig(type.ToTypeSig().ToString())}");
codes.Add($"\t// {typeName}");
}

codes.Add("\t// }}");

codes.Add("");
codes.Add("\tpublic void RefMethods()");
codes.Add("\t{");
methods.Sort((a, b) =>

List<(string, string, string)> methodTypeAndNames = methods.Select(m =>
(PrettifyTypeSig(m.Method.DeclaringType.ToString()), PrettifyMethodSig(m.Method.Name), PrettifyMethodSig(m.ToMethodSpec().ToString())))
.ToList();
methodTypeAndNames.Sort((a, b) =>
{
int c = a.Method.DeclaringType.FullName.CompareTo(b.Method.DeclaringType.FullName);
int c = String.Compare(a.Item1, b.Item1, StringComparison.Ordinal);
if (c != 0)
{
return c;
}
c = String.Compare(a.Item2, b.Item2, StringComparison.Ordinal);
if (c != 0)
{
return c;
}
c = a.Method.Name.CompareTo(b.Method.Name);
return c;
return String.Compare(a.Item3, b.Item3, StringComparison.Ordinal);
});
foreach(var method in methods)
foreach(var method in methodTypeAndNames)
{
codes.Add($"\t\t// {PrettifyMethodSig(method.ToMethodSpec().ToString())}");
codes.Add($"\t\t// {PrettifyMethodSig(method.Item3)}");
}
codes.Add("\t}");

codes.Add("}");


var utf8WithoutBOM = new System.Text.UTF8Encoding(false);
File.WriteAllText(outputFile, string.Join("\n", codes), utf8WithoutBOM);
var utf8WithoutBom = new System.Text.UTF8Encoding(false);
File.WriteAllText(outputFile, string.Join("\n", codes), utf8WithoutBom);
Debug.Log($"[GenericReferenceWriter] write {outputFile}");
}
}
Expand Down

0 comments on commit 768512b

Please sign in to comment.