glsl: glcpp: Allow "#if undefined-macro' to evaluate to false.
authorCarl Worth <cworth@cworth.org>
Fri, 8 Jun 2012 22:00:49 +0000 (15:00 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 26 Jun 2012 22:20:03 +0000 (15:20 -0700)
A strict reading of the GLSL specification would have this be an
error, but we've received reports from users who expect the
preprocessor to interepret undefined macros as 0. This is the standard
behavior of the rpeprocessor for C, and according to these user
reports is also the behavior of other OpenGL implementations.

So here's one of those cases where we can make our users happier by
ignoring the specification. And it's hard to imagine users who really,
really want to see an error for this case.

The two affected tests cases are updated to reflect the new behavior.

Signed-off-by: Carl Worth <cworth@cworth.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/glcpp/glcpp-parse.y
src/glsl/glcpp/tests/070-undefined-macro-in-expression.c
src/glsl/glcpp/tests/070-undefined-macro-in-expression.c.expected
src/glsl/glcpp/tests/098-elif-undefined.c
src/glsl/glcpp/tests/098-elif-undefined.c.expected

index 9e8f9b2d653e6e0ffdaf07a3283ab156d7bfb4fe..78ff8fa9c590beb71c13ab57132bf80764023495 100644 (file)
@@ -341,6 +341,9 @@ integer_constant:
 
 expression:
        integer_constant
+|      IDENTIFIER {
+               $$ = 0;
+       }
 |      expression OR expression {
                $$ = $1 || $3;
        }
index b6dc2ba075fe2596d7e794b13fd369a9e055cff3..d15a4840b0143d8f3b9292ed1160b1dae14dc3ee 100644 (file)
@@ -1,2 +1,5 @@
 #if UNDEFINED_MACRO
+Failure
+#else
+Success
 #endif
index 2bb38a1411ec2d9a38cd27c5ce01339218c187b3..d5a845255790a9a669dd999f924b153f919c304f 100644 (file)
@@ -1,2 +1,6 @@
-0:1(21): preprocessor error: syntax error, unexpected IDENTIFIER
+
+
+
+Success
+
 
index 52a331cc414efd755bf46cf377116e1d312ffa6d..1f520d4d4320ac53f84b3ee8fed7fb6018a61465 100644 (file)
@@ -1,3 +1,7 @@
 #if 0
+Not this
 #elif UNDEFINED_MACRO
+Nor this
+#else
+Yes, this.
 #endif
index de967eac438c1f4129e42fc2a4f8ca0c4d3a242a..2af0a12690abcf6ca10720e406ba331070674d47 100644 (file)
@@ -1,5 +1,8 @@
-0:2(22): preprocessor error: syntax error, unexpected IDENTIFIER
-0:1(7): preprocessor error: Unterminated #if
 
 
 
+
+
+Yes, this.
+
+