hack up const and volatile modifiers in type chains a bit
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 13 Mar 2003 17:29:53 +0000 (17:29 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 13 Mar 2003 17:29:53 +0000 (17:29 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2384 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCC.y
src/SDCCast.c
src/SDCCglue.c
src/SDCCicode.c
src/SDCCsymt.c
src/SDCCsymt.h
src/SDCCval.c

index 24741ae5c6be39a0f1215a5c658e383aff496a37..16839f811f7fe07169248a7be0689d95ab75a545 100644 (file)
@@ -1009,7 +1009,6 @@ pointer
                     DCL_TYPE($3) = POINTER ;
                     break;
                 case S_CODE:
-                    DCL_PTR_CONST($3) = 1;
                     DCL_TYPE($3) = CPOINTER ;
                     break;
                 case S_EEPROM:
index ddad912515bca9a6a8e6095a918ce5f87100f455..093a90435dbc5b5ec61c79d1989326f0ffa7c3ec 100644 (file)
@@ -2061,9 +2061,6 @@ decorateType (ast * tree)
        }
       RRVAL (tree) = 1;
       COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree)->next);
-      if (IS_PTR(LTYPE(tree))) {
-             SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree));
-      }
       return tree;
 
       /*------------------------------------------------------------------*/
@@ -2144,8 +2141,8 @@ decorateType (ast * tree)
       {
        sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree));
        COPYTYPE (TTYPE (tree), TETYPE (tree), ltc);
-       if (!tree->initMode && IS_CONSTANT(TETYPE(tree)))
-         werror (E_CODE_WRITE, "++/--");
+       if (!tree->initMode && IS_CONSTANT (TTYPE (tree)))
+         werror (E_CODE_WRITE, tree->opval.op==INC_OP ? "++" : "--");
 
        if (tree->right)
          RLVAL (tree) = 1;
@@ -2241,10 +2238,7 @@ decorateType (ast * tree)
          goto errorTreeReturn;
        }
       if (SPEC_SCLS (tree->left->etype) == S_CODE)
-       {
-         DCL_TYPE (p) = CPOINTER;
-         DCL_PTR_CONST (p) = port->mem.code_ro;
-       }
+       DCL_TYPE (p) = CPOINTER;
       else if (SPEC_SCLS (tree->left->etype) == S_XDATA)
        DCL_TYPE (p) = FPOINTER;
       else if (SPEC_SCLS (tree->left->etype) == S_XSTACK)
@@ -2267,8 +2261,6 @@ decorateType (ast * tree)
       p->next = LTYPE (tree);
       TTYPE (tree) = p;
       TETYPE (tree) = getSpec (TTYPE (tree));
-      DCL_PTR_CONST (p) = SPEC_CONST (TETYPE (tree));
-      DCL_PTR_VOLATILE (p) = SPEC_VOLATILE (TETYPE (tree));
       LLVAL (tree) = 1;
       TLVAL (tree) = 1;
       return tree;
@@ -2401,7 +2393,6 @@ decorateType (ast * tree)
          TTYPE (tree) = copyLinkChain ((IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree))) ?
                                        LTYPE (tree)->next : NULL);
          TETYPE (tree) = getSpec (TTYPE (tree));
-         SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree));
          return tree;
        }
 
@@ -3099,12 +3090,12 @@ decorateType (ast * tree)
       RRVAL (tree) = 1;
       TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree));
 
-      if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
-       werror (E_CODE_WRITE, ");
+      if (!tree->initMode && IS_CONSTANT (LTYPE (tree)))
+       werror (E_CODE_WRITE, *tree->opval.op==MUL_ASSIGN ? "*=" : "/=");
 
       if (LRVAL (tree))
        {
-         werror (E_LVALUE_REQUIRED, "*= or /=");
+         werror (E_LVALUE_REQUIRED, *tree->opval.op==MUL_ASSIGN ? "*=" : "/=");
          goto errorTreeReturn;
        }
       LLVAL (tree) = 1;
@@ -3126,8 +3117,8 @@ decorateType (ast * tree)
       RRVAL (tree) = 1;
       TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree));
 
-      if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
-       werror (E_CODE_WRITE, " ");
+      if (!tree->initMode && IS_CONSTANT (LTYPE (tree)))
+       werror (E_CODE_WRITE, "&= or |= or ^= or >>= or <<=");
 
       if (LRVAL (tree))
        {
@@ -3161,8 +3152,8 @@ decorateType (ast * tree)
                               computeType (LTYPE (tree),
                                            RTYPE (tree)));
 
-      if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
-       werror (E_CODE_WRITE, " ");
+      if (!tree->initMode && IS_CONSTANT (LTYPE (tree)))
+       werror (E_CODE_WRITE, "-=");
 
       if (LRVAL (tree))
        {
@@ -3202,8 +3193,8 @@ decorateType (ast * tree)
                               computeType (LTYPE (tree),
                                            RTYPE (tree)));
 
-      if (!tree->initMode && IS_CONSTANT (LETYPE (tree)))
-       werror (E_CODE_WRITE, " ");
+      if (!tree->initMode && IS_CONSTANT (LTYPE (tree)))
+       werror (E_CODE_WRITE, "+=");
 
       if (LRVAL (tree))
        {
@@ -3250,8 +3241,8 @@ decorateType (ast * tree)
       RRVAL (tree) = 1;
       LLVAL (tree) = 1;
       if (!tree->initMode ) {
-       if ((IS_SPEC(LETYPE(tree)) && IS_CONSTANT (LETYPE (tree))))
-         werror (E_CODE_WRITE, " ");
+       if (IS_CONSTANT (LTYPE (tree)))
+         werror (E_CODE_WRITE, "=");
       }
       if (LRVAL (tree))
        {
@@ -4426,7 +4417,7 @@ skipall:
 }
 
 
-#define INDENT(x,f) { int i ; for (i=0;i < x; i++) fprintf(f," "); }
+#define INDENT(x,f) { int i ; fprintf (f, "%d:", tree->lineno); for (i=0;i < x; i++) fprintf(f," "); }
 /*-----------------------------------------------------------------*/
 /* ast_print : prints the ast (for debugging purposes)             */
 /*-----------------------------------------------------------------*/
@@ -4916,14 +4907,14 @@ void ast_print (ast * tree, FILE *outfile, int indent)
                ast_print(tree->right,outfile,indent+2);
                return;
        case OR_ASSIGN:
-               fprintf(outfile,"ORASS(*=) (%p) type (",tree);
+               fprintf(outfile,"ORASS(|=) (%p) type (",tree);
                printTypeChain(tree->ftype,outfile);
                fprintf(outfile,")\n");
                ast_print(tree->left,outfile,indent+2);
                ast_print(tree->right,outfile,indent+2);
                return;
        case XOR_ASSIGN:
-               fprintf(outfile,"XORASS(*=) (%p) type (",tree);
+               fprintf(outfile,"XORASS(^=) (%p) type (",tree);
                printTypeChain(tree->ftype,outfile);
                fprintf(outfile,")\n");
                ast_print(tree->left,outfile,indent+2);
@@ -4937,7 +4928,7 @@ void ast_print (ast * tree, FILE *outfile, int indent)
                ast_print(tree->right,outfile,indent+2);
                return;
        case LEFT_ASSIGN:
-               fprintf(outfile,"LSHFTASS(*=) (%p) type (",tree);
+               fprintf(outfile,"LSHFTASS(<<=) (%p) type (",tree);
                printTypeChain(tree->ftype,outfile);
                fprintf(outfile,")\n");
                ast_print(tree->left,outfile,indent+2);
index 8dced77b7a6fb9c2b43c893552aff64a7762b3fd..e72964cd4dcf5e01550ad3984f49ed002dc81e93 100644 (file)
@@ -408,7 +408,6 @@ initPointer (initList * ilist, sym_link *toType)
                        val->type = newLink ();
                        if (SPEC_SCLS (expr->left->etype) == S_CODE) {
                                DCL_TYPE (val->type) = CPOINTER;
-                               DCL_PTR_CONST (val->type) = port->mem.code_ro;
                        }
                        else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
                                DCL_TYPE (val->type) = FPOINTER;
@@ -467,7 +466,6 @@ initPointer (initList * ilist, sym_link *toType)
                val->type = newLink ();
                if (SPEC_SCLS (expr->right->etype) == S_CODE) {
                        DCL_TYPE (val->type) = CPOINTER;
-                       DCL_PTR_CONST (val->type) = port->mem.code_ro;
                }
                else if (SPEC_SCLS (expr->right->etype) == S_XDATA)
                        DCL_TYPE (val->type) = FPOINTER;
index 9c37fe0a2d5f22cdc4197ffc06ea11eb134f0c4f..32f913aec7f0a10e33a7ac3013399320ebd9f20a 100644 (file)
@@ -845,14 +845,7 @@ isOperandVolatile (operand * op, bool chkTemp)
   if (IS_ITEMP (op) && !chkTemp)
     return 0;
 
-  opetype = getSpec (optype = operandType (op));
-
-  if (IS_PTR (optype) && DCL_PTR_VOLATILE (optype))
-    return 1;
-
-  if (IS_VOLATILE (opetype))
-    return 1;
-  return 0;
+  return IS_VOLATILE(operandType(op));
 }
 
 /*-----------------------------------------------------------------*/
@@ -2128,7 +2121,9 @@ aggrToPtr (sym_link * type, bool force)
   ptype = newLink ();
 
   ptype->next = type;
-  /* if the output class is generic */
+
+#ifdef JWK
+  /* if the output class is code */
   if ((DCL_TYPE (ptype) = PTR_TYPE (SPEC_OCLS (etype))) == CPOINTER)
     DCL_PTR_CONST (ptype) = port->mem.code_ro;
 
@@ -2140,6 +2135,10 @@ aggrToPtr (sym_link * type, bool force)
   /* the variable was volatile then pointer to volatile */
   if (IS_VOLATILE (etype))
     DCL_PTR_VOLATILE (ptype) = 1;
+#else
+  DCL_TYPE (ptype) = PTR_TYPE (SPEC_OCLS (etype));
+#endif
+
   return ptype;
 }
 
@@ -2152,11 +2151,11 @@ geniCodeArray2Ptr (operand * op)
   sym_link *optype = operandType (op);
   sym_link *opetype = getSpec (optype);
 
+#ifdef JWK
   /* set the pointer depending on the storage class */
   if ((DCL_TYPE (optype) = PTR_TYPE (SPEC_OCLS (opetype))) == CPOINTER)
     DCL_PTR_CONST (optype) = port->mem.code_ro;
 
-
   /* if the variable was declared a constant */
   /* then the pointer points to a constant */
   if (IS_CONSTANT (opetype))
@@ -2165,6 +2164,10 @@ geniCodeArray2Ptr (operand * op)
   /* the variable was volatile then pointer to volatile */
   if (IS_VOLATILE (opetype))
     DCL_PTR_VOLATILE (optype) = 1;
+#else
+  DCL_TYPE (optype) = PTR_TYPE (SPEC_OCLS (opetype));
+#endif
+
   op->isaddr = 0;
   return op;
 }
@@ -2451,6 +2454,7 @@ geniCodeAddressOf (operand * op)
   p = newLink ();
   p->class = DECLARATOR;
 
+#ifdef JWK
   /* set the pointer depending on the storage class */
   if ((DCL_TYPE (p) = PTR_TYPE (SPEC_OCLS (opetype))) == CPOINTER)
     DCL_PTR_CONST (p) = port->mem.code_ro;
@@ -2461,6 +2465,10 @@ geniCodeAddressOf (operand * op)
 
   if (IS_VOLATILE (opetype))
     DCL_PTR_VOLATILE (p) = 1;
+#else
+  DCL_TYPE (p) = PTR_TYPE (SPEC_OCLS (opetype));
+#endif
+
 
   p->next = copyLinkChain (optype);
 
index b160c7f7311a11933a8c9ae27482cf1f92849722..0dce6fa4a2e08e20d43c8aa840aef4182c3691fa 100644 (file)
@@ -347,8 +347,6 @@ pointerTypes (sym_link * ptr, sym_link * type)
      storage class of the type */
   if (IS_SPEC (type))
     {
-      DCL_PTR_CONST (ptr) = SPEC_CONST (type);
-      DCL_PTR_VOLATILE (ptr) = SPEC_VOLATILE (type);
       switch (SPEC_SCLS (type))
        {
        case S_XDATA:
@@ -364,7 +362,6 @@ pointerTypes (sym_link * ptr, sym_link * type)
          DCL_TYPE (ptr) = POINTER;
          break;
        case S_CODE:
-         DCL_PTR_CONST (ptr) = port->mem.code_ro;
          DCL_TYPE (ptr) = CPOINTER;
          break;
        case S_EEPROM:
@@ -457,22 +454,26 @@ addDecl (symbol * sym, int type, sym_link * p)
     }
 
   /* if the type is an unknown pointer and has
-     a tspec then take the storage class const & volatile
+     a tspec then take the const & volatile
      attribute from the tspec & make it those of this
      symbol */
+
   if (p &&
-      !IS_SPEC (p) &&
-      //DCL_TYPE (p) == UPOINTER &&
+      IS_DECL (p) &&
+      DCL_TYPE (p) == UPOINTER &&
       DCL_TSPEC (p))
     {
+      // only for declarators
+      wassert (IS_DECL(sym->type));
+
       if (!IS_SPEC (sym->etype))
        {
          sym->etype = sym->etype->next = newLink ();
          sym->etype->class = SPECIFIER;
        }
-      SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p));
-      SPEC_CONST (sym->etype) = SPEC_CONST (DCL_TSPEC (p));
-      SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p));
+      
+      DCL_PTR_CONST (sym->type) = SPEC_CONST (DCL_TSPEC (p));
+      DCL_PTR_VOLATILE (sym->type) = SPEC_VOLATILE (DCL_TSPEC (p));
       DCL_TSPEC (p) = NULL;
     }
 
@@ -2096,12 +2097,12 @@ printTypeChain (sym_link * start, FILE * of)
              break;
            }
        }
-       /* search entry in list before "type" */
-    for (search = start; search && search->next != type;)
-       search = search->next;
-    type = search;
-    if (type)
-      fputc (' ', of);
+      /* search entry in list before "type" */
+      for (search = start; search && search->next != type;)
+       search = search->next;
+      type = search;
+      if (type)
+       fputc (' ', of);
     }
   if (nlr)
     fprintf (of, "\n");
index f1cc4de749906ba38440b2af1caa9a0186eebb2a..f49036fad9380f9a7827b648133fcbe45d01c57a 100644 (file)
@@ -177,8 +177,8 @@ typedef struct declarator
   {
     DECLARATOR_TYPE dcl_type;  /* POINTER,ARRAY or FUNCTION  */
     unsigned int num_elem;     /* # of elems if type==array  */
-    short ptr_const:1;         /* pointer is constant        */
-    short ptr_volatile:1;      /* pointer is volatile        */
+    unsigned ptr_const:1;      /* pointer is constant        */
+    unsigned ptr_volatile:1;   /* pointer is volatile        */
     struct sym_link *tspec;    /* pointer type specifier     */
   }
 declarator;
@@ -203,7 +203,6 @@ typedef struct sym_link
       unsigned hasVargs:1;      /* functions has varargs      */
       unsigned calleeSaves:1;  /* functions uses callee save */
       unsigned hasbody:1;      /* function body defined      */
-      //unsigned ret:1;                /* return statement for a function */
       unsigned hasFcall:1;     /* does it call other functions */
       unsigned reent:1;                /* function is reentrant      */
       unsigned naked:1;                /* naked function             */
@@ -414,7 +413,10 @@ symbol;
 #define IS_LONG(x)   (IS_SPEC(x) && x->select.s._long)
 #define IS_UNSIGNED(x) (IS_SPEC(x) && x->select.s._unsigned)
 #define IS_TYPEDEF(x)(IS_SPEC(x) && x->select.s._typedef)
-#define IS_CONSTANT(x)  (IS_SPEC(x) && ( x->select.s._const == 1))
+#define IS_CONSTANT(x)  (!x ? 0 : \
+                           IS_SPEC(x) ? \
+                           x->select.s._const == 1 : \
+                           x->select.d.ptr_const)
 #define IS_STRUCT(x) (IS_SPEC(x) && x->select.s.noun == V_STRUCT)
 #define IS_ABSOLUTE(x)  (IS_SPEC(x) && x->select.s._absadr )
 #define IS_REGISTER(x)  (IS_SPEC(x) && SPEC_SCLS(x) == S_REGISTER)
@@ -424,7 +426,10 @@ symbol;
 #define IS_VOID(x)   (IS_SPEC(x) && x->select.s.noun == V_VOID)
 #define IS_CHAR(x)   (IS_SPEC(x) && x->select.s.noun == V_CHAR)
 #define IS_EXTERN(x)   (IS_SPEC(x) && x->select.s._extern)
-#define IS_VOLATILE(x)  (IS_SPEC(x) && x->select.s._volatile )
+#define IS_VOLATILE(x)  (!x ? 0 : \
+                          IS_SPEC(x) ? \
+                          x->select.s._volatile : \
+                          x->select.d.ptr_volatile)
 #define IS_INTEGRAL(x) (IS_SPEC(x) && (x->select.s.noun == V_INT ||  \
                                        x->select.s.noun == V_CHAR || \
                                        x->select.s.noun == V_BIT ||  \
index 4a223058e97e38a9c6dcd4fed8bbdb336310f97e..b2a9899615e51d6ceba129b227685c6f64fb96fb 100644 (file)
@@ -1546,7 +1546,6 @@ valForArray (ast * arrExpr)
   if (SPEC_SCLS (arrExpr->left->etype) == S_CODE)
     {
       DCL_TYPE (val->type) = CPOINTER;
-      DCL_PTR_CONST (val->type) = port->mem.code_ro;
     }
   else if (SPEC_SCLS (arrExpr->left->etype) == S_XDATA)
     DCL_TYPE (val->type) = FPOINTER;
@@ -1617,7 +1616,6 @@ valForStructElem (ast * structT, ast * elemT)
   if (SPEC_SCLS (structT->etype) == S_CODE)
     {
       DCL_TYPE (val->type) = CPOINTER;
-      DCL_PTR_CONST (val->type) = port->mem.code_ro;
     }
   else if (SPEC_SCLS (structT->etype) == S_XDATA)
     DCL_TYPE (val->type) = FPOINTER;