[clang] [clang-format] Add an option to format integer and float literal case (PR #151590)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 3 01:58:18 PDT 2025
================
@@ -3558,6 +3558,76 @@ struct FormatStyle {
/// \version 9
std::vector<std::string> NamespaceMacros;
+ /// Control over each component in a numeric literal.
+ enum NumericLiteralComponentStyle : int8_t {
+ /// Leave this component of the literal as is.
+ NLCS_Leave,
+ /// Always format this component with upper case characters.
+ NLCS_Always,
+ /// Never format this component with upper case characters.
+ NLCS_Never,
+ };
+
+ /// Character case format for different components of a numeric literal.
+ struct NumericLiteralCaseStyle {
+ /// Format floating point exponent separator character case.
+ /// \code{.text}
+ /// /* UpperCaseFloatExponentSeparator = Leave */
+ /// float a = 6.02e23 + 1.0E10;
+ /// /* UpperCaseFloatExponentSeparator = Always */
+ /// float a = 6.02E23 + 1.0E10;
+ /// /* UpperCaseFloatExponentSeparator = Never */
+ /// float a = 6.02e23 + 1.0e10;
+ /// \endcode
+ NumericLiteralComponentStyle UpperCaseFloatExponentSeparator;
+ /// Format hexadecimal digit case.
+ /// \code{.text}
+ /// /* UpperCaseHexDigit = Leave */
+ /// a = 0xaBcDeF;
+ /// /* UpperCaseHexDigit = Always */
+ /// a = 0xABCDEF;
+ /// /* UpperCaseHexDigit = Never */
+ /// a = 0xabcdef;
+ /// \endcode
+ NumericLiteralComponentStyle UpperCaseHexDigit;
+ /// Format integer prefix case.
+ /// \code{.text}
+ /// /* UpperCasePrefix = Leave */
+ /// a = 0XF0 | 0b1;
+ /// /* UpperCasePrefix = Always */
+ /// a = 0XF0 | 0B1;
+ /// /* UpperCasePrefix = Never */
+ /// a = 0xF0 | 0b1;
+ /// \endcode
+ NumericLiteralComponentStyle UpperCasePrefix;
+ /// Format suffix case. This option excludes case-specific reserved
+ /// suffixes, such as ``min`` in C++.
+ /// \code{.text}
+ /// /* UpperCaseSuffix = Leave */
+ /// a = 1uLL;
+ /// /* UpperCaseSuffix = Always */
+ /// a = 1ULL;
+ /// /* UpperCaseSuffix = Never */
+ /// a = 1ull;
+ /// \endcode
+ NumericLiteralComponentStyle UpperCaseSuffix;
+
+ bool operator==(const NumericLiteralCaseStyle &R) const {
+ return UpperCaseFloatExponentSeparator ==
+ R.UpperCaseFloatExponentSeparator &&
+ UpperCaseHexDigit == R.UpperCaseHexDigit &&
+ UpperCasePrefix == R.UpperCasePrefix &&
+ UpperCaseSuffix == R.UpperCaseSuffix;
+ }
+ bool operator!=(const NumericLiteralCaseStyle &R) const {
----------------
HazardyKnusperkeks wrote:
```suggestion
}
bool operator!=(const NumericLiteralCaseStyle &R) const {
```
https://github.com/llvm/llvm-project/pull/151590
More information about the cfe-commits
mailing list