summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.h')
-rw-r--r--clang/lib/Format/TokenAnnotator.h42
1 files changed, 2 insertions, 40 deletions
diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h
index dfe1d1ddebd..baa68ded974 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -83,7 +83,7 @@ public:
/// \c true if this line starts with the given tokens in order, ignoring
/// comments.
template <typename... Ts> bool startsWith(Ts... Tokens) const {
- return startsWithInternal(First, Tokens...);
+ return First && First->startsSequence(Tokens...);
}
/// \c true if this line ends with the given tokens in reversed order,
@@ -91,7 +91,7 @@ public:
/// For example, given tokens [T1, T2, T3, ...], the function returns true if
/// this line is like "... T3 T2 T1".
template <typename... Ts> bool endsWith(Ts... Tokens) const {
- return endsWithInternal(Last, Tokens...);
+ return Last && Last->endsSequence(Tokens...);
}
/// \c true if this line looks like a function definition instead of a
@@ -130,44 +130,6 @@ private:
// Disallow copying.
AnnotatedLine(const AnnotatedLine &) = delete;
void operator=(const AnnotatedLine &) = delete;
-
- template <typename A, typename... Ts>
- bool startsWithInternal(const FormatToken *Tok, A K1) const {
- // Even though we skip comments in the outer `startWithInternal` function,
- // this loop is still necessary if it is invoked by the public interface
- // `startsWith`.
- while (Tok && Tok->is(tok::comment))
- Tok = Tok->Next;
- return Tok && Tok->is(K1);
- }
-
- template <typename A, typename... Ts>
- bool startsWithInternal(const FormatToken *Tok, A K1, Ts... Tokens) const {
- // Skip comments before calling `startsWithInternal(Tok, K1)` so that the
- // second call to `startsWithInternal` takes the correct `Tok->Next`, which
- // should be the next token of the token checked in the first call.
- while (Tok && Tok->is(tok::comment))
- Tok = Tok->Next;
- return Tok && startsWithInternal(Tok, K1) &&
- startsWithInternal(Tok->Next, Tokens...);
- }
-
- template <typename A, typename... Ts>
- bool endsWithInternal(const FormatToken *Tok, A K1) const {
- // See the comments above in `startsWithInternal(Tok, K1)`.
- while (Tok && Tok->is(tok::comment))
- Tok = Tok->Previous;
- return Tok && Tok->is(K1);
- }
-
- template <typename A, typename... Ts>
- bool endsWithInternal(const FormatToken *Tok, A K1, Ts... Tokens) const {
- // See the comments above in `startsWithInternal(Tok, K1, Tokens)`.
- while (Tok && Tok->is(tok::comment))
- Tok = Tok->Previous;
- return Tok && endsWithInternal(Tok, K1) &&
- endsWithInternal(Tok->Previous, Tokens...);
- }
};
/// \brief Determines extra information about the tokens comprising an
OpenPOWER on IntegriCloud