diff options
author | Alex Lorenz <arphaman@gmail.com> | 2017-08-30 13:24:37 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2017-08-30 13:24:37 +0000 |
commit | 23654b501c819f79e91781eaa85a3b4e6985f1f8 (patch) | |
tree | 953b45e9d0dd1c754bbd198f0379258c27e43cd8 /clang/lib/Tooling/Refactoring/ASTSelection.cpp | |
parent | 7b8183fdabfe88add2514ebecf2ae621f8ef91aa (diff) | |
download | bcm5719-llvm-23654b501c819f79e91781eaa85a3b4e6985f1f8.tar.gz bcm5719-llvm-23654b501c819f79e91781eaa85a3b4e6985f1f8.zip |
[refactor] Examine the whole range for ObjC @implementation decls
when computing the AST selection
llvm-svn: 312121
Diffstat (limited to 'clang/lib/Tooling/Refactoring/ASTSelection.cpp')
-rw-r--r-- | clang/lib/Tooling/Refactoring/ASTSelection.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/Tooling/Refactoring/ASTSelection.cpp b/clang/lib/Tooling/Refactoring/ASTSelection.cpp index 0bf5d95624e..4fa00866978 100644 --- a/clang/lib/Tooling/Refactoring/ASTSelection.cpp +++ b/clang/lib/Tooling/Refactoring/ASTSelection.cpp @@ -17,6 +17,21 @@ using ast_type_traits::DynTypedNode; namespace { +CharSourceRange getLexicalDeclRange(Decl *D, const SourceManager &SM, + const LangOptions &LangOpts) { + if (!isa<ObjCImplDecl>(D)) + return CharSourceRange::getTokenRange(D->getSourceRange()); + // Objective-C implementation declarations end at the '@' instead of the 'end' + // keyword. Use the lexer to find the location right after 'end'. + SourceRange R = D->getSourceRange(); + SourceLocation LocAfterEnd = Lexer::findLocationAfterToken( + R.getEnd(), tok::raw_identifier, SM, LangOpts, + /*SkipTrailingWhitespaceAndNewLine=*/false); + return LocAfterEnd.isValid() + ? CharSourceRange::getCharRange(R.getBegin(), LocAfterEnd) + : CharSourceRange::getTokenRange(R); +} + /// Constructs the tree of selected AST nodes that either contain the location /// of the cursor or overlap with the selection range. class ASTSelectionFinder @@ -62,9 +77,8 @@ public: if (SM.getFileID(FileLoc) != TargetFile) return true; - // FIXME (Alex Lorenz): Add location adjustment for ObjCImplDecls. SourceSelectionKind SelectionKind = - selectionKindFor(CharSourceRange::getTokenRange(D->getSourceRange())); + selectionKindFor(getLexicalDeclRange(D, SM, Context.getLangOpts())); SelectionStack.push_back( SelectedASTNode(DynTypedNode::create(*D), SelectionKind)); LexicallyOrderedRecursiveASTVisitor::TraverseDecl(D); |