clang-format: Fix for #pragma option formatting.

Adapted patch from Sergey Razmetov. Thank you.

llvm-svn: 235492
This commit is contained in:
Daniel Jasper 2015-04-22 09:45:42 +00:00
parent cd2334e86e
commit ee4a8a140a
3 changed files with 16 additions and 2 deletions

View File

@ -545,6 +545,8 @@ struct AdditionalKeywords {
kw_throws = &IdentTable.get("throws");
kw___except = &IdentTable.get("__except");
kw_mark = &IdentTable.get("mark");
kw_option = &IdentTable.get("option");
kw_optional = &IdentTable.get("optional");
kw_repeated = &IdentTable.get("repeated");
@ -582,6 +584,9 @@ struct AdditionalKeywords {
IdentifierInfo *kw_synchronized;
IdentifierInfo *kw_throws;
// Pragma keywords.
IdentifierInfo *kw_mark;
// Proto keywords.
IdentifierInfo *kw_option;
IdentifierInfo *kw_optional;

View File

@ -582,11 +582,14 @@ private:
void parsePragma() {
next(); // Consume "pragma".
if (CurrentToken && CurrentToken->TokenText == "mark") {
if (CurrentToken &&
CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option)) {
bool IsMark = CurrentToken->is(Keywords.kw_mark);
next(); // Consume "mark".
next(); // Consume first token (so we fix leading whitespace).
while (CurrentToken) {
CurrentToken->Type = TT_ImplicitStringLiteral;
if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator))
CurrentToken->Type = TT_ImplicitStringLiteral;
next();
}
}

View File

@ -8795,6 +8795,12 @@ TEST_F(FormatTest, UnderstandsPragmas) {
"(including parentheses)."));
}
TEST_F(FormatTest, UnderstandPragmaOption) {
verifyFormat("#pragma option -C -A");
EXPECT_EQ("#pragma option -C -A", format("#pragma option -C -A"));
}
#define EXPECT_ALL_STYLES_EQUAL(Styles) \
for (size_t i = 1; i < Styles.size(); ++i) \
EXPECT_EQ(Styles[0], Styles[i]) << "Style #" << i << " of " \