Compute the constant value of a constant initializer.
authorEric Anholt <eric@anholt.net>
Thu, 1 Apr 2010 01:53:26 +0000 (15:53 -1000)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 2 Apr 2010 18:05:16 +0000 (11:05 -0700)
Fixes constFunc.frag.

ast_to_hir.cpp

index 11000a8134623325bf75d0f406a3ca9ed845a70f..aa7e165ee769ee361282b0ce8a20c6265b5efe23 100644 (file)
@@ -1434,13 +1434,22 @@ ast_declarator_list::hir(exec_list *instructions,
         }
 
         ir_dereference *const lhs = new ir_dereference(var);
-        ir_rvalue *const rhs = decl->initializer->hir(instructions, state);
+        ir_rvalue *rhs = decl->initializer->hir(instructions, state);
 
-        /* FINISHME: If the declaration is either 'const' or 'uniform', the
-         * FINISHME: initializer (rhs) must be a constant expression.
+        /* Calculate the constant value if this is a const
+         * declaration.
          */
+        if (this->type->qualifier.constant) {
+           rhs = rhs->constant_expression_value();
+           if (!rhs) {
+              _mesa_glsl_error(& initializer_loc, state,
+                               "initializer of const variable `%s' must be a "
+                               "constant expression",
+                               decl->identifier);
+           }
+        }
 
-        if (!rhs->type->is_error()) {
+        if (rhs && !rhs->type->is_error()) {
            bool temp = var->read_only;
            if (this->type->qualifier.constant)
               var->read_only = false;