[PATCH] D19106: Fixed a bug in AnnotatedLine::startsWith when there are comments in the line.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 19 11:37:43 PDT 2016


PING.

On Thu, Apr 14, 2016 at 1:52 PM Eric Liu <ioeric at google.com> wrote:

> ioeric updated this revision to Diff 53691.
> ioeric added a comment.
>
> - Addressed reviewer comment.
>
>
> http://reviews.llvm.org/D19106
>
> Files:
>   lib/Format/TokenAnnotator.h
>
> Index: lib/Format/TokenAnnotator.h
> ===================================================================
> --- lib/Format/TokenAnnotator.h
> +++ lib/Format/TokenAnnotator.h
> @@ -83,7 +83,7 @@
>    /// \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...);
> +    return startsWithInternal(First, Tokens...);
>    }
>
>    /// \c true if this line looks like a function definition instead of a
> @@ -124,15 +124,24 @@
>    void operator=(const AnnotatedLine &) = delete;
>
>    template <typename A, typename... Ts>
> -  bool startsWith(FormatToken *Tok, A K1) const {
> +  bool startsWithInternal(const FormatToken *Tok, A K1) const {
> +    // Even though we skip comments in the outter `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 startsWith(FormatToken *Tok, A K1, Ts... Tokens) const {
> -    return startsWith(Tok, K1) && startsWith(Tok->Next, Tokens...);
> +  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...);
>    }
>  };
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160419/caa4ba6b/attachment.html>


More information about the cfe-commits mailing list