diff options
author | Alex Lorenz <arphaman@gmail.com> | 2017-08-30 15:00:27 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2017-08-30 15:00:27 +0000 |
commit | c39a2d7279ddf0b791c44a2d85a31d763ad0ddb7 (patch) | |
tree | fe31d9543eb9be48fb7fbdab0eacdb9214e373b2 /lib/Tooling/Refactoring/ASTSelection.cpp | |
parent | 31c7a3b61a7c35ae586c7e36fbff1361e051d5ad (diff) |
[refactor] AST selection tree should contain syntactic form
of PseudoObjectExpr
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@312127 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/Refactoring/ASTSelection.cpp')
-rw-r--r-- | lib/Tooling/Refactoring/ASTSelection.cpp | 22 |
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 |