diff options
-rw-r--r-- | cc.h | 1 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | pp.c | 23 | ||||
-rw-r--r-- | scan.c | 6 |
4 files changed, 28 insertions, 4 deletions
@@ -383,6 +383,7 @@ _Noreturn void error(const struct location *, const char *, ...); void scanfrom(const char *, FILE *); void scanopen(void); +void scansetloc(struct location loc); void scan(struct token *); /* preprocessor */ @@ -139,7 +139,7 @@ static const char target[] = "$target"; static const char *const startfiles[] = {$startfiles}; static const char *const endfiles[] = {$endfiles}; static const char *const preprocesscmd[] = { - "$DEFAULT_PREPROCESSOR", "-P", + "$DEFAULT_PREPROCESSOR", "-E", /* clear preprocessor GNU C version */ "-U", "__GNUC__", @@ -302,15 +302,18 @@ undef(void) static void directive(void) { + struct location newloc; enum ppflags oldflags; - char *name; + char *name = NULL; scan(&tok); if (tok.kind == TNEWLINE) return; /* empty directive */ oldflags = ppflags; ppflags |= PPNEWLINE; - name = tokencheck(&tok, TIDENT, "or newline after '#'"); + if (tok.kind == TNUMBER) + goto line; /* gcc line markers */ + name = tokencheck(&tok, TIDENT, "newline, or number after '#'"); if (strcmp(name, "if") == 0) { error(&tok.loc, "#if directive is not implemented"); } else if (strcmp(name, "ifdef") == 0) { @@ -330,7 +333,21 @@ directive(void) scan(&tok); undef(); } else if (strcmp(name, "line") == 0) { - error(&tok.loc, "#line directive is not implemented"); + scan(&tok); + tokencheck(&tok, TNUMBER, "after #line"); +line: + newloc.line = strtoull(tok.lit, NULL, 0); + scan(&tok); + newloc.file = tok.loc.file; + if (tok.kind == TSTRINGLIT) { + /* XXX: handle escape sequences (reuse string decoding from expr.c) */ + newloc.file = strchr(tok.lit, '"') + 1; + *strchr(newloc.file, '"') = '\0'; + scan(&tok); + } + while (tok.kind == TNUMBER) + scan(&tok); + scansetloc(newloc); } else if (strcmp(name, "error") == 0) { error(&tok.loc, "#error directive is not implemented"); } else if (strcmp(name, "pragma") == 0) { @@ -444,6 +444,12 @@ scanopen(void) } } +void +scansetloc(struct location loc) +{ + scanner->loc = loc; +} + static void scanclose(void) { |