44std::pair<tooling::Replacements, unsigned>
47 switch (Style.Language) {
61 const auto &Option = Style.IntegerLiteralSeparator;
62 const auto Binary = Option.Binary;
63 const auto Decimal = Option.Decimal;
64 const auto Hex = Option.Hex;
65 const bool SkipBinary =
Binary == 0;
66 const bool SkipDecimal =
Decimal == 0;
67 const bool SkipHex =
Hex == 0;
69 if (SkipBinary && SkipDecimal && SkipHex)
72 const auto BinaryMinDigits =
73 std::max((
int)Option.BinaryMinDigits,
Binary + 1);
74 const auto DecimalMinDigits =
75 std::max((
int)Option.DecimalMinDigits,
Decimal + 1);
76 const auto HexMinDigits = std::max((
int)Option.HexMinDigits,
Hex + 1);
78 const auto &SourceMgr =
Env.getSourceManager();
81 const auto ID =
Env.getFileID();
83 Lexer Lex(
ID, SourceMgr.getBufferOrFake(
ID), SourceMgr, LangOpts);
94 auto Text = StringRef(SourceMgr.getCharacterData(Location), Length);
95 if (Tok.
is(tok::comment)) {
102 if (Skip || Tok.
isNot(tok::numeric_constant) ||
Text[0] ==
'.' ||
111 if ((IsBase2 && SkipBinary) || (IsBase10 && SkipDecimal) ||
120 Pos != StringRef::npos) {
125 if ((IsBase10 &&
Text.find_last_of(
".eEfFdDmM") != StringRef::npos) ||
126 (IsBase16 &&
Text.find_last_of(
".pP") != StringRef::npos)) {
129 const auto Start =
Text[0] ==
'0' ? 2 : 0;
130 auto End =
Text.find_first_of(
"uUlLzZn", Start);
131 if (End == StringRef::npos)
133 if (Start > 0 || End < Length) {
134 Length = End - Start;
138 auto MinDigits = DecimalMinDigits;
141 MinDigits = BinaryMinDigits;
142 }
else if (IsBase16) {
143 DigitsPerGroup =
Hex;
144 MinDigits = HexMinDigits;
146 const auto SeparatorCount =
Text.count(Separator);
147 const int DigitCount = Length - SeparatorCount;
148 const bool RemoveSeparator = DigitsPerGroup < 0 || DigitCount < MinDigits;
149 if (RemoveSeparator && SeparatorCount == 0)
151 if (!RemoveSeparator && SeparatorCount > 0 &&
152 checkSeparator(
Text, DigitsPerGroup)) {
155 const auto &Formatted =
156 format(
Text, DigitsPerGroup, DigitCount, RemoveSeparator);
157 assert(Formatted !=
Text);
159 Location = Location.getLocWithOffset(Start);
167bool IntegerLiteralSeparatorFixer::checkSeparator(
169 assert(DigitsPerGroup > 0);
173 if (
C == Separator) {
174 if (I < DigitsPerGroup)
178 if (I == DigitsPerGroup)
187std::string IntegerLiteralSeparatorFixer::format(
const StringRef IntegerLiteral,
190 bool RemoveSeparator)
const {
191 assert(DigitsPerGroup != 0);
193 std::string Formatted;
195 if (RemoveSeparator) {
196 for (
auto C : IntegerLiteral)
198 Formatted.push_back(
C);
202 int Remainder = DigitCount % DigitsPerGroup;
205 for (
auto C : IntegerLiteral) {
208 if (I == (Remainder > 0 ? Remainder : DigitsPerGroup)) {
209 Formatted.push_back(Separator);
213 Formatted.push_back(
C);
static constexpr CPUSuffix Suffixes[]
This file declares IntegerLiteralSeparatorFixer that fixes C++ integer literal separators.
static CharSourceRange getCharRange(SourceRange R)
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
void SetCommentRetentionState(bool Mode)
SetCommentRetentionMode - Change the comment retention mode of the lexer to the specified mode.
Token - This structure provides full information about a lexed token.
SourceLocation getEndLoc() const
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
unsigned getLength() const
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
bool isNot(tok::TokenKind K) const
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.