gobject-introspection r163 - in trunk: . tools
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: gobject-introspection r163 - in trunk: . tools
- Date: Sun, 23 Mar 2008 21:55:18 +0000 (GMT)
Author: johan
Date: Sun Mar 23 21:55:17 2008
New Revision: 163
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=163&view=rev
Log:
2008-03-23 Johan Dahlin <johan gnome org>
* tools/Makefile.am:
* tools/scanner.c:
* tools/scanner.h:
* tools/scannerlexer.l:
* tools/scannerparser.y:
* tools/sourcescanner.c:
* tools/sourcescanner.h:
Split out the source scanner from the generator.
Rename the symbols used in the scanner to use the gi_ prefix.
This should make it possible to use the raw C parser from
other programs.
Added:
trunk/tools/sourcescanner.c
trunk/tools/sourcescanner.h
Modified:
trunk/ChangeLog
trunk/tools/Makefile.am
trunk/tools/scanner.c
trunk/tools/scanner.h
trunk/tools/scannerlexer.l
trunk/tools/scannerparser.y
Modified: trunk/tools/Makefile.am
==============================================================================
--- trunk/tools/Makefile.am (original)
+++ trunk/tools/Makefile.am Sun Mar 23 21:55:17 2008
@@ -5,7 +5,7 @@
gmetadata-header.c
CLEANFILES = scannerparser.c scannerparser.h scannerlexer.c scannerlexer.h gmetadata-header.c
-AM_YFLAGS = -d
+AM_YFLAGS = -d -t
EXTRA_DIST = quote-file.sh
# Why do I have to do this automake?
@@ -43,6 +43,8 @@
g_idl_generate_LDADD = $(GIREPO_LIBS) $(top_builddir)/girepository/libgirepository.la
g_idl_scanner_SOURCES = \
+ sourcescanner.c \
+ sourcescanner.h \
scanner.c \
scanner.h \
scannerlexer.l \
Modified: trunk/tools/scanner.c
==============================================================================
--- trunk/tools/scanner.c (original)
+++ trunk/tools/scanner.c Sun Mar 23 21:55:17 2008
@@ -30,6 +30,7 @@
#include <glib-object.h>
#include <sys/wait.h> /* waitpid */
#include <gmodule.h>
+#include "sourcescanner.h"
#include "scanner.h"
#include "gidlparser.h"
#include "gidlmodule.h"
@@ -53,16 +54,12 @@
g_ascii_strdown (igenerator->namespace, -1);
igenerator->module = g_idl_module_new (namespace, shared_library);
- igenerator->typedef_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- igenerator->struct_or_union_or_enum_table =
- g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)csymbol_unref);
-
igenerator->type_map = g_hash_table_new (g_str_hash, g_str_equal);
igenerator->type_by_lower_case_prefix =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
igenerator->symbols = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- igenerator->directives_map = g_hash_table_new (g_str_hash, g_str_equal);
-
+ igenerator->scanner = gi_source_scanner_new ();
+
return igenerator;
}
@@ -73,29 +70,15 @@
g_free (generator->shared_library);
g_free (generator->lower_case_namespace);
- g_list_foreach (generator->filenames, (GFunc)g_free, NULL);
- g_list_free (generator->filenames);
-
- g_free (generator->current_filename);
-
- g_list_foreach (generator->symbol_list, (GFunc)csymbol_unref, NULL);
- g_list_free (generator->symbol_list);
-
- g_hash_table_destroy (generator->typedef_table);
- g_hash_table_destroy (generator->struct_or_union_or_enum_table);
-
g_idl_module_free (generator->module);
g_list_foreach (generator->get_type_symbols, (GFunc)g_free, NULL);
g_list_free (generator->get_type_symbols);
- g_hash_table_destroy (generator->type_map);
g_hash_table_destroy (generator->type_by_lower_case_prefix);
g_hash_table_destroy (generator->symbols);
- g_hash_table_destroy (generator->directives_map);
-
g_free (generator);
}
@@ -133,7 +116,7 @@
}
static GIdlNodeType *
-create_node_from_ctype (CType * ctype)
+create_node_from_ctype (GISourceType * ctype)
{
GIdlNodeType *node;
@@ -298,9 +281,9 @@
static const gchar *
lookup_symbol (GIGenerator *igenerator, const gchar *typename)
{
- const gchar *name =
- g_hash_table_lookup (igenerator->symbols, typename);
+ const gchar *name;
+ name = g_hash_table_lookup (igenerator->symbols, typename);
if (!name)
{
g_printerr ("Unknown symbol: %s\n", typename);
@@ -340,19 +323,19 @@
* for GdkWindow
*/
g_hash_table_insert (igenerator->type_by_lower_case_prefix,
- alt_lower_case_prefix, node);
- }
- else
- {
- g_free (alt_lower_case_prefix);
+ g_strdup (alt_lower_case_prefix),
+ node);
}
+ g_free (alt_lower_case_prefix);
+
node->gtype_name = g_strdup (node->node.name);
node->gtype_init = g_strdup (symbol_name);
node->parent = g_strdup (lookup_symbol (igenerator,
g_type_name (g_type_parent (type_id))));
type_interfaces = g_type_interfaces (type_id, &n_type_interfaces);
+
for (i = 0; i < n_type_interfaces; i++)
{
char *iface_name =
@@ -407,10 +390,10 @@
lower_case_prefix, node);
node->gtype_name = g_strdup (node->node.name);
node->gtype_init = g_strdup (symbol_name);
-
+
iface_prereqs =
g_type_interface_prerequisites (type_id, &n_iface_prereqs);
-
+
for (i = 0; i < n_iface_prereqs; i++)
{
if (g_type_fundamental (iface_prereqs[i]) == G_TYPE_OBJECT)
@@ -533,12 +516,15 @@
/* ignore already processed functions */
if (symbol_name == NULL)
return FALSE;
-
+
if (!g_module_symbol (module,
symbol_name,
(gpointer *) & type_fun))
return FALSE;
-
+
+ if (igenerator->verbose)
+ g_print ("DEBUG: calling %s\n", symbol_name);
+
type_id = type_fun ();
type_fundamental = g_type_fundamental (type_id);
lower_case_prefix =
@@ -547,6 +533,9 @@
strlen (symbol_name) - strlen ("_get_type")),
"_", "");
+ if (igenerator->verbose)
+ g_print ("DEBUG: processing it as a %s\n", g_type_name (type_fundamental));
+
switch (type_fundamental)
{
case G_TYPE_OBJECT:
@@ -581,7 +570,7 @@
{
GModule *module;
GList *l;
-
+
module = g_module_open (filename,
G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
@@ -591,6 +580,9 @@
return;
}
+ if (igenerator->verbose)
+ g_print ("DEBUG: opened library %s\n", filename);
+
for (l = igenerator->get_type_symbols; l != NULL; l = l->next)
{
if (g_igenerator_process_module_symbol (igenerator,
@@ -601,7 +593,7 @@
}
static void
-g_igenerator_process_function_symbol (GIGenerator * igenerator, CSymbol * sym)
+g_igenerator_process_function_symbol (GIGenerator * igenerator, GISourceSymbol * sym)
{
GIdlNodeFunction *func;
char *last_underscore;
@@ -680,11 +672,11 @@
func->result = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
func->result->type = create_node_from_ctype (sym->base_type->base_type);
- directives = g_hash_table_lookup (igenerator->directives_map, func->symbol);
+ directives = g_hash_table_lookup (igenerator->scanner->directives_map, func->symbol);
for (j = directives; j; j = j->next)
{
- CDirective *directive = j->data;
+ GISourceDirective *directive = j->data;
if (g_ascii_strncasecmp ("return", directive->name, 6) == 0)
{
GSList *options;
@@ -700,7 +692,7 @@
for (param_l = sym->base_type->child_list, i = 1; param_l != NULL;
param_l = param_l->next, i++)
{
- CSymbol *param_sym = param_l->data;
+ GISourceSymbol *param_sym = param_l->data;
GIdlNodeParam *param;
param = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
@@ -708,7 +700,7 @@
for (j = directives; j; j = j->next)
{
- CDirective *directive = j->data;
+ GISourceDirective *directive = j->data;
if (g_ascii_strcasecmp (param_sym->ident, directive->name) == 0)
{
@@ -749,14 +741,14 @@
/* By removing it here, we mark it as handled, memory will be freed by
* the cleanup for sym */
- g_hash_table_remove (igenerator->directives_map, func->symbol);
+ g_hash_table_remove (igenerator->scanner->directives_map, func->symbol);
}
static void
g_igenerator_process_unregistered_struct_typedef (GIGenerator * igenerator,
- CSymbol * sym,
- CType * struct_type)
+ GISourceSymbol * sym,
+ GISourceType * struct_type)
{
GIdlNodeStruct *node =
(GIdlNodeStruct *) g_idl_node_new (G_IDL_NODE_STRUCT);
@@ -775,7 +767,7 @@
for (member_l = struct_type->child_list; member_l != NULL;
member_l = member_l->next)
{
- CSymbol *member = member_l->data;
+ GISourceSymbol *member = member_l->data;
GIdlNodeField *gifield =
(GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
@@ -786,18 +778,18 @@
}
static void
-g_igenerator_process_struct_typedef (GIGenerator * igenerator, CSymbol * sym)
+g_igenerator_process_struct_typedef (GIGenerator * igenerator, GISourceSymbol * sym)
{
- CType *struct_type = sym->base_type;
+ GISourceType *struct_type = sym->base_type;
gboolean opaque_type = FALSE;
GIdlNode *type;
if (struct_type->child_list == NULL)
{
- CSymbol *struct_symbol;
+ GISourceSymbol *struct_symbol;
g_assert (struct_type->name != NULL);
struct_symbol =
- g_hash_table_lookup (igenerator->struct_or_union_or_enum_table,
+ g_hash_table_lookup (igenerator->scanner->struct_or_union_or_enum_table,
struct_type->name);
if (struct_symbol != NULL)
{
@@ -809,7 +801,7 @@
{
opaque_type = TRUE;
}
-
+
type = g_hash_table_lookup (igenerator->type_map, sym->ident);
if (type != NULL)
{
@@ -824,7 +816,7 @@
for (member_l = struct_type->child_list->next; member_l != NULL;
member_l = member_l->next)
{
- CSymbol *member = member_l->data;
+ GISourceSymbol *member = member_l->data;
/* ignore private / reserved members */
if (member->ident[0] == '_'
|| g_str_has_prefix (member->ident, "priv"))
@@ -845,7 +837,7 @@
for (member_l = struct_type->child_list; member_l != NULL;
member_l = member_l->next)
{
- CSymbol *member = member_l->data;
+ GISourceSymbol *member = member_l->data;
GIdlNodeField *gifield =
(GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
node->members = g_list_append (node->members, gifield);
@@ -889,7 +881,7 @@
for (member_l = struct_type->child_list->next; member_l != NULL;
member_l = member_l->next)
{
- CSymbol *member = member_l->data;
+ GISourceSymbol *member = member_l->data;
/* ignore private / reserved members */
if (member->ident[0] == '_')
{
@@ -926,7 +918,7 @@
vfunc_param_l = vfunc_param_l->next, sig_param_l =
sig_param_l->next)
{
- CSymbol *vfunc_param = vfunc_param_l->data;
+ GISourceSymbol *vfunc_param = vfunc_param_l->data;
GIdlNodeParam *sig_param = sig_param_l->data;
if (vfunc_param->ident != NULL)
{
@@ -955,7 +947,7 @@
for (param_l = member->base_type->base_type->child_list, i = 1;
param_l != NULL; param_l = param_l->next, i++)
{
- CSymbol *param_sym = param_l->data;
+ GISourceSymbol *param_sym = param_l->data;
GIdlNodeParam *param =
(GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
if (param_sym->ident == NULL)
@@ -985,17 +977,17 @@
}
static void
-g_igenerator_process_union_typedef (GIGenerator * igenerator, CSymbol * sym)
+g_igenerator_process_union_typedef (GIGenerator * igenerator, GISourceSymbol * sym)
{
- CType *union_type = sym->base_type;
+ GISourceType *union_type = sym->base_type;
gboolean opaque_type = FALSE;
GIdlNode *type;
if (union_type->child_list == NULL)
{
g_assert (union_type->name != NULL);
- CSymbol *union_symbol =
- g_hash_table_lookup (igenerator->struct_or_union_or_enum_table,
+ GISourceSymbol *union_symbol =
+ g_hash_table_lookup (igenerator->scanner->struct_or_union_or_enum_table,
union_type->name);
if (union_symbol != NULL)
{
@@ -1016,7 +1008,7 @@
for (member_l = union_type->child_list; member_l != NULL;
member_l = member_l->next)
{
- CSymbol *member = member_l->data;
+ GISourceSymbol *member = member_l->data;
GIdlNodeField *gifield =
(GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
node->members = g_list_append (node->members, gifield);
@@ -1044,7 +1036,7 @@
for (member_l = union_type->child_list; member_l != NULL;
member_l = member_l->next)
{
- CSymbol *member = member_l->data;
+ GISourceSymbol *member = member_l->data;
GIdlNodeField *gifield =
(GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
node->members = g_list_append (node->members, gifield);
@@ -1055,19 +1047,19 @@
}
static void
-g_igenerator_process_enum_typedef (GIGenerator * igenerator, CSymbol * sym)
+g_igenerator_process_enum_typedef (GIGenerator * igenerator, GISourceSymbol * sym)
{
- CType *enum_type;
+ GISourceType *enum_type;
GList *member_l;
GIdlNodeEnum *node;
- CSymbol *enum_symbol;
+ GISourceSymbol *enum_symbol;
enum_type = sym->base_type;
if (enum_type->child_list == NULL)
{
g_assert (enum_type->name != NULL);
enum_symbol =
- g_hash_table_lookup (igenerator->struct_or_union_or_enum_table,
+ g_hash_table_lookup (igenerator->scanner->struct_or_union_or_enum_table,
enum_type->name);
if (enum_symbol != NULL)
{
@@ -1095,7 +1087,7 @@
for (member_l = enum_type->child_list; member_l != NULL;
member_l = member_l->next)
{
- CSymbol *member = member_l->data;
+ GISourceSymbol *member = member_l->data;
GIdlNodeValue *gival =
(GIdlNodeValue *) g_idl_node_new (G_IDL_NODE_VALUE);
node->values = g_list_append (node->values, gival);
@@ -1106,7 +1098,7 @@
static void
g_igenerator_process_function_typedef (GIGenerator * igenerator,
- CSymbol * sym)
+ GISourceSymbol * sym)
{
GList *param_l;
int i;
@@ -1128,7 +1120,7 @@
for (param_l = sym->base_type->base_type->child_list, i = 1;
param_l != NULL; param_l = param_l->next, i++)
{
- CSymbol *param_sym = param_l->data;
+ GISourceSymbol *param_sym = param_l->data;
GIdlNodeParam *param =
(GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
if (param_sym->ident == NULL)
@@ -1145,7 +1137,7 @@
}
static void
-g_igenerator_process_constant (GIGenerator * igenerator, CSymbol * sym)
+g_igenerator_process_constant (GIGenerator * igenerator, GISourceSymbol * sym)
{
GIdlNodeConstant *giconst =
(GIdlNodeConstant *) g_idl_node_new (G_IDL_NODE_CONSTANT);
@@ -1170,12 +1162,12 @@
static void
g_igenerator_process_symbols (GIGenerator * igenerator)
{
- GList *l;
+ GSList *l;
/* process type symbols first to ensure complete type hashtables */
/* type symbols */
- for (l = igenerator->symbol_list; l != NULL; l = l->next)
+ for (l = igenerator->scanner->symbols; l != NULL; l = l->next)
{
- CSymbol *sym = l->data;
+ GISourceSymbol *sym = l->data;
if (sym->ident[0] == '_')
{
/* ignore private / reserved symbols */
@@ -1218,9 +1210,9 @@
}
}
/* other symbols */
- for (l = igenerator->symbol_list; l != NULL; l = l->next)
+ for (l = igenerator->scanner->symbols; l != NULL; l = l->next)
{
- CSymbol *sym = l->data;
+ GISourceSymbol *sym = l->data;
if (sym->ident[0] == '_')
{
/* ignore private / reserved symbols */
@@ -1238,58 +1230,16 @@
}
void
-g_igenerator_add_symbol (GIGenerator * igenerator, CSymbol * symbol)
-{
- /* only add symbols of main file */
- gboolean found_filename = FALSE;
- GList *l;
-
- for (l = igenerator->filenames; l != NULL; l = l->next)
- {
- if (strcmp (l->data, igenerator->current_filename) == 0)
- {
- found_filename = TRUE;
- break;
- }
- }
-
- if (found_filename || igenerator->macro_scan)
- {
- igenerator->symbol_list =
- g_list_prepend (igenerator->symbol_list, csymbol_ref (symbol));
- }
-
- if (symbol->type == CSYMBOL_TYPE_TYPEDEF)
-
- {
- g_hash_table_insert (igenerator->typedef_table, g_strdup (symbol->ident), GINT_TO_POINTER (TRUE));
- }
- else if (symbol->type == CSYMBOL_TYPE_STRUCT
- || symbol->type == CSYMBOL_TYPE_UNION
- || symbol->type == CSYMBOL_TYPE_ENUM)
- {
- g_hash_table_insert (igenerator->struct_or_union_or_enum_table,
- g_strdup (symbol->ident), csymbol_ref (symbol));
- }
-}
-
-gboolean
-g_igenerator_is_typedef (GIGenerator * igenerator, const char *name)
-{
- gboolean b = g_hash_table_lookup (igenerator->typedef_table, name) != NULL;
- return b;
-}
-
-void
g_igenerator_generate (GIGenerator * igenerator,
const gchar * filename,
GList *libraries)
{
- GList *l;
+ GSList *l;
+ GList *k;
- for (l = igenerator->symbol_list; l != NULL; l = l->next)
+ for (l = igenerator->scanner->symbols; l != NULL; l = l->next)
{
- CSymbol *sym = l->data;
+ GISourceSymbol *sym = l->data;
if (sym->type == CSYMBOL_TYPE_FUNCTION
&& g_str_has_suffix (sym->ident, "_get_type"))
{
@@ -1305,8 +1255,8 @@
/* ensure to initialize GObject */
g_type_class_ref (G_TYPE_OBJECT);
- for (l = libraries; l; l = l->next)
- g_igenerator_process_module (igenerator, (const gchar*)l->data);
+ for (k = libraries; k; k = k->next)
+ g_igenerator_process_module (igenerator, (const gchar*)k->data);
g_igenerator_process_symbols (igenerator);
@@ -1361,13 +1311,15 @@
{
GError *error = NULL;
char *tmp_name = NULL;
- FILE *fmacros =
- fdopen (g_file_open_tmp ("gen-introspect-XXXXXX.h", &tmp_name, &error),
+ FILE *fmacros;
+ GSList *k, *symbols;
+ GList *l;
+
+ fmacros = fdopen (g_file_open_tmp ("gen-introspect-XXXXXX.h", &tmp_name, &error),
"w+");
g_unlink (tmp_name);
- GList *l;
- for (l = igenerator->filenames; l != NULL; l = l->next)
+ for (l = igenerator->scanner->filenames; l != NULL; l = l->next)
{
FILE *f = fopen (l->data, "r");
int line = 1;
@@ -1486,13 +1438,13 @@
fclose (f);
}
- igenerator->macro_scan = TRUE;
+ igenerator->scanner->macro_scan = TRUE;
rewind (fmacros);
- g_igenerator_parse_file (igenerator, fmacros);
+ gi_source_scanner_parse_file (igenerator->scanner, fmacros);
fclose (fmacros);
- igenerator->macro_scan = FALSE;
+ igenerator->scanner->macro_scan = FALSE;
}
static void
@@ -1601,10 +1553,10 @@
f = fdopen (cpp_in, "w");
- for (l = igenerator->filenames; l != NULL; l = l->next)
+ for (l = igenerator->scanner->filenames; l != NULL; l = l->next)
{
if (igenerator->verbose)
- g_printf ("Pre-processing %s\n", (char*)l->data);
+ g_printf ("DEBUG: Pre-processing %s\n", (char*)l->data);
fprintf (f, "#include <%s>\n", (char *) l->data);
@@ -1689,6 +1641,7 @@
GError *error = NULL;
GList *l, *libraries = NULL;
GList *cpp_options = NULL;
+ GSList *k, *symbols;
char *buffer;
size_t size;
FILE *tmp;
@@ -1783,6 +1736,13 @@
return 1;
}
+ g_type_init ();
+
+ /* initialize threading as this may be required by libraries that we'll use
+ * libsoup-2.2 is an example of that.
+ */
+ g_thread_init (NULL);
+
igenerator = g_igenerator_new (namespace, shared_library);
if (verbose)
@@ -1794,17 +1754,10 @@
g_igenerator_free (igenerator);
return 0;
}
- igenerator->filenames = filenames;
+ igenerator->scanner->filenames = filenames;
cpp_options = g_list_reverse (cpp_options);
libraries = g_list_reverse (libraries);
- g_type_init ();
-
- /* initialize threading as this may be required by libraries that we'll use
- * libsoup-2.2 is an example of that.
- */
- g_thread_init (NULL);
-
if (include_idls)
{
for (i = 0; i < g_strv_length (include_idls); i++)
@@ -1812,7 +1765,7 @@
}
for (l = sources; l; l = l->next)
- g_igenerator_lex_filename (igenerator, l->data);
+ gi_source_scanner_lex_filename (igenerator->scanner, l->data);
g_list_foreach (sources, (GFunc)g_free, NULL);
g_list_free (sources);
@@ -1825,7 +1778,7 @@
return 1;
}
- if (!g_igenerator_parse_file (igenerator, tmp))
+ if (!gi_source_scanner_parse_file (igenerator->scanner, tmp))
{
fclose (tmp);
g_igenerator_free (igenerator);
@@ -1833,11 +1786,13 @@
}
g_igenerator_parse_macros (igenerator);
-
+
g_igenerator_generate (igenerator, output, libraries);
fclose (tmp);
+#if 0
g_igenerator_free (igenerator);
+#endif
return 0;
}
Modified: trunk/tools/scanner.h
==============================================================================
--- trunk/tools/scanner.h (original)
+++ trunk/tools/scanner.h Sun Mar 23 21:55:17 2008
@@ -26,11 +26,10 @@
#include <glib.h>
#include "gidlmodule.h"
+#include "sourcescanner.h"
-G_BEGIN_DECLS typedef struct _GIGenerator GIGenerator;
-typedef struct _CSymbol CSymbol;
-typedef struct _CType CType;
-typedef struct _CDirective CDirective;
+G_BEGIN_DECLS
+typedef struct _GIGenerator GIGenerator;
struct _GIGenerator
{
@@ -40,14 +39,6 @@
char *lower_case_namespace;
gboolean verbose;
- /* specified files to be parsed */
- GList *filenames;
- /* source reference of current lexer position */
- char *current_filename;
- GList *symbol_list;
- GHashTable *typedef_table;
- GHashTable *struct_or_union_or_enum_table;
-
GIdlModule *module;
GList *get_type_symbols;
GHashTable *type_map;
@@ -55,121 +46,12 @@
GHashTable *symbols; /* typename -> module.name */
- /* symbol -> GList of CDirective */
- GHashTable *directives_map;
-
- /* scanner variables */
- gboolean macro_scan;
-};
-
-typedef enum
-{
- CSYMBOL_TYPE_INVALID,
- CSYMBOL_TYPE_CONST,
- CSYMBOL_TYPE_OBJECT,
- CSYMBOL_TYPE_FUNCTION,
- CSYMBOL_TYPE_STRUCT,
- CSYMBOL_TYPE_UNION,
- CSYMBOL_TYPE_ENUM,
- CSYMBOL_TYPE_TYPEDEF
-} CSymbolType;
-
-struct _CSymbol
-{
- int ref_count;
- CSymbolType type;
- int id;
- char *ident;
- CType *base_type;
- gboolean const_int_set;
- int const_int;
- char *const_string;
- GSList *directives; /* list of CDirective */
+ GISourceScanner *scanner;
};
-typedef enum
-{
- CTYPE_INVALID,
- CTYPE_VOID,
- CTYPE_BASIC_TYPE,
- CTYPE_TYPEDEF,
- CTYPE_STRUCT,
- CTYPE_UNION,
- CTYPE_ENUM,
- CTYPE_POINTER,
- CTYPE_ARRAY,
- CTYPE_FUNCTION
-} CTypeType;
-
-typedef enum
-{
- STORAGE_CLASS_NONE = 0,
- STORAGE_CLASS_TYPEDEF = 1 << 1,
- STORAGE_CLASS_EXTERN = 1 << 2,
- STORAGE_CLASS_STATIC = 1 << 3,
- STORAGE_CLASS_AUTO = 1 << 4,
- STORAGE_CLASS_REGISTER = 1 << 5
-} StorageClassSpecifier;
-
-typedef enum
-{
- TYPE_QUALIFIER_NONE = 0,
- TYPE_QUALIFIER_CONST = 1 << 1,
- TYPE_QUALIFIER_RESTRICT = 1 << 2,
- TYPE_QUALIFIER_VOLATILE = 1 << 3
-} TypeQualifier;
-
-typedef enum
-{
- FUNCTION_NONE = 0,
- FUNCTION_INLINE = 1 << 1
-} FunctionSpecifier;
-
-typedef enum
-{
- UNARY_ADDRESS_OF,
- UNARY_POINTER_INDIRECTION,
- UNARY_PLUS,
- UNARY_MINUS,
- UNARY_BITWISE_COMPLEMENT,
- UNARY_LOGICAL_NEGATION
-} UnaryOperator;
-
-struct _CType
-{
- CTypeType type;
- StorageClassSpecifier storage_class_specifier;
- TypeQualifier type_qualifier;
- FunctionSpecifier function_specifier;
- char *name;
- CType *base_type;
- GList *child_list;
-};
-
-struct _CDirective {
- char *name;
- char *value;
- GSList *options;
-};
-
-CSymbol * csymbol_new (CSymbolType type);
-gboolean csymbol_get_const_boolean (CSymbol *symbol);
-CSymbol * csymbol_ref (CSymbol *symbol);
-void csymbol_unref (CSymbol *symbol);
-CDirective * cdirective_new (const gchar *name,
- const gchar *value,
- GSList *options);
-void cdirective_free (CDirective *directive);
-
-gboolean g_igenerator_lex_filename (GIGenerator *igenerator,
- const gchar *filename);
-gboolean g_igenerator_parse_file (GIGenerator *igenerator,
- FILE *file);
void g_igenerator_set_verbose (GIGenerator *igenerator,
gboolean verbose);
-void g_igenerator_add_symbol (GIGenerator *igenerator,
- CSymbol *symbol);
-gboolean g_igenerator_is_typedef (GIGenerator *igenerator,
- const char *name);
+
G_END_DECLS
-#endif
+
+#endif /* __SCANNER_H__ */
Modified: trunk/tools/scannerlexer.l
==============================================================================
--- trunk/tools/scannerlexer.l (original)
+++ trunk/tools/scannerlexer.l Sun Mar 23 21:55:17 2008
@@ -31,18 +31,19 @@
#include <ctype.h>
#include <stdio.h>
-#include "scanner.h"
+#include <glib.h>
+#include "sourcescanner.h"
#include "scannerparser.h"
#include "grealpath.h"
int lineno;
-extern int yylex (GIGenerator *igenerator);
-#define YY_DECL int yylex (GIGenerator *igenerator)
+extern int yylex (GISourceScanner *scanner);
+#define YY_DECL int yylex (GISourceScanner *scanner)
static int yywrap (void);
-static void parse_comment (GIGenerator *igenerator);
-static void process_directive (GIGenerator *igenerator);
-static int check_identifier (GIGenerator *igenerator, const char *);
+static void parse_comment (GISourceScanner *scanner);
+static void process_directive (GISourceScanner *scanner);
+static int check_identifier (GISourceScanner *scanner, const char *);
%}
intsuffix ([uU][lL]?)|([lL][uU]?)
@@ -57,13 +58,13 @@
"\n" { ++lineno; } /* " */
[\t\f\v\r ]+ { /* Ignore whitespace. */ }
-"/*" { parse_comment(igenerator); }
+"/*" { parse_comment(scanner); }
"//".* { }
"#define "[a-zA-Z_][a-zA-Z_0-9]*"(" { yyless (yyleng - 1); return FUNCTION_MACRO; }
"#define "[a-zA-Z_][a-zA-Z_0-9]* { return OBJECT_MACRO; }
-"#" { process_directive(igenerator); }
+"#" { process_directive(scanner); }
"{" { return '{'; }
"<%" { return '{'; }
@@ -116,7 +117,7 @@
"," { return ','; }
"->" { return ARROW; }
-[a-zA-Z_][a-zA-Z_0-9]* { if (igenerator->macro_scan) return IDENTIFIER; else REJECT; }
+[a-zA-Z_][a-zA-Z_0-9]* { if (scanner->macro_scan) return IDENTIFIER; else REJECT; }
"auto" { return AUTO; }
"_Bool" { return BOOL; }
@@ -154,7 +155,7 @@
"volatile" { return VOLATILE; }
"while" { return WHILE; }
-[a-zA-Z_][a-zA-Z_0-9]* { return check_identifier(igenerator, yytext); }
+[a-zA-Z_][a-zA-Z_0-9]* { return check_identifier(scanner, yytext); }
"0"[xX][0-9a-fA-F]+{intsuffix}? { return INTEGER; }
"0"[0-7]+{intsuffix}? { return INTEGER; }
@@ -169,7 +170,7 @@
"\""{stringtext}*"\"" { return STRING; }
"L\""{stringtext}*"\"" { return STRING; }
-. { fprintf(stderr, "%s:%d: unexpected character `%c'\n", igenerator->current_filename, lineno, yytext[0]); }
+. { fprintf(stderr, "%s:%d: unexpected character `%c'\n", scanner->current_filename, lineno, yytext[0]); }
%%
@@ -181,16 +182,16 @@
static void
-parse_gtkdoc (GIGenerator *igenerator,
- gchar *symbol,
- int *c1,
- int *c2)
+parse_gtkdoc (GISourceScanner *scanner,
+ gchar *symbol,
+ int *c1,
+ int *c2)
{
gboolean isline = FALSE;
gchar line[256];
int i;
gchar **parts;
- CDirective *directive;
+ GISourceDirective *directive;
char *name,*value;
GSList *directives;
GSList *options = NULL;
@@ -263,10 +264,10 @@
else
rname = name;
- directive = cdirective_new (rname, value, options);
- directives = g_hash_table_lookup (igenerator->directives_map, symbol);
+ directive = gi_source_directive_new (rname, value, options);
+ directives = g_hash_table_lookup (scanner->directives_map, symbol);
directives = g_slist_prepend (directives, directive);
- g_hash_table_replace (igenerator->directives_map,
+ g_hash_table_replace (scanner->directives_map,
g_strdup (symbol), directives);
g_strfreev (parts);
@@ -275,7 +276,7 @@
static void
-parse_comment (GIGenerator *igenerator)
+parse_comment (GISourceScanner *scanner)
{
GString *symbol = NULL;
gboolean startofline = FALSE, have_symbol = FALSE, start1 = FALSE, start_symbol = FALSE;
@@ -317,7 +318,7 @@
c1 = c2;
c2 = input();
if (symbol)
- parse_gtkdoc (igenerator, symbol->str, &c1, &c2);
+ parse_gtkdoc (scanner, symbol->str, &c1, &c2);
}
}
@@ -327,7 +328,7 @@
}
static int
-check_identifier (GIGenerator *igenerator,
+check_identifier (GISourceScanner *scanner,
const char *s)
{
/*
@@ -335,7 +336,7 @@
* identifier.
*/
- if (g_igenerator_is_typedef (igenerator, s)) {
+ if (gi_source_scanner_is_typedef (scanner, s)) {
return TYPEDEF_NAME;
} else if (strcmp (s, "__builtin_va_list") == 0) {
return TYPEDEF_NAME;
@@ -345,7 +346,7 @@
}
static void
-process_directive (GIGenerator *igenerator)
+process_directive (GISourceScanner *scanner)
{
/* extract current filename from #line directives */
GString *filename_builder;
@@ -383,8 +384,8 @@
if (filename_builder->len > 0) {
char *filename = g_strcompress (filename_builder->str);
- g_free (igenerator->current_filename);
- igenerator->current_filename = g_realpath(filename);
+ g_free (scanner->current_filename);
+ scanner->current_filename = g_realpath(filename);
g_free(filename);
}
Modified: trunk/tools/scannerparser.y
==============================================================================
--- trunk/tools/scannerparser.y (original)
+++ trunk/tools/scannerparser.y Sun Mar 23 21:55:17 2008
@@ -31,202 +31,35 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include "scanner.h"
+#include <glib.h>
+#include "sourcescanner.h"
+#include "scannerparser.h"
extern FILE *yyin;
extern int lineno;
extern char *yytext;
-extern int yylex (GIGenerator *igenerator);
-static void yyerror(GIGenerator *igenerator, const char *s);
+extern int yylex (GISourceScanner *scanner);
+static void yyerror (GISourceScanner *scanner, const char *str);
static int last_enum_value = -1;
static GHashTable *const_table = NULL;
-
-CSymbol *
-csymbol_new (CSymbolType type)
-{
- CSymbol *s = g_slice_new0 (CSymbol);
- s->ref_count = 1;
- s->type = type;
- return s;
-}
-
-static void
-ctype_free (CType * type)
-{
- g_free (type->name);
- g_list_foreach (type->child_list, (GFunc)csymbol_unref, NULL);
- g_list_free (type->child_list);
- g_slice_free (CType, type);
-}
-
-CSymbol *
-csymbol_ref (CSymbol * symbol)
-{
- symbol->ref_count++;
-}
-
-void
-csymbol_unref (CSymbol * symbol)
-{
- symbol->ref_count--;
- if (symbol->ref_count == 0)
- {
- g_free (symbol->ident);
- if (symbol->base_type)
- ctype_free (symbol->base_type);
- g_free (symbol->const_string);
- g_slist_foreach (symbol->directives, (GFunc)cdirective_free, NULL);
- g_slist_free (symbol->directives);
- g_slice_free (CSymbol, symbol);
- }
-}
-
-gboolean
-csymbol_get_const_boolean (CSymbol * symbol)
-{
- return (symbol->const_int_set && symbol->const_int) || symbol->const_string;
-}
-
-CType *
-ctype_new (CTypeType type)
-{
- CType *t = g_slice_new0 (CType);
- t->type = type;
- return t;
-}
-
-CType *
-ctype_copy (CType * type)
-{
- GList *l;
- CType *result = g_slice_new0 (CType);
- result->type = type->type;
- result->storage_class_specifier = type->storage_class_specifier;
- result->type_qualifier = type->type_qualifier;
- result->function_specifier = type->function_specifier;
- if (type->name)
- result->name = g_strdup (type->name);
- if (type->base_type)
- result->base_type = ctype_copy (type->base_type);
- for (l = type->child_list; l; l = l->next)
- result->child_list = g_list_append (result->child_list, csymbol_ref (l->data));
- return result;
-}
-
-CType *
-cbasic_type_new (const char *name)
-{
- CType *basic_type = ctype_new (CTYPE_BASIC_TYPE);
- basic_type->name = g_strdup (name);
- return basic_type;
-}
-
-CType *
-ctypedef_new (const char *name)
-{
- CType *typedef_ = ctype_new (CTYPE_TYPEDEF);
- typedef_->name = g_strdup (name);
- return typedef_;
-}
-
-CType *
-cstruct_new (const char *name)
-{
- CType *struct_ = ctype_new (CTYPE_STRUCT);
- struct_->name = g_strdup (name);
- return struct_;
-}
-
-CType *
-cunion_new (const char *name)
-{
- CType *union_ = ctype_new (CTYPE_UNION);
- union_->name = g_strdup (name);
- return union_;
-}
-
-CType *
-cenum_new (const char *name)
-{
- CType *enum_ = ctype_new (CTYPE_ENUM);
- enum_->name = g_strdup (name);
- return enum_;
-}
-
-CType *
-cpointer_new (CType * base_type)
-{
- CType *pointer = ctype_new (CTYPE_POINTER);
- if (base_type != NULL)
- pointer->base_type = ctype_copy (base_type);
- return pointer;
-}
-
-CType *
-carray_new (void)
-{
- CType *array = ctype_new (CTYPE_ARRAY);
- return array;
-}
-
-CType *
-cfunction_new (void)
-{
- CType *func = ctype_new (CTYPE_FUNCTION);
- return func;
-}
-
-/* use specified type as base type of symbol */
-static void
-csymbol_merge_type (CSymbol *symbol, CType *type)
-{
- CType **foundation_type = &(symbol->base_type);
- while (*foundation_type != NULL) {
- foundation_type = &((*foundation_type)->base_type);
- }
- *foundation_type = type;
-}
-
-CDirective *
-cdirective_new (const gchar *name,
- const gchar *value,
- GSList *options)
-{
- CDirective *directive;
-
- directive = g_slice_new (CDirective);
- directive->name = g_strdup (name);
- directive->value = g_strdup (value);
- directive->options = options;
- return directive;
-}
-
-void
-cdirective_free (CDirective *directive)
-{
- g_free (directive->name);
- g_free (directive->value);
- g_slice_free (CDirective, directive);
-}
-
%}
%error-verbose
%union {
char *str;
GList *list;
- CSymbol *symbol;
- CType *ctype;
+ GISourceSymbol *symbol;
+ GISourceType *ctype;
StorageClassSpecifier storage_class_specifier;
TypeQualifier type_qualifier;
FunctionSpecifier function_specifier;
UnaryOperator unary_operator;
}
-%parse-param { GIGenerator* igenerator }
-%lex-param { GIGenerator* igenerator }
+%parse-param { GISourceScanner* scanner }
+%lex-param { GISourceScanner* scanner }
%token <str> IDENTIFIER "identifier"
%token <str> TYPEDEF_NAME "typedef-name"
@@ -308,14 +141,14 @@
{
$$ = g_hash_table_lookup (const_table, $1);
if ($$ == NULL) {
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
} else {
- $$ = csymbol_ref ($$);
+ $$ = gi_source_symbol_ref ($$);
}
}
| INTEGER
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
if (g_str_has_prefix (yytext, "0x") && strlen (yytext) > 2) {
$$->const_int = strtol (yytext + 2, NULL, 16);
@@ -327,11 +160,11 @@
}
| CHARACTER
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| FLOATING
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| strings
| '(' expression ')'
@@ -344,7 +177,7 @@
strings
: STRING
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
yytext[strlen (yytext) - 1] = '\0';
$$->const_string = g_strcompress (yytext + 1);
}
@@ -377,31 +210,31 @@
: primary_expression
| postfix_expression '[' expression ']'
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| postfix_expression '(' argument_expression_list ')'
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| postfix_expression '(' ')'
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| postfix_expression '.' identifier_or_typedef_name
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| postfix_expression ARROW identifier_or_typedef_name
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| postfix_expression PLUSPLUS
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| postfix_expression MINUSMINUS
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
;
@@ -414,11 +247,11 @@
: postfix_expression
| PLUSPLUS unary_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| MINUSMINUS unary_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| unary_operator cast_expression
{
@@ -436,21 +269,21 @@
break;
case UNARY_LOGICAL_NEGATION:
$$ = $2;
- $$->const_int = !csymbol_get_const_boolean ($2);
+ $$->const_int = !gi_source_symbol_get_const_boolean ($2);
break;
default:
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
break;
}
}
| SIZEOF unary_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| SIZEOF '(' type_name ')'
{
ctype_free ($3);
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
;
@@ -494,13 +327,13 @@
: cast_expression
| multiplicative_expression '*' cast_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int * $3->const_int;
}
| multiplicative_expression '/' cast_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
if ($3->const_int != 0) {
$$->const_int = $1->const_int / $3->const_int;
@@ -508,7 +341,7 @@
}
| multiplicative_expression '%' cast_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int % $3->const_int;
}
@@ -518,13 +351,13 @@
: multiplicative_expression
| additive_expression '+' multiplicative_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int + $3->const_int;
}
| additive_expression '-' multiplicative_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int - $3->const_int;
}
@@ -534,13 +367,13 @@
: additive_expression
| shift_expression SL additive_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int << $3->const_int;
}
| shift_expression SR additive_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int >> $3->const_int;
}
@@ -550,25 +383,25 @@
: shift_expression
| relational_expression '<' shift_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int < $3->const_int;
}
| relational_expression '>' shift_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int > $3->const_int;
}
| relational_expression LTEQ shift_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int <= $3->const_int;
}
| relational_expression GTEQ shift_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int >= $3->const_int;
}
@@ -578,13 +411,13 @@
: relational_expression
| equality_expression EQ relational_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int == $3->const_int;
}
| equality_expression NOTEQ relational_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int != $3->const_int;
}
@@ -594,7 +427,7 @@
: equality_expression
| and_expression '&' equality_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int & $3->const_int;
}
@@ -604,7 +437,7 @@
: and_expression
| exclusive_or_expression '^' and_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int ^ $3->const_int;
}
@@ -614,7 +447,7 @@
: exclusive_or_expression
| inclusive_or_expression '|' exclusive_or_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
$$->const_int = $1->const_int | $3->const_int;
}
@@ -624,9 +457,11 @@
: inclusive_or_expression
| logical_and_expression ANDAND inclusive_or_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
- $$->const_int = csymbol_get_const_boolean ($1) && csymbol_get_const_boolean ($3);
+ $$->const_int =
+ gi_source_symbol_get_const_boolean ($1) &&
+ gi_source_symbol_get_const_boolean ($3);
}
;
@@ -634,9 +469,11 @@
: logical_and_expression
| logical_or_expression OROR logical_and_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_CONST);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST);
$$->const_int_set = TRUE;
- $$->const_int = csymbol_get_const_boolean ($1) || csymbol_get_const_boolean ($3);
+ $$->const_int =
+ gi_source_symbol_get_const_boolean ($1) ||
+ gi_source_symbol_get_const_boolean ($3);
}
;
@@ -644,7 +481,7 @@
: logical_or_expression
| logical_or_expression '?' expression ':' conditional_expression
{
- $$ = csymbol_get_const_boolean ($1) ? $3 : $5;
+ $$ = gi_source_symbol_get_const_boolean ($1) ? $3 : $5;
}
;
@@ -652,7 +489,7 @@
: conditional_expression
| unary_expression assignment_operator assignment_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
;
@@ -674,7 +511,7 @@
: assignment_expression
| expression ',' assignment_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
;
@@ -689,8 +526,8 @@
{
GList *l;
for (l = $2; l != NULL; l = l->next) {
- CSymbol *sym = l->data;
- csymbol_merge_type (sym, ctype_copy ($1));
+ GISourceSymbol *sym = l->data;
+ gi_source_symbol_merge_type (sym, gi_source_type_copy ($1));
if ($1->storage_class_specifier & STORAGE_CLASS_TYPEDEF) {
sym->type = CSYMBOL_TYPE_TYPEDEF;
} else if (sym->base_type->type == CTYPE_FUNCTION) {
@@ -698,8 +535,8 @@
} else {
sym->type = CSYMBOL_TYPE_OBJECT;
}
- g_igenerator_add_symbol (igenerator, sym);
- csymbol_unref (sym);
+ gi_source_scanner_add_symbol (scanner, sym);
+ gi_source_symbol_unref (sym);
}
ctype_free ($1);
}
@@ -717,7 +554,7 @@
}
| storage_class_specifier
{
- $$ = ctype_new (CTYPE_INVALID);
+ $$ = gi_source_type_new (CTYPE_INVALID);
$$->storage_class_specifier |= $1;
}
| type_specifier declaration_specifiers
@@ -733,7 +570,7 @@
}
| type_qualifier
{
- $$ = ctype_new (CTYPE_INVALID);
+ $$ = gi_source_type_new (CTYPE_INVALID);
$$->type_qualifier |= $1;
}
| function_specifier declaration_specifiers
@@ -743,7 +580,7 @@
}
| function_specifier
{
- $$ = ctype_new (CTYPE_INVALID);
+ $$ = gi_source_type_new (CTYPE_INVALID);
$$->function_specifier |= $1;
}
;
@@ -790,49 +627,49 @@
type_specifier
: VOID
{
- $$ = ctype_new (CTYPE_VOID);
+ $$ = gi_source_type_new (CTYPE_VOID);
}
| CHAR
{
- $$ = cbasic_type_new ("char");
+ $$ = gi_source_basic_type_new ("char");
}
| SHORT
{
- $$ = cbasic_type_new ("short");
+ $$ = gi_source_basic_type_new ("short");
}
| INT
{
- $$ = cbasic_type_new ("int");
+ $$ = gi_source_basic_type_new ("int");
}
| LONG
{
- $$ = cbasic_type_new ("long");
+ $$ = gi_source_basic_type_new ("long");
}
| FLOAT
{
- $$ = cbasic_type_new ("float");
+ $$ = gi_source_basic_type_new ("float");
}
| DOUBLE
{
- $$ = cbasic_type_new ("double");
+ $$ = gi_source_basic_type_new ("double");
}
| SIGNED
{
- $$ = cbasic_type_new ("signed");
+ $$ = gi_source_basic_type_new ("signed");
}
| UNSIGNED
{
- $$ = cbasic_type_new ("unsigned");
+ $$ = gi_source_basic_type_new ("unsigned");
}
| BOOL
{
- $$ = cbasic_type_new ("bool");
+ $$ = gi_source_basic_type_new ("bool");
}
| struct_or_union_specifier
| enum_specifier
| typedef_name
{
- $$ = ctypedef_new ($1);
+ $$ = gi_source_typedef_new ($1);
g_free ($1);
}
;
@@ -844,7 +681,7 @@
$$->name = $2;
$$->child_list = $4;
- CSymbol *sym = csymbol_new (CSYMBOL_TYPE_INVALID);
+ GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
if ($$->type == CTYPE_STRUCT) {
sym->type = CSYMBOL_TYPE_STRUCT;
} else if ($$->type == CTYPE_UNION) {
@@ -853,9 +690,9 @@
g_assert_not_reached ();
}
sym->ident = g_strdup ($$->name);
- sym->base_type = ctype_copy ($$);
- g_igenerator_add_symbol (igenerator, sym);
- csymbol_unref (sym);
+ sym->base_type = gi_source_type_copy ($$);
+ gi_source_scanner_add_symbol (scanner, sym);
+ gi_source_symbol_unref (sym);
}
| struct_or_union '{' struct_declaration_list '}'
{
@@ -872,11 +709,11 @@
struct_or_union
: STRUCT
{
- $$ = cstruct_new (NULL);
+ $$ = gi_source_struct_new (NULL);
}
| UNION
{
- $$ = cunion_new (NULL);
+ $$ = gi_source_union_new (NULL);
}
;
@@ -894,11 +731,11 @@
GList *l;
$$ = NULL;
for (l = $2; l != NULL; l = l->next) {
- CSymbol *sym = l->data;
+ GISourceSymbol *sym = l->data;
if ($1->storage_class_specifier & STORAGE_CLASS_TYPEDEF) {
sym->type = CSYMBOL_TYPE_TYPEDEF;
}
- csymbol_merge_type (sym, ctype_copy ($1));
+ gi_source_symbol_merge_type (sym, gi_source_type_copy ($1));
$$ = g_list_append ($$, sym);
}
ctype_free ($1);
@@ -919,7 +756,7 @@
}
| type_qualifier
{
- $$ = ctype_new (CTYPE_INVALID);
+ $$ = gi_source_type_new (CTYPE_INVALID);
$$->type_qualifier |= $1;
}
;
@@ -938,12 +775,12 @@
struct_declarator
: /* empty, support for anonymous structs and unions */
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| declarator
| ':' constant_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
}
| declarator ':' constant_expression
;
@@ -951,31 +788,31 @@
enum_specifier
: ENUM identifier_or_typedef_name '{' enumerator_list '}'
{
- $$ = cenum_new ($2);
+ $$ = gi_source_enum_new ($2);
$$->child_list = $4;
last_enum_value = -1;
}
| ENUM '{' enumerator_list '}'
{
- $$ = cenum_new (NULL);
+ $$ = gi_source_enum_new (NULL);
$$->child_list = $3;
last_enum_value = -1;
}
| ENUM identifier_or_typedef_name '{' enumerator_list ',' '}'
{
- $$ = cenum_new ($2);
+ $$ = gi_source_enum_new ($2);
$$->child_list = $4;
last_enum_value = -1;
}
| ENUM '{' enumerator_list ',' '}'
{
- $$ = cenum_new (NULL);
+ $$ = gi_source_enum_new (NULL);
$$->child_list = $3;
last_enum_value = -1;
}
| ENUM identifier_or_typedef_name
{
- $$ = cenum_new ($2);
+ $$ = gi_source_enum_new ($2);
}
;
@@ -993,20 +830,20 @@
enumerator
: identifier
{
- $$ = csymbol_new (CSYMBOL_TYPE_OBJECT);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_OBJECT);
$$->ident = $1;
$$->const_int_set = TRUE;
$$->const_int = ++last_enum_value;
- g_hash_table_insert (const_table, g_strdup ($$->ident), csymbol_ref ($$));
+ g_hash_table_insert (const_table, g_strdup ($$->ident), gi_source_symbol_ref ($$));
}
| identifier '=' constant_expression
{
- $$ = csymbol_new (CSYMBOL_TYPE_OBJECT);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_OBJECT);
$$->ident = $1;
$$->const_int_set = TRUE;
$$->const_int = $3->const_int;
last_enum_value = $$->const_int;
- g_hash_table_insert (const_table, g_strdup ($$->ident), csymbol_ref ($$));
+ g_hash_table_insert (const_table, g_strdup ($$->ident), gi_source_symbol_ref ($$));
}
;
@@ -1036,7 +873,7 @@
: pointer direct_declarator
{
$$ = $2;
- csymbol_merge_type ($$, $1);
+ gi_source_symbol_merge_type ($$, $1);
}
| direct_declarator
;
@@ -1044,7 +881,7 @@
direct_declarator
: identifier
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
$$->ident = $1;
}
| '(' declarator ')'
@@ -1054,56 +891,56 @@
| direct_declarator '[' assignment_expression ']'
{
$$ = $1;
- csymbol_merge_type ($$, carray_new ());
+ gi_source_symbol_merge_type ($$, gi_source_array_new ());
}
| direct_declarator '[' ']'
{
$$ = $1;
- csymbol_merge_type ($$, carray_new ());
+ gi_source_symbol_merge_type ($$, gi_source_array_new ());
}
| direct_declarator '(' parameter_type_list ')'
{
- CType *func = cfunction_new ();
+ GISourceType *func = gi_source_function_new ();
// ignore (void) parameter list
- if ($3 != NULL && ($3->next != NULL || ((CSymbol *) $3->data)->base_type->type != CTYPE_VOID)) {
+ if ($3 != NULL && ($3->next != NULL || ((GISourceSymbol *) $3->data)->base_type->type != CTYPE_VOID)) {
func->child_list = $3;
}
$$ = $1;
- csymbol_merge_type ($$, func);
+ gi_source_symbol_merge_type ($$, func);
}
| direct_declarator '(' identifier_list ')'
{
- CType *func = cfunction_new ();
+ GISourceType *func = gi_source_function_new ();
func->child_list = $3;
$$ = $1;
- csymbol_merge_type ($$, func);
+ gi_source_symbol_merge_type ($$, func);
}
| direct_declarator '(' ')'
{
- CType *func = cfunction_new ();
+ GISourceType *func = gi_source_function_new ();
$$ = $1;
- csymbol_merge_type ($$, func);
+ gi_source_symbol_merge_type ($$, func);
}
;
pointer
: '*' type_qualifier_list
{
- $$ = cpointer_new (NULL);
+ $$ = gi_source_pointer_new (NULL);
$$->type_qualifier = $2;
}
| '*'
{
- $$ = cpointer_new (NULL);
+ $$ = gi_source_pointer_new (NULL);
}
| '*' type_qualifier_list pointer
{
- $$ = cpointer_new ($3);
+ $$ = gi_source_pointer_new ($3);
$$->type_qualifier = $2;
}
| '*' pointer
{
- $$ = cpointer_new ($2);
+ $$ = gi_source_pointer_new ($2);
}
;
@@ -1135,16 +972,16 @@
: declaration_specifiers declarator
{
$$ = $2;
- csymbol_merge_type ($$, $1);
+ gi_source_symbol_merge_type ($$, $1);
}
| declaration_specifiers abstract_declarator
{
$$ = $2;
- csymbol_merge_type ($$, $1);
+ gi_source_symbol_merge_type ($$, $1);
}
| declaration_specifiers
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
$$->base_type = $1;
}
;
@@ -1152,13 +989,13 @@
identifier_list
: identifier
{
- CSymbol *sym = csymbol_new (CSYMBOL_TYPE_INVALID);
+ GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
sym->ident = $1;
$$ = g_list_append (NULL, sym);
}
| identifier_list ',' identifier
{
- CSymbol *sym = csymbol_new (CSYMBOL_TYPE_INVALID);
+ GISourceSymbol *sym = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
sym->ident = $3;
$$ = g_list_append ($1, sym);
}
@@ -1172,14 +1009,14 @@
abstract_declarator
: pointer
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
- csymbol_merge_type ($$, $1);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ gi_source_symbol_merge_type ($$, $1);
}
| direct_abstract_declarator
| pointer direct_abstract_declarator
{
$$ = $2;
- csymbol_merge_type ($$, $1);
+ gi_source_symbol_merge_type ($$, $1);
}
;
@@ -1190,55 +1027,55 @@
}
| '[' ']'
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
- csymbol_merge_type ($$, carray_new ());
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ gi_source_symbol_merge_type ($$, gi_source_array_new ());
}
| '[' assignment_expression ']'
{
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
- csymbol_merge_type ($$, carray_new ());
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ gi_source_symbol_merge_type ($$, gi_source_array_new ());
}
| direct_abstract_declarator '[' ']'
{
$$ = $1;
- csymbol_merge_type ($$, carray_new ());
+ gi_source_symbol_merge_type ($$, gi_source_array_new ());
}
| direct_abstract_declarator '[' assignment_expression ']'
{
$$ = $1;
- csymbol_merge_type ($$, carray_new ());
+ gi_source_symbol_merge_type ($$, gi_source_array_new ());
}
| '(' ')'
{
- CType *func = cfunction_new ();
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
- csymbol_merge_type ($$, func);
+ GISourceType *func = gi_source_function_new ();
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ gi_source_symbol_merge_type ($$, func);
}
| '(' parameter_type_list ')'
{
- CType *func = cfunction_new ();
+ GISourceType *func = gi_source_function_new ();
// ignore (void) parameter list
- if ($2 != NULL && ($2->next != NULL || ((CSymbol *) $2->data)->base_type->type != CTYPE_VOID)) {
+ if ($2 != NULL && ($2->next != NULL || ((GISourceSymbol *) $2->data)->base_type->type != CTYPE_VOID)) {
func->child_list = $2;
}
- $$ = csymbol_new (CSYMBOL_TYPE_INVALID);
- csymbol_merge_type ($$, func);
+ $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID);
+ gi_source_symbol_merge_type ($$, func);
}
| direct_abstract_declarator '(' ')'
{
- CType *func = cfunction_new ();
+ GISourceType *func = gi_source_function_new ();
$$ = $1;
- csymbol_merge_type ($$, func);
+ gi_source_symbol_merge_type ($$, func);
}
| direct_abstract_declarator '(' parameter_type_list ')'
{
- CType *func = cfunction_new ();
+ GISourceType *func = gi_source_function_new ();
// ignore (void) parameter list
- if ($3 != NULL && ($3->next != NULL || ((CSymbol *) $3->data)->base_type->type != CTYPE_VOID)) {
+ if ($3 != NULL && ($3->next != NULL || ((GISourceSymbol *) $3->data)->base_type->type != CTYPE_VOID)) {
func->child_list = $3;
}
$$ = $1;
- csymbol_merge_type ($$, func);
+ gi_source_symbol_merge_type ($$, func);
}
;
@@ -1372,8 +1209,8 @@
{
if ($2->const_int_set || $2->const_string != NULL) {
$2->ident = $1;
- g_igenerator_add_symbol (igenerator, $2);
- csymbol_unref ($2);
+ gi_source_scanner_add_symbol (scanner, $2);
+ gi_source_symbol_unref ($2);
}
}
;
@@ -1385,30 +1222,29 @@
;
%%
-
static void
-yyerror (GIGenerator *igenerator, const char *s)
+yyerror (GISourceScanner *scanner, const char *s)
{
/* ignore errors while doing a macro scan as not all object macros
* have valid expressions */
- if (!igenerator->macro_scan)
+ if (!scanner->macro_scan)
{
fprintf(stderr, "%s:%d: %s\n",
- igenerator->current_filename, lineno, s);
+ scanner->current_filename, lineno, s);
}
}
gboolean
-g_igenerator_parse_file (GIGenerator *igenerator, FILE *file)
+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)csymbol_unref);
+ g_free, (GDestroyNotify)gi_source_symbol_unref);
lineno = 1;
yyin = file;
- yyparse (igenerator);
+ yyparse (scanner);
g_hash_table_destroy (const_table);
const_table = NULL;
@@ -1419,15 +1255,14 @@
}
gboolean
-g_igenerator_lex_filename (GIGenerator *igenerator, const gchar *filename)
+gi_source_scanner_lex_filename (GISourceScanner *scanner, const gchar *filename)
{
yyin = fopen (filename, "r");
- while (yylex (igenerator) != YYEOF)
+ while (yylex (scanner) != YYEOF)
;
fclose (yyin);
return TRUE;
}
-
Added: trunk/tools/sourcescanner.c
==============================================================================
--- (empty file)
+++ trunk/tools/sourcescanner.c Sun Mar 23 21:55:17 2008
@@ -0,0 +1,281 @@
+/* GObject introspectaion: public scanner api
+ *
+ * Copyright (C) 2007 JÃrg Billeter
+ * Copyright (C) 2008 Johan Dahlin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "sourcescanner.h"
+
+GISourceSymbol *
+gi_source_symbol_new (GISourceSymbolType type)
+{
+ GISourceSymbol *s = g_slice_new0 (GISourceSymbol);
+ s->ref_count = 1;
+ s->type = type;
+ return s;
+}
+
+void
+ctype_free (GISourceType * type)
+{
+ g_free (type->name);
+ g_list_foreach (type->child_list, (GFunc)gi_source_symbol_unref, NULL);
+ g_list_free (type->child_list);
+ g_slice_free (GISourceType, type);
+}
+
+GISourceSymbol *
+gi_source_symbol_ref (GISourceSymbol * symbol)
+{
+ symbol->ref_count++;
+}
+
+void
+gi_source_symbol_unref (GISourceSymbol * symbol)
+{
+ symbol->ref_count--;
+ if (symbol->ref_count == 0)
+ {
+ g_free (symbol->ident);
+ if (symbol->base_type)
+ ctype_free (symbol->base_type);
+ g_free (symbol->const_string);
+ g_slist_foreach (symbol->directives, (GFunc)gi_source_directive_free, NULL);
+ g_slist_free (symbol->directives);
+ g_slice_free (GISourceSymbol, symbol);
+ }
+}
+
+gboolean
+gi_source_symbol_get_const_boolean (GISourceSymbol * symbol)
+{
+ return (symbol->const_int_set && symbol->const_int) || symbol->const_string;
+}
+
+/* use specified type as base type of symbol */
+void
+gi_source_symbol_merge_type (GISourceSymbol *symbol,
+ GISourceType *type)
+{
+ GISourceType **foundation_type = &(symbol->base_type);
+
+ while (*foundation_type != NULL)
+ {
+ foundation_type = &((*foundation_type)->base_type);
+ }
+ *foundation_type = type;
+}
+
+
+GISourceType *
+gi_source_type_new (GISourceTypeType type)
+{
+ GISourceType *t = g_slice_new0 (GISourceType);
+ t->type = type;
+ return t;
+}
+
+GISourceType *
+gi_source_type_copy (GISourceType * type)
+{
+ GList *l;
+ GISourceType *result = g_slice_new0 (GISourceType);
+ result->type = type->type;
+ result->storage_class_specifier = type->storage_class_specifier;
+ result->type_qualifier = type->type_qualifier;
+ result->function_specifier = type->function_specifier;
+ if (type->name)
+ result->name = g_strdup (type->name);
+ if (type->base_type)
+ result->base_type = gi_source_type_copy (type->base_type);
+ for (l = type->child_list; l; l = l->next)
+ result->child_list = g_list_append (result->child_list, gi_source_symbol_ref (l->data));
+ return result;
+}
+
+GISourceType *
+gi_source_basic_type_new (const char *name)
+{
+ GISourceType *basic_type = gi_source_type_new (CTYPE_BASIC_TYPE);
+ basic_type->name = g_strdup (name);
+ return basic_type;
+}
+
+GISourceType *
+gi_source_typedef_new (const char *name)
+{
+ GISourceType *typedef_ = gi_source_type_new (CTYPE_TYPEDEF);
+ typedef_->name = g_strdup (name);
+ return typedef_;
+}
+
+GISourceType *
+gi_source_struct_new (const char *name)
+{
+ GISourceType *struct_ = gi_source_type_new (CTYPE_STRUCT);
+ struct_->name = g_strdup (name);
+ return struct_;
+}
+
+GISourceType *
+gi_source_union_new (const char *name)
+{
+ GISourceType *union_ = gi_source_type_new (CTYPE_UNION);
+ union_->name = g_strdup (name);
+ return union_;
+}
+
+GISourceType *
+gi_source_enum_new (const char *name)
+{
+ GISourceType *enum_ = gi_source_type_new (CTYPE_ENUM);
+ enum_->name = g_strdup (name);
+ return enum_;
+}
+
+GISourceType *
+gi_source_pointer_new (GISourceType * base_type)
+{
+ GISourceType *pointer = gi_source_type_new (CTYPE_POINTER);
+ if (base_type != NULL)
+ pointer->base_type = gi_source_type_copy (base_type);
+ return pointer;
+}
+
+GISourceType *
+gi_source_array_new (void)
+{
+ GISourceType *array = gi_source_type_new (CTYPE_ARRAY);
+ return array;
+}
+
+GISourceType *
+gi_source_function_new (void)
+{
+ GISourceType *func = gi_source_type_new (CTYPE_FUNCTION);
+ return func;
+}
+
+GISourceDirective *
+gi_source_directive_new (const gchar *name,
+ const gchar *value,
+ GSList *options)
+{
+ GISourceDirective *directive;
+
+ directive = g_slice_new (GISourceDirective);
+ directive->name = g_strdup (name);
+ directive->value = g_strdup (value);
+ directive->options = options;
+ return directive;
+}
+
+void
+gi_source_directive_free (GISourceDirective *directive)
+{
+ g_free (directive->name);
+ g_free (directive->value);
+ g_slice_free (GISourceDirective, directive);
+}
+
+GISourceScanner *
+gi_source_scanner_new (void)
+{
+ GISourceScanner * scanner;
+
+ scanner = g_slice_new0 (GISourceScanner);
+ scanner->typedef_table = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, NULL);
+ scanner->directives_map = g_hash_table_new (g_str_hash, g_str_equal);
+ scanner->struct_or_union_or_enum_table =
+ g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify)gi_source_symbol_unref);
+
+ return scanner;
+}
+
+void
+gi_source_scanner_free (GISourceScanner *scanner)
+{
+ g_free (scanner->current_filename);
+
+ g_hash_table_destroy (scanner->directives_map);
+ g_hash_table_destroy (scanner->typedef_table);
+ g_hash_table_destroy (scanner->struct_or_union_or_enum_table);
+
+ g_slist_foreach (scanner->symbols, (GFunc)gi_source_symbol_unref, NULL);
+ g_slist_free (scanner->symbols);
+
+ g_list_foreach (scanner->filenames, (GFunc)g_free, NULL);
+ g_list_free (scanner->filenames);
+
+}
+
+gboolean
+gi_source_scanner_is_typedef (GISourceScanner *scanner,
+ const char *name)
+{
+ gboolean b = g_hash_table_lookup (scanner->typedef_table, name) != NULL;
+ return b;
+}
+
+void
+gi_source_scanner_add_symbol (GISourceScanner *scanner,
+ GISourceSymbol *symbol)
+{
+ gboolean found_filename = FALSE;
+ GList *l;
+
+ for (l = scanner->filenames; l != NULL; l = l->next)
+ {
+ if (strcmp (l->data, scanner->current_filename) == 0)
+ {
+ found_filename = TRUE;
+ break;
+ }
+ }
+
+ if (found_filename || scanner->macro_scan)
+ scanner->symbols = g_slist_prepend (scanner->symbols,
+ gi_source_symbol_ref (symbol));
+
+ switch (symbol->type)
+ {
+ case CSYMBOL_TYPE_TYPEDEF:
+ g_hash_table_insert (scanner->typedef_table,
+ g_strdup (symbol->ident),
+ GINT_TO_POINTER (TRUE));
+ break;
+ case CSYMBOL_TYPE_STRUCT:
+ case CSYMBOL_TYPE_UNION:
+ case CSYMBOL_TYPE_ENUM:
+ g_hash_table_insert (scanner->struct_or_union_or_enum_table,
+ g_strdup (symbol->ident),
+ gi_source_symbol_ref (symbol));
+ break;
+ default:
+ break;
+ }
+}
+
+GSList *
+gi_source_scanner_get_symbols (GISourceScanner *scanner)
+{
+ return g_slist_reverse (scanner->symbols);
+}
Added: trunk/tools/sourcescanner.h
==============================================================================
--- (empty file)
+++ trunk/tools/sourcescanner.h Sun Mar 23 21:55:17 2008
@@ -0,0 +1,177 @@
+/* GObject introspectaion: public scanner api
+ *
+ * Copyright (C) 2007 JÃrg Billeter
+ * Copyright (C) 2008 Johan Dahlin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __SOURCE_SCANNER_H__
+#define __SOURCE_SCANNER_H__
+
+#include <glib.h>
+#include <stdio.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GISourceScanner GISourceScanner;
+typedef struct _GISourceSymbol GISourceSymbol;
+typedef struct _GISourceType GISourceType;
+typedef struct _GISourceDirective GISourceDirective;
+
+typedef enum
+{
+ CSYMBOL_TYPE_INVALID,
+ CSYMBOL_TYPE_CONST,
+ CSYMBOL_TYPE_OBJECT,
+ CSYMBOL_TYPE_FUNCTION,
+ CSYMBOL_TYPE_STRUCT,
+ CSYMBOL_TYPE_UNION,
+ CSYMBOL_TYPE_ENUM,
+ CSYMBOL_TYPE_TYPEDEF
+} GISourceSymbolType;
+
+typedef enum
+{
+ CTYPE_INVALID,
+ CTYPE_VOID,
+ CTYPE_BASIC_TYPE,
+ CTYPE_TYPEDEF,
+ CTYPE_STRUCT,
+ CTYPE_UNION,
+ CTYPE_ENUM,
+ CTYPE_POINTER,
+ CTYPE_ARRAY,
+ CTYPE_FUNCTION
+} GISourceTypeType;
+
+typedef enum
+{
+ STORAGE_CLASS_NONE = 0,
+ STORAGE_CLASS_TYPEDEF = 1 << 1,
+ STORAGE_CLASS_EXTERN = 1 << 2,
+ STORAGE_CLASS_STATIC = 1 << 3,
+ STORAGE_CLASS_AUTO = 1 << 4,
+ STORAGE_CLASS_REGISTER = 1 << 5
+} StorageClassSpecifier;
+
+typedef enum
+{
+ TYPE_QUALIFIER_NONE = 0,
+ TYPE_QUALIFIER_CONST = 1 << 1,
+ TYPE_QUALIFIER_RESTRICT = 1 << 2,
+ TYPE_QUALIFIER_VOLATILE = 1 << 3
+} TypeQualifier;
+
+typedef enum
+{
+ FUNCTION_NONE = 0,
+ FUNCTION_INLINE = 1 << 1
+} FunctionSpecifier;
+
+typedef enum
+{
+ UNARY_ADDRESS_OF,
+ UNARY_POINTER_INDIRECTION,
+ UNARY_PLUS,
+ UNARY_MINUS,
+ UNARY_BITWISE_COMPLEMENT,
+ UNARY_LOGICAL_NEGATION
+} UnaryOperator;
+
+struct _GISourceScanner
+{
+ char *current_filename;
+ gboolean macro_scan;
+ GSList *symbols;
+ GList *filenames;
+ GHashTable *directives_map;
+ GHashTable *typedef_table;
+ GHashTable *struct_or_union_or_enum_table;
+};
+
+struct _GISourceSymbol
+{
+ int ref_count;
+ GISourceSymbolType type;
+ int id;
+ char *ident;
+ GISourceType *base_type;
+ gboolean const_int_set;
+ int const_int;
+ char *const_string;
+ GSList *directives; /* list of GISourceDirective */
+};
+
+struct _GISourceType
+{
+ GISourceTypeType type;
+ StorageClassSpecifier storage_class_specifier;
+ TypeQualifier type_qualifier;
+ FunctionSpecifier function_specifier;
+ char *name;
+ GISourceType *base_type;
+ GList *child_list;
+};
+
+struct _GISourceDirective
+{
+ char *name;
+ char *value;
+ GSList *options;
+};
+
+GISourceScanner * gi_source_scanner_new (void);
+gboolean gi_source_scanner_lex_filename (GISourceScanner *igenerator,
+ const gchar *filename);
+gboolean gi_source_scanner_parse_file (GISourceScanner *igenerator,
+ FILE *file);
+GSList * gi_source_scanner_get_symbols (GISourceScanner *scanner);
+void gi_source_scanner_free (GISourceScanner *scanner);
+
+GISourceSymbol * gi_source_symbol_new (GISourceSymbolType type);
+gboolean gi_source_symbol_get_const_boolean (GISourceSymbol *symbol);
+GISourceSymbol * gi_source_symbol_ref (GISourceSymbol *symbol);
+void gi_source_symbol_unref (GISourceSymbol *symbol);
+
+GISourceDirective * gi_source_directive_new (const gchar *name,
+ const gchar *value,
+ GSList *options);
+void gi_source_directive_free (GISourceDirective *directive);
+
+/* Private */
+GISourceType * gi_source_array_new (void);
+void gi_source_scanner_add_symbol (GISourceScanner *scanner,
+ GISourceSymbol *symbol);
+gboolean gi_source_scanner_is_typedef (GISourceScanner *scanner,
+ const char *name);
+void gi_source_symbol_merge_type (GISourceSymbol *symbol,
+ GISourceType *type);
+GISourceType * gi_source_type_new (GISourceTypeType type);
+GISourceType * gi_source_type_copy (GISourceType *type);
+GISourceType * gi_source_basic_type_new (const char *name);
+GISourceType * gi_source_typedef_new (const char *name);
+GISourceType * gi_source_struct_new (const char *name);
+GISourceType * gi_source_union_new (const char *name);
+GISourceType * gi_source_enum_new (const char *name);
+GISourceType * gi_source_pointer_new (GISourceType *base_type);
+GISourceType * gi_source_array_new (void);
+GISourceType * gi_source_function_new (void);
+
+G_END_DECLS
+
+#endif /* __SOURCE_SCANNER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]