15#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
16#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
19#include "llvm/ADT/SmallPtrSet.h"
114 llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
120 enum class IfStmtKind {
129 bool precededByCommentOrPPDirective()
const;
130 bool parseLevel(
const FormatToken *OpeningBrace =
nullptr,
131 IfStmtKind *IfKind =
nullptr,
133 bool *SeenExplicitAccessModifier =
nullptr);
136 FormatToken *parseBlock(
bool MustBeDeclaration =
false,
137 unsigned AddLevels = 1u,
bool MunchSemi =
true,
138 bool KeepBraces =
true, IfStmtKind *IfKind =
nullptr,
139 bool UnindentWhitesmithsBraces =
false,
140 bool IndentAfterExplicitAccessModifier =
false);
141 void parseChildBlock();
142 void parsePPDirective();
143 void parsePPDefine();
144 void parsePPIf(
bool IfDef);
147 void parsePPPragma();
148 void parsePPUnknown();
149 void readTokenWithJavaScriptASI();
150 void parseStructuralElement(
const FormatToken *OpeningBrace =
nullptr,
151 IfStmtKind *IfKind =
nullptr,
153 bool *HasDoWhile =
nullptr,
154 bool *HasLabel =
nullptr);
155 bool tryToParseBracedList();
156 bool parseBracedList(
bool IsAngleBracket =
false,
bool IsEnum =
false);
157 bool parseParens(
TokenType StarAndAmpTokenType = TT_Unknown,
158 bool InMacroCall =
false);
161 void parseSquare(
bool SkipLambda =
false);
162 void keepAncestorBraces();
163 void parseUnbracedBody(
bool CheckEOF =
false);
164 bool isFollowedByConditionalElse()
const;
167 void handleAttributes();
168 bool handleCppAttributes();
170 FormatToken *parseIfThenElse(IfStmtKind *IfKind,
bool KeepBraces =
false,
171 bool IsVerilogAssert =
false);
172 void parseTryCatch();
173 void parseLoopBody(
bool KeepBraces,
bool WrapRightBrace);
174 void parseForOrWhileLoop(
bool HasParens =
true);
176 void parseLabel(
bool IsGotoLabel =
false);
177 void parseCaseLabel();
178 void parseSwitch(
bool IsExpr);
179 void parseNamespace();
180 bool parseModuleDecl();
181 bool parseImportDecl();
183 void parseAccessSpecifier();
185 bool parseStructLike();
186 bool parseRequires(
bool SeenEqual);
187 void parseRequiresClause();
188 void parseRequiresExpression();
189 void parseConstraintExpression();
190 void parseCppExportBlock();
191 void parseNamespaceOrExportBlock(
unsigned AddLevels);
192 void parseJavaEnumBody();
196 void parseRecord(
bool ParseAsExpr =
false,
bool IsJavaRecord =
false);
197 void parseObjCLightweightGenerics();
198 void parseObjCMethod();
199 void parseObjCProtocolList();
200 void parseObjCUntilAtEnd();
201 void parseObjCInterfaceOrImplementation();
202 bool parseObjCProtocol();
203 void parseJavaScriptEs6ImportExport();
204 void parseStatementMacro();
205 void parseCSharpAttribute();
209 void parseCSharpGenericTypeConstraint();
210 bool tryToParseLambda();
211 bool tryToParseChildBlock();
212 bool tryToParseLambdaIntroducer();
213 bool tryToParsePropertyAccessor();
214 void tryToParseJSFunction();
215 bool tryToParseSimpleAttribute();
216 void parseVerilogHierarchyIdentifier();
217 void parseVerilogSensitivityList();
220 unsigned parseVerilogHierarchyHeader();
221 void parseVerilogTable();
222 void parseVerilogCaseLabel();
224 void parseVerilogExtern();
226 void skipVerilogQualifiers();
228 std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>
229 parseMacroCall(
const PPState &SavedPPState);
233 enum class LineLevel { Remove, Keep };
235 void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);
241 void nextToken(
int LevelDifference = 0);
242 void readToken(
int LevelDifference = 0);
258 void flushComments(
bool NewlineBeforeNext);
260 void calculateBraceTypes(
bool ExpectClassBody =
false);
267 void conditionalCompilationCondition(
bool Unreachable);
268 void conditionalCompilationStart(
bool Unreachable);
269 void conditionalCompilationAlternative();
270 void conditionalCompilationEnd();
281 size_t computePPHash()
const;
283 bool parsingPPDirective()
const {
return CurrentLines != &Lines; }
288 std::unique_ptr<UnwrappedLine> Line;
302 llvm::DenseMap<FormatToken *, SmallVector<UnwrappedLine, 8>> ExpandedLines;
306 llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> Unexpanded;
310 bool InExpansion =
false;
315 std::optional<MacroCallReconstructor> Reconstruct;
341 llvm::BitVector DeclarationScopeStack;
348 llvm::Regex CommentPragmasRegex;
365 bool IsDecltypeAutoFunction =
false;
375 PPBranch(PPBranchKind Kind,
size_t Line) : Kind(Kind),
Line(Line) {}
382 enum IncludeGuardState {
401 explicit PPState(IncludeGuardState IncludeGuard)
402 : IncludeGuard(IncludeGuard) {}
413 int BranchLevel = -1;
426 std::stack<int> ChainBranchIndex;
429 IncludeGuardState IncludeGuard;
436 bool AtEndOfPPLine =
false;
446 const FormatToken *TokenAfterIfWithConditionalElse =
nullptr;
451 unsigned FirstStartColumn;
This file contains the main building blocks of macro support in clang-format.
Implements an efficient mapping from strings to IdentifierInfo nodes.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
This class handles loading and caching of source files into memory.
The base class of the type hierarchy.
Top level wrappers for InstallAPI frontend operations.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...