diff options
author | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-10-10 02:34:47 +0000 |
---|---|---|
committer | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-10-10 02:34:47 +0000 |
commit | fbdf83521b17c4683e4f819587000bbce71d928b (patch) | |
tree | 729317d14b678ab28d26557e4d46478783435cc4 /clang/lib/Tooling/Refactoring/SourceCode.cpp | |
parent | 79a8476d4363912553d5165a055601bcd417e8ff (diff) | |
download | bcm5719-llvm-fbdf83521b17c4683e4f819587000bbce71d928b.tar.gz bcm5719-llvm-fbdf83521b17c4683e4f819587000bbce71d928b.zip |
[libTooling] Move Transformer files to their own directory/library.
Summary:
The Transformer library has been growing inside of
lib/Tooling/Refactoring. However, it's not really related to anything else in
that directory. This revision moves all Transformer-related files into their own
include & lib directories. A followup revision will (temporarily) add
forwarding headers to help any users migrate their code to the new location.
Reviewers: gribozavr
Subscribers: mgorny, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68637
llvm-svn: 374271
Diffstat (limited to 'clang/lib/Tooling/Refactoring/SourceCode.cpp')
-rw-r--r-- | clang/lib/Tooling/Refactoring/SourceCode.cpp | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/clang/lib/Tooling/Refactoring/SourceCode.cpp b/clang/lib/Tooling/Refactoring/SourceCode.cpp deleted file mode 100644 index cee8f43f3e6..00000000000 --- a/clang/lib/Tooling/Refactoring/SourceCode.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//===--- SourceCode.cpp - Source code manipulation routines -----*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file provides functions that simplify extraction of source code. -// -//===----------------------------------------------------------------------===// -#include "clang/Tooling/Refactoring/SourceCode.h" -#include "clang/Lex/Lexer.h" - -using namespace clang; - -StringRef clang::tooling::getText(CharSourceRange Range, - const ASTContext &Context) { - return Lexer::getSourceText(Range, Context.getSourceManager(), - Context.getLangOpts()); -} - -CharSourceRange clang::tooling::maybeExtendRange(CharSourceRange Range, - tok::TokenKind Next, - ASTContext &Context) { - Optional<Token> Tok = Lexer::findNextToken( - Range.getEnd(), Context.getSourceManager(), Context.getLangOpts()); - if (!Tok || !Tok->is(Next)) - return Range; - return CharSourceRange::getTokenRange(Range.getBegin(), Tok->getLocation()); -} - -llvm::Optional<CharSourceRange> -clang::tooling::getRangeForEdit(const CharSourceRange &EditRange, - const SourceManager &SM, - const LangOptions &LangOpts) { - // FIXME: makeFileCharRange() has the disadvantage of stripping off "identity" - // macros. For example, if we're looking to rewrite the int literal 3 to 6, - // and we have the following definition: - // #define DO_NOTHING(x) x - // then - // foo(DO_NOTHING(3)) - // will be rewritten to - // foo(6) - // rather than the arguably better - // foo(DO_NOTHING(6)) - // Decide whether the current behavior is desirable and modify if not. - CharSourceRange Range = Lexer::makeFileCharRange(EditRange, SM, LangOpts); - if (Range.isInvalid()) - return None; - - if (Range.getBegin().isMacroID() || Range.getEnd().isMacroID()) - return None; - if (SM.isInSystemHeader(Range.getBegin()) || - SM.isInSystemHeader(Range.getEnd())) - return None; - - std::pair<FileID, unsigned> BeginInfo = SM.getDecomposedLoc(Range.getBegin()); - std::pair<FileID, unsigned> EndInfo = SM.getDecomposedLoc(Range.getEnd()); - if (BeginInfo.first != EndInfo.first || - BeginInfo.second > EndInfo.second) - return None; - - return Range; -} |