eduucaldas updated this revision to Diff 271980. eduucaldas added a comment.
Why does this work? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D82157/new/ https://reviews.llvm.org/D82157 Files: clang/lib/Tooling/Syntax/BuildTree.cpp clang/unittests/Tooling/Syntax/TreeTest.cpp
Index: clang/unittests/Tooling/Syntax/TreeTest.cpp =================================================================== --- clang/unittests/Tooling/Syntax/TreeTest.cpp +++ clang/unittests/Tooling/Syntax/TreeTest.cpp @@ -1228,6 +1228,93 @@ )txt")); } +TEST_P(SyntaxTreeTest, UserDefinedLiteral) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +long double operator "" _w(long double); +unsigned operator "" _w(const char*); +template <char...> unsigned operator "" _x(); +int main() { + 1.2_w; // calls operator "" _w(1.2L) + 12_w; // calls operator "" _w("12") + 12_x; // calls operator<'1', '2'> "" _x() +} + )cpp", + R"txt( +*: TranslationUnit +|-SimpleDeclaration +| |-long +| |-double +| |-SimpleDeclarator +| | |-operator +| | |-"" +| | |-_w +| | `-ParametersAndQualifiers +| | |-( +| | |-SimpleDeclaration +| | | |-long +| | | `-double +| | `-) +| `-; +|-SimpleDeclaration +| |-unsigned +| |-SimpleDeclarator +| | |-operator +| | |-"" +| | |-_w +| | `-ParametersAndQualifiers +| | |-( +| | |-SimpleDeclaration +| | | |-const +| | | |-char +| | | `-SimpleDeclarator +| | | `-* +| | `-) +| `-; +|-TemplateDeclaration +| |-template +| |-< +| |-SimpleDeclaration +| | `-char +| |-... +| |-> +| `-SimpleDeclaration +| |-unsigned +| |-SimpleDeclarator +| | |-operator +| | |-"" +| | |-_x +| | `-ParametersAndQualifiers +| | |-( +| | `-) +| `-; +`-SimpleDeclaration + |-int + |-SimpleDeclarator + | |-main + | `-ParametersAndQualifiers + | |-( + | `-) + `-CompoundStatement + |-{ + |-ExpressionStatement + | |-UserDefinedLiteralExpression + | | `-1.2_w + | `-; + |-ExpressionStatement + | |-UserDefinedLiteralExpression + | | `-12_w + | `-; + |-ExpressionStatement + | |-UserDefinedLiteralExpression + | | `-12_x + | `-; + `-} +)txt")); +} TEST_P(SyntaxTreeTest, IntegerLiteral) { EXPECT_TRUE(treeDumpEqual( R"cpp( Index: clang/lib/Tooling/Syntax/BuildTree.cpp =================================================================== --- clang/lib/Tooling/Syntax/BuildTree.cpp +++ clang/lib/Tooling/Syntax/BuildTree.cpp @@ -623,6 +623,19 @@ return NNS; } + bool TraverseUserDefinedLiteral(UserDefinedLiteral *S) { return true; } + + bool WalkUpFromUserDefinedLiteral(UserDefinedLiteral *S) { + // The user-defined-literal `1.2_w` is not split in the tokens `1.2` and + // `_w` as we might imagine, its tokens are `1.2_w` only. + // As a node is built by folding tokens we cannot generate one + // for `_w` + Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken); + Builder.foldNode(Builder.getExprRange(S), + new (allocator()) syntax::IntegerLiteralExpression, S); + return true; + } + bool WalkUpFromDeclRefExpr(DeclRefExpr *S) { if (auto *NNS = BuildNestedNameSpecifier(S->getQualifierLoc())) Builder.markChild(NNS, syntax::NodeRole::IdExpression_qualifier);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits