[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs
Shaurya Gupta via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 15 06:29:38 PDT 2019
SureYeaah updated this revision to Diff 209844.
SureYeaah marked 5 inline comments as done.
SureYeaah added a comment.
Removed unrelated changes
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D64717/new/
https://reviews.llvm.org/D64717
Files:
clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -299,10 +299,10 @@
return ^1;
}
void f() {
- int a = 5 + [[4 ^* ^xyz^()]];
+ int a = 5 + [[4 ^* xyz^()]];
// multivariable initialization
if(1)
- int x = ^1, y = ^a + 1, a = ^1, z = a + 1;
+ int x = ^1, y = [[a + 1]], a = ^1, z = a + 1;
// if without else
if(^1) {}
// if with else
@@ -320,7 +320,7 @@
a = ^2;
// while
while(a < ^1)
- ^a++;
+ [[a++]];
// do while
do
a = ^1;
@@ -340,8 +340,10 @@
return 1;
class T {
T(int a = ^1) {};
+ T f() { return T(); }
int xyz = ^1;
};
+ [[T.[[^t]]]]();
}
// function default argument
void f(int b = ^1) {
@@ -359,6 +361,10 @@
a = ^a ^+ 1;
// lambda
auto lamb = [&^a, &^b](int r = ^1) {return 1;}
+ // assigment
+ [[a ^= 5]];
+ // DeclRefExpr
+ a = [[b]], b = [[xyz]]();
}
)cpp");
// vector of pairs of input and output strings
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -77,16 +77,22 @@
return Visitor.ReferencedDecls;
}
-// An expr is not extractable if it's null or an expression of type void
-// FIXME: Ignore assignment (a = 1) Expr since it is extracted as dummy = a =
+// An expr is not extractable if it's null, an expression of type void, an
+// assignment expression, MemberExpr or a DeclRefExpr
static bool isExtractableExpr(const clang::Expr *Expr) {
- if (Expr) {
- const Type *ExprType = Expr->getType().getTypePtrOrNull();
- // FIXME: check if we need to cover any other types
- if (ExprType)
- return !ExprType->isVoidType();
- }
- return false;
+ if (!Expr)
+ return false;
+ // FIXME: check if we need to cover any other types
+ if (const Type *ExprType = Expr->getType().getTypePtrOrNull())
+ if (ExprType->isVoidType())
+ return false;
+ if (const BinaryOperator *BinOpExpr =
+ llvm::dyn_cast_or_null<BinaryOperator>(Expr))
+ if (BinOpExpr->getOpcode() == BinaryOperatorKind::BO_Assign)
+ return false;
+ if (llvm::isa<DeclRefExpr>(Expr) || llvm::isa<MemberExpr>(Expr))
+ return false;
+ return true;
}
ExtractionContext::ExtractionContext(const SelectionTree::Node *Node,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64717.209844.patch
Type: text/x-patch
Size: 2719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190715/7cb4b50c/attachment-0001.bin>
More information about the cfe-commits
mailing list