Skip to content

Commit c914fcb

Browse files
Merge pull request #590 from curin/main
Add Parameter Types to InheritDoc comments
2 parents 4882174 + 98fcc16 commit c914fcb

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +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; }
2425

2526
public bool IsVirtual
2627
{

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

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

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ 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
{
@@ -509,6 +510,11 @@ private void VisitFunctionDecl(FunctionDecl functionDecl)
509510
name = GetRemappedCursorName(parent);
510511
}
511512

513+
if (cxxMethodDecl is not null)
514+
{
515+
overloadCount = GetOverloadCount(cxxMethodDecl);
516+
}
517+
512518
var isManualImport = _config.WithManualImports.Contains(name);
513519

514520
var className = name;
@@ -622,6 +628,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl)
622628
}
623629
},
624630
CustomAttrGeneratorData = (functionDecl, _outputBuilder, this),
631+
ParameterTypes = overloadCount > 1 ? functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _)).ToArray() : null,
625632
};
626633
Debug.Assert(_outputBuilder is not null);
627634

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)