This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add 'switch' statement to match.pd language
- From: Michael Matz <matz at suse dot de>
- To: Richard Biener <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 16 Jul 2015 16:51:49 +0200 (CEST)
- Subject: Re: [PATCH] Add 'switch' statement to match.pd language
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot LSU dot 2 dot 11 dot 1507141457160 dot 9923 at zhemvz dot fhfr dot qr> <alpine dot LSU dot 2 dot 20 dot 1507151618130 dot 23227 at wotan dot suse dot de> <9742E78F-EF7F-4AFB-8F26-D3B5871BA366 at gmail dot com> <alpine dot LSU dot 2 dot 20 dot 1507151658480 dot 23227 at wotan dot suse dot de> <alpine dot LSU dot 2 dot 11 dot 1507160901000 dot 9923 at zhemvz dot fhfr dot qr>
Hi,
On Thu, 16 Jul 2015, Richard Biener wrote:
> > Similar, if the condition is an atom you should be able to leave the
> > parens away:
> >
> > (switch
> > cond (minus @0 @1)
> > )
> >
> > (given a predicate 'cond' defined appropriately).
>
> Yes. Though techincally the condition cannot be an atom because
> it has to be a c-expr and that has no notion of atom vs. no-atom.
"1" is a valid c-expr, and quite atomy :) (Or "true")
> But the issue is to unambiguously parse the else clause, thus
Ah, yes, I remember, the c-expr vs expr case; the parser is too limited :)
In that case I find the extra keyword without parens even better:
(switch
when (bla) (foo)
when (bar) (boo)
(blob))
I.e. following 'when' it's an c-expr (when single token, parens optional),
when not following 'when' its a result expr (atomic or not). Think of it
as an infix multi-part keyword (like smalltalk has multi-part method
names), the keyword(s) being "switch(when)*".
I'm undecided if I'd allow function calls as atoms as well (because they
contain parens), like so:
(switch
when integer_zero(@0) @1
when integer_zero(@1) @0
(plus @0 @1))
This would mean that there would be no single-token conditions without
parens where one could leave out outer parens, as otherwise you have a
ambiguity between:
(switch
when true (@0) // (@0) is the result
...)
and
(switch
when token(@0) @1 // (@0) belongs to the when-expr
...)
One has to chose between one or the other, and I think the latter (i.e.
function calls as lone when-expr) occur more often.
(Limiting the number of parens is worthwhile IMHO, but you probably
guessed that much already :))
Ciao,
Michael.