Skip to content

Commit

Permalink
Merge pull request #318 from tannergooding/main
Browse files Browse the repository at this point in the history
Fix when the base vtbl is emitted inline
  • Loading branch information
tannergooding authored Dec 26, 2021
2 parents bdbc056 + a2a9fb2 commit 82e6715
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
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

0 comments on commit 82e6715

Please sign in to comment.