improved type-checking, fixed preprocessor bug, fixed syntax bug
authoreck <none@none>
Mon, 27 Nov 1989 11:37:11 +0000 (11:37 +0000)
committereck <none@none>
Mon, 27 Nov 1989 11:37:11 +0000 (11:37 +0000)
lang/cem/cemcom.ansi/ch3.c
lang/cem/cemcom.ansi/ch3mon.c
lang/cem/cemcom.ansi/domacro.c
lang/cem/cemcom.ansi/expression.g
lang/cem/cemcom.ansi/replace.c

index 3a880c9..1b1e6da 100644 (file)
@@ -170,7 +170,7 @@ ch3cast(expp, oper, tp)
                expression of class Type.
        */
        register struct type *oldtp;
-       int qual_lev;
+       int qual_lev, ascompat = 0;
 
        if (oper == RETURN && tp->tp_fund == VOID) {
                expr_strict(*expp, "return <expression> in function returning void");
@@ -196,14 +196,28 @@ ch3cast(expp, oper, tp)
                return;
        }
 #endif NOBITFIELD
-       if (oper == CASTAB || oper == '=' || oper == RETURN) {
-               qual_lev = -2;
-       } else if (oper == CAST) qual_lev = -999;       /* ??? hack */
-       else qual_lev = -1;
+       switch (oper) {
+       default:        qual_lev = -1; break;
+       case CAST:      qual_lev = -999; break;         /* ??? hack */
+       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)) {
                /* 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)
                            != oldtp->tp_up->tp_typequal) {
                                expr_strict( *expp, "qualifier error");
@@ -377,13 +391,10 @@ equal_type(tp, otp, qual_lev)
        if (!tp
            || !otp
            || (tp->tp_fund != otp->tp_fund)
+           || (tp->tp_size != otp->tp_size)
            || (tp->tp_unsigned != otp->tp_unsigned)
            || (tp->tp_align != otp->tp_align))
                return 0;
-       if (tp->tp_fund != ARRAY) {
-               if (tp->tp_size != otp->tp_size)
-                       return 0;
-       }
        if (qual_lev >= 0) {
                if (tp->tp_typequal != otp->tp_typequal)
                        strict("illegal qualifiers");
index e3ed328..eeab430 100644 (file)
@@ -28,7 +28,8 @@ ch3mon(oper, expp)
        */
        register struct expr *expr;
 
-       any2opnd(expp, oper);
+       if (oper != PLUSPLUS && oper != MINMIN)
+               any2opnd(expp, oper);
 
        switch (oper)   {
        case '*':                       /* 3.3.3.2 */
index 8f6f0b2..f6b5270 100644 (file)
@@ -604,6 +604,7 @@ get_text(formals, length)
        c = GetChar();
 
        repl->r_ptr = repl->r_text = Malloc(repl->r_size = ITEXTSIZE);
+       *repl->r_ptr = '\0';
        while ((c != EOI) && (class(c) != STNL)) {
                if (BLANK(c)) {
                        if (!blank++) add2repl(repl, ' ');
index 2aad3bb..53933cf 100644 (file)
@@ -92,15 +92,14 @@ postfix_expression(register struct expr **expp;)
        |
                [ '.' | ARROW ]                 { oper = DOT; }
                identifier(&idf)                { ch3sel(expp, oper, idf); }
-       ]*
-       [
+       |
                [
                        PLUSPLUS        { oper = POSTINCR; }
                |
                        MINMIN          { oper = POSTDECR; }
                ]
                    { ch3incr(expp, oper); }
-       ]?
+       ]*
 ;
 
 parameter_list(struct expr **expp;)
index d4a0c89..7fae3a9 100644 (file)
@@ -549,6 +549,7 @@ macro2buffer(repl, idf, args)
        int err = 0;
        char *stringify();
 
+       ASSERT(ptr[idf->id_macro->mc_length] == '\0');
        while (*ptr) {
            if (*ptr == '\'' || *ptr == '"') {
                register int delim = *ptr;