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

Fix when the base vtbl is emitted inline #318

Merged
merged 1 commit into from
Dec 26, 2021
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 @@ -1444,7 +1444,7 @@ private void VisitRecordDecl(RecordDecl recordDecl)
}
}

if (hasVtbl || (hasBaseVtbl && !HasField(cxxRecordDecl)))
if (hasVtbl || (hasBaseVtbl && !HasBaseField(cxxRecordDecl)))
{
var fieldDesc = new FieldDesc {
AccessSpecifier = AccessSpecifier.Public,
Expand Down
50 changes: 36 additions & 14 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3720,25 +3720,34 @@ private bool HasSuppressGCTransition(Cursor cursor)
return HasRemapping(namedDecl, _config.WithSuppressGCTransitions);
}

private bool HasField(RecordDecl recordDecl)
private bool HasBaseField(CXXRecordDecl cxxRecordDecl)
{
var hasFields = recordDecl.Fields.Any() || recordDecl.Decls.Any((decl) => (decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymousStructOrUnion && HasField(nestedRecordDecl));
var hasBaseField = false;

if (!hasFields && (recordDecl is CXXRecordDecl cxxRecordDecl))
foreach (var cxxBaseSpecifier in cxxRecordDecl.Bases)
{
foreach (var cxxBaseSpecifier in cxxRecordDecl.Bases)
{
var baseCxxRecordDecl = GetRecordDecl(cxxBaseSpecifier);
var baseCxxRecordDecl = GetRecordDecl(cxxBaseSpecifier);

if (HasField(baseCxxRecordDecl))
{
hasFields = true;
break;
}
if (HasField(baseCxxRecordDecl))
{
hasBaseField = true;
break;
}
}

return hasFields;
return hasBaseField;
}

private bool HasField(RecordDecl recordDecl)
{
var hasField = recordDecl.Fields.Any() || recordDecl.Decls.Any((decl) => (decl is RecordDecl nestedRecordDecl) && nestedRecordDecl.IsAnonymousStructOrUnion && HasField(nestedRecordDecl));

if (!hasField && (recordDecl is CXXRecordDecl cxxRecordDecl))
{
hasField = HasBaseField(cxxRecordDecl);
}

return hasField;
}

private bool HasUnsafeMethod(CXXRecordDecl cxxRecordDecl)
Expand Down Expand Up @@ -3899,6 +3908,7 @@ bool IsExcludedByName(Cursor cursor, ref uint isExcludedValue)
var isExcludedByConfigOption = false;

string qualifiedName;
string qualifiedNameWithoutParameters = "";
string name;
string kind;

Expand All @@ -3908,6 +3918,12 @@ bool IsExcludedByName(Cursor cursor, ref uint isExcludedValue)
// can remove no-definition declarations in favor of remapped anonymous declarations.

qualifiedName = GetCursorQualifiedName(namedDecl);

if (namedDecl is FunctionDecl)
{
qualifiedNameWithoutParameters = GetCursorQualifiedName(namedDecl, truncateFunctionParameters: true);
}

name = GetCursorName(namedDecl);
kind = $"{namedDecl.DeclKindName} declaration";

Expand Down Expand Up @@ -3992,7 +4008,9 @@ bool IsExcludedByName(Cursor cursor, ref uint isExcludedValue)
return true;
}

if (_config.ExcludedNames.Contains(name))
var dottedQualifiedNameWithoutParameters = qualifiedNameWithoutParameters.Replace("::", ".");

if (_config.ExcludedNames.Contains(qualifiedNameWithoutParameters) || _config.ExcludedNames.Contains(dottedQualifiedNameWithoutParameters) || _config.ExcludedNames.Contains(name))
{
if (_config.LogExclusions)
{
Expand Down Expand Up @@ -4021,7 +4039,11 @@ bool IsExcludedByName(Cursor cursor, ref uint isExcludedValue)
return true;
}

if (_config.IncludedNames.Any() && !_config.IncludedNames.Contains(qualifiedName) && !_config.IncludedNames.Contains(dottedQualifiedName) && !_config.IncludedNames.Contains(name))
if (_config.IncludedNames.Any() && !_config.IncludedNames.Contains(qualifiedName)
&& !_config.IncludedNames.Contains(dottedQualifiedName)
&& !_config.IncludedNames.Contains(qualifiedNameWithoutParameters)
&& !_config.IncludedNames.Contains(dottedQualifiedNameWithoutParameters)
&& !_config.IncludedNames.Contains(name))
{
if (_config.LogExclusions)
{
Expand Down