diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs index 128804ac..2cc99e78 100644 --- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs +++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs @@ -46,7 +46,7 @@ namespace CppSharp.Generators.CLI public void GenerateIncludeForwardRefs() { var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase); - typeReferenceCollector.Process(TranslationUnit); + typeReferenceCollector.Process(TranslationUnit, filterNamespaces: false); var includes = new SortedSet(StringComparer.InvariantCulture); @@ -75,7 +75,7 @@ namespace CppSharp.Generators.CLI public void GenerateForwardRefs(Namespace @namespace) { var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase); - typeReferenceCollector.Process(@namespace); + typeReferenceCollector.Process(@namespace, filterNamespaces: true); // Use a set to remove duplicate entries. var forwardRefs = new SortedSet(StringComparer.InvariantCulture); diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index d45f399e..9bb47ef0 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -55,7 +55,7 @@ namespace CppSharp.Generators.CLI PushBlock(CLIBlockKind.IncludesForwardReferences); var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase); - typeReferenceCollector.Process(TranslationUnit); + typeReferenceCollector.Process(TranslationUnit, filterNamespaces: false); var includes = new SortedSet(StringComparer.InvariantCulture); diff --git a/src/Generator/Generators/CLI/CLITypeReferences.cs b/src/Generator/Generators/CLI/CLITypeReferences.cs index ebd89f0e..fdc4c6fd 100644 --- a/src/Generator/Generators/CLI/CLITypeReferences.cs +++ b/src/Generator/Generators/CLI/CLITypeReferences.cs @@ -43,7 +43,19 @@ namespace CppSharp.Generators.CLI return @ref; } - public void Process(Namespace @namespace) + static Namespace GetEffectiveNamespace(Declaration decl) + { + if (decl == null || decl.Namespace == null) + return null; + + var @namespace = decl.Namespace as Namespace; + if (@namespace != null) + return @namespace; + + return GetEffectiveNamespace(@namespace); + } + + public void Process(Namespace @namespace, bool filterNamespaces) { var collector = new RecordCollector(@namespace.TranslationUnit); @namespace.Visit(collector); @@ -55,14 +67,17 @@ namespace CppSharp.Generators.CLI if (record.Value is Namespace) continue; - var declNamespace = record.Value.Namespace; + if (filterNamespaces) + { + var declNamespace = GetEffectiveNamespace(record.Value.Namespace); - var isSameNamespace = declNamespace == @namespace; - if (declNamespace != null) - isSameNamespace |= declNamespace.QualifiedName == @namespace.QualifiedName; + var isSameNamespace = declNamespace == @namespace; + if (declNamespace != null) + isSameNamespace |= declNamespace.QualifiedName == @namespace.QualifiedName; - if (!isSameNamespace) - continue; + if (!isSameNamespace) + continue; + } record.Value.Visit(this); GenerateInclude(record);