[gtk+/wip/otte/shader: 32/51] gskslexpression: Implment function calls
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 32/51] gskslexpression: Implment function calls
- Date: Sat, 30 Sep 2017 18:07:32 +0000 (UTC)
commit 0118dc91b7b46ead73c9e4ee2ddfc56fde4cf797
Author: Benjamin Otte <otte redhat com>
Date: Wed Sep 27 19:00:44 2017 +0200
gskslexpression: Implment function calls
gsk/gskslexpression.c | 65 +++++++++++++++++++++++++++++++-----------
gsk/gskslexpressionprivate.h | 4 +-
gsk/gskslnode.c | 5 ++-
3 files changed, 54 insertions(+), 20 deletions(-)
---
diff --git a/gsk/gskslexpression.c b/gsk/gskslexpression.c
index d7ca5cc..82033c3 100644
--- a/gsk/gskslexpression.c
+++ b/gsk/gskslexpression.c
@@ -1039,9 +1039,9 @@ gsk_sl_expression_error_new (void)
}
GskSlExpression *
-gsk_sl_expression_parse_constructor_call (GskSlScope *scope,
- GskSlPreprocessor *stream,
- GskSlType *type)
+gsk_sl_expression_parse_function_call (GskSlScope *scope,
+ GskSlPreprocessor *stream,
+ GskSlFunction *function)
{
GskSlExpressionFunctionCall *call;
const GskSlToken *token;
@@ -1050,13 +1050,12 @@ gsk_sl_expression_parse_constructor_call (GskSlScope *scope,
guint i;
call = gsk_sl_expression_new (GskSlExpressionFunctionCall, &GSK_SL_EXPRESSION_FUNCTION_CALL);
- call->function = gsk_sl_function_new_constructor (type);
- g_assert (call->function);
+ call->function = gsk_sl_function_ref (function);
token = gsk_sl_preprocessor_get (stream);
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_PAREN))
{
- gsk_sl_preprocessor_error (stream, SYNTAX, "Expected opening \"(\" when calling constructor");
+ gsk_sl_preprocessor_error (stream, SYNTAX, "Expected opening \"(\" when calling function.");
return (GskSlExpression *) call;
}
gsk_sl_preprocessor_consume (stream, (GskSlExpression *) call);
@@ -1114,21 +1113,47 @@ gsk_sl_expression_parse_primary (GskSlScope *scope,
{
case GSK_SL_TOKEN_IDENTIFIER:
{
- GskSlExpressionReference *reference;
+ GskSlExpression *expr;
GskSlVariable *variable;
+ char *name;
+
+ name = g_strdup (token->str);
+ gsk_sl_preprocessor_consume (stream, NULL);
- variable = gsk_sl_scope_lookup_variable (scope, token->str);
- if (variable == NULL)
+ token = gsk_sl_preprocessor_get (stream);
+ if (gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_PAREN))
{
- gsk_sl_preprocessor_error (stream, DECLARATION, "No variable named \"%s\".", token->str);
- gsk_sl_preprocessor_consume (stream, NULL);
- return gsk_sl_expression_error_new ();
+ GskSlFunction *function = gsk_sl_scope_lookup_function (scope, name);
+
+ if (function == NULL)
+ {
+ gsk_sl_preprocessor_error (stream, DECLARATION, "No function named \"%s\".", name);
+ expr = gsk_sl_expression_error_new ();
+ }
+ else
+ {
+ expr = gsk_sl_expression_parse_function_call (scope, stream, function);
+ }
+ }
+ else
+ {
+ GskSlExpressionReference *reference;
+ variable = gsk_sl_scope_lookup_variable (scope, name);
+ if (variable == NULL)
+ {
+ gsk_sl_preprocessor_error (stream, DECLARATION, "No variable named \"%s\".", name);
+ expr = gsk_sl_expression_error_new ();
+ }
+ else
+ {
+ reference = gsk_sl_expression_new (GskSlExpressionReference, &GSK_SL_EXPRESSION_REFERENCE);
+ reference->variable = gsk_sl_variable_ref (variable);
+ expr = (GskSlExpression *) reference;
+ }
}
- reference = gsk_sl_expression_new (GskSlExpressionReference, &GSK_SL_EXPRESSION_REFERENCE);
- reference->variable = gsk_sl_variable_ref (variable);
- gsk_sl_preprocessor_consume (stream, (GskSlExpression *) reference);
- return (GskSlExpression *) reference;
+ g_free (name);
+ return expr;
}
case GSK_SL_TOKEN_INTCONSTANT:
@@ -1212,11 +1237,17 @@ gsk_sl_expression_parse_primary (GskSlScope *scope,
case GSK_SL_TOKEN_DMAT4X3:
case GSK_SL_TOKEN_DMAT4X4:
{
+ GskSlFunction *constructor;
+ GskSlExpression *expression;
GskSlType *type;
type = gsk_sl_type_new_parse (stream);
+ constructor = gsk_sl_function_new_constructor (type);
+ expression = gsk_sl_expression_parse_function_call (scope, stream, constructor);
+ gsk_sl_function_unref (constructor);
+ gsk_sl_type_unref (type);
- return gsk_sl_expression_parse_constructor_call (scope, stream, type);
+ return expression;
}
default:
diff --git a/gsk/gskslexpressionprivate.h b/gsk/gskslexpressionprivate.h
index 214d634..3fb1811 100644
--- a/gsk/gskslexpressionprivate.h
+++ b/gsk/gskslexpressionprivate.h
@@ -29,9 +29,9 @@ GskSlExpression * gsk_sl_expression_parse_assignment (GskSlScope
GskSlPreprocessor *stream);
GskSlExpression * gsk_sl_expression_parse_constant (GskSlScope *scope,
GskSlPreprocessor *stream);
-GskSlExpression * gsk_sl_expression_parse_constructor_call (GskSlScope *scope,
+GskSlExpression * gsk_sl_expression_parse_function_call (GskSlScope *scope,
GskSlPreprocessor *stream,
- GskSlType *type);
+ GskSlFunction *function);
GskSlExpression * gsk_sl_expression_ref (GskSlExpression *expression);
void gsk_sl_expression_unref (GskSlExpression *expression);
diff --git a/gsk/gskslnode.c b/gsk/gskslnode.c
index 8e57e60..33ac6f8 100644
--- a/gsk/gskslnode.c
+++ b/gsk/gskslnode.c
@@ -396,10 +396,13 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
if (token->type == GSK_SL_TOKEN_LEFT_PAREN)
{
GskSlNodeExpression *node_expression;
+ GskSlFunction *constructor;
+ constructor = gsk_sl_function_new_constructor (type);
node_expression = gsk_sl_node_new (GskSlNodeExpression, &GSK_SL_NODE_EXPRESSION);
- node_expression->expression = gsk_sl_expression_parse_constructor_call (scope, preproc, type);
+ node_expression->expression = gsk_sl_expression_parse_function_call (scope, preproc,
constructor);
node = (GskSlNode *) node_expression;
+ gsk_sl_function_unref (constructor);
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]