diff --git a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs index d05c90b3..0a33d680 100644 --- a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs +++ b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs @@ -21,6 +21,7 @@ internal struct FunctionOrDelegateDesc public bool HasBody { get; set; } public bool IsInherited { get; set; } public bool NeedsUnscopedRef { get; set; } + public string[]? ParameterTypes { get; set; } public bool IsVirtual { diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs index 712f8c81..8380a582 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs @@ -372,6 +372,12 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM Write(desc.ParentName); Write('.'); Write(desc.EscapedName); + if (desc.ParameterTypes is not null) + { + Write('('); + Write(string.Join(", ", desc.ParameterTypes)); + Write(')'); + } WriteLine("\" />"); } else diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 23e40097..f5711355 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -501,6 +501,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) var name = GetRemappedCursorName(functionDecl); var cxxMethodDecl = functionDecl as CXXMethodDecl; + uint overloadCount = 0; if (cxxMethodDecl is not null and CXXConstructorDecl) { @@ -509,6 +510,11 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) name = GetRemappedCursorName(parent); } + if (cxxMethodDecl is not null) + { + overloadCount = GetOverloadCount(cxxMethodDecl); + } + var isManualImport = _config.WithManualImports.Contains(name); var className = name; @@ -622,6 +628,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) } }, CustomAttrGeneratorData = (functionDecl, _outputBuilder, this), + ParameterTypes = overloadCount > 1 ? functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _)).ToArray() : null, }; Debug.Assert(_outputBuilder is not null); diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 0d45f9de..ff5eab67 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -3096,6 +3096,39 @@ uint GetOverloadIndex(CXXMethodDecl cxxMethodDeclToMatch, CXXRecordDecl cxxRecor } } + private uint GetOverloadCount(CXXMethodDecl cxxMethodDeclToMatch) + { + var parent = cxxMethodDeclToMatch.Parent; + Debug.Assert(parent is not null); + + return GetOverloadIndex(cxxMethodDeclToMatch, parent, baseCount: 0); + + uint GetOverloadIndex(CXXMethodDecl cxxMethodDeclToMatch, CXXRecordDecl cxxRecordDecl, uint baseCount) + { + var count = baseCount; + + foreach (var cxxBaseSpecifier in cxxRecordDecl.Bases) + { + var baseCxxRecordDecl = GetRecordDecl(cxxBaseSpecifier); + count = GetOverloadIndex(cxxMethodDeclToMatch, baseCxxRecordDecl, count); + } + + foreach (var cxxMethodDecl in cxxRecordDecl.Methods) + { + if (IsExcluded(cxxMethodDecl)) + { + continue; + } + else if (cxxMethodDecl.Name == cxxMethodDeclToMatch.Name) + { + count++; + } + } + + return count; + } + } + private CXXRecordDecl GetRecordDecl(CXXBaseSpecifier cxxBaseSpecifier) { var baseType = cxxBaseSpecifier.Type;