Commit 9d537999 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

widl: Use a struct list for the import stack.

parent 5deda2de
...@@ -28,12 +28,10 @@ extern char *parser_text; ...@@ -28,12 +28,10 @@ extern char *parser_text;
extern int parser_debug; extern int parser_debug;
extern int yy_flex_debug; extern int yy_flex_debug;
extern int import_stack_ptr; extern int parse_only;
void push_import( char *import_name ); void push_import( char *import_name );
void pop_import(void); void pop_import(void);
#define parse_only import_stack_ptr
int is_type(const char *name); int is_type(const char *name);
int do_warning(const char *toggle, warning_list_t *wnum); int do_warning(const char *toggle, warning_list_t *wnum);
......
...@@ -81,13 +81,15 @@ static void switch_to_acf(void); ...@@ -81,13 +81,15 @@ static void switch_to_acf(void);
static warning_list_t *disabled_warnings = NULL; static warning_list_t *disabled_warnings = NULL;
#define MAX_IMPORT_DEPTH 20 struct import_state
struct { {
YY_BUFFER_STATE state; YY_BUFFER_STATE buffer;
char *input_name; char *input_name;
int line_number; int line_number;
} import_stack[MAX_IMPORT_DEPTH]; struct list entry;
int import_stack_ptr = 0; };
static struct list import_stack = LIST_INIT( import_stack );
int parse_only = 0;
struct import struct import
{ {
...@@ -159,7 +161,8 @@ struct uuid *parse_uuid(const char *u) ...@@ -159,7 +161,8 @@ struct uuid *parse_uuid(const char *u)
} }
<PP_PRAGMA>midl_echo[^\n]* yyless(9); yy_pop_state(); return tCPPQUOTE; <PP_PRAGMA>midl_echo[^\n]* yyless(9); yy_pop_state(); return tCPPQUOTE;
<PP_PRAGMA>winrt[^\n]* { <PP_PRAGMA>winrt[^\n]* {
if(import_stack_ptr) { if (!list_empty( &import_stack ))
{
if(!winrt_mode) if(!winrt_mode)
error_loc("winrt IDL file imported in non-winrt mode\n"); error_loc("winrt IDL file imported in non-winrt mode\n");
}else { }else {
...@@ -234,7 +237,7 @@ SAFEARRAY{ws}*/\( return tSAFEARRAY; ...@@ -234,7 +237,7 @@ SAFEARRAY{ws}*/\( return tSAFEARRAY;
<INITIAL,ATTR>\.\.\. return ELLIPSIS; <INITIAL,ATTR>\.\.\. return ELLIPSIS;
<INITIAL,ATTR>. return yytext[0]; <INITIAL,ATTR>. return yytext[0];
<<EOF>> { <<EOF>> {
if (import_stack_ptr) if (!list_empty( &import_stack ))
return aEOF; return aEOF;
if (acf_name) if (acf_name)
{ {
...@@ -510,32 +513,38 @@ static char *get_buffered_cstring(void) ...@@ -510,32 +513,38 @@ static char *get_buffered_cstring(void)
void pop_import(void) void pop_import(void)
{ {
int ptr = import_stack_ptr-1; struct list *entry = list_head( &import_stack );
struct import_state *state;
if (yyin) fclose( yyin ); assert( entry );
yy_delete_buffer( YY_CURRENT_BUFFER );
yy_switch_to_buffer( import_stack[ptr].state ); state = LIST_ENTRY( entry, struct import_state, entry );
input_name = import_stack[ptr].input_name; list_remove( &state->entry );
line_number = import_stack[ptr].line_number; parse_only = !list_empty( &import_stack );
import_stack_ptr--;
if (yyin) fclose( yyin );
yy_delete_buffer( YY_CURRENT_BUFFER );
yy_switch_to_buffer( state->buffer );
input_name = state->input_name;
line_number = state->line_number;
free( state );
} }
void push_import( char *import_name ) void push_import( char *import_name )
{ {
struct import_state *state;
FILE *f; FILE *f;
char *path, *name; char *path, *name;
struct import *import; struct import *import;
int ptr = import_stack_ptr;
int ret; int ret;
if (import_stack_ptr == MAX_IMPORT_DEPTH) state = xmalloc( sizeof(struct import_state ));
error_loc("Exceeded max import depth\n"); list_add_head( &import_stack, &state->entry );
parse_only = !list_empty( &import_stack );
import_stack[ptr].state = YY_CURRENT_BUFFER; state->buffer = YY_CURRENT_BUFFER;
import_stack[ptr].input_name = input_name; state->input_name = input_name;
import_stack[ptr].line_number = line_number; state->line_number = line_number;
import_stack_ptr++; input_name = NULL;
yyin = NULL;
/* reset buffer for <<EOF>>, in case import fails or already imported */ /* reset buffer for <<EOF>>, in case import fails or already imported */
yy_scan_string( "" ); yy_scan_string( "" );
...@@ -573,12 +582,12 @@ void push_import( char *import_name ) ...@@ -573,12 +582,12 @@ void push_import( char *import_name )
static void switch_to_acf(void) static void switch_to_acf(void)
{ {
int ptr = import_stack_ptr;
int ret;
char *name; char *name;
int ret;
FILE *f; FILE *f;
assert(import_stack_ptr == 0); if (yyin) fclose( yyin );
yy_delete_buffer( YY_CURRENT_BUFFER );
input_name = acf_name; input_name = acf_name;
acf_name = NULL; acf_name = NULL;
...@@ -595,7 +604,6 @@ static void switch_to_acf(void) ...@@ -595,7 +604,6 @@ static void switch_to_acf(void)
if((f = fopen(name, "r")) == NULL) if((f = fopen(name, "r")) == NULL)
error_loc("Unable to open %s\n", name); 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)); yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
} }
......
...@@ -871,8 +871,6 @@ int main(int argc,char *argv[]) ...@@ -871,8 +871,6 @@ int main(int argc,char *argv[])
init_types(); init_types();
ret = parser_parse(); ret = parser_parse();
fclose(parser_in);
if(ret) { if(ret) {
exit(1); exit(1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment