22
22
#include " UnwrappedLineFormatter.h"
23
23
#include " UsingDeclarationsSorter.h"
24
24
#include " clang/Tooling/Inclusions/HeaderIncludes.h"
25
+
25
26
#include " llvm/ADT/Sequence.h"
27
+ #include < limits>
26
28
27
29
#define DEBUG_TYPE " format-formatter"
28
30
@@ -777,7 +779,7 @@ template <> struct MappingTraits<FormatStyle::SpacesInLineComment> {
777
779
IO.mapOptional (" Maximum" , signedMaximum);
778
780
Space.Maximum = static_cast <unsigned >(signedMaximum);
779
781
780
- if (Space.Maximum != - 1u )
782
+ if (Space.Maximum < std::numeric_limits< unsigned >:: max () )
781
783
Space.Minimum = std::min (Space.Minimum , Space.Maximum );
782
784
}
783
785
};
@@ -1672,7 +1674,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
1672
1674
LLVMStyle.SpacesBeforeTrailingComments = 1 ;
1673
1675
LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never;
1674
1676
LLVMStyle.SpacesInContainerLiterals = true ;
1675
- LLVMStyle.SpacesInLineCommentPrefix = {/* Minimum=*/ 1 , /* Maximum=*/ -1u };
1677
+ LLVMStyle.SpacesInLineCommentPrefix = {
1678
+ /* Minimum=*/ 1 , /* Maximum=*/ std::numeric_limits<unsigned >::max ()};
1676
1679
LLVMStyle.SpacesInParens = FormatStyle::SIPO_Never;
1677
1680
LLVMStyle.SpacesInSquareBrackets = false ;
1678
1681
LLVMStyle.Standard = FormatStyle::LS_Latest;
@@ -3168,11 +3171,12 @@ static bool affectsRange(ArrayRef<tooling::Range> Ranges, unsigned Start,
3168
3171
// the index of the first of the duplicates as the others are going to be
3169
3172
// removed. OffsetToEOL describes the cursor's position relative to the end of
3170
3173
// its current line.
3171
- // If `Cursor` is not on any #include, `Index` will be UINT_MAX.
3174
+ // If `Cursor` is not on any #include, `Index` will be
3175
+ // std::numeric_limits<unsigned>::max().
3172
3176
static std::pair<unsigned , unsigned >
3173
3177
FindCursorIndex (const ArrayRef<IncludeDirective> &Includes,
3174
3178
const ArrayRef<unsigned > &Indices, unsigned Cursor) {
3175
- unsigned CursorIndex = UINT_MAX ;
3179
+ unsigned CursorIndex = std::numeric_limits< unsigned >:: max () ;
3176
3180
unsigned OffsetToEOL = 0 ;
3177
3181
for (int i = 0 , e = Includes.size (); i != e; ++i) {
3178
3182
unsigned Start = Includes[Indices[i]].Offset ;
@@ -3440,11 +3444,12 @@ tooling::Replacements sortCppIncludes(const FormatStyle &Style, StringRef Code,
3440
3444
return Replaces;
3441
3445
}
3442
3446
3443
- // Returns group number to use as a first order sort on imports. Gives UINT_MAX
3444
- // if the import does not match any given groups.
3447
+ // Returns group number to use as a first order sort on imports. Gives
3448
+ // std::numeric_limits<unsigned>::max() if the import does not match any given
3449
+ // groups.
3445
3450
static unsigned findJavaImportGroup (const FormatStyle &Style,
3446
3451
StringRef ImportIdentifier) {
3447
- unsigned LongestMatchIndex = UINT_MAX ;
3452
+ unsigned LongestMatchIndex = std::numeric_limits< unsigned >:: max () ;
3448
3453
unsigned LongestMatchLength = 0 ;
3449
3454
for (unsigned I = 0 ; I < Style.JavaImportGroups .size (); I++) {
3450
3455
const std::string &GroupPrefix = Style.JavaImportGroups [I];
@@ -3673,13 +3678,15 @@ formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
3673
3678
namespace {
3674
3679
3675
3680
inline bool isHeaderInsertion (const tooling::Replacement &Replace) {
3676
- return Replace.getOffset () == UINT_MAX && Replace.getLength () == 0 &&
3681
+ return Replace.getOffset () == std::numeric_limits<unsigned >::max () &&
3682
+ Replace.getLength () == 0 &&
3677
3683
tooling::HeaderIncludes::IncludeRegex.match (
3678
3684
Replace.getReplacementText ());
3679
3685
}
3680
3686
3681
3687
inline bool isHeaderDeletion (const tooling::Replacement &Replace) {
3682
- return Replace.getOffset () == UINT_MAX && Replace.getLength () == 1 ;
3688
+ return Replace.getOffset () == std::numeric_limits<unsigned >::max () &&
3689
+ Replace.getLength () == 1 ;
3683
3690
}
3684
3691
3685
3692
// FIXME: insert empty lines between newly created blocks.
@@ -3699,7 +3706,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces,
3699
3706
consumeError (HeaderInsertions.add (R));
3700
3707
} else if (isHeaderDeletion (R)) {
3701
3708
HeadersToDelete.insert (R.getReplacementText ());
3702
- } else if (R.getOffset () == UINT_MAX ) {
3709
+ } else if (R.getOffset () == std::numeric_limits< unsigned >:: max () ) {
3703
3710
llvm::errs () << " Insertions other than header #include insertion are "
3704
3711
" not supported! "
3705
3712
<< R.getReplacementText () << " \n " ;
0 commit comments