mesa/program: Add _mesa_symbol_table_replace_symbol()
authorSamuel Iglesias Gonsálvez <siglesias@igalia.com>
Thu, 20 Oct 2016 07:04:59 +0000 (09:04 +0200)
committerSamuel Iglesias Gonsálvez <siglesias@igalia.com>
Wed, 26 Oct 2016 09:57:02 +0000 (11:57 +0200)
This function allows to modify an existing symbol.

v2:
- Remove namespace usage now that it was deleted.

Signed-off-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Reviewed-by: Timothy Arceri <timothy.arceri@collabora.com>
src/mesa/program/symbol_table.c
src/mesa/program/symbol_table.h

index 23cb7ec26b1fcbd55972d5415c4d8ed36ebf6bca..37066c904cc91c42866c0af45f78732a8f76a8df 100644 (file)
@@ -211,6 +211,20 @@ _mesa_symbol_table_add_symbol(struct _mesa_symbol_table *table,
    return 0;
 }
 
+int
+_mesa_symbol_table_replace_symbol(struct _mesa_symbol_table *table,
+                                  const char *name,
+                                  void *declaration)
+{
+    struct symbol *sym = find_symbol(table, name);
+
+    /* If the symbol doesn't exist, it cannot be replaced. */
+    if (sym == NULL)
+       return -1;
+
+    sym->data = declaration;
+    return 0;
+}
 
 int
 _mesa_symbol_table_add_global_symbol(struct _mesa_symbol_table *table,
index ff1e6f2065a2893c877ed4daf13a66b9684a8233..cba47143ef2db3bf85bff61fc10715fb4ba6d7ec 100644 (file)
@@ -32,6 +32,10 @@ extern void _mesa_symbol_table_pop_scope(struct _mesa_symbol_table *table);
 extern int _mesa_symbol_table_add_symbol(struct _mesa_symbol_table *symtab,
                                          const char *name, void *declaration);
 
+extern int _mesa_symbol_table_replace_symbol(struct _mesa_symbol_table *table,
+                                             const char *name,
+                                             void *declaration);
+
 extern int
 _mesa_symbol_table_add_global_symbol(struct _mesa_symbol_table *symtab,
                                      const char *name,