[PATCH] D86699: [SyntaxTree] Ignore implicit non-leaf `CXXConstructExpr`
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 31 10:26:41 PDT 2020
eduucaldas updated this revision to Diff 288984.
eduucaldas added a comment.
Use `IgnoreExpr.h` infrastructure.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86699/new/
https://reviews.llvm.org/D86699
Files:
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===================================================================
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -1745,19 +1745,15 @@
struct X {
friend X operator+(X, const X&);
};
-// FIXME: Remove additional `UnknownExpression` wrapping `x`. For that, ignore
-// implicit copy constructor called on `x`. This should've been ignored already,
-// as we `IgnoreImplicit` when traversing an `Stmt`.
void test(X x, X y) {
[[x + y]];
}
)cpp",
{R"txt(
BinaryOperatorExpression Expression
-|-UnknownExpression LeftHandSide
-| `-IdExpression
-| `-UnqualifiedId UnqualifiedId
-| `-'x'
+|-IdExpression LeftHandSide
+| `-UnqualifiedId UnqualifiedId
+| `-'x'
|-'+' OperatorToken
`-IdExpression RightHandSide
`-UnqualifiedId UnqualifiedId
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===================================================================
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -13,6 +13,7 @@
#include "clang/AST/DeclarationName.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
+#include "clang/AST/IgnoreExpr.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/TypeLoc.h"
@@ -44,8 +45,25 @@
using namespace clang;
+static Expr *ignoreImplicitCXXConstructExpr(Expr *E) {
+ if (auto *C = dyn_cast<CXXConstructExpr>(E)) {
+ auto NumArgs = C->getNumArgs();
+ if (NumArgs == 1 || (NumArgs > 1 && isa<CXXDefaultArgExpr>(C->getArg(1)))) {
+ auto *A = C->getArg(0);
+ if (A->getSourceRange() == E->getSourceRange())
+ return A;
+ }
+ }
+ return E;
+}
+
+static Expr *ignoreImplicit(Expr *E) {
+ return IgnoreExprNodes(E, IgnoreImplicitSingleStep,
+ ignoreImplicitCXXConstructExpr);
+}
+
LLVM_ATTRIBUTE_UNUSED
-static bool isImplicitExpr(Expr *E) { return E->IgnoreImplicit() != E; }
+static bool isImplicitExpr(Expr *E) { return ignoreImplicit(E) != E; }
namespace {
/// Get start location of the Declarator from the TypeLoc.
@@ -740,7 +758,7 @@
for (auto *D : DS->decls())
Builder.noticeDeclWithoutSemicolon(D);
} else if (auto *E = dyn_cast_or_null<Expr>(S)) {
- return RecursiveASTVisitor::TraverseStmt(E->IgnoreImplicit());
+ return RecursiveASTVisitor::TraverseStmt(ignoreImplicit(E));
}
return RecursiveASTVisitor::TraverseStmt(S);
}
@@ -1579,7 +1597,7 @@
void syntax::TreeBuilder::markExprChild(Expr *Child, NodeRole Role) {
if (!Child)
return;
- Child = Child->IgnoreImplicit();
+ Child = ignoreImplicit(Child);
syntax::Tree *ChildNode = Mapping.find(Child);
assert(ChildNode != nullptr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86699.288984.patch
Type: text/x-patch
Size: 2782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200831/6c9ff126/attachment.bin>
More information about the cfe-commits
mailing list