Skip to content

Commit

Permalink
Ignore external (no module) translation units
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Oct 2, 2021
1 parent 851ec5e commit bcf41e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/Generator.Tests/GeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions src/Generator/Passes/CleanUnitPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/Generator/Passes/DelegatesPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Namespace>(
var groups = module.Units.Where(u => u.IsGenerated).SelectMany(
u => u.Declarations).OfType<Namespace>(
).GroupBy(d => d.Name).Where(g => g.Any(d => d.HasDeclarations)).ToList();
if (groups.Count == 1)
parent = groups.Last().Last();
Expand All @@ -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
{
Expand Down

0 comments on commit bcf41e4

Please sign in to comment.