gobject-introspection r135 - trunk/tools
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: gobject-introspection r135 - trunk/tools
- Date: Mon, 10 Mar 2008 17:47:29 +0000 (GMT)
Author: johan
Date: Mon Mar 10 17:47:29 2008
New Revision: 135
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=135&view=rev
Log:
2008-02-22 Mark Doffman <mark doffman codethink co uk>
* tools/quote-file.sh
* tools/compiler.c
* tools/generate.c
Move to using the 'C' struct compiler code.
WARNING: This commit does not compile. It is a partial change.
Added:
trunk/tools/quote-file.sh (contents, props changed)
Modified:
trunk/tools/Makefile.am
trunk/tools/compiler.c
trunk/tools/generate.c
Modified: trunk/tools/Makefile.am
==============================================================================
--- trunk/tools/Makefile.am (original)
+++ trunk/tools/Makefile.am Mon Mar 10 17:47:29 2008
@@ -1,9 +1,12 @@
## Process this file with automake to produce Makefile.in
INCLUDES = -DGIREPO_DEFAULT_SEARCH_PATH="\"$(libdir)\""
-BUILT_SOURCES = scannerparser.c scannerparser.h scannerlexer.c scannerlexer.h
-CLEANFILES = scannerparser.c scannerparser.h scannerlexer.c scannerlexer.h
+BUILT_SOURCES = scannerparser.c scannerparser.h scannerlexer.c scannerlexer.h \
+ gmetadata-header.c
+
+CLEANFILES = scannerparser.c scannerparser.h scannerlexer.c scannerlexer.h gmetadata-header.c
AM_YFLAGS = -d
+EXTRA_DIST = quote-file.sh
# Why do I have to do this automake?
scannerlexer.h: scannerlexer.c
@@ -11,13 +14,24 @@
noinst_LTLIBRARIES = libgirepository-parser.la
bin_PROGRAMS = g-idl-compiler g-idl-generate g-idl-scanner
+gmetadata-header.c: $(top_srcdir)/girepository/gmetadata.h
+ $(srcdir)/quote-file.sh $^ $@
+
libgirepository_parser_la_SOURCES = \
gidlmodule.c \
gidlmodule.h \
gidlnode.c \
gidlnode.h \
gidlparser.c \
- gidlparser.h
+ gidlparser.h \
+ gidlcompilercontext.c \
+ gidlcompilercontext.h \
+ gidlcompilerentrynode.c \
+ gidlcompilerentrynode.h \
+ gidlcompilertypenode.c \
+ gidlcompilertypenode.h \
+ gmetadata-header.c
+
libgirepository_parser_la_CFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository
g_idl_compiler_SOURCES = compiler.c
Modified: trunk/tools/compiler.c
==============================================================================
--- trunk/tools/compiler.c (original)
+++ trunk/tools/compiler.c Mon Mar 10 17:47:29 2008
@@ -30,8 +30,8 @@
#include "gidlnode.h"
#include "gidlparser.h"
#include "gmetadata.h"
+#include "gidlcompilercontext.h"
-gboolean raw = FALSE;
gboolean no_init = FALSE;
gchar **input = NULL;
gchar *output = NULL;
@@ -40,102 +40,6 @@
gboolean debug = FALSE;
gboolean verbose = FALSE;
-static gchar *
-format_output (GMetadata *metadata)
-{
- GString *result;
- gint i;
-
- result = g_string_sized_new (6 * metadata->len);
-
- 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);
-}
-
-static void
-write_out_metadata (gchar *prefix,
- GMetadata *metadata)
-{
- FILE *file;
-
- if (output == NULL)
- file = stdout;
- else
- {
- gchar *filename;
-
- if (prefix)
- filename = g_strdup_printf ("%s-%s", prefix, output);
- else
- filename = g_strdup (output);
- file = g_fopen (filename, "w");
-
- if (file == NULL)
- {
- g_fprintf (stderr, "failed to open '%s': %s\n",
- filename, g_strerror (errno));
- g_free (filename);
-
- return;
- }
-
- g_free (filename);
- }
-
- if (raw)
- fwrite (metadata->data, 1, metadata->len, file);
- else
- {
- gchar *code;
-
- 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,
@@ -150,8 +54,6 @@
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" },
@@ -169,8 +71,11 @@
GError *error = NULL;
GList *m, *modules;
gint i;
+ GList *c;
+ gint entry_id;
- g_metadata_check_sanity ();
+ FILE *file;
+ GIdlCompilerContext *ctx;
context = g_option_context_new ("");
g_option_context_add_main_entries (context, options, NULL);
@@ -188,7 +93,6 @@
if (!input)
{
g_fprintf (stderr, "no input files\n");
-
return 1;
}
@@ -213,7 +117,8 @@
{
GIdlModule *module = m->data;
gchar *prefix;
- GMetadata *metadata;
+ GError *err = NULL;
+
if (mname && strcmp (mname, module->name) != 0)
continue;
@@ -223,26 +128,71 @@
g_free (module->shared_library);
module->shared_library = g_strdup (shlib);
}
- metadata = g_idl_module_build_metadata (module, modules);
- if (metadata == NULL)
+
+ 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_error ("Failed to build metadata for module '%s'\n", module->name);
+ g_fprintf (stderr, "Error creating new compiler context: %s",
+ err->message);
- continue;
+ return 1;
}
- if (!g_metadata_validate (metadata, &error))
- g_error ("Invalid metadata for module '%s': %s",
- module->name, error->message);
+ /* 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;
- if (!mname && (m->next || m->prev) && output)
- prefix = module->name;
+ entry_id = g_idl_compiler_get_entry_id(ctx, node->name);
+
+ g_idl_compiler_write_node(node, entry_id, ctx);
+ }
+
+ if (output == NULL)
+ file = stdout;
else
- prefix = NULL;
+ {
+ gchar *filename;
+
+ if (prefix)
+ filename = g_strdup_printf ("%s-%s", prefix, output);
+ else
+ filename = g_strdup (output);
+ file = g_fopen (filename, "w");
+
+ if (file == NULL)
+ {
+ g_fprintf (stderr, "failed to open '%s': %s\n",
+ filename, g_strerror (errno));
+ g_free (filename);
+
+ return;
+ }
+
+ g_free (filename);
+ }
+
+ g_idl_compiler_context_finalize(ctx, file, module->shared_library, &err);
- write_out_metadata (prefix, metadata);
- g_metadata_free (metadata);
- metadata = NULL;
+ g_idl_compiler_context_destroy(ctx);
/* when writing to stdout, stop after the first module */
if (m->next && !output && !mname)
Modified: trunk/tools/generate.c
==============================================================================
--- trunk/tools/generate.c (original)
+++ trunk/tools/generate.c Mon Mar 10 17:47:29 2008
@@ -1117,12 +1117,17 @@
GModule **dlhandle,
gsize *len)
{
- guchar *metadata;
+ gpointer metadata;
gsize *metadata_size;
GModule *handle;
- handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY);
- if (!g_module_symbol (handle, "_G_METADATA", (gpointer *) &metadata))
+ handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY);
+ if (!handle)
+ {
+ g_printerr("Could not load module '%s'\n", filename);
+ return NULL;
+ }
+ if (!g_module_symbol (handle, "_G_METADATA", &metadata))
{
g_printerr ("Could not load metadata from '%s': %s\n",
filename, g_module_error ());
@@ -1141,7 +1146,7 @@
if (dlhandle)
*dlhandle = handle;
- return metadata;
+ return *((const guchar **) metadata);
}
int
@@ -1169,7 +1174,7 @@
for (i = 0; input[i]; i++)
{
GModule *dlhandle = NULL;
- const guchar *metadata;
+ const guchar *metadata = NULL;
gsize len;
if (raw)
Added: trunk/tools/quote-file.sh
==============================================================================
--- (empty file)
+++ trunk/tools/quote-file.sh Mon Mar 10 17:47:29 2008
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+cat $1 | sed -e '1 i\const char gmetadata_header[] =\n' -e 's/\\/\\\\/g' -e 's/\"/\\\"/g' -e 's/.*/\"&\\n\"/' -e '$ a\;' > $2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]