After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 614015 - Allow multiple values in one case statement inside switch
Allow multiple values in one case statement inside switch
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Parser
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-03-26 14:12 UTC by Jukka-Pekka Iivonen
Modified: 2017-12-15 14:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Multivalue 'switch...case' patch (617 bytes, patch)
2010-03-26 14:12 UTC, Jukka-Pekka Iivonen
none Details | Review
parser: Accept comma-separated list in case-statements of switchs (1.87 KB, patch)
2017-12-14 11:48 UTC, Rico Tzschichholz
committed Details | Review

Description Jukka-Pekka Iivonen 2010-03-26 14:12:22 UTC
Created attachment 157169 [details] [review]
Multivalue 'switch...case' patch

This simple patch allows to give multiple values in one case statement. For example, see the following:

	switch (int_a) {
	case 0, 1, 2:
		print ("Here\n");
		break;
	default:
		print ("Default\n");
		break;
	}
Comment 1 Marc-Andre Lureau 2010-03-26 14:26:11 UTC
nice

Sometime I wish I would have case ranges too:

http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Case-Ranges.html#Case-Ranges

With your approach that shouldn't be too hard, although generating lot of label is  probably a bad idea, it would need a proper switch range support.
Comment 2 Maciej (Matthew) Piechotka 2013-12-21 11:03:26 UTC
(In reply to comment #0)
> Created an attachment (id=157169) [details] [review]
> Multivalue 'switch...case' patch
> 
> This simple patch allows to give multiple values in one case statement. For
> example, see the following:
> 
>     switch (int_a) {
>     case 0, 1, 2:
>         print ("Here\n");
>         break;
>     default:
>         print ("Default\n");
>         break;
>     }

It's redundant syntax (at least now) - you can write it in a way similar to C/C++/C#/...:

switch (int_a) {
case 0:
case 1:
case 2:
    print ("Here\n");
    break;
default:
    print ("Default\n");
    break;
}
Comment 3 Rico Tzschichholz 2017-12-14 11:48:58 UTC
Created attachment 365529 [details] [review]
parser: Accept comma-separated list in case-statements of switchs

  switch (i) {
  case 0, 1, 2:
    break;
  }