Skip to content

Commit 20a002e

Browse files
Merge pull request #430 from tannergooding/main
Ensure that IsIncludedFileOrLocation checks the full path
2 parents 6847d67 + bb1947e commit 20a002e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

sources/ClangSharp.PInvokeGenerator/Extensions/StringExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
22

33
using System;
4+
using System.IO;
45
using System.Runtime.InteropServices;
56
using ClangSharp.Abstractions;
67

@@ -16,6 +17,9 @@ public static string Unquote(this string str)
1617
public static string NormalizePath(this string str)
1718
=> str.Replace('\\', '/').Replace("//", "/");
1819

20+
public static string NormalizeFullPath(this string str)
21+
=> string.IsNullOrWhiteSpace(str) ? str : Path.GetFullPath(str).NormalizePath();
22+
1923
public static string AsString(this AccessSpecifier value) => value switch {
2024
AccessSpecifier.Public => "public",
2125
AccessSpecifier.Protected => "protected",

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,17 +2934,9 @@ private string GetTypeName(Cursor? cursor, Cursor? context, Type rootType, Type
29342934
{
29352935
if (!_typeNames.TryGetValue((cursor, context, type), out var result))
29362936
{
2937-
result.typeName = type.AsString.NormalizePath();
2938-
2939-
if (result.typeName.Contains("unnamed struct at"))
2940-
{
2941-
result.typeName = result.typeName.Replace("unnamed struct at", "anonymous struct at");
2942-
}
2943-
2944-
if (result.typeName.Contains("unnamed union at"))
2945-
{
2946-
result.typeName = result.typeName.Replace("unnamed union at", "anonymous union at");
2947-
}
2937+
result.typeName = type.AsString.NormalizePath()
2938+
.Replace("unnamed struct at", "anonymous struct at")
2939+
.Replace("unnamed union at", "anonymous union at");
29482940

29492941
result.nativeTypeName = result.typeName;
29502942

@@ -4317,6 +4309,10 @@ bool IsIncludedFileOrLocation(Cursor cursor, CXFile file, CXSourceLocation locat
43174309
{
43184310
return true;
43194311
}
4312+
else if (_config.TraversalNames.Contains(fileName.NormalizeFullPath(), equalityComparer))
4313+
{
4314+
return true;
4315+
}
43204316
else if (!_config.TraversalNames.Any() && location.IsFromMainFile)
43214317
{
43224318
return true;

sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ public IReadOnlyCollection<string> NativeTypeNamesToStrip
311311
init
312312
{
313313
AddRange(_nativeTypeNamesToStrip, value, StringExtensions.NormalizePath);
314+
AddRange(_nativeTypeNamesToStrip, value, StringExtensions.NormalizeFullPath);
314315
}
315316
}
316317

@@ -362,6 +363,7 @@ public IReadOnlyCollection<string> TraversalNames
362363
init
363364
{
364365
AddRange(_traversalNames, value, StringExtensions.NormalizePath);
366+
AddRange(_traversalNames, value, StringExtensions.NormalizeFullPath);
365367
}
366368
}
367369

0 commit comments

Comments
 (0)