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

Add Parameter Types to InheritDoc comments #590

Merged
merged 4 commits into from
Jan 31, 2025
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
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -509,6 +510,11 @@ private void VisitFunctionDecl(FunctionDecl functionDecl)
name = GetRemappedCursorName(parent);
}

if (cxxMethodDecl is not null)
{
overloadCount = GetOverloadCount(cxxMethodDecl);
tannergooding marked this conversation as resolved.
Show resolved Hide resolved
}

var isManualImport = _config.WithManualImports.Contains(name);

var className = name;
Expand Down Expand Up @@ -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);

Expand Down
33 changes: 33 additions & 0 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down