From: Jacek Caban Subject: [PATCH 3/6] widl: Write proper C++ forward declarations for interfaces inside namespace. Message-Id: <55BB5E15.5000706@codeweavers.com> Date: Fri, 31 Jul 2015 13:37:57 +0200 --- tools/widl/header.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/widl/header.c b/tools/widl/header.c index a71ad1a..7ae0e68 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -52,6 +52,16 @@ static void indent(FILE *h, int delta) if (delta > 0) indentation += delta; } +static void write_line(FILE *f, int delta, const char *fmt, ...) +{ + va_list ap; + indent(f, delta); + va_start(ap, fmt); + vfprintf(f, fmt, ap); + va_end(ap); + fprintf(f, "\n"); +} + int is_ptrchain_attr(const var_t *var, enum attr_type t) { if (is_attr(var->attrs, t)) @@ -141,6 +151,24 @@ static const char *uuid_string(const UUID *uuid) return buf; } +static void write_namespace_start(FILE *header, struct namespace *namespace) +{ + if(is_global_namespace(namespace)) + return; + + write_namespace_start(header, namespace->parent); + write_line(header, 1, "namespace %s {", namespace->name); +} + +static void write_namespace_end(FILE *header, struct namespace *namespace) +{ + if(is_global_namespace(namespace)) + return; + + write_line(header, -1, "}", namespace->name); + write_namespace_end(header, namespace->parent); +} + const char *get_name(const var_t *v) { static char buffer[256]; @@ -1221,7 +1249,12 @@ static void write_forward(FILE *header, type_t *iface) { fprintf(header, "#ifndef __%s_FWD_DEFINED__\n", iface->c_name); fprintf(header, "#define __%s_FWD_DEFINED__\n", iface->c_name); - fprintf(header, "typedef interface %s %s;\n", iface->name, iface->name); + fprintf(header, "typedef interface %s %s;\n", iface->c_name, iface->c_name); + fprintf(header, "#ifdef __cplusplus\n"); + write_namespace_start(header, iface->namespace); + write_line(header, 0, "interface %s;", iface->name); + write_namespace_end(header, iface->namespace); + fprintf(header, "#endif /* __cplusplus */\n"); fprintf(header, "#endif\n\n" ); }