Mesa (glsl2): glcpp: Add an explicit diagnostic for #if with no expression.

Carl Worth cworth at kemper.freedesktop.org
Wed Aug 11 14:38:10 PDT 2010


Module: Mesa
Branch: glsl2
Commit: 253cad3f424f71f6984431e5edbde1694ccfae3f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=253cad3f424f71f6984431e5edbde1694ccfae3f

Author: Carl Worth <cworth at cworth.org>
Date:   Wed Aug 11 13:59:22 2010 -0700

glcpp: Add an explicit diagnostic for #if with no expression.

This is more clear than the previously-generated diagnostic which was
something confusing like "enexpected newline".

This change makse test 080-if-witout-expression.c now pass.

---

 src/glsl/glcpp/glcpp-parse.y                       |   10 ++++++++++
 .../tests/080-if-without-expression.c.expected     |    5 ++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 795030e..0e0d9d4 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -241,6 +241,16 @@ control_line:
 			parser->skip_stack->type = SKIP_TO_ENDIF;
 		}
 	}
+|	HASH_IF NEWLINE {
+		/* #if without an expression is only an error if we
+		 *  are not skipping */
+		if (parser->skip_stack == NULL ||
+		    parser->skip_stack->type == SKIP_NO_SKIP)
+		{
+			glcpp_error(& @1, parser, "#if with no expression");
+		}	
+		_glcpp_parser_skip_stack_push_if (parser, & @1, 0);
+	}
 |	HASH_IFDEF IDENTIFIER junk NEWLINE {
 		macro_t *macro = hash_table_find (parser->defines, $2);
 		talloc_free ($2);
diff --git a/src/glsl/glcpp/tests/080-if-without-expression.c.expected b/src/glsl/glcpp/tests/080-if-without-expression.c.expected
index 1a3e383..768ba0f 100644
--- a/src/glsl/glcpp/tests/080-if-without-expression.c.expected
+++ b/src/glsl/glcpp/tests/080-if-without-expression.c.expected
@@ -1,3 +1,6 @@
 0:2(1): preprocessor error: #if with no expression
-
  
+
+
+
+



More information about the mesa-commit mailing list