clang: lib/Format/FormatToken.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_FORMATTOKEN_H

16#define LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H

17

22#include <unordered_set>

23

25namespace format {

26

27#define LIST_TOKEN_TYPES \

28 TYPE(AfterPPDirective) \

29 TYPE(ArrayInitializerLSquare) \

30 TYPE(ArraySubscriptLSquare) \

31 TYPE(AttributeColon) \

32 TYPE(AttributeLParen) \

33 TYPE(AttributeMacro) \

34 TYPE(AttributeRParen) \

35 TYPE(AttributeSquare) \

36 TYPE(BinaryOperator) \

37 TYPE(BitFieldColon) \

38 TYPE(BlockComment) \

39 \

40 TYPE(BlockLBrace) \

41 TYPE(BracedListLBrace) \

42 TYPE(CaseLabelArrow) \

43 \

44 TYPE(CaseLabelColon) \

45 TYPE(CastRParen) \

46 TYPE(ClassLBrace) \

47 TYPE(ClassRBrace) \

48 TYPE(CompoundRequirementLBrace) \

49 \

50 TYPE(ConditionalExpr) \

51 \

52 TYPE(ConditionLParen) \

53 TYPE(ConflictAlternative) \

54 TYPE(ConflictEnd) \

55 TYPE(ConflictStart) \

56 \

57 TYPE(ControlStatementLBrace) \

58 TYPE(ControlStatementRBrace) \

59 TYPE(CppCastLParen) \

60 TYPE(CSharpGenericTypeConstraint) \

61 TYPE(CSharpGenericTypeConstraintColon) \

62 TYPE(CSharpGenericTypeConstraintComma) \

63 TYPE(CSharpNamedArgumentColon) \

64 TYPE(CSharpNullable) \

65 TYPE(CSharpNullConditionalLSquare) \

66 TYPE(CSharpStringLiteral) \

67 TYPE(CtorInitializerColon) \

68 TYPE(CtorInitializerComma) \

69 TYPE(CtorDtorDeclName) \

70 TYPE(DesignatedInitializerLSquare) \

71 TYPE(DesignatedInitializerPeriod) \

72 TYPE(DictLiteral) \

73 TYPE(DoWhile) \

74 TYPE(ElseLBrace) \

75 TYPE(ElseRBrace) \

76 TYPE(EnumLBrace) \

77 TYPE(EnumRBrace) \

78 TYPE(FatArrow) \

79 TYPE(ForEachMacro) \

80 TYPE(FunctionAnnotationRParen) \

81 TYPE(FunctionDeclarationName) \

82 TYPE(FunctionDeclarationLParen) \

83 TYPE(FunctionLBrace) \

84 TYPE(FunctionLikeOrFreestandingMacro) \

85 TYPE(FunctionTypeLParen) \

86 \

87 TYPE(GenericSelectionColon) \

88 \

89 TYPE(GotoLabelColon) \

90 TYPE(IfMacro) \

91 TYPE(ImplicitStringLiteral) \

92 TYPE(InheritanceColon) \

93 TYPE(InheritanceComma) \

94 TYPE(InlineASMBrace) \

95 TYPE(InlineASMColon) \

96 TYPE(InlineASMSymbolicNameLSquare) \

97 TYPE(JavaAnnotation) \

98 TYPE(JsAndAndEqual) \

99 TYPE(JsComputedPropertyName) \

100 TYPE(JsExponentiation) \

101 TYPE(JsExponentiationEqual) \

102 TYPE(JsPipePipeEqual) \

103 TYPE(JsPrivateIdentifier) \

104 TYPE(JsTypeColon) \

105 TYPE(JsTypeOperator) \

106 TYPE(JsTypeOptionalQuestion) \

107 TYPE(LambdaArrow) \

108 TYPE(LambdaDefinitionLParen) \

109 TYPE(LambdaLBrace) \

110 TYPE(LambdaLSquare) \

111 TYPE(LeadingJavaAnnotation) \

112 TYPE(LineComment) \

113 TYPE(MacroBlockBegin) \

114 TYPE(MacroBlockEnd) \

115 TYPE(ModulePartitionColon) \

116 TYPE(NamespaceLBrace) \

117 TYPE(NamespaceMacro) \

118 TYPE(NamespaceRBrace) \

119 TYPE(NonNullAssertion) \

120 TYPE(NullCoalescingEqual) \

121 TYPE(NullCoalescingOperator) \

122 TYPE(NullPropagatingOperator) \

123 TYPE(ObjCBlockLBrace) \

124 TYPE(ObjCBlockLParen) \

125 TYPE(ObjCDecl) \

126 TYPE(ObjCForIn) \

127 TYPE(ObjCMethodExpr) \

128 TYPE(ObjCMethodSpecifier) \

129 TYPE(ObjCProperty) \

130 TYPE(ObjCStringLiteral) \

131 TYPE(OverloadedOperator) \

132 TYPE(OverloadedOperatorLParen) \

133 TYPE(PointerOrReference) \

134 TYPE(ProtoExtensionLSquare) \

135 TYPE(PureVirtualSpecifier) \

136 TYPE(RangeBasedForLoopColon) \

137 TYPE(RecordLBrace) \

138 TYPE(RecordRBrace) \

139 TYPE(RegexLiteral) \

140 TYPE(RequiresClause) \

141 TYPE(RequiresClauseInARequiresExpression) \

142 TYPE(RequiresExpression) \

143 TYPE(RequiresExpressionLBrace) \

144 TYPE(RequiresExpressionLParen) \

145 TYPE(SelectorName) \

146 TYPE(StartOfName) \

147 TYPE(StatementAttributeLikeMacro) \

148 TYPE(StatementMacro) \

149

150

151

152 \

153 TYPE(StringInConcatenation) \

154 TYPE(StructLBrace) \

155 TYPE(StructRBrace) \

156 TYPE(StructuredBindingLSquare) \

157 TYPE(SwitchExpressionLabel) \

158 TYPE(SwitchExpressionLBrace) \

159 TYPE(TableGenBangOperator) \

160 TYPE(TableGenCondOperator) \

161 TYPE(TableGenCondOperatorColon) \

162 TYPE(TableGenCondOperatorComma) \

163 TYPE(TableGenDAGArgCloser) \

164 TYPE(TableGenDAGArgListColon) \

165 TYPE(TableGenDAGArgListColonToAlign) \

166 TYPE(TableGenDAGArgListComma) \

167 TYPE(TableGenDAGArgListCommaToBreak) \

168 TYPE(TableGenDAGArgOpener) \

169 TYPE(TableGenDAGArgOpenerToBreak) \

170 TYPE(TableGenDAGArgOperatorID) \

171 TYPE(TableGenDAGArgOperatorToBreak) \

172 TYPE(TableGenListCloser) \

173 TYPE(TableGenListOpener) \

174 TYPE(TableGenMultiLineString) \

175 TYPE(TableGenTrailingPasteOperator) \

176 TYPE(TableGenValueSuffix) \

177 TYPE(TemplateCloser) \

178 TYPE(TemplateOpener) \

179 TYPE(TemplateString) \

180 TYPE(TrailingAnnotation) \

181 TYPE(TrailingReturnArrow) \

182 TYPE(TrailingUnaryOperator) \

183 TYPE(TypeDeclarationParen) \

184 TYPE(TemplateName) \

185 TYPE(TypeName) \

186 TYPE(TypenameMacro) \

187 TYPE(UnaryOperator) \

188 TYPE(UnionLBrace) \

189 TYPE(UnionRBrace) \

190 TYPE(UntouchableMacroFunc) \

191 TYPE(VariableTemplate) \

192 \

193 TYPE(VerilogAssignComma) \

194 \

195 TYPE(VerilogBlockLabelColon) \

196

197

198 \

199 TYPE(VerilogDimensionedTypeName) \

200 \

201 TYPE(VerilogInstancePortComma) \

202 TYPE(VerilogInstancePortLParen) \

203

204 \

205 TYPE(VerilogMultiLineListLParen) \

206 \

207 TYPE(VerilogNumberBase) \

208 \

209 TYPE(VerilogStrength) \

210 \

211 TYPE(VerilogTableItem) \

212 \

213 TYPE(VerilogTypeComma) \

214 TYPE(Unknown)

215

216

217

219#define TYPE(X) TT_##X,

221#undef TYPE

224

225

227

228

230

231

233

235

236

238

239

241

242

244

245

247};

248

249struct FormatToken;

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

278

279

280

281

282

283

284

286

287

290

292

293

294

296};

300

301

302

314 Type(TT_Unknown) {}

315

316

318

319

320

321

322

324

325

326

327

328

329 std::shared_ptr Role;

331

334

335

337

338

340

341

343

344

345

346

347

350

351

353

354

356

357

360

362

363

364

366

368

369

370

371

373

374

375

376

378

379

380

381

383

384

386

387

390private:

391

392 unsigned BlockKind : 2;

393

394public:

397 }

399 BlockKind = BBK;

400 assert(getBlockKind() == BBK && "BraceBlockKind overflow!");

401 }

403private:

404

405 unsigned Decision : 2;

406

407public:

410 }

412 Decision = D;

413 assert(getDecision() == D && "FormatDecision overflow!");

414 }

416private:

417

418 unsigned PackingKind : 2;

419

420public:

423 }

425 PackingKind = K;

426 assert(getPackingKind() == K && "ParameterPackingKind overflow!");

427 }

428

429private:

430 unsigned TypeIsFinalized : 1;

432

433public:

434

435

438

439

440

442 return;

443 assert((!TypeIsFinalized || T == Type) &&

444 "Please use overwriteFixedType to change a fixed type.");

446 }

447

448

449

450

453 return;

455 TypeIsFinalized = true;

456 }

459 return;

460 TypeIsFinalized = false;

462 }

464

465

467

468

469

470

471

473

474

475

476

477

479

480

481

483

484

485

486

489

490

492

493

496

498

499

500

502

503

504

506

507

508

510

511

512

514

515

516

518

519

520

521

524

525

527

528

530

531

534

535

536

537

538

540

541

542

543

545

546

547

548

551

552

553

554

555

557

559

560

561

564

565

567

568

570

571

573

574

576

577

579

580

582

583

585

586

588

589

591

592

594

595

596

597

598

600

601

602

604

605

606

607 std::optional MacroCtx;

608

609

610

611

612

613

614

615

626 }

629

630 template <typename A, typename B> bool isOneOf(A K1, B K2) const {

632 }

633 template <typename A, typename B, typename... Ts>

634 bool isOneOf(A K1, B K2, Ts... Ks) const {

635 return is(K1) || isOneOf(K2, Ks...);

636 }

637 template bool isNot(T Kind) const { return is(Kind); }

639 bool isIf(bool AllowConstexprMacro = true) const {

640 return is(tok::kw_if) || endsSequence(tok::kw_constexpr, tok::kw_if) ||

641 (endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);

642 }

643

646 return true;

649 return false;

650 }

651

652

653

654 template <typename A, typename... Ts>

656 return startsSequenceInternal(K1, Tokens...);

657 }

658

659

660

661

662

663

664

665 template <typename A, typename... Ts>

667 return endsSequenceInternal(K1, Tokens...);

668 }

669

671

673 return isOneOf(tok::kw___attribute, tok::kw___declspec, TT_AttributeMacro);

675

679

681 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private);

682 }

683

686 return false;

687 if (!ColonRequired)

688 return true;

690 return NextNonComment && NextNonComment->is(tok::colon);

691 }

692

694 return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,

695 tok::kw__Nonnull, tok::kw__Nullable,

696 tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,

697 tok::kw___funcref) ||

699 }

700

703

705 return is(tok::at) && Next &&

710 }

711

712

713

715 if (is(TT_TemplateString) && TokenText.ends_with("${"))

716 return true;

717 if (is(TT_DictLiteral) && is(tok::less))

718 return true;

719 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,

720 TT_TemplateOpener);

721 }

722

723

725 if (is(TT_TemplateString) && TokenText.starts_with("}"))

726 return true;

727 if (is(TT_DictLiteral) && is(tok::greater))

728 return true;

729 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,

730 TT_TemplateCloser);

731 }

732

733

735 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&

736 isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,

737 TT_LambdaArrow, TT_LeadingJavaAnnotation);

739

741 return isOneOf(tok::star, tok::amp, tok::ampamp);

742 }

743

747 return false;

748

750 case tok::ampamp:

751 case tok::ampequal:

752 case tok::amp:

753 case tok::pipe:

754 case tok::tilde:

755 case tok::exclaim:

756 case tok::exclaimequal:

757 case tok::pipepipe:

758 case tok::pipeequal:

759 case tok::caret:

760 case tok::caretequal:

761 return true;

762 default:

763 return false;

764 }

765 }

766

769 case tok:➕

770 case tok::plusplus:

771 case tok:➖

772 case tok::minusminus:

773 case tok::exclaim:

774 case tok::tilde:

775 case tok::kw_sizeof:

776 case tok::kw_alignof:

777 return true;

778 default:

779 return false;

780 }

781 }

784

786 }

787

789 return is(tok::comment) &&

791 }

792

793

794

797 return true;

798

799 return isOneOf(tok::kw_throw, tok::kw_typeid, tok::kw_return,

800 tok::kw_sizeof, tok::kw_alignof, tok::kw_alignas,

801 tok::kw_decltype, tok::kw_noexcept, tok::kw_static_assert,

802 tok::kw__Atomic,

804#include "clang/Basic/TransformTypeTraits.def"

805 tok::kw_requires);

806 }

807

808

809

811 if (isNot(tok::string_literal))

812 return false;

814 if (Content.starts_with("\"") || Content.starts_with("'"))

815 Content = Content.drop_front(1);

816 if (Content.ends_with("\"") || Content.ends_with("'"))

817 Content = Content.drop_back(1);

818 Content = Content.trim();

819 return Content.size() > 1 &&

820 (Content.back() == ':' || Content.back() == '=');

821 }

823

824

825

826

827

830 }

831

832

833

836 }

837

842 true);

843 }

844

845

850 return Tok;

851 }

852

853

856 while (Tok && Tok->is(tok::comment))

858 return Tok;

859 }

860

861

863

864

865

867

868

869

871 if (!IsCpp || isNot(tok::l_square))

872 return false;

874 do {

875 T = T->getPreviousNonComment();

876 } while (T && T->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,

877 tok::ampamp));

878 return T && T->is(tok::kw_auto);

879 }

880

881

884 return true;

886 }

887

888

889

892 if (is(tok::comment))

894

895 if (NamespaceTok && NamespaceTok->isOneOf(tok::kw_inline, tok::kw_export))

897 return NamespaceTok &&

898 NamespaceTok->isOneOf(tok::kw_namespace, TT_NamespaceMacro)

899 ? NamespaceTok

900 : nullptr;

901 }

902

904

905private:

906

909

910 template <typename A, typename... Ts>

911 bool startsSequenceInternal(A K1, Ts... Tokens) const {

912 if (is(tok::comment) && Next)

913 return Next->startsSequenceInternal(K1, Tokens...);

914 return is(K1) && Next && Next->startsSequenceInternal(Tokens...);

915 }

916

917 template bool startsSequenceInternal(A K1) const {

918 if (is(tok::comment) && Next)

919 return Next->startsSequenceInternal(K1);

920 return is(K1);

921 }

922

923 template <typename A, typename... Ts> bool endsSequenceInternal(A K1) const {

925 return Previous->endsSequenceInternal(K1);

926 return is(K1);

927 }

928

929 template <typename A, typename... Ts>

930 bool endsSequenceInternal(A K1, Ts... Tokens) const {

932 return Previous->endsSequenceInternal(K1, Tokens...);

933 return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...);

935};

939

941public:

944

945

946

948

949

950

951

952

953

954

957 bool DryRun) {

958 return 0;

959 }

960

961

962

965 bool DryRun) {

966 return 0;

967 }

968

969

971

973

974protected:

976};

977

979public:

982

984

986 bool DryRun) override;

987

989 bool DryRun) override;

991

993 Commas.push_back(Token);

994 }

995

997 if (Commas.empty())

998 return nullptr;

999 return Commas.back();

1000 }

1001

1002private:

1003

1004

1005 struct ColumnFormat {

1006

1007 unsigned Columns;

1008

1009

1010 unsigned TotalWidth;

1011

1012

1013 unsigned LineCount;

1014

1015

1017 };

1018

1019

1020

1021 const ColumnFormat *getColumnFormat(unsigned RemainingCharacters) const;

1022

1023

1024 SmallVector<const FormatToken *, 8> Commas;

1025

1026

1027

1028 SmallVector<unsigned, 8> ItemLengths;

1029

1030

1031 SmallVector<ColumnFormat, 4> Formats;

1033 bool HasNestedBracedList;

1034};

1035

1036

1037

1042 kw_in = &IdentTable.get("in");

1043 kw_of = &IdentTable.get("of");

1051

1052 kw_as = &IdentTable.get("as");

1059 kw_get = &IdentTable.get("get");

1062 kw_is = &IdentTable.get("is");

1063 kw_let = &IdentTable.get("let");

1066 kw_set = &IdentTable.get("set");

1069 kw_var = &IdentTable.get("var");

1071

1085

1088

1095

1100

1101

1103 &IdentTable.get("__CLANG_FORMAT_INTERNAL_IDENT_AFTER_DEFINE__");

1104

1105

1121 kw_out = &IdentTable.get("out");

1123 kw_ref = &IdentTable.get("ref");

1135

1136

1169 kw_end = &IdentTable.get("end");

1194 kw_iff = &IdentTable.get("iff");

1248 kw_tri = &IdentTable.get("tri");

1266 kw_wor = &IdentTable.get("wor");

1267

1268

1272

1273

1274 kw_bit = &IdentTable.get("bit");

1277 kw_dag = &IdentTable.get("dag");

1278 kw_def = &IdentTable.get("def");

1287

1288

1289

1290

1291 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(

1295

1297

1298 CSharpExtraKeywords = std::unordered_set<IdentifierInfo *>(

1305

1309

1311

1312

1313

1314

1315 VerilogExtraKeywords = std::unordered_set<IdentifierInfo *>(

1380

1381 TableGenExtraKeywords = std::unordered_set<IdentifierInfo *>({

1403

1419

1440

1452

1456

1463

1464

1470

1473

1507

1639

1643

1646

1660

1661

1663

1666 }

1668

1669

1670

1671

1672

1674 bool AcceptIdentifierName = true) const {

1675

1676

1678 return false;

1680 case tok::kw_break:

1681 case tok::kw_case:

1682 case tok::kw_catch:

1683 case tok::kw_class:

1684 case tok::kw_continue:

1685 case tok::kw_const:

1686 case tok::kw_default:

1687 case tok::kw_delete:

1688 case tok::kw_do:

1689 case tok::kw_else:

1690 case tok::kw_enum:

1691 case tok::kw_export:

1692 case tok::kw_false:

1693 case tok::kw_for:

1694 case tok::kw_if:

1695 case tok::kw_import:

1696 case tok::kw_module:

1697 case tok::kw_new:

1698 case tok::kw_return:

1699 case tok::kw_static:

1700 case tok::kw_switch:

1701 case tok::kw_this:

1702 case tok::kw_throw:

1703 case tok::kw_true:

1704 case tok::kw_try:

1705 case tok::kw_typeof:

1706 case tok::kw_void:

1707 case tok::kw_while:

1708

1709 return false;

1710 case tok::identifier: {

1711

1712

1713 bool IsPseudoKeyword =

1715 JsExtraKeywords.end();

1716 return AcceptIdentifierName || !IsPseudoKeyword;

1717 }

1718 default:

1719

1720

1721 break;

1722 }

1723

1725

1726#define KEYWORD(X, Y) case tok::kw_##X:

1727#include "clang/Basic/TokenKinds.def"

1728

1729

1730 return true;

1731 default:

1732

1733 return false;

1734 }

1735 }

1736

1737

1738

1740 if (Tok.isAccessSpecifierKeyword())

1741 return true;

1742 switch (Tok.Tok.getKind()) {

1743 case tok::kw_bool:

1744 case tok::kw_break:

1745 case tok::kw_case:

1746 case tok::kw_catch:

1747 case tok::kw_char:

1748 case tok::kw_class:

1749 case tok::kw_const:

1750 case tok::kw_continue:

1751 case tok::kw_default:

1752 case tok::kw_do:

1753 case tok::kw_double:

1754 case tok::kw_else:

1755 case tok::kw_enum:

1756 case tok::kw_explicit:

1757 case tok::kw_extern:

1758 case tok::kw_false:

1759 case tok::kw_float:

1760 case tok::kw_for:

1761 case tok::kw_goto:

1762 case tok::kw_if:

1763 case tok::kw_int:

1764 case tok::kw_long:

1765 case tok::kw_namespace:

1766 case tok::kw_new:

1767 case tok::kw_operator:

1768 case tok::kw_return:

1769 case tok::kw_short:

1770 case tok::kw_sizeof:

1771 case tok::kw_static:

1772 case tok::kw_struct:

1773 case tok::kw_switch:

1774 case tok::kw_this:

1775 case tok::kw_throw:

1776 case tok::kw_true:

1777 case tok::kw_try:

1778 case tok::kw_typeof:

1779 case tok::kw_using:

1780 case tok::kw_virtual:

1781 case tok::kw_void:

1782 case tok::kw_volatile:

1783 case tok::kw_while:

1784 return true;

1785 default:

1786 return Tok.is(tok::identifier) &&

1787 CSharpExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==

1788 CSharpExtraKeywords.end();

1789 }

1791

1794 }

1799 }

1800

1803 case tok::kw_case:

1804 case tok::kw_class:

1805 case tok::kw_const:

1806 case tok::kw_continue:

1807 case tok::kw_default:

1808 case tok::kw_do:

1809 case tok::kw_extern:

1810 case tok::kw_else:

1811 case tok::kw_enum:

1812 case tok::kw_for:

1813 case tok::kw_if:

1814 case tok::kw_restrict:

1815 case tok::kw_signed:

1816 case tok::kw_static:

1817 case tok::kw_struct:

1818 case tok::kw_typedef:

1819 case tok::kw_union:

1820 case tok::kw_unsigned:

1821 case tok::kw_virtual:

1822 case tok::kw_while:

1823 return false;

1824 case tok::identifier:

1827 VerilogExtraKeywords.end();

1828 default:

1829

1832 }

1833

1834

1835

1836

1838 auto Info = Tok.Tok.getIdentifierInfo();

1839 if (!Info)

1840 return false;

1841 switch (Info->getPPKeywordID()) {

1842 case tok::pp_define:

1843 case tok::pp_else:

1844 case tok::pp_endif:

1845 case tok::pp_ifdef:

1846 case tok::pp_ifndef:

1847 case tok::pp_include:

1848 case tok::pp_line:

1849 case tok::pp_pragma:

1850 case tok::pp_undef:

1851 return true;

1852 default:

1860 }

1861 }

1862

1863

1865

1868 }

1869

1870

1880 }

1881

1882

1885 return false;

1888 return !(Prev &&

1890 }

1896 }

1897

1900

1901 return Tok.is(TT_CaseLabelColon) ||

1902 (Tok.is(tok::kw_default) &&

1905 }

1906

1907

1908

1912 }

1913

1916 case tok::kw_extern:

1917 case tok::kw_signed:

1918 case tok::kw_static:

1919 case tok::kw_unsigned:

1920 case tok::kw_virtual:

1921 return true;

1922 case tok::identifier:

1930 default:

1931 return false;

1932 }

1933 }

1937 kw_let, tok::kw_class);

1938 }

1939

1942 case tok::kw_class:

1943 case tok::kw_else:

1944 case tok::kw_false:

1945 case tok::kw_if:

1946 case tok::kw_int:

1947 case tok::kw_true:

1948 return true;

1949 default:

1950 return Tok.is(tok::identifier) &&

1952 TableGenExtraKeywords.end();

1953 }

1954 }

1955

1956private:

1957

1958 std::unordered_set<IdentifierInfo *> JsExtraKeywords;

1959

1960

1961 std::unordered_set<IdentifierInfo *> CSharpExtraKeywords;

1962

1963

1964 std::unordered_set<IdentifierInfo *> VerilogExtraKeywords;

1965

1966

1967 std::unordered_set<IdentifierInfo *> TableGenExtraKeywords;

1968};

1969

1970inline bool isLineComment(const FormatToken &FormatTok) {

1971 return FormatTok.is(tok::comment) && !FormatTok.TokenText.starts_with("/*");

1972}

1973

1974

1975

1976

1978 const FormatToken *Previous,

1979 const FormatToken *MinColumnToken) {

1980 if (Previous || !MinColumnToken)

1981 return false;

1982 unsigned MinContinueColumn =

1983 MinColumnToken->OriginalColumn + (isLineComment(*MinColumnToken) ? 0 : 1);

1984 return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&

1986 FormatTok.OriginalColumn >= MinContinueColumn;

1987}

1988

1989

1990bool startsNextParameter(const FormatToken &Current, const FormatStyle &Style);

1991

1992}

1993}

1994

1995#endif

enum clang::sema::@1727::IndirectLocalPathEntry::EntryKind Kind

Various functions to configurably format source code.

Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.

Defines and computes precedence levels for binary/ternary operators.

static constexpr bool isOneOf()

#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _)

ContinuationIndenter * Indenter

One of these records is kept for each identifier that is lexed.

tok::PPKeywordKind getPPKeywordID() const

Return the preprocessor keyword ID for this identifier.

Implements an efficient mapping from strings to IdentifierInfo nodes.

IdentifierInfo & get(StringRef Name)

Return the identifier token info for the specified named identifier.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

Encodes a location in the source.

A trivial tuple used to represent a source range.

SourceLocation getEnd() const

SourceLocation getBegin() const

Token - This structure provides full information about a lexed token.

IdentifierInfo * getIdentifierInfo() const

bool is(tok::TokenKind K) const

is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....

tok::TokenKind getKind() const

bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const

Return true if we have an ObjC keyword identifier.

The base class of the type hierarchy.

unsigned formatFromToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) override

Apply the special formatting that the given role demands.

void CommaFound(const FormatToken *Token) override

Adds Token as the next comma to the CommaSeparated list.

const FormatToken * lastComma() override

unsigned formatAfterToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) override

Same as formatFromToken, but assumes that the first token has already been set thereby deciding on th...

void precomputeFormattingInfos(const FormatToken *Token) override

After the TokenAnnotator has finished annotating all the tokens, this function precomputes required i...

virtual unsigned formatAfterToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun)

Same as formatFromToken, but assumes that the first token has already been set thereby deciding on th...

virtual void precomputeFormattingInfos(const FormatToken *Token)

After the TokenAnnotator has finished annotating all the tokens, this function precomputes required i...

const FormatStyle & Style

virtual void CommaFound(const FormatToken *Token)

Notifies the Role that a comma was found.

virtual const FormatToken * lastComma()

virtual unsigned formatFromToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun)

Apply the special formatting that the given role demands.

const char * getTokenTypeName(TokenType Type)

Determines the name of a token type.

MacroRole

Roles a token can take in a configured macro expansion.

@ MR_UnexpandedArg

The token is part of a macro argument that was previously formatted as expansion when formatting the ...

@ MR_Hidden

The token was expanded from a macro definition, and is not visible as part of the macro call.

@ MR_ExpandedArg

The token was expanded from a macro argument when formatting the expanded token sequence.

bool continuesLineComment(const FormatToken &FormatTok, const FormatToken *Previous, const FormatToken *MinColumnToken)

bool isLineComment(const FormatToken &FormatTok)

TokenType

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

bool startsNextParameter(const FormatToken &Current, const FormatStyle &Style)

bool isStringLiteral(TokenKind K)

Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.

ObjCKeywordKind

Provides a namespace for Objective-C keywords which start with an '@'.

TokenKind

Provides a simple uniform namespace for tokens from all C languages.

PPKeywordKind

Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.

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

prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)

Return the precedence of the specified binary operator token.

const FunctionProtoType * T

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

IdentifierInfo * kw_endchecker

IdentifierInfo * kw_endcelldefine

IdentifierInfo * kw_endtable

IdentifierInfo * kw_decimal

IdentifierInfo * kw_module

IdentifierInfo * kw_randc

bool isVerilogEnd(const FormatToken &Tok) const

Returns whether Tok is a Verilog keyword that closes a block.

IdentifierInfo * kw_undefineall

IdentifierInfo * kw_verilogHashHash

IdentifierInfo * kw_foreach

IdentifierInfo * kw_forever

IdentifierInfo * kw_nounconnected_drive

IdentifierInfo * kw_celldefine

IdentifierInfo * kw_delay_mode_unit

IdentifierInfo * kw_signals

IdentifierInfo * kw_strong0

IdentifierInfo * kw_unsafe

IdentifierInfo * kw_inside

IdentifierInfo * kw_CF_ENUM

IdentifierInfo * kw_ifnone

IdentifierInfo * kw_checked

IdentifierInfo * kw_extend

IdentifierInfo * kw_endmodule

IdentifierInfo * kw_inout

IdentifierInfo * kw_synchronized

IdentifierInfo * kw_sample

IdentifierInfo * kw_object

IdentifierInfo * kw_specparam

IdentifierInfo * kw_randcase

IdentifierInfo * kw_endcase

bool isWordLike(const FormatToken &Tok, bool IsVerilog=true) const

Returns true if Tok is a keyword or an identifier.

IdentifierInfo * kw_native

IdentifierInfo * kw_randsequence

IdentifierInfo * kw_always_ff

IdentifierInfo * kw_always_latch

IdentifierInfo * kw_end_keywords

IdentifierInfo * kw_typeof

IdentifierInfo * kw_endproperty

IdentifierInfo * kw_final

IdentifierInfo * kw_interconnect

IdentifierInfo * kw_trireg

IdentifierInfo * kw_apostrophe

IdentifierInfo * kw_join_any

IdentifierInfo * kw_endgenerate

IdentifierInfo * kw_option

IdentifierInfo * kw_assert

IdentifierInfo * kw_weak0

IdentifierInfo * kw_intersect

IdentifierInfo * kw_uwire

IdentifierInfo * kw_string

bool isVerilogBegin(const FormatToken &Tok) const

Returns whether Tok is a Verilog keyword that opens a block.

IdentifierInfo * kw_before

IdentifierInfo * kw_constraint

bool isJavaScriptIdentifier(const FormatToken &Tok, bool AcceptIdentifierName=true) const

Returns true if Tok is a true JavaScript identifier, returns false if it is a keyword or a pseudo key...

IdentifierInfo * kw_initial

bool isVerilogQualifier(const FormatToken &Tok) const

IdentifierInfo * kw_priority

IdentifierInfo * kw_weak1

IdentifierInfo * kw_supply1

IdentifierInfo * kw_input

IdentifierInfo * kw_medium

IdentifierInfo * kw_qsignals

IdentifierInfo * kw_illegal_bins

IdentifierInfo * kw_cover

IdentifierInfo * kw_assume

IdentifierInfo * kw_default_trireg_strength

bool isVerilogStructuredProcedure(const FormatToken &Tok) const

Returns whether Tok is a Verilog keyword that starts a structured procedure like 'always'.

IdentifierInfo * kw_negedge

IdentifierInfo * kw_endtask

IdentifierInfo * kw_CF_OPTIONS

bool isVerilogEndOfLabel(const FormatToken &Tok) const

IdentifierInfo * kw_defset

IdentifierInfo * kw_unique0

IdentifierInfo * kw_vectored

IdentifierInfo * kw_readonly

IdentifierInfo * kw_interface

IdentifierInfo * kw_include

IdentifierInfo * kw_delay_mode_path

IdentifierInfo * kw_declare

bool isVerilogWordOperator(const FormatToken &Tok) const

IdentifierInfo * kw_NS_ERROR_ENUM

IdentifierInfo * kw_sbyte

IdentifierInfo * kw_yield

IdentifierInfo * kw_checker

IdentifierInfo * kw_delay_mode_distributed

IdentifierInfo * kw_ignore_bins

IdentifierInfo * kw_CF_CLOSED_ENUM

IdentifierInfo * kw_program

IdentifierInfo * kw_endfunction

IdentifierInfo * kw_posedge

IdentifierInfo * kw_implicit

IdentifierInfo * kw_assign

IdentifierInfo * kw_optional

IdentifierInfo * kw_delay_mode_zero

IdentifierInfo * kw_delegate

IdentifierInfo * kw_slots

IdentifierInfo * kw_import

IdentifierInfo * kw_multiclass

IdentifierInfo * kw_large

IdentifierInfo * kw_trior

IdentifierInfo * kw_casex

IdentifierInfo * kw_dollar

bool isTableGenKeyword(const FormatToken &Tok) const

IdentifierInfo * kw_repeat

IdentifierInfo * kw_highz0

IdentifierInfo * kw_ushort

bool isVerilogKeywordSymbol(const FormatToken &Tok) const

IdentifierInfo * kw_where

IdentifierInfo * kw_pull1

IdentifierInfo * kw_automatic

IdentifierInfo * kw_ulong

IdentifierInfo * kw_default_decay_time

IdentifierInfo * kw_small

IdentifierInfo * kw_stackalloc

IdentifierInfo * kw_finally

IdentifierInfo * kw_event

IdentifierInfo * kw_timescale

IdentifierInfo * kw_coverpoint

IdentifierInfo * kw_scalared

IdentifierInfo * kw_strong1

IdentifierInfo * kw_NS_CLOSED_ENUM

IdentifierInfo * kw_supply0

IdentifierInfo * kw_endpackage

IdentifierInfo * kw_triand

IdentifierInfo * kw_join_none

IdentifierInfo * kw_returns

IdentifierInfo * kw_local

IdentifierInfo * kw_resetall

IdentifierInfo * kw_solve

bool isCSharpKeyword(const FormatToken &Tok) const

Returns true if Tok is a C# keyword, returns false if it is a anything else.

IdentifierInfo * kw_region

IdentifierInfo * kw_disable

IdentifierInfo * kw___has_include_next

IdentifierInfo * kw___has_include

bool isVerilogHierarchy(const FormatToken &Tok) const

Returns whether Tok is a Verilog keyword that opens a module, etc.

IdentifierInfo * kw_repeated

IdentifierInfo * kw_binsof

IdentifierInfo * kw_endclass

IdentifierInfo * kw_package

IdentifierInfo * kw_async

IdentifierInfo * kw_pull0

IdentifierInfo * kw_wildcard

IdentifierInfo * kw_required

IdentifierInfo * kw_always_comb

IdentifierInfo * kw_internal

IdentifierInfo * kw_sequence

bool isVerilogPPDirective(const FormatToken &Tok) const

Returns whether Tok is a Verilog preprocessor directive.

IdentifierInfo * kw_primitive

IdentifierInfo * kw_casez

IdentifierInfo * kw_localparam

IdentifierInfo * kw_endinterface

IdentifierInfo * kw_infer

IdentifierInfo * kw_unconnected_drive

IdentifierInfo * kw_throws

IdentifierInfo * kw_begin

IdentifierInfo * kw_NS_ENUM

IdentifierInfo * kw_override

IdentifierInfo * kw___except

IdentifierInfo * kw_endprimitive

IdentifierInfo * kw_endgroup

IdentifierInfo * kw_elsif

IdentifierInfo * kw_table

IdentifierInfo * kw_params

IdentifierInfo * kw_endprogram

IdentifierInfo * kw_parameter

IdentifierInfo * kw_NS_OPTIONS

IdentifierInfo * kw_abstract

IdentifierInfo * kw_fixed

IdentifierInfo * kw_internal_ident_after_define

bool isTableGenDefinition(const FormatToken &Tok) const

IdentifierInfo * kw_await

IdentifierInfo * kw_packed

IdentifierInfo * kw_defvar

IdentifierInfo * kw_implements

IdentifierInfo * kw_always

IdentifierInfo * kw_specify

IdentifierInfo * kw_endclocking

IdentifierInfo * kw_verilogHash

IdentifierInfo * kw_generate

IdentifierInfo * kw_macromodule

IdentifierInfo * kw_covergroup

IdentifierInfo * kw_instanceof

IdentifierInfo * kw_matches

IdentifierInfo * kw_qslots

IdentifierInfo * kw_function

IdentifierInfo * kw_unchecked

bool isVerilogIdentifier(const FormatToken &Tok) const

IdentifierInfo * kw_clocking

IdentifierInfo * kw_unique

IdentifierInfo * kw_endspecify

IdentifierInfo * kw_highz1

IdentifierInfo * kw_extends

IdentifierInfo * kw_begin_keywords

IdentifierInfo * kw_tagged

IdentifierInfo * kw_property

IdentifierInfo * kw_default_nettype

IdentifierInfo * kw_output

IdentifierInfo * kw_endsequence

IdentifierInfo * kw_sealed

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.

unsigned NestingLevel

The nesting level of this token, i.e.

unsigned MustBreakBeforeFinalized

Whether MustBreakBefore is finalized during parsing and must not be reset between runs.

bool isMemberAccess() const

Returns true if this is a "." or "->" accessing a member.

unsigned FakeRParens

Insert this many fake ) after this token for correct indentation.

bool ArrayInitializerLineStart

This notes the start of the line of an array initializer.

bool isTypeFinalized() const

bool Optional

Is optional and can be removed.

bool MacroParent

When macro expansion introduces nodes with children, those are marked as MacroParent.

int Newlines

The number of newlines immediately before the Token after formatting.

SmallVector< AnnotatedLine *, 1 > Children

If this token starts a block, this contains all the unwrapped lines in it.

bool closesScopeAfterBlock() const

bool isObjCAtKeyword(tok::ObjCKeywordKind Kind) const

prec::Level ForcedPrecedence

Used to set an operator precedence explicitly.

bool closesBlockOrBlockTypeList(const FormatStyle &Style) const

Same as opensBlockOrBlockTypeList, but for the closing token.

unsigned BindingStrength

The binding strength of a token.

bool isObjCAccessSpecifier() const

const FormatToken * getNamespaceToken() const

Return the actual namespace token, if this token starts a namespace block.

bool isTypeName(const LangOptions &LangOpts) const

unsigned StartsBinaryExpression

true if this token starts a binary expression, i.e.

void setPackingKind(ParameterPackingKind K)

unsigned ClosesTemplateDeclaration

true if this is the ">" of "template<..>".

unsigned OperatorIndex

If this is an operator (or "."/"->") in a sequence of operators with the same precedence,...

bool MightBeFunctionDeclParen

Might be function declaration open/closing paren.

unsigned OriginalColumn

The original 0-based column of this token, including expanded tabs.

unsigned ContinuesLineCommentSection

Does this line comment continue a line comment section?

unsigned CanBreakBefore

true if it is allowed to break before this token.

bool isCppAlternativeOperatorKeyword() const

StringRef TokenText

The raw text of the token.

unsigned LongestObjCSelectorName

If this is the first ObjC selector name in an ObjC method definition or call, this contains the lengt...

ParameterPackingKind getPackingKind() const

SourceLocation getStartOfNonWhitespace() const

Returns actual token start location without leading escaped newlines and whitespace.

bool startsSequence(A K1, Ts... Tokens) const

true if this token starts a sequence with the given tokens in order, following the Next pointers,...

tok::TokenKind ParentBracket

If this is a bracket ("<", "(", "[" or "{"), contains the kind of the surrounding bracket.

unsigned LastNewlineOffset

The offset just past the last ' ' in this token's leading whitespace (relative to WhiteSpaceStart).

unsigned SplitPenalty

Penalty for inserting a line break before this token.

bool opensScope() const

Returns whether Tok is ([{ or an opening < of a template or in protos.

bool isPointerOrReference() const

FormatToken * getNextNonComment() const

Returns the next token ignoring comments.

void setDecision(FormatDecision D)

FormatToken * getPreviousNonComment() const

Returns the previous token ignoring comments.

SmallVector< prec::Level, 4 > FakeLParens

Stores the number of required fake parentheses and the corresponding operator precedence.

unsigned Finalized

If true, this token has been fully formatted (indented and potentially re-formatted inside),...

std::optional< MacroExpansion > MacroCtx

BraceBlockKind getBlockKind() const

FormatToken * Next

The next token in the unwrapped line.

unsigned IsMultiline

Whether the token text contains newlines (escaped or not).

unsigned EndsCppAttributeGroup

true if this token ends a group of C++ attributes.

unsigned NewlinesBefore

The number of newlines immediately before the Token.

void setBlockKind(BraceBlockKind BBK)

bool isIf(bool AllowConstexprMacro=true) const

unsigned SpacesRequiredBefore

The number of spaces that should be inserted before this token.

std::shared_ptr< TokenRole > Role

A token can have a special role that can carry extra information about the token's formatting.

unsigned MustBreakBefore

Whether there must be a line break before this token.

unsigned HasUnescapedNewline

Whether there is at least one unescaped newline before the Token.

unsigned PartOfMultiVariableDeclStmt

Is this token part of a DeclStmt defining multiple variables?

unsigned ColumnWidth

The width of the non-whitespace parts of the token (or its first line for multi-line tokens) in colum...

unsigned ObjCSelectorNameParts

If this is the first ObjC selector name in an ObjC method definition or call, this contains the numbe...

void setType(TokenType T)

bool HasFormFeedBefore

Has "\n\f\n" or "\n\f\r\n" before TokenText.

bool isFunctionLikeKeyword() const

Returns true if this is a keyword that can be used like a function call (e.g.

bool isStringLiteral() const

bool IsArrayInitializer

This starts an array initializer.

bool isBlockIndentedInitRBrace(const FormatStyle &Style) const

Returns true if this token ends a block indented initializer list.

bool closesScope() const

Returns whether Tok is )]} or a closing > of a template or in protos.

unsigned EndsBinaryExpression

true if this token ends a binary expression.

bool isBinaryOperator() const

bool isCppStructuredBinding(bool IsCpp) const

Returns whether the token is the left square bracket of a C++ structured binding declaration.

unsigned UnbreakableTailLength

The length of following tokens until the next natural split point, or the next token that can be brok...

prec::Level getPrecedence() const

FormatDecision getDecision() const

bool is(tok::TokenKind Kind) const

unsigned LastLineColumnWidth

Contains the width in columns of the last line of a multi-line token.

unsigned IndentLevel

The indent level of this token. Copied from the surrounding line.

bool opensBlockOrBlockTypeList(const FormatStyle &Style) const

Returns true if this tokens starts a block-type list, i.e.

unsigned BlockParameterCount

Number of parameters that are nested blocks, if this is "(", "[" or "<".

unsigned TotalLength

The total length of the unwrapped line up to and including this token.

bool hasWhitespaceBefore() const

Returns true if the range of whitespace immediately preceding the Token is not empty.

bool isOneOf(A K1, B K2) const

TokenType getType() const

Returns the token's type, e.g.

unsigned IsFirst

Indicates that this is the first token of the file.

bool isUnaryOperator() const

unsigned IsUnterminatedLiteral

Set to true if this token is an unterminated literal.

bool isTrailingComment() const

unsigned ClosesRequiresClause

true if this is the last token within requires clause.

unsigned ParameterIndex

The 0-based index of the parameter/argument.

int8_t BraceCount

Number of optional braces to be inserted after this token: -1: a single left brace 0: no braces >0: n...

bool isAccessSpecifierKeyword() const

bool canBePointerOrReferenceQualifier() const

unsigned ParameterCount

Number of parameters, if this is "(", "[" or "<".

bool isAccessSpecifier(bool ColonRequired=true) const

bool StartsColumn

The first token in set of column elements.

bool isTypeOrIdentifier(const LangOptions &LangOpts) const

SourceRange WhitespaceRange

The range of the whitespace immediately preceding the Token.

FormatToken * NextOperator

If this is an operator (or "."/"->") in a sequence of operators with the same precedence,...

FormatToken * MatchingParen

If this is a bracket, this points to the matching one.

void copyFrom(const FormatToken &Tok)

void overwriteFixedType(TokenType T)

FormatToken * Previous

The previous token in the unwrapped line.

bool isLabelString() const

Returns true if this is a string literal that's like a label, e.g.

bool endsSequence(A K1, Ts... Tokens) const

true if this token ends a sequence with the given tokens in order, following the Previous pointers,...

void setFinalizedType(TokenType T)

Sets the type and also the finalized flag.

The current state when indenting a unwrapped line.

Contains information on the token's role in a macro expansion.

llvm::SmallVector< FormatToken *, 1 > ExpandedFrom

The stack of macro call identifier tokens this token was expanded from.

unsigned StartOfExpansion

The number of expansions of which this macro is the first entry.

MacroRole Role

The token's role in the macro expansion.

unsigned EndOfExpansion

The number of currently open expansions in ExpandedFrom this macro is the last token in.