diff options
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.h | 2 | ||||
-rw-r--r-- | clang/lib/Format/Format.cpp | 2 |
3 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index d4bf6ecfa91..872545660ca 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -63,7 +63,8 @@ ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style, bool BinPackInconclusiveFunctions) : Style(Style), SourceMgr(SourceMgr), Whitespaces(Whitespaces), Encoding(Encoding), - BinPackInconclusiveFunctions(BinPackInconclusiveFunctions) {} + BinPackInconclusiveFunctions(BinPackInconclusiveFunctions), + CommentPragmasRegex(Style.CommentPragmas) {} LineState ContinuationIndenter::getInitialState(unsigned FirstIndent, const AnnotatedLine *Line, @@ -810,12 +811,16 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, return 0; } } else if (Current.Type == TT_BlockComment && Current.isTrailingComment()) { + if (CommentPragmasRegex.match(Current.TokenText.substr(2))) + return 0; Token.reset(new BreakableBlockComment( Current, State.Line->Level, StartColumn, Current.OriginalColumn, !Current.Previous, State.Line->InPPDirective, Encoding, Style)); } else if (Current.Type == TT_LineComment && (Current.Previous == NULL || Current.Previous->Type != TT_ImplicitStringLiteral)) { + if (CommentPragmasRegex.match(Current.TokenText.substr(2))) + return 0; Token.reset(new BreakableLineComment(Current, State.Line->Level, StartColumn, /*InPPDirective=*/false, Encoding, Style)); diff --git a/clang/lib/Format/ContinuationIndenter.h b/clang/lib/Format/ContinuationIndenter.h index 41f3f4b8808..2b33f5b0fd2 100644 --- a/clang/lib/Format/ContinuationIndenter.h +++ b/clang/lib/Format/ContinuationIndenter.h @@ -18,6 +18,7 @@ #include "Encoding.h" #include "clang/Format/Format.h" +#include "llvm/Support/Regex.h" namespace clang { class SourceManager; @@ -122,6 +123,7 @@ private: WhitespaceManager &Whitespaces; encoding::Encoding Encoding; bool BinPackInconclusiveFunctions; + llvm::Regex CommentPragmasRegex; }; struct ParenState { diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 7eb7a2c9c88..2d03a30b25b 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -193,6 +193,7 @@ template <> struct MappingTraits<FormatStyle> { IO.mapOptional("SpaceBeforeAssignmentOperators", Style.SpaceBeforeAssignmentOperators); IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth); + IO.mapOptional("CommentPragmas", Style.CommentPragmas); // For backward compatibility. if (!IO.outputting()) { @@ -275,6 +276,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.SpaceBeforeAssignmentOperators = true; LLVMStyle.ContinuationIndentWidth = 4; LLVMStyle.SpacesInAngles = false; + LLVMStyle.CommentPragmas = "^ IWYU pragma:"; LLVMStyle.PenaltyBreakComment = 300; LLVMStyle.PenaltyBreakFirstLessLess = 120; |