From 1b6d1941dc5b589632c254ee6e960404d7cef5f2 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 27 Sep 2012 17:11:05 -0600 Subject: dtc: cpp co-existence: add support for #line directives Line control directives of the following formats are supported: #line LINE "FILE" # LINE "FILE" [FLAGS] This allows dtc to consume the output of pre-processors, and to provide error messages that refer to the original filename, including taking into account any #include directives that the pre-processor may have performed. Signed-off-by: Stephen Warren Acked-by: David Gibson --- dtc-lexer.l | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'dtc-lexer.l') diff --git a/dtc-lexer.l b/dtc-lexer.l index edbeb86..254d5af 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -71,6 +71,27 @@ static int pop_input_file(void); push_input_file(name); } +<*>^"#"(line)?{WS}+[0-9]+{WS}+{STRING}({WS}+[0-9]+)? { + char *line, *tmp, *fn; + /* skip text before line # */ + line = yytext; + while (!isdigit(*line)) + line++; + /* skip digits in line # */ + tmp = line; + while (!isspace(*tmp)) + tmp++; + /* "NULL"-terminate line # */ + *tmp = '\0'; + /* start of filename */ + fn = strchr(tmp + 1, '"') + 1; + /* strip trailing " from filename */ + tmp = strchr(fn, '"'); + *tmp = 0; + /* -1 since #line is the number of the next line */ + srcpos_set_line(xstrdup(fn), atoi(line) - 1); + } + <*><> { if (!pop_input_file()) { yyterminate(); -- cgit v1.2.1