forked from laurentlb/shader-minifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is relatively simple and straightforward. Note that this is much more permissive than GLSL compilers seem to be; for example I'm pretty sure this will allow much more in a case label than it should (I think a literal int must come after). But I don't think it will cause the minifier to emit invalid GLSL unless the input was invalid already. It's actually somewhat unclear what the right grammar even is here. Looking at the 4.5 spec linked in laurentlb#18 -- section 9 (the normative grammar), page 205 says that a `case_label` is `CASE expression COLON`, but from testing with an actual compiler it looks like it needs to be a literal integer. Also the definition of `switch_statement_list` doesn't include `case_label`. So by my reading that's a bug in the spec (or at least a place that compilers are quite reasonably more restrictive) so even if we did want to be perfectly correct here I'm not sure what exactly that looks like :) Fixes laurentlb#18.
- Loading branch information
Showing
8 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
void h() | ||
{ | ||
switch(42){ | ||
case 42: | ||
break; | ||
} | ||
} | ||
|
||
#define GOOD 42 | ||
|
||
void i() | ||
{ | ||
switch(42){ | ||
case GOOD: | ||
break; | ||
} | ||
} | ||
void h(in int i) | ||
{ | ||
switch(i){ | ||
case 0: | ||
break; | ||
} | ||
} | ||
void i(in int i) | ||
{ | ||
switch(i+42){ | ||
case 0: | ||
break; | ||
} | ||
} | ||
float G() | ||
{ | ||
switch(42){ | ||
case 42: | ||
float i=4.2; | ||
float k=2.4; | ||
return i+k; | ||
case 43: | ||
float i=4.3; | ||
return i+3.4; | ||
default: | ||
return 0.; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
void switchConst() { | ||
switch (42) { | ||
case 42: | ||
break; | ||
} | ||
} | ||
|
||
#define GOOD 42 | ||
void switchDefine() { | ||
switch (42) { | ||
case GOOD: | ||
break; | ||
} | ||
} | ||
|
||
void switchArg(in int someArg) { | ||
switch (someArg) { | ||
case 0: | ||
break; | ||
} | ||
} | ||
|
||
void switchExpr(in int someArg) { | ||
switch (someArg + 42) { | ||
case 0: | ||
break; | ||
} | ||
} | ||
|
||
float switchMultiple() { | ||
switch (42) { | ||
case 42: | ||
float someVar = 4.2; | ||
float otherVar = 2.4; | ||
return someVar + otherVar; | ||
case 43: | ||
float someVar = 4.3; | ||
return someVar + 3.4; | ||
default: | ||
return 0.0; | ||
} | ||
} |