[gtk+/wip/otte/shader: 133/269] gskslvariable: Store constness of variables
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 133/269] gskslvariable: Store constness of variables
- Date: Tue, 24 Oct 2017 06:01:47 +0000 (UTC)
commit 703dfc16911db5485a12b59c91f05aee10cad4cf
Author: Benjamin Otte <otte redhat com>
Date: Tue Sep 26 05:02:29 2017 +0200
gskslvariable: Store constness of variables
gsk/gskslnode.c | 17 +++++++++--------
gsk/gskslprogram.c | 16 ++++++++--------
gsk/gskslvariable.c | 13 ++++++++++++-
gsk/gskslvariableprivate.h | 4 +++-
4 files changed, 32 insertions(+), 18 deletions(-)
---
diff --git a/gsk/gskslnode.c b/gsk/gskslnode.c
index f7261e8..38c4d12 100644
--- a/gsk/gskslnode.c
+++ b/gsk/gskslnode.c
@@ -248,22 +248,27 @@ static const GskSlNodeClass GSK_SL_NODE_EXPRESSION = {
static GskSlNode *
gsk_sl_node_parse_declaration (GskSlScope *scope,
GskSlPreprocessor *stream,
- GskSlPointerType *type)
+ GskSlDecorations *decoration,
+ GskSlType *type)
{
GskSlNodeDeclaration *declaration;
+ GskSlPointerType *pointer_type;
const GskSlToken *token;
declaration = gsk_sl_node_new (GskSlNodeDeclaration, &GSK_SL_NODE_DECLARATION);
+ pointer_type = gsk_sl_pointer_type_new (type, TRUE,
decoration->values[GSK_SL_DECORATION_CALLER_ACCESS].value);
token = gsk_sl_preprocessor_get (stream);
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_IDENTIFIER))
{
- declaration->variable = gsk_sl_variable_new (type, NULL);
+ declaration->variable = gsk_sl_variable_new (pointer_type, NULL,
decoration->values[GSK_SL_DECORATION_CONST].set);
+ gsk_sl_pointer_type_unref (pointer_type);
return (GskSlNode *) declaration;
}
- declaration->variable = gsk_sl_variable_new (type, token->str);
+ declaration->variable = gsk_sl_variable_new (pointer_type, token->str,
decoration->values[GSK_SL_DECORATION_CONST].set);
gsk_sl_preprocessor_consume (stream, (GskSlNode *) declaration);
+ gsk_sl_pointer_type_unref (pointer_type);
token = gsk_sl_preprocessor_get (stream);
if (gsk_sl_token_is (token, GSK_SL_TOKEN_EQUAL))
@@ -388,11 +393,7 @@ gsk_sl_node_parse_statement (GskSlScope *scope,
}
else
{
- GskSlPointerType *pointer_type;
-
- pointer_type = gsk_sl_pointer_type_new (type, TRUE,
decoration.values[GSK_SL_DECORATION_CALLER_ACCESS].value);
- node = gsk_sl_node_parse_declaration (scope, preproc, pointer_type);
- gsk_sl_pointer_type_unref (pointer_type);
+ node = gsk_sl_node_parse_declaration (scope, preproc, &decoration, type);
}
gsk_sl_type_unref (type);
diff --git a/gsk/gskslprogram.c b/gsk/gskslprogram.c
index f351996..a0f405a 100644
--- a/gsk/gskslprogram.c
+++ b/gsk/gskslprogram.c
@@ -70,18 +70,22 @@ static gboolean
gsk_sl_program_parse_variable (GskSlProgram *program,
GskSlScope *scope,
GskSlPreprocessor *preproc,
- GskSlPointerType *type,
+ GskSlDecorations *decoration,
+ GskSlType *type,
const char *name)
{
GskSlVariable *variable;
const GskSlToken *token;
+ GskSlPointerType *pointer_type;
token = gsk_sl_preprocessor_get (preproc);
if (!gsk_sl_token_is (token, GSK_SL_TOKEN_SEMICOLON))
return FALSE;
gsk_sl_preprocessor_consume (preproc, NULL);
- variable = gsk_sl_variable_new (type, name);
+ pointer_type = gsk_sl_pointer_type_new (type, FALSE,
decoration->values[GSK_SL_DECORATION_CALLER_ACCESS].value);
+ variable = gsk_sl_variable_new (pointer_type, name, decoration->values[GSK_SL_DECORATION_CONST].set);
+ gsk_sl_pointer_type_unref (pointer_type);
program->variables = g_slist_append (program->variables, variable);
gsk_sl_scope_add_variable (scope, variable);
@@ -117,7 +121,7 @@ gsk_sl_program_parse_declaration (GskSlProgram *program,
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);
+ GskSlVariable *variable = gsk_sl_variable_new (ptype, 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);
@@ -152,11 +156,7 @@ gsk_sl_program_parse_declaration (GskSlProgram *program,
}
else
{
- GskSlPointerType *pointer_type;
-
- pointer_type = gsk_sl_pointer_type_new (type, FALSE,
decoration.values[GSK_SL_DECORATION_CALLER_ACCESS].value);
- success &= gsk_sl_program_parse_variable (program, scope, preproc, pointer_type, name);
- gsk_sl_pointer_type_unref (pointer_type);
+ success &= gsk_sl_program_parse_variable (program, scope, preproc, &decoration, type, name);
}
return success;
diff --git a/gsk/gskslvariable.c b/gsk/gskslvariable.c
index faa3521..b84ccc0 100644
--- a/gsk/gskslvariable.c
+++ b/gsk/gskslvariable.c
@@ -28,11 +28,13 @@ struct _GskSlVariable {
GskSlPointerType *type;
char *name;
+ gboolean constant;
};
GskSlVariable *
gsk_sl_variable_new (GskSlPointerType *type,
- const char *name)
+ const char *name,
+ gboolean constant)
{
GskSlVariable *variable;
@@ -41,6 +43,7 @@ gsk_sl_variable_new (GskSlPointerType *type,
variable->ref_count = 1;
variable->type = gsk_sl_pointer_type_ref (type);
variable->name = g_strdup (name);
+ variable->constant = constant;
return variable;
}
@@ -75,6 +78,8 @@ void
gsk_sl_variable_print (const GskSlVariable *variable,
GString *string)
{
+ if (variable->constant)
+ g_string_append (string, "const ");
gsk_sl_pointer_type_print (variable->type, string);
if (variable->name)
{
@@ -95,6 +100,12 @@ gsk_sl_variable_get_name (const GskSlVariable *variable)
return variable->name;
}
+gboolean
+gsk_sl_variable_is_constant (const GskSlVariable *variable)
+{
+ return variable->constant;
+}
+
guint32
gsk_sl_variable_write_spv (const GskSlVariable *variable,
GskSpvWriter *writer)
diff --git a/gsk/gskslvariableprivate.h b/gsk/gskslvariableprivate.h
index bfb7be9..f909d22 100644
--- a/gsk/gskslvariableprivate.h
+++ b/gsk/gskslvariableprivate.h
@@ -26,7 +26,8 @@
G_BEGIN_DECLS
GskSlVariable * gsk_sl_variable_new (GskSlPointerType *type,
- const char *name);
+ const char *name,
+ gboolean constant);
GskSlVariable * gsk_sl_variable_ref (GskSlVariable *variable);
void gsk_sl_variable_unref (GskSlVariable *variable);
@@ -36,6 +37,7 @@ void gsk_sl_variable_print (const GskSlVari
GskSlPointerType * gsk_sl_variable_get_type (const GskSlVariable *variable);
const char * gsk_sl_variable_get_name (const GskSlVariable *variable);
+gboolean gsk_sl_variable_is_constant (const GskSlVariable *variable);
guint32 gsk_sl_variable_write_spv (const GskSlVariable *variable,
GskSpvWriter *writer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]