diff --git a/Makefile b/Makefile index f777f50..5645ee8 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ ifdef V VECHO = : else VECHO = echo " " -ARFLAGS = rc +ARFLAGS ?= rc .SILENT: endif diff --git a/dtc-lexer.l b/dtc-lexer.l index 52bed7b..62e42ff 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -38,6 +38,10 @@ LINECOMMENT "//".*\n #include "srcpos.h" #include "dtc-parser.tab.h" +#define MAX_INCLUDE_NESTING 100 +YY_BUFFER_STATE include_stack[MAX_INCLUDE_NESTING]; +int include_stack_pointer = 0; + YYLTYPE yylloc; extern bool treesource_error; @@ -280,11 +284,15 @@ static void push_input_file(const char *filename) { assert(filename); + assert(include_stack_pointer < MAX_INCLUDE_NESTING); + srcfile_push(filename); yyin = current_srcfile->f; - yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE)); + include_stack[include_stack_pointer++] = YY_CURRENT_BUFFER; + + yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); } @@ -293,7 +301,12 @@ static bool pop_input_file(void) if (srcfile_pop() == 0) return false; - yypop_buffer_state(); + assert(include_stack_pointer > 0); + + yy_delete_buffer( YY_CURRENT_BUFFER ); + + yy_switch_to_buffer( include_stack[--include_stack_pointer] ); + yyin = current_srcfile->f; return true; diff --git a/dtc-parser.y b/dtc-parser.y index ca3f500..c43edd5 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -24,6 +24,8 @@ #include "dtc.h" #include "srcpos.h" +YYLTYPE yylloc; + extern int yylex(void); extern void yyerror(char const *s); #define ERROR(loc, ...) \ @@ -129,7 +131,7 @@ headers: | header headers { if ($2 != $1) - ERROR(&@2, "Header flags don't match earlier ones"); + ERROR(&yylloc, "Header flags don't match earlier ones"); $$ = $1; } ; @@ -175,7 +177,7 @@ devicetree: add_label(&target->labels, $2); merge_nodes(target, $4); } else - ERROR(&@3, "Label or path %s not found", $3); + ERROR(&yylloc, "Label or path %s not found", $3); $$ = $1; } | devicetree DT_REF nodedef @@ -185,7 +187,7 @@ devicetree: if (target) merge_nodes(target, $3); else - ERROR(&@2, "Label or path %s not found", $2); + ERROR(&yylloc, "Label or path %s not found", $2); $$ = $1; } | devicetree DT_DEL_NODE DT_REF ';' @@ -195,7 +197,7 @@ devicetree: if (target) delete_node(target); else - ERROR(&@3, "Label or path %s not found", $3); + ERROR(&yylloc, "Label or path %s not found", $3); $$ = $1; @@ -313,7 +315,7 @@ arrayprefix: if ((bits != 8) && (bits != 16) && (bits != 32) && (bits != 64)) { - ERROR(&@2, "Array elements must be" + ERROR(&yylloc, "Array elements must be" " 8, 16, 32 or 64-bits"); bits = 32; } @@ -339,7 +341,7 @@ arrayprefix: * mask), all bits are one. */ if (($2 > mask) && (($2 | mask) != -1ULL)) - ERROR(&@2, "Value out of range for" + ERROR(&yylloc, "Value out of range for" " %d-bit array element", $1.bits); } @@ -354,7 +356,7 @@ arrayprefix: REF_PHANDLE, $2); else - ERROR(&@2, "References are only allowed in " + ERROR(&yylloc, "References are only allowed in " "arrays with 32-bit elements."); $$.data = data_append_integer($1.data, val, $1.bits); @@ -441,7 +443,7 @@ integer_mul: if ($3 != 0) { $$ = $1 / $3; } else { - ERROR(&@$, "Division by zero"); + ERROR(&yylloc, "Division by zero"); $$ = 0; } } @@ -450,7 +452,7 @@ integer_mul: if ($3 != 0) { $$ = $1 % $3; } else { - ERROR(&@$, "Division by zero"); + ERROR(&yylloc, "Division by zero"); $$ = 0; } } @@ -490,7 +492,7 @@ subnodes: } | subnode propdef { - ERROR(&@2, "Properties must precede subnodes"); + ERROR(&yylloc, "Properties must precede subnodes"); YYERROR; } ;