diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2016-05-17 12:35:18 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2016-05-17 12:35:18 +0000 |
| commit | af34e06c694a0a9258011bb5f7480cffa3203a7c (patch) | |
| tree | 36da11f1a189ed2556899e7737cd29764a867254 /clang-tools-extra/include-fixer/IncludeFixer.cpp | |
| parent | ca9a0fe2b926e3821cf4485e7bd9b59407b474f2 (diff) | |
| download | bcm5719-llvm-af34e06c694a0a9258011bb5f7480cffa3203a7c.tar.gz bcm5719-llvm-af34e06c694a0a9258011bb5f7480cffa3203a7c.zip | |
[include-fixer] Make the "extend to the right" hack support typos without nested names in the front.
This handles cases where the initial namespace is unknown.
llvm-svn: 269758
Diffstat (limited to 'clang-tools-extra/include-fixer/IncludeFixer.cpp')
| -rw-r--r-- | clang-tools-extra/include-fixer/IncludeFixer.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/clang-tools-extra/include-fixer/IncludeFixer.cpp b/clang-tools-extra/include-fixer/IncludeFixer.cpp index 55476f95e68..f64aedcbbe9 100644 --- a/clang-tools-extra/include-fixer/IncludeFixer.cpp +++ b/clang-tools-extra/include-fixer/IncludeFixer.cpp @@ -129,11 +129,7 @@ public: } } - /// If we have a scope specification, use that to get more precise results. - std::string QueryString; - if (SS && SS->getRange().isValid()) { - auto Range = CharSourceRange::getTokenRange(SS->getRange().getBegin(), - Typo.getLoc()); + auto ExtendNestedNameSpecifier = [this](CharSourceRange Range) { StringRef Source = Lexer::getSourceText(Range, getCompilerInstance().getSourceManager(), getCompilerInstance().getLangOpts()); @@ -158,7 +154,21 @@ public: while (isIdentifierBody(*End) || *End == ':') ++End; - QueryString = std::string(Source.begin(), End); + return std::string(Source.begin(), End); + }; + + /// If we have a scope specification, use that to get more precise results. + std::string QueryString; + if (SS && SS->getRange().isValid()) { + auto Range = CharSourceRange::getTokenRange(SS->getRange().getBegin(), + Typo.getLoc()); + + QueryString = ExtendNestedNameSpecifier(Range); + } else if (Typo.getName().isIdentifier() && !Typo.getLoc().isMacroID()) { + auto Range = + CharSourceRange::getTokenRange(Typo.getBeginLoc(), Typo.getEndLoc()); + + QueryString = ExtendNestedNameSpecifier(Range); } else { QueryString = Typo.getAsString(); } |

