Skip to content

Commit

Permalink
Merge pull request #72 from wackoisgod/alignof
Browse files Browse the repository at this point in the history
Alignof
  • Loading branch information
xoofx authored Feb 16, 2023
2 parents 0095344 + a643bbe commit d0d3a1f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/CppAst.Tests/TestStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct Struct3
Assert.AreEqual("Struct0", cppStruct.Name);
Assert.AreEqual(0, cppStruct.Fields.Count);
Assert.AreEqual(sizeof(byte), cppStruct.SizeOf);
Assert.AreEqual(1, cppStruct.AlignOf);
}

{
Expand All @@ -50,6 +51,7 @@ struct Struct3
Assert.True(cppStruct.BaseTypes[0].Type is CppClass);
Assert.True(ReferenceEquals(compilation.Classes[0], cppStruct.BaseTypes[0].Type));
Assert.AreEqual(sizeof(byte), cppStruct.SizeOf);
Assert.AreEqual(1, cppStruct.AlignOf);
}

{
Expand All @@ -60,6 +62,7 @@ struct Struct3
Assert.AreEqual(CppTypeKind.Primitive, cppStruct.Fields[0].Type.TypeKind);
Assert.AreEqual(CppPrimitiveKind.Int, ((CppPrimitiveType) cppStruct.Fields[0].Type).Kind);
Assert.AreEqual(sizeof(int), cppStruct.SizeOf);
Assert.AreEqual(4, cppStruct.AlignOf);
}

{
Expand All @@ -76,6 +79,7 @@ struct Struct3
Assert.AreEqual(CppVisibility.Public, cppStruct.Fields[1].Visibility);
Assert.AreEqual(sizeof(int), cppStruct.Fields[1].Offset);
Assert.AreEqual(sizeof(int) + sizeof(float), cppStruct.SizeOf);
Assert.AreEqual(4, cppStruct.AlignOf);
}
}
);
Expand Down Expand Up @@ -104,6 +108,7 @@ public void TestAnonymous()
Assert.AreEqual(2, cppStruct.Fields.Count);
Assert.AreEqual(sizeof(int), cppStruct.Fields[1].Offset);
Assert.AreEqual(sizeof(int) + sizeof(int), cppStruct.SizeOf);
Assert.AreEqual(4, cppStruct.AlignOf);
}
}
);
Expand Down
5 changes: 5 additions & 0 deletions src/CppAst/CppClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ private bool Equals(CppClass other)
/// <inheritdoc />
public override int SizeOf { get; set; }

/// <summary>
/// Gets the alignment of this instance.
/// </summary>
public int AlignOf { get; set; }

/// <inheritdoc />
public override bool Equals(object obj)
{
Expand Down
1 change: 1 addition & 0 deletions src/CppAst/CppModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private CppClass VisitClassDecl(CXCursor cursor, void* data)
cppStruct.Attributes.AddRange(ParseAttributes(cursor));
cppStruct.IsDefinition = true;
cppStruct.SizeOf = (int)cursor.Type.SizeOf;
cppStruct.AlignOf = (int)cursor.Type.AlignOf;
context.IsChildrenVisited = true;
cursor.VisitChildren(VisitMember, new CXClientData((IntPtr)data));
}
Expand Down

0 comments on commit d0d3a1f

Please sign in to comment.