Revert revisions 157,149-148,136-129 and 120. Move back to using

2008-04-22  Johan Dahlin  <johan@gnome.org>

    * girepository/ginfo.c (g_info_from_entry), (g_type_info_new),
    (g_type_info_is_pointer), (g_type_info_get_tag),
    (g_type_info_get_param_type), (g_type_info_get_interface),
    (g_type_info_get_array_length), (g_type_info_is_zero_terminated),
    (g_type_info_get_n_error_domains), (g_type_info_get_error_domain),
    (g_error_domain_info_get_codes), (g_enum_info_get_value),
    (g_object_info_get_interface), (g_object_info_get_field),
    (g_interface_info_get_prerequisite),
    (g_signal_info_get_class_closure), (g_constant_info_get_value):
    * girepository/ginvoke.c (get_ffi_type):
    * girepository/girepository.h:
    * girepository/gmetadata.c (g_metadata_get_dir_entry),
    (g_metadata_check_sanity), (validate_header),
    (validate_array_type_blob), (validate_iface_type_blob),
    (validate_param_type_blob), (validate_error_type_blob),
    (validate_type_blob), (validate_constant_blob),
    (validate_struct_blob), (validate_enum_blob):
    * girepository/gmetadata.h:
    * tests/Makefile.am:
    * tests/invoke/Makefile.am:
    * tests/invoke/invoke.c (main):
    * tests/roundtrips.sh:
    * tools/Makefile.am:
    * tools/compiler.c (format_output), (write_out_metadata), (main):
    * tools/generate.c (write_type_name), (write_type_info),
    (write_constant_value), (write_enum_info), (load_metadata), (main):
    * tools/gidlcompilercontext.c:
    * tools/gidlcompilercontext.h:
    * tools/gidlcompilerentrynode.c:
    * tools/gidlcompilerentrynode.h:
    * tools/gidlcompilertypenode.c:
    * tools/gidlcompilertypenode.h:
    * tools/gidlmodule.c (g_idl_module_build_metadata):
    * tools/gidlmodule.h:
    * tools/gidlnode.c (init_stats), (dump_stats),
    (g_idl_node_get_size), (g_idl_node_get_full_size),
    (g_idl_node_cmp), (g_idl_node_can_have_member),
    (g_idl_node_add_member), (g_idl_node_param_direction_string),
    (parse_int_value), (parse_uint_value), (parse_float_value),
    (parse_boolean_value), (find_entry_node), (find_entry),
    (serialize_type), (g_idl_node_build_metadata), (write_string):
    * tools/gidlnode.h:
    * tools/gidlparser.c (parse_type_internal):
    * tools/quote-file.sh:
    Revert revisions 157,149-148,136-129 and 120.
    Move back to using g-idl-generate to generate the metadata and
    avoids dependency on a c compiler.


svn path=/trunk/; revision=214
This commit is contained in:
Johan Dahlin 2008-04-22 22:48:16 +00:00 committed by Evan Welsh
parent 3c6a7cd907
commit c0b53bde4d

View File

@ -28,146 +28,72 @@
#include "gidlnode.h" #include "gidlnode.h"
#include "gidlparser.h" #include "gidlparser.h"
#include "gmetadata.h" #include "gmetadata.h"
#include "gidlcompilercontext.h"
static GLogLevelFlags logged_levels; gboolean raw = FALSE;
gboolean no_init = FALSE;
gchar **input = NULL;
gchar *output = NULL;
gchar *mname = NULL;
gchar *shlib = NULL;
gboolean debug = FALSE;
gboolean verbose = FALSE;
static void log_handler (const gchar *log_domain, static gchar *
GLogLevelFlags log_level, format_output (GMetadata *metadata)
const gchar *message,
gpointer user_data)
{ {
GString *result;
gint i;
if (log_level & logged_levels) result = g_string_sized_new (6 * metadata->len);
g_log_default_handler (log_domain, log_level, message, user_data);
g_string_append_printf (result, "#include <stdlib.h>\n");
g_string_append_printf (result, "#include <girepository.h>\n\n");
g_string_append_printf (result, "const unsigned char _G_METADATA[] = \n{");
for (i = 0; i < metadata->len; i++)
{
if (i > 0)
g_string_append (result, ", ");
if (i % 10 == 0)
g_string_append (result, "\n\t");
g_string_append_printf (result, "0x%.2x", metadata->data[i]);
}
g_string_append_printf (result, "\n};\n\n");
g_string_append_printf (result, "const gsize _G_METADATA_SIZE = %u;\n\n",
(guint)metadata->len);
if (!no_init)
{
g_string_append_printf (result,
"__attribute__((constructor)) void\n"
"register_metadata (void)\n"
"{\n"
"\tGMetadata *metadata;\n"
"\tmetadata = g_metadata_new_from_const_memory (_G_METADATA, _G_METADATA_SIZE);\n"
"\tg_irepository_register (NULL, metadata);\n"
"}\n\n");
g_string_append_printf (result,
"__attribute__((destructor)) void\n"
"unregister_metadata (void)\n"
"{\n"
"\tg_irepository_unregister (NULL, \"%s\");\n"
"}\n",
g_metadata_get_namespace (metadata));
}
return g_string_free (result, FALSE);
} }
int static void
main (int argc, char ** argv) write_out_metadata (gchar *prefix,
GMetadata *metadata)
{ {
gboolean no_init = FALSE;
gchar **input = NULL;
gchar *output = NULL;
gchar *mname = NULL;
gchar *shlib = NULL;
gboolean debug = FALSE;
gboolean verbose = FALSE;
GOptionContext *context;
GError *error = NULL;
GList *m, *modules;
gint i;
GList *c;
gint entry_id;
FILE *file; FILE *file;
GIdlCompilerContext *ctx;
GOptionEntry options[] =
{
{ "no-init", 0, 0, G_OPTION_ARG_NONE, &no_init,
"do not create _init() function", NULL },
{ "output", 'o', 0, G_OPTION_ARG_FILENAME, &output,
"output file", "FILE" },
{ "module", 'm', 0, G_OPTION_ARG_STRING, &mname,
"module to compile", "NAME" },
{ "shared-library", 'l', 0, G_OPTION_ARG_FILENAME, &shlib,
"shared library", "FILE" },
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug,
"show debug messages", NULL },
{ "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose,
"show verbose messages", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input,
NULL, NULL },
{ NULL, }
};
context = g_option_context_new ("");
g_option_context_add_main_entries (context, options, NULL);
g_option_context_parse (context, &argc, &argv, &error);
g_option_context_free (context);
logged_levels = G_LOG_LEVEL_MASK & ~(G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_DEBUG);
if (debug)
logged_levels = logged_levels | G_LOG_LEVEL_DEBUG;
if (verbose)
logged_levels = logged_levels | G_LOG_LEVEL_MESSAGE;
g_log_set_default_handler (log_handler, NULL);
if (!input)
{
g_fprintf (stderr, "no input files\n");
return 1;
}
modules = NULL;
for (i = 0; input[i]; i++)
{
GList *mods;
mods = g_idl_parse_file (input[i], &error);
if (mods == NULL)
{
g_fprintf (stderr, "error parsing file %s: %s\n",
input[i], error->message);
return 1;
}
modules = g_list_concat (modules, mods);
}
for (m = modules; m; m = m->next)
{
GIdlModule *module = m->data;
gchar *prefix;
GError *err = NULL;
if (mname && strcmp (mname, module->name) != 0)
continue;
if (shlib)
{
if (module->shared_library)
g_free (module->shared_library);
module->shared_library = g_strdup (shlib);
}
if (!mname && (m->next || m->prev) && output)
prefix = module->name;
else
prefix = NULL;
ctx = g_idl_compiler_context_new (module->name, &err);
if (err != NULL)
{
g_fprintf (stderr, "Error creating new compiler context: %s",
err->message);
return 1;
}
/* This is making sure all the types
* that have local directory entries are already
* in the entries database.
*
* A method of finding out if an external reference is
* needed
*/
for (c = module->entries; c; c = c->next)
{
GIdlNode *node = (GIdlNode*) c->data;
g_idl_compiler_add_entry (ctx, node);
}
for (c = module->entries; c; c = c->next)
{
GIdlNode *node = (GIdlNode*) c->data;
entry_id = g_idl_compiler_get_entry_id (ctx, node->name);
g_idl_compiler_write_node (node, entry_id, ctx);
}
if (output == NULL) if (output == NULL)
file = stdout; file = stdout;
@ -193,9 +119,126 @@ main (int argc, char ** argv)
g_free (filename); g_free (filename);
} }
g_idl_compiler_context_finalize (ctx, file, module->shared_library, &err); if (raw)
fwrite (metadata->data, 1, metadata->len, file);
else
{
gchar *code;
g_idl_compiler_context_destroy (ctx); code = format_output (metadata);
fputs (code, file);
g_free (code);
}
if (output != NULL)
fclose (file);
}
GLogLevelFlags logged_levels;
static void log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
if (log_level & logged_levels)
g_log_default_handler (log_domain, log_level, message, user_data);
}
static GOptionEntry options[] =
{
{ "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "emit raw metadata", NULL },
{ "code", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &raw, "emit C code", NULL },
{ "no-init", 0, 0, G_OPTION_ARG_NONE, &no_init, "do not create _init() function", NULL },
{ "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" },
{ "module", 'm', 0, G_OPTION_ARG_STRING, &mname, "module to compile", "NAME" },
{ "shared-library", 'l', 0, G_OPTION_ARG_FILENAME, &shlib, "shared library", "FILE" },
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "show debug messages", NULL },
{ "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "show verbose messages", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL },
{ NULL, }
};
int
main (int argc, char ** argv)
{
GOptionContext *context;
GError *error = NULL;
GList *c, *m, *modules;
gint i;
g_metadata_check_sanity ();
context = g_option_context_new ("");
g_option_context_add_main_entries (context, options, NULL);
g_option_context_parse (context, &argc, &argv, &error);
g_option_context_free (context);
logged_levels = G_LOG_LEVEL_MASK & ~(G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_DEBUG);
if (debug)
logged_levels = logged_levels | G_LOG_LEVEL_DEBUG;
if (verbose)
logged_levels = logged_levels | G_LOG_LEVEL_MESSAGE;
g_log_set_default_handler (log_handler, NULL);
if (!input)
{
g_fprintf (stderr, "no input files\n");
return 1;
}
modules = NULL;
for (i = 0; input[i]; i++)
{
GList *mods;
mods = g_idl_parse_file (input[i], &error);
if (mods == NULL)
{
g_fprintf (stderr, "error parsing file %s: %s\n",
input[i], error->message);
return 1;
}
modules = g_list_concat (modules, mods);
}
for (m = modules; m; m = m->next)
{
GIdlModule *module = m->data;
gchar *prefix;
GMetadata *metadata;
if (mname && strcmp (mname, module->name) != 0)
continue;
if (shlib)
{
if (module->shared_library)
g_free (module->shared_library);
module->shared_library = g_strdup (shlib);
}
metadata = g_idl_module_build_metadata (module, modules);
if (metadata == NULL)
{
g_error ("Failed to build metadata for module '%s'\n", module->name);
continue;
}
if (!g_metadata_validate (metadata, &error))
g_error ("Invalid metadata for module '%s': %s",
module->name, error->message);
if (!mname && (m->next || m->prev) && output)
prefix = module->name;
else
prefix = NULL;
write_out_metadata (prefix, metadata);
g_metadata_free (metadata);
metadata = NULL;
/* when writing to stdout, stop after the first module */ /* when writing to stdout, stop after the first module */
if (m->next && !output && !mname) if (m->next && !output && !mname)