Browse Source

Ignore external (no module) translation units

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1635/head
Dimitar Dobrev 4 years ago
parent
commit
0d8b236f7e
  1. 2
      src/Generator.Tests/ASTTestFixture.cs
  2. 9
      src/Generator.Tests/GeneratorTest.cs
  3. 27
      src/Generator/Passes/CleanUnitPass.cs
  4. 5
      src/Generator/Passes/DelegatesPass.cs

2
src/Generator.Tests/ASTTestFixture.cs

@ -18,10 +18,10 @@ namespace CppSharp.Generator.Tests @@ -18,10 +18,10 @@ namespace CppSharp.Generator.Tests
var parserOptions = new ParserOptions();
var testsPath = GeneratorTest.GetTestsDirectory("Native");
parserOptions.AddIncludeDirs(testsPath);
parserOptions.SkipPrivateDeclarations = true;
var module = options.AddModule("Test");
module.IncludeDirs.Add(testsPath);
module.Headers.AddRange(files);
Driver = new Driver(options)

9
src/Generator.Tests/GeneratorTest.cs

@ -42,10 +42,17 @@ namespace CppSharp.Utils @@ -42,10 +42,17 @@ namespace CppSharp.Utils
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)
{

27
src/Generator/Passes/CleanUnitPass.cs

@ -31,9 +31,14 @@ namespace CppSharp.Passes @@ -31,9 +31,14 @@ namespace CppSharp.Passes
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)
@ -41,10 +46,9 @@ namespace CppSharp.Passes @@ -41,10 +46,9 @@ namespace CppSharp.Passes
return false;
}
string GetIncludePath(string filePath)
private string GetIncludePath(string filePath)
{
var includePath = filePath;
var shortestIncludePath = filePath;
for (uint i = 0; i < Context.ParserOptions.IncludeDirsCount; ++i)
{
@ -57,16 +61,15 @@ namespace CppSharp.Passes @@ -57,16 +61,15 @@ namespace CppSharp.Passes
idx = filePath.IndexOf(path, System.StringComparison.Ordinal);
}
if (idx == -1) continue;
string inc = filePath.Substring(path.Length);
if (inc.Length < includePath.Length && inc.Length < shortestIncludePath.Length)
shortestIncludePath = inc;
if (idx != -1)
{
includePath = filePath[path.Length..];
break;
}
}
includePath = Options.IncludePrefix
+ shortestIncludePath.TrimStart(new char[] { '\\', '/' });
+ includePath.TrimStart(new char[] { '\\', '/' });
return includePath.Replace('\\', '/');
}

5
src/Generator/Passes/DelegatesPass.cs

@ -215,7 +215,8 @@ namespace CppSharp.Passes @@ -215,7 +215,8 @@ namespace CppSharp.Passes
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();
@ -231,7 +232,7 @@ namespace CppSharp.Passes @@ -231,7 +232,7 @@ namespace CppSharp.Passes
}
if (parent == null)
parent = module.Units.Last();
parent = module.Units.Last(u => u.IsGenerated);
var namespaceDelegates = new Namespace
{

Loading…
Cancel
Save