clang: lib/Format/ContinuationIndenter.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_CONTINUATIONINDENTER_H

16#define LLVM_CLANG_LIB_FORMAT_CONTINUATIONINDENTER_H

17

20

23

25

33

37

39

40 std::optional getDelimiterStyle(StringRef Delimiter) const;

41

42 std::optional

44};

45

46

47

50

51

52

54

55

56

57

58

59

60

61

62

63

64

65

66

67

69

73

75

77

79};

80

82public:

83

84

90 bool BinPackInconclusiveFunctions);

91

92

93

94

95

98

99

100

101

103

104

106

107

108

109

110

111

112

113

114

116 unsigned ExtraSpaces = 0);

117

118

119

121

122private:

123

124

125 unsigned moveStateToNextToken(LineState &State, bool DryRun, bool Newline);

126

127

128 void moveStatePastFakeLParens(LineState &State, bool Newline);

129

130 void moveStatePastFakeRParens(LineState &State);

131

132

133 void moveStatePastScopeOpener(LineState &State, bool Newline);

134

135 void moveStatePastScopeCloser(LineState &State);

136

137 void moveStateToNewBlock(LineState &State, bool NewLine);

138

139

140

141

142 unsigned reformatRawStringLiteral(const FormatToken &Current,

144 const FormatStyle &RawStringStyle,

145 bool DryRun, bool Newline);

146

147

148

150 bool DryRun, bool AllowBreak, bool Newline);

151

152

153

154 std::optional getRawStringStyle(const FormatToken &Current,

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175 std::pair<unsigned, bool> breakProtrudingToken(const FormatToken &Current,

177 bool AllowBreak, bool DryRun,

178 bool Strict);

179

180

181

182 std::unique_ptr

184 bool AllowBreak);

185

186

187

188

189

190

191

192

193 void addTokenOnCurrentLine(LineState &State, bool DryRun,

194 unsigned ExtraSpaces);

195

196

197

198

199

200

201

202

203 unsigned addTokenOnNewLine(LineState &State, bool DryRun);

204

205

207

208

209

210

211

212

214

215

216

217

218

219

220 bool nextIsMultilineString(const LineState &State);

221

222 FormatStyle Style;

227 bool BinPackInconclusiveFunctions;

228 llvm::Regex CommentPragmasRegex;

230};

231

247

248

249

250

251

252

254

255

256

258

259

260

261

262

263

265

266

267

269

270

271

272

273

275

276

278

279

281

282

284

285

286

288

289

290

292

293

294

296

297

298

299

301

302

304

305

306

307

308

309

311

312

313

314

315

316

318

319

321

322

323

325

326

327

329

330

332

333

334

336

337

338

340

341

342

343

344

345

347

348

349

351

352

353

354

355

356

358

359

360

361

362

363

365

366

367

368

369

371

372

373

375

376

377

379

381

382

383

385

386

387

389

390

392

446};

447

448

449

450

452

454

455

457

458

460

461

463

464

466

467

468

470

471

473

474

475

477

478

479

480

481

482

483

484

485

486

487

488

489

490

492

493

495

496

497

498

500

501

519};

520

521}

522}

523

524#endif

Contains functions for text encoding manipulation.

This file contains the declaration of the FormatToken, a wrapper around Token with additional informa...

This class handles loading and caching of source files into memory.

Base class for tokens / ranges of tokens that can allow breaking within the tokens - for example,...

bool canBreak(const LineState &State)

Returns true, if a line break after State is allowed.

unsigned addTokenToState(LineState &State, bool Newline, bool DryRun, unsigned ExtraSpaces=0)

Appends the next token to State and updates information necessary for indentation.

unsigned getColumnLimit(const LineState &State) const

Get the column limit for this line.

LineState getInitialState(unsigned FirstIndent, unsigned FirstStartColumn, const AnnotatedLine *Line, bool DryRun)

Get the initial state, i.e.

ContinuationIndenter(const FormatStyle &Style, const AdditionalKeywords &Keywords, const SourceManager &SourceMgr, WhitespaceManager &Whitespaces, encoding::Encoding Encoding, bool BinPackInconclusiveFunctions)

Constructs a ContinuationIndenter to format Line starting in column FirstIndent.

bool mustBreak(const LineState &State)

Returns true, if a line break after State is mandatory.

Manages the whitespaces around tokens and their replacements.

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

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

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

Represents the spaces at the start of a line, keeping track of what the spaces are for.

Definition ContinuationIndenter.h:48

IndentationAndAlignment operator+(unsigned Spaces) const

Adding indentation is more common than padding. So the operator does that.

IndentationAndAlignment(unsigned Total, unsigned IndentedFrom)

IndentationAndAlignment addPadding(unsigned Spaces) const

Add spaces for right-justifying the token.

IndentationAndAlignment operator-(unsigned Spaces) const

IndentationAndAlignment & operator+=(unsigned Spaces)

bool operator<(const IndentationAndAlignment &Other) const

unsigned IndentedFrom

The column that the position of the start of the line is calculated from.

Definition ContinuationIndenter.h:53

unsigned Total

Definition ContinuationIndenter.h:49

The current state when indenting a unwrapped line.

Definition ContinuationIndenter.h:451

unsigned StartOfStringLiteral

The start column of the string literal, if we're in a string literal sequence, 0 otherwise.

Definition ContinuationIndenter.h:469

bool IgnoreStackForComparison

Ignore the stack of ParenStates for state comparison.

Definition ContinuationIndenter.h:491

bool operator<(const LineState &Other) const

Comparison operator to be able to used LineState in map.

Definition ContinuationIndenter.h:502

unsigned LowestLevelOnLine

The lowest NestingLevel on the current line.

Definition ContinuationIndenter.h:465

const AnnotatedLine * Line

The line that is being formatted.

Definition ContinuationIndenter.h:499

bool NoLineBreak

Disallow line breaks for this line.

Definition ContinuationIndenter.h:472

unsigned Column

The number of used columns in the current line.

Definition ContinuationIndenter.h:453

SmallVector< ParenState > Stack

A stack keeping track of properties applying to parenthesis levels.

Definition ContinuationIndenter.h:476

bool NoContinuation

true if NextToken should not continue this line.

Definition ContinuationIndenter.h:459

unsigned StartOfLineLevel

The NestingLevel at the start of this line.

Definition ContinuationIndenter.h:462

unsigned FirstIndent

The indent of the first token.

Definition ContinuationIndenter.h:494

FormatToken * NextToken

The token that needs to be next formatted.

Definition ContinuationIndenter.h:456

bool AvoidBinPacking

Avoid bin packing, i.e.

Definition ContinuationIndenter.h:324

unsigned NestedNameSpecifierContinuation

If a nested name specifier was broken over multiple lines, this contains the start column of the seco...

Definition ContinuationIndenter.h:291

bool AlignColons

true if the colons of the curren ObjC method expression should be aligned.

Definition ContinuationIndenter.h:357

bool BreakBeforeClosingParen

Whether a newline needs to be inserted before the block's closing paren.

Definition ContinuationIndenter.h:317

bool BreakBeforeParameter

Break after the next comma (or all the commas in this context if AvoidBinPacking is true).

Definition ContinuationIndenter.h:328

const FormatToken * Tok

The token opening this parenthesis level, or nullptr if this level is opened by fake parenthesis.

Definition ContinuationIndenter.h:253

bool BreakBeforeClosingBrace

Whether a newline needs to be inserted before the block's closing brace.

Definition ContinuationIndenter.h:310

unsigned FirstLessLess

The position the first "<<" operator encountered on each level.

Definition ContinuationIndenter.h:274

bool LastOperatorWrapped

True if the last binary operator on this level was wrapped to the next line.

Definition ContinuationIndenter.h:339

unsigned VariablePos

The column of the first variable name in a variable declaration.

Definition ContinuationIndenter.h:300

unsigned LastSpace

The position of the last space on each level.

Definition ContinuationIndenter.h:264

bool NoLineBreak

Line breaking in this context would break a formatting rule.

Definition ContinuationIndenter.h:331

unsigned QuestionColumn

The column of a ? in a conditional expression;.

Definition ContinuationIndenter.h:277

unsigned StartOfFunctionCall

The start of the most recent function in a builder-type call.

Definition ContinuationIndenter.h:283

bool IsCSharpGenericTypeConstraint

Definition ContinuationIndenter.h:380

bool ObjCSelectorNameFound

true if at least one selector name was found in the current ObjC method expression.

Definition ContinuationIndenter.h:364

bool NoLineBreakInOperand

Same as NoLineBreak, but is restricted until the end of the operand (including the next ",...

Definition ContinuationIndenter.h:335

bool operator<(const ParenState &Other) const

Definition ContinuationIndenter.h:393

bool ContainsUnwrappedBuilder

true if this ParenState contains multiple segments of a builder-type call on one line.

Definition ContinuationIndenter.h:350

unsigned ColonPos

The position of the colon in an ObjC method declaration/call.

Definition ContinuationIndenter.h:280

bool UnindentOperator

Indicates the indent should be reduced by the length of the operator.

Definition ContinuationIndenter.h:391

bool ContainsLineBreak

true if this ParenState already contains a line-break.

Definition ContinuationIndenter.h:346

bool IsAligned

Whether this block's indentation is used for alignment.

Definition ContinuationIndenter.h:303

unsigned StartOfArraySubscripts

Contains the start of array subscript expressions, so that they can be aligned.

Definition ContinuationIndenter.h:287

bool NestedBlockInlined

The start of a nested block (e.g.

Definition ContinuationIndenter.h:374

ParenState(const FormatToken *Tok, IndentationAndAlignment Indent, unsigned LastSpace, bool AvoidBinPacking, bool NoLineBreak)

Definition ContinuationIndenter.h:233

bool HasMultipleNestedBlocks

true if there are multiple nested blocks inside these parens.

Definition ContinuationIndenter.h:370

bool IsChainedConditional

true if the current ParenState represents the false branch of a chained conditional expression (e....

Definition ContinuationIndenter.h:384

bool BreakBeforeClosingAngle

Whether a newline needs to be inserted before a closing angle >.

Definition ContinuationIndenter.h:320

unsigned CallContinuation

If a call expression was broken over multiple lines, this contains the start column of the second lin...

Definition ContinuationIndenter.h:295

bool IsWrappedConditional

true if there conditionnal was wrapped on the first operator (the question mark)

Definition ContinuationIndenter.h:388

IndentationAndAlignment Indent

The position to which a specific parenthesis level needs to be indented.

Definition ContinuationIndenter.h:257

unsigned NestedBlockIndent

If a block relative to this parenthesis level gets wrapped, indent it this much.

Definition ContinuationIndenter.h:268

bool IsInsideObjCArrayLiteral

true if the current ParenState represents an Objective-C array literal.

Definition ContinuationIndenter.h:378

llvm::StringMap< FormatStyle > EnclosingFunctionStyle

Definition ContinuationIndenter.h:36

std::optional< FormatStyle > getDelimiterStyle(StringRef Delimiter) const

std::optional< FormatStyle > getEnclosingFunctionStyle(StringRef EnclosingFunction) const

RawStringFormatStyleManager(const FormatStyle &CodeStyle)

llvm::StringMap< FormatStyle > DelimiterStyle

Definition ContinuationIndenter.h:35