Browse Source

Revert "Ignore external (no module) translation units"

This reverts commit 0d8b236f7e.
pg
josetr 3 years ago
parent
commit
9555eec24f
  1. 9
      src/Generator.Tests/GeneratorTest.cs
  2. 27
      src/Generator/Passes/CleanUnitPass.cs
  3. 5
      src/Generator/Passes/DelegatesPass.cs

9
src/Generator.Tests/GeneratorTest.cs

@ -44,16 +44,9 @@ namespace CppSharp.Utils @@ -44,16 +44,9 @@ namespace CppSharp.Utils
testModule.Libraries.Add($"{name}.Native");
Diagnostics.Message("Looking for tests in: {0}", path);
var files = Directory.EnumerateFiles(path, "*.h", SearchOption.AllDirectories);
var files = Directory.EnumerateFiles(path, "*.h");
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,14 +31,9 @@ namespace CppSharp.Passes @@ -31,14 +31,9 @@ namespace CppSharp.Passes
includeDir = ".";
includeDir = Path.GetFullPath(includeDir);
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;
return Options.Modules.FirstOrDefault(
m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)) ??
Options.Modules[1];
}
public override bool VisitDeclarationContext(DeclarationContext context)
@ -46,9 +41,10 @@ namespace CppSharp.Passes @@ -46,9 +41,10 @@ namespace CppSharp.Passes
return false;
}
private string GetIncludePath(string filePath)
string GetIncludePath(string filePath)
{
var includePath = filePath;
var shortestIncludePath = filePath;
for (uint i = 0; i < Context.ParserOptions.IncludeDirsCount; ++i)
{
@ -61,15 +57,16 @@ namespace CppSharp.Passes @@ -61,15 +57,16 @@ namespace CppSharp.Passes
idx = filePath.IndexOf(path, System.StringComparison.Ordinal);
}
if (idx != -1)
{
includePath = filePath[path.Length..];
break;
}
if (idx == -1) continue;
string inc = filePath.Substring(path.Length);
if (inc.Length < includePath.Length && inc.Length < shortestIncludePath.Length)
shortestIncludePath = inc;
}
includePath = Options.IncludePrefix
+ includePath.TrimStart(new char[] { '\\', '/' });
+ shortestIncludePath.TrimStart(new char[] { '\\', '/' });
return includePath.Replace('\\', '/');
}

5
src/Generator/Passes/DelegatesPass.cs

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

Loading…
Cancel
Save