summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2018-02-11 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2018-02-13 14:11:27 +0100
commite8e567546282d714729df55d10ca26ec35c71416 (patch)
treea59f33e6f9f10b3f5faedd59b735420c19abdc0d /giscanner
parent6f677e77413b628756a9dbb8082f783757b099f3 (diff)
downloadgobject-introspection-e8e567546282d714729df55d10ca26ec35c71416.tar.gz
Reuse const_table between calls to SourceScanner parse_files and parse_macros.
Macro constants may now refer to constants defined in source files. Test case provided by Philip Chimento. Fixes issues #173 and #75.
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/scannerparser.y14
-rw-r--r--giscanner/sourcescanner.c3
-rw-r--r--giscanner/sourcescanner.h1
3 files changed, 7 insertions, 11 deletions
diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y
index 2735f5f4..db3aef1f 100644
--- a/giscanner/scannerparser.y
+++ b/giscanner/scannerparser.y
@@ -48,7 +48,6 @@ extern void ctype_free (GISourceType * type);
static int last_enum_value = -1;
static gboolean is_bitfield;
-static GHashTable *const_table = NULL;
/**
* parse_c_string_literal:
@@ -326,7 +325,7 @@ set_or_merge_base_type (GISourceType *type,
primary_expression
: identifier
{
- $$ = g_hash_table_lookup (const_table, $1);
+ $$ = g_hash_table_lookup (scanner->const_table, $1);
if ($$ == NULL) {
$$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, scanner->current_file, lineno);
} else {
@@ -1120,7 +1119,7 @@ enumerator
$$->ident = $1;
$$->const_int_set = TRUE;
$$->const_int = ++last_enum_value;
- g_hash_table_insert (const_table, g_strdup ($$->ident), gi_source_symbol_ref ($$));
+ g_hash_table_insert (scanner->const_table, g_strdup ($$->ident), gi_source_symbol_ref ($$));
}
| identifier '=' constant_expression
{
@@ -1129,7 +1128,7 @@ enumerator
$$->const_int_set = TRUE;
$$->const_int = $3->const_int;
last_enum_value = $$->const_int;
- g_hash_table_insert (const_table, g_strdup ($$->ident), gi_source_symbol_ref ($$));
+ g_hash_table_insert (scanner->const_table, g_strdup ($$->ident), gi_source_symbol_ref ($$));
}
;
@@ -1791,16 +1790,9 @@ gi_source_scanner_parse_file (GISourceScanner *scanner, FILE *file)
{
g_return_val_if_fail (file != NULL, FALSE);
- const_table = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify)gi_source_symbol_unref);
-
lineno = 1;
yyin = file;
yyparse (scanner);
-
- g_hash_table_destroy (const_table);
- const_table = NULL;
-
yyin = NULL;
return TRUE;
diff --git a/giscanner/sourcescanner.c b/giscanner/sourcescanner.c
index 7de891f5..8c400171 100644
--- a/giscanner/sourcescanner.c
+++ b/giscanner/sourcescanner.c
@@ -218,6 +218,8 @@ gi_source_scanner_new (void)
scanner = g_slice_new0 (GISourceScanner);
scanner->typedef_table = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
+ scanner->const_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+ (GDestroyNotify) gi_source_symbol_unref);
scanner->files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal,
g_object_unref, NULL);
g_queue_init (&scanner->conditionals);
@@ -238,6 +240,7 @@ gi_source_scanner_free (GISourceScanner *scanner)
g_object_unref (scanner->current_file);
g_hash_table_destroy (scanner->typedef_table);
+ g_hash_table_destroy (scanner->const_table);
g_slist_foreach (scanner->comments, (GFunc)gi_source_comment_free, NULL);
g_slist_free (scanner->comments);
diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h
index 2167df70..c3e9c655 100644
--- a/giscanner/sourcescanner.h
+++ b/giscanner/sourcescanner.h
@@ -115,6 +115,7 @@ struct _GISourceScanner
GHashTable *files;
GSList *comments; /* _GIComment */
GHashTable *typedef_table;
+ GHashTable *const_table;
gboolean skipping;
GQueue conditionals;
};