Skip to content

Commit d48c915

Browse files
balazssomogyisombalazsxoofx
authored andcommitted
Improve attribute parsing (xoofx#82)
Adding support for parsing attributes defined as a macro, and parsing function attributes that are on a separate line before the function declaration. Co-authored-by: Balazs Somogyi <[email protected]> Co-authored-by: Alexandre Mutel <[email protected]>
1 parent c3f4a9a commit d48c915

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/CppAst.Tests/AttributesTest/TestTokenAttributes.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,29 @@ struct [[deprecated(""old"")]] TestMessage{
154154
[Test]
155155
public void TestCpp11StructAttributesWithMacro()
156156
{
157-
ParseAssert(@"
157+
ParseAssert(@"
158158
#define CLASS_ATTRIBUTE [[complex_attribute::attribute_name(""attribute_argument"")]]
159-
struct CLASS_ATTRIBUTE Test{
159+
struct
160+
CLASS_ATTRIBUTE
161+
Test{
160162
int a;
161163
int b;
162164
};", compilation =>
163-
{
164-
Assert.False(compilation.HasErrors);
165+
{
166+
Assert.False(compilation.HasErrors);
165167

166-
Assert.AreEqual(1, compilation.Classes.Count);
167-
Assert.AreEqual(1, compilation.Classes[0].TokenAttributes.Count);
168-
{
169-
var attr = compilation.Classes[0].TokenAttributes[0];
170-
Assert.AreEqual("complex_attribute", attr.Scope);
171-
Assert.AreEqual("attribute_name", attr.Name);
172-
Assert.AreEqual("\"attribute_argument\"", attr.Arguments);
173-
}
174-
},
175-
// we are using a C++14 attribute because it can be used everywhere
176-
new CppParserOptions() { AdditionalArguments = { "-std=c++14" }, ParseTokenAttributes = true }
177-
);
168+
Assert.AreEqual(1, compilation.Classes.Count);
169+
Assert.AreEqual(1, compilation.Classes[0].TokenAttributes.Count);
170+
{
171+
var attr = compilation.Classes[0].TokenAttributes[0];
172+
Assert.AreEqual("complex_attribute", attr.Scope);
173+
Assert.AreEqual("attribute_name", attr.Name);
174+
Assert.AreEqual("\"attribute_argument\"", attr.Arguments);
175+
}
176+
},
177+
// we are using a C++14 attribute because it can be used everywhere
178+
new CppParserOptions() { AdditionalArguments = { "-std=c++14" }, ParseTokenAttributes = true }
179+
);
178180
}
179181

180182
[Test]

0 commit comments

Comments
 (0)