Browse Source

dtc: Remove ugly include stack abuse

Currently, dt_from_source() uses push_input_file() to set up the
initial input file for the lexer.  That sounds sensible - put the
outermost input file at the bottom of the stack - until you realise
that what it *actually* does is pushes the current, uninitialized,
lexer input state onto the stack, then sets up the new lexer input.

That necessitates an extra check in pop_input_file(), rather than
signalling termination in the natural way when the include stack is
empty, it has to check when it pops the bogus uninitialized state off
the stack.  Ick.

With that fixed, push_input_file(), pop_input_file() and
incl_file_stack itself become local to the lexer, so make them static.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 17 years ago committed by Jon Loeliger
parent
commit
8a88ad8bad
  1. 12
      dtc-lexer.l
  2. 3
      srcpos.h
  3. 3
      treesource.c

12
dtc-lexer.l

@ -52,6 +52,9 @@ static int dts_version; /* = 0 */ @@ -52,6 +52,9 @@ static int dts_version; /* = 0 */
DPRINT("<V1>\n"); \
BEGIN(V1); \
}

static void push_input_file(const char *filename);
static int pop_input_file(void);
%}

%%
@ -229,7 +232,7 @@ struct incl_file { @@ -229,7 +232,7 @@ struct incl_file {
struct incl_file *prev;
};

struct incl_file *incl_file_stack;
static struct incl_file *incl_file_stack;


/*
@ -240,7 +243,7 @@ struct incl_file *incl_file_stack; @@ -240,7 +243,7 @@ struct incl_file *incl_file_stack;
static int incl_depth = 0;


void push_input_file(const char *filename)
static void push_input_file(const char *filename)
{
struct incl_file *incl_file;
struct dtc_file *newfile;
@ -282,7 +285,7 @@ void push_input_file(const char *filename) @@ -282,7 +285,7 @@ void push_input_file(const char *filename)
}


int pop_input_file(void)
static int pop_input_file(void)
{
struct incl_file *incl_file;

@ -312,8 +315,5 @@ int pop_input_file(void) @@ -312,8 +315,5 @@ int pop_input_file(void)
*/
free(incl_file);

if (YY_CURRENT_BUFFER == 0)
return 0;

return 1;
}

3
srcpos.h

@ -75,9 +75,6 @@ extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2))); @@ -75,9 +75,6 @@ extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));

extern struct dtc_file *srcpos_file;

extern void push_input_file(const char *filename);
extern int pop_input_file(void);

struct search_path {
const char *dir; /* NULL for current directory */
struct search_path *prev, *next;

3
treesource.c

@ -32,7 +32,8 @@ struct boot_info *dt_from_source(const char *fname) @@ -32,7 +32,8 @@ struct boot_info *dt_from_source(const char *fname)
the_boot_info = NULL;
treesource_error = 0;

push_input_file(fname);
srcpos_file = dtc_open_file(fname, NULL);
yyin = srcpos_file->file;

if (yyparse() != 0)
return NULL;

Loading…
Cancel
Save