[cfe-commits] Patch - Add fix-it hint for missing case keyword within a switch scope

Richard Trieu rtrieu at google.com
Tue Apr 19 17:19:53 PDT 2011


I have reworked the program flow.  Instead of tentative parsing, the already
parsed expression is reused within the case statement parsing following
colon detection.

On Fri, Apr 15, 2011 at 2:03 PM, Douglas Gregor <dgregor at apple.com> wrote:

>
> On Apr 15, 2011, at 11:58 AM, Richard Trieu wrote:
>
> > When a valid expression is followed by a colon inside a switch scope,
> suggest a fix-it hint to insert a case before the expression.
> >
> > int f1(int i) {
> >  switch (i) {
> >    0: return 1;
> >    default: return 0;
> >  }
> > }
> >
> > case.cc:3:4: error: expected 'case' keyword before expression
> >    0: return 1;
> >    ^
> >    case
>
> Cool idea, but this...
>
> +    // If a case statement is missing, then back-track to this point and
> +    // insert case keyword.
> +    Token OldToken = Tok;
> +    TentativeParsingAction TPA(*this);
>
> is a huge performance problem, since tentative parsing is expensive and
> should be avoided except after an error occurs or when required by the
> language.
>
> Is there a way to make this diagnostic kick in only when an error is
> imminent, e.g., because we've seen <expression> ':' somewhere within a
> switch statement?
>
>        - Doug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110419/ec3454ee/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: missing-case-keyword2.patch
Type: text/x-patch
Size: 7992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110419/ec3454ee/attachment.bin>


More information about the cfe-commits mailing list