owenpan updated this revision to Diff 508293. owenpan added a comment. Don't format imaginary numbers.
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146844/new/ https://reviews.llvm.org/D146844 Files: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp clang/unittests/Format/IntegerLiteralSeparatorTest.cpp Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp =================================================================== --- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp +++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp @@ -51,6 +51,18 @@ "o1 = 07;\n" "o5 = 012345", Style); + + verifyFormat("bi = 0b10000i;\n" + "dif = 1234if;\n" + "hil = 0xABCil", + Style); + + const StringRef UDL("u = 0xDEAD'BEEF'DE'AD'BEE'F_u64;"); + verifyFormat("u = 0xDE'AD'BE'EF'DE'AD'BE'EF_u64;", UDL, Style); + Style.IntegerLiteralSeparator.Hex = -1; + verifyFormat("u = 0xDEADBEEFDEADBEEF_u64;", UDL, Style); + Style.IntegerLiteralSeparator.Hex = 0; + verifyFormat(UDL, Style); } TEST_F(IntegerLiteralSeparatorTest, UnderscoreAsSeparator) { Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp =================================================================== --- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp +++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp @@ -44,10 +44,13 @@ std::pair<tooling::Replacements, unsigned> IntegerLiteralSeparatorFixer::process(const Environment &Env, const FormatStyle &Style) { + std::string Suffix("uUlLzZn"); + switch (Style.Language) { case FormatStyle::LK_Cpp: case FormatStyle::LK_ObjC: Separator = '\''; + Suffix.push_back('_'); break; case FormatStyle::LK_CSharp: case FormatStyle::LK_Java: @@ -107,7 +110,8 @@ continue; } if ((IsBase10 && Text.find_last_of(".eEfFdDmM") != StringRef::npos) || - (IsBase16 && Text.find_last_of(".pP") != StringRef::npos)) { + (IsBase16 && Text.find_last_of(".pP") != StringRef::npos) || + Text.find_last_of('i') != StringRef::npos) { continue; } if (((IsBase2 && Binary < 0) || (IsBase10 && Decimal < 0) || @@ -116,7 +120,7 @@ continue; } const auto Start = Text[0] == '0' ? 2 : 0; - auto End = Text.find_first_of("uUlLzZn"); + auto End = Text.find_first_of(Suffix, Start); if (End == StringRef::npos) End = Length; if (Start > 0 || End < Length) {
Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp =================================================================== --- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp +++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp @@ -51,6 +51,18 @@ "o1 = 07;\n" "o5 = 012345", Style); + + verifyFormat("bi = 0b10000i;\n" + "dif = 1234if;\n" + "hil = 0xABCil", + Style); + + const StringRef UDL("u = 0xDEAD'BEEF'DE'AD'BEE'F_u64;"); + verifyFormat("u = 0xDE'AD'BE'EF'DE'AD'BE'EF_u64;", UDL, Style); + Style.IntegerLiteralSeparator.Hex = -1; + verifyFormat("u = 0xDEADBEEFDEADBEEF_u64;", UDL, Style); + Style.IntegerLiteralSeparator.Hex = 0; + verifyFormat(UDL, Style); } TEST_F(IntegerLiteralSeparatorTest, UnderscoreAsSeparator) { Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp =================================================================== --- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp +++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp @@ -44,10 +44,13 @@ std::pair<tooling::Replacements, unsigned> IntegerLiteralSeparatorFixer::process(const Environment &Env, const FormatStyle &Style) { + std::string Suffix("uUlLzZn"); + switch (Style.Language) { case FormatStyle::LK_Cpp: case FormatStyle::LK_ObjC: Separator = '\''; + Suffix.push_back('_'); break; case FormatStyle::LK_CSharp: case FormatStyle::LK_Java: @@ -107,7 +110,8 @@ continue; } if ((IsBase10 && Text.find_last_of(".eEfFdDmM") != StringRef::npos) || - (IsBase16 && Text.find_last_of(".pP") != StringRef::npos)) { + (IsBase16 && Text.find_last_of(".pP") != StringRef::npos) || + Text.find_last_of('i') != StringRef::npos) { continue; } if (((IsBase2 && Binary < 0) || (IsBase10 && Decimal < 0) || @@ -116,7 +120,7 @@ continue; } const auto Start = Text[0] == '0' ? 2 : 0; - auto End = Text.find_first_of("uUlLzZn"); + auto End = Text.find_first_of(Suffix, Start); if (End == StringRef::npos) End = Length; if (Start > 0 || End < Length) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits