Module: wine Branch: master Commit: 66fa9a714e95633deb7ef06ebda27fdea6b8f536 URL: http://source.winehq.org/git/wine.git/?a=commit;h=66fa9a714e95633deb7ef06ebd...
Author: Rob Shearman rob@codeweavers.com Date: Fri Apr 25 10:59:40 2008 +0100
widl: Create a statement object for import statements.
Move the writing of include directives into the generated header into header.c.
---
tools/widl/header.c | 12 ++++++++++++ tools/widl/header.h | 1 + tools/widl/parser.l | 11 +---------- tools/widl/parser.y | 36 ++++++++++++++++++++++++++++-------- 4 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index 0d7e0b2..ae70454 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -1039,3 +1039,15 @@ void write_coclass_forward(type_t *cocl) fprintf(header, "typedef struct %s %s;\n", cocl->name, cocl->name); fprintf(header, "#endif /* defined __%s_FWD_DEFINED__ */\n\n", cocl->name ); } + +void write_import(const char *fname) +{ + char *hname, *p; + + hname = dup_basename(fname, ".idl"); + p = hname + strlen(hname) - 2; + if (p <= hname || strcmp( p, ".h" )) strcat(hname, ".h"); + + fprintf(header, "#include <%s>\n", hname); + free(hname); +} diff --git a/tools/widl/header.h b/tools/widl/header.h index c663c70..c2cecd5 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -49,6 +49,7 @@ extern int need_proxy_file(const statement_list_t *stmts); extern const var_t *is_callas(const attr_list_t *list); extern void write_args(FILE *h, const var_list_t *arg, const char *name, int obj, int do_indent); extern void write_array(FILE *h, array_dims_t *v, int field); +extern void write_import(const char *fname); extern void write_forward(type_t *iface); extern void write_interface(type_t *iface); extern void write_dispinterface(type_t *iface); diff --git a/tools/widl/parser.l b/tools/widl/parser.l index d40c9d0..1e8460b 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -411,20 +411,11 @@ struct imports { int do_import(char *fname) { FILE *f; - char *hname, *path, *p; + char *path; struct imports *import; int ptr = import_stack_ptr; int ret;
- if (!parse_only && do_header) { - hname = dup_basename(fname, ".idl"); - p = hname + strlen(hname) - 2; - if (p <= hname || strcmp( p, ".h" )) strcat(hname, ".h"); - - fprintf(header, "#include <%s>\n", hname); - free(hname); - } - import = first_import; while (import && strcmp(import->name, fname)) import = import->next; diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 43c4af2..d57d286 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -78,6 +78,12 @@ struct typenode { struct list entry; };
+struct _import_t +{ + char *name; + int import_performed; +}; + typelist_t incomplete_types = LIST_INIT(incomplete_types);
static void add_incomplete(type_t *t); @@ -150,6 +156,7 @@ static statement_t *make_statement_library(typelib_t *typelib); static statement_t *make_statement_cppquote(const char *str); static statement_t *make_statement_importlib(const char *str); static statement_t *make_statement_module(type_t *type); +static statement_t *make_statement_import(const char *str); static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt);
#define tsENUM 1 @@ -180,7 +187,8 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s unsigned int num; double dbl; interface_info_t ifinfo; - typelib_t *typelib; + typelib_t *typelib; + struct _import_t *import; }
%token <str> aIDENTIFIER @@ -298,9 +306,9 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s %type <func_list> int_statements dispint_meths %type <type> coclass coclasshdr coclassdef %type <num> pointer_type version -%type <str> libraryhdr callconv cppquote importlib +%type <str> libraryhdr callconv cppquote importlib import %type <uuid> uuid_string -%type <num> import_start +%type <import> import_start %type <typelib> library_start librarydef %type <statement> statement typedef %type <stmt_list> gbl_statements imp_statements @@ -387,7 +395,7 @@ statement: constdef ';' { $$ = make_statement_init_decl($1); | externdef ';' { $$ = make_statement_extern($1); if (!parse_only && do_header) write_externdef($1); } - | import { $$ = NULL; } + | import { $$ = make_statement_import($1); } | structdef ';' { $$ = make_statement_type_decl($1); if (!parse_only && do_header) { write_type_def_or_decl(header, $1, FALSE, NULL); @@ -406,13 +414,18 @@ statement: constdef ';' { $$ = make_statement_init_decl($1); cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; if (!parse_only && do_header) fprintf(header, "%s\n", $3); } ; import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY); - $$ = do_import($2); - if (!$$) yychar = aEOF; + $$ = xmalloc(sizeof(struct _import_t)); + $$->name = $2; + $$->import_performed = do_import($2); + if (!$$->import_performed) yychar = aEOF; } ;
-import: import_start imp_statements aEOF - { if ($1) pop_import(); } +import: import_start imp_statements aEOF { $$ = $1->name; + if ($1->import_performed) pop_import(); + free($1); + if (!parse_only && do_header) write_import($$); + } ;
importlib: tIMPORTLIB '(' aSTRING ')' @@ -2607,6 +2620,13 @@ static statement_t *make_statement_importlib(const char *str) return stmt; }
+static statement_t *make_statement_import(const char *str) +{ + statement_t *stmt = make_statement(STMT_IMPORT); + stmt->u.str = str; + return stmt; +} + static statement_t *make_statement_module(type_t *type) { statement_t *stmt = make_statement(STMT_MODULE);