Add support for "switch" statements.
Switches with both uniform and varying "switch" expressions are supported. Switch statements with varying expressions and very large numbers of labels may not perform well; some issues to be filed shortly will track opportunities for improving these.
This commit is contained in:
9
tests_errors/switch-1.ispc
Normal file
9
tests_errors/switch-1.ispc
Normal file
@@ -0,0 +1,9 @@
|
||||
// Case statement value must be a compile-time integer constant
|
||||
|
||||
void foo(float f) {
|
||||
switch (f) {
|
||||
case 1.5:
|
||||
++f;
|
||||
}
|
||||
}
|
||||
|
||||
12
tests_errors/switch-2.ispc
Normal file
12
tests_errors/switch-2.ispc
Normal file
@@ -0,0 +1,12 @@
|
||||
// Duplicate case value "1"
|
||||
|
||||
void foo(float f) {
|
||||
switch (f) {
|
||||
case 1:
|
||||
++f;
|
||||
case 2:
|
||||
case 1:
|
||||
f = 0;
|
||||
}
|
||||
}
|
||||
|
||||
13
tests_errors/switch-3.ispc
Normal file
13
tests_errors/switch-3.ispc
Normal file
@@ -0,0 +1,13 @@
|
||||
// "case" label illegal outside of "switch" statement
|
||||
|
||||
void foo(float f) {
|
||||
switch (f) {
|
||||
case 1:
|
||||
++f;
|
||||
case 2:
|
||||
f = 0;
|
||||
}
|
||||
case 3:
|
||||
--f;
|
||||
}
|
||||
|
||||
13
tests_errors/switch-4.ispc
Normal file
13
tests_errors/switch-4.ispc
Normal file
@@ -0,0 +1,13 @@
|
||||
// "default" label illegal outside of "switch" statement
|
||||
|
||||
void foo(float f) {
|
||||
default:
|
||||
++f;
|
||||
switch (f) {
|
||||
case 1:
|
||||
++f;
|
||||
case 2:
|
||||
f = 0;
|
||||
}
|
||||
}
|
||||
|
||||
14
tests_errors/switch-5.ispc
Normal file
14
tests_errors/switch-5.ispc
Normal file
@@ -0,0 +1,14 @@
|
||||
// "default" label illegal outside of "switch" statement
|
||||
|
||||
void foo(float f) {
|
||||
default:
|
||||
++f;
|
||||
switch (f) {
|
||||
case 1:
|
||||
++f;
|
||||
continue;
|
||||
case 2:
|
||||
f = 0;
|
||||
}
|
||||
}
|
||||
|
||||
12
tests_errors/switch-6.ispc
Normal file
12
tests_errors/switch-6.ispc
Normal file
@@ -0,0 +1,12 @@
|
||||
// "continue" statement illegal outside of for/while/do/foreach loops
|
||||
|
||||
void foo(float f) {
|
||||
switch (f) {
|
||||
case 1:
|
||||
++f;
|
||||
continue;
|
||||
case 2:
|
||||
f = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user