Skip to content

Commit

Permalink
Revert code for anonymous nested types (not sure why I did this in th…
Browse files Browse the repository at this point in the history
…e 1st place)
  • Loading branch information
xoofx committed May 19, 2024
1 parent 1fbed1e commit c6b63e5
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions src/CppAst/CppModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,43 +325,10 @@ private CXChildVisitResult VisitMember(CXCursor cursor, CXCursor parent, void* d
case CXCursorKind.CXCursor_StructDecl:
case CXCursorKind.CXCursor_UnionDecl:
{
bool isAnonymous = cursor.IsAnonymous;
var cppClass = VisitClassDecl(cursor, data);
var containerContext = GetOrCreateDeclarationContainer(parent, data);
// Empty struct/class/union declaration are considered as fields
if (isAnonymous)
{
cppClass.Name = string.Empty;
Debug.Assert(string.IsNullOrEmpty(cppClass.Name));

// We try to recover the offset from the previous field
// Might not be always correct (with alignment rules),
// but not sure how to recover the offset without recalculating the entire offsets
var offset = 0;
var cppClassContainer = containerContext.Container as CppClass;
if (cppClassContainer is object && cppClassContainer.Fields.Count > 0)
{
var lastField = cppClassContainer.Fields[cppClassContainer.Fields.Count - 1];
offset = (int)lastField.Offset + lastField.Type.SizeOf;
}

// Create an anonymous field for the type
var cppField = new CppField(cppClass, string.Empty)
{
Visibility = containerContext.CurrentVisibility,
StorageQualifier = GetStorageQualifier(cursor),
IsAnonymous = true,
Offset = offset,
};
ParseAttributes(cursor, cppField, true);
containerContext.DeclarationContainer.Fields.Add(cppField);
element = cppField;
}
else
{
cppClass.Visibility = containerContext.CurrentVisibility;
element = cppClass;
}
cppClass.Visibility = containerContext.CurrentVisibility;
element = cppClass;
break;
}

Expand Down

0 comments on commit c6b63e5

Please sign in to comment.