print the types involved in an error.

This commit is contained in:
christos 2008-04-27 01:45:04 +00:00
parent 4c10a03972
commit cb68ac0e9c
2 changed files with 28 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.35 2008/04/27 00:13:58 christos Exp $ */ /* $NetBSD: err.c,v 1.36 2008/04/27 01:45:04 christos Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: err.c,v 1.35 2008/04/27 00:13:58 christos Exp $"); __RCSID("$NetBSD: err.c,v 1.36 2008/04/27 01:45:04 christos Exp $");
#endif #endif
#include <sys/types.h> #include <sys/types.h>
@ -166,8 +166,8 @@ const char *msgs[] = {
"left operand of '->' must be pointer to struct/union", /* 104 */ "left operand of '->' must be pointer to struct/union", /* 104 */
"non-unique member requires struct/union %s", /* 105 */ "non-unique member requires struct/union %s", /* 105 */
"left operand of '->' must be pointer", /* 106 */ "left operand of '->' must be pointer", /* 106 */
"operands of '%s' have incompatible types", /* 107 */ "operands of '%s' have incompatible types (%s != %s)", /* 107 */
"operand of '%s' has incompatible type", /* 108 */ "operand of '%s' has incompatible type (%s != %s)", /* 108 */
"void type illegal in expression", /* 109 */ "void type illegal in expression", /* 109 */
"pointer to function is not allowed here", /* 110 */ "pointer to function is not allowed here", /* 110 */
"unacceptable operand of '%s'", /* 111 */ "unacceptable operand of '%s'", /* 111 */
@ -230,7 +230,7 @@ const char *msgs[] = {
"array subscript cannot be > %d: %ld", /* 168 */ "array subscript cannot be > %d: %ld", /* 168 */
"precedence confusion possible: parenthesize!", /* 169 */ "precedence confusion possible: parenthesize!", /* 169 */
"first operand must have scalar type, op ? :", /* 170 */ "first operand must have scalar type, op ? :", /* 170 */
"assignment type mismatch", /* 171 */ "assignment type mismatch (%s != %s)", /* 171 */
"too many struct/union initializers", /* 172 */ "too many struct/union initializers", /* 172 */
"too many array initializers, expected %d", /* 173 */ "too many array initializers, expected %d", /* 173 */
"too many initializers", /* 174 */ "too many initializers", /* 174 */
@ -299,7 +299,7 @@ const char *msgs[] = {
"redeclaration of formal parameter %s", /* 237 */ "redeclaration of formal parameter %s", /* 237 */
"initialisation of union is illegal in traditional C", /* 238 */ "initialisation of union is illegal in traditional C", /* 238 */
"constant argument to NOT", /* 239 */ "constant argument to NOT", /* 239 */
"assignment of different structures", /* 240 */ "assignment of different structures (%s != %s)", /* 240 */
"dubious operation on enum, op %s", /* 241 */ "dubious operation on enum, op %s", /* 241 */
"combination of '%s' and '%s', op %s", /* 242 */ "combination of '%s' and '%s', op %s", /* 242 */
"dubious comparison of enums, op %s", /* 243 */ "dubious comparison of enums, op %s", /* 243 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.47 2008/04/27 00:13:58 christos Exp $ */ /* $NetBSD: tree.c,v 1.48 2008/04/27 01:45:04 christos Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint) #if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.47 2008/04/27 00:13:58 christos Exp $"); __RCSID("$NetBSD: tree.c,v 1.48 2008/04/27 01:45:04 christos Exp $");
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -2164,27 +2164,42 @@ static void
incompat(op_t op, tspec_t lt, tspec_t rt) incompat(op_t op, tspec_t lt, tspec_t rt)
{ {
mod_t *mp; mod_t *mp;
int e = 0;
mp = &modtab[op]; mp = &modtab[op];
if (lt == VOID || (mp->m_binary && rt == VOID)) { if (lt == VOID || (mp->m_binary && rt == VOID)) {
/* void type illegal in expression */ /* void type illegal in expression */
error(109); e = 109;
} else if (op == ASSIGN) { } else if (op == ASSIGN) {
if ((lt == STRUCT || lt == UNION) && if ((lt == STRUCT || lt == UNION) &&
(rt == STRUCT || rt == UNION)) { (rt == STRUCT || rt == UNION)) {
/* assignment of different structures */ /* assignment of different structures */
error(240); e = 240;
} else { } else {
/* assignment type mismatch */ /* assignment type mismatch */
error(171); e = 171;
} }
} else if (mp->m_binary) { } else if (mp->m_binary) {
/* operands of %s have incompatible types */ /* operands of %s have incompatible types */
error(107, mp->m_name); e = 107;
} else { } else {
/* operand of %s has incompatible type */ /* operand of %s has incompatible type */
error(108, mp->m_name); e = 108;
}
switch (e) {
case 0:
return;
case 109:
error(e);
return;
case 108:
case 107:
error(e, mp->m_name, basictyname(lt), basictyname(rt));
return;
default:
error(e, basictyname(lt), basictyname(rt));
return;
} }
} }