diff options
Diffstat (limited to 'lib/Edit/Commit.cpp')
-rw-r--r-- | lib/Edit/Commit.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/Edit/Commit.cpp b/lib/Edit/Commit.cpp index cb7a784a41af4..afc1a131eb258 100644 --- a/lib/Edit/Commit.cpp +++ b/lib/Edit/Commit.cpp @@ -1,4 +1,4 @@ -//===----- Commit.cpp - A unit of edits -----------------------------------===// +//===- Commit.cpp - A unit of edits ---------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -8,10 +8,16 @@ //===----------------------------------------------------------------------===// #include "clang/Edit/Commit.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Edit/EditedSource.h" +#include "clang/Edit/FileOffset.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/PPConditionalDirectiveRecord.h" +#include "llvm/ADT/StringRef.h" +#include <cassert> +#include <utility> using namespace clang; using namespace edit; @@ -36,9 +42,9 @@ CharSourceRange Commit::Edit::getInsertFromRange(SourceManager &SM) const { } Commit::Commit(EditedSource &Editor) - : SourceMgr(Editor.getSourceManager()), LangOpts(Editor.getLangOpts()), - PPRec(Editor.getPPCondDirectiveRecord()), - Editor(&Editor), IsCommitable(true) { } + : SourceMgr(Editor.getSourceManager()), LangOpts(Editor.getLangOpts()), + PPRec(Editor.getPPCondDirectiveRecord()), + Editor(&Editor) {} bool Commit::insert(SourceLocation loc, StringRef text, bool afterToken, bool beforePreviousInsertions) { @@ -225,8 +231,7 @@ bool Commit::canInsert(SourceLocation loc, FileOffset &offs) { isAtStartOfMacroExpansion(loc, &loc); const SourceManager &SM = SourceMgr; - while (SM.isMacroArgExpansion(loc)) - loc = SM.getImmediateSpellingLoc(loc); + loc = SM.getTopMacroCallerLoc(loc); if (loc.isMacroID()) if (!isAtStartOfMacroExpansion(loc, &loc)) @@ -256,8 +261,7 @@ bool Commit::canInsertAfterToken(SourceLocation loc, FileOffset &offs, isAtEndOfMacroExpansion(loc, &loc); const SourceManager &SM = SourceMgr; - while (SM.isMacroArgExpansion(loc)) - loc = SM.getImmediateSpellingLoc(loc); + loc = SM.getTopMacroCallerLoc(loc); if (loc.isMacroID()) if (!isAtEndOfMacroExpansion(loc, &loc)) @@ -278,14 +282,12 @@ bool Commit::canInsertAfterToken(SourceLocation loc, FileOffset &offs, } bool Commit::canInsertInOffset(SourceLocation OrigLoc, FileOffset Offs) { - for (unsigned i = 0, e = CachedEdits.size(); i != e; ++i) { - Edit &act = CachedEdits[i]; + for (const auto &act : CachedEdits) if (act.Kind == Act_Remove) { if (act.Offset.getFID() == Offs.getFID() && Offs > act.Offset && Offs < act.Offset.getWithOffset(act.Length)) return false; // position has been removed. } - } if (!Editor) return true; @@ -340,6 +342,7 @@ bool Commit::isAtStartOfMacroExpansion(SourceLocation loc, SourceLocation *MacroBegin) const { return Lexer::isAtStartOfMacroExpansion(loc, SourceMgr, LangOpts, MacroBegin); } + bool Commit::isAtEndOfMacroExpansion(SourceLocation loc, SourceLocation *MacroEnd) const { return Lexer::isAtEndOfMacroExpansion(loc, SourceMgr, LangOpts, MacroEnd); |