Skip to content

Commit d557274

Browse files
committed
Adjust to only add parameters to inherit doc if necessary
1 parent 43759a9 commit d557274

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal struct FunctionOrDelegateDesc
2121
public bool HasBody { get; set; }
2222
public bool IsInherited { get; set; }
2323
public bool NeedsUnscopedRef { get; set; }
24-
public string[] ParameterTypes { get; set; }
24+
public string[]? ParameterTypes { get; set; }
2525

2626
public bool IsVirtual
2727
{

sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,12 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM
372372
Write(desc.ParentName);
373373
Write('.');
374374
Write(desc.EscapedName);
375-
Write('(');
376-
Write(string.Join(", ", desc.ParameterTypes));
377-
Write(')');
375+
if (desc.ParameterTypes is not null && desc.ParameterTypes.Length > 0)
376+
{
377+
Write('(');
378+
Write(string.Join(", ", desc.ParameterTypes));
379+
Write(')');
380+
}
378381
WriteLine("\" />");
379382
}
380383
else

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,15 @@ private void VisitFunctionDecl(FunctionDecl functionDecl)
501501
var name = GetRemappedCursorName(functionDecl);
502502

503503
var cxxMethodDecl = functionDecl as CXXMethodDecl;
504+
uint overloadCount = 0;
504505

505506
if (cxxMethodDecl is not null and CXXConstructorDecl)
506507
{
507508
var parent = cxxMethodDecl.Parent;
508509
Debug.Assert(parent is not null);
509510
name = GetRemappedCursorName(parent);
511+
512+
overloadCount = GetOverloadCount(cxxMethodDecl);
510513
}
511514

512515
var isManualImport = _config.WithManualImports.Contains(name);
@@ -622,7 +625,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl)
622625
}
623626
},
624627
CustomAttrGeneratorData = (functionDecl, _outputBuilder, this),
625-
ParameterTypes = functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _)).ToArray(),
628+
ParameterTypes = overloadCount > 1 ? functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _)).ToArray() : null,
626629
};
627630
Debug.Assert(_outputBuilder is not null);
628631

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,6 +3096,39 @@ uint GetOverloadIndex(CXXMethodDecl cxxMethodDeclToMatch, CXXRecordDecl cxxRecor
30963096
}
30973097
}
30983098

3099+
private uint GetOverloadCount(CXXMethodDecl cxxMethodDeclToMatch)
3100+
{
3101+
var parent = cxxMethodDeclToMatch.Parent;
3102+
Debug.Assert(parent is not null);
3103+
3104+
return GetOverloadIndex(cxxMethodDeclToMatch, parent, baseCount: 0);
3105+
3106+
uint GetOverloadIndex(CXXMethodDecl cxxMethodDeclToMatch, CXXRecordDecl cxxRecordDecl, uint baseCount)
3107+
{
3108+
var count = baseCount;
3109+
3110+
foreach (var cxxBaseSpecifier in cxxRecordDecl.Bases)
3111+
{
3112+
var baseCxxRecordDecl = GetRecordDecl(cxxBaseSpecifier);
3113+
count = GetOverloadIndex(cxxMethodDeclToMatch, baseCxxRecordDecl, count);
3114+
}
3115+
3116+
foreach (var cxxMethodDecl in cxxRecordDecl.Methods)
3117+
{
3118+
if (IsExcluded(cxxMethodDecl))
3119+
{
3120+
continue;
3121+
}
3122+
else if (cxxMethodDecl.Name == cxxMethodDeclToMatch.Name)
3123+
{
3124+
count++;
3125+
}
3126+
}
3127+
3128+
return count;
3129+
}
3130+
}
3131+
30993132
private CXXRecordDecl GetRecordDecl(CXXBaseSpecifier cxxBaseSpecifier)
31003133
{
31013134
var baseType = cxxBaseSpecifier.Type;

0 commit comments

Comments
 (0)