diff options
| author | 2019-01-27 16:42:12 +0000 | |
|---|---|---|
| committer | 2019-01-27 16:42:12 +0000 | |
| commit | b773203fb58f3ef282fb69c832d8710cab5bc82d (patch) | |
| tree | e75913f147570fbd75169647b144df85b88a038c /gnu/llvm/tools/clang/lib/Edit/Commit.cpp | |
| parent | tweak errno in previous (diff) | |
| download | wireguard-openbsd-b773203fb58f3ef282fb69c832d8710cab5bc82d.tar.xz wireguard-openbsd-b773203fb58f3ef282fb69c832d8710cab5bc82d.zip | |
Import LLVM 7.0.1 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Edit/Commit.cpp')
| -rw-r--r-- | gnu/llvm/tools/clang/lib/Edit/Commit.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/gnu/llvm/tools/clang/lib/Edit/Commit.cpp b/gnu/llvm/tools/clang/lib/Edit/Commit.cpp index cb7a784a41a..e72b13cf819 100644 --- a/gnu/llvm/tools/clang/lib/Edit/Commit.cpp +++ b/gnu/llvm/tools/clang/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) { @@ -141,7 +147,7 @@ bool Commit::replaceWithInner(CharSourceRange range, } FileOffset OuterEnd = OuterBegin.getWithOffset(OuterLen); - FileOffset InnerEnd = InnerBegin.getWithOffset(InnerLen); + FileOffset InnerEnd = InnerBegin.getWithOffset(InnerLen); if (OuterBegin.getFID() != InnerBegin.getFID() || InnerBegin < OuterBegin || InnerBegin > OuterEnd || @@ -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; @@ -298,7 +300,7 @@ bool Commit::canRemoveRange(CharSourceRange range, range = Lexer::makeFileCharRange(range, SM, LangOpts); if (range.isInvalid()) return false; - + if (range.getBegin().isMacroID() || range.getEnd().isMacroID()) return false; if (SM.isInSystemHeader(range.getBegin()) || @@ -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); |
