mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
Look for include files in the directory of the including file.
Looking in the diretory dtc is invoked from is not very useful behavior. As part of the code reorganization to implement this, I removed the uniquifying of name storage -- it seemed a rather dubious optimization given likely usage, and some aspects of it would have been mildly awkward to integrate with the new code. Signed-off-by: Scott Wood <scottwood@freescale.com>
This commit is contained in:
parent
f77fe6a20e
commit
910efac4b4
5 changed files with 136 additions and 102 deletions
64
dtc-lexer.l
64
dtc-lexer.l
|
@ -74,7 +74,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<*>\"([^\\"]|\\.)*\" {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("String: %s\n", yytext);
|
||||
yylval.data = data_copy_escape_string(yytext+1,
|
||||
|
@ -84,7 +84,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<*>"/dts-v1/" {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("Keyword: /dts-v1/\n");
|
||||
dts_version = 1;
|
||||
|
@ -93,7 +93,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<*>"/memreserve/" {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("Keyword: /memreserve/\n");
|
||||
BEGIN_DEFAULT();
|
||||
|
@ -101,7 +101,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<*>{LABEL}: {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("Label: %s\n", yytext);
|
||||
yylval.labelref = strdup(yytext);
|
||||
|
@ -110,7 +110,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<INITIAL>[bodh]# {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
if (*yytext == 'b')
|
||||
yylval.cbase = 2;
|
||||
|
@ -125,7 +125,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<INITIAL>[0-9a-fA-F]+ {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
yylval.literal = strdup(yytext);
|
||||
DPRINT("Literal: '%s'\n", yylval.literal);
|
||||
|
@ -133,7 +133,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<V1>[0-9]+|0[xX][0-9a-fA-F]+ {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
yylval.literal = strdup(yytext);
|
||||
DPRINT("Literal: '%s'\n", yylval.literal);
|
||||
|
@ -141,7 +141,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
\&{LABEL} { /* label reference */
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("Ref: %s\n", yytext+1);
|
||||
yylval.labelref = strdup(yytext+1);
|
||||
|
@ -149,7 +149,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
"&{/"{PATHCHAR}+\} { /* new-style path reference */
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
yytext[yyleng-1] = '\0';
|
||||
DPRINT("Ref: %s\n", yytext+2);
|
||||
|
@ -158,7 +158,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<INITIAL>"&/"{PATHCHAR}+ { /* old-style path reference */
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("Ref: %s\n", yytext+1);
|
||||
yylval.labelref = strdup(yytext+1);
|
||||
|
@ -166,7 +166,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<BYTESTRING>[0-9a-fA-F]{2} {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
yylval.byte = strtol(yytext, NULL, 16);
|
||||
DPRINT("Byte: %02x\n", (int)yylval.byte);
|
||||
|
@ -174,7 +174,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<BYTESTRING>"]" {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("/BYTESTRING\n");
|
||||
BEGIN_DEFAULT();
|
||||
|
@ -182,7 +182,7 @@ static int dts_version; /* = 0 */
|
|||
}
|
||||
|
||||
<PROPNODENAME>{PROPNODECHAR}+ {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("PropNodeName: %s\n", yytext);
|
||||
yylval.propnodename = strdup(yytext);
|
||||
|
@ -190,11 +190,10 @@ static int dts_version; /* = 0 */
|
|||
return DT_PROPNODENAME;
|
||||
}
|
||||
|
||||
|
||||
<*>[[:space:]]+ /* eat whitespace */
|
||||
|
||||
<*>"/*"([^*]|\*+[^*/])*\*+"/" {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("Comment: %s\n", yytext);
|
||||
/* eat comments */
|
||||
|
@ -203,7 +202,7 @@ static int dts_version; /* = 0 */
|
|||
<*>"//".*\n /* eat line comments */
|
||||
|
||||
<*>. {
|
||||
yylloc.filenum = srcpos_filenum;
|
||||
yylloc.file = srcpos_file;
|
||||
yylloc.first_line = yylineno;
|
||||
DPRINT("Char: %c (\\x%02x)\n", yytext[0],
|
||||
(unsigned)yytext[0]);
|
||||
|
@ -227,8 +226,7 @@ static int dts_version; /* = 0 */
|
|||
*/
|
||||
|
||||
struct incl_file {
|
||||
int filenum;
|
||||
FILE *file;
|
||||
struct dtc_file *file;
|
||||
YY_BUFFER_STATE yy_prev_buf;
|
||||
int yy_prev_lineno;
|
||||
struct incl_file *prev;
|
||||
|
@ -247,8 +245,9 @@ static int incl_depth = 0;
|
|||
|
||||
int push_input_file(const char *filename)
|
||||
{
|
||||
FILE *f;
|
||||
struct incl_file *incl_file;
|
||||
struct dtc_file *newfile;
|
||||
struct search_path search, *searchptr = NULL;
|
||||
|
||||
if (!filename) {
|
||||
yyerror("No include file name given.");
|
||||
|
@ -260,7 +259,19 @@ int push_input_file(const char *filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
f = dtc_open_file(filename);
|
||||
if (srcpos_file) {
|
||||
search.dir = srcpos_file->dir;
|
||||
search.next = NULL;
|
||||
search.prev = NULL;
|
||||
searchptr = &search;
|
||||
}
|
||||
|
||||
newfile = dtc_open_file(filename, searchptr);
|
||||
if (!newfile) {
|
||||
yyerrorf("Couldn't open \"%s\": %s",
|
||||
filename, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
incl_file = malloc(sizeof(struct incl_file));
|
||||
if (!incl_file) {
|
||||
|
@ -273,8 +284,7 @@ int push_input_file(const char *filename)
|
|||
*/
|
||||
incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
|
||||
incl_file->yy_prev_lineno = yylineno;
|
||||
incl_file->filenum = srcpos_filenum;
|
||||
incl_file->file = yyin;
|
||||
incl_file->file = srcpos_file;
|
||||
incl_file->prev = incl_file_stack;
|
||||
|
||||
incl_file_stack = incl_file;
|
||||
|
@ -282,9 +292,9 @@ int push_input_file(const char *filename)
|
|||
/*
|
||||
* Establish new context.
|
||||
*/
|
||||
srcpos_filenum = lookup_file_name(filename, 0);
|
||||
srcpos_file = newfile;
|
||||
yylineno = 1;
|
||||
yyin = f;
|
||||
yyin = newfile->file;
|
||||
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
|
||||
|
||||
return 1;
|
||||
|
@ -298,7 +308,7 @@ int pop_input_file(void)
|
|||
if (incl_file_stack == 0)
|
||||
return 0;
|
||||
|
||||
fclose(yyin);
|
||||
dtc_close_file(srcpos_file);
|
||||
|
||||
/*
|
||||
* Pop.
|
||||
|
@ -313,8 +323,8 @@ int pop_input_file(void)
|
|||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
yy_switch_to_buffer(incl_file->yy_prev_buf);
|
||||
yylineno = incl_file->yy_prev_lineno;
|
||||
srcpos_filenum = incl_file->filenum;
|
||||
yyin = incl_file->file;
|
||||
srcpos_file = incl_file->file;
|
||||
yyin = incl_file->file ? incl_file->file->file : NULL;
|
||||
|
||||
/*
|
||||
* Free old state.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue