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;
165 void handleAttributes();
166 bool handleCppAttributes();
168 FormatToken *parseIfThenElse(IfStmtKind *IfKind,
bool KeepBraces =
false,
169 bool IsVerilogAssert =
false);
170 void parseTryCatch();
171 void parseLoopBody(
bool KeepBraces,
bool WrapRightBrace);
172 void parseForOrWhileLoop(
bool HasParens =
true);
174 void parseLabel(
bool IsGotoLabel =
false);
175 void parseCaseLabel();
176 void parseSwitch(
bool IsExpr);
177 void parseNamespace();
178 bool parseModuleDecl();
179 bool parseImportDecl();
181 void parseAccessSpecifier();
183 bool parseStructLike();
184 bool parseRequires(
bool SeenEqual);
185 void parseRequiresClause();
186 void parseRequiresExpression();
187 void parseConstraintExpression();
188 void parseCppExportBlock();
189 void parseNamespaceOrExportBlock(
unsigned AddLevels);
190 void parseJavaEnumBody();
194 void parseRecord(
bool ParseAsExpr =
false,
bool IsJavaRecord =
false);
195 void parseObjCLightweightGenerics();
196 void parseObjCMethod();
197 void parseObjCProtocolList();
198 void parseObjCUntilAtEnd();
199 void parseObjCInterfaceOrImplementation();
200 bool parseObjCProtocol();
201 void parseJavaScriptEs6ImportExport();
202 void parseStatementMacro();
203 void parseCSharpAttribute();
207 void parseCSharpGenericTypeConstraint();
208 bool tryToParseLambda();
209 bool tryToParseChildBlock();
210 bool tryToParseLambdaIntroducer();
211 bool tryToParsePropertyAccessor();
212 void tryToParseJSFunction();
213 bool tryToParseSimpleAttribute();
214 void parseVerilogHierarchyIdentifier();
215 void parseVerilogSensitivityList();
218 unsigned parseVerilogHierarchyHeader();
219 void parseVerilogTable();
220 void parseVerilogCaseLabel();
222 void parseVerilogExtern();
224 void skipVerilogQualifiers();
226 std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>
227 parseMacroCall(
const PPState &SavedPPState);
231 enum class LineLevel { Remove, Keep };
233 void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);
239 void nextToken(
int LevelDifference = 0);
240 void readToken(
int LevelDifference = 0);
256 void flushComments(
bool NewlineBeforeNext);
258 void calculateBraceTypes(
bool ExpectClassBody =
false);
265 void conditionalCompilationCondition(
bool Unreachable);
266 void conditionalCompilationStart(
bool Unreachable);
267 void conditionalCompilationAlternative();
268 void conditionalCompilationEnd();
279 size_t computePPHash()
const;
281 bool parsingPPDirective()
const {
return CurrentLines != &Lines; }
286 std::unique_ptr<UnwrappedLine> Line;
300 llvm::DenseMap<FormatToken *, SmallVector<UnwrappedLine, 8>> ExpandedLines;
304 llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> Unexpanded;
308 bool InExpansion =
false;
313 std::optional<MacroCallReconstructor> Reconstruct;
339 llvm::BitVector DeclarationScopeStack;
346 llvm::Regex CommentPragmasRegex;
363 bool IsDecltypeAutoFunction =
false;
373 PPBranch(PPBranchKind Kind,
size_t Line) : Kind(Kind),
Line(Line) {}
380 enum IncludeGuardState {
399 explicit PPState(IncludeGuardState IncludeGuard)
400 : IncludeGuard(IncludeGuard) {}
411 int BranchLevel = -1;
424 std::stack<int> ChainBranchIndex;
427 IncludeGuardState IncludeGuard;
434 bool AtEndOfPPLine =
false;
444 const FormatToken *TokenAfterIfWithConditionalElse =
nullptr;
449 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...