From ae85bbecd4fde8fecf04334768741ece3293dc56 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 10 May 2010 12:35:46 -0400 Subject: Updates (Can't remember exactly what updates these are or even what the do. I'm just committing all local changes so I can push this to p.fd.o since right now the only copy in the world (due to the p.fd.o /home purge incident) is on my local hard disk.) --- src/Makefile.am | 17 ++ src/dbusidl.c | 578 ++++++++++++++++++++++++++------------------------- src/dbusidl.h | 57 ++--- src/dbusidlprivate.h | 60 +++--- src/didl2docbook.c | 185 ++++------------- src/didl2xml.c | 76 ++----- src/idl.h | 2 - src/idlparser.y | 36 +++- src/test.c | 27 ++- 9 files changed, 459 insertions(+), 579 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index c4c29ec..5901444 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -99,6 +99,23 @@ didl_to_xml_LDADD = \ # ---------------------------------------------------------------------------------------------------- +bin_PROGRAMS += didl-from-xml + +didl_from_xml_SOURCES = \ + didlfromxml.c \ + $(NULL) + +didl_from_xml_CFLAGS = \ + $(GLIB2_CFLAGS) \ + $(NULL) + +didl_from_xml_LDADD = \ + $(GLIB2_LIBS) \ + libdbus-idl-1.la \ + $(NULL) + +# ---------------------------------------------------------------------------------------------------- + clean-local: rm -f *~ libdbus_idl_1_la-* diff --git a/src/dbusidl.c b/src/dbusidl.c index e3ffad2..546f130 100644 --- a/src/dbusidl.c +++ b/src/dbusidl.c @@ -50,7 +50,6 @@ di_base_type_to_string (DIBaseType type) case DI_BASE_TYPE_ENUM: ret = "enum"; break; case DI_BASE_TYPE_ERROR_MEMBER: ret = "error_member"; break; case DI_BASE_TYPE_ERROR_DOMAIN: ret = "error_domain"; break; - case DI_BASE_TYPE_NAMESPACE: ret = "namespace"; break; default: g_assert_not_reached (); break; @@ -138,6 +137,76 @@ di_base_get_doc_brief (DIBase *base) return di_base_get_annotation_value (base, AN_DOC_BRIEF); } +DIBase * +di_base_get_parent (DIBase *base) +{ + return base->parent; +} + +const gchar * +di_base_get_namespace (DIBase *base) +{ + const gchar *name; + DIBase *i; + gchar *s; + + if (base->namespace != NULL) + goto out; + + i = base; + name = NULL; + while (name == NULL && i != NULL) + { + switch (i->type) + { + case DI_BASE_TYPE_INTERFACE: + name = ((DIInterface *) i)->name; + break; + + case DI_BASE_TYPE_STRUCT: + name = ((DIStruct *) i)->name; + break; + + case DI_BASE_TYPE_ENUM: + name = ((DIEnum *) i)->name; + break; + + case DI_BASE_TYPE_ERROR_DOMAIN: + name = ((DIErrorDomain *) i)->name; + break; + + default: + /* do nothing */ + break; + } + + i = i->parent; + } + + g_warn_if_fail (name != NULL); + + if (name != NULL) + { + base->namespace = g_strdup (name); + s = strrchr (base->namespace, '.'); + g_assert (s != NULL); + *s = '\0'; + } + + out: + g_debug ("namespace = '%s'", base->namespace); + return base->namespace; +} + +void +di_base_set_parent (DIBase *object, + DIBase *parent) +{ + g_warn_if_fail (object->parent == NULL); + object->parent = parent; +} + + /* ---------------------------------------------------------------------------------------------------- */ /* getters */ @@ -145,12 +214,15 @@ di_base_get_doc_brief (DIBase *base) const gchar * di_type_get_name (DIType *type) { - return type->fully_qualified_name != NULL ? type->fully_qualified_name : type->name; + return type->name; } const gchar * di_type_get_signature (DIType *type) { + g_debug ("name = %s -> %s", + type->name, + type->signature); return type->signature; } @@ -218,7 +290,7 @@ di_type_get_complete_signature (DIType *type) } else { - g_string_append_printf (s, "[%s]", type->fully_qualified_name); + g_string_append_printf (s, "[%s]", type->name); } out: @@ -267,12 +339,6 @@ di_method_get_name (DIMethod *method) return method->name; } -const gchar * -di_method_get_fully_qualified_name (DIMethod *method) -{ - return method->fully_qualified_name; -} - GList * di_method_get_args (DIMethod *method) { @@ -298,12 +364,6 @@ di_signal_get_name (DISignal *signal) return signal->name; } -const gchar * -di_signal_get_fully_qualified_name (DISignal *signal) -{ - return signal->fully_qualified_name; -} - GList * di_signal_get_args (DISignal *signal) { @@ -323,12 +383,6 @@ di_property_get_name (DIProperty *property) return property->name; } -const gchar * -di_property_get_fully_qualified_name (DIProperty *property) -{ - return property->fully_qualified_name; -} - DIType * di_property_get_type (DIProperty *property) { @@ -354,12 +408,6 @@ di_interface_get_name (DIInterface *interface) return interface->name; } -const gchar * -di_interface_get_fully_qualified_name (DIInterface *interface) -{ - return interface->fully_qualified_name; -} - GList * di_interface_get_methods (DIInterface *interface) { @@ -398,12 +446,6 @@ di_struct_get_name (DIStruct *struct_) return struct_->name; } -const gchar * -di_struct_get_fully_qualified_name (DIStruct *struct_) -{ - return struct_->fully_qualified_name; -} - GList * di_struct_get_members (DIStruct *struct_) { @@ -418,12 +460,6 @@ di_enum_member_get_name (DIEnumMember *enum_member) return enum_member->name; } -const gchar * -di_enum_member_get_fully_qualified_name (DIEnumMember *enum_member) -{ - return enum_member->fully_qualified_name; -} - guint di_enum_member_get_value (DIEnumMember *enum_member) { @@ -442,12 +478,6 @@ di_enum_get_name (DIEnum *enum_) return enum_->name; } -const gchar * -di_enum_get_fully_qualified_name (DIEnum *enum_) -{ - return enum_->fully_qualified_name; -} - GList * di_enum_get_members (DIEnum *enum_) { @@ -462,24 +492,12 @@ di_error_member_get_name (DIErrorMember *error_member) return error_member->name; } -const gchar * -di_error_member_get_fully_qualified_name (DIErrorMember *error_member) -{ - return error_member->fully_qualified_name; -} - const gchar * di_error_domain_get_name (DIErrorDomain *error_domain) { return error_domain->name; } -const gchar * -di_error_domain_get_fully_qualified_name (DIErrorDomain *error_domain) -{ - return error_domain->fully_qualified_name; -} - GList * di_error_domain_get_members (DIErrorDomain *error_domain) { @@ -488,34 +506,28 @@ di_error_domain_get_members (DIErrorDomain *error_domain) /* ---------------------------------------------------------------------------------------------------- */ -const gchar * -di_namespace_get_name (DINamespace *namespace) -{ - return namespace->name; -} - GList * -di_namespace_get_interfaces (DINamespace *namespace) +di_parser_get_interfaces (DIParser *parser) { - return namespace->interfaces; + return parser->interfaces; } GList * -di_namespace_get_structs (DINamespace *namespace) +di_parser_get_structs (DIParser *parser) { - return namespace->structs; + return parser->structs; } GList * -di_namespace_get_enums (DINamespace *namespace) +di_parser_get_enums (DIParser *parser) { - return namespace->enums; + return parser->enums; } GList * -di_namespace_get_error_domains (DINamespace *namespace) +di_parser_get_error_domains (DIParser *parser) { - return namespace->error_domains; + return parser->error_domains; } /* ---------------------------------------------------------------------------------------------------- */ @@ -538,101 +550,6 @@ di_comment_get_base (DIComment *comment) return comment->link; } - -const gchar * -di_comment_get_symbol (DIComment *comment) -{ - const gchar *ret; - - ret = NULL; - - if (comment->link == NULL) - goto out; - - switch (di_base_get_type (comment->link)) - { - case DI_BASE_TYPE_METHOD: - ret = di_method_get_name ((DIMethod *) comment->link); - break; - case DI_BASE_TYPE_SIGNAL: - ret = di_signal_get_name ((DISignal *) comment->link); - break; - case DI_BASE_TYPE_PROPERTY: - ret = di_property_get_name ((DIProperty *) comment->link); - break; - case DI_BASE_TYPE_INTERFACE: - ret = di_interface_get_name ((DIInterface *) comment->link); - break; - case DI_BASE_TYPE_STRUCT: - ret = di_struct_get_name ((DIStruct *) comment->link); - break; - case DI_BASE_TYPE_ENUM: - ret = di_enum_get_name ((DIEnum *) comment->link); - break; - case DI_BASE_TYPE_ERROR_DOMAIN: - ret = di_error_domain_get_name ((DIErrorDomain *) comment->link); - break; - case DI_BASE_TYPE_NAMESPACE: - ret = di_namespace_get_name ((DINamespace *) comment->link); - break; - - default: - g_warning ("Cannot use gtkdoc-style comment on base %s", - di_base_type_to_string (comment->link->type)); - break; - } - - out: - return ret; -} - -const gchar * -di_comment_get_fully_qualified_symbol (DIComment *comment) -{ - const gchar *ret; - - ret = NULL; - - if (comment->link == NULL) - goto out; - - switch (di_base_get_type (comment->link)) - { - case DI_BASE_TYPE_METHOD: - ret = di_method_get_fully_qualified_name ((DIMethod *) comment->link); - break; - case DI_BASE_TYPE_SIGNAL: - ret = di_signal_get_fully_qualified_name ((DISignal *) comment->link); - break; - case DI_BASE_TYPE_PROPERTY: - ret = di_property_get_fully_qualified_name ((DIProperty *) comment->link); - break; - case DI_BASE_TYPE_INTERFACE: - ret = di_interface_get_fully_qualified_name ((DIInterface *) comment->link); - break; - case DI_BASE_TYPE_STRUCT: - ret = di_struct_get_fully_qualified_name ((DIStruct *) comment->link); - break; - case DI_BASE_TYPE_ENUM: - ret = di_enum_get_fully_qualified_name ((DIEnum *) comment->link); - break; - case DI_BASE_TYPE_ERROR_DOMAIN: - ret = di_error_domain_get_fully_qualified_name ((DIErrorDomain *) comment->link); - break; - case DI_BASE_TYPE_NAMESPACE: - ret = di_namespace_get_name ((DINamespace *) comment->link); - break; - - default: - g_warning ("Cannot use gtkdoc-style comment on base %s", - di_base_type_to_string (comment->link->type)); - break; - } - - out: - return ret; -} - const gchar * di_comment_get_text (DIComment *comment) { @@ -721,11 +638,6 @@ di_error_domain_free (DIErrorDomain *error_domain) { } -void -di_namespace_free (DINamespace *namespace) -{ -} - void di_comment_free (DIComment *comment) { @@ -970,30 +882,6 @@ di_error_domain_new (gchar *decl_filename, return ret; } -DINamespace * -di_namespace_new (gchar *decl_filename, - guint decl_lineno, - gchar *name, - GList *interfaces, - GList *structs, - GList *enums, - GList *error_domains, - GList *annotations) -{ - DINamespace *ret; - ret = g_new0 (DINamespace, 1); - ret->base.type = DI_BASE_TYPE_NAMESPACE; - ret->base.decl_filename = decl_filename; - ret->base.decl_lineno = decl_lineno; - ret->name = name; - ret->interfaces = interfaces; - ret->structs = structs; - ret->enums = enums; - ret->error_domains = error_domains; - ret->base.annotations = annotations; - return ret; -} - DIComment * di_comment_new (gchar *decl_filename, guint decl_lineno, @@ -1116,7 +1004,7 @@ void di_type_print (DIType *type, guint indent) { g_print ("%*s%s", indent, "", - type->fully_qualified_name != NULL ? type->fully_qualified_name : type->name); + type->name); if (type->inner_types != NULL) { GList *l; @@ -1330,25 +1218,6 @@ di_error_domain_print (DIErrorDomain *error_domain, guint indent) g_print ("%*s};\n", indent, ""); } -void -di_namespace_print (DINamespace *namespace, guint indent) -{ - GList *l; - - di_base_print_annotations ((DIBase *) namespace, indent); - g_print ("%*snamespace %s {\n", indent, "", namespace->name); - for (l = namespace->structs; l != NULL; l = l->next) - di_struct_print (l->data, indent + 2); - for (l = namespace->enums; l != NULL; l = l->next) - di_enum_print (l->data, indent + 2); - for (l = namespace->error_domains; l != NULL; l = l->next) - di_error_domain_print (l->data, indent + 2); - for (l = namespace->interfaces; l != NULL; l = l->next) - di_interface_print (l->data, indent + 2); - g_print ("%*s};\n", indent, ""); -} - - /* ---------------------------------------------------------------------------------------------------- */ static void ensure_method (DIParser *parser, @@ -1400,6 +1269,72 @@ ensure_signal (DIParser *parser, /* ---------------------------------------------------------------------------------------------------- */ +void di_parser_add (DIParser *parser, + DIBase *object) +{ + DIBase *base; + const gchar *name; + + name = NULL; + + switch (object->type) + { + case DI_BASE_TYPE_INTERFACE: + parser->interfaces = g_list_append (parser->interfaces, object); + name = di_interface_get_name ((DIInterface *) object); + break; + + case DI_BASE_TYPE_STRUCT: + parser->structs = g_list_append (parser->structs, object); + name = di_struct_get_name ((DIStruct *) object); + break; + + case DI_BASE_TYPE_ENUM: + parser->enums = g_list_append (parser->enums, object); + name = di_enum_get_name ((DIEnum *) object); + break; + + case DI_BASE_TYPE_ERROR_DOMAIN: + parser->error_domains = g_list_append (parser->error_domains, object); + name = di_error_domain_get_name ((DIErrorDomain *) object); + break; + + default: + case DI_BASE_TYPE_COMMENT: + g_assert_not_reached (); + break; + } + + if (name != NULL) + { + base = (DIBase *) g_hash_table_lookup (parser->symbol_table, name); + if (base != NULL) + { + parser->errors = g_list_append (parser->errors, + g_strdup_printf ("%s:%d: error: name %s for %s is already in use", + object->decl_filename, + object->decl_lineno, + name, + di_base_type_to_string (object->type))); + parser->errors = g_list_append (parser->errors, + g_strdup_printf ("%s:%d: error: name %s previously declared as a %s", + base->decl_filename, + base->decl_lineno, + name, + di_base_type_to_string (base->type))); + goto out; + } + + g_hash_table_insert (parser->symbol_table, + (gpointer) name, + object); + } + + out: + ; +} + +#if 0 static gboolean insert_and_check (DIParser *parser, DIBase *symbol, @@ -1437,9 +1372,11 @@ insert_and_check (DIParser *parser, out: return ret; } +#endif /* ---------------------------------------------------------------------------------------------------- */ +#if 0 static void type_compute_fully_qualified_name (DIParser *parser, DIType *type, @@ -1485,15 +1422,16 @@ type_compute_fully_qualified_name (DIParser *parser, type->name); } } +#endif /* ---------------------------------------------------------------------------------------------------- */ +#if 0 static void build_symbol_table (DIParser *parser) { GList *l, *ll, *lll, *llll; - parser->symbol_table = g_hash_table_new (g_str_hash, g_str_equal); /* for all namespaces */ for (l = parser->namespaces; l != NULL; l = l->next) { @@ -1627,10 +1565,11 @@ build_symbol_table (DIParser *parser) } } /* for all namespaces */ } +#endif /* ---------------------------------------------------------------------------------------------------- */ -DIBase * +static DIBase * di_parser_lookup_symbol (DIParser *parser, const gchar *fully_qualified_name) { @@ -1701,14 +1640,46 @@ visit_type (DIParser *parser, DIBase *base; /* can either reference a struct or an enum */ - base = di_parser_lookup_symbol (parser, type->fully_qualified_name); + base = di_parser_lookup_symbol (parser, type->name); + if (base == NULL) + { + /* if the name doesn't contain a dot, prefix with the namespace - this is to allow + * e.g. + * + * namespace com.example { + * struct S1 { + * int32 foo; + * int32 baz; + * }; + * + * interface Bar { + * Frob (S1 a_struct); + * }; + * }; + * + * e.g. S1 in the Frob() method really means com.example.S1. + */ + if (strstr (type->name, ".") == NULL) + { + gchar *t; + t = type->name; + type->name = g_strconcat (di_base_get_namespace (referenced_in), + ".", + type->name, + NULL); + g_free (t); + } + + base = di_parser_lookup_symbol (parser, type->name); + } + if (base == NULL) { parser->errors = g_list_append (parser->errors, g_strdup_printf ("%s:%d: error: cannot resolve type %s", referenced_in->decl_filename, referenced_in->decl_lineno, - type->fully_qualified_name)); + type->name)); } else if (base->type == DI_BASE_TYPE_STRUCT) { @@ -1748,18 +1719,17 @@ visit_type (DIParser *parser, "but got a %s", referenced_in->decl_filename, referenced_in->decl_lineno, - type->fully_qualified_name, + type->name, di_base_type_to_string (base->type))); } } type->signature = g_string_free (s, FALSE); + #if 0 - g_debug ("signature %s for %s %s %s", + g_debug ("signature %s for %s", type->signature, - type->name, - di_base_type_to_string (referenced_in->type), - referenced_in->fully_qualified_name); + di_base_type_to_string (referenced_in->type)); #endif } @@ -1980,7 +1950,6 @@ inject_gtkdoc_style_comments (DIParser *parser) case DI_BASE_TYPE_PROPERTY: case DI_BASE_TYPE_INTERFACE: - case DI_BASE_TYPE_NAMESPACE: /* do nothing */ break; @@ -2152,26 +2121,59 @@ check_doc_references (DIParser *parser) /* ---------------------------------------------------------------------------------------------------- */ DIParser * -di_parser_new (const gchar *path) +di_parser_new (gchar **files) { DIParser *parser; gchar *s; + guint n; + + g_return_val_if_fail (files != NULL, NULL); parser = g_new0 (DIParser, 1); + parser->symbol_table = g_hash_table_new (g_str_hash, g_str_equal); - yyin = fopen (path, "rt"); - if (yyin == NULL) + for (n = 0; files[n] != NULL; n++) { - s = g_strdup_printf ("Error opening file %s: %m", path); - parser->errors = g_list_append (parser->errors, s); - goto out; - } + const gchar *path = files[n]; + + if (g_str_has_suffix (path, ".xml")) + { + gchar *xml_data; + GError *error; + + error = NULL; + if (!g_file_get_contents (path, &xml_data, NULL, &error)) + { + s = g_strdup_printf ("Error opening file %s: %s", path, error->message); + parser->errors = g_list_append (parser->errors, s); + g_error_free (error); + goto out; + } + + //parse_xml (parser, path) + + g_free (xml_data); + } + else if (g_str_has_suffix (path, ".didl")) + { + yyin = fopen (path, "rt"); + if (yyin == NULL) + { + s = g_strdup_printf ("Error opening file %s: %m", path); + parser->errors = g_list_append (parser->errors, s); + goto out; + } - parser->path_to_current_file = g_strdup (path); + parser->path_to_current_file = g_strdup (path); - /* this covers lexical and syntactical analysis */ - yyparse (parser); - fclose (yyin); + /* this covers lexical and syntactical analysis */ + yyparse (parser); + fclose (yyin); + } + + g_free (parser->path_to_current_file); + parser->path_to_current_file = NULL; + } /* bail if we have errors at this point */ if (parser->errors != NULL) @@ -2182,7 +2184,6 @@ di_parser_new (const gchar *path) /* First build the symbol table - this is basically a mapping from the fully * qualified name into a DIBase pointer. It contain the following objects * - * o namespaces * o interfaces * - methods * - signals @@ -2200,7 +2201,7 @@ di_parser_new (const gchar *path) * While doing this, also compute fully-qualified names and output errors * if there are collisions. */ - build_symbol_table (parser); + //build_symbol_table (parser); /* bail if we have errors at this point */ if (parser->errors != NULL) @@ -2225,33 +2226,12 @@ di_parser_new (const gchar *path) return parser; } -GList * -di_parser_get_namespaces (DIParser *parser) -{ - return parser->namespaces; -} - GList * di_parser_get_comments (DIParser *parser) { return parser->comments; } -DIComment * -di_parser_lookup_comment_for_symbol (DIParser *parser, - const gchar *fully_qualified_name) -{ - GList *l; - for (l = parser->comments; l != NULL; l = l->next) - { - DIComment *comment = l->data; - - if (g_strcmp0 (di_comment_get_fully_qualified_symbol (comment), fully_qualified_name) == 0) - return comment; - } - return NULL; -} - GList * di_parser_get_warnings (DIParser *parser) { @@ -2272,28 +2252,12 @@ di_parser_free (DIParser *parser) /* ---------------------------------------------------------------------------------------------------- */ -DINamespace * -di_parser_lookup_namespace (DIParser *parser, - const gchar *name) -{ - GList *l; - for (l = parser->namespaces; l != NULL; l = l->next) - { - DINamespace *i = l->data; - if (g_strcmp0 (i->name, name) == 0) - return i; - } - return NULL; -} - -/* ---------------------------------------------------------------------------------------------------- */ - DIInterface * -di_namespace_lookup_interface (DINamespace *namespace, - const gchar *name) +di_parser_lookup_interface (DIParser *parser, + const gchar *name) { GList *l; - for (l = namespace->interfaces; l != NULL; l = l->next) + for (l = parser->interfaces; l != NULL; l = l->next) { DIInterface *interface = l->data; if (g_strcmp0 (interface->name, name) == 0) @@ -2303,11 +2267,11 @@ di_namespace_lookup_interface (DINamespace *namespace, } DIStruct * -di_namespace_lookup_struct (DINamespace *namespace, - const gchar *name) +di_parser_lookup_struct (DIParser *parser, + const gchar *name) { GList *l; - for (l = namespace->structs; l != NULL; l = l->next) + for (l = parser->structs; l != NULL; l = l->next) { DIStruct *struct_ = l->data; if (g_strcmp0 (struct_->name, name) == 0) @@ -2317,11 +2281,11 @@ di_namespace_lookup_struct (DINamespace *namespace, } DIEnum * -di_namespace_lookup_enum (DINamespace *namespace, - const gchar *name) +di_parser_lookup_enum (DIParser *parser, + const gchar *name) { GList *l; - for (l = namespace->enums; l != NULL; l = l->next) + for (l = parser->enums; l != NULL; l = l->next) { DIEnum *enum_ = l->data; if (g_strcmp0 (enum_->name, name) == 0) @@ -2331,11 +2295,11 @@ di_namespace_lookup_enum (DINamespace *namespace, } DIErrorDomain * -di_namespace_lookup_error_domain (DINamespace *namespace, - const gchar *name) +di_parser_lookup_error_domain (DIParser *parser, + const gchar *name) { GList *l; - for (l = namespace->error_domains; l != NULL; l = l->next) + for (l = parser->error_domains; l != NULL; l = l->next) { DIErrorDomain *error_domain = l->data; if (g_strcmp0 (error_domain->name, name) == 0) @@ -2390,3 +2354,43 @@ di_interface_lookup_property (DIInterface *interface, } /* ---------------------------------------------------------------------------------------------------- */ + +void +di_interface_add_prefix (DIInterface *interface, + const gchar *prefix) +{ + gchar *s; + s = interface->name; + interface->name = g_strconcat (prefix, ".", s, NULL); + g_free (s); +} + +void +di_struct_add_prefix (DIStruct *struct_, + const gchar *prefix) +{ + gchar *s; + s = struct_->name; + struct_->name = g_strconcat (prefix, ".", s, NULL); + g_free (s); +} + +void +di_enum_add_prefix (DIEnum *enum_, + const gchar *prefix) +{ + gchar *s; + s = enum_->name; + enum_->name = g_strconcat (prefix, ".", s, NULL); + g_free (s); +} + +void +di_error_domain_add_prefix (DIErrorDomain *error_domain, + const gchar *prefix) +{ + gchar *s; + s = error_domain->name; + error_domain->name = g_strconcat (prefix, ".", s, NULL); + g_free (s); +} diff --git a/src/dbusidl.h b/src/dbusidl.h index 1e95bea..8897510 100644 --- a/src/dbusidl.h +++ b/src/dbusidl.h @@ -44,7 +44,6 @@ typedef enum DI_BASE_TYPE_ENUM, DI_BASE_TYPE_ERROR_MEMBER, DI_BASE_TYPE_ERROR_DOMAIN, - DI_BASE_TYPE_NAMESPACE, DI_BASE_TYPE_COMMENT, } DIBaseType; @@ -83,7 +82,6 @@ typedef struct _DIEnumMember DIEnumMember; typedef struct _DIEnum DIEnum; typedef struct _DIErrorMember DIErrorMember; typedef struct _DIErrorDomain DIErrorDomain; -typedef struct _DINamespace DINamespace; typedef struct _DIComment DIComment; /* ---------------------------------------------------------------------------------------------------- */ @@ -103,6 +101,8 @@ DIAnnotation *di_base_get_annotation (DIBase *base, const gchar *name); const gchar *di_base_get_annotation_value (DIBase *base, const gchar *name); +DIBase *di_base_get_parent (DIBase *base); +const gchar *di_base_get_namespace (DIBase *base); /* ---------------------------------------------------------------------------------------------------- */ @@ -121,7 +121,6 @@ DIArgDirection di_arg_get_direction (DIArg *arg); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_method_get_name (DIMethod *method); -const gchar *di_method_get_fully_qualified_name (DIMethod *method); GList *di_method_get_args (DIMethod *method); const gchar *di_method_get_in_signature (DIMethod *method); const gchar *di_method_get_out_signature (DIMethod *method); @@ -129,14 +128,12 @@ const gchar *di_method_get_out_signature (DIMethod *method); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_signal_get_name (DISignal *signal); -const gchar *di_signal_get_fully_qualified_name (DISignal *signal); GList *di_signal_get_args (DISignal *signal); const gchar *di_signal_get_signature (DISignal *signal); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_property_get_name (DIProperty *property); -const gchar *di_property_get_fully_qualified_name (DIProperty *property); DIType *di_property_get_type (DIProperty *property); const gchar *di_property_get_signature (DIProperty *property); DIPropertyFlags di_property_get_flags (DIProperty *property); @@ -144,7 +141,6 @@ DIPropertyFlags di_property_get_flags (DIProperty *property); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_interface_get_name (DIInterface *interface); -const gchar *di_interface_get_fully_qualified_name (DIInterface *interface); GList *di_interface_get_methods (DIInterface *interface); GList *di_interface_get_signals (DIInterface *interface); GList *di_interface_get_properties (DIInterface *interface); @@ -163,55 +159,32 @@ DIType *di_struct_member_get_type (DIStructMember *struct_member); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_struct_get_name (DIStruct *struct_); -const gchar *di_struct_get_fully_qualified_name (DIStruct *struct_); GList *di_struct_get_members (DIStruct *struct_); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_enum_member_get_name (DIEnumMember *enum_member); -const gchar *di_enum_member_get_fully_qualified_name (DIEnumMember *enum_member); guint di_enum_member_get_value (DIEnumMember *enum_member); gboolean di_enum_member_get_unset (DIEnumMember *enum_member); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_enum_get_name (DIEnum *enum_); -const gchar *di_enum_get_fully_qualified_name (DIEnum *enum_); GList *di_enum_get_members (DIEnum *enum_); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_error_member_get_name (DIErrorMember *error_member); -const gchar *di_error_member_get_fully_qualified_name (DIErrorMember *error_member); /* ---------------------------------------------------------------------------------------------------- */ const gchar *di_error_domain_get_name (DIErrorDomain *error_domain); -const gchar *di_error_domain_get_fully_qualified_name (DIErrorDomain *error_domain); GList *di_error_domain_get_members (DIErrorDomain *error_domain); /* ---------------------------------------------------------------------------------------------------- */ -const gchar *di_namespace_get_name (DINamespace *namespace); -GList *di_namespace_get_interfaces (DINamespace *namespace); -GList *di_namespace_get_structs (DINamespace *namespace); -GList *di_namespace_get_enums (DINamespace *namespace); -GList *di_namespace_get_error_domains (DINamespace *namespace); -DIInterface *di_namespace_lookup_interface (DINamespace *namespace, - const gchar *name); -DIStruct *di_namespace_lookup_struct (DINamespace *namespace, - const gchar *name); -DIEnum *di_namespace_lookup_enum (DINamespace *namespace, - const gchar *name); -DIErrorDomain *di_namespace_lookup_error_domain (DINamespace *namespace, - const gchar *name); - -/* ---------------------------------------------------------------------------------------------------- */ - const gchar *di_comment_get_raw (DIComment *comment); gboolean di_comment_get_is_multiline (DIComment *comment); -const gchar *di_comment_get_symbol (DIComment *comment); -const gchar *di_comment_get_fully_qualified_symbol (DIComment *comment); DIBase *di_comment_get_base (DIComment *comment); const gchar *di_comment_get_brief (DIComment *comment); const gchar *di_comment_get_text (DIComment *comment); @@ -221,21 +194,31 @@ const gchar *di_comment_get_tag_value (DIComment *comment, /* ---------------------------------------------------------------------------------------------------- */ -DIParser *di_parser_new (const gchar *path); -GList *di_parser_get_namespaces (DIParser *parser); -GList *di_parser_get_comments (DIParser *parser); -DINamespace *di_parser_lookup_namespace (DIParser *parser, +DIParser *di_parser_new (gchar **files); +GList *di_parser_get_interfaces (DIParser *parser); +GList *di_parser_get_structs (DIParser *parser); +GList *di_parser_get_enums (DIParser *parser); +GList *di_parser_get_error_domains (DIParser *parser); +DIInterface *di_parser_lookup_interface (DIParser *parser, + const gchar *name); +DIStruct *di_parser_lookup_struct (DIParser *parser, const gchar *name); -DIBase *di_parser_lookup_symbol (DIParser *parser, - const gchar *fully_qualified_name); -DIComment *di_parser_lookup_comment_for_symbol (DIParser *parser, - const gchar *fully_qualified_name); +DIEnum *di_parser_lookup_enum (DIParser *parser, + const gchar *name); +DIErrorDomain *di_parser_lookup_error_domain (DIParser *parser, + const gchar *name); +GList *di_parser_get_comments (DIParser *parser); GList *di_parser_get_warnings (DIParser *parser); GList *di_parser_get_errors (DIParser *parser); void di_parser_free (DIParser *parser); /* ---------------------------------------------------------------------------------------------------- */ +void di_interface_print (DIInterface *interface, guint indent); +void di_struct_print (DIStruct *struct_, guint indent); +void di_enum_print (DIEnum *enum_, guint indent); +void di_error_domain_print (DIErrorDomain *error_domain, guint indent); + G_END_DECLS #endif /* __DBUS_IDL_H */ diff --git a/src/dbusidlprivate.h b/src/dbusidlprivate.h index 9649d4f..9a58ea5 100644 --- a/src/dbusidlprivate.h +++ b/src/dbusidlprivate.h @@ -31,6 +31,8 @@ struct _DIBase gchar *decl_filename; guint decl_lineno; GList *annotations; + DIBase *parent; + gchar *namespace; }; struct _DIAnnotation @@ -49,9 +51,6 @@ struct _DIType gchar *signature; gchar *complete_signature; - - /* only set if type is a user supplied type */ - gchar *fully_qualified_name; }; struct _DIArg @@ -66,7 +65,6 @@ struct _DIMethod { DIBase base; gchar *name; - gchar *fully_qualified_name; GList *args; gchar *in_signature; @@ -77,7 +75,6 @@ struct _DISignal { DIBase base; gchar *name; - gchar *fully_qualified_name; GList *args; gchar *signature; @@ -87,7 +84,6 @@ struct _DIProperty { DIBase base; gchar *name; - gchar *fully_qualified_name; DIType *type; DIPropertyFlags flags; @@ -98,7 +94,6 @@ struct _DIInterface { DIBase base; gchar *name; - gchar *fully_qualified_name; GList *methods; GList *signals; GList *properties; @@ -115,7 +110,6 @@ struct _DIStruct { DIBase base; gchar *name; - gchar *fully_qualified_name; GList *members; gchar *signature; @@ -125,7 +119,6 @@ struct _DIEnumMember { DIBase base; gchar *name; - gchar *fully_qualified_name; guint32 value; gboolean unset; }; @@ -134,7 +127,6 @@ struct _DIEnum { DIBase base; gchar *name; - gchar *fully_qualified_name; GList *members; }; @@ -142,27 +134,15 @@ struct _DIErrorMember { DIBase base; gchar *name; - gchar *fully_qualified_name; }; struct _DIErrorDomain { DIBase base; gchar *name; - gchar *fully_qualified_name; GList *members; }; -struct _DINamespace -{ - DIBase base; - gchar *name; - GList *interfaces; - GList *structs; - GList *enums; - GList *error_domains; -}; - struct _DIComment { DIBase base; @@ -179,10 +159,15 @@ struct _DIComment struct _DIParser { gchar *path_to_current_file; - GList *namespaces; - GList *warnings; - GList *errors; - GList *comments; + + GList *interfaces; + GList *structs; + GList *enums; + GList *error_domains; + + GList *warnings; + GList *errors; + GList *comments; /* hash from fully-qualified name to DIBase* */ GHashTable *symbol_table; @@ -257,14 +242,6 @@ DIErrorDomain *di_error_domain_new (gchar *decl_filename, gchar *name, GList *members, GList *annotations); -DINamespace *di_namespace_new (gchar *decl_filename, - guint decl_lineno, - gchar *name, - GList *interfaces, - GList *structs, - GList *enums, - GList *error_domains, - GList *annotations); DIComment *di_comment_new (gchar *decl_filename, guint decl_lineno, gboolean is_multiline, @@ -289,11 +266,23 @@ void di_enum_member_free (DIEnumMember *enum_member); void di_enum_free (DIEnum *enum_); void di_error_member_free (DIErrorMember *error_member); void di_error_domain_free (DIErrorDomain *error_domain); -void di_namespace_free (DINamespace *namespace); void di_comment_free (DIComment *comment); /* ---------------------------------------------------------------------------------------------------- */ +void di_base_set_parent (DIBase *object, + DIBase *parent); + +void di_parser_add (DIParser *parser, + DIBase *object); + +void di_interface_add_prefix (DIInterface *interface, const gchar *prefix); +void di_struct_add_prefix (DIStruct *struct_, const gchar *prefix); +void di_enum_add_prefix (DIEnum *enum_, const gchar *prefix); +void di_error_domain_add_prefix (DIErrorDomain *error_domain, const gchar *prefix); + +/* ---------------------------------------------------------------------------------------------------- */ + void di_annotation_print (DIAnnotation *annotation, guint indent); void di_type_print (DIType *type, guint indent); void di_arg_print (DIArg *arg, guint indent); @@ -307,7 +296,6 @@ void di_enum_member_print (DIEnumMember *enum_member, guint indent); void di_enum_print (DIEnum *enum_, guint indent); void di_error_member_print (DIErrorMember *error_member, guint indent); void di_error_domain_print (DIErrorDomain *error_domain, guint indent); -void di_namespace_print (DINamespace *namespace, guint indent); void di_comment_print (DIComment *comment, guint indent); /* ---------------------------------------------------------------------------------------------------- */ diff --git a/src/didl2docbook.c b/src/didl2docbook.c index 3d531b5..9f26a82 100644 --- a/src/didl2docbook.c +++ b/src/didl2docbook.c @@ -26,40 +26,15 @@ static gchar **opt_input_files; static gchar *opt_output_dir; -static gchar **opt_namespaces; static GOptionEntry entries[] = { { "idl", 'i', 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_input_files, "IDL files (may be used several times)", NULL }, { "output", 'o', 0, G_OPTION_ARG_FILENAME, &opt_output_dir, "Directory for output", NULL }, - { "namespaces", 'n', 0, G_OPTION_ARG_STRING_ARRAY, &opt_namespaces, "Namespaces to consider (may be used several times)", NULL }, { NULL } }; /* ---------------------------------------------------------------------------------------------------- */ -static gboolean -check_ignore_namespace (DINamespace *namespace, - gchar **namespaces_to_consider) -{ - guint n; - gboolean ret; - - ret = FALSE; - - for (n = 0; namespaces_to_consider[n] != NULL; n++) - { - if (g_strcmp0 (di_namespace_get_name (namespace), namespaces_to_consider[n]) == 0) - goto out; - } - - ret = TRUE; - - out: - return ret; -} - -/* ---------------------------------------------------------------------------------------------------- */ - static void print_type (DIType *type, GString *s, @@ -365,9 +340,9 @@ print_interface (DIInterface *iface, " Interface %s\n" " %s\n" " \n", - di_interface_get_fully_qualified_name (iface), - di_interface_get_fully_qualified_name (iface), - di_interface_get_fully_qualified_name (iface), + di_interface_get_name (iface), + di_interface_get_name (iface), + di_interface_get_name (iface), get_doc (iface, TRUE)); /* Synopsis for methods */ @@ -502,7 +477,7 @@ print_interface (DIInterface *iface, g_string_append_printf (s, " \n" " %s ()\n", - di_method_get_fully_qualified_name (method), + di_method_get_name (method), di_method_get_name (method)); g_string_append_printf (s, " \n"); @@ -539,7 +514,7 @@ print_interface (DIInterface *iface, g_string_append_printf (s, " \n" " %s ()\n", - di_signal_get_fully_qualified_name (signal), + di_signal_get_name (signal), di_signal_get_name (signal)); g_string_append_printf (s, " \n"); @@ -575,7 +550,7 @@ print_interface (DIInterface *iface, g_string_append_printf (s, " \n" " %s ()\n", - di_property_get_fully_qualified_name (property), + di_property_get_name (property), di_property_get_name (property)); g_string_append_printf (s, " \n"); @@ -686,14 +661,14 @@ print_struct (DIStruct *struct_, " Struct %s\n" " %s\n" " \n", - di_struct_get_fully_qualified_name (struct_), - di_struct_get_fully_qualified_name (struct_), - di_struct_get_fully_qualified_name (struct_), + di_struct_get_name (struct_), + di_struct_get_name (struct_), + di_struct_get_name (struct_), get_doc (struct_, TRUE)); print_struct_members (di_struct_get_members (struct_), "struct", - di_struct_get_fully_qualified_name (struct_), + di_struct_get_name (struct_), get_doc (struct_, FALSE), s); } @@ -713,9 +688,9 @@ print_enum (DIEnum *enum_, " Enum %s\n" " %s\n" " \n", - di_enum_get_fully_qualified_name (enum_), - di_enum_get_fully_qualified_name (enum_), - di_enum_get_fully_qualified_name (enum_), + di_enum_get_name (enum_), + di_enum_get_name (enum_), + di_enum_get_name (enum_), get_doc (enum_, TRUE)); @@ -741,7 +716,7 @@ print_enum (DIEnum *enum_, g_string_append_printf (s, "enum %s\n" "{\n", - di_enum_get_fully_qualified_name (enum_)); + di_enum_get_name (enum_)); for (l = di_enum_get_members (enum_); l != NULL; l = l->next) { @@ -801,9 +776,9 @@ print_error_domain (DIErrorDomain *error_domain, " Error Domain %s\n" " %s\n" " \n", - di_error_domain_get_fully_qualified_name (error_domain), - di_error_domain_get_fully_qualified_name (error_domain), - di_error_domain_get_fully_qualified_name (error_domain), + di_error_domain_get_name (error_domain), + di_error_domain_get_name (error_domain), + di_error_domain_get_name (error_domain), get_doc (error_domain, TRUE)); @@ -817,7 +792,7 @@ print_error_domain (DIErrorDomain *error_domain, g_string_append_printf (s, "error_domain %s\n" "{\n", - di_error_domain_get_fully_qualified_name (error_domain)); + di_error_domain_get_name (error_domain)); for (l = di_error_domain_get_members (error_domain); l != NULL; l = l->next) { @@ -885,38 +860,18 @@ write_file (const gchar *filename, } static gboolean -print_namespace (DINamespace *namespace, - GError **error) +print_all (DIParser *parser, + GError **error) { GList *l; gboolean ret; gchar *filename; - GString *sn; ret = FALSE; - - sn = g_string_new (NULL); - g_string_append (sn, - "\n" - "\n"); - - g_string_append_printf (sn, - "\n", - di_namespace_get_name (namespace)); - - g_string_append_printf (sn, - " \n" - " Foo\n"); - /* ---------------------------------------------------------------------------------------------------- */ - - /* Print all interfaces in separate files */ - g_string_append_printf (sn, - " \n" - " D-Bus interfaces\n"); - for (l = di_namespace_get_interfaces (namespace); l != NULL; l = l->next) + /* Print all interfaces */ + for (l = di_parser_get_interfaces (parser); l != NULL; l = l->next) { DIInterface *iface = l->data; GString *s; @@ -929,7 +884,7 @@ print_namespace (DINamespace *namespace, print_interface (iface, s); filename = g_strdup_printf ("didl-%s.xml", - di_interface_get_fully_qualified_name (iface)); + di_interface_get_name (iface)); if (!write_file (filename, s, error)) { g_free (filename); @@ -937,23 +892,12 @@ print_namespace (DINamespace *namespace, goto out; } g_string_free (s, TRUE); - - g_string_append_printf (sn, - " \n", - filename); - g_free (filename); } - g_string_append_printf (sn, - " \n"); /* ---------------------------------------------------------------------------------------------------- */ - - /* Print all structs in separate files */ - g_string_append_printf (sn, - " \n" - " Structs\n"); - for (l = di_namespace_get_structs (namespace); l != NULL; l = l->next) + /* Print all structs */ + for (l = di_parser_get_structs (parser); l != NULL; l = l->next) { DIStruct *struct_ = l->data; GString *s; @@ -966,7 +910,7 @@ print_namespace (DINamespace *namespace, print_struct (struct_, s); filename = g_strdup_printf ("didl-%s.xml", - di_struct_get_fully_qualified_name (struct_)); + di_struct_get_name (struct_)); if (!write_file (filename, s, error)) { g_free (filename); @@ -975,22 +919,12 @@ print_namespace (DINamespace *namespace, } g_string_free (s, TRUE); - g_string_append_printf (sn, - " \n", - filename); - g_free (filename); } - g_string_append_printf (sn, - " \n"); /* ---------------------------------------------------------------------------------------------------- */ - - /* Print all enums in separate files */ - g_string_append_printf (sn, - " \n" - " Enumerations\n"); - for (l = di_namespace_get_enums (namespace); l != NULL; l = l->next) + /* Print all enums */ + for (l = di_parser_get_enums (parser); l != NULL; l = l->next) { DIEnum *enum_ = l->data; GString *s; @@ -1003,7 +937,7 @@ print_namespace (DINamespace *namespace, print_enum (enum_, s); filename = g_strdup_printf ("didl-%s.xml", - di_enum_get_fully_qualified_name (enum_)); + di_enum_get_name (enum_)); if (!write_file (filename, s, error)) { g_free (filename); @@ -1012,22 +946,12 @@ print_namespace (DINamespace *namespace, } g_string_free (s, TRUE); - g_string_append_printf (sn, - " \n", - filename); - g_free (filename); } - g_string_append_printf (sn, - " \n"); /* ---------------------------------------------------------------------------------------------------- */ - - /* Print all error domains in separate files */ - g_string_append_printf (sn, - " \n" - " Error domains\n"); - for (l = di_namespace_get_error_domains (namespace); l != NULL; l = l->next) + /* Print all error domains */ + for (l = di_parser_get_error_domains (parser); l != NULL; l = l->next) { DIErrorDomain *error_domain = l->data; GString *s; @@ -1040,7 +964,7 @@ print_namespace (DINamespace *namespace, print_error_domain (error_domain, s); filename = g_strdup_printf ("didl-%s.xml", - di_error_domain_get_fully_qualified_name (error_domain)); + di_error_domain_get_name (error_domain)); if (!write_file (filename, s, error)) { g_free (filename); @@ -1049,36 +973,14 @@ print_namespace (DINamespace *namespace, } g_string_free (s, TRUE); - g_string_append_printf (sn, - " \n", - filename); - g_free (filename); } - g_string_append_printf (sn, - " \n"); - /* ---------------------------------------------------------------------------------------------------- */ - g_string_append_printf (sn, - " \n"); - g_string_append_printf (sn, "\n"); - - filename = g_strdup_printf ("didl-%s.xml", - di_namespace_get_name (namespace)); - if (!write_file (filename, sn, error)) - { - g_free (filename); - goto out; - } - g_free (filename); - ret = TRUE; out: - if (sn != NULL) - g_string_free (sn, TRUE); return ret; } @@ -1097,7 +999,6 @@ main (int argc, char *argv[]) opt_input_files = NULL; opt_output_dir = NULL; - opt_namespaces = NULL; ret = 1; @@ -1118,7 +1019,7 @@ main (int argc, char *argv[]) goto out; } - parser = di_parser_new (opt_input_files[0]); + parser = di_parser_new (opt_input_files); for (l = di_parser_get_errors (parser); l != NULL; l = l->next) { g_printerr ("%s\n", (const gchar *) l->data); @@ -1130,21 +1031,12 @@ main (int argc, char *argv[]) if (di_parser_get_errors (parser) != NULL) goto out; - for (l = di_parser_get_namespaces (parser); l != NULL; l = l->next) + error = NULL; + if (!print_all (parser, &error)) { - DINamespace *namespace = l->data; - - if (opt_namespaces != NULL) - if (check_ignore_namespace (namespace, opt_namespaces)) - continue; - - error = NULL; - if (!print_namespace (namespace, &error)) - { - g_printerr ("Error writing file: %s", error->message); - g_error_free (error); - goto out; - } + g_printerr ("Error writing file: %s", error->message); + g_error_free (error); + goto out; } ret = 0; @@ -1156,6 +1048,5 @@ main (int argc, char *argv[]) g_option_context_free (context); g_strfreev (opt_input_files); g_free (opt_output_dir); - g_strfreev (opt_namespaces); return ret;; } diff --git a/src/didl2xml.c b/src/didl2xml.c index 35ab8b2..aa0caf5 100644 --- a/src/didl2xml.c +++ b/src/didl2xml.c @@ -26,40 +26,15 @@ static gchar **opt_input_files; static gchar *opt_output_dir; -static gchar **opt_namespaces; static GOptionEntry entries[] = { { "idl", 'i', 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_input_files, "IDL files (may be used several times)", NULL }, { "output", 'o', 0, G_OPTION_ARG_FILENAME, &opt_output_dir, "Directory for output", NULL }, - { "namespaces", 'n', 0, G_OPTION_ARG_STRING_ARRAY, &opt_namespaces, "Namespaces to consider (may be used several times)", NULL }, { NULL } }; /* ---------------------------------------------------------------------------------------------------- */ -static gboolean -check_ignore_namespace (DINamespace *namespace, - gchar **namespaces_to_consider) -{ - guint n; - gboolean ret; - - ret = FALSE; - - for (n = 0; namespaces_to_consider[n] != NULL; n++) - { - if (g_strcmp0 (di_namespace_get_name (namespace), namespaces_to_consider[n]) == 0) - goto out; - } - - ret = TRUE; - - out: - return ret; -} - -/* ---------------------------------------------------------------------------------------------------- */ - static void print_annotations (DIBase *base, guint indent, @@ -239,7 +214,7 @@ print_interface (DIInterface *iface, g_string_append_printf (s, "%*s\n", indent, "", - di_interface_get_fully_qualified_name (iface)); + di_interface_get_name (iface)); print_annotations ((DIBase *) iface, indent + 2, s); g_string_append (s, "\n"); @@ -288,7 +263,7 @@ print_struct (DIStruct *struct_, g_string_append_printf (s, "%*s\n", indent, "", - di_struct_get_fully_qualified_name (struct_)); + di_struct_get_name (struct_)); print_annotations ((DIBase *) struct_, indent + 2, s); g_string_append (s, "\n"); @@ -324,7 +299,7 @@ print_enum (DIEnum *enum_, g_string_append_printf (s, "%*s\n", indent, "", - di_enum_get_fully_qualified_name (enum_)); + di_enum_get_name (enum_)); print_annotations ((DIBase *) enum_, indent + 2, s); g_string_append (s, "\n"); @@ -358,7 +333,7 @@ print_error_domain (DIErrorDomain *error_domain, g_string_append_printf (s, "%*s\n", indent, "", - di_error_domain_get_fully_qualified_name (error_domain)); + di_error_domain_get_name (error_domain)); print_annotations ((DIBase *) error_domain, indent + 2, s); g_string_append (s, "\n"); @@ -421,8 +396,8 @@ write_file (const gchar *filename, } static gboolean -print_namespace (DINamespace *namespace, - GError **error) +print_all (DIParser *parser, + GError **error) { GList *l; gboolean ret; @@ -432,7 +407,7 @@ print_namespace (DINamespace *namespace, /* ---------------------------------------------------------------------------------------------------- */ /* Print all interfaces in separate files */ - for (l = di_namespace_get_interfaces (namespace); l != NULL; l = l->next) + for (l = di_parser_get_interfaces (parser); l != NULL; l = l->next) { DIInterface *iface = l->data; GString *s; @@ -446,7 +421,7 @@ print_namespace (DINamespace *namespace, g_string_append (s, "\n"); filename = g_strdup_printf ("%s.xml", - di_interface_get_fully_qualified_name (iface)); + di_interface_get_name (iface)); if (!write_file (filename, s, error)) { g_free (filename); @@ -459,7 +434,7 @@ print_namespace (DINamespace *namespace, /* ---------------------------------------------------------------------------------------------------- */ /* Print all structs in separate files */ - for (l = di_namespace_get_structs (namespace); l != NULL; l = l->next) + for (l = di_parser_get_structs (parser); l != NULL; l = l->next) { DIStruct *struct_ = l->data; GString *s; @@ -473,7 +448,7 @@ print_namespace (DINamespace *namespace, g_string_append (s, "\n"); filename = g_strdup_printf ("%s.xml", - di_struct_get_fully_qualified_name (struct_)); + di_struct_get_name (struct_)); if (!write_file (filename, s, error)) { g_free (filename); @@ -486,7 +461,7 @@ print_namespace (DINamespace *namespace, /* ---------------------------------------------------------------------------------------------------- */ /* Print all enums in separate files */ - for (l = di_namespace_get_enums (namespace); l != NULL; l = l->next) + for (l = di_parser_get_enums (parser); l != NULL; l = l->next) { DIEnum *enum_ = l->data; GString *s; @@ -502,7 +477,7 @@ print_namespace (DINamespace *namespace, g_string_append (s, "\n"); filename = g_strdup_printf ("%s.xml", - di_enum_get_fully_qualified_name (enum_)); + di_enum_get_name (enum_)); if (!write_file (filename, s, error)) { g_free (filename); @@ -516,7 +491,7 @@ print_namespace (DINamespace *namespace, /* ---------------------------------------------------------------------------------------------------- */ /* Print all error domains in separate files */ - for (l = di_namespace_get_error_domains (namespace); l != NULL; l = l->next) + for (l = di_parser_get_error_domains (parser); l != NULL; l = l->next) { DIErrorDomain *error_domain = l->data; GString *s; @@ -531,7 +506,7 @@ print_namespace (DINamespace *namespace, g_string_append (s, "\n"); filename = g_strdup_printf ("%s.xml", - di_error_domain_get_fully_qualified_name (error_domain)); + di_error_domain_get_name (error_domain)); if (!write_file (filename, s, error)) { g_free (filename); @@ -564,7 +539,6 @@ main (int argc, char *argv[]) opt_input_files = NULL; opt_output_dir = NULL; - opt_namespaces = NULL; ret = 1; @@ -585,7 +559,7 @@ main (int argc, char *argv[]) goto out; } - parser = di_parser_new (opt_input_files[0]); + parser = di_parser_new (opt_input_files); for (l = di_parser_get_errors (parser); l != NULL; l = l->next) { g_printerr ("%s\n", (const gchar *) l->data); @@ -597,21 +571,12 @@ main (int argc, char *argv[]) if (di_parser_get_errors (parser) != NULL) goto out; - for (l = di_parser_get_namespaces (parser); l != NULL; l = l->next) + error = NULL; + if (!print_all (parser, &error)) { - DINamespace *namespace = l->data; - - if (opt_namespaces != NULL) - if (check_ignore_namespace (namespace, opt_namespaces)) - continue; - - error = NULL; - if (!print_namespace (namespace, &error)) - { - g_printerr ("Error writing file: %s", error->message); - g_error_free (error); - goto out; - } + g_printerr ("Error writing file: %s", error->message); + g_error_free (error); + goto out; } ret = 0; @@ -623,6 +588,5 @@ main (int argc, char *argv[]) g_option_context_free (context); g_strfreev (opt_input_files); g_free (opt_output_dir); - g_strfreev (opt_namespaces); return ret;; } diff --git a/src/idl.h b/src/idl.h index 0d7a07e..1736886 100644 --- a/src/idl.h +++ b/src/idl.h @@ -32,6 +32,4 @@ extern int yyparse (DIParser *parser); extern int yydebug; extern int yy_flex_debug; -extern DINamespace *yynamespace; - #endif /* __IDL_H */ diff --git a/src/idlparser.y b/src/idlparser.y index c31e643..9a3e202 100644 --- a/src/idlparser.y +++ b/src/idlparser.y @@ -154,16 +154,32 @@ file: ns_decl : annotation_list NAMESPACE dbus_name OBRACE ns_decls EBRACE SEMICOLON { - DINamespace *namespace; - namespace = di_namespace_new (g_strdup (parser->path_to_current_file), - yylineno, - $3, - $5.interfaces, - $5.structs, - $5.enums, - $5.error_domains, - $1); - parser->namespaces = g_list_append (parser->namespaces, namespace); + GList *l; + + for (l = $5.interfaces; l != NULL; l = l->next) + { + di_interface_add_prefix ((DIInterface *) l->data, $3); + di_parser_add (parser, (DIBase *) l->data); + } + + for (l = $5.structs; l != NULL; l = l->next) + { + di_struct_add_prefix ((DIStruct *) l->data, $3); + di_parser_add (parser, (DIBase *) l->data); + } + + for (l = $5.enums; l != NULL; l = l->next) + { + di_enum_add_prefix ((DIEnum *) l->data, $3); + di_parser_add (parser, (DIBase *) l->data); + } + + for (l = $5.error_domains; l != NULL; l = l->next) + { + di_error_domain_add_prefix ((DIErrorDomain *) l->data, $3); + di_parser_add (parser, (DIBase *) l->data); + } + $5.interfaces = NULL; $5.structs = NULL; $5.enums = NULL; diff --git a/src/test.c b/src/test.c index 5408cf8..cd71879 100644 --- a/src/test.c +++ b/src/test.c @@ -30,10 +30,14 @@ pof (const gchar *path) DIParser *parser; gboolean ret; GList *l; + const gchar *files[2]; + + files[0] = path; + files[1] = NULL; ret = FALSE; - parser = di_parser_new (path); + parser = di_parser_new ((gchar **) files); for (l = di_parser_get_errors (parser); l != NULL; l = l->next) { @@ -52,10 +56,25 @@ pof (const gchar *path) goto out; - for (l = di_parser_get_namespaces (parser); l != NULL; l = l->next) + for (l = di_parser_get_interfaces (parser); l != NULL; l = l->next) + { + DIInterface *interface = l->data; + di_interface_print (interface, 0); + } + for (l = di_parser_get_structs (parser); l != NULL; l = l->next) + { + DIStruct *struct_ = l->data; + di_struct_print (struct_, 0); + } + for (l = di_parser_get_enums (parser); l != NULL; l = l->next) + { + DIEnum *enum_ = l->data; + di_enum_print (enum_, 0); + } + for (l = di_parser_get_error_domains (parser); l != NULL; l = l->next) { - DINamespace *namespace = l->data; - di_namespace_print (namespace, 0); + DIErrorDomain *error_domain = l->data; + di_error_domain_print (error_domain, 0); } out: -- cgit v1.2.3