summaryrefslogtreecommitdiff
path: root/lib/Format/FormatToken.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Format/FormatToken.h')
-rw-r--r--lib/Format/FormatToken.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h
index 9094e7689e1de..10390c42911b8 100644
--- a/lib/Format/FormatToken.h
+++ b/lib/Format/FormatToken.h
@@ -86,6 +86,7 @@ namespace format {
TYPE(RegexLiteral) \
TYPE(SelectorName) \
TYPE(StartOfName) \
+ TYPE(StatementMacro) \
TYPE(StructuredBindingLSquare) \
TYPE(TemplateCloser) \
TYPE(TemplateOpener) \
@@ -188,10 +189,6 @@ struct FormatToken {
bool ClosesTemplateDeclaration = false;
/// Number of parameters, if this is "(", "[" or "<".
- ///
- /// This is initialized to 1 as we don't need to distinguish functions with
- /// 0 parameters from functions with 1 parameter. Thus, we can simply count
- /// the number of commas.
unsigned ParameterCount = 0;
/// Number of parameters that are nested blocks,
@@ -268,7 +265,7 @@ struct FormatToken {
/// \c true if this token ends a binary expression.
bool EndsBinaryExpression = false;
- /// Is this is an operator (or "."/"->") in a sequence of operators
+ /// If this is an operator (or "."/"->") in a sequence of operators
/// with the same precedence, contains the 0-based operator index.
unsigned OperatorIndex = 0;
@@ -325,6 +322,14 @@ struct FormatToken {
}
template <typename T> bool isNot(T Kind) const { return !is(Kind); }
+ bool closesScopeAfterBlock() const {
+ if (BlockKind == BK_Block)
+ return true;
+ if (closesScope())
+ return Previous->closesScopeAfterBlock();
+ return false;
+ }
+
/// \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>
@@ -520,8 +525,8 @@ struct FormatToken {
const FormatToken *NamespaceTok = this;
if (is(tok::comment))
NamespaceTok = NamespaceTok->getNextNonComment();
- // Detect "(inline)? namespace" in the beginning of a line.
- if (NamespaceTok && NamespaceTok->is(tok::kw_inline))
+ // Detect "(inline|export)? namespace" in the beginning of a line.
+ if (NamespaceTok && NamespaceTok->isOneOf(tok::kw_inline, tok::kw_export))
NamespaceTok = NamespaceTok->getNextNonComment();
return NamespaceTok && NamespaceTok->is(tok::kw_namespace) ? NamespaceTok
: nullptr;
@@ -594,6 +599,8 @@ public:
/// Notifies the \c Role that a comma was found.
virtual void CommaFound(const FormatToken *Token) {}
+ virtual const FormatToken *lastComma() { return nullptr; }
+
protected:
const FormatStyle &Style;
};
@@ -616,6 +623,12 @@ public:
Commas.push_back(Token);
}
+ const FormatToken *lastComma() override {
+ if (Commas.empty())
+ return nullptr;
+ return Commas.back();
+ }
+
private:
/// A struct that holds information on how to format a given list with
/// a specific number of columns.
@@ -672,6 +685,7 @@ struct AdditionalKeywords {
kw_function = &IdentTable.get("function");
kw_get = &IdentTable.get("get");
kw_import = &IdentTable.get("import");
+ kw_infer = &IdentTable.get("infer");
kw_is = &IdentTable.get("is");
kw_let = &IdentTable.get("let");
kw_module = &IdentTable.get("module");
@@ -743,6 +757,7 @@ struct AdditionalKeywords {
IdentifierInfo *kw_function;
IdentifierInfo *kw_get;
IdentifierInfo *kw_import;
+ IdentifierInfo *kw_infer;
IdentifierInfo *kw_is;
IdentifierInfo *kw_let;
IdentifierInfo *kw_module;