eduucaldas created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Given an UserDefinedLiteral `1.2_w`: Problem: Lexer generates one Token for the literal, but ClangAST references two source locations Fix: Ignore the operator and interpret it as the underlying literal. e.g.: `1.2_w` token generates syntax node IntegerLiteral(1.2_w) Repository: rG LLVM Github Monorepo 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,95 @@ )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 + | |-UnknownExpression + | | `-UnknownExpression + | | `-1.2_w + | `-; + |-ExpressionStatement + | |-UnknownExpression + | | `-UnknownExpression + | | `-12_w + | `-; + |-ExpressionStatement + | |-UnknownExpression + | | `-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 @@ -624,6 +624,9 @@ } bool WalkUpFromDeclRefExpr(DeclRefExpr *S) { + if (S->getNameInfo().getName().getNameKind() == + clang::DeclarationName::CXXLiteralOperatorName) + return true; 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