From bcf41e4169dfc23423e210f0c3299822050b6605 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sat, 2 Oct 2021 16:21:41 +0300 Subject: [PATCH] Ignore external (no module) translation units Signed-off-by: Dimitar Dobrev --- src/Generator.Tests/GeneratorTest.cs | 9 ++++++++- src/Generator/Passes/CleanUnitPass.cs | 11 ++++++++--- src/Generator/Passes/DelegatesPass.cs | 5 +++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Generator.Tests/GeneratorTest.cs b/src/Generator.Tests/GeneratorTest.cs index a400bc9739..d2f7e75919 100644 --- a/src/Generator.Tests/GeneratorTest.cs +++ b/src/Generator.Tests/GeneratorTest.cs @@ -42,9 +42,16 @@ public virtual void Setup(Driver driver) testModule.IncludeDirs.Add(path); Diagnostics.Message("Looking for tests in: {0}", path); - var files = Directory.EnumerateFiles(path, "*.h"); + var files = Directory.EnumerateFiles(path, "*.h", SearchOption.AllDirectories); foreach (var file in files) + { + string includeDir = Path.GetDirectoryName(file); + if (!testModule.IncludeDirs.Contains(includeDir)) + { + testModule.IncludeDirs.Add(includeDir); + } testModule.Headers.Add(Path.GetFileName(file)); + } } public virtual void Preprocess(Driver driver, ASTContext ctx) diff --git a/src/Generator/Passes/CleanUnitPass.cs b/src/Generator/Passes/CleanUnitPass.cs index c9978f92fb..0bc9c04782 100644 --- a/src/Generator/Passes/CleanUnitPass.cs +++ b/src/Generator/Passes/CleanUnitPass.cs @@ -31,9 +31,14 @@ private Module GetModule(TranslationUnit unit) includeDir = "."; includeDir = Path.GetFullPath(includeDir); - return Options.Modules.FirstOrDefault( - m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)) ?? - Options.Modules[1]; + Module module = Options.Modules.Find( + m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)); + if (module == null) + { + unit.ExplicitlyIgnore(); + module = Options.Modules[1]; + } + return module; } public override bool VisitDeclarationContext(DeclarationContext context) diff --git a/src/Generator/Passes/DelegatesPass.cs b/src/Generator/Passes/DelegatesPass.cs index 1f427a47ff..68d205faae 100644 --- a/src/Generator/Passes/DelegatesPass.cs +++ b/src/Generator/Passes/DelegatesPass.cs @@ -215,7 +215,8 @@ private DeclarationContext GetDeclContextForDelegates(DeclarationContext @namesp Namespace parent = null; if (string.IsNullOrEmpty(module.OutputNamespace)) { - var groups = module.Units.SelectMany(u => u.Declarations).OfType( + var groups = module.Units.Where(u => u.IsGenerated).SelectMany( + u => u.Declarations).OfType( ).GroupBy(d => d.Name).Where(g => g.Any(d => d.HasDeclarations)).ToList(); if (groups.Count == 1) parent = groups.Last().Last(); @@ -231,7 +232,7 @@ private DeclarationContext GetDeclContextForDelegates(DeclarationContext @namesp } if (parent == null) - parent = module.Units.Last(); + parent = module.Units.Last(u => u.IsGenerated); var namespaceDelegates = new Namespace {