aboutsummaryrefslogtreecommitdiffhomepage
path: root/c
diff options
context:
space:
mode:
author lemon<lsof@mailbox.org>2025-11-08 10:19:29 +0100
committer lemon<lsof@mailbox.org>2025-11-08 12:45:31 +0100
commit27581faf3d34ec06e3256d967d27888121943898 (patch)
tree1a106b6d84dccc560e038187c53fc1c37ef242d7 /c
parenta5cb382018dade88d20f385ba7557f80902b52c3 (diff)
lex: #warning and #error
Diffstat (limited to 'c')
-rw-r--r--c/lex.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/c/lex.c b/c/lex.c
index 7d045f0..06457c5 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -1650,6 +1650,17 @@ pppragma(struct lexer *lx, const struct span *span0)
}
}
+static void
+ppdiag(struct lexer *lx, const struct span *span0, bool err)
+{
+ const uchar *p = getfile(lx->fileid)->p;
+ uint off = lx->chridx, end;
+ ppskipline(lx);
+ end = lx->chridx;
+ while (off < end && aisspace(p[off])) ++off;
+ (err ? error : warn)(span0, "%S", p + off, end - off);
+}
+
enum directive {
PPXXX,
/* !sorted */
@@ -1750,8 +1761,8 @@ lex(struct lexer *lx, struct token *tk_)
case PPINCLUDE: ppinclude(lx, &tk->span); break;
case PPLINE: break;
case PPPRAGMA: pppragma(lx, &tk->span); break;
- case PPWARNING: break;
- case PPERROR: break;
+ case PPWARNING: ppdiag(lx, &tk->span, 0); break;
+ case PPERROR: ppdiag(lx, &tk->span, 1); break;
default: assert(0&&"nyi");
}
} else {