From c06b00d71cb6689d5ee209c02c0e834cdee3ae3d Mon Sep 17 00:00:00 2001 From: Andrew Spiering Date: Sun, 12 Feb 2023 01:25:34 -0800 Subject: [PATCH 1/2] Adding in support for AlignOf on CppClass --- src/CppAst.Tests/TestStructs.cs | 5 +++++ src/CppAst/CppClass.cs | 2 ++ src/CppAst/CppModelBuilder.cs | 1 + 3 files changed, 8 insertions(+) diff --git a/src/CppAst.Tests/TestStructs.cs b/src/CppAst.Tests/TestStructs.cs index 8fb4891..425bdfd 100644 --- a/src/CppAst.Tests/TestStructs.cs +++ b/src/CppAst.Tests/TestStructs.cs @@ -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); } { @@ -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); } { @@ -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); } { @@ -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); } } ); @@ -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); } } ); diff --git a/src/CppAst/CppClass.cs b/src/CppAst/CppClass.cs index 962fc46..d51800d 100644 --- a/src/CppAst/CppClass.cs +++ b/src/CppAst/CppClass.cs @@ -96,6 +96,8 @@ private bool Equals(CppClass other) /// public override int SizeOf { get; set; } + public int AlignOf { get; set; } + /// public override bool Equals(object obj) { diff --git a/src/CppAst/CppModelBuilder.cs b/src/CppAst/CppModelBuilder.cs index 0352a28..86253ae 100644 --- a/src/CppAst/CppModelBuilder.cs +++ b/src/CppAst/CppModelBuilder.cs @@ -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)); } From a643bbe685a2b6cfd16561eaef5400133a181383 Mon Sep 17 00:00:00 2001 From: Andrew Spiering Date: Sun, 12 Feb 2023 01:27:32 -0800 Subject: [PATCH 2/2] Adding a little comment --- src/CppAst/CppClass.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CppAst/CppClass.cs b/src/CppAst/CppClass.cs index d51800d..7a01c40 100644 --- a/src/CppAst/CppClass.cs +++ b/src/CppAst/CppClass.cs @@ -96,6 +96,9 @@ private bool Equals(CppClass other) /// public override int SizeOf { get; set; } + /// + /// Gets the alignment of this instance. + /// public int AlignOf { get; set; } ///