[gtk+/wip/otte/shader: 200/200] gsksl: Constant variables must be initialized



commit 2ef2ed4a36398b0a35adaf2765442fc4322376c8
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 17 01:02:44 2017 +0200

    gsksl: Constant variables must be initialized
    
    If they aren't, throw a fit and just initialize them with 0.

 gsk/gsksldeclaration.c |    7 +++++++
 gsk/gskslstatement.c   |   14 ++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/gsk/gsksldeclaration.c b/gsk/gsksldeclaration.c
index 48e2665..6894864 100644
--- a/gsk/gsksldeclaration.c
+++ b/gsk/gsksldeclaration.c
@@ -262,6 +262,13 @@ gsk_sl_declaration_parse_variable (GskSlScope           *scope,
     }
   gsk_sl_preprocessor_consume (preproc, NULL);
 
+  if (qualifier->storage == GSK_SL_STORAGE_GLOBAL_CONST &&
+      initial_value == NULL)
+    {
+      gsk_sl_preprocessor_error (preproc, DECLARATION, "Variables with \"const\" qualifier must be 
initialized with a constant value.");
+      initial_value = gsk_sl_value_new (type);
+    }
+
   variable = gsk_sl_declaration_new (&GSK_SL_DECLARATION_VARIABLE);
   variable->variable = gsk_sl_variable_new (name, type, qualifier, initial_value);
   variable->initial = initial;
diff --git a/gsk/gskslstatement.c b/gsk/gskslstatement.c
index 00bc601..aa9fda4 100644
--- a/gsk/gskslstatement.c
+++ b/gsk/gskslstatement.c
@@ -506,7 +506,7 @@ gsk_sl_statement_parse_declaration (GskSlScope           *scope,
                                     GskSlType            *type)
 {
   GskSlStatementDeclaration *declaration;
-  GskSlValue *value = NULL;
+  GskSlValue *initial_value = NULL;
   const GskSlToken *token;
   char *name;
 
@@ -539,7 +539,7 @@ gsk_sl_statement_parse_declaration (GskSlScope           *scope,
               unconverted = gsk_sl_expression_get_constant (declaration->initial);
               if (unconverted)
                 {
-                  value = gsk_sl_value_new_convert (unconverted, type);
+                  initial_value = gsk_sl_value_new_convert (unconverted, type);
                   gsk_sl_value_free (unconverted);
                 }
             }
@@ -548,10 +548,16 @@ gsk_sl_statement_parse_declaration (GskSlScope           *scope,
   else
     {
       name = NULL;
-      value = NULL;
     }
 
-  declaration->variable = gsk_sl_variable_new (name, type, qualifier, value);
+  if (qualifier->storage == GSK_SL_STORAGE_LOCAL_CONST &&
+      initial_value == NULL)
+    {
+      gsk_sl_preprocessor_error (stream, DECLARATION, "Variables with \"const\" qualifier must be 
initialized with a value.");
+      initial_value = gsk_sl_value_new (type);
+    }
+
+  declaration->variable = gsk_sl_variable_new (name, type, qualifier, initial_value);
   g_free (name);
   gsk_sl_scope_add_variable (scope, declaration->variable);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]