clang: lib/Format/UnwrappedLineParser.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H

16#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H

17

19#include

20

22namespace format {

23

24struct UnwrappedLineNode;

25

26

27

28

29

30

31

34

35

36 std::list Tokens;

37

38

40

41

42

44

45

47

49

51

52

54

56

57

59

60

61

63

64

65

66

67

69

70

71

73

75

77};

78

79

80

81

82

83

84

85

86

87

88

89

90

91

93public:

97};

98

100

102public:

107 llvm::SpecificBumpPtrAllocator &Allocator,

109

111

112private:

113 enum class IfStmtKind {

114 NotIf,

115 IfOnly,

116 IfElse,

117 IfElseIf

118 };

119

120 void reset();

121 void parseFile();

122 bool precededByCommentOrPPDirective() const;

123 bool parseLevel(const FormatToken *OpeningBrace = nullptr,

124 IfStmtKind *IfKind = nullptr,

127 const FormatToken *OpeningBrace = nullptr) const;

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);

136 void parsePPElse();

137 void parsePPEndIf();

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);

150 void keepAncestorBraces();

151 void parseUnbracedBody(bool CheckEOF = false);

152 void handleAttributes();

153 bool handleCppAttributes();

154 bool isBlockBegin(const FormatToken &Tok) const;

155 FormatToken *parseIfThenElse(IfStmtKind *IfKind, bool KeepBraces = false,

156 bool IsVerilogAssert = false);

157 void parseTryCatch();

158 void parseLoopBody(bool KeepBraces, bool WrapRightBrace);

159 void parseForOrWhileLoop(bool HasParens = true);

160 void parseDoWhile();

161 void parseLabel(bool LeftAlignLabel = false);

162 void parseCaseLabel();

163 void parseSwitch(bool IsExpr);

164 void parseNamespace();

165 bool parseModuleImport();

166 void parseNew();

167 void parseAccessSpecifier();

168 bool parseEnum();

169 bool parseStructLike();

170 bool parseRequires();

171 void parseRequiresClause(FormatToken *RequiresToken);

172 void parseRequiresExpression(FormatToken *RequiresToken);

173 void parseConstraintExpression();

174 void parseCppExportBlock();

175 void parseNamespaceOrExportBlock(unsigned AddLevels);

176 void parseJavaEnumBody();

177

178

179

180 void parseRecord(bool ParseAsExpr = false);

181 void parseObjCLightweightGenerics();

182 void parseObjCMethod();

183 void parseObjCProtocolList();

184 void parseObjCUntilAtEnd();

185 void parseObjCInterfaceOrImplementation();

186 bool parseObjCProtocol();

187 void parseJavaScriptEs6ImportExport();

188 void parseStatementMacro();

189 void parseCSharpAttribute();

190

191

192

193 void parseCSharpGenericTypeConstraint();

194 bool tryToParseLambda();

195 bool tryToParseChildBlock();

196 bool tryToParseLambdaIntroducer();

197 bool tryToParsePropertyAccessor();

198 void tryToParseJSFunction();

199 bool tryToParseSimpleAttribute();

200 void parseVerilogHierarchyIdentifier();

201 void parseVerilogSensitivityList();

202

203

204 unsigned parseVerilogHierarchyHeader();

205 void parseVerilogTable();

206 void parseVerilogCaseLabel();

207 std::optional<llvm::SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>>

208 parseMacroCall();

209

210

211

212 enum class LineLevel { Remove, Keep };

213

214 void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);

215 bool eof() const;

216

217

218

219

220 void nextToken(int LevelDifference = 0);

221 void readToken(int LevelDifference = 0);

222

223

224

225

226

227

228

229

230

231

232

235

236

237 void flushComments(bool NewlineBeforeNext);

239 void calculateBraceTypes(bool ExpectClassBody = false);

241

242

243

244

245

246 void conditionalCompilationCondition(bool Unreachable);

247 void conditionalCompilationStart(bool Unreachable);

248 void conditionalCompilationAlternative();

249 void conditionalCompilationEnd();

250

251 bool isOnNewLine(const FormatToken &FormatTok);

252

253

254

255 bool containsExpansion(const UnwrappedLine &Line) const;

256

257

258

259

260 size_t computePPHash() const;

261

262 bool parsingPPDirective() const { return CurrentLines != &Lines; }

263

264

265

266

267 std::unique_ptr Line;

268

269

270

271

272

273

274

275

277

278

279

280

281 llvm::DenseMap<FormatToken *, SmallVector<UnwrappedLine, 8>> ExpandedLines;

282

283

284

285 llvm::DenseMap<FormatToken *, std::unique_ptr> Unexpanded;

286

287

288

289 bool InExpansion = false;

290

291

292

293

294 std::optional Reconstruct;

295

296

297

298

299

302 bool MustBreakBeforeNextToken;

303

304

306

307

308

309

311

312

313

314

315

317

318

319

320 llvm::BitVector DeclarationScopeStack;

321

323 bool IsCpp;

326

327 llvm::Regex CommentPragmasRegex;

328

331

333

334

335

337

338

339

341

342

343

344 bool IsDecltypeAutoFunction = false;

345

346

347

348 enum PPBranchKind {

349 PP_Conditional,

350 PP_Unreachable

351 };

352

353 struct PPBranch {

354 PPBranch(PPBranchKind Kind, size_t Line) : Kind(Kind), Line(Line) {}

355 PPBranchKind Kind;

356 size_t Line;

357 };

358

359

361

362

363

364

365

366

367

368 int PPBranchLevel;

369

370

371

373

374

376

377

378

379

380

381 std::stack PPChainBranchIndex;

382

383

384

385 enum IncludeGuardState {

386 IG_Inited,

387 IG_IfNdefed,

388 IG_Defined,

389 IG_Found,

390 IG_Rejected,

391 };

392

393

394 IncludeGuardState IncludeGuard;

395

396

397

399

400

401

402

403 unsigned FirstStartColumn;

404

406

409};

410

416

419};

420

422

423}

424}

425

426#endif

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.

Takes a set of macro definitions as strings and allows expanding calls to those macros.

Interface for users of the UnwrappedLineParser to receive the parsed lines.

virtual ~UnwrappedLineConsumer()

virtual void finishRun()=0

virtual void consumeUnwrappedLine(const UnwrappedLine &Line)=0

std::ostream & operator<<(std::ostream &Stream, const UnwrappedLine &Line)

TokenType

Determines the semantic type of a syntactic token, e.g.

The JSON file list parser is used to communicate input to InstallAPI.

Represents a complete lambda introducer.

Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...

The FormatStyle is used to configure the formatting to follow specific guidelines.

A wrapper around a Token storing information about the whitespace characters preceding it.

SmallVector< UnwrappedLine, 0 > Children

UnwrappedLineNode(FormatToken *Tok, llvm::ArrayRef< UnwrappedLine > Children={})

An unwrapped line is a sequence of Token, that we would like to put on a single line if there was no ...

unsigned PPLevel

The PPBranchLevel (adjusted for header guards) if this line is a InMacroBody line,...

bool InMacroBody

Whether it is part of a macro body.

std::list< UnwrappedLineNode > Tokens

The Tokens comprising this UnwrappedLine.

unsigned FirstStartColumn

bool IsContinuation

True if this line should be indented by ContinuationIndent in addition to the normal indention level.

unsigned Level

The indent level of the UnwrappedLine.

unsigned UnbracedBodyLevel

Nesting level of unbraced body of a control statement.

bool InPragmaDirective

Whether this UnwrappedLine is part of a pramga directive.

bool InPPDirective

Whether this UnwrappedLine is part of a preprocessor directive.

bool SeenDecltypeAuto

Whether the parser has seen decltype(auto) in this line.

size_t MatchingClosingBlockLineIndex

If this UnwrappedLine opens a block, stores the index of the line with the corresponding closing brac...

static const size_t kInvalidIndex

size_t MatchingOpeningBlockLineIndex

If this UnwrappedLine closes a block in a sequence of lines, MatchingOpeningBlockLineIndex stores the...