Skip to content

Commit

Permalink
support inline variable parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
SatyaRanjanDas-tomtom committed Jan 8, 2025
1 parent 848a24a commit 941c577
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions cppparser/src/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ varattrib
| tknVolatile [ZZLOG;] { $$ = VOLATILE; }
| tknMutable [ZZLOG;] { $$ = MUTABLE; }
| tknConstExpr [ZZLOG;] { $$ = CONST_EXPR; }
| tknInline [ZZLOG;] { $$ = INLINE; }
;

typeconverter
Expand Down
27 changes: 27 additions & 0 deletions cppparser/test/unit/vardecl-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,30 @@ TEST_CASE_METHOD(VarDeclTest, "int variable, array_one[100], array_two[500];", "
const auto& thirdVar = varlist->varDeclList()[1];
CHECK(thirdVar.arraySizes().size() == 1);
}

#if TEST_CASE_SNIPPET_STARTS_FROM_NEXT_LINE
class A
{
public:
static const inline std::string_view dbname_ = "Company";
};
#endif

TEST_CASE_METHOD(VarDeclTest, "inline var", "[vardecl]")
{
auto testSnippet = getTestSnippetParseStream(__LINE__ - 5);

cppparser::CppParser parser;
const auto ast = parser.parseStream(testSnippet.data(), testSnippet.size());
REQUIRE(ast != nullptr);

const auto members = GetAllOwnedEntities(*ast);
REQUIRE(members.size() == 1);
const cppast::CppConstCompoundEPtr clsA = members[0];
REQUIRE(clsA);
const auto clsMembers = GetAllOwnedEntities(*clsA);
REQUIRE(clsMembers.size() == 2);
cppast::CppConstVarEPtr var = clsMembers[1];
REQUIRE(var);
CHECK((var->typeAttr() & cppast::CppIdentifierAttrib::INLINE));
}

0 comments on commit 941c577

Please sign in to comment.