summaryrefslogtreecommitdiff
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
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.
-rw-r--r--giscanner/scannerparser.y14
-rw-r--r--giscanner/sourcescanner.c3
-rw-r--r--giscanner/sourcescanner.h1
-rw-r--r--tests/scanner/Regress-1.0-C-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page14
-rw-r--r--tests/scanner/Regress-1.0-Gjs-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page14
-rw-r--r--tests/scanner/Regress-1.0-Python-expected/Regress.FOO_FLAGS_SECOND_AND_THIRD.page14
-rw-r--r--tests/scanner/Regress-1.0-expected.gir5
-rw-r--r--tests/scanner/foo.h1
8 files changed, 55 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;
};
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 @@
+<?xml version="1.0"?>
+<page id="Regress.FOO_FLAGS_SECOND_AND_THIRD"
+ type="topic"
+ style="default"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="default" type="guide"/>
+ </info>
+ <title>Regress.FOO_FLAGS_SECOND_AND_THIRD</title>
+
+
+</page>
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 @@
+<?xml version="1.0"?>
+<page id="Regress.FOO_FLAGS_SECOND_AND_THIRD"
+ type="topic"
+ style="default"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="default" type="guide"/>
+ </info>
+ <title>Regress.FOO_FLAGS_SECOND_AND_THIRD</title>
+
+
+</page>
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 @@
+<?xml version="1.0"?>
+<page id="Regress.FOO_FLAGS_SECOND_AND_THIRD"
+ type="topic"
+ style="default"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="default" type="guide"/>
+ </info>
+ <title>Regress.FOO_FLAGS_SECOND_AND_THIRD</title>
+
+
+</page>
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.</doc>
c:type="REGRESS_FOO_DEFINE_SHOULD_BE_EXPOSED">
<type name="utf8" c:type="gchar*"/>
</constant>
+ <constant name="FOO_FLAGS_SECOND_AND_THIRD"
+ value="6"
+ c:type="REGRESS_FOO_FLAGS_SECOND_AND_THIRD">
+ <type name="gint" c:type="gint"/>
+ </constant>
<constant name="FOO_PIE_IS_TASTY"
value="3.141590"
c:type="REGRESS_FOO_PIE_IS_TASTY">
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);