From 7ea7654db6e827038e38c3589c8d5b314db3fcb2 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Mon, 18 May 2020 20:28:51 -0700 Subject: fix: line accounting is less buggy --- sys/cmd/cc/pp.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'sys/cmd/cc/pp.c') diff --git a/sys/cmd/cc/pp.c b/sys/cmd/cc/pp.c index ceb9d66..30bb3d4 100644 --- a/sys/cmd/cc/pp.c +++ b/sys/cmd/cc/pp.c @@ -62,7 +62,7 @@ defmacro(Lexer *lx, string name, string macro) { Sym *mac; - printf("DEFINING MACRO %s\n", name); + printf("DEFINING MACRO %s, ON LINE %d\n", name, lx->pos.line); mac = define(&lx->sym, name, Smacro); mac->macro = macro; @@ -400,6 +400,9 @@ ppend(Lexer *lx) b = getnsbyte(lx); } while (b > 0 && b != '\n'); + if (b == '\n') + lx->pos.line++; + return 0; } @@ -409,15 +412,17 @@ static error ppund(Lexer *lx) { - Sym *sym; string s; + error err; s = ident(lx); intern(&s); - sym = lookup(&lx->sym, s); - if (!sym) { + printf("FORGETTING %s\n", s); + err = forget(&lx->sym, s); + if (err) { errorat(lx->pos, "attempting to undefine unrecognized symbol '%s'", s); + return err; } ppend(lx); return 0; @@ -443,7 +448,7 @@ ppdef(Lexer *lx) sym = lookup(&lx->sym, s); if (sym) { errorat(lx->pos, "macro redefined: '%s'", sym->name); - goto Bad; + // goto Bad; } n = 0; @@ -537,6 +542,7 @@ ppdef(Lexer *lx) b = getbyte(lx); /* unix */ if (b == '\n') { + lx->pos.line++; b = getbyte(lx); continue; } @@ -544,23 +550,24 @@ ppdef(Lexer *lx) if (b == '\r') { b = getbyte(lx); if (b == '\n') { + lx->pos.line++; b = getbyte(lx); continue; } } str·appendbyte(&buf, '\\'); } - if (b == '\n') + if (b == '\n') { + lx->pos.line++; break; + } if (b == '#' && n > 0) { - panicf("needs implementation"); + panicf("tokenizer needs implementation"); } str·appendbyte(&buf, b); b = getbyte(lx); - if (b == '\n') - lx->pos.line++; if (b == EOF) { errorat(lx->pos, "eof found in macro '%s'", s); goto Bad; @@ -797,7 +804,7 @@ ppinc(Lexer *lx) lx->buf[0] = '\0'; strcat(lx->buf, s); - if (io·exists(lx->buf, ReadOK)) { + if (os·exists(lx->buf, ReadOK)) { break; } } @@ -833,7 +840,7 @@ ppprag(Lexer *lx) goto Bad; } if (strcmp(s, "once") == 0) { - lx->io->kind |= IOonce; + pushomit(lx->io->path); return 0; } Bad: @@ -882,8 +889,10 @@ Skip: if (c != '#') { if (!isspace(c)) b = 0; - if (c == '\n') + if (c == '\n') { + lx->pos.line++; b = 1; + } continue; } if (!b) -- cgit v1.2.1