[gtk+/wip/otte/shader: 131/269] gsksl: Parse common layout() specifiers



commit 8f292ea35b392b9e0af0d4e79023f89a1885df94
Author: Benjamin Otte <otte redhat com>
Date:   Tue Sep 26 00:40:37 2017 +0200

    gsksl: Parse common layout() specifiers
    
    In particular: binding, set, location and component.

 gsk/gskslpointertype.c        |  131 +++++++++++++++++++++++++++++++++++++++++
 gsk/gskslpointertypeprivate.h |    4 +
 2 files changed, 135 insertions(+), 0 deletions(-)
---
diff --git a/gsk/gskslpointertype.c b/gsk/gskslpointertype.c
index 841ccd8..af024b9 100644
--- a/gsk/gskslpointertype.c
+++ b/gsk/gskslpointertype.c
@@ -77,6 +77,115 @@ gsk_sl_decoration_list_add_simple (GskSlPreprocessor *preproc,
   return gsk_sl_decoration_list_set (preproc, list, decoration, 1);
 }
 
+static gboolean
+gsk_sl_decoration_list_parse_assignment (GskSlPreprocessor *preproc,
+                                         GskSlDecorations  *list,
+                                         GskSlDecoration    decoration)
+{
+  const GskSlToken *token;
+  gboolean success = TRUE;
+
+  gsk_sl_preprocessor_consume (preproc, NULL);
+  
+  token = gsk_sl_preprocessor_get (preproc);
+  if (!gsk_sl_token_is (token, GSK_SL_TOKEN_EQUAL))
+    {
+      gsk_sl_preprocessor_error (preproc, "Expected \"=\" sign to assign a value.");
+      return FALSE;
+    }
+  gsk_sl_preprocessor_consume (preproc, NULL);
+
+  /* XXX: This should be a constant expression */
+  token = gsk_sl_preprocessor_get (preproc);
+  if (gsk_sl_token_is (token, GSK_SL_TOKEN_INTCONSTANT))
+    {
+      success = gsk_sl_decoration_list_set (preproc, list, decoration, token->i32);
+      gsk_sl_preprocessor_consume (preproc, NULL);
+    }
+  else if (gsk_sl_token_is (token, GSK_SL_TOKEN_UINTCONSTANT))
+    {
+      success = gsk_sl_decoration_list_set (preproc, list, decoration, token->u32);
+      gsk_sl_preprocessor_consume (preproc, NULL);
+    }
+  else
+    {
+      gsk_sl_preprocessor_error (preproc, "Assignment is not an integer.");
+      return FALSE;
+    }
+
+  return success;
+}
+
+static gboolean
+gsk_sl_decoration_list_parse_layout (GskSlPreprocessor *preproc,
+                                     GskSlDecorations  *list)
+{
+  const GskSlToken *token;
+  gboolean success = TRUE;
+
+  memset (list, 0, sizeof (GskSlDecorations));
+
+  while (TRUE)
+    {
+      token = gsk_sl_preprocessor_get (preproc);
+
+      if (gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
+        {
+          gsk_sl_preprocessor_error (preproc, "Expected layout identifier.");
+          success = FALSE;
+          break;
+        }
+      else if (gsk_sl_token_is (token, GSK_SL_TOKEN_IDENTIFIER))
+        {
+          if (g_str_equal (token->str, "location"))
+            {
+              success &= gsk_sl_decoration_list_parse_assignment (preproc,
+                                                                  list, 
+                                                                  GSK_SL_DECORATION_LAYOUT_LOCATION);
+            }
+          else if (g_str_equal (token->str, "component"))
+            {
+              success &= gsk_sl_decoration_list_parse_assignment (preproc,
+                                                                  list, 
+                                                                  GSK_SL_DECORATION_LAYOUT_COMPONENT);
+            }
+          else if (g_str_equal (token->str, "binding"))
+            {
+              success &= gsk_sl_decoration_list_parse_assignment (preproc,
+                                                                  list, 
+                                                                  GSK_SL_DECORATION_LAYOUT_BINDING);
+            }
+          else if (g_str_equal (token->str, "set"))
+            {
+              success &= gsk_sl_decoration_list_parse_assignment (preproc,
+                                                                  list, 
+                                                                  GSK_SL_DECORATION_LAYOUT_SET);
+            }
+          else
+            {
+              gsk_sl_preprocessor_error (preproc, "Unknown layout identifier.");
+              gsk_sl_preprocessor_consume (preproc, NULL);
+              success = FALSE;
+            }
+        }
+      else
+        {
+          gsk_sl_preprocessor_error (preproc, "Expected layout identifier.");
+          gsk_sl_preprocessor_consume (preproc, NULL);
+          success = FALSE;
+          continue;
+        }
+
+      token = gsk_sl_preprocessor_get (preproc);
+      if (!gsk_sl_token_is (token, GSK_SL_TOKEN_COMMA))
+        break;
+
+      gsk_sl_preprocessor_consume (preproc, NULL);
+    }
+
+  return success;
+}
+
 gboolean
 gsk_sl_decoration_list_parse (GskSlPreprocessor *preproc,
                               GskSlDecorations  *list)
@@ -207,6 +316,28 @@ gsk_sl_decoration_list_parse (GskSlPreprocessor *preproc,
           gsk_sl_preprocessor_consume (preproc, NULL);
           break;
 
+        case GSK_SL_TOKEN_LAYOUT:
+          gsk_sl_preprocessor_consume (preproc, NULL);
+          token = gsk_sl_preprocessor_get (preproc);
+          if (!gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_PAREN))
+            {
+              gsk_sl_preprocessor_error (preproc, "Expected opening \"(\" after layout specifier");
+              success = FALSE;
+              break;
+            }
+          gsk_sl_preprocessor_consume (preproc, NULL);
+
+          success &= gsk_sl_decoration_list_parse_layout (preproc, list);
+
+          token = gsk_sl_preprocessor_get (preproc);
+          if (!gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
+            {
+              gsk_sl_preprocessor_error (preproc, "Expected opening \"(\" after layout specifier");
+              success = FALSE;
+            }
+          gsk_sl_preprocessor_consume (preproc, NULL);
+          break;
+
         default:
           return success;
       }
diff --git a/gsk/gskslpointertypeprivate.h b/gsk/gskslpointertypeprivate.h
index a008111..08e59d8 100644
--- a/gsk/gskslpointertypeprivate.h
+++ b/gsk/gskslpointertypeprivate.h
@@ -34,6 +34,10 @@ typedef enum {
   GSK_SL_DECORATION_VOLATILE,
   GSK_SL_DECORATION_RESTRICT,
   GSK_SL_DECORATION_ACCESS,
+  GSK_SL_DECORATION_LAYOUT_LOCATION,
+  GSK_SL_DECORATION_LAYOUT_COMPONENT,
+  GSK_SL_DECORATION_LAYOUT_SET,
+  GSK_SL_DECORATION_LAYOUT_BINDING,
   /* add */
   GSK_SL_N_DECORATIONS
 } GskSlDecoration;


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