diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:44:14 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:44:14 +0000 |
commit | 2b6b257f4e5503a7a2675bdb8735693db769f75c (patch) | |
tree | e85e046ae7003fe3bcc8b5454cd0fa3f7407b470 /lib/Format/FormatToken.h | |
parent | b4348ed0b7e90c0831b925fbee00b5f179a99796 (diff) |
Notes
Diffstat (limited to 'lib/Format/FormatToken.h')
-rw-r--r-- | lib/Format/FormatToken.h | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index b683660f350a..43b162513620 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -54,6 +54,7 @@ namespace format { TYPE(JsComputedPropertyName) \ TYPE(JsFatArrow) \ TYPE(JsTypeColon) \ + TYPE(JsTypeOperator) \ TYPE(JsTypeOptionalQuestion) \ TYPE(LambdaArrow) \ TYPE(LambdaLSquare) \ @@ -144,7 +145,7 @@ struct FormatToken { /// \brief Whether the token text contains newlines (escaped or not). bool IsMultiline = false; - /// \brief Indicates that this is the first token. + /// \brief Indicates that this is the first token of the file. bool IsFirst = false; /// \brief Whether there must be a line break before this token. @@ -296,6 +297,20 @@ struct FormatToken { } template <typename T> bool isNot(T Kind) const { return !is(Kind); } + /// \c true if this token starts a sequence with the given tokens in order, + /// following the ``Next`` pointers, ignoring comments. + template <typename A, typename... Ts> + bool startsSequence(A K1, Ts... Tokens) const { + return startsSequenceInternal(K1, Tokens...); + } + + /// \c true if this token ends a sequence with the given tokens in order, + /// following the ``Previous`` pointers, ignoring comments. + template <typename A, typename... Ts> + bool endsSequence(A K1, Ts... Tokens) const { + return endsSequenceInternal(K1, Tokens...); + } + bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); } bool isObjCAtKeyword(tok::ObjCKeywordKind Kind) const { @@ -428,6 +443,34 @@ private: // Disallow copying. FormatToken(const FormatToken &) = delete; void operator=(const FormatToken &) = delete; + + template <typename A, typename... Ts> + bool startsSequenceInternal(A K1, Ts... Tokens) const { + if (is(tok::comment) && Next) + return Next->startsSequenceInternal(K1, Tokens...); + return is(K1) && Next && Next->startsSequenceInternal(Tokens...); + } + + template <typename A> + bool startsSequenceInternal(A K1) const { + if (is(tok::comment) && Next) + return Next->startsSequenceInternal(K1); + return is(K1); + } + + template <typename A, typename... Ts> + bool endsSequenceInternal(A K1) const { + if (is(tok::comment) && Previous) + return Previous->endsSequenceInternal(K1); + return is(K1); + } + + template <typename A, typename... Ts> + bool endsSequenceInternal(A K1, Ts... Tokens) const { + if (is(tok::comment) && Previous) + return Previous->endsSequenceInternal(K1, Tokens...); + return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...); + } }; class ContinuationIndenter; @@ -528,17 +571,24 @@ struct AdditionalKeywords { kw_final = &IdentTable.get("final"); kw_override = &IdentTable.get("override"); kw_in = &IdentTable.get("in"); + kw_of = &IdentTable.get("of"); kw_CF_ENUM = &IdentTable.get("CF_ENUM"); kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS"); kw_NS_ENUM = &IdentTable.get("NS_ENUM"); kw_NS_OPTIONS = &IdentTable.get("NS_OPTIONS"); + kw_as = &IdentTable.get("as"); + kw_async = &IdentTable.get("async"); + kw_await = &IdentTable.get("await"); kw_finally = &IdentTable.get("finally"); + kw_from = &IdentTable.get("from"); kw_function = &IdentTable.get("function"); kw_import = &IdentTable.get("import"); kw_is = &IdentTable.get("is"); kw_let = &IdentTable.get("let"); + kw_type = &IdentTable.get("type"); kw_var = &IdentTable.get("var"); + kw_yield = &IdentTable.get("yield"); kw_abstract = &IdentTable.get("abstract"); kw_assert = &IdentTable.get("assert"); @@ -571,6 +621,7 @@ struct AdditionalKeywords { IdentifierInfo *kw_final; IdentifierInfo *kw_override; IdentifierInfo *kw_in; + IdentifierInfo *kw_of; IdentifierInfo *kw_CF_ENUM; IdentifierInfo *kw_CF_OPTIONS; IdentifierInfo *kw_NS_ENUM; @@ -578,12 +629,18 @@ struct AdditionalKeywords { IdentifierInfo *kw___except; // JavaScript keywords. + IdentifierInfo *kw_as; + IdentifierInfo *kw_async; + IdentifierInfo *kw_await; IdentifierInfo *kw_finally; + IdentifierInfo *kw_from; IdentifierInfo *kw_function; IdentifierInfo *kw_import; IdentifierInfo *kw_is; IdentifierInfo *kw_let; + IdentifierInfo *kw_type; IdentifierInfo *kw_var; + IdentifierInfo *kw_yield; // Java keywords. IdentifierInfo *kw_abstract; |