Skip to content

Commit 4b5d408

Browse files
committed
refactor and add getIncludeGuardState
1 parent 351e04b commit 4b5d408

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,13 @@ UnwrappedLineParser::UnwrappedLineParser(
162162
LangOpts(getFormattingLangOpts(Style)), Keywords(Keywords),
163163
CommentPragmasRegex(Style.CommentPragmas), Tokens(nullptr),
164164
Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1),
165-
IncludeGuard(Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
166-
Style.IndentPPDirectives == FormatStyle::PPDIS_Leave
167-
? IG_Rejected
168-
: IG_Inited),
165+
IncludeGuard(getIncludeGuardState(Style.IndentPPDirectives)),
169166
IncludeGuardToken(nullptr), FirstStartColumn(FirstStartColumn),
170167
Macros(Style.Macros, SourceMgr, Style, Allocator, IdentTable) {}
171168

172169
void UnwrappedLineParser::reset() {
173170
PPBranchLevel = -1;
174-
IncludeGuard = Style.IndentPPDirectives == FormatStyle::PPDIS_None ||
175-
Style.IndentPPDirectives == FormatStyle::PPDIS_Leave
176-
? IG_Rejected
177-
: IG_Inited;
171+
IncludeGuard = getIncludeGuardState(Style.IndentPPDirectives);
178172
IncludeGuardToken = nullptr;
179173
Line.reset(new UnwrappedLine);
180174
CommentsBeforeNextToken.clear();
@@ -1142,8 +1136,7 @@ void UnwrappedLineParser::parsePPEndIf() {
11421136
// If the #endif of a potential include guard is the last thing in the file,
11431137
// then we found an include guard.
11441138
if (IncludeGuard == IG_Defined && PPBranchLevel == -1 && Tokens->isEOF() &&
1145-
Style.IndentPPDirectives != FormatStyle::PPDIS_None &&
1146-
Style.IndentPPDirectives != FormatStyle::PPDIS_Leave) {
1139+
getIncludeGuardState(Style.IndentPPDirectives) == IG_Inited) {
11471140
IncludeGuard = IG_Found;
11481141
}
11491142
}

clang/lib/Format/UnwrappedLineParser.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@ class UnwrappedLineParser {
397397
// Current state of include guard search.
398398
IncludeGuardState IncludeGuard;
399399

400+
IncludeGuardState
401+
getIncludeGuardState(FormatStyle::PPDirectiveIndentStyle Style) const {
402+
return Style == FormatStyle::PPDIS_None || Style == FormatStyle::PPDIS_Leave
403+
? IG_Rejected
404+
: IG_Inited;
405+
}
406+
400407
// Points to the #ifndef condition for a potential include guard. Null unless
401408
// IncludeGuardState == IG_IfNdefed.
402409
FormatToken *IncludeGuardToken;

0 commit comments

Comments
 (0)