[gtk+/wip/otte/shader: 16/55] gskslnode: Always return a statement
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 16/55] gskslnode: Always return a statement
- Date: Tue, 3 Oct 2017 03:40:19 +0000 (UTC)
commit c13361d3881d540902a3da579874fee8ea4ac49c
Author: Benjamin Otte <otte redhat com>
Date: Wed Sep 27 17:50:18 2017 +0200
gskslnode: Always return a statement
Same thing as with expresssions: On parsing errors, return something,
anything really.
gsk/gskslfunction.c | 24 ++------
gsk/gskslnode.c | 98 ++++++++----------------------
gsk/gskslpointertype.c | 132 +++++++++++++++++------------------------
gsk/gskslpointertypeprivate.h | 2 +-
gsk/gskslprogram.c | 72 +++++++++--------------
5 files changed, 113 insertions(+), 215 deletions(-)
---
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index e132e3f..4f1ead1 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -314,7 +314,6 @@ gsk_sl_function_new_parse (GskSlScope *scope,
{
GskSlFunctionDeclared *function;
const GskSlToken *token;
- gboolean success = TRUE;
function = gsk_sl_function_new (GskSlFunctionDeclared, &GSK_SL_FUNCTION_DECLARED);
function->return_type = gsk_sl_type_ref (return_type);
@@ -324,8 +323,7 @@ gsk_sl_function_new_parse (GskSlScope *scope,
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_PAREN))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected an openening \"(\"");
- gsk_sl_function_unref ((GskSlFunction *) function);
- return NULL;
+ return (GskSlFunction *) function;
}
gsk_sl_preprocessor_consume (preproc, (GskSlNode *) function);
@@ -333,8 +331,7 @@ gsk_sl_function_new_parse (GskSlScope *scope,
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected a closing \")\"");
- gsk_sl_function_unref ((GskSlFunction *) function);
- return NULL;
+ return (GskSlFunction *) function;
}
gsk_sl_preprocessor_consume (preproc, (GskSlNode *) function);
@@ -348,8 +345,7 @@ gsk_sl_function_new_parse (GskSlScope *scope,
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_BRACE))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected an opening \"{\"");
- gsk_sl_function_unref ((GskSlFunction *) function);
- return NULL;
+ return (GskSlFunction *) function;
}
gsk_sl_preprocessor_consume (preproc, (GskSlNode *) function);
@@ -362,26 +358,16 @@ gsk_sl_function_new_parse (GskSlScope *scope,
GskSlNode *statement;
statement = gsk_sl_node_parse_statement (function->scope, preproc);
- if (statement)
- function->statements = g_slist_append (function->statements, statement);
- else
- success = FALSE;
+ function->statements = g_slist_append (function->statements, statement);
}
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_BRACE))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Missing closing \"}\" at end.");
- gsk_sl_function_unref ((GskSlFunction *) function);
- return NULL;
+ return (GskSlFunction *) function;
}
gsk_sl_preprocessor_consume (preproc, (GskSlNode *) function);
- if (!success)
- {
- gsk_sl_function_unref ((GskSlFunction *) function);
- return NULL;
- }
-
return (GskSlFunction *) function;
}
diff --git a/gsk/gskslnode.c b/gsk/gskslnode.c
index 7b3f961..8e57e60 100644
--- a/gsk/gskslnode.c
+++ b/gsk/gskslnode.c
@@ -279,15 +279,17 @@ gsk_sl_node_parse_declaration (GskSlScope *scope,
"Cannot convert from initializer type %s to variable type %s",
gsk_sl_type_get_name (gsk_sl_expression_get_return_type
(declaration->initial)),
gsk_sl_type_get_name (type));
- gsk_sl_node_unref ((GskSlNode *) declaration);
- return NULL;
+ gsk_sl_expression_unref (declaration->initial);
+ declaration->initial = NULL;
}
-
- unconverted = gsk_sl_expression_get_constant (declaration->initial);
- if (unconverted)
+ else
{
- value = gsk_sl_value_new_convert (unconverted, type);
- gsk_sl_value_free (unconverted);
+ unconverted = gsk_sl_expression_get_constant (declaration->initial);
+ if (unconverted)
+ {
+ value = gsk_sl_value_new_convert (unconverted, type);
+ gsk_sl_value_free (unconverted);
+ }
}
}
}
@@ -322,7 +324,7 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
case GSK_SL_TOKEN_EOF:
gsk_sl_preprocessor_error (preproc, SYNTAX, "Unexpected end of document");
- return NULL;
+ return (GskSlNode *) gsk_sl_node_new (GskSlNodeEmpty, &GSK_SL_NODE_EMPTY);
case GSK_SL_TOKEN_CONST:
case GSK_SL_TOKEN_IN:
@@ -382,34 +384,22 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
{
GskSlType *type;
GskSlDecorations decoration;
- gboolean success;
- success = gsk_sl_decoration_list_parse (scope,
- preproc,
- &decoration);
+ gsk_sl_decoration_list_parse (scope,
+ preproc,
+ &decoration);
type = gsk_sl_type_new_parse (preproc);
- if (type == NULL)
- break;
token = gsk_sl_preprocessor_get (preproc);
if (token->type == GSK_SL_TOKEN_LEFT_PAREN)
{
- GskSlExpression *expression = gsk_sl_expression_parse_constructor_call (scope, preproc, type);
-
- if (expression)
- {
- GskSlNodeExpression *node_expression;
+ GskSlNodeExpression *node_expression;
- node_expression = gsk_sl_node_new (GskSlNodeExpression, &GSK_SL_NODE_EXPRESSION);
- node_expression->expression = expression;
- node = (GskSlNode *) node_expression;
- }
- else
- {
- node = NULL;
- }
+ node_expression = gsk_sl_node_new (GskSlNodeExpression, &GSK_SL_NODE_EXPRESSION);
+ node_expression->expression = gsk_sl_expression_parse_constructor_call (scope, preproc, type);
+ node = (GskSlNode *) node_expression;
}
else
{
@@ -417,12 +407,6 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
}
gsk_sl_type_unref (type);
-
- if (!success)
- {
- gsk_sl_node_unref (node);
- node = NULL;
- }
}
break;
@@ -435,16 +419,7 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
gsk_sl_preprocessor_consume (preproc, (GskSlNode *) return_node);
token = gsk_sl_preprocessor_get (preproc);
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_SEMICOLON))
- {
- return_node->value = gsk_sl_expression_parse (scope, preproc);
-
- if (return_node->value == NULL)
- {
- gsk_sl_node_unref ((GskSlNode *) return_node);
- node = NULL;
- break;
- }
- }
+ return_node->value = gsk_sl_expression_parse (scope, preproc);
return_type = gsk_sl_scope_get_return_type (scope);
node = (GskSlNode *) return_node;
@@ -452,16 +427,12 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
if (return_type == NULL)
{
gsk_sl_preprocessor_error (preproc, SCOPE, "Cannot return from here.");
- gsk_sl_node_unref (node);
- node = NULL;
}
else if (return_node->value == NULL)
{
if (!gsk_sl_type_equal (return_type, gsk_sl_type_get_scalar (GSK_SL_VOID)))
{
gsk_sl_preprocessor_error (preproc, TYPE_MISMATCH,"Functions expectes a return value of type
%s", gsk_sl_type_get_name (return_type));
- gsk_sl_node_unref (node);
- node = NULL;
}
}
else
@@ -469,8 +440,6 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
if (gsk_sl_type_equal (return_type, gsk_sl_type_get_scalar (GSK_SL_VOID)))
{
gsk_sl_preprocessor_error (preproc, TYPE_MISMATCH, "Cannot return a value from a void
function.");
- gsk_sl_node_unref (node);
- node = NULL;
}
else if (!gsk_sl_type_can_convert (return_type, gsk_sl_expression_get_return_type
(return_node->value)))
{
@@ -478,8 +447,6 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
"Cannot convert type %s to return type %s.",
gsk_sl_type_get_name (gsk_sl_expression_get_return_type
(return_node->value)),
gsk_sl_type_get_name (return_type));
- gsk_sl_node_unref (node);
- node = NULL;
break;
}
}
@@ -488,36 +455,21 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
default:
{
- GskSlExpression * expression = gsk_sl_expression_parse (scope, preproc);
-
- if (expression)
- {
- GskSlNodeExpression *node_expression;
+ GskSlNodeExpression *node_expression;
- node_expression = gsk_sl_node_new (GskSlNodeExpression, &GSK_SL_NODE_EXPRESSION);
- node_expression->expression = expression;
+ node_expression = gsk_sl_node_new (GskSlNodeExpression, &GSK_SL_NODE_EXPRESSION);
+ node_expression->expression = gsk_sl_expression_parse (scope, preproc);
- node = (GskSlNode *) node_expression;
- }
- else
- {
- return NULL;
- }
+ node = (GskSlNode *) node_expression;
}
break;
}
- if (node == NULL)
- return NULL;
-
token = gsk_sl_preprocessor_get (preproc);
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_SEMICOLON))
- {
- gsk_sl_preprocessor_error (preproc, SYNTAX, "No semicolon at end of statement.");
- gsk_sl_node_unref (node);
- return NULL;
- }
- gsk_sl_preprocessor_consume (preproc, (GskSlNode *) node);
+ gsk_sl_preprocessor_error (preproc, SYNTAX, "No semicolon at end of statement.");
+ else
+ gsk_sl_preprocessor_consume (preproc, (GskSlNode *) node);
return node;
}
diff --git a/gsk/gskslpointertype.c b/gsk/gskslpointertype.c
index 0fb6964..c3f38b5 100644
--- a/gsk/gskslpointertype.c
+++ b/gsk/gskslpointertype.c
@@ -53,7 +53,7 @@ gsk_sl_pointer_type_new (GskSlType *type,
return result;
}
-static gboolean
+static void
gsk_sl_decoration_list_set (GskSlPreprocessor *preproc,
GskSlDecorations *list,
GskSlDecoration decoration,
@@ -61,11 +61,9 @@ gsk_sl_decoration_list_set (GskSlPreprocessor *preproc,
{
list->values[decoration].set = TRUE;
list->values[decoration].value = value;
-
- return TRUE;
}
-static gboolean
+static void
gsk_sl_decoration_list_add_simple (GskSlPreprocessor *preproc,
GskSlDecorations *list,
GskSlDecoration decoration)
@@ -73,13 +71,13 @@ gsk_sl_decoration_list_add_simple (GskSlPreprocessor *preproc,
if (list->values[decoration].set)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Duplicate qualifier.");
- return FALSE;
+ return;
}
- return gsk_sl_decoration_list_set (preproc, list, decoration, 1);
+ gsk_sl_decoration_list_set (preproc, list, decoration, 1);
}
-static gboolean
+static void
gsk_sl_decoration_list_parse_assignment (GskSlPreprocessor *preproc,
GskSlScope *scope,
GskSlDecorations *list,
@@ -89,7 +87,6 @@ gsk_sl_decoration_list_parse_assignment (GskSlPreprocessor *preproc,
const GskSlToken *token;
GskSlValue *value;
GskSlType *type;
- gboolean success = TRUE;
gsk_sl_preprocessor_consume (preproc, NULL);
@@ -97,13 +94,13 @@ gsk_sl_decoration_list_parse_assignment (GskSlPreprocessor *preproc,
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_EQUAL))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected \"=\" sign to assign a value.");
- return FALSE;
+ return;
}
gsk_sl_preprocessor_consume (preproc, NULL);
expression = gsk_sl_expression_parse_constant (scope, preproc);
if (expression == NULL)
- return FALSE;
+ return;
value = gsk_sl_expression_get_constant (expression);
gsk_sl_expression_unref (expression);
@@ -111,35 +108,31 @@ gsk_sl_decoration_list_parse_assignment (GskSlPreprocessor *preproc,
if (value == NULL)
{
gsk_sl_preprocessor_error (preproc, CONSTANT, "Expression is not constant.");
- return FALSE;
+ return;
}
type = gsk_sl_value_get_type (value);
if (gsk_sl_type_is_scalar (type) && gsk_sl_type_get_scalar_type (type) == GSK_SL_INT)
{
- success = gsk_sl_decoration_list_set (preproc, list, decoration, *(gint32 *) gsk_sl_value_get_data
(value));
+ gsk_sl_decoration_list_set (preproc, list, decoration, *(gint32 *) gsk_sl_value_get_data (value));
}
else if (gsk_sl_type_is_scalar (type) && gsk_sl_type_get_scalar_type (type) == GSK_SL_UINT)
{
- success = gsk_sl_decoration_list_set (preproc, list, decoration, *(guint32 *) gsk_sl_value_get_data
(value));
+ gsk_sl_decoration_list_set (preproc, list, decoration, *(guint32 *) gsk_sl_value_get_data (value));
}
else
{
gsk_sl_preprocessor_error (preproc, TYPE_MISMATCH, "Type of expression is not an integer type, but
%s", gsk_sl_type_get_name (type));
- success = FALSE;
}
gsk_sl_value_free (value);
-
- return success;
}
-static gboolean
+static void
gsk_sl_decoration_list_parse_layout (GskSlPreprocessor *preproc,
GskSlScope *scope,
GskSlDecorations *list)
{
const GskSlToken *token;
- gboolean success = TRUE;
memset (list, 0, sizeof (GskSlDecorations));
@@ -150,51 +143,48 @@ gsk_sl_decoration_list_parse_layout (GskSlPreprocessor *preproc,
if (gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "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,
- scope,
- list,
- GSK_SL_DECORATION_LAYOUT_LOCATION);
+ gsk_sl_decoration_list_parse_assignment (preproc,
+ scope,
+ list,
+ GSK_SL_DECORATION_LAYOUT_LOCATION);
}
else if (g_str_equal (token->str, "component"))
{
- success &= gsk_sl_decoration_list_parse_assignment (preproc,
- scope,
- list,
- GSK_SL_DECORATION_LAYOUT_COMPONENT);
+ gsk_sl_decoration_list_parse_assignment (preproc,
+ scope,
+ list,
+ GSK_SL_DECORATION_LAYOUT_COMPONENT);
}
else if (g_str_equal (token->str, "binding"))
{
- success &= gsk_sl_decoration_list_parse_assignment (preproc,
- scope,
- list,
- GSK_SL_DECORATION_LAYOUT_BINDING);
+ gsk_sl_decoration_list_parse_assignment (preproc,
+ scope,
+ list,
+ GSK_SL_DECORATION_LAYOUT_BINDING);
}
else if (g_str_equal (token->str, "set"))
{
- success &= gsk_sl_decoration_list_parse_assignment (preproc,
- scope,
- list,
- GSK_SL_DECORATION_LAYOUT_SET);
+ gsk_sl_decoration_list_parse_assignment (preproc,
+ scope,
+ list,
+ GSK_SL_DECORATION_LAYOUT_SET);
}
else
{
gsk_sl_preprocessor_error (preproc, UNSUPPORTED, "Unknown layout identifier.");
gsk_sl_preprocessor_consume (preproc, NULL);
- success = FALSE;
}
}
else
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected layout identifier.");
gsk_sl_preprocessor_consume (preproc, NULL);
- success = FALSE;
continue;
}
@@ -204,17 +194,14 @@ gsk_sl_decoration_list_parse_layout (GskSlPreprocessor *preproc,
gsk_sl_preprocessor_consume (preproc, NULL);
}
-
- return success;
}
-gboolean
+void
gsk_sl_decoration_list_parse (GskSlScope *scope,
GskSlPreprocessor *preproc,
GskSlDecorations *list)
{
const GskSlToken *token;
- gboolean success = TRUE;
memset (list, 0, sizeof (GskSlDecorations));
@@ -224,7 +211,7 @@ gsk_sl_decoration_list_parse (GskSlScope *scope,
switch (token->type)
{
case GSK_SL_TOKEN_CONST:
- success &= gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_CONST);
+ gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_CONST);
gsk_sl_preprocessor_consume (preproc, NULL);
break;
@@ -232,13 +219,12 @@ gsk_sl_decoration_list_parse (GskSlScope *scope,
if (list->values[GSK_SL_DECORATION_CALLER_ACCESS].value & GSK_SL_DECORATION_ACCESS_READ)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "\"in\" qualifier specified twice.");
- success = FALSE;
}
else
{
- success &= gsk_sl_decoration_list_set (preproc, list,
- GSK_SL_DECORATION_CALLER_ACCESS,
- list->values[GSK_SL_DECORATION_CALLER_ACCESS].value |
GSK_SL_DECORATION_ACCESS_READ);
+ gsk_sl_decoration_list_set (preproc, list,
+ GSK_SL_DECORATION_CALLER_ACCESS,
+ list->values[GSK_SL_DECORATION_CALLER_ACCESS].value |
GSK_SL_DECORATION_ACCESS_READ);
}
gsk_sl_preprocessor_consume (preproc, NULL);
break;
@@ -247,13 +233,12 @@ gsk_sl_decoration_list_parse (GskSlScope *scope,
if (list->values[GSK_SL_DECORATION_CALLER_ACCESS].value & GSK_SL_DECORATION_ACCESS_WRITE)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "\"out\" qualifier specified twice.");
- success = FALSE;
}
else
{
- success &= gsk_sl_decoration_list_set (preproc, list,
- GSK_SL_DECORATION_CALLER_ACCESS,
- list->values[GSK_SL_DECORATION_CALLER_ACCESS].value |
GSK_SL_DECORATION_ACCESS_WRITE);
+ gsk_sl_decoration_list_set (preproc, list,
+ GSK_SL_DECORATION_CALLER_ACCESS,
+ list->values[GSK_SL_DECORATION_CALLER_ACCESS].value |
GSK_SL_DECORATION_ACCESS_WRITE);
}
gsk_sl_preprocessor_consume (preproc, NULL);
break;
@@ -262,39 +247,37 @@ gsk_sl_decoration_list_parse (GskSlScope *scope,
if (list->values[GSK_SL_DECORATION_CALLER_ACCESS].value & GSK_SL_DECORATION_ACCESS_READ)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "\"in\" qualifier already used.");
- success = FALSE;
}
else if (list->values[GSK_SL_DECORATION_CALLER_ACCESS].value & GSK_SL_DECORATION_ACCESS_WRITE)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "\"out\" qualifier already used.");
- success = FALSE;
}
else
{
- success &= gsk_sl_decoration_list_set (preproc, list,
- GSK_SL_DECORATION_CALLER_ACCESS,
- GSK_SL_DECORATION_ACCESS_READWRITE);
+ gsk_sl_decoration_list_set (preproc, list,
+ GSK_SL_DECORATION_CALLER_ACCESS,
+ GSK_SL_DECORATION_ACCESS_READWRITE);
}
gsk_sl_preprocessor_consume (preproc, NULL);
break;
case GSK_SL_TOKEN_INVARIANT:
- success &= gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_INVARIANT);
+ gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_INVARIANT);
gsk_sl_preprocessor_consume (preproc, NULL);
break;
case GSK_SL_TOKEN_COHERENT:
- success &= gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_COHERENT);
+ gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_COHERENT);
gsk_sl_preprocessor_consume (preproc, NULL);
break;
case GSK_SL_TOKEN_VOLATILE:
- success &= gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_VOLATILE);
+ gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_VOLATILE);
gsk_sl_preprocessor_consume (preproc, NULL);
break;
case GSK_SL_TOKEN_RESTRICT:
- success &= gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_RESTRICT);
+ gsk_sl_decoration_list_add_simple (preproc, list, GSK_SL_DECORATION_RESTRICT);
gsk_sl_preprocessor_consume (preproc, NULL);
break;
@@ -303,18 +286,16 @@ gsk_sl_decoration_list_parse (GskSlScope *scope,
if (list->values[GSK_SL_DECORATION_ACCESS].value & GSK_SL_DECORATION_ACCESS_READ)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "\"readonly\" qualifier specified twice.");
- success = FALSE;
}
else if (list->values[GSK_SL_DECORATION_ACCESS].value & GSK_SL_DECORATION_ACCESS_WRITE)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "\"writeonly\" qualifier already used.");
- success = FALSE;
}
else
{
- success &= gsk_sl_decoration_list_set (preproc, list,
- GSK_SL_DECORATION_ACCESS,
- GSK_SL_DECORATION_ACCESS_READ);
+ gsk_sl_decoration_list_set (preproc, list,
+ GSK_SL_DECORATION_ACCESS,
+ GSK_SL_DECORATION_ACCESS_READ);
}
gsk_sl_preprocessor_consume (preproc, NULL);
break;
@@ -323,18 +304,16 @@ gsk_sl_decoration_list_parse (GskSlScope *scope,
if (list->values[GSK_SL_DECORATION_ACCESS].value & GSK_SL_DECORATION_ACCESS_READ)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "\"readonly\" qualifier already used.");
- success = FALSE;
}
else if (list->values[GSK_SL_DECORATION_ACCESS].value & GSK_SL_DECORATION_ACCESS_WRITE)
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "\"writeonly\" qualifier specified twice.");
- success = FALSE;
}
else
{
- success &= gsk_sl_decoration_list_set (preproc, list,
- GSK_SL_DECORATION_ACCESS,
- GSK_SL_DECORATION_ACCESS_WRITE);
+ gsk_sl_decoration_list_set (preproc, list,
+ GSK_SL_DECORATION_ACCESS,
+ GSK_SL_DECORATION_ACCESS_WRITE);
}
gsk_sl_preprocessor_consume (preproc, NULL);
break;
@@ -345,24 +324,21 @@ gsk_sl_decoration_list_parse (GskSlScope *scope,
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_PAREN))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected opening \"(\" after layout specifier");
- success = FALSE;
break;
}
gsk_sl_preprocessor_consume (preproc, NULL);
- success &= gsk_sl_decoration_list_parse_layout (preproc, scope, list);
+ gsk_sl_decoration_list_parse_layout (preproc, scope, list);
token = gsk_sl_preprocessor_get (preproc);
- if (!gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
- {
- gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected opening \"(\" after layout specifier");
- success = FALSE;
- }
- gsk_sl_preprocessor_consume (preproc, NULL);
+ if (gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
+ gsk_sl_preprocessor_consume (preproc, NULL);
+ else
+ gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected closing \")\" at end of layout specifier");
break;
default:
- return success;
+ return;
}
}
}
diff --git a/gsk/gskslpointertypeprivate.h b/gsk/gskslpointertypeprivate.h
index 2624472..9e92dfd 100644
--- a/gsk/gskslpointertypeprivate.h
+++ b/gsk/gskslpointertypeprivate.h
@@ -58,7 +58,7 @@ struct _GskSlDecorations
} values[GSK_SL_N_DECORATIONS];
};
-gboolean gsk_sl_decoration_list_parse (GskSlScope *scope,
+void gsk_sl_decoration_list_parse (GskSlScope *scope,
GskSlPreprocessor *stream,
GskSlDecorations *list);
diff --git a/gsk/gskslprogram.c b/gsk/gskslprogram.c
index 8d083a5..04969a4 100644
--- a/gsk/gskslprogram.c
+++ b/gsk/gskslprogram.c
@@ -68,7 +68,7 @@ gsk_sl_program_init (GskSlProgram *program)
program->scope = gsk_sl_scope_new (NULL, NULL);
}
-static gboolean
+static void
gsk_sl_program_parse_variable (GskSlProgram *program,
GskSlScope *scope,
GskSlPreprocessor *preproc,
@@ -90,8 +90,6 @@ gsk_sl_program_parse_variable (GskSlProgram *program,
gsk_sl_preprocessor_consume (preproc, program);
initial = gsk_sl_expression_parse_assignment (scope, preproc);
- if (initial == NULL)
- return NULL;
if (!gsk_sl_type_can_convert (type, gsk_sl_expression_get_return_type (initial)))
{
@@ -100,31 +98,30 @@ gsk_sl_program_parse_variable (GskSlProgram *program,
gsk_sl_type_get_name (gsk_sl_expression_get_return_type (initial)),
gsk_sl_type_get_name (type));
gsk_sl_expression_unref (initial);
- return NULL;
}
-
- unconverted = gsk_sl_expression_get_constant (initial);
- gsk_sl_expression_unref (initial);
- if (unconverted)
- {
- value = gsk_sl_value_new_convert (unconverted, type);
- gsk_sl_value_free (unconverted);
- }
- else
+ else
{
- gsk_sl_preprocessor_error (preproc, UNSUPPORTED, "Non-constant initializer are not supported
yet.");
- return FALSE;
+ unconverted = gsk_sl_expression_get_constant (initial);
+ gsk_sl_expression_unref (initial);
+ if (unconverted)
+ {
+ value = gsk_sl_value_new_convert (unconverted, type);
+ gsk_sl_value_free (unconverted);
+ }
+ else
+ {
+ gsk_sl_preprocessor_error (preproc, UNSUPPORTED, "Non-constant initializer are not supported
yet.");
+ value = NULL;
+ }
}
token = gsk_sl_preprocessor_get (preproc);
}
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_SEMICOLON))
- {
- gsk_sl_preprocessor_error (preproc, SYNTAX, "No semicolon at end of variable declaration.");
- return FALSE;
- }
- gsk_sl_preprocessor_consume (preproc, NULL);
+ gsk_sl_preprocessor_error (preproc, SYNTAX, "No semicolon at end of variable declaration.");
+ else
+ gsk_sl_preprocessor_consume (preproc, NULL);
pointer_type = gsk_sl_pointer_type_new (type, FALSE,
decoration->values[GSK_SL_DECORATION_CALLER_ACCESS].value);
variable = gsk_sl_variable_new (pointer_type, g_strdup (name), value,
decoration->values[GSK_SL_DECORATION_CONST].set);
@@ -132,8 +129,6 @@ gsk_sl_program_parse_variable (GskSlProgram *program,
program->variables = g_slist_append (program->variables, variable);
gsk_sl_scope_add_variable (scope, variable);
-
- return TRUE;
}
static void
@@ -144,37 +139,29 @@ gsk_sl_program_parse_declaration (GskSlProgram *program,
GskSlType *type;
const GskSlToken *token;
GskSlDecorations decoration;
- gboolean success;
char *name;
- success = gsk_sl_decoration_list_parse (scope,
- preproc,
- &decoration);
+ gsk_sl_decoration_list_parse (scope,
+ preproc,
+ &decoration);
type = gsk_sl_type_new_parse (preproc);
- if (type == NULL)
- {
- gsk_sl_preprocessor_consume (preproc, program);
- return;
- }
token = gsk_sl_preprocessor_get (preproc);
if (gsk_sl_token_is (token, GSK_SL_TOKEN_SEMICOLON))
{
- if (success)
- {
- GskSlPointerType *ptype = gsk_sl_pointer_type_new (type, FALSE,
decoration.values[GSK_SL_DECORATION_CALLER_ACCESS].value);
- GskSlVariable *variable = gsk_sl_variable_new (ptype, NULL, NULL,
decoration.values[GSK_SL_DECORATION_CONST].set);
- gsk_sl_pointer_type_unref (ptype);
- program->variables = g_slist_append (program->variables, variable);
- gsk_sl_preprocessor_consume (preproc, program);
- }
+ GskSlPointerType *ptype = gsk_sl_pointer_type_new (type, FALSE,
decoration.values[GSK_SL_DECORATION_CALLER_ACCESS].value);
+ GskSlVariable *variable = gsk_sl_variable_new (ptype, NULL, NULL,
decoration.values[GSK_SL_DECORATION_CONST].set);
+ gsk_sl_pointer_type_unref (ptype);
+ program->variables = g_slist_append (program->variables, variable);
+ gsk_sl_preprocessor_consume (preproc, program);
gsk_sl_type_unref (type);
return;
}
else if (!gsk_sl_token_is (token, GSK_SL_TOKEN_IDENTIFIER))
{
gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected a variable name");
+ gsk_sl_preprocessor_consume (preproc, program);
gsk_sl_type_unref (type);
return;
}
@@ -192,14 +179,11 @@ gsk_sl_program_parse_declaration (GskSlProgram *program,
preproc,
type,
name);
- if (function)
- program->functions = g_slist_append (program->functions, function);
- else
- success = FALSE;
+ program->functions = g_slist_append (program->functions, function);
}
else
{
- success &= gsk_sl_program_parse_variable (program, scope, preproc, &decoration, type, name);
+ gsk_sl_program_parse_variable (program, scope, preproc, &decoration, type, name);
}
g_free (name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]