16 #ifndef LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H 17 #define LLVM_CLANG_LIB_FORMAT_FORMATTOKEN_H 24 #include <unordered_set> 29 #define LIST_TOKEN_TYPES \ 30 TYPE(ArrayInitializerLSquare) \ 31 TYPE(ArraySubscriptLSquare) \ 32 TYPE(AttributeColon) \ 33 TYPE(AttributeParen) \ 34 TYPE(AttributeSquare) \ 35 TYPE(BinaryOperator) \ 39 TYPE(ConditionalExpr) \ 40 TYPE(ConflictAlternative) \ 43 TYPE(CtorInitializerColon) \ 44 TYPE(CtorInitializerComma) \ 45 TYPE(DesignatedInitializerLSquare) \ 46 TYPE(DesignatedInitializerPeriod) \ 49 TYPE(FunctionAnnotationRParen) \ 50 TYPE(FunctionDeclarationName) \ 51 TYPE(FunctionLBrace) \ 52 TYPE(FunctionTypeLParen) \ 53 TYPE(ImplicitStringLiteral) \ 54 TYPE(InheritanceColon) \ 55 TYPE(InheritanceComma) \ 56 TYPE(InlineASMBrace) \ 57 TYPE(InlineASMColon) \ 58 TYPE(JavaAnnotation) \ 59 TYPE(JsComputedPropertyName) \ 60 TYPE(JsExponentiation) \ 61 TYPE(JsExponentiationEqual) \ 63 TYPE(JsNonNullAssertion) \ 65 TYPE(JsTypeOperator) \ 66 TYPE(JsTypeOptionalQuestion) \ 69 TYPE(LeadingJavaAnnotation) \ 71 TYPE(MacroBlockBegin) \ 73 TYPE(ObjCBlockLBrace) \ 74 TYPE(ObjCBlockLParen) \ 77 TYPE(ObjCMethodExpr) \ 78 TYPE(ObjCMethodSpecifier) \ 80 TYPE(ObjCStringLiteral) \ 81 TYPE(OverloadedOperator) \ 82 TYPE(OverloadedOperatorLParen) \ 83 TYPE(PointerOrReference) \ 84 TYPE(PureVirtualSpecifier) \ 85 TYPE(RangeBasedForLoopColon) \ 89 TYPE(StructuredBindingLSquare) \ 90 TYPE(TemplateCloser) \ 91 TYPE(TemplateOpener) \ 92 TYPE(TemplateString) \ 93 TYPE(ProtoExtensionLSquare) \ 94 TYPE(TrailingAnnotation) \ 95 TYPE(TrailingReturnArrow) \ 96 TYPE(TrailingUnaryOperator) \ 101 #define TYPE(X) TT_##X, 207 std::unique_ptr<TokenRole>
Role;
319 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
320 return is(K1) ||
is(K2);
322 template <
typename A,
typename B,
typename... Ts>
326 template <
typename T>
bool isNot(T
Kind)
const {
return !
is(Kind); }
330 template <
typename A,
typename... Ts>
332 return startsSequenceInternal(K1, Tokens...);
337 template <
typename A,
typename... Ts>
339 return endsSequenceInternal(K1, Tokens...);
349 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
350 (!ColonRequired || (Next && Next->
is(tok::colon)));
357 return is(tok::at) && Next &&
367 if (
is(TT_TemplateString) && TokenText.endswith(
"${"))
369 if (
is(TT_DictLiteral) &&
is(tok::less))
371 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
377 if (
is(TT_TemplateString) && TokenText.startswith(
"}"))
379 if (
is(TT_DictLiteral) &&
is(tok::greater))
381 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
387 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
388 !
isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
397 case tok::minusminus:
401 case tok::kw_alignof:
414 return is(tok::comment) &&
426 case tok::kw_alignof:
427 case tok::kw_alignas:
428 case tok::kw_decltype:
429 case tok::kw_noexcept:
430 case tok::kw_static_assert:
431 case tok::kw___attribute:
441 if (!
is(tok::string_literal))
444 if (Content.startswith(
"\"") || Content.startswith(
"'"))
445 Content = Content.drop_front(1);
446 if (Content.endswith(
"\"") || Content.endswith(
"'"))
447 Content = Content.drop_back(1);
448 Content = Content.trim();
449 return Content.size() > 1 &&
450 (Content.back() ==
':' || Content.back() ==
'=');
459 return WhitespaceRange.
getEnd();
470 while (Tok && Tok->
is(tok::comment))
478 while (Tok && Tok->
is(tok::comment))
488 return is(TT_ArrayInitializerLSquare) ||
489 is(TT_ProtoExtensionLSquare) ||
491 (BlockKind ==
BK_Block ||
is(TT_DictLiteral) ||
505 }
while (T && T->
isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
507 return T && T->
is(tok::kw_auto);
521 if (
is(tok::comment))
524 if (NamespaceTok && NamespaceTok->
is(tok::kw_inline))
526 return NamespaceTok && NamespaceTok->
is(tok::kw_namespace) ? NamespaceTok
535 template <
typename A,
typename... Ts>
536 bool startsSequenceInternal(A K1, Ts... Tokens)
const {
537 if (
is(tok::comment) && Next)
538 return Next->startsSequenceInternal(K1, Tokens...);
539 return is(K1) && Next && Next->startsSequenceInternal(Tokens...);
542 template <
typename A>
bool startsSequenceInternal(A K1)
const {
543 if (
is(tok::comment) && Next)
544 return Next->startsSequenceInternal(K1);
548 template <
typename A,
typename... Ts>
bool endsSequenceInternal(A K1)
const {
549 if (
is(tok::comment) && Previous)
550 return Previous->endsSequenceInternal(K1);
554 template <
typename A,
typename... Ts>
555 bool endsSequenceInternal(A K1, Ts... Tokens)
const {
556 if (
is(tok::comment) && Previous)
557 return Previous->endsSequenceInternal(K1, Tokens...);
558 return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...);
609 bool DryRun)
override;
612 bool DryRun)
override;
616 Commas.push_back(Token);
622 struct ColumnFormat {
638 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
650 bool HasNestedBracedList;
657 kw_final = &IdentTable.
get(
"final");
658 kw_override = &IdentTable.
get(
"override");
659 kw_in = &IdentTable.
get(
"in");
660 kw_of = &IdentTable.
get(
"of");
661 kw_CF_ENUM = &IdentTable.
get(
"CF_ENUM");
662 kw_CF_OPTIONS = &IdentTable.
get(
"CF_OPTIONS");
663 kw_NS_ENUM = &IdentTable.
get(
"NS_ENUM");
664 kw_NS_OPTIONS = &IdentTable.
get(
"NS_OPTIONS");
666 kw_as = &IdentTable.
get(
"as");
667 kw_async = &IdentTable.
get(
"async");
668 kw_await = &IdentTable.
get(
"await");
669 kw_declare = &IdentTable.
get(
"declare");
670 kw_finally = &IdentTable.
get(
"finally");
671 kw_from = &IdentTable.
get(
"from");
672 kw_function = &IdentTable.
get(
"function");
673 kw_get = &IdentTable.
get(
"get");
674 kw_import = &IdentTable.
get(
"import");
675 kw_is = &IdentTable.
get(
"is");
676 kw_let = &IdentTable.
get(
"let");
677 kw_module = &IdentTable.
get(
"module");
678 kw_readonly = &IdentTable.
get(
"readonly");
679 kw_set = &IdentTable.
get(
"set");
680 kw_type = &IdentTable.
get(
"type");
681 kw_typeof = &IdentTable.
get(
"typeof");
682 kw_var = &IdentTable.
get(
"var");
683 kw_yield = &IdentTable.
get(
"yield");
685 kw_abstract = &IdentTable.
get(
"abstract");
686 kw_assert = &IdentTable.
get(
"assert");
687 kw_extends = &IdentTable.
get(
"extends");
688 kw_implements = &IdentTable.
get(
"implements");
689 kw_instanceof = &IdentTable.
get(
"instanceof");
690 kw_interface = &IdentTable.
get(
"interface");
691 kw_native = &IdentTable.
get(
"native");
692 kw_package = &IdentTable.
get(
"package");
693 kw_synchronized = &IdentTable.
get(
"synchronized");
694 kw_throws = &IdentTable.
get(
"throws");
695 kw___except = &IdentTable.
get(
"__except");
696 kw___has_include = &IdentTable.
get(
"__has_include");
697 kw___has_include_next = &IdentTable.
get(
"__has_include_next");
699 kw_mark = &IdentTable.
get(
"mark");
701 kw_extend = &IdentTable.
get(
"extend");
702 kw_option = &IdentTable.
get(
"option");
703 kw_optional = &IdentTable.
get(
"optional");
704 kw_repeated = &IdentTable.
get(
"repeated");
705 kw_required = &IdentTable.
get(
"required");
706 kw_returns = &IdentTable.
get(
"returns");
708 kw_signals = &IdentTable.
get(
"signals");
709 kw_qsignals = &IdentTable.
get(
"Q_SIGNALS");
710 kw_slots = &IdentTable.
get(
"slots");
711 kw_qslots = &IdentTable.
get(
"Q_SLOTS");
715 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
716 {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
717 kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly,
718 kw_set, kw_type, kw_typeof, kw_var, kw_yield,
720 kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface});
788 return Tok.
is(tok::identifier) &&
790 JsExtraKeywords.end();
795 std::unordered_set<IdentifierInfo *> JsExtraKeywords;
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)) {...
The base class of the type hierarchy.
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token...
tok::TokenKind getKind() const
One of these records is kept for each identifier that is lexed.
Token - This structure provides full information about a lexed token.
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
Implements an efficient mapping from strings to IdentifierInfo nodes.
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Defines and computes precedence levels for binary/ternary operators.
SourceLocation getEnd() const
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IdentifierInfo * getIdentifierInfo() const
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Dataflow Directional Tag Classes.
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)
Return the precedence of the specified binary operator token.
A trivial tuple used to represent a source range.