improved type-checking, fixed preprocessor bug, fixed syntax bug
This commit is contained in:
parent
5d81b090b9
commit
671556cfc4
5 changed files with 27 additions and 14 deletions
|
@ -170,7 +170,7 @@ ch3cast(expp, oper, tp)
|
||||||
expression of class Type.
|
expression of class Type.
|
||||||
*/
|
*/
|
||||||
register struct type *oldtp;
|
register struct type *oldtp;
|
||||||
int qual_lev;
|
int qual_lev, ascompat = 0;
|
||||||
|
|
||||||
if (oper == RETURN && tp->tp_fund == VOID) {
|
if (oper == RETURN && tp->tp_fund == VOID) {
|
||||||
expr_strict(*expp, "return <expression> in function returning void");
|
expr_strict(*expp, "return <expression> in function returning void");
|
||||||
|
@ -196,14 +196,28 @@ ch3cast(expp, oper, tp)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif NOBITFIELD
|
#endif NOBITFIELD
|
||||||
if (oper == CASTAB || oper == '=' || oper == RETURN) {
|
switch (oper) {
|
||||||
qual_lev = -2;
|
default: qual_lev = -1; break;
|
||||||
} else if (oper == CAST) qual_lev = -999; /* ??? hack */
|
case CAST: qual_lev = -999; break; /* ??? hack */
|
||||||
else qual_lev = -1;
|
case CASTAB:
|
||||||
|
case '=':
|
||||||
|
case RETURN: ascompat = 1; /* assignment compatibility */
|
||||||
|
/* fallthrough */
|
||||||
|
case '-':
|
||||||
|
case '<':
|
||||||
|
case '>':
|
||||||
|
case LESSEQ:
|
||||||
|
case GREATEREQ:
|
||||||
|
case EQUAL:
|
||||||
|
case NOTEQUAL:
|
||||||
|
case ':':
|
||||||
|
qual_lev = -2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (equal_type(tp, oldtp, qual_lev)) {
|
if (equal_type(tp, oldtp, qual_lev)) {
|
||||||
/* life is easy */
|
/* life is easy */
|
||||||
if (qual_lev == -2 && tp->tp_fund == POINTER) {
|
if (ascompat && tp->tp_fund == POINTER) {
|
||||||
if ((tp->tp_up->tp_typequal & oldtp->tp_up->tp_typequal)
|
if ((tp->tp_up->tp_typequal & oldtp->tp_up->tp_typequal)
|
||||||
!= oldtp->tp_up->tp_typequal) {
|
!= oldtp->tp_up->tp_typequal) {
|
||||||
expr_strict( *expp, "qualifier error");
|
expr_strict( *expp, "qualifier error");
|
||||||
|
@ -377,13 +391,10 @@ equal_type(tp, otp, qual_lev)
|
||||||
if (!tp
|
if (!tp
|
||||||
|| !otp
|
|| !otp
|
||||||
|| (tp->tp_fund != otp->tp_fund)
|
|| (tp->tp_fund != otp->tp_fund)
|
||||||
|
|| (tp->tp_size != otp->tp_size)
|
||||||
|| (tp->tp_unsigned != otp->tp_unsigned)
|
|| (tp->tp_unsigned != otp->tp_unsigned)
|
||||||
|| (tp->tp_align != otp->tp_align))
|
|| (tp->tp_align != otp->tp_align))
|
||||||
return 0;
|
return 0;
|
||||||
if (tp->tp_fund != ARRAY) {
|
|
||||||
if (tp->tp_size != otp->tp_size)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (qual_lev >= 0) {
|
if (qual_lev >= 0) {
|
||||||
if (tp->tp_typequal != otp->tp_typequal)
|
if (tp->tp_typequal != otp->tp_typequal)
|
||||||
strict("illegal qualifiers");
|
strict("illegal qualifiers");
|
||||||
|
|
|
@ -28,7 +28,8 @@ ch3mon(oper, expp)
|
||||||
*/
|
*/
|
||||||
register struct expr *expr;
|
register struct expr *expr;
|
||||||
|
|
||||||
any2opnd(expp, oper);
|
if (oper != PLUSPLUS && oper != MINMIN)
|
||||||
|
any2opnd(expp, oper);
|
||||||
|
|
||||||
switch (oper) {
|
switch (oper) {
|
||||||
case '*': /* 3.3.3.2 */
|
case '*': /* 3.3.3.2 */
|
||||||
|
|
|
@ -604,6 +604,7 @@ get_text(formals, length)
|
||||||
c = GetChar();
|
c = GetChar();
|
||||||
|
|
||||||
repl->r_ptr = repl->r_text = Malloc(repl->r_size = ITEXTSIZE);
|
repl->r_ptr = repl->r_text = Malloc(repl->r_size = ITEXTSIZE);
|
||||||
|
*repl->r_ptr = '\0';
|
||||||
while ((c != EOI) && (class(c) != STNL)) {
|
while ((c != EOI) && (class(c) != STNL)) {
|
||||||
if (BLANK(c)) {
|
if (BLANK(c)) {
|
||||||
if (!blank++) add2repl(repl, ' ');
|
if (!blank++) add2repl(repl, ' ');
|
||||||
|
|
|
@ -92,15 +92,14 @@ postfix_expression(register struct expr **expp;)
|
||||||
|
|
|
|
||||||
[ '.' | ARROW ] { oper = DOT; }
|
[ '.' | ARROW ] { oper = DOT; }
|
||||||
identifier(&idf) { ch3sel(expp, oper, idf); }
|
identifier(&idf) { ch3sel(expp, oper, idf); }
|
||||||
]*
|
|
|
||||||
[
|
|
||||||
[
|
[
|
||||||
PLUSPLUS { oper = POSTINCR; }
|
PLUSPLUS { oper = POSTINCR; }
|
||||||
|
|
|
|
||||||
MINMIN { oper = POSTDECR; }
|
MINMIN { oper = POSTDECR; }
|
||||||
]
|
]
|
||||||
{ ch3incr(expp, oper); }
|
{ ch3incr(expp, oper); }
|
||||||
]?
|
]*
|
||||||
;
|
;
|
||||||
|
|
||||||
parameter_list(struct expr **expp;)
|
parameter_list(struct expr **expp;)
|
||||||
|
|
|
@ -549,6 +549,7 @@ macro2buffer(repl, idf, args)
|
||||||
int err = 0;
|
int err = 0;
|
||||||
char *stringify();
|
char *stringify();
|
||||||
|
|
||||||
|
ASSERT(ptr[idf->id_macro->mc_length] == '\0');
|
||||||
while (*ptr) {
|
while (*ptr) {
|
||||||
if (*ptr == '\'' || *ptr == '"') {
|
if (*ptr == '\'' || *ptr == '"') {
|
||||||
register int delim = *ptr;
|
register int delim = *ptr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue