Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/lib/Format/FormatToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace clang {
namespace format {

#define LIST_TOKEN_TYPES \
TYPE(AfterPPDirective) \
TYPE(ArrayInitializerLSquare) \
TYPE(ArraySubscriptLSquare) \
TYPE(AttributeColon) \
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4941,6 +4941,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
Right.is(TT_ModulePartitionColon)) {
return true;
}

if (Right.is(TT_AfterPPDirective))
return true;

// No space between import foo:bar but keep a space between import :bar;
if (Left.is(tok::identifier) && Right.is(TT_ModulePartitionColon))
return false;
Expand Down
9 changes: 7 additions & 2 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,12 @@ void UnwrappedLineParser::parsePPDirective() {
case tok::pp_pragma:
parsePPPragma();
break;
case tok::pp_error:
case tok::pp_warning:
nextToken();
if (!eof() && Style.isCpp())
FormatTok->setFinalizedType(TT_AfterPPDirective);
[[fallthrough]];
default:
parsePPUnknown();
break;
Expand Down Expand Up @@ -1211,9 +1217,8 @@ void UnwrappedLineParser::parsePPPragma() {
}

void UnwrappedLineParser::parsePPUnknown() {
do {
while (!eof())
nextToken();
} while (!eof());
if (Style.IndentPPDirectives != FormatStyle::PPDIS_None)
Line->Level += PPBranchLevel + 1;
addUnwrappedLine();
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3635,6 +3635,13 @@ TEST_F(TokenAnnotatorTest, SwitchInMacroArgument) {
EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_FunctionLBrace);
}

TEST_F(TokenAnnotatorTest, AfterPPDirective) {
auto Tokens = annotate("#error -- My error message");

ASSERT_EQ(Tokens.size(), 7u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::minusminus, TT_AfterPPDirective);
}

} // namespace
} // namespace format
} // namespace clang
Loading