From a1c48856104c9e1e85abfff136a61196d85c0081 Mon Sep 17 00:00:00 2001 From: triton Date: Tue, 17 Dec 2013 19:11:39 +0000 Subject: [PATCH] Fixed the output of forward references in CLI headers. We now use a sorted set to prevent duplicated references and have a stable ordering. --- src/Generator/Generators/CLI/CLIHeadersTemplate.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs index 3792b926..6806f651 100644 --- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs +++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs @@ -97,7 +97,13 @@ namespace CppSharp.Generators.CLI // Create a new tree of namespaces out of the type references found. var rootNamespace = new TranslationUnit(); - foreach (var typeRef in typeReferences) + var sortedRefs = typeReferences.ToList(); + sortedRefs.Sort((ref1, ref2) => + string.CompareOrdinal(ref1.FowardReference, ref2.FowardReference)); + + var forwardRefs = new SortedSet(); + + foreach (var typeRef in sortedRefs) { if (string.IsNullOrWhiteSpace(typeRef.FowardReference)) continue; @@ -106,6 +112,12 @@ namespace CppSharp.Generators.CLI if (!(declaration.Namespace is Namespace)) continue; + if (!forwardRefs.Add(typeRef.FowardReference)) + continue; + + if (typeRef.Include.InHeader) + continue; + var @namespace = FindCreateNamespace(rootNamespace, declaration); @namespace.TypeReferences.Add(typeRef); }