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 void handleAttributes();
165 bool handleCppAttributes();
167 FormatToken *parseIfThenElse(IfStmtKind *IfKind,
bool KeepBraces =
false,
168 bool IsVerilogAssert =
false);
169 void parseTryCatch();
170 void parseLoopBody(
bool KeepBraces,
bool WrapRightBrace);
171 void parseForOrWhileLoop(
bool HasParens =
true);
173 void parseLabel(
bool IsGotoLabel =
false);
174 void parseCaseLabel();
175 void parseSwitch(
bool IsExpr);
176 void parseNamespace();
177 bool parseModuleDecl();
178 bool parseImportDecl();
180 void parseAccessSpecifier();
182 bool parseStructLike();
183 bool parseRequires(
bool SeenEqual);
184 void parseRequiresClause();
185 void parseRequiresExpression();
186 void parseConstraintExpression();
187 void parseCppExportBlock();
188 void parseNamespaceOrExportBlock(
unsigned AddLevels);
189 void parseJavaEnumBody();
193 void parseRecord(
bool ParseAsExpr =
false,
bool IsJavaRecord =
false);
194 void parseObjCLightweightGenerics();
195 void parseObjCMethod();
196 void parseObjCProtocolList();
197 void parseObjCUntilAtEnd();
198 void parseObjCInterfaceOrImplementation();
199 bool parseObjCProtocol();
200 void parseJavaScriptEs6ImportExport();
201 void parseStatementMacro();
202 void parseCSharpAttribute();
206 void parseCSharpGenericTypeConstraint();
207 bool tryToParseLambda();
208 bool tryToParseChildBlock();
209 bool tryToParseLambdaIntroducer();
210 bool tryToParsePropertyAccessor();
211 void tryToParseJSFunction();
212 bool tryToParseSimpleAttribute();
213 void parseVerilogHierarchyIdentifier();
214 void parseVerilogSensitivityList();
217 unsigned parseVerilogHierarchyHeader();
218 void parseVerilogTable();
219 void parseVerilogCaseLabel();
221 void parseVerilogExtern();
223 void skipVerilogQualifiers();
225 std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>
226 parseMacroCall(
const PPState &SavedPPState);
230 enum class LineLevel { Remove, Keep };
232 void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);
238 void nextToken(
int LevelDifference = 0);
239 void readToken(
int LevelDifference = 0);
255 void flushComments(
bool NewlineBeforeNext);
257 void calculateBraceTypes(
bool ExpectClassBody =
false);
264 void conditionalCompilationCondition(
bool Unreachable);
265 void conditionalCompilationStart(
bool Unreachable);
266 void conditionalCompilationAlternative();
267 void conditionalCompilationEnd();
278 size_t computePPHash()
const;
280 bool parsingPPDirective()
const {
return CurrentLines != &Lines; }
285 std::unique_ptr<UnwrappedLine> Line;
299 llvm::DenseMap<FormatToken *, SmallVector<UnwrappedLine, 8>> ExpandedLines;
303 llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> Unexpanded;
307 bool InExpansion =
false;
312 std::optional<MacroCallReconstructor> Reconstruct;
338 llvm::BitVector DeclarationScopeStack;
345 llvm::Regex CommentPragmasRegex;
362 bool IsDecltypeAutoFunction =
false;
372 PPBranch(PPBranchKind Kind,
size_t Line) : Kind(Kind),
Line(Line) {}
379 enum IncludeGuardState {
398 explicit PPState(IncludeGuardState IncludeGuard)
399 : IncludeGuard(IncludeGuard) {}
410 int BranchLevel = -1;
423 std::stack<int> ChainBranchIndex;
426 IncludeGuardState IncludeGuard;
433 bool AtEndOfPPLine =
false;
445 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...