diff options
Diffstat (limited to 'src/dbusidl.c')
-rw-r--r-- | src/dbusidl.c | 578 |
1 files changed, 291 insertions, 287 deletions
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_) { @@ -463,23 +493,11 @@ di_error_member_get_name (DIErrorMember *error_member) } 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) { @@ -722,11 +639,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) @@ -2226,32 +2227,11 @@ di_parser_new (const gchar *path) } 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); +} |