diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 5453f1db..fb4ad164 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -1122,7 +1122,7 @@ private void VisitRecordDecl(RecordDecl recordDecl) if (_testOutputBuilder != null) { _testOutputBuilder.AddUsingDirective("System"); - _testOutputBuilder.AddUsingDirective($"static {_config.Namespace}.{_config.MethodClassName}"); + _testOutputBuilder.AddUsingDirective($"static {GetNamespace(_config.MethodClassName)}.{_config.MethodClassName}"); _testOutputBuilder.WriteIndented("/// Validates that the of the { - AccessSpecifier = accessSpecifier, + AccessSpecifier = AccessSpecifier.Public, EscapedName = EscapeAndStripName(name), IsMemberFunction = true, NativeTypeName = nativeTypeName, @@ -1692,18 +1692,12 @@ void OutputVtblEntry(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethodDecl) var cxxMethodDeclTypeName = GetRemappedTypeName(cxxMethodDecl, cxxRecordDecl, cxxMethodDecl.Type, out var nativeTypeName, skipUsing: false, ignoreTransparentStructsWhereRequired: true); - var accessSpecifier = GetAccessSpecifier(cxxMethodDecl); var remappedName = FixupNameForMultipleHits(cxxMethodDecl); var escapedName = EscapeAndStripName(remappedName); - if (accessSpecifier == AccessSpecifier.Private) - { - accessSpecifier = AccessSpecifier.Internal; - } - var desc = new FieldDesc { - AccessSpecifier = accessSpecifier, + AccessSpecifier = AccessSpecifier.Public, NativeTypeName = nativeTypeName, EscapedName = escapedName, Offset = null, @@ -1732,7 +1726,6 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod var currentContext = _context.AddLast((cxxMethodDecl, null)); - var accessSpecifier = GetAccessSpecifier(cxxMethodDecl); var returnType = cxxMethodDecl.ReturnType; var returnTypeName = GetRemappedTypeName(cxxMethodDecl, cxxRecordDecl, returnType, out var nativeTypeName); @@ -1749,7 +1742,7 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod var desc = new FunctionOrDelegateDesc<(string Name, PInvokeGenerator This)> { - AccessSpecifier = accessSpecifier, + AccessSpecifier = AccessSpecifier.Public, IsAggressivelyInlined = _config.GenerateAggressiveInlining, EscapedName = EscapeAndStripName(name), IsMemberFunction = true, diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index c93ca931..ebb6ae2d 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -582,33 +582,63 @@ private void VisitCXXUuidofExpr(CXXUuidofExpr cxxUuidofExpr) private void VisitDeclRefExpr(DeclRefExpr declRefExpr) { var outputBuilder = StartCSharpCode(); - if ((declRefExpr.Decl is EnumConstantDecl enumConstantDecl) && (declRefExpr.DeclContext != enumConstantDecl.DeclContext) && (enumConstantDecl.DeclContext is NamedDecl namedDecl)) - { - var enumName = GetRemappedCursorName(namedDecl); - if (!_config.DontUseUsingStaticsForEnums) + var name = GetRemappedCursorName(declRefExpr.Decl, out _, skipUsing: true); + var escapedName = EscapeName(name); + + if (declRefExpr.Decl is EnumConstantDecl enumConstantDecl) + { + if ((declRefExpr.DeclContext != enumConstantDecl.DeclContext) && (enumConstantDecl.DeclContext is NamedDecl namedDecl)) { - if (enumName.StartsWith("__AnonymousEnum_")) + var enumName = GetRemappedCursorName(namedDecl, out _, skipUsing: true); + + if (!_config.DontUseUsingStaticsForEnums) { - if (outputBuilder.Name != _config.MethodClassName) + if (enumName.StartsWith("__AnonymousEnum_")) + { + if (outputBuilder.Name != _config.MethodClassName) + { + outputBuilder.AddUsingDirective($"static {GetNamespace(_config.MethodClassName)}.{_config.MethodClassName}"); + } + } + else { - outputBuilder.AddUsingDirective($"static {_config.Namespace}.{_config.MethodClassName}"); + outputBuilder.AddUsingDirective($"static {GetNamespace(enumName)}.{enumName}"); } } else { - outputBuilder.AddUsingDirective($"static {_config.Namespace}.{enumName}"); + outputBuilder.Write(enumName); + outputBuilder.Write("."); } } - else + } + else + { + if (TryGetNamespace(name, out var namespaceName)) + { + var namespaceNameParts = namespaceName.Split(';'); + namespaceName = namespaceNameParts[0]; + + if (namespaceNameParts.Length == 2) + { + if ($"{_currentNamespace}.{outputBuilder.Name}" != namespaceName) + { + outputBuilder.AddUsingDirective($"static {namespaceName}.{namespaceNameParts[1]}"); + } + } + else if (_currentNamespace != namespaceName) + { + outputBuilder.AddUsingDirective(namespaceName); + } + } + + if (declRefExpr.Decl is FunctionDecl) { - outputBuilder.Write(enumName); - outputBuilder.Write("."); + escapedName = EscapeAndStripName(name); } } - var name = GetRemappedCursorName(declRefExpr.Decl); - var escapedName = (declRefExpr.Decl is FunctionDecl) ? EscapeAndStripName(name) : EscapeName(name); outputBuilder.Write(escapedName); StopCSharpCode(); @@ -1321,7 +1351,7 @@ void HandleUnmanagedConstant(InitListExpr initListExpr, Type type, string typeNa if (_testOutputBuilder != null) { _testOutputBuilder.AddUsingDirective("System"); - _testOutputBuilder.AddUsingDirective($"static {_config.Namespace}.{_config.MethodClassName}"); + _testOutputBuilder.AddUsingDirective($"static {GetNamespace(_config.MethodClassName)}.{_config.MethodClassName}"); _testOutputBuilder.WriteIndented("/// Validates that the value of the Defines the base type of a struct as it was in the native signature."); @@ -361,7 +362,7 @@ static void GenerateNativeTypeNameAttribute(PInvokeGenerator generator) sw.WriteLine(); sw.Write("namespace "); - sw.WriteLine(config.Namespace); + sw.WriteLine(generator.GetNamespace("NativeTypeName")); sw.WriteLine('{'); sw.WriteLine(" /// Defines the type of a member as it was used in the native signature."); @@ -403,7 +404,7 @@ static void GenerateVtblIndexAttribute(PInvokeGenerator generator) sw.WriteLine(); sw.Write("namespace "); - sw.WriteLine(config.Namespace); + sw.WriteLine(generator.GetNamespace("VtblIndexAttribute")); sw.WriteLine('{'); sw.WriteLine(" /// Defines the vtbl index of a method as it was in the native signature."); @@ -452,7 +453,7 @@ static void GenerateTransparentStructs(PInvokeGenerator generator) sw.WriteLine(); sw.Write("namespace "); - sw.WriteLine(config.Namespace); + sw.WriteLine(generator.GetNamespace(name)); sw.WriteLine('{'); sw.Write(" public "); @@ -1220,11 +1221,12 @@ private void CloseOutputBuilder(Stream stream, IOutputBuilder outputBuilder, boo void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) { var indentationString = csharpOutputBuilder.IndentationString; + var nonTestName = outputBuilder.IsTestOutput ? outputBuilder.Name[0..^5] : outputBuilder.Name; if (emitNamespaceDeclaration) { sw.Write("namespace "); - sw.Write(Config.Namespace); + sw.Write(GetNamespace(nonTestName)); if (csharpOutputBuilder.IsTestOutput) { @@ -1246,7 +1248,7 @@ void ForCSharp(CSharpOutputBuilder csharpOutputBuilder) if (outputBuilder.IsTestOutput) { sw.Write("/// Provides validation of the class."); sw.Write(indentationString); } @@ -1312,7 +1314,7 @@ void ForXml(XmlOutputBuilder xmlOutputBuilder) { sw.Write(indentationString); sw.Write(""); } @@ -2055,8 +2057,15 @@ private static CXXRecordDecl GetRecordDecl(CXXBaseSpecifier cxxBaseSpecifier) private string GetRemappedCursorName(NamedDecl namedDecl) { + return GetRemappedCursorName(namedDecl, out _, skipUsing: false); + } + + private string GetRemappedCursorName(NamedDecl namedDecl, out string nativeTypeName, bool skipUsing) + { + nativeTypeName = GetCursorName(namedDecl); + var name = GetCursorQualifiedName(namedDecl); - var remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out var wasRemapped); + var remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out var wasRemapped, skipUsing); if (wasRemapped) { @@ -2064,7 +2073,7 @@ private string GetRemappedCursorName(NamedDecl namedDecl) } name = name.Replace("::", "."); - remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped); + remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped, skipUsing); if (wasRemapped) { @@ -2072,7 +2081,7 @@ private string GetRemappedCursorName(NamedDecl namedDecl) } name = GetCursorQualifiedName(namedDecl, truncateFunctionParameters: true); - remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped); + remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped, skipUsing); if (wasRemapped) { @@ -2080,15 +2089,15 @@ private string GetRemappedCursorName(NamedDecl namedDecl) } name = name.Replace("::", "."); - remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped); + remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped, skipUsing); if (wasRemapped) { return remappedName; } - name = GetCursorName(namedDecl); - remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped); + name = nativeTypeName; + remappedName = GetRemappedName(name, namedDecl, tryRemapOperatorName: true, out wasRemapped, skipUsing); if (wasRemapped) { @@ -2165,11 +2174,40 @@ private string GetRemappedName(string name, Cursor cursor, bool tryRemapOperator wasRemapped = false; return AddUsingDirectiveIfNeeded(_outputBuilder, remappedName, skipUsing); - static string AddUsingDirectiveIfNeeded(IOutputBuilder outputBuilder, string remappedName, bool skipUsing) + string AddUsingDirectiveIfNeeded(IOutputBuilder outputBuilder, string remappedName, bool skipUsing) { - if (!skipUsing && s_needsSystemSupportRegex.IsMatch(remappedName)) + if (!skipUsing) { - outputBuilder?.EmitSystemSupport(); + if (s_needsSystemSupportRegex.IsMatch(remappedName)) + { + outputBuilder?.EmitSystemSupport(); + } + + var namespaceName = GetNamespace(remappedName); + var needsUsing = false; + + if (_currentNamespace is not null) + { + var namespaceNameParts = namespaceName.Split(';'); + namespaceName = namespaceNameParts[0]; + + if (namespaceNameParts.Length != 2) + { + if (!_currentNamespace.StartsWith(namespaceName)) + { + needsUsing = true; + } + else if ((_currentNamespace.Length > namespaceName.Length) && (_currentNamespace[namespaceName.Length] != '.')) + { + needsUsing = true; + } + } + } + + if (needsUsing) + { + outputBuilder?.EmitUsingDirective(namespaceName); + } } return remappedName; @@ -2576,11 +2614,11 @@ private string GetTypeName(Cursor cursor, Cursor context, Type rootType, Type ty if (result.typeName.StartsWith("enum ")) { - result.typeName = result.typeName.Substring(5); + result.typeName = result.typeName[5..]; } else if (result.typeName.StartsWith("struct ")) { - result.typeName = result.typeName.Substring(7); + result.typeName = result.typeName[7..]; } } @@ -2853,16 +2891,6 @@ private string GetTypeNameForPointeeType(Cursor cursor, Cursor context, Type roo private void GetTypeSize(Cursor cursor, Type type, ref long alignment32, ref long alignment64, out long size32, out long size64) { - if (cursor is NamedDecl namedDecl) - { - var cursorName = GetRemappedCursorName(namedDecl); - - if (cursorName == "VkRayTracingPipelineCreateInfoKHR") - { - Debugger.Break(); - } - } - var has8BytePrimitiveField = false; GetTypeSize(cursor, type, ref alignment32, ref alignment64, ref has8BytePrimitiveField, out size32, out size64); } @@ -3234,7 +3262,7 @@ private void GetTypeSize(Cursor cursor, Type type, ref long alignment32, ref lon alignment32 = Math.Min(alignment32, maxFieldAlignment32); } - if (alignment64 == 4) + if ((alignment64 == 4) && !anyFieldIs8BytePrimitive) { alignment64 = Math.Max(alignment64, maxFieldAlignment64); } @@ -4814,6 +4842,9 @@ private void StartUsingOutputBuilder(string name, bool includeTestOutput = false { var nameTests = $"{name}Tests"; + // Set the current namespace so subsequent type lookups add the right using + _currentNamespace = GetNamespace(name); + if (_outputBuilder != null) { Debug.Assert(_outputBuilderUsers >= 1); @@ -4905,6 +4936,7 @@ private void StopUsingOutputBuilder() { if (_outputBuilderUsers == 1) { + _currentNamespace = null; _outputBuilder = null; _testOutputBuilder = null; } @@ -5216,6 +5248,27 @@ private string GetLibraryPath(string remappedName) : libraryPath; } + private string GetNamespace(string remappedName) + { + if (!TryGetNamespace(remappedName, out var namespaceName)) + { + namespaceName = _config.DefaultNamespace; + } + return namespaceName; + } + + private bool TryGetNamespace(string remappedName, out string namespaceName) + { + var index = remappedName.IndexOf('*'); + + if (index != -1) + { + remappedName = remappedName[..index]; + } + + return _config.WithNamespaces.TryGetValue(remappedName, out namespaceName); + } + private bool GetSetLastError(string remappedName) => _config.WithSetLastErrors.Contains("*") || _config.WithSetLastErrors.Contains(remappedName); diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfiguration.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfiguration.cs index 469f361a..6684d947 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfiguration.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfiguration.cs @@ -18,13 +18,14 @@ public sealed class PInvokeGeneratorConfiguration private readonly Dictionary> _withAttributes; private readonly Dictionary _withCallConvs; private readonly Dictionary _withLibraryPaths; + private readonly Dictionary _withNamespaces; private readonly Dictionary _withTransparentStructs; private readonly Dictionary _withTypes; private readonly Dictionary> _withUsings; private PInvokeGeneratorConfigurationOptions _options; - public PInvokeGeneratorConfiguration(string libraryPath, string namespaceName, string outputLocation, string testOutputLocation, PInvokeGeneratorOutputMode outputMode = PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions options = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, string headerFile = null, string methodClassName = null, string methodPrefixToStrip = null, IReadOnlyDictionary remappedNames = null, string[] traversalNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null) + public PInvokeGeneratorConfiguration(string libraryPath, string namespaceName, string outputLocation, string testOutputLocation, PInvokeGeneratorOutputMode outputMode = PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions options = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, string headerFile = null, string methodClassName = null, string methodPrefixToStrip = null, IReadOnlyDictionary remappedNames = null, string[] traversalNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null) { if (excludedNames is null) { @@ -93,6 +94,7 @@ public PInvokeGeneratorConfiguration(string libraryPath, string namespaceName, s _withAttributes = new Dictionary>(); _withCallConvs = new Dictionary(); _withLibraryPaths = new Dictionary(); + _withNamespaces = new Dictionary(); _withTransparentStructs = new Dictionary(); _withTypes = new Dictionary(); _withUsings = new Dictionary>(); @@ -102,7 +104,7 @@ public PInvokeGeneratorConfiguration(string libraryPath, string namespaceName, s LibraryPath = $@"""{libraryPath}"""; MethodClassName = methodClassName; MethodPrefixToStrip = methodPrefixToStrip; - Namespace = namespaceName; + DefaultNamespace = namespaceName; OutputMode = outputMode; OutputLocation = Path.GetFullPath(outputLocation); TestOutputLocation = !string.IsNullOrWhiteSpace(testOutputLocation) ? Path.GetFullPath(testOutputLocation) : string.Empty; @@ -135,6 +137,7 @@ public PInvokeGeneratorConfiguration(string libraryPath, string namespaceName, s AddRange(_withAttributes, withAttributes); AddRange(_withCallConvs, withCallConvs); AddRange(_withLibraryPaths, withLibraryPaths); + AddRange(_withNamespaces, withNamespaces); AddRange(_withTransparentStructs, withTransparentStructs, RemoveAtPrefix); AddRange(_withTypes, withTypes); AddRange(_withUsings, withUsings); @@ -224,7 +227,7 @@ public bool ExcludeFnptrCodegen public string MethodPrefixToStrip { get;} - public string Namespace { get; } + public string DefaultNamespace { get; } public PInvokeGeneratorOutputMode OutputMode { get; } @@ -246,6 +249,8 @@ public bool ExcludeFnptrCodegen public IReadOnlyDictionary WithLibraryPaths => _withLibraryPaths; + public IReadOnlyDictionary WithNamespaces => _withNamespaces; + public string[] WithSetLastErrors { get; } public IReadOnlyDictionary WithTransparentStructs => _withTransparentStructs; diff --git a/sources/ClangSharpPInvokeGenerator/Program.cs b/sources/ClangSharpPInvokeGenerator/Program.cs index a6f355dd..8039ff61 100644 --- a/sources/ClangSharpPInvokeGenerator/Program.cs +++ b/sources/ClangSharpPInvokeGenerator/Program.cs @@ -114,6 +114,7 @@ public static async Task Main(params string[] args) AddWithAttributeOption(s_rootCommand); AddWithCallConvOption(s_rootCommand); AddWithLibraryPathOption(s_rootCommand); + AddWithNamespaceOption(s_rootCommand); AddWithSetLastErrorOption(s_rootCommand); AddWithTransparentStructOption(s_rootCommand); AddWithTypeOption(s_rootCommand); @@ -148,6 +149,7 @@ public static int Run(InvocationContext context) var withAttributeNameValuePairs = context.ParseResult.ValueForOption("--with-attribute"); var withCallConvNameValuePairs = context.ParseResult.ValueForOption("--with-callconv"); var withLibraryPathNameValuePairs = context.ParseResult.ValueForOption("--with-librarypath"); + var withNamespaceNameValuePairs = context.ParseResult.ValueForOption("--with-namespace"); var withSetLastErrors = context.ParseResult.ValueForOption("--with-setlasterror"); var withTransparentStructNameValuePairs = context.ParseResult.ValueForOption("--with-transparent-struct"); var withTypeNameValuePairs = context.ParseResult.ValueForOption("--with-type"); @@ -188,6 +190,7 @@ public static int Run(InvocationContext context) ParseKeyValuePairs(withAttributeNameValuePairs, errorList, out Dictionary> withAttributes); ParseKeyValuePairs(withCallConvNameValuePairs, errorList, out Dictionary withCallConvs); ParseKeyValuePairs(withLibraryPathNameValuePairs, errorList, out Dictionary withLibraryPath); + ParseKeyValuePairs(withNamespaceNameValuePairs, errorList, out Dictionary withNamespaces); ParseKeyValuePairs(withTransparentStructNameValuePairs, errorList, out Dictionary withTransparentStructs); ParseKeyValuePairs(withTypeNameValuePairs, errorList, out Dictionary withTypes); ParseKeyValuePairs(withUsingNameValuePairs, errorList, out Dictionary> withUsings); @@ -527,7 +530,7 @@ public static int Run(InvocationContext context) translationFlags |= CXTranslationUnit_Flags.CXTranslationUnit_IncludeAttributedTypes; // Include attributed types in CXType translationFlags |= CXTranslationUnit_Flags.CXTranslationUnit_VisitImplicitAttributes; // Implicit attributes should be visited - var config = new PInvokeGeneratorConfiguration(libraryPath, namespaceName, outputLocation, testOutputLocation, outputMode, configOptions, excludedNames, headerFile, methodClassName, methodPrefixToStrip, remappedNames, traversalNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPath, withSetLastErrors, withTransparentStructs, withTypes, withUsings); + var config = new PInvokeGeneratorConfiguration(libraryPath, namespaceName, outputLocation, testOutputLocation, outputMode, configOptions, excludedNames, headerFile, methodClassName, methodPrefixToStrip, remappedNames, traversalNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPath, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings); if (config.GenerateMacroBindings) { @@ -1028,6 +1031,19 @@ private static void AddWithLibraryPathOption(RootCommand rootCommand) rootCommand.AddOption(option); } + private static void AddWithNamespaceOption(RootCommand rootCommand) + { + var option = new Option( + aliases: new string[] { "--with-namespace", "-wn" }, + description: "A namespace to be used for the given remapped declaration name during binding generation.", + argumentType: typeof(string), + getDefaultValue: Array.Empty, + arity: ArgumentArity.OneOrMore + ); + + rootCommand.AddOption(option); + } + private static void AddWithSetLastErrorOption(RootCommand rootCommand) { var option = new Option( diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/PInvokeGeneratorTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/PInvokeGeneratorTest.cs index 59ff851b..09b6e814 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/PInvokeGeneratorTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/PInvokeGeneratorTest.cs @@ -36,23 +36,23 @@ public abstract class PInvokeGeneratorTest protected static string EscapeXml(string value) => new XText(value).ToString(); - protected static Task ValidateGeneratedCSharpLatestWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.None | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); + protected static Task ValidateGeneratedCSharpLatestWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.None | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); - protected static Task ValidateGeneratedCSharpLatestUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); + protected static Task ValidateGeneratedCSharpLatestUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); - protected static Task ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); + protected static Task ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); - protected static Task ValidateGeneratedCSharpCompatibleUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); + protected static Task ValidateGeneratedCSharpCompatibleUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.CSharp, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); - protected static Task ValidateGeneratedXmlLatestWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null, [CallerFilePath] string filePath = "") => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.None | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs, filePath); + protected static Task ValidateGeneratedXmlLatestWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null, [CallerFilePath] string filePath = "") => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.None | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs, filePath); - protected static Task ValidateGeneratedXmlLatestUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); + protected static Task ValidateGeneratedXmlLatestUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); - protected static Task ValidateGeneratedXmlCompatibleWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); + protected static Task ValidateGeneratedXmlCompatibleWindowsBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); - protected static Task ValidateGeneratedXmlCompatibleUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); + protected static Task ValidateGeneratedXmlCompatibleUnixBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorConfigurationOptions additionalConfigOptions = PInvokeGeneratorConfigurationOptions.None, string[] excludedNames = null, IReadOnlyDictionary remappedNames = null, IReadOnlyDictionary withAccessSpecifiers = null, IReadOnlyDictionary> withAttributes = null, IReadOnlyDictionary withCallConvs = null, IReadOnlyDictionary withLibraryPaths = null, IReadOnlyDictionary withNamespaces = null, string[] withSetLastErrors = null, IReadOnlyDictionary withTransparentStructs = null, IReadOnlyDictionary withTypes = null, IReadOnlyDictionary> withUsings = null, IEnumerable expectedDiagnostics = null, string libraryPath = DefaultLibraryPath, string[] commandlineArgs = null) => ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorOutputMode.Xml, PInvokeGeneratorConfigurationOptions.GenerateCompatibleCode | PInvokeGeneratorConfigurationOptions.GenerateUnixTypes | additionalConfigOptions, excludedNames, remappedNames, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings, expectedDiagnostics, libraryPath, commandlineArgs); - private static async Task ValidateGeneratedBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorOutputMode outputMode, PInvokeGeneratorConfigurationOptions configOptions, string[] excludedNames, IReadOnlyDictionary remappedNames, IReadOnlyDictionary withAccessSpecifiers, IReadOnlyDictionary> withAttributes, IReadOnlyDictionary withCallConvs, IReadOnlyDictionary withLibraryPaths, string[] withSetLastErrors, IReadOnlyDictionary withTransparentStructs, IReadOnlyDictionary withTypes, IReadOnlyDictionary> withUsings, IEnumerable expectedDiagnostics, string libraryPath, string[] commandlineArgs, [CallerFilePath] string filePath = "") + private static async Task ValidateGeneratedBindingsAsync(string inputContents, string expectedOutputContents, PInvokeGeneratorOutputMode outputMode, PInvokeGeneratorConfigurationOptions configOptions, string[] excludedNames, IReadOnlyDictionary remappedNames, IReadOnlyDictionary withAccessSpecifiers, IReadOnlyDictionary> withAttributes, IReadOnlyDictionary withCallConvs, IReadOnlyDictionary withLibraryPaths, IReadOnlyDictionary withNamespaces, string[] withSetLastErrors, IReadOnlyDictionary withTransparentStructs, IReadOnlyDictionary withTypes, IReadOnlyDictionary> withUsings, IEnumerable expectedDiagnostics, string libraryPath, string[] commandlineArgs, [CallerFilePath] string filePath = "") { Assert.True(File.Exists(DefaultInputFileName)); @@ -64,7 +64,7 @@ private static async Task ValidateGeneratedBindingsAsync(string inputContents, s using var unsavedFile = CXUnsavedFile.Create(DefaultInputFileName, inputContents); var unsavedFiles = new CXUnsavedFile[] { unsavedFile }; - var config = new PInvokeGeneratorConfiguration(libraryPath, DefaultNamespaceName, Path.GetRandomFileName(), testOutputLocation: null, outputMode, configOptions, excludedNames, headerFile: null, methodClassName: null, methodPrefixToStrip: null, remappedNames, traversalNames: null, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withSetLastErrors, withTransparentStructs, withTypes, withUsings); + var config = new PInvokeGeneratorConfiguration(libraryPath, DefaultNamespaceName, Path.GetRandomFileName(), testOutputLocation: null, outputMode, configOptions, excludedNames, headerFile: null, methodClassName: null, methodPrefixToStrip: null, remappedNames, traversalNames: null, withAccessSpecifiers, withAttributes, withCallConvs, withLibraryPaths, withNamespaces, withSetLastErrors, withTransparentStructs, withTypes, withUsings); using (var pinvokeGenerator = new PInvokeGenerator(config, (path) => outputStream)) {