summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.h
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-04-25 15:09:22 +0000
committerEric Liu <ioeric@google.com>2016-04-25 15:09:22 +0000
commit4cfb88a936a60c09ceeee336b73b1fb9a6d80a2d (patch)
tree5f4ae40eff88c26b9eca545fd8a74ed5cf9f1610 /clang/lib/Format/TokenAnnotator.h
parent06c14ec31e738ba8cd7c87449389f3e5d0b4c5ea (diff)
downloadbcm5719-llvm-4cfb88a936a60c09ceeee336b73b1fb9a6d80a2d.tar.gz
bcm5719-llvm-4cfb88a936a60c09ceeee336b73b1fb9a6d80a2d.zip
Added Fixer implementation and fix() interface in clang-format for removing redundant code.
Summary: After applying replacements, redundant code like extra commas or empty namespaces might be introduced. Fixer can detect and remove any redundant code introduced by replacements. The current implementation only handles redundant commas. Reviewers: djasper, klimek Subscribers: ioeric, mprobst, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D18551 llvm-svn: 267416
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.h')
-rw-r--r--clang/lib/Format/TokenAnnotator.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h
index 141e8b4106a..dfe1d1ddebd 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -86,6 +86,14 @@ public:
return startsWithInternal(First, Tokens...);
}
+ /// \c true if this line ends with the given tokens in reversed order,
+ /// ignoring comments.
+ /// 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...);
+ }
+
/// \c true if this line looks like a function definition instead of a
/// function declaration. Asserts MightBeFunctionDecl.
bool mightBeFunctionDefinition() const {
@@ -143,6 +151,23 @@ private:
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