15#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
16#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
19#include "llvm/ADT/SmallPtrSet.h"
111 llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
117 enum class IfStmtKind {
126 bool precededByCommentOrPPDirective()
const;
127 bool parseLevel(
const FormatToken *OpeningBrace =
nullptr,
128 IfStmtKind *IfKind =
nullptr,
130 bool *SeenExplicitAccessModifier =
nullptr);
133 FormatToken *parseBlock(
bool MustBeDeclaration =
false,
134 unsigned AddLevels = 1u,
bool MunchSemi =
true,
135 bool KeepBraces =
true, IfStmtKind *IfKind =
nullptr,
136 bool UnindentWhitesmithsBraces =
false,
137 bool IndentAfterExplicitAccessModifier =
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 StarAndAmpTokenType = TT_Unknown,
155 bool InMacroCall =
false);
157 void keepAncestorBraces();
158 void parseUnbracedBody(
bool CheckEOF =
false);
159 void handleAttributes();
160 bool handleCppAttributes();
162 FormatToken *parseIfThenElse(IfStmtKind *IfKind,
bool KeepBraces =
false,
163 bool IsVerilogAssert =
false);
164 void parseTryCatch();
165 void parseLoopBody(
bool KeepBraces,
bool WrapRightBrace);
166 void parseForOrWhileLoop(
bool HasParens =
true);
168 void parseLabel(
bool IsGotoLabel =
false);
169 void parseCaseLabel();
170 void parseSwitch(
bool IsExpr);
171 void parseNamespace();
172 bool parseModuleDecl();
173 bool parseImportDecl();
175 void parseAccessSpecifier();
177 bool parseStructLike();
178 bool parseRequires(
bool SeenEqual);
179 void parseRequiresClause();
180 void parseRequiresExpression();
181 void parseConstraintExpression();
182 void parseCppExportBlock();
183 void parseNamespaceOrExportBlock(
unsigned AddLevels);
184 void parseJavaEnumBody();
188 void parseRecord(
bool ParseAsExpr =
false,
bool IsJavaRecord =
false);
189 void parseObjCLightweightGenerics();
190 void parseObjCMethod();
191 void parseObjCProtocolList();
192 void parseObjCUntilAtEnd();
193 void parseObjCInterfaceOrImplementation();
194 bool parseObjCProtocol();
195 void parseJavaScriptEs6ImportExport();
196 void parseStatementMacro();
197 void parseCSharpAttribute();
201 void parseCSharpGenericTypeConstraint();
202 bool tryToParseLambda();
203 bool tryToParseChildBlock();
204 bool tryToParseLambdaIntroducer();
205 bool tryToParsePropertyAccessor();
206 void tryToParseJSFunction();
207 bool tryToParseSimpleAttribute();
208 void parseVerilogHierarchyIdentifier();
209 void parseVerilogSensitivityList();
212 unsigned parseVerilogHierarchyHeader();
213 void parseVerilogTable();
214 void parseVerilogCaseLabel();
216 void parseVerilogExtern();
218 void skipVerilogQualifiers();
220 std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>
221 parseMacroCall(
const PPState &SavedPPState);
225 enum class LineLevel { Remove, Keep };
227 void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);
233 void nextToken(
int LevelDifference = 0);
234 void readToken(
int LevelDifference = 0);
250 void flushComments(
bool NewlineBeforeNext);
252 void calculateBraceTypes(
bool ExpectClassBody =
false);
259 void conditionalCompilationCondition(
bool Unreachable);
260 void conditionalCompilationStart(
bool Unreachable);
261 void conditionalCompilationAlternative();
262 void conditionalCompilationEnd();
273 size_t computePPHash()
const;
275 bool parsingPPDirective()
const {
return CurrentLines != &Lines; }
280 std::unique_ptr<UnwrappedLine> Line;
294 llvm::DenseMap<FormatToken *, SmallVector<UnwrappedLine, 8>> ExpandedLines;
298 llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> Unexpanded;
302 bool InExpansion =
false;
307 std::optional<MacroCallReconstructor> Reconstruct;
333 llvm::BitVector DeclarationScopeStack;
340 llvm::Regex CommentPragmasRegex;
357 bool IsDecltypeAutoFunction =
false;
367 PPBranch(PPBranchKind Kind,
size_t Line) : Kind(Kind),
Line(Line) {}
374 enum IncludeGuardState {
393 explicit PPState(IncludeGuardState IncludeGuard)
394 : IncludeGuard(IncludeGuard) {}
405 int BranchLevel = -1;
418 std::stack<int> ChainBranchIndex;
421 IncludeGuardState IncludeGuard;
428 bool AtEndOfPPLine =
false;
440 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...
Represents a complete lambda introducer.