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(TemplateCloser) \
88 TYPE(TemplateOpener) \
89 TYPE(TemplateString) \
90 TYPE(TrailingAnnotation) \
91 TYPE(TrailingReturnArrow) \
92 TYPE(TrailingUnaryOperator) \
97 #define TYPE(X) TT_##X,
203 std::unique_ptr<TokenRole>
Role;
305 template <
typename A,
typename B>
bool isOneOf(A K1, B K2)
const {
306 return is(K1) ||
is(K2);
308 template <
typename A,
typename B,
typename... Ts>
312 template <
typename T>
bool isNot(T
Kind)
const {
return !
is(Kind); }
316 template <
typename A,
typename... Ts>
318 return startsSequenceInternal(K1,
Tokens...);
323 template <
typename A,
typename... Ts>
325 return endsSequenceInternal(K1,
Tokens...);
335 return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
336 (!ColonRequired || (
Next &&
Next->
is(tok::colon)));
351 if (
is(TT_TemplateString) &&
TokenText.endswith(
"${"))
353 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
358 if (
is(TT_TemplateString) &&
TokenText.startswith(
"}"))
360 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
366 return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
367 !
isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
376 case tok::minusminus:
380 case tok::kw_alignof:
393 return is(tok::comment) &&
405 case tok::kw_alignof:
406 case tok::kw_alignas:
407 case tok::kw_decltype:
408 case tok::kw_noexcept:
409 case tok::kw_static_assert:
410 case tok::kw___attribute:
420 if (!
is(tok::string_literal))
423 if (Content.startswith(
"\"") || Content.startswith(
"'"))
424 Content = Content.drop_front(1);
425 if (Content.endswith(
"\"") || Content.endswith(
"'"))
426 Content = Content.drop_back(1);
427 Content = Content.trim();
428 return Content.size() > 1 &&
429 (Content.back() ==
':' || Content.back() ==
'=');
448 while (Tok && Tok->
is(tok::comment))
456 while (Tok && Tok->
is(tok::comment))
466 return is(TT_ArrayInitializerLSquare) ||
485 if (
is(tok::comment))
488 if (NamespaceTok && NamespaceTok->
is(tok::kw_inline))
490 return NamespaceTok && NamespaceTok->
is(tok::kw_namespace) ? NamespaceTok
499 template <
typename A,
typename... Ts>
500 bool startsSequenceInternal(A K1, Ts...
Tokens)
const {
501 if (
is(tok::comment) &&
Next)
502 return Next->startsSequenceInternal(K1,
Tokens...);
506 template <
typename A>
507 bool startsSequenceInternal(A K1)
const {
508 if (
is(tok::comment) &&
Next)
509 return Next->startsSequenceInternal(K1);
513 template <
typename A,
typename... Ts>
514 bool endsSequenceInternal(A K1)
const {
516 return Previous->endsSequenceInternal(K1);
520 template <
typename A,
typename... Ts>
521 bool endsSequenceInternal(A K1, Ts...
Tokens)
const {
528 class ContinuationIndenter;
575 bool DryRun)
override;
578 bool DryRun)
override;
582 Commas.push_back(Token);
588 struct ColumnFormat {
604 const ColumnFormat *getColumnFormat(
unsigned RemainingCharacters)
const;
616 bool HasNestedBracedList;
680 JsExtraKeywords = std::unordered_set<IdentifierInfo *>(
752 return Tok.
is(tok::identifier) &&
754 JsExtraKeywords.end();
759 std::unordered_set<IdentifierInfo *> JsExtraKeywords;
SourceLocation getEnd() const
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...
One of these records is kept for each identifier that is lexed.
Token - This structure provides full information about a lexed token.
tok::TokenKind getKind() const
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.
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.
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
ArrayRef< FormatToken * > Tokens
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
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)) {...
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.
IdentifierInfo * getIdentifierInfo() const
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.