Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that IsIncludedFileOrLocation checks the full path #430

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.

using System;
using System.IO;
using System.Runtime.InteropServices;
using ClangSharp.Abstractions;

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

public static string NormalizeFullPath(this string str)
=> string.IsNullOrWhiteSpace(str) ? str : Path.GetFullPath(str).NormalizePath();

public static string AsString(this AccessSpecifier value) => value switch {
AccessSpecifier.Public => "public",
AccessSpecifier.Protected => "protected",
Expand Down
18 changes: 7 additions & 11 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2934,17 +2934,9 @@ private string GetTypeName(Cursor? cursor, Cursor? context, Type rootType, Type
{
if (!_typeNames.TryGetValue((cursor, context, type), out var result))
{
result.typeName = type.AsString.NormalizePath();

if (result.typeName.Contains("unnamed struct at"))
{
result.typeName = result.typeName.Replace("unnamed struct at", "anonymous struct at");
}

if (result.typeName.Contains("unnamed union at"))
{
result.typeName = result.typeName.Replace("unnamed union at", "anonymous union at");
}
result.typeName = type.AsString.NormalizePath()
.Replace("unnamed struct at", "anonymous struct at")
.Replace("unnamed union at", "anonymous union at");

result.nativeTypeName = result.typeName;

Expand Down Expand Up @@ -4317,6 +4309,10 @@ bool IsIncludedFileOrLocation(Cursor cursor, CXFile file, CXSourceLocation locat
{
return true;
}
else if (_config.TraversalNames.Contains(fileName.NormalizeFullPath(), equalityComparer))
{
return true;
}
else if (!_config.TraversalNames.Any() && location.IsFromMainFile)
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public IReadOnlyCollection<string> NativeTypeNamesToStrip
init
{
AddRange(_nativeTypeNamesToStrip, value, StringExtensions.NormalizePath);
AddRange(_nativeTypeNamesToStrip, value, StringExtensions.NormalizeFullPath);
}
}

Expand Down Expand Up @@ -362,6 +363,7 @@ public IReadOnlyCollection<string> TraversalNames
init
{
AddRange(_traversalNames, value, StringExtensions.NormalizePath);
AddRange(_traversalNames, value, StringExtensions.NormalizeFullPath);
}
}

Expand Down