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/ADT/DenseSet.h"
26#include "llvm/Support/Regex.h"
34struct UnwrappedLineNode;
111 llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
117 enum class IfStmtKind {
126 bool precededByCommentOrPPDirective()
const;
127 bool parseLevel(
const FormatToken *OpeningBrace =
nullptr,
128 bool CanContainBracedList =
true,
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 bool CanContainBracedList =
true,
140 void parseChildBlock(
bool CanContainBracedList =
true,
142 void parsePPDirective();
143 void parsePPDefine();
144 void parsePPIf(
bool IfDef);
147 void parsePPPragma();
148 void parsePPUnknown();
149 void readTokenWithJavaScriptASI();
150 void parseStructuralElement(
bool IsTopLevel =
false,
152 IfStmtKind *IfKind =
nullptr,
154 bool *HasDoWhile =
nullptr,
155 bool *HasLabel =
nullptr);
156 bool tryToParseBracedList();
157 bool parseBracedList(
bool ContinueOnSemicolons =
false,
bool IsEnum =
false,
159 void parseParens(
TokenType AmpAmpTokenType = TT_Unknown);
161 void keepAncestorBraces();
162 void parseUnbracedBody(
bool CheckEOF =
false);
163 void handleAttributes();
164 bool handleCppAttributes();
166 FormatToken *parseIfThenElse(IfStmtKind *IfKind,
bool KeepBraces =
false);
167 void parseTryCatch();
168 void parseLoopBody(
bool KeepBraces,
bool WrapRightBrace);
169 void parseForOrWhileLoop(
bool HasParens =
true);
171 void parseLabel(
bool LeftAlignLabel =
false);
172 void parseCaseLabel();
174 void parseNamespace();
175 bool parseModuleImport();
177 void parseAccessSpecifier();
179 bool parseStructLike();
180 bool parseRequires();
181 void parseRequiresClause(
FormatToken *RequiresToken);
182 void parseRequiresExpression(
FormatToken *RequiresToken);
183 void parseConstraintExpression();
184 void parseJavaEnumBody();
188 void parseRecord(
bool ParseAsExpr =
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();
215 std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>
220 enum class LineLevel { Remove, Keep };
222 void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);
228 void nextToken(
int LevelDifference = 0);
229 void readToken(
int LevelDifference = 0);
245 void flushComments(
bool NewlineBeforeNext);
247 void calculateBraceTypes(
bool ExpectClassBody =
false);
253 void conditionalCompilationCondition(
bool Unreachable);
254 void conditionalCompilationStart(
bool Unreachable);
255 void conditionalCompilationAlternative();
256 void conditionalCompilationEnd();
267 size_t computePPHash()
const;
269 bool parsingPPDirective()
const {
return CurrentLines != &Lines; }
274 std::unique_ptr<UnwrappedLine> Line;
288 llvm::DenseMap<FormatToken *, SmallVector<UnwrappedLine, 8>> ExpandedLines;
292 llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> Unexpanded;
296 bool InExpansion =
false;
301 std::optional<MacroCallReconstructor> Reconstruct;
309 bool MustBreakBeforeNextToken;
327 llvm::BitVector DeclarationScopeStack;
332 llvm::Regex CommentPragmasRegex;
351 PPBranch(PPBranchKind Kind,
size_t Line) : Kind(Kind), Line(Line) {}
378 std::stack<int> PPChainBranchIndex;
382 enum IncludeGuardState {
391 IncludeGuardState IncludeGuard;
400 unsigned FirstStartColumn;
419 : Level(0), PPLevel(0), InPPDirective(
false), InPragmaDirective(
false),
421 MatchingOpeningBlockLineIndex(kInvalidIndex) {}
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.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Represents a complete lambda introducer.