18#include "llvm/ADT/StringExtras.h"
27 switch (Style.Language) {
28 case FormatStyle::LK_C:
29 case FormatStyle::LK_Cpp:
30 case FormatStyle::LK_ObjC:
31 case FormatStyle::LK_CSharp:
32 case FormatStyle::LK_Java:
33 case FormatStyle::LK_JavaScript:
40 const auto &Option = Style.NumericLiteralCase;
41 const auto Leave = FormatStyle::NLCS_Leave;
42 return Option.Prefix != Leave || Option.HexDigit != Leave ||
43 Option.ExponentLetter != Leave || Option.Suffix != Leave;
48 FormatStyle::NumericLiteralComponentStyle ConfigValue) {
49 switch (ConfigValue) {
50 case FormatStyle::NLCS_Upper:
51 return Component.upper();
52 case FormatStyle::NLCS_Lower:
53 return Component.lower();
56 return Component.str();
63 static constexpr std::array<StringRef, 11> SortedReservedSuffixes = {
64 "d",
"h",
"i",
"if",
"il",
"min",
"ms",
"ns",
"s",
"us",
"y",
69 assert(llvm::is_sorted(SortedReservedSuffixes) &&
70 "Must be sorted as precondition for lower_bound().");
72 auto entry = llvm::lower_bound(SortedReservedSuffixes, Suffix);
73 if (entry == SortedReservedSuffixes.cend())
75 return *entry == Suffix;
78static std::string
format(StringRef NumericLiteral,
const FormatStyle &Style) {
79 const char Separator = Style.isCpp() ?
'\'' :
'_';
81 const bool HasBaseLetter = Info.
BaseLetterPos != StringRef::npos;
83 const bool HasSuffix = Info.
SuffixPos != StringRef::npos;
85 std::string Formatted;
90 Style.NumericLiteralCase.Prefix);
95 NumericLiteral.slice(HasBaseLetter ? 1 + Info.
BaseLetterPos : 0,
98 : NumericLiteral.size()),
99 Style.NumericLiteralCase.HexDigit);
105 : NumericLiteral.size()),
106 Style.NumericLiteralCase.ExponentLetter);
110 StringRef Suffix = NumericLiteral.drop_front(Info.
SuffixPos);
115 Formatted += Suffix.str();
124std::pair<tooling::Replacements, unsigned>
126 const FormatStyle &Style) {
135 Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
145 auto Length =
Tok.getLength();
150 auto Location =
Tok.getLocation();
151 auto Text = StringRef(SourceMgr.getCharacterData(Location), Length);
152 if (
Tok.is(tok::comment)) {
160 if (
Skip ||
Tok.isNot(tok::numeric_constant) ||
167 if (Formatted !=
Text) {
This file declares NumericLiteralCaseFixer that standardizes character case within numeric literals.
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.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.