[gtk+/wip/otte/shader: 93/98] gsksl: Parse array declarations



commit 47fab0cc16a5359ecf3a4a1be0a437677431a3be
Author: Benjamin Otte <otte redhat com>
Date:   Sun Oct 22 16:13:18 2017 +0200

    gsksl: Parse array declarations

 gsk/gskslcompiler.h    |    1 +
 gsk/gsksldeclaration.c |    8 +++++++-
 gsk/gskslfunction.c    |   11 +++++++++--
 gsk/gskslstatement.c   |    7 ++++++-
 gsk/gsksltype.c        |    3 +++
 5 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/gsk/gskslcompiler.h b/gsk/gskslcompiler.h
index 532f94d..8a549ab 100644
--- a/gsk/gskslcompiler.h
+++ b/gsk/gskslcompiler.h
@@ -41,6 +41,7 @@ typedef enum {
 } GskSlCompilerError;
 
 typedef enum {
+  GSK_SL_COMPILER_WARNING_ARRAY_OF_ARRAY,
   GSK_SL_COMPILER_WARNING_CONSTANT,
   GSK_SL_COMPILER_WARNING_DEAD_CODE,
   GSK_SL_COMPILER_WARNING_SHADOW,
diff --git a/gsk/gsksldeclaration.c b/gsk/gsksldeclaration.c
index ca2edea..e8ae53b 100644
--- a/gsk/gsksldeclaration.c
+++ b/gsk/gsksldeclaration.c
@@ -218,14 +218,18 @@ static GskSlDeclaration *
 gsk_sl_declaration_parse_variable (GskSlScope           *scope,
                                    GskSlPreprocessor    *preproc,
                                    const GskSlQualifier *qualifier,
-                                   GskSlType            *type,
+                                   GskSlType            *base_type,
                                    const char           *name)
 {
   GskSlDeclarationVariable *variable;
   GskSlValue *initial_value = NULL;
   GskSlExpression *initial = NULL;
+  GskSlType *type;
   const GskSlToken *token;
 
+  type = gsk_sl_type_ref (base_type);
+  type = gsk_sl_type_parse_array (type, scope, preproc);
+
   gsk_sl_qualifier_check_type (qualifier, preproc, type);
 
   token = gsk_sl_preprocessor_get (preproc);
@@ -276,6 +280,8 @@ gsk_sl_declaration_parse_variable (GskSlScope           *scope,
   variable->initial = initial;
   gsk_sl_scope_add_variable (scope, variable->variable);
 
+  gsk_sl_type_unref (type);
+
   return &variable->parent;
 }
 
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index c64b7af..a7c508b 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -603,6 +603,7 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
           token = gsk_sl_preprocessor_get (preproc);
           if (gsk_sl_token_is (token, GSK_SL_TOKEN_IDENTIFIER))
             {
+              char *name;
               guint i;
 
               if (gsk_sl_scope_lookup_variable (function->scope, token->str))
@@ -619,14 +620,20 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
                     gsk_sl_preprocessor_warn (preproc, SHADOW, "Function argument \"%s\" shadows global 
variable of same name.", token->str);
                 }
 
-              variable = gsk_sl_variable_new (token->str, type, &qualifier, NULL);
+              name = g_strdup (token->str);
+              gsk_sl_preprocessor_consume (preproc, (GskSlStatement *) function);
+
+              type = gsk_sl_type_parse_array (type, scope, preproc);
+
+              variable = gsk_sl_variable_new (name, type, &qualifier, NULL);
               function->function_type = gsk_sl_function_type_add_argument (function->function_type,
                                                                            qualifier.storage,
                                                                            type);
               g_ptr_array_add (arguments, variable);
               
               gsk_sl_scope_add_variable (function->scope, variable);
-              gsk_sl_preprocessor_consume (preproc, (GskSlStatement *) function);
+
+              g_free (name);
             }
           else
             {
diff --git a/gsk/gskslstatement.c b/gsk/gskslstatement.c
index 27e605f..a35e5ae 100644
--- a/gsk/gskslstatement.c
+++ b/gsk/gskslstatement.c
@@ -628,13 +628,15 @@ static GskSlStatement *
 gsk_sl_statement_parse_declaration (GskSlScope           *scope,
                                     GskSlPreprocessor    *stream,
                                     const GskSlQualifier *qualifier,
-                                    GskSlType            *type)
+                                    GskSlType            *base_type)
 {
   GskSlStatementDeclaration *declaration;
   GskSlValue *initial_value = NULL;
   const GskSlToken *token;
+  GskSlType *type;
   char *name;
 
+  type = gsk_sl_type_ref (base_type);
   declaration = gsk_sl_statement_new (GskSlStatementDeclaration, &GSK_SL_STATEMENT_DECLARATION);
   
   token = gsk_sl_preprocessor_get (stream);
@@ -643,6 +645,8 @@ gsk_sl_statement_parse_declaration (GskSlScope           *scope,
       name = g_strdup (token->str);
       gsk_sl_preprocessor_consume (stream, (GskSlStatement *) declaration);
 
+      type = gsk_sl_type_parse_array (type, scope, stream);
+
       token = gsk_sl_preprocessor_get (stream);
       if (gsk_sl_token_is (token, GSK_SL_TOKEN_EQUAL))
         {
@@ -685,6 +689,7 @@ gsk_sl_statement_parse_declaration (GskSlScope           *scope,
   declaration->variable = gsk_sl_variable_new (name, type, qualifier, initial_value);
   g_free (name);
   gsk_sl_scope_add_variable (scope, declaration->variable);
+  gsk_sl_type_unref (type);
 
   return (GskSlStatement *) declaration;
 }
diff --git a/gsk/gsksltype.c b/gsk/gsksltype.c
index ab42323..6efdcaf 100644
--- a/gsk/gsksltype.c
+++ b/gsk/gsksltype.c
@@ -2227,6 +2227,9 @@ gsk_sl_type_parse_array (GskSlType         *type,
 
   gsk_sl_preprocessor_consume (preproc, NULL);
 
+  if (gsk_sl_type_is_array (type))
+    gsk_sl_preprocessor_warn (preproc, ARRAY_OF_ARRAY, "Declaring array of %s which is already an array.", 
gsk_sl_type_get_name (type));
+
   length = gsk_sl_expression_parse_integral_constant (scope, preproc, 1, G_MAXINT);
 
   token = gsk_sl_preprocessor_get (preproc);


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