[gircompiler] Clean up parsing

We never actually include multiple modules in the compiler,
so just nuke that.  Also rather than passing around GIrModule
consistently pass around a GIrTypelibBuild structure which
has various things.

This lets us maintain a stack there which we can walk for
better error messages.

Also, fix up the node lookup in giroffsets.c; previously
it didn't really handle includes correctly.  We really need to
switch to always using Foo.Bar (i.e. GIName) names internally...
This commit is contained in:
Colin Walters 2010-07-26 16:26:46 -04:00 committed by Evan Welsh
parent b2df59c315
commit 45a04358b6

View File

@ -140,7 +140,7 @@ main (int argc, char ** argv)
GOptionContext *context; GOptionContext *context;
GError *error = NULL; GError *error = NULL;
GIrParser *parser; GIrParser *parser;
GList *m, *modules; GIrModule *module;
gint i; gint i;
g_typelib_check_sanity (); g_typelib_check_sanity ();
@ -178,35 +178,22 @@ main (int argc, char ** argv)
g_ir_parser_set_includes (parser, (const char*const*) includedirs); g_ir_parser_set_includes (parser, (const char*const*) includedirs);
modules = NULL; module = g_ir_parser_parse_file (parser, input[0], &error);
for (i = 0; input[i]; i++) if (module == NULL)
{ {
GList *mods; g_fprintf (stderr, "error parsing file %s: %s\n",
mods = g_ir_parser_parse_file (parser, input[i], &error); input[0], error->message);
if (mods == NULL) return 1;
{
g_fprintf (stderr, "error parsing file %s: %s\n",
input[i], error->message);
return 1;
}
modules = g_list_concat (modules, mods);
} }
g_debug ("[parsing] done"); g_debug ("[parsing] done");
g_debug ("[building] start"); g_debug ("[building] start");
for (m = modules; m; m = m->next) {
{
GIrModule *module = m->data;
gchar *prefix;
GTypelib *typelib; GTypelib *typelib;
if (mname && strcmp (mname, module->name) != 0)
continue;
if (shlib) if (shlib)
{ {
if (module->shared_library) if (module->shared_library)
@ -216,33 +203,16 @@ main (int argc, char ** argv)
g_debug ("[building] module %s", module->name); g_debug ("[building] module %s", module->name);
typelib = g_ir_module_build_typelib (module, modules); typelib = g_ir_module_build_typelib (module);
if (typelib == NULL) if (typelib == NULL)
{ g_error ("Failed to build typelib for module '%s'\n", module->name);
g_error ("Failed to build typelib for module '%s'\n", module->name);
continue;
}
if (!g_typelib_validate (typelib, &error)) if (!g_typelib_validate (typelib, &error))
g_error ("Invalid typelib for module '%s': %s", g_error ("Invalid typelib for module '%s': %s",
module->name, error->message); module->name, error->message);
if (!mname && (m->next || m->prev) && output) write_out_typelib (NULL, typelib);
prefix = module->name;
else
prefix = NULL;
write_out_typelib (prefix, typelib);
g_typelib_free (typelib); g_typelib_free (typelib);
typelib = NULL; typelib = NULL;
/* when writing to stdout, stop after the first module */
if (m->next && !output && !mname)
{
g_warning ("%d modules omitted\n", g_list_length (modules) - 1);
break;
}
} }
g_debug ("[building] done"); g_debug ("[building] done");