From: Bernhard Kölbl besentv@gmail.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- tools/widl/header.c | 23 +++++++++++++++++++++++ tools/widl/parser.l | 1 + tools/widl/parser.y | 17 ++++++++++++++++- tools/widl/widltypes.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index 8b9c64e1e38..1db6efbefcd 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -215,6 +215,21 @@ const char *get_name(const var_t *v) return v->name; }
+static void write_deprecated(FILE *h, const expr_t *deprecated_attr) +{ + const expr_t *deprecated_ver = deprecated_attr->u.ext; + const expr_t *deprecated_msg = deprecated_attr->ref->ref; + if (deprecated_msg->type == EXPR_STRLIT && deprecated_ver->type == EXPR_GTREQL) { + const char *deprecated_text = deprecated_msg->u.sval; + write_apicontract_guard_start(h, deprecated_ver); + indent(h, 0); + fprintf(h, "DEPRECATED("%s")\n", deprecated_text); + write_apicontract_guard_end(h, deprecated_ver); + } + else + warning("Deprecated attributes without explicit contract declaration are not supported, yet.\n"); +} + static void write_fields(FILE *h, var_list_t *fields, enum name_type name_type) { unsigned nameless_struct_cnt = 0, nameless_struct_i = 0, nameless_union_cnt = 0, nameless_union_i = 0; @@ -1231,6 +1246,7 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) const decl_spec_t *ret = type_function_get_ret(func->declspec.type); const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV); const var_list_t *args = type_function_get_args(func->declspec.type); + const expr_t *deprecated = get_attrp(func->attrs, ATTR_DEPRECATED); const var_t *arg;
if (!callconv) callconv = "STDMETHODCALLTYPE"; @@ -1277,6 +1293,8 @@ static void write_cpp_method_def(FILE *header, const type_t *iface) fprintf(header, "#else\n"); }
+ if (deprecated) + write_deprecated(header, deprecated); indent(header, 0); fprintf(header, "virtual "); write_type_decl_left(header, ret); @@ -1361,6 +1379,9 @@ static void do_write_c_method_def(FILE *header, const type_t *iface, const char } if (!is_callas(func->attrs)) { const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV); + const expr_t *deprecated = get_attrp(func->attrs, ATTR_DEPRECATED); + if (deprecated) + write_deprecated(header, deprecated); if (!callconv) callconv = "STDMETHODCALLTYPE"; indent(header, 0); write_type_decl_left(header, type_function_get_ret(func->declspec.type)); @@ -2155,6 +2176,8 @@ void write_header(const statement_list_t *stmts) fprintf(header, "#ifndef __%s__\n", header_token); fprintf(header, "#define __%s__\n\n", header_token);
+ fprintf(header, "#define DEPRECATED(x)\n\n"); + fprintf(header, "/* Forward declarations */\n\n"); write_forward_decls(header, stmts);
diff --git a/tools/widl/parser.l b/tools/widl/parser.l index 9286a494d4d..5a5f54103b9 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -348,6 +348,7 @@ static const struct keyword attr_keywords[] = {"defaultcollelem", tDEFAULTCOLLELEM, 0}, {"defaultvalue", tDEFAULTVALUE, 0}, {"defaultvtable", tDEFAULTVTABLE, 0}, + {"deprecated", tDEPRECATED, 1}, {"disable_consistency_check", tDISABLECONSISTENCYCHECK, 0}, {"displaybind", tDISPLAYBIND, 0}, {"dllname", tDLLNAME, 0}, diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 02db99a55b7..54d6ee2ae22 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -186,6 +186,7 @@ static typelib_t *current_typelib; %token tDEFAULTCOLLELEM %token tDEFAULTVALUE %token tDEFAULTVTABLE +%token tDEPRECATED %token tDISABLECONSISTENCYCHECK tDISPLAYBIND %token tDISPINTERFACE %token tDLLNAME tDONTFREE tDOUBLE tDUAL @@ -281,8 +282,9 @@ static typelib_t *current_typelib; %type <expr> m_expr expr expr_const expr_int_const array m_bitfield %type <expr_list> m_exprs /* exprs expr_list */ expr_list_int_const %type <expr> contract_req +%type <expr> deprecated_ver %type <expr> static_attr -%type <expr> activatable_attr +%type <expr> activatable_attr deprecated_attr %type <type> delegatedef %type <stgclass> storage_cls_spec %type <type_qualifier> type_qualifier m_type_qual_list @@ -591,6 +593,17 @@ activatable_attr: } | contract_req { $$ = $1; } /* activatable on the default activation factory */
+deprecated_ver: + contract_req { $$ = $1; } + | aNUM { $$ = make_exprl(EXPR_NUM, $1); } + ; + +deprecated_attr: + aSTRING ',' aIDENTIFIER ',' deprecated_ver { + $$ = make_expr2(EXPR_MEMBER, make_exprs(EXPR_STRLIT, $1), make_exprs(EXPR_IDENTIFIER, $3)); + $$ = make_expr2(EXPR_MEMBER, $$, $5); + } + attribute: { $$ = NULL; } | tACTIVATABLE '(' activatable_attr ')' { $$ = make_attrp(ATTR_ACTIVATABLE, $3); } | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); } @@ -617,6 +630,7 @@ attribute: { $$ = NULL; } | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); } | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE, $3); } | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); } + | tDEPRECATED '(' deprecated_attr ')' { $$ = make_attrp(ATTR_DEPRECATED, $3); } | tDISABLECONSISTENCYCHECK { $$ = make_attr(ATTR_DISABLECONSISTENCYCHECK); } | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); } | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); } @@ -2352,6 +2366,7 @@ struct allowed_attr allowed_attr[] = /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" }, /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" }, /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "defaultvtable" }, + /* ATTR_DEPRECATED */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "deprecated" }, /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" }, /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, NULL }, /* ATTR_DISPLAYBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" }, diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 0d88e713433..906fd7272ff 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -96,6 +96,7 @@ enum attr_type ATTR_DEFAULTCOLLELEM, ATTR_DEFAULTVALUE, ATTR_DEFAULTVTABLE, + ATTR_DEPRECATED, ATTR_DISABLECONSISTENCYCHECK, ATTR_DISPINTERFACE, ATTR_DISPLAYBIND,