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(StatementMacro) \ 90 TYPE(StructuredBindingLSquare) \ 91 TYPE(TemplateCloser) \ 92 TYPE(TemplateOpener) \ 93 TYPE(TemplateString) \ 94 TYPE(ProtoExtensionLSquare) \ 95 TYPE(TrailingAnnotation) \ 96 TYPE(TrailingReturnArrow) \ 97 TYPE(TrailingUnaryOperator) \ 102 #define TYPE(X) TT_##X, 204 std::unique_ptr<TokenRole>
Role;
316 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
317 return is(K1) ||
is(K2);
319 template <
typename A,
typename B,
typename... Ts>
323 template <
typename T>
bool isNot(T
Kind)
const {
return !
is(Kind); }
335 template <
typename A,
typename... Ts>
337 return startsSequenceInternal(K1, Tokens...);
342 template <
typename A,
typename... Ts>
344 return endsSequenceInternal(K1, Tokens...);
354 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
355 (!ColonRequired || (Next && Next->
is(tok::colon)));
362 return is(tok::at) && Next &&
372 if (
is(TT_TemplateString) && TokenText.endswith(
"${"))
374 if (
is(TT_DictLiteral) &&
is(tok::less))
376 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
382 if (
is(TT_TemplateString) && TokenText.startswith(
"}"))
384 if (
is(TT_DictLiteral) &&
is(tok::greater))
386 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
392 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
393 !
isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
402 case tok::minusminus:
406 case tok::kw_alignof:
419 return is(tok::comment) &&
431 case tok::kw_alignof:
432 case tok::kw_alignas:
433 case tok::kw_decltype:
434 case tok::kw_noexcept:
435 case tok::kw_static_assert:
436 case tok::kw___attribute:
446 if (!
is(tok::string_literal))
449 if (Content.startswith(
"\"") || Content.startswith(
"'"))
450 Content = Content.drop_front(1);
451 if (Content.endswith(
"\"") || Content.endswith(
"'"))
452 Content = Content.drop_back(1);
453 Content = Content.trim();
454 return Content.size() > 1 &&
455 (Content.back() ==
':' || Content.back() ==
'=');
464 return WhitespaceRange.
getEnd();
475 while (Tok && Tok->
is(tok::comment))
483 while (Tok && Tok->
is(tok::comment))
493 return is(TT_ArrayInitializerLSquare) ||
494 is(TT_ProtoExtensionLSquare) ||
496 (BlockKind ==
BK_Block ||
is(TT_DictLiteral) ||
510 }
while (T && T->
isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
512 return T && T->
is(tok::kw_auto);
526 if (
is(tok::comment))
529 if (NamespaceTok && NamespaceTok->
isOneOf(tok::kw_inline, tok::kw_export))
531 return NamespaceTok && NamespaceTok->
is(tok::kw_namespace) ? NamespaceTok
540 template <
typename A,
typename... Ts>
541 bool startsSequenceInternal(A K1, Ts... Tokens)
const {
542 if (
is(tok::comment) && Next)
543 return Next->startsSequenceInternal(K1, Tokens...);
544 return is(K1) && Next && Next->startsSequenceInternal(Tokens...);
547 template <
typename A>
bool startsSequenceInternal(A K1)
const {
548 if (
is(tok::comment) && Next)
549 return Next->startsSequenceInternal(K1);
553 template <
typename A,
typename... Ts>
bool endsSequenceInternal(A K1)
const {
554 if (
is(tok::comment) && Previous)
555 return Previous->endsSequenceInternal(K1);
559 template <
typename A,
typename... Ts>
560 bool endsSequenceInternal(A K1, Ts... Tokens)
const {
561 if (
is(tok::comment) && Previous)
562 return Previous->endsSequenceInternal(K1, Tokens...);
563 return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...);
616 bool DryRun)
override;
619 bool DryRun)
override;
623 Commas.push_back(Token);
629 return Commas.back();
635 struct ColumnFormat {
651 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
663 bool HasNestedBracedList;
670 kw_final = &IdentTable.
get(
"final");
671 kw_override = &IdentTable.
get(
"override");
672 kw_in = &IdentTable.
get(
"in");
673 kw_of = &IdentTable.
get(
"of");
674 kw_CF_ENUM = &IdentTable.
get(
"CF_ENUM");
675 kw_CF_OPTIONS = &IdentTable.
get(
"CF_OPTIONS");
676 kw_NS_ENUM = &IdentTable.
get(
"NS_ENUM");
677 kw_NS_OPTIONS = &IdentTable.
get(
"NS_OPTIONS");
679 kw_as = &IdentTable.
get(
"as");
680 kw_async = &IdentTable.
get(
"async");
681 kw_await = &IdentTable.
get(
"await");
682 kw_declare = &IdentTable.
get(
"declare");
683 kw_finally = &IdentTable.
get(
"finally");
684 kw_from = &IdentTable.
get(
"from");
685 kw_function = &IdentTable.
get(
"function");
686 kw_get = &IdentTable.
get(
"get");
687 kw_import = &IdentTable.
get(
"import");
688 kw_infer = &IdentTable.
get(
"infer");
689 kw_is = &IdentTable.
get(
"is");
690 kw_let = &IdentTable.
get(
"let");
691 kw_module = &IdentTable.
get(
"module");
692 kw_readonly = &IdentTable.
get(
"readonly");
693 kw_set = &IdentTable.
get(
"set");
694 kw_type = &IdentTable.
get(
"type");
695 kw_typeof = &IdentTable.
get(
"typeof");
696 kw_var = &IdentTable.
get(
"var");
697 kw_yield = &IdentTable.
get(
"yield");
699 kw_abstract = &IdentTable.
get(
"abstract");
700 kw_assert = &IdentTable.
get(
"assert");
701 kw_extends = &IdentTable.
get(
"extends");
702 kw_implements = &IdentTable.
get(
"implements");
703 kw_instanceof = &IdentTable.
get(
"instanceof");
704 kw_interface = &IdentTable.
get(
"interface");
705 kw_native = &IdentTable.
get(
"native");
706 kw_package = &IdentTable.
get(
"package");
707 kw_synchronized = &IdentTable.
get(
"synchronized");
708 kw_throws = &IdentTable.
get(
"throws");
709 kw___except = &IdentTable.
get(
"__except");
710 kw___has_include = &IdentTable.
get(
"__has_include");
711 kw___has_include_next = &IdentTable.
get(
"__has_include_next");
713 kw_mark = &IdentTable.
get(
"mark");
715 kw_extend = &IdentTable.
get(
"extend");
716 kw_option = &IdentTable.
get(
"option");
717 kw_optional = &IdentTable.
get(
"optional");
718 kw_repeated = &IdentTable.
get(
"repeated");
719 kw_required = &IdentTable.
get(
"required");
720 kw_returns = &IdentTable.
get(
"returns");
722 kw_signals = &IdentTable.
get(
"signals");
723 kw_qsignals = &IdentTable.
get(
"Q_SIGNALS");
724 kw_slots = &IdentTable.
get(
"slots");
725 kw_qslots = &IdentTable.
get(
"Q_SLOTS");
729 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
730 {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
731 kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly,
732 kw_set, kw_type, kw_typeof, kw_var, kw_yield,
734 kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface});
803 return Tok.
is(tok::identifier) &&
805 JsExtraKeywords.end();
810 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.