diff options
author | Daniel Jasper <djasper@google.com> | 2015-06-17 09:43:56 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-06-17 09:43:56 +0000 |
commit | e285b8dd2e0d21721d6ddcc1dfa5cffce506f773 (patch) | |
tree | 897bdee7e5e680ed57061687dc0e0a5a4db25f61 /clang/lib/Format/TokenAnnotator.h | |
parent | afa4ea71217a3564e4cb1a2439c6dd5bb3bfa863 (diff) | |
download | bcm5719-llvm-e285b8dd2e0d21721d6ddcc1dfa5cffce506f773.tar.gz bcm5719-llvm-e285b8dd2e0d21721d6ddcc1dfa5cffce506f773.zip |
clang-format: NFC. Add a function to test whether an annotated line
starts with a given sequence of tokens. Only the one-token version is
used yet, but other usages are coming up momentarily.
llvm-svn: 239892
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.h')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h index a948cdb1c41..b8a6be057a6 100644 --- a/clang/lib/Format/TokenAnnotator.h +++ b/clang/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 |