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..7a01c40 100644 --- a/src/CppAst/CppClass.cs +++ b/src/CppAst/CppClass.cs @@ -96,6 +96,11 @@ private bool Equals(CppClass other) /// public override int SizeOf { get; set; } + /// + /// Gets the alignment of this instance. + /// + 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)); }