summaryrefslogtreecommitdiffstats
path: root/lib/Tooling/Refactoring
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-08-30 15:28:01 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-08-30 15:28:01 +0000
commit372f6de315f595de2447aba414265588525e8adc (patch)
tree0041c67e65de36f8afb78065cd1946ee66c07ddc /lib/Tooling/Refactoring
parent4ad0f6316a7ab5616c300986bbe9b23712cc9088 (diff)
Recommit r312127: [refactor] AST selection tree should contain syntactic
form of PseudoObjectExpr The new commit adjusts unittest test code compilation options so that the Objective-C code in the unittest can be parsed on non-macOS platforms. Original message: The AST selection finder now constructs a selection tree that contains only the syntactic form of PseudoObjectExpr. This form of selection tree is more meaningful when doing downstream analysis as we're interested in the syntactic features of the AST and the correct lexical parent relation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312132 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/Refactoring')
-rw-r--r--lib/Tooling/Refactoring/ASTSelection.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Tooling/Refactoring/ASTSelection.cpp b/lib/Tooling/Refactoring/ASTSelection.cpp
index 4fa0086697..841b9e384d 100644
--- a/lib/Tooling/Refactoring/ASTSelection.cpp
+++ b/lib/Tooling/Refactoring/ASTSelection.cpp
@@ -10,6 +10,7 @@
#include "clang/Tooling/Refactoring/ASTSelection.h"
#include "clang/AST/LexicallyOrderedRecursiveASTVisitor.h"
#include "clang/Lex/Lexer.h"
+#include "llvm/Support/SaveAndRestore.h"
using namespace clang;
using namespace tooling;
@@ -60,6 +61,21 @@ public:
return std::move(Result);
}
+ bool TraversePseudoObjectExpr(PseudoObjectExpr *E) {
+ // Avoid traversing the semantic expressions. They should be handled by
+ // looking through the appropriate opaque expressions in order to build
+ // a meaningful selection tree.
+ llvm::SaveAndRestore<bool> LookThrough(LookThroughOpaqueValueExprs, true);
+ return TraverseStmt(E->getSyntacticForm());
+ }
+
+ bool TraverseOpaqueValueExpr(OpaqueValueExpr *E) {
+ if (!LookThroughOpaqueValueExprs)
+ return true;
+ llvm::SaveAndRestore<bool> LookThrough(LookThroughOpaqueValueExprs, false);
+ return TraverseStmt(E->getSourceExpr());
+ }
+
bool TraverseDecl(Decl *D) {
if (isa<TranslationUnitDecl>(D))
return LexicallyOrderedRecursiveASTVisitor::TraverseDecl(D);
@@ -97,6 +113,8 @@ public:
bool TraverseStmt(Stmt *S) {
if (!S)
return true;
+ if (auto *Opaque = dyn_cast<OpaqueValueExpr>(S))
+ return TraverseOpaqueValueExpr(Opaque);
// FIXME (Alex Lorenz): Improve handling for macro locations.
SourceSelectionKind SelectionKind =
selectionKindFor(CharSourceRange::getTokenRange(S->getSourceRange()));
@@ -149,6 +167,10 @@ private:
FileID TargetFile;
const ASTContext &Context;
std::vector<SelectedASTNode> SelectionStack;
+ /// Controls whether we can traverse through the OpaqueValueExpr. This is
+ /// typically enabled during the traversal of syntactic form for
+ /// PseudoObjectExprs.
+ bool LookThroughOpaqueValueExprs = false;
};
} // end anonymous namespace