rjelonek updated this revision to Diff 315169. rjelonek added a comment. Add support to `#pragma hdrstop( "c:\\projects\\include\\myinc.pch" )'
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D94217/new/ https://reviews.llvm.org/D94217 Files: clang/lib/Format/Format.cpp clang/unittests/Format/SortIncludesTest.cpp Index: clang/unittests/Format/SortIncludesTest.cpp =================================================================== --- clang/unittests/Format/SortIncludesTest.cpp +++ clang/unittests/Format/SortIncludesTest.cpp @@ -879,6 +879,27 @@ "#include \"a.h\"")); } +TEST_F(SortIncludesTest, DoNotTreatPrecompiledHeadersAsFirstBlock) { + Style.IncludeBlocks = Style.IBS_Merge; + std::string Code = "#include \"d.h\"\r\n" + "#include \"b.h\"\r\n" + "#pragma hdrstop\r\n" + "\r\n" + "#include \"c.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"e.h\"\r\n"; + + std::string Expected = "#include \"b.h\"\r\n" + "#include \"d.h\"\r\n" + "#pragma hdrstop\r\n" + "\r\n" + "#include \"e.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"c.h\"\r\n"; + + EXPECT_EQ(Expected, sort(Code, "e.cpp", 2)); +} + } // end namespace } // end namespace format } // end namespace clang Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2305,7 +2305,10 @@ sortCppIncludes(Style, IncludesInBlock, Ranges, FileName, Code, Replaces, Cursor); IncludesInBlock.clear(); - FirstIncludeBlock = false; + if (Trimmed.startswith("#pragma hdrstop")) // precompiled headers + FirstIncludeBlock = true; + else + FirstIncludeBlock = false; } Prev = Pos + 1; }
Index: clang/unittests/Format/SortIncludesTest.cpp =================================================================== --- clang/unittests/Format/SortIncludesTest.cpp +++ clang/unittests/Format/SortIncludesTest.cpp @@ -879,6 +879,27 @@ "#include \"a.h\"")); } +TEST_F(SortIncludesTest, DoNotTreatPrecompiledHeadersAsFirstBlock) { + Style.IncludeBlocks = Style.IBS_Merge; + std::string Code = "#include \"d.h\"\r\n" + "#include \"b.h\"\r\n" + "#pragma hdrstop\r\n" + "\r\n" + "#include \"c.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"e.h\"\r\n"; + + std::string Expected = "#include \"b.h\"\r\n" + "#include \"d.h\"\r\n" + "#pragma hdrstop\r\n" + "\r\n" + "#include \"e.h\"\r\n" + "#include \"a.h\"\r\n" + "#include \"c.h\"\r\n"; + + EXPECT_EQ(Expected, sort(Code, "e.cpp", 2)); +} + } // end namespace } // end namespace format } // end namespace clang Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2305,7 +2305,10 @@ sortCppIncludes(Style, IncludesInBlock, Ranges, FileName, Code, Replaces, Cursor); IncludesInBlock.clear(); - FirstIncludeBlock = false; + if (Trimmed.startswith("#pragma hdrstop")) // precompiled headers + FirstIncludeBlock = true; + else + FirstIncludeBlock = false; } Prev = Pos + 1; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits