diff options
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index f0412cd..8b217bc 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -22,7 +22,9 @@ #include "UnwrappedLineFormatter.h" #include "UsingDeclarationsSorter.h" #include "clang/Tooling/Inclusions/HeaderIncludes.h" + #include "llvm/ADT/Sequence.h" +#include <limits> #define DEBUG_TYPE "format-formatter" @@ -777,7 +779,7 @@ template <> struct MappingTraits<FormatStyle::SpacesInLineComment> { IO.mapOptional("Maximum", signedMaximum); Space.Maximum = static_cast<unsigned>(signedMaximum); - if (Space.Maximum != -1u) + if (Space.Maximum < std::numeric_limits<unsigned>::max()) Space.Minimum = std::min(Space.Minimum, Space.Maximum); } }; @@ -1672,7 +1674,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.SpacesBeforeTrailingComments = 1; LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never; LLVMStyle.SpacesInContainerLiterals = true; - LLVMStyle.SpacesInLineCommentPrefix = {/*Minimum=*/1, /*Maximum=*/-1u}; + LLVMStyle.SpacesInLineCommentPrefix = { + /*Minimum=*/1, /*Maximum=*/std::numeric_limits<unsigned>::max()}; LLVMStyle.SpacesInParens = FormatStyle::SIPO_Never; LLVMStyle.SpacesInSquareBrackets = false; LLVMStyle.Standard = FormatStyle::LS_Latest; @@ -3168,11 +3171,12 @@ static bool affectsRange(ArrayRef<tooling::Range> Ranges, unsigned Start, // the index of the first of the duplicates as the others are going to be // removed. OffsetToEOL describes the cursor's position relative to the end of // its current line. -// If `Cursor` is not on any #include, `Index` will be UINT_MAX. +// If `Cursor` is not on any #include, `Index` will be +// std::numeric_limits<unsigned>::max(). static std::pair<unsigned, unsigned> FindCursorIndex(const ArrayRef<IncludeDirective> &Includes, const ArrayRef<unsigned> &Indices, unsigned Cursor) { - unsigned CursorIndex = UINT_MAX; + unsigned CursorIndex = std::numeric_limits<unsigned>::max(); unsigned OffsetToEOL = 0; for (int i = 0, e = Includes.size(); i != e; ++i) { unsigned Start = Includes[Indices[i]].Offset; @@ -3440,11 +3444,12 @@ tooling::Replacements sortCppIncludes(const FormatStyle &Style, StringRef Code, return Replaces; } -// Returns group number to use as a first order sort on imports. Gives UINT_MAX -// if the import does not match any given groups. +// Returns group number to use as a first order sort on imports. Gives +// std::numeric_limits<unsigned>::max() if the import does not match any given +// groups. static unsigned findJavaImportGroup(const FormatStyle &Style, StringRef ImportIdentifier) { - unsigned LongestMatchIndex = UINT_MAX; + unsigned LongestMatchIndex = std::numeric_limits<unsigned>::max(); unsigned LongestMatchLength = 0; for (unsigned I = 0; I < Style.JavaImportGroups.size(); I++) { const std::string &GroupPrefix = Style.JavaImportGroups[I]; @@ -3673,13 +3678,15 @@ formatReplacements(StringRef Code, const tooling::Replacements &Replaces, namespace { inline bool isHeaderInsertion(const tooling::Replacement &Replace) { - return Replace.getOffset() == UINT_MAX && Replace.getLength() == 0 && + return Replace.getOffset() == std::numeric_limits<unsigned>::max() && + Replace.getLength() == 0 && tooling::HeaderIncludes::IncludeRegex.match( Replace.getReplacementText()); } inline bool isHeaderDeletion(const tooling::Replacement &Replace) { - return Replace.getOffset() == UINT_MAX && Replace.getLength() == 1; + return Replace.getOffset() == std::numeric_limits<unsigned>::max() && + Replace.getLength() == 1; } // FIXME: insert empty lines between newly created blocks. @@ -3699,7 +3706,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces, consumeError(HeaderInsertions.add(R)); } else if (isHeaderDeletion(R)) { HeadersToDelete.insert(R.getReplacementText()); - } else if (R.getOffset() == UINT_MAX) { + } else if (R.getOffset() == std::numeric_limits<unsigned>::max()) { llvm::errs() << "Insertions other than header #include insertion are " "not supported! " << R.getReplacementText() << "\n"; |