Debian Codegraph @

mixlib/mix_symbol_table.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /* -*-c-*- ---------------- mix_symbol_table.h :
2 * Type mix_symbol_table_t and functions to manipulate it.
3 * ------------------------------------------------------------------
4 * Copyright (C) 2000, 2004, 2007 Free Software Foundation, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 */
21
22
23 #ifndef MIX_SYMBOL_TABLE_H
24 #define MIX_SYMBOL_TABLE_H
25
26 #include <stdio.h>
27 #include "mix_types.h"
28
29 /* A symbol table shall be implemented as a hash table */
30 typedef GHashTable mix_symbol_table_t ;
31
32 /* Maximum length of stored symbols */
33 #define MIX_SYM_MAX_LEN 10
34
35 /* Create an empty table */
36 extern mix_symbol_table_t *
37 mix_symbol_table_new (void);
38
39 /* Create a table and populate it with the contents of a table stored
40 in -file- using mix_symbol_table_print (table, MIX_SYM_LINE, file)
41 */
42 extern mix_symbol_table_t *
43 mix_symbol_table_new_from_file (FILE *file);
44
45
46 /* Delete a table */
47 extern void
48 mix_symbol_table_delete (mix_symbol_table_t *table);
49
50 /* add/remove symbols from other table */
51 extern gboolean
52 mix_symbol_table_merge_table (mix_symbol_table_t *table,
53 const mix_symbol_table_t *from);
54
55 extern gboolean
•56 mix_symbol_table_subtract_table (mix_symbol_table_t *table,
57 const mix_symbol_table_t *other);
58
59 /* Add/remove symbols one by one */
60 /* possible outcomes: */
61 enum {
62 MIX_SYM_FAIL, /* attempt failed */
63 MIX_SYM_OK,
64 MIX_SYM_DUP, /* duplicated symbol */
65 MIX_SYM_LONG /* symbol too long: only MIX_SYM_MAX_LEN chars used */
66 };
67
68 extern gint
69 mix_symbol_table_add (mix_symbol_table_t *table,
70 const gchar *sym, mix_word_t value);
71
72 #define mix_symbol_table_remove(table, sym) \
73 g_hash_table_remove (table, sym)
74
75
76 /* Add or modify symbol if it exists */
77 extern gint
78 mix_symbol_table_insert (mix_symbol_table_t *table,
79 const gchar *sym, mix_word_t new_value);
80
81 /* Add or modify symbol if it exists, without copying sym */
82 #define mix_symbol_table_insert_static(table,sym,value)\
83 g_hash_table_insert (table,(gpointer)sym,GUINT_TO_POINTER (value))
84
85 /* Symbols lookup */
86 extern gboolean
87 mix_symbol_table_is_defined (const mix_symbol_table_t *table, const gchar *sym);
88
89 #define mix_symbol_table_value(table,sym) \
90 (mix_word_t)GPOINTER_TO_UINT (g_hash_table_lookup ((GHashTable *)table, \
91 (gpointer)sym))
92
93 /* Traverse the table */
94 #define mix_symbol_table_foreach(table,func,data) \
95 g_hash_table_foreach (table,func,data)
96
97 /* Print the table */
98 enum {
99 MIX_SYM_ROWS, /* each symbol/value in a row */
100 MIX_SYM_LINE /* {,symbol =value}*; in a single row */
101 };
102
103 extern void
104 mix_symbol_table_print (const mix_symbol_table_t *table, gint mode,
105 FILE *file, gboolean skiplocal);
106
107
108 #endif /* MIX_SYMBOL_TABLE_H */
109