fixed null-pointer constants and SkipToNewLine()
authoreck <none@none>
Tue, 12 Dec 1989 12:52:03 +0000 (12:52 +0000)
committereck <none@none>
Tue, 12 Dec 1989 12:52:03 +0000 (12:52 +0000)
lang/cem/cemcom.ansi/LLlex.c
lang/cem/cemcom.ansi/arith.c
lang/cem/cemcom.ansi/ch3.c
lang/cem/cemcom.ansi/ch3bin.c
lang/cem/cemcom.ansi/ch3mon.c
lang/cem/cemcom.ansi/expression.g
lang/cem/cemcom.ansi/skip.c

index 443f6cd..12f08f4 100644 (file)
@@ -115,7 +115,6 @@ GetToken(ptok)
        */
        char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
        register int ch, nch;
-       int nlflag = 0;
 
        token_nmb++;
 
@@ -590,7 +589,7 @@ quoted(ch)
 
                        for (;;) {
                                ch = GetChar();
-                               if (vch = hex_val(ch), vch == -1)
+                               if ((vch = hex_val(ch)) == -1)
                                        break;
                                hex = hex * 16 + vch;
                        }
index ece5613..dea510f 100644 (file)
@@ -135,21 +135,31 @@ relbalance(e1p, oper, e2p)
        register struct expr **e1p, **e2p;
 {
        /*      The expressions *e1p and *e2p are balanced to be operands
-               of the relational operator oper.
+               of the relational operator oper, or the ':'.
+               Care is taken to switch the operands in case of a
+               null-pointer constant. This is done so that ch3cast()
+               allows assignments of a null-pointer to a function
+               pointer.
        */
-       if ((*e1p)->ex_type->tp_fund == FUNCTION)
-               function2pointer(*e1p);
-       if ((*e2p)->ex_type->tp_fund == FUNCTION)
-               function2pointer(*e2p);
-       if ((*e1p)->ex_type->tp_fund == POINTER)
-               ch3pointer(e2p, oper, (*e1p)->ex_type);
-       else if ((*e2p)->ex_type->tp_fund == POINTER)
-               ch3pointer(e1p, oper, (*e2p)->ex_type);
-       else if ((*e1p)->ex_type == (*e2p)->ex_type
-               && (*e1p)->ex_type->tp_fund == ENUM) {}
+       register struct expr *e1 = *e1p, *e2 = *e2p;
+       struct expr *tmpexpr;
+
+       if (e1->ex_type->tp_fund == POINTER
+           && is_cp_cst(e1)
+           && e1->VL_VALUE == 0) {
+               tmpexpr = e1;
+               e1 = e2;
+               e2 = tmpexpr;
+       }
+       if (e1->ex_type->tp_fund == POINTER)
+               ch3pointer(e2p, oper, e1->ex_type);
+       else if (e2->ex_type->tp_fund == POINTER)
+               ch3pointer(e1p, oper, e2->ex_type);
+       else if (e1->ex_type == e2->ex_type
+               && e1->ex_type->tp_fund == ENUM) {}
        else if (oper == ':'
-                   && (*e1p)->ex_type->tp_fund == VOID
-                   && (*e2p)->ex_type->tp_fund == VOID) {}
+                   && e1->ex_type->tp_fund == VOID
+                   && e2->ex_type->tp_fund == VOID) {}
        else
                arithbalance(e1p, oper, e2p);
 }
index 6960f9b..4808442 100644 (file)
@@ -177,8 +177,9 @@ ch3cast(expp, oper, tp)
                (*expp)->ex_type = void_type;
                return;
        }
-       if ((*expp)->ex_type->tp_fund == FUNCTION)
+       if ((*expp)->ex_type->tp_fund == FUNCTION) {
                function2pointer(*expp);
+       }
        if ((*expp)->ex_type->tp_fund == ARRAY)
                array2pointer(*expp);
        if ((*expp)->ex_class == String)
@@ -287,6 +288,7 @@ ch3cast(expp, oper, tp)
                case '=':
                case CASTAB:
                case RETURN:
+               case ':':
                    if (tp->tp_up && oldtp->tp_up) {
                            if (tp->tp_up->tp_fund == VOID
                                && oldtp->tp_up->tp_fund != FUNCTION) {
@@ -296,13 +298,17 @@ ch3cast(expp, oper, tp)
                                && tp->tp_up->tp_fund != FUNCTION) {
                                break;  /* switch */
                            }
+                           if (oldtp->tp_up->tp_fund == VOID
+                               && is_cp_cst(*expp)
+                               && (*expp)->VL_VALUE == (arith)0)
+                               break;  /* switch */
                    }
                    /* falltrough */
                default:
                    if (oper == CASTAB)
-                           expr_warning(*expp, "incompatible pointers");
+                           expr_strict(*expp, "incompatible pointers in call");
                    else
-                           expr_warning(*expp, "incompatible pointers in %s",
+                           expr_strict(*expp, "incompatible pointers in %s",
                                                        symbol2str(oper));
                    break;
                case CAST: break;
index 10a9a45..6a65a7a 100644 (file)
@@ -70,25 +70,11 @@ ch3bin(expp, oper, expr)
                break;
 
        case '(':                               /* 3.3.2.2 */
-#if 1
-               if (    expp_tp->tp_fund == POINTER &&
-                       expp_tp->tp_up->tp_fund == FUNCTION
-               )       {
+               if (expp_tp->tp_fund == POINTER
+                   && expp_tp->tp_up->tp_fund == FUNCTION)     {
                        ch3mon('*', expp);
                        expp_tp = (*expp)->ex_type;
                }
-#else
-               if (expp_tp->tp_fund != POINTER
-                   || expp->tp_up->tp_fund != FUNCTION) {
-                       expr_error(*expp, "call of non-function (%s)",
-                               symbol2str(expp_tp->tp_fund));
-                       /* leave the expression; it may still serve */
-                       free_expression(expr);  /* there go the parameters */
-                       *expp = new_oper(error_type,
-                                       *expp, '(', (struct expr *)0);
-               }
-#endif
-#if 1
                if (expp_tp->tp_fund != FUNCTION)       {
                        expr_error(*expp, "call of non-function (%s)",
                                symbol2str(expp_tp->tp_fund));
@@ -97,7 +83,6 @@ ch3bin(expp, oper, expr)
                        *expp = new_oper(error_type,
                                        *expp, '(', (struct expr *)0);
                }
-#endif
                else
                        *expp = new_oper(expp_tp->tp_up,
                                        *expp, '(', expr);
@@ -105,8 +90,6 @@ ch3bin(expp, oper, expr)
                break;
 
        case PARCOMMA:                          /* 3.3.2.2 */
-               if (expp_tp->tp_fund == FUNCTION)
-                       function2pointer(*expp);
                *expp = new_oper(expr->ex_type, *expp, PARCOMMA, expr);
                break;
 
@@ -249,13 +232,12 @@ ch3bin(expp, oper, expr)
                break;
 
        case ':':
-               if (    is_struct_or_union(expp_tp->tp_fund)
-               ||      is_struct_or_union(expr->ex_type->tp_fund)
-               )       {
+               if (is_struct_or_union(expp_tp->tp_fund)
+                   || is_struct_or_union(expr->ex_type->tp_fund))      {
                        if (!equal_type(expp_tp, expr->ex_type, -1))
                                expr_error(*expp, "illegal balance");
                }
-               else
+               else 
                        relbalance(expp, oper, &expr);
 #ifdef LINT
                if (    (is_cp_cst(*expp) && is_cp_cst(expr))
@@ -333,9 +315,10 @@ mk_binop(expp, oper, expr, commutative)
        else if (is_fp_cst(expr) && is_fp_cst(ex))
                fltcstbin(expp, oper, expr);
        else    {
-               *expp = (commutative && expr->ex_depth >= ex->ex_depth) ?
-                               new_oper(ex->ex_type, expr, oper, ex) :
-                               new_oper(ex->ex_type, ex, oper, expr);
+               *expp = (commutative && (expr->ex_depth >= ex->ex_depth
+                                       || is_cp_cst(ex)))
+                           ? new_oper(ex->ex_type, expr, oper, ex)
+                           : new_oper(ex->ex_type, ex, oper, expr);
        }
 }
 
index eeab430..be2692f 100644 (file)
@@ -150,7 +150,7 @@ ch3mon(oper, expp)
                                   (arith)((*expp)->SG_LEN) :
                                   size_of_type((*expp)->ex_type,
                                       symbol2str((*expp)->ex_type->tp_fund))
-                              , INT);
+                              , ULONG);
                expr->ex_flags |= EX_SIZEOF;
                free_expression(*expp);
                *expp = expr;
index 53933cf..cc388bb 100644 (file)
@@ -146,7 +146,7 @@ size_of(register struct expr **expp;)
        [%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER)
                cast(&tp)
                {
-                       *expp = intexpr(size_of_type(tp, "type"), INT);
+                       *expp = intexpr(size_of_type(tp, "type"), ULONG);
                        (*expp)->ex_flags |= EX_SIZEOF;
                }
        |
index 998d46e..9c1e713 100644 (file)
@@ -63,10 +63,24 @@ SkipToNewLine()
 {
        register int ch;
        register int garbage = 0;
+#ifndef        NOPP
+       register int delim = 0;
+#endif
 
        while ((ch = GetChar()) != '\n') {
 #ifndef NOPP
-               if (ch == '/') {
+               if (delim) {
+                       if (ch == '\\') {
+                               if (GetChar() == '\n') break;
+                       } else if (ch == delim) {
+                               delim = 0;
+                       }
+                       continue;
+               }
+               else if (ch == '\'' || ch == '\"') {
+                       delim = ch;
+                       garbage = 1;
+               } else if (ch == '/') {
                        if ((ch = GetChar()) == '*'
                            && !InputLevel
                        ) {
@@ -78,6 +92,9 @@ SkipToNewLine()
                if (!is_wsp(ch))
                        garbage = 1;
        }
+#ifndef        NOPP
+       if (delim) strict("unclosed opening %c", delim);
+#endif
        ++LineNumber;
        return garbage;
 }