aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/TokenAnnotator.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Format/TokenAnnotator.h')
-rw-r--r--lib/Format/TokenAnnotator.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/Format/TokenAnnotator.h b/lib/Format/TokenAnnotator.h
index a948cdb1c419..b8a6be057a6c 100644
--- a/lib/Format/TokenAnnotator.h
+++ b/lib/Format/TokenAnnotator.h
@@ -59,7 +59,7 @@ public:
I->Tok->Previous = Current;
Current = Current->Next;
Current->Children.clear();
- for (const auto& Child : Node.Children) {
+ for (const auto &Child : Node.Children) {
Children.push_back(new AnnotatedLine(Child));
Current->Children.push_back(Children.back());
}
@@ -80,6 +80,12 @@ public:
}
}
+ /// \c true if this line starts with the given tokens in order, ignoring
+ /// comments.
+ template <typename... Ts> bool startsWith(Ts... Tokens) const {
+ return startsWith(First, Tokens...);
+ }
+
FormatToken *First;
FormatToken *Last;
@@ -107,6 +113,18 @@ private:
// Disallow copying.
AnnotatedLine(const AnnotatedLine &) = delete;
void operator=(const AnnotatedLine &) = delete;
+
+ template <typename A, typename... Ts>
+ bool startsWith(FormatToken *Tok, A K1) const {
+ while (Tok && Tok->is(tok::comment))
+ Tok = Tok->Next;
+ return Tok && Tok->is(K1);
+ }
+
+ template <typename A, typename... Ts>
+ bool startsWith(FormatToken *Tok, A K1, Ts... Tokens) const {
+ return startsWith(Tok, K1) && startsWith(Tok->Next, Tokens...);
+ }
};
/// \brief Determines extra information about the tokens comprising an