15#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
16#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/BitVector.h"
25#include "llvm/Support/Regex.h"
33struct UnwrappedLineNode;
113 llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
119 enum class IfStmtKind {
128 bool precededByCommentOrPPDirective()
const;
129 bool parseLevel(
const FormatToken *OpeningBrace =
nullptr,
130 IfStmtKind *IfKind =
nullptr,
134 FormatToken *parseBlock(
bool MustBeDeclaration =
false,
135 unsigned AddLevels = 1u,
bool MunchSemi =
true,
136 bool KeepBraces =
true, IfStmtKind *IfKind =
nullptr,
137 bool UnindentWhitesmithsBraces =
false);
138 void parseChildBlock();
139 void parsePPDirective();
140 void parsePPDefine();
141 void parsePPIf(
bool IfDef);
144 void parsePPPragma();
145 void parsePPUnknown();
146 void readTokenWithJavaScriptASI();
147 void parseStructuralElement(
const FormatToken *OpeningBrace =
nullptr,
148 IfStmtKind *IfKind =
nullptr,
150 bool *HasDoWhile =
nullptr,
151 bool *HasLabel =
nullptr);
152 bool tryToParseBracedList();
153 bool parseBracedList(
bool IsAngleBracket =
false,
bool IsEnum =
false);
154 bool parseParens(
TokenType AmpAmpTokenType = TT_Unknown);
156 void keepAncestorBraces();
157 void parseUnbracedBody(
bool CheckEOF =
false);
158 void handleAttributes();
159 bool handleCppAttributes();
161 FormatToken *parseIfThenElse(IfStmtKind *IfKind,
bool KeepBraces =
false,
162 bool IsVerilogAssert =
false);
163 void parseTryCatch();
164 void parseLoopBody(
bool KeepBraces,
bool WrapRightBrace);
165 void parseForOrWhileLoop(
bool HasParens =
true);
167 void parseLabel(
bool LeftAlignLabel =
false);
168 void parseCaseLabel();
170 void parseNamespace();
171 bool parseModuleImport();
173 void parseAccessSpecifier();
175 bool parseStructLike();
176 bool parseRequires();
177 void parseRequiresClause(
FormatToken *RequiresToken);
178 void parseRequiresExpression(
FormatToken *RequiresToken);
179 void parseConstraintExpression();
180 void parseJavaEnumBody();
184 void parseRecord(
bool ParseAsExpr =
false);
185 void parseObjCLightweightGenerics();
186 void parseObjCMethod();
187 void parseObjCProtocolList();
188 void parseObjCUntilAtEnd();
189 void parseObjCInterfaceOrImplementation();
190 bool parseObjCProtocol();
191 void parseJavaScriptEs6ImportExport();
192 void parseStatementMacro();
193 void parseCSharpAttribute();
197 void parseCSharpGenericTypeConstraint();
198 bool tryToParseLambda();
199 bool tryToParseChildBlock();
200 bool tryToParseLambdaIntroducer();
201 bool tryToParsePropertyAccessor();
202 void tryToParseJSFunction();
203 bool tryToParseSimpleAttribute();
204 void parseVerilogHierarchyIdentifier();
205 void parseVerilogSensitivityList();
208 unsigned parseVerilogHierarchyHeader();
209 void parseVerilogTable();
210 void parseVerilogCaseLabel();
211 std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>
216 enum class LineLevel { Remove, Keep };
218 void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);
224 void nextToken(
int LevelDifference = 0);
225 void readToken(
int LevelDifference = 0);
241 void flushComments(
bool NewlineBeforeNext);
243 void calculateBraceTypes(
bool ExpectClassBody =
false);
250 void conditionalCompilationCondition(
bool Unreachable);
251 void conditionalCompilationStart(
bool Unreachable);
252 void conditionalCompilationAlternative();
253 void conditionalCompilationEnd();
264 size_t computePPHash()
const;
266 bool parsingPPDirective()
const {
return CurrentLines != &Lines; }
271 std::unique_ptr<UnwrappedLine> Line;
285 llvm::DenseMap<FormatToken *, SmallVector<UnwrappedLine, 8>> ExpandedLines;
289 llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> Unexpanded;
293 bool InExpansion =
false;
298 std::optional<MacroCallReconstructor> Reconstruct;
306 bool MustBreakBeforeNextToken;
324 llvm::BitVector DeclarationScopeStack;
329 llvm::Regex CommentPragmasRegex;
346 bool IsDecltypeAutoFunction =
false;
356 PPBranch(PPBranchKind Kind,
size_t Line) : Kind(Kind), Line(Line) {}
383 std::stack<int> PPChainBranchIndex;
387 enum IncludeGuardState {
396 IncludeGuardState IncludeGuard;
405 unsigned FirstStartColumn;
Contains functions for text encoding manipulation.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
This file contains the main building blocks of macro support in clang-format.
Implements an efficient mapping from strings to IdentifierInfo nodes.
This class handles loading and caching of source files into memory.
The base class of the type hierarchy.
Represents a complete lambda introducer.