Skip to content

Commit 941c577

Browse files
support inline variable parsing
1 parent 848a24a commit 941c577

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

cppparser/src/parser.y

+1
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ varattrib
11291129
| tknVolatile [ZZLOG;] { $$ = VOLATILE; }
11301130
| tknMutable [ZZLOG;] { $$ = MUTABLE; }
11311131
| tknConstExpr [ZZLOG;] { $$ = CONST_EXPR; }
1132+
| tknInline [ZZLOG;] { $$ = INLINE; }
11321133
;
11331134

11341135
typeconverter

cppparser/test/unit/vardecl-test.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,30 @@ TEST_CASE_METHOD(VarDeclTest, "int variable, array_one[100], array_two[500];", "
7171
const auto& thirdVar = varlist->varDeclList()[1];
7272
CHECK(thirdVar.arraySizes().size() == 1);
7373
}
74+
75+
#if TEST_CASE_SNIPPET_STARTS_FROM_NEXT_LINE
76+
class A
77+
{
78+
public:
79+
static const inline std::string_view dbname_ = "Company";
80+
};
81+
#endif
82+
83+
TEST_CASE_METHOD(VarDeclTest, "inline var", "[vardecl]")
84+
{
85+
auto testSnippet = getTestSnippetParseStream(__LINE__ - 5);
86+
87+
cppparser::CppParser parser;
88+
const auto ast = parser.parseStream(testSnippet.data(), testSnippet.size());
89+
REQUIRE(ast != nullptr);
90+
91+
const auto members = GetAllOwnedEntities(*ast);
92+
REQUIRE(members.size() == 1);
93+
const cppast::CppConstCompoundEPtr clsA = members[0];
94+
REQUIRE(clsA);
95+
const auto clsMembers = GetAllOwnedEntities(*clsA);
96+
REQUIRE(clsMembers.size() == 2);
97+
cppast::CppConstVarEPtr var = clsMembers[1];
98+
REQUIRE(var);
99+
CHECK((var->typeAttr() & cppast::CppIdentifierAttrib::INLINE));
100+
}

0 commit comments

Comments
 (0)