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 <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
committed by
Jon Loeliger
parent
1ff3d3f8de
commit
1b6d1941dc
21
dtc-lexer.l
21
dtc-lexer.l
@@ -71,6 +71,27 @@ static int pop_input_file(void);
|
|||||||
push_input_file(name);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
<*><<EOF>> {
|
<*><<EOF>> {
|
||||||
if (!pop_input_file()) {
|
if (!pop_input_file()) {
|
||||||
yyterminate();
|
yyterminate();
|
||||||
|
|||||||
6
srcpos.c
6
srcpos.c
@@ -328,3 +328,9 @@ srcpos_warn(struct srcpos *pos, char const *fmt, ...)
|
|||||||
|
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void srcpos_set_line(char *f, int l)
|
||||||
|
{
|
||||||
|
current_srcfile->name = f;
|
||||||
|
current_srcfile->lineno = l;
|
||||||
|
}
|
||||||
|
|||||||
2
srcpos.h
2
srcpos.h
@@ -113,4 +113,6 @@ extern void srcpos_error(struct srcpos *pos, char const *, ...)
|
|||||||
extern void srcpos_warn(struct srcpos *pos, char const *, ...)
|
extern void srcpos_warn(struct srcpos *pos, char const *, ...)
|
||||||
__attribute__((format(printf, 2, 3)));
|
__attribute__((format(printf, 2, 3)));
|
||||||
|
|
||||||
|
extern void srcpos_set_line(char *f, int l);
|
||||||
|
|
||||||
#endif /* _SRCPOS_H_ */
|
#endif /* _SRCPOS_H_ */
|
||||||
|
|||||||
11
tests/line_directives.dts
Normal file
11
tests/line_directives.dts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/* common format */
|
||||||
|
#line 3 "foo.dts"
|
||||||
|
/* newer gcc format */
|
||||||
|
# 9 "baz.dts" 1
|
||||||
|
/* flags are optional */
|
||||||
|
# 6 "bar.dts"
|
||||||
|
|
||||||
|
/ {
|
||||||
|
};
|
||||||
@@ -257,6 +257,8 @@ dtc_tests () {
|
|||||||
run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb propname_escapes.dts
|
run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb propname_escapes.dts
|
||||||
run_test propname_escapes dtc_escapes.test.dtb
|
run_test propname_escapes dtc_escapes.test.dtb
|
||||||
|
|
||||||
|
run_dtc_test -I dts -O dtb -o line_directives.test.dtb line_directives.dts
|
||||||
|
|
||||||
run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts
|
run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts
|
||||||
run_test string_escapes dtc_escapes.test.dtb
|
run_test string_escapes dtc_escapes.test.dtb
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user