[PATCH 2/2] dtc: cpp co-existence: add support for #line directives
Stephen Warren
swarren at wwwdotorg.org
Tue Sep 25 08:51:17 EST 2012
From: Stephen Warren <swarren at nvidia.com>
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 at nvidia.com>
---
dtc-lexer.l | 21 +++++++++++++++++++++
srcpos.c | 6 ++++++
srcpos.h | 2 ++
tests/propname_escapes.dts | 7 +++++++
4 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/dtc-lexer.l b/dtc-lexer.l
index edbeb86..506a1bf 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}|" "){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>> {
if (!pop_input_file()) {
yyterminate();
diff --git a/srcpos.c b/srcpos.c
index 3ee523d..246ab4b 100644
--- a/srcpos.c
+++ b/srcpos.c
@@ -328,3 +328,9 @@ srcpos_warn(struct srcpos *pos, char const *fmt, ...)
va_end(va);
}
+
+void srcpos_set_line(char *f, int l)
+{
+ current_srcfile->name = f;
+ current_srcfile->lineno = l;
+}
diff --git a/srcpos.h b/srcpos.h
index 5617916..93a2712 100644
--- a/srcpos.h
+++ b/srcpos.h
@@ -113,4 +113,6 @@ extern void srcpos_error(struct srcpos *pos, char const *, ...)
extern void srcpos_warn(struct srcpos *pos, char const *, ...)
__attribute__((format(printf, 2, 3)));
+extern void srcpos_set_line(char *f, int l);
+
#endif /* _SRCPOS_H_ */
diff --git a/tests/propname_escapes.dts b/tests/propname_escapes.dts
index 9f70618..9f5793d 100644
--- a/tests/propname_escapes.dts
+++ b/tests/propname_escapes.dts
@@ -1,5 +1,12 @@
/dts-v1/;
+/* common format */
+#line 3 "foo.dts"
+/* newer gcc format */
+# 6 "bar.dts"
+/* newer gcc sometimes uses */
+# 9 "baz.dts" 1
+
/ {
#address-cells = <1>;
\#gpio-cells = <2>;
--
1.7.0.4
More information about the devicetree-discuss
mailing list