From e8e567546282d714729df55d10ca26ec35c71416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sun, 11 Feb 2018 00:00:00 +0000 Subject: 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. --- giscanner/scannerparser.y | 14 +++----------- giscanner/sourcescanner.c | 3 +++ giscanner/sourcescanner.h | 1 + .../Regress.FOO_FLAGS_SECOND_AND_THIRD.page | 14 ++++++++++++++ .../Regress.FOO_FLAGS_SECOND_AND_THIRD.page | 14 ++++++++++++++ .../Regress.FOO_FLAGS_SECOND_AND_THIRD.page | 14 ++++++++++++++ tests/scanner/Regress-1.0-expected.gir | 5 +++++ tests/scanner/foo.h | 1 + 8 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 tests/scanner/Regress-1.0-C-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page create mode 100644 tests/scanner/Regress-1.0-Gjs-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page create mode 100644 tests/scanner/Regress-1.0-Python-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page 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; }; diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page b/tests/scanner/Regress-1.0-C-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page new file mode 100644 index 00000000..50df7545 --- /dev/null +++ b/tests/scanner/Regress-1.0-C-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page @@ -0,0 +1,14 @@ + + + + + + Regress.FOO_FLAGS_SECOND_AND_THIRD + + + diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page b/tests/scanner/Regress-1.0-Gjs-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page new file mode 100644 index 00000000..50df7545 --- /dev/null +++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page @@ -0,0 +1,14 @@ + + + + + + Regress.FOO_FLAGS_SECOND_AND_THIRD + + + diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page b/tests/scanner/Regress-1.0-Python-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page new file mode 100644 index 00000000..50df7545 --- /dev/null +++ b/tests/scanner/Regress-1.0-Python-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page @@ -0,0 +1,14 @@ + + + + + + Regress.FOO_FLAGS_SECOND_AND_THIRD + + + diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 980ad650..cd47fcb5 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -945,6 +945,11 @@ it says it's pointer but it's actually a string. c:type="REGRESS_FOO_DEFINE_SHOULD_BE_EXPOSED"> + + + diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h index 02d9b7c8..bf9d2c37 100644 --- a/tests/scanner/foo.h +++ b/tests/scanner/foo.h @@ -246,6 +246,7 @@ typedef enum REGRESS_FOO_FLAGS_THIRD = 1 << 2 } RegressFooFlagsType; +#define REGRESS_FOO_FLAGS_SECOND_AND_THIRD (REGRESS_FOO_FLAGS_SECOND | REGRESS_FOO_FLAGS_THIRD) _GI_TEST_EXTERN GType regress_foo_flags_type_get_type (void); -- cgit v1.2.1