[clangd] Support extraction of binary "subexpressions" like a + [[b + c]].
Summary:
These aren't formally subexpressions in C++, in this case + is left-associative.
However informally +, *, etc are usually (mathematically) associative and users
consider these subexpressions.
We detect these and in simple cases support extracting the partial expression.
As well as builtin associative operators, we assume that overloads of them
are associative and support those too.
Reviewers: SureYeaah
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D65139
llvm-svn: 367121
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp
index 2d62fd2..d7c6759 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -452,5 +452,12 @@
llvm_unreachable("A tree must always be rooted at TranslationUnitDecl.");
}
+const SelectionTree::Node &SelectionTree::Node::ignoreImplicit() const {
+ if (Children.size() == 1 &&
+ Children.front()->ASTNode.getSourceRange() == ASTNode.getSourceRange())
+ return Children.front()->ignoreImplicit();
+ return *this;
+}
+
} // namespace clangd
} // namespace clang