15#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
16#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
24struct UnwrappedLineNode;
107 llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
113 enum class IfStmtKind {
122 bool precededByCommentOrPPDirective()
const;
123 bool parseLevel(
const FormatToken *OpeningBrace =
nullptr,
124 IfStmtKind *IfKind =
nullptr,
128 FormatToken *parseBlock(
bool MustBeDeclaration =
false,
129 unsigned AddLevels = 1u,
bool MunchSemi =
true,
130 bool KeepBraces =
true, IfStmtKind *IfKind =
nullptr,
131 bool UnindentWhitesmithsBraces =
false);
132 void parseChildBlock();
133 void parsePPDirective();
134 void parsePPDefine();
135 void parsePPIf(
bool IfDef);
138 void parsePPPragma();
139 void parsePPUnknown();
140 void readTokenWithJavaScriptASI();
141 void parseStructuralElement(
const FormatToken *OpeningBrace =
nullptr,
142 IfStmtKind *IfKind =
nullptr,
144 bool *HasDoWhile =
nullptr,
145 bool *HasLabel =
nullptr);
146 bool tryToParseBracedList();
147 bool parseBracedList(
bool IsAngleBracket =
false,
bool IsEnum =
false);
148 bool parseParens(
TokenType AmpAmpTokenType = TT_Unknown,
149 bool InMacroCall =
false);
151 void keepAncestorBraces();
152 void parseUnbracedBody(
bool CheckEOF =
false);
153 void handleAttributes();
154 bool handleCppAttributes();
156 FormatToken *parseIfThenElse(IfStmtKind *IfKind,
bool KeepBraces =
false,
157 bool IsVerilogAssert =
false);
158 void parseTryCatch();
159 void parseLoopBody(
bool KeepBraces,
bool WrapRightBrace);
160 void parseForOrWhileLoop(
bool HasParens =
true);
162 void parseLabel(
bool LeftAlignLabel =
false);
163 void parseCaseLabel();
164 void parseSwitch(
bool IsExpr);
165 void parseNamespace();
166 bool parseModuleImport();
168 void parseAccessSpecifier();
170 bool parseStructLike();
171 bool parseRequires(
bool SeenEqual);
172 void parseRequiresClause(
FormatToken *RequiresToken);
173 void parseRequiresExpression(
FormatToken *RequiresToken);
174 void parseConstraintExpression();
175 void parseCppExportBlock();
176 void parseNamespaceOrExportBlock(
unsigned AddLevels);
177 void parseJavaEnumBody();
181 void parseRecord(
bool ParseAsExpr =
false,
bool IsJavaRecord =
false);
182 void parseObjCLightweightGenerics();
183 void parseObjCMethod();
184 void parseObjCProtocolList();
185 void parseObjCUntilAtEnd();
186 void parseObjCInterfaceOrImplementation();
187 bool parseObjCProtocol();
188 void parseJavaScriptEs6ImportExport();
189 void parseStatementMacro();
190 void parseCSharpAttribute();
194 void parseCSharpGenericTypeConstraint();
195 bool tryToParseLambda();
196 bool tryToParseChildBlock();
197 bool tryToParseLambdaIntroducer();
198 bool tryToParsePropertyAccessor();
199 void tryToParseJSFunction();
200 bool tryToParseSimpleAttribute();
201 void parseVerilogHierarchyIdentifier();
202 void parseVerilogSensitivityList();
205 unsigned parseVerilogHierarchyHeader();
206 void parseVerilogTable();
207 void parseVerilogCaseLabel();
208 std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>
213 enum class LineLevel { Remove, Keep };
215 void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);
221 void nextToken(
int LevelDifference = 0);
222 void readToken(
int LevelDifference = 0);
238 void flushComments(
bool NewlineBeforeNext);
240 void calculateBraceTypes(
bool ExpectClassBody =
false);
247 void conditionalCompilationCondition(
bool Unreachable);
248 void conditionalCompilationStart(
bool Unreachable);
249 void conditionalCompilationAlternative();
250 void conditionalCompilationEnd();
261 size_t computePPHash()
const;
263 bool parsingPPDirective()
const {
return CurrentLines != &Lines; }
268 std::unique_ptr<UnwrappedLine> Line;
282 llvm::DenseMap<FormatToken *, SmallVector<UnwrappedLine, 8>> ExpandedLines;
286 llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> Unexpanded;
290 bool InExpansion =
false;
295 std::optional<MacroCallReconstructor> Reconstruct;
324 llvm::BitVector DeclarationScopeStack;
331 llvm::Regex CommentPragmasRegex;
348 bool IsDecltypeAutoFunction =
false;
358 PPBranch(PPBranchKind Kind,
size_t Line) : Kind(Kind), Line(Line) {}
385 std::stack<int> PPChainBranchIndex;
389 enum IncludeGuardState {
398 IncludeGuardState IncludeGuard;
407 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.
The JSON file list parser is used to communicate input to InstallAPI.
Represents a complete lambda introducer.