cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit e0b772b836265b77686e9a7aa8ad01bb1fca53e7
parent 9b287512602f9f7ce66eeec228372135df5753a9
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 23 Apr 2019 21:05:58 -0700

Improve some error messages

Diffstat:
Mexpr.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/expr.c b/expr.c @@ -132,9 +132,9 @@ mkbinaryexpr(struct location *loc, enum tokenkind op, struct expr *l, struct exp case TLOR: case TLAND: if (!(lp & PROPSCALAR)) - error(loc, "left-hand-side of logical operator must be scalar"); + error(loc, "left operand of '%s' operator must be scalar", tokstr[op]); if (!(rp & PROPSCALAR)) - error(loc, "right-hand-side of logical operator must be scalar"); + error(loc, "right operand of '%s' operator must be scalar", tokstr[op]); l = exprconvert(l, &typebool); r = exprconvert(r, &typebool); t = &typeint; @@ -201,13 +201,13 @@ mkbinaryexpr(struct location *loc, enum tokenkind op, struct expr *l, struct exp case TMUL: case TDIV: if (!(lp & PROPARITH) || !(rp & PROPARITH)) - error(loc, "operands to '%c' operator must be arithmetic", op == TMUL ? '*' : '/'); + error(loc, "operands to '%s' operator must be arithmetic", tokstr[op]); t = commonreal(&l, &r); break; case TSHL: case TSHR: if (!(lp & PROPINT) || !(rp & PROPINT)) - error(loc, "operands to '%s' operator must be integer", op == TSHL ? "<<" : ">>"); + error(loc, "operands to '%s' operator must be integer", tokstr[op]); l = exprconvert(l, typeintpromote(l->type)); r = exprconvert(r, typeintpromote(r->type)); t = l->type; @@ -373,7 +373,7 @@ primaryexpr(struct scope *s) else if (tolower(end[0]) == 'l' && !end[1]) e->type = &typeldouble; else - error(&tok.loc, "invalid floating constant suffix '%s'", *end); + error(&tok.loc, "invalid floating constant suffix '%s'", end); } else { /* integer constant */ errno = 0; @@ -616,14 +616,14 @@ postfixexpr(struct scope *s, struct expr *r) case TARROW: op = tok.kind; if (r->type->kind != TYPEPOINTER) - error(&tok.loc, "arrow operator must be applied to pointer to struct/union"); + error(&tok.loc, "'%s' operator must be applied to pointer to struct/union", tokstr[op]); t = r->type->base; tq = r->type->qual; if (t->kind != TYPESTRUCT && t->kind != TYPEUNION) - error(&tok.loc, "arrow operator must be applied to pointer to struct/union"); + error(&tok.loc, "'%s' operator must be applied to pointer to struct/union", tokstr[op]); next(); if (tok.kind != TIDENT) - error(&tok.loc, "expected identifier after '->' operator"); + error(&tok.loc, "expected identifier after '%s' operator", tokstr[op]); lvalue = op == TARROW || r->unary.base->lvalue; r = exprconvert(r, mkpointertype(&typechar, QUALNONE)); offset = 0;