From 55dbed804bb40df7c40c98fd0e3e2057d89d0d02 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 2 Nov 2017 18:05:48 +0000 Subject: [refactor][selection] canonicalize selected string literal to objc string literal when possible git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317224 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Tooling/Refactoring/ASTSelection.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'lib/Tooling/Refactoring/ASTSelection.cpp') diff --git a/lib/Tooling/Refactoring/ASTSelection.cpp b/lib/Tooling/Refactoring/ASTSelection.cpp index 71a0d44be1..ab2be15512 100644 --- a/lib/Tooling/Refactoring/ASTSelection.cpp +++ b/lib/Tooling/Refactoring/ASTSelection.cpp @@ -249,9 +249,30 @@ struct SelectedNodeWithParents { SelectedNodeWithParents &operator=(SelectedNodeWithParents &&) = default; SelectedASTNode::ReferenceType Node; llvm::SmallVector Parents; + + /// Canonicalizes the given selection by selecting different related AST nodes + /// when it makes sense to do so. + void canonicalize(); }; } // end anonymous namespace +void SelectedNodeWithParents::canonicalize() { + const Stmt *S = Node.get().Node.get(); + assert(S && "non statement selection!"); + const Stmt *Parent = Parents[Parents.size() - 1].get().Node.get(); + if (!Parent) + return; + // Select the parent expression when: + // - The string literal in ObjC string literal is selected, e.g.: + // @"test" becomes @"test" + // ~~~~~~ ~~~~~~~ + if (isa(S) && isa(Parent)) + Node = Parents.pop_back_val(); + // FIXME: Syntactic form -> Entire pseudo-object expr. + // FIXME: Callee -> Call. + // FIXME: Callee member expr -> Call. +} + /// Finds the set of bottom-most selected AST nodes that are in the selection /// tree with the specified selection kind. /// @@ -330,7 +351,7 @@ CodeRangeASTSelection::create(SourceRange SelectionRange, return None; const Stmt *CodeRangeStmt = Selected.Node.get().Node.get(); if (!isa(CodeRangeStmt)) { - // FIXME (Alex L): Canonicalize. + Selected.canonicalize(); return CodeRangeASTSelection(Selected.Node, Selected.Parents, /*AreChildrenSelected=*/false); } -- cgit v1.2.3