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(AttributeParen) \ 33 TYPE(BinaryOperator) \ 37 TYPE(ConditionalExpr) \ 38 TYPE(ConflictAlternative) \ 41 TYPE(CtorInitializerColon) \ 42 TYPE(CtorInitializerComma) \ 43 TYPE(DesignatedInitializerLSquare) \ 44 TYPE(DesignatedInitializerPeriod) \ 47 TYPE(FunctionAnnotationRParen) \ 48 TYPE(FunctionDeclarationName) \ 49 TYPE(FunctionLBrace) \ 50 TYPE(FunctionTypeLParen) \ 51 TYPE(ImplicitStringLiteral) \ 52 TYPE(InheritanceColon) \ 53 TYPE(InheritanceComma) \ 54 TYPE(InlineASMBrace) \ 55 TYPE(InlineASMColon) \ 56 TYPE(JavaAnnotation) \ 57 TYPE(JsComputedPropertyName) \ 58 TYPE(JsExponentiation) \ 59 TYPE(JsExponentiationEqual) \ 61 TYPE(JsNonNullAssertion) \ 63 TYPE(JsTypeOperator) \ 64 TYPE(JsTypeOptionalQuestion) \ 67 TYPE(LeadingJavaAnnotation) \ 69 TYPE(MacroBlockBegin) \ 71 TYPE(ObjCBlockLBrace) \ 72 TYPE(ObjCBlockLParen) \ 75 TYPE(ObjCMethodExpr) \ 76 TYPE(ObjCMethodSpecifier) \ 78 TYPE(ObjCStringLiteral) \ 79 TYPE(OverloadedOperator) \ 80 TYPE(OverloadedOperatorLParen) \ 81 TYPE(PointerOrReference) \ 82 TYPE(PureVirtualSpecifier) \ 83 TYPE(RangeBasedForLoopColon) \ 87 TYPE(StructuredBindingLSquare) \ 88 TYPE(TemplateCloser) \ 89 TYPE(TemplateOpener) \ 90 TYPE(TemplateString) \ 91 TYPE(TrailingAnnotation) \ 92 TYPE(TrailingReturnArrow) \ 93 TYPE(TrailingUnaryOperator) \ 98 #define TYPE(X) TT_##X, 204 std::unique_ptr<TokenRole>
Role;
306 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
307 return is(K1) ||
is(K2);
309 template <
typename A,
typename B,
typename... Ts>
317 template <
typename A,
typename... Ts>
319 return startsSequenceInternal(K1, Tokens...);
324 template <
typename A,
typename... Ts>
326 return endsSequenceInternal(K1, Tokens...);
336 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
337 (!ColonRequired || (Next && Next->
is(tok::colon)));
344 return is(tok::at) && Next &&
353 if (
is(TT_TemplateString) && TokenText.endswith(
"${"))
355 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
360 if (
is(TT_TemplateString) && TokenText.startswith(
"}"))
362 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
368 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
369 !
isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
378 case tok::minusminus:
382 case tok::kw_alignof:
395 return is(tok::comment) &&
407 case tok::kw_alignof:
408 case tok::kw_alignas:
409 case tok::kw_decltype:
410 case tok::kw_noexcept:
411 case tok::kw_static_assert:
412 case tok::kw___attribute:
422 if (!
is(tok::string_literal))
425 if (Content.startswith(
"\"") || Content.startswith(
"'"))
426 Content = Content.drop_front(1);
427 if (Content.endswith(
"\"") || Content.endswith(
"'"))
428 Content = Content.drop_back(1);
429 Content = Content.trim();
430 return Content.size() > 1 &&
431 (Content.back() ==
':' || Content.back() ==
'=');
440 return WhitespaceRange.
getEnd();
450 while (Tok && Tok->
is(tok::comment))
458 while (Tok && Tok->
is(tok::comment))
468 return is(TT_ArrayInitializerLSquare) ||
470 (BlockKind ==
BK_Block ||
is(TT_DictLiteral) ||
484 }
while (T && T->
isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
486 return T && T->
is(tok::kw_auto);
500 if (
is(tok::comment))
503 if (NamespaceTok && NamespaceTok->
is(tok::kw_inline))
505 return NamespaceTok && NamespaceTok->
is(tok::kw_namespace) ? NamespaceTok
514 template <
typename A,
typename... Ts>
515 bool startsSequenceInternal(A K1, Ts... Tokens)
const {
516 if (
is(tok::comment) && Next)
517 return Next->startsSequenceInternal(K1, Tokens...);
518 return is(K1) && Next && Next->startsSequenceInternal(Tokens...);
521 template <
typename A>
bool startsSequenceInternal(A K1)
const {
522 if (
is(tok::comment) && Next)
523 return Next->startsSequenceInternal(K1);
527 template <
typename A,
typename... Ts>
bool endsSequenceInternal(A K1)
const {
528 if (
is(tok::comment) && Previous)
529 return Previous->endsSequenceInternal(K1);
533 template <
typename A,
typename... Ts>
534 bool endsSequenceInternal(A K1, Ts... Tokens)
const {
535 if (
is(tok::comment) && Previous)
536 return Previous->endsSequenceInternal(K1, Tokens...);
537 return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...);
588 bool DryRun)
override;
591 bool DryRun)
override;
595 Commas.push_back(Token);
601 struct ColumnFormat {
617 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
629 bool HasNestedBracedList;
636 kw_final = &IdentTable.
get(
"final");
637 kw_override = &IdentTable.
get(
"override");
638 kw_in = &IdentTable.
get(
"in");
639 kw_of = &IdentTable.
get(
"of");
640 kw_CF_ENUM = &IdentTable.
get(
"CF_ENUM");
641 kw_CF_OPTIONS = &IdentTable.
get(
"CF_OPTIONS");
642 kw_NS_ENUM = &IdentTable.
get(
"NS_ENUM");
643 kw_NS_OPTIONS = &IdentTable.
get(
"NS_OPTIONS");
645 kw_as = &IdentTable.
get(
"as");
646 kw_async = &IdentTable.
get(
"async");
647 kw_await = &IdentTable.
get(
"await");
648 kw_declare = &IdentTable.
get(
"declare");
649 kw_finally = &IdentTable.
get(
"finally");
650 kw_from = &IdentTable.
get(
"from");
651 kw_function = &IdentTable.
get(
"function");
652 kw_get = &IdentTable.
get(
"get");
653 kw_import = &IdentTable.
get(
"import");
654 kw_is = &IdentTable.
get(
"is");
655 kw_let = &IdentTable.
get(
"let");
656 kw_module = &IdentTable.
get(
"module");
657 kw_readonly = &IdentTable.
get(
"readonly");
658 kw_set = &IdentTable.
get(
"set");
659 kw_type = &IdentTable.
get(
"type");
660 kw_typeof = &IdentTable.
get(
"typeof");
661 kw_var = &IdentTable.
get(
"var");
662 kw_yield = &IdentTable.
get(
"yield");
664 kw_abstract = &IdentTable.
get(
"abstract");
665 kw_assert = &IdentTable.
get(
"assert");
666 kw_extends = &IdentTable.
get(
"extends");
667 kw_implements = &IdentTable.
get(
"implements");
668 kw_instanceof = &IdentTable.
get(
"instanceof");
669 kw_interface = &IdentTable.
get(
"interface");
670 kw_native = &IdentTable.
get(
"native");
671 kw_package = &IdentTable.
get(
"package");
672 kw_synchronized = &IdentTable.
get(
"synchronized");
673 kw_throws = &IdentTable.
get(
"throws");
674 kw___except = &IdentTable.
get(
"__except");
675 kw___has_include = &IdentTable.
get(
"__has_include");
676 kw___has_include_next = &IdentTable.
get(
"__has_include_next");
678 kw_mark = &IdentTable.
get(
"mark");
680 kw_extend = &IdentTable.
get(
"extend");
681 kw_option = &IdentTable.
get(
"option");
682 kw_optional = &IdentTable.
get(
"optional");
683 kw_repeated = &IdentTable.
get(
"repeated");
684 kw_required = &IdentTable.
get(
"required");
685 kw_returns = &IdentTable.
get(
"returns");
687 kw_signals = &IdentTable.
get(
"signals");
688 kw_qsignals = &IdentTable.
get(
"Q_SIGNALS");
689 kw_slots = &IdentTable.
get(
"slots");
690 kw_qslots = &IdentTable.
get(
"Q_SLOTS");
694 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
695 {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
696 kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly,
697 kw_set, kw_type, kw_typeof, kw_var, kw_yield,
699 kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface});
767 return Tok.
is(tok::identifier) &&
769 JsExtraKeywords.end();
774 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.
const FunctionProtoType * T
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.