From 701a0d7e47ca48e43a2bbdfbdd31065a9f9552a6 Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Wed, 20 Mar 2019 20:49:43 +0000 Subject: [clang-format] BeforeHash added to IndentPPDirectives Summary: The option BeforeHash added to IndentPPDirectives. Fixes Bug 36019. https://bugs.llvm.org/show_bug.cgi?id=36019 Reviewers: djasper, klimek, krasimir, sammccall, mprobst, Nicola, MyDeveloperDay Reviewed By: klimek, MyDeveloperDay Subscribers: kadircet, MyDeveloperDay, mnussbaum, geleji, ufna, cfe-commits Patch by to-mix. Differential Revision: https://reviews.llvm.org/D52150 llvm-svn: 356613 --- clang/lib/Format/UnwrappedLineParser.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'clang/lib/Format/UnwrappedLineParser.cpp') diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 3abb6f40d74..4bd71aa26d5 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -655,6 +655,7 @@ void UnwrappedLineParser::parseChildBlock() { void UnwrappedLineParser::parsePPDirective() { assert(FormatTok->Tok.is(tok::hash) && "'#' expected"); ScopedMacroState MacroState(*Line, Tokens, FormatTok); + nextToken(); if (!FormatTok->Tok.getIdentifierInfo()) { @@ -823,7 +824,7 @@ void UnwrappedLineParser::parsePPDefine() { FormatTok->WhitespaceRange.getEnd()) { parseParens(); } - if (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash) + if (Style.IndentPPDirectives != FormatStyle::PPDIS_None) Line->Level += PPBranchLevel + 1; addUnwrappedLine(); ++Line->Level; @@ -840,7 +841,7 @@ void UnwrappedLineParser::parsePPUnknown() { do { nextToken(); } while (!eof()); - if (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash) + if (Style.IndentPPDirectives != FormatStyle::PPDIS_None) Line->Level += PPBranchLevel + 1; addUnwrappedLine(); } @@ -2671,6 +2672,9 @@ void UnwrappedLineParser::readToken(int LevelDifference) { // Comments stored before the preprocessor directive need to be output // before the preprocessor directive, at the same level as the // preprocessor directive, as we consider them to apply to the directive. + if (Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHash && + PPBranchLevel > 0) + Line->Level += PPBranchLevel; flushComments(isOnNewLine(*FormatTok)); parsePPDirective(); } -- cgit v1.2.3