glsl: Change is_precision_statement to default_precision != none.
authorKenneth Graunke <kenneth@whitecape.org>
Mon, 15 Jul 2013 22:39:35 +0000 (15:39 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 18 Jul 2013 23:57:23 +0000 (16:57 -0700)
Currently, we store precision in ast_type_specifier, rather than
ast_type_qualifier.  This works because precision is the last qualifier,
and immediately adjacent to the type.

Default precision statements (such as "precision highp float") are
represented as ast_type_specifier objects, with a boolean to indicate
that it's a default precision statement rather than an ordinary type.

ast_type_specifier::precision will be moving to ast_type_qualifier soon,
in order to support arbitrary qualifier ordering.  However, we still
need to store a "this is a precision statement" flag /and/ the default
precision in ast_type_specifier.

This patch changes the boolean into a new field, default_precision.
If default_precision != ast_precision_none, it's a precision statement
with the specified precision.  Otherwise, it's an ordinary type.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/glsl/ast.h
src/glsl/ast_to_hir.cpp
src/glsl/glsl_parser.yy

index 816d5fccbbc1bbbe59655fdb7420da53e3a29cac..1208704ff6df9e9b0d87e731fafade13f32c3927 100644 (file)
@@ -534,7 +534,7 @@ public:
                       ast_expression *array_size)
       : ast_node(), type_name(that->type_name), structure(that->structure),
         is_array(is_array), array_size(array_size), precision(that->precision),
-        is_precision_statement(that->is_precision_statement)
+        default_precision(that->default_precision)
    {
       /* empty */
    }
@@ -543,7 +543,7 @@ public:
    ast_type_specifier(const char *name) 
       : type_name(name), structure(NULL),
        is_array(false), array_size(NULL), precision(ast_precision_none),
-       is_precision_statement(false)
+       default_precision(ast_precision_none)
    {
       /* empty */
    }
@@ -552,7 +552,7 @@ public:
    ast_type_specifier(ast_struct_specifier *s)
       : type_name(s->name), structure(s),
        is_array(false), array_size(NULL), precision(ast_precision_none),
-       is_precision_statement(false)
+       default_precision(ast_precision_none)
    {
       /* empty */
    }
@@ -573,7 +573,8 @@ public:
 
    unsigned precision:2;
 
-   bool is_precision_statement;
+   /** For precision statements, this is the given precision; otherwise none. */
+   unsigned default_precision:2;
 };
 
 
index 28ccf72887010a57c21c4fd09de604882470c9c6..c1a2af30aea291992109cc101a1f323ed3e2cf57 100644 (file)
@@ -3958,7 +3958,7 @@ ir_rvalue *
 ast_type_specifier::hir(exec_list *instructions,
                          struct _mesa_glsl_parse_state *state)
 {
-   if (!this->is_precision_statement && this->structure == NULL)
+   if (this->default_precision == ast_precision_none && this->structure == NULL)
       return NULL;
 
    YYLTYPE loc = this->get_location();
@@ -3984,7 +3984,7 @@ ast_type_specifier::hir(exec_list *instructions,
     *    field can be either int or float [...].  Any other types or
     *    qualifiers will result in an error.
     */
-   if (this->is_precision_statement) {
+   if (this->default_precision != ast_precision_none) {
       assert(this->precision != ast_precision_none);
       assert(this->structure == NULL); /* The check for structures was
                                         * performed above. */
index ff57c29741f2c1e43bee17093b5a93bfd2b5b19b..1a13f4855037a476b88c63d2b3ea91067b2349d8 100644 (file)
@@ -793,7 +793,7 @@ declaration:
    | PRECISION precision_qualifier type_specifier_no_prec ';'
    {
       $3->precision = $2;
-      $3->is_precision_statement = true;
+      $3->default_precision = $2;
       $$ = $3;
    }
    | interface_block