Module: wine Branch: master Commit: 5deda2de3fb6ddcf8d84ed8245597a7b46020df8 URL: https://gitlab.winehq.org/wine/wine/-/commit/5deda2de3fb6ddcf8d84ed8245597a7...
Author: Rémi Bernon rbernon@codeweavers.com Date: Wed Jan 25 23:02:38 2023 +0100
widl: Simplify handling of already parsed imports.
---
tools/widl/parser.h | 2 +- tools/widl/parser.l | 36 ++++++++++++++++++++---------------- tools/widl/parser.y | 15 ++++----------- 3 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/tools/widl/parser.h b/tools/widl/parser.h index 83832ecfcd8..f465fafa03c 100644 --- a/tools/widl/parser.h +++ b/tools/widl/parser.h @@ -29,7 +29,7 @@ extern int parser_debug; extern int yy_flex_debug;
extern int import_stack_ptr; -int do_import(char *fname); +void push_import( char *import_name ); void pop_import(void);
#define parse_only import_stack_ptr diff --git a/tools/widl/parser.l b/tools/widl/parser.l index 710b6e37636..47783cbacb3 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -512,7 +512,7 @@ void pop_import(void) { int ptr = import_stack_ptr-1;
- fclose(yyin); + if (yyin) fclose( yyin ); yy_delete_buffer( YY_CURRENT_BUFFER ); yy_switch_to_buffer( import_stack[ptr].state ); input_name = import_stack[ptr].input_name; @@ -520,7 +520,7 @@ void pop_import(void) import_stack_ptr--; }
-int do_import(char *fname) +void push_import( char *import_name ) { FILE *f; char *path, *name; @@ -528,26 +528,32 @@ int do_import(char *fname) int ptr = import_stack_ptr; int ret;
+ if (import_stack_ptr == MAX_IMPORT_DEPTH) + error_loc("Exceeded max import depth\n"); + + import_stack[ptr].state = YY_CURRENT_BUFFER; + import_stack[ptr].input_name = input_name; + import_stack[ptr].line_number = line_number; + import_stack_ptr++; + yyin = NULL; + + /* reset buffer for <<EOF>>, in case import fails or already imported */ + yy_scan_string( "" ); + LIST_FOR_EACH_ENTRY( import, &imports, struct import, entry ) - if (!strcmp( import->name, fname )) return 0; /* already imported */ + if (!strcmp( import->name, import_name )) return; /* already imported */
import = xmalloc( sizeof(struct import) ); - import->name = xstrdup( fname ); + import->name = xstrdup( import_name ); list_add_tail( &imports, &import->entry );
/* don't search for a file name with a path in the include directories, * for compatibility with MIDL */ - if (strchr( fname, '/' ) || strchr( fname, '\' )) - path = xstrdup( fname ); - else if (!(path = wpp_find_include( fname, input_name ))) - error_loc("Unable to open include file %s\n", fname); + if (strchr( import_name, '/' ) || strchr( import_name, '\' )) + path = xstrdup( import_name ); + else if (!(path = wpp_find_include( import_name, input_name ))) + error_loc( "Unable to open include file %s\n", import_name );
- if (import_stack_ptr == MAX_IMPORT_DEPTH) - error_loc("Exceeded max import depth\n"); - - import_stack[ptr].input_name = input_name; - import_stack[ptr].line_number = line_number; - import_stack_ptr++; input_name = path; line_number = 1;
@@ -562,9 +568,7 @@ int do_import(char *fname) if((f = fopen(name, "r")) == NULL) error_loc("Unable to open %s\n", name);
- import_stack[ptr].state = YY_CURRENT_BUFFER; yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE)); - return 1; }
static void switch_to_acf(void) diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 6777a281ec7..031e5482792 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -331,7 +331,7 @@ int parser_lex( PARSER_STYPE *yylval ); %type <str> libraryhdr callconv cppquote importlib import %type <str> typename m_typename %type <uuid> uuid_string -%type <import> import_start +%type <str> import_start %type <typelib> library_start librarydef %type <statement> statement typedef pragma_warning %type <stmt_list> gbl_statements imp_statements int_statements @@ -504,17 +504,10 @@ typedecl:
cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; } ; -import_start: tIMPORT aSTRING ';' { $$ = xmalloc(sizeof(struct _import_t)); - $$->name = $2; - $$->import_performed = do_import($2); - if (!$$->import_performed) yychar = aEOF; - } - ;
-import: import_start imp_statements aEOF { $$ = $1->name; - if ($1->import_performed) pop_import(); - free($1); - } +import_start: tIMPORT aSTRING ';' { $$ = $2; push_import($2); } + ; +import: import_start imp_statements aEOF { pop_import(); } ;
importlib: tIMPORTLIB '(' aSTRING ')'