summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2015-06-03 13:10:41 +0000
committerManuel Klimek <klimek@google.com>2015-06-03 13:10:41 +0000
commit94a89231f6ca2c56228f5258d46c4d5d5c5581f5 (patch)
treef8e63eba32ba4408629381eebfbadbe76ed6016f /clang/lib/Tooling
parent1f58ef71ea400d52cb8be5cfdc0bfd20e1389ce5 (diff)
downloadbcm5719-llvm-94a89231f6ca2c56228f5258d46c4d5d5c5581f5.tar.gz
bcm5719-llvm-94a89231f6ca2c56228f5258d46c4d5d5c5581f5.zip
Allow replacements created from token ranges to specify language options.
The default language options will lead to incorrect replacements in C++ code, for example when trying to replace nested name specifiers ending in "::". llvm-svn: 238922
Diffstat (limited to 'clang/lib/Tooling')
-rw-r--r--clang/lib/Tooling/Core/Replacement.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp
index b9fc92bb6c7..32e8e5bd6b9 100644
--- a/clang/lib/Tooling/Core/Replacement.cpp
+++ b/clang/lib/Tooling/Core/Replacement.cpp
@@ -43,8 +43,9 @@ Replacement::Replacement(const SourceManager &Sources, SourceLocation Start,
Replacement::Replacement(const SourceManager &Sources,
const CharSourceRange &Range,
- StringRef ReplacementText) {
- setFromSourceRange(Sources, Range, ReplacementText);
+ StringRef ReplacementText,
+ const LangOptions &LangOpts) {
+ setFromSourceRange(Sources, Range, ReplacementText, LangOpts);
}
bool Replacement::isApplicable() const {
@@ -124,23 +125,25 @@ void Replacement::setFromSourceLocation(const SourceManager &Sources,
// to handle ranges for refactoring in general first - there is no obvious
// good way how to integrate this into the Lexer yet.
static int getRangeSize(const SourceManager &Sources,
- const CharSourceRange &Range) {
+ const CharSourceRange &Range,
+ const LangOptions &LangOpts) {
SourceLocation SpellingBegin = Sources.getSpellingLoc(Range.getBegin());
SourceLocation SpellingEnd = Sources.getSpellingLoc(Range.getEnd());
std::pair<FileID, unsigned> Start = Sources.getDecomposedLoc(SpellingBegin);
std::pair<FileID, unsigned> End = Sources.getDecomposedLoc(SpellingEnd);
if (Start.first != End.first) return -1;
if (Range.isTokenRange())
- End.second += Lexer::MeasureTokenLength(SpellingEnd, Sources,
- LangOptions());
+ End.second += Lexer::MeasureTokenLength(SpellingEnd, Sources, LangOpts);
return End.second - Start.second;
}
void Replacement::setFromSourceRange(const SourceManager &Sources,
const CharSourceRange &Range,
- StringRef ReplacementText) {
+ StringRef ReplacementText,
+ const LangOptions &LangOpts) {
setFromSourceLocation(Sources, Sources.getSpellingLoc(Range.getBegin()),
- getRangeSize(Sources, Range), ReplacementText);
+ getRangeSize(Sources, Range, LangOpts),
+ ReplacementText);
}
unsigned shiftedCodePosition(const Replacements &Replaces, unsigned Position) {
OpenPOWER on IntegriCloud