undid the hackup of const and volatile, the problem is much bigger
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 16 Mar 2003 11:24:18 +0000 (11:24 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 16 Mar 2003 11:24:18 +0000 (11:24 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2394 4a8a32a2-be11-0410-ad9d-d568d2c75423

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

index 44e903b60673c0f5920f46e411eb5ccf1f7879d4..c558c6c7390b131bdc5824dc1588c2f5e9ae4598 100644 (file)
@@ -976,6 +976,7 @@ pointer
                     DCL_TYPE($3) = POINTER ;
                     break;
                 case S_CODE:
+                    DCL_PTR_CONST($3) = 1;
                     DCL_TYPE($3) = CPOINTER ;
                     break;
                 case S_EEPROM:
index 35d8cc821da279764a34f5514304bc86cef38edb..0962481a8c8aaf5cc23b165b3ca6c1a1f18e77f7 100644 (file)
@@ -2061,6 +2061,9 @@ 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;
 
       /*------------------------------------------------------------------*/
@@ -2237,7 +2240,10 @@ decorateType (ast * tree)
          goto errorTreeReturn;
        }
       if (SPEC_SCLS (tree->left->etype) == S_CODE)
-       DCL_TYPE (p) = CPOINTER;
+       {
+         DCL_TYPE (p) = CPOINTER;
+         DCL_PTR_CONST (p) = port->mem.code_ro;
+       }
       else if (SPEC_SCLS (tree->left->etype) == S_XDATA)
        DCL_TYPE (p) = FPOINTER;
       else if (SPEC_SCLS (tree->left->etype) == S_XSTACK)
@@ -2260,6 +2266,8 @@ 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;
@@ -2389,9 +2397,9 @@ decorateType (ast * tree)
              werror (E_LVALUE_REQUIRED, "pointer deref");
              goto errorTreeReturn;
            }
-         TTYPE (tree) = copyLinkChain ((IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree))) ?
-                                       LTYPE (tree)->next : NULL);
+         TTYPE (tree) = copyLinkChain (LTYPE (tree)->next);
          TETYPE (tree) = getSpec (TTYPE (tree));
+         SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree));
          return tree;
        }
 
index 22af1da0f784aa77e84af58fff25718008f98005..400f36ffd59a6c0411c69564c339158de421f4d3 100644 (file)
@@ -408,6 +408,7 @@ initPointer (initList * ilist, sym_link *toType)
                        val->type = newLink (DECLARATOR);
                        if (SPEC_SCLS (expr->left->etype) == S_CODE) {
                                DCL_TYPE (val->type) = CPOINTER;
+                               DCL_TYPE (val->type) = port->mem.code_ro;
                        }
                        else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
                                DCL_TYPE (val->type) = FPOINTER;
@@ -466,6 +467,7 @@ initPointer (initList * ilist, sym_link *toType)
                val->type = newLink (DECLARATOR);
                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 e37ea9d24421a352c8e548a99073400cfa0de6af..4ee005545ba7f2bc5a1f51defee057d39e6da3df 100644 (file)
@@ -839,10 +839,20 @@ isOperandGlobal (operand * op)
 int 
 isOperandVolatile (operand * op, bool chkTemp)
 {
+  sym_link *optype;
+  sym_link *opetype;
+
   if (IS_ITEMP (op) && !chkTemp)
     return 0;
 
-  return IS_VOLATILE(operandType(op));
+  opetype = getSpec (optype = operandType (op));
+    
+  if (IS_PTR (optype) && DCL_PTR_VOLATILE (optype))   
+    return 1;   
+    
+  if (IS_VOLATILE (opetype))   
+    return 1;   
+  return 0; 
 }
 
 /*-----------------------------------------------------------------*/
@@ -2119,7 +2129,6 @@ aggrToPtr (sym_link * type, bool force)
 
   ptype->next = type;
 
-#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;
@@ -2132,9 +2141,6 @@ 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;
 }
@@ -2148,7 +2154,6 @@ 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;
@@ -2161,9 +2166,6 @@ 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;
@@ -2450,7 +2452,6 @@ geniCodeAddressOf (operand * op)
 
   p = newLink (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,10 +2462,6 @@ 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);
 
@@ -2562,10 +2559,12 @@ geniCodeDerefPtr (operand * op,int lvl)
 
   op->isGptr = IS_GENPTR (optype);
 
+#ifdef JWK
   /* if the pointer was declared as a constant */
   /* then we cannot allow assignment to the derefed */
   if (IS_PTR_CONST (optype))
     SPEC_CONST (retype) = 1;
+#endif
 
   op->isaddr = (IS_PTR (rtype) ||
                IS_STRUCT (rtype) ||
index dfec56bbd932838ee549f88e55f33f8a13fcce9d..231e4f65b1b13c1514604bd5c944578cf663b70b 100644 (file)
@@ -373,7 +373,9 @@ pointerTypes (sym_link * ptr, sym_link * type)
          break;
        }
       /* the storage class of type ends here */
-      SPEC_SCLS (type) = 0;
+      SPEC_SCLS (type) = 
+       SPEC_CONST (type) =
+       SPEC_VOLATILE (type) = 0;
     }
 
   /* now change all the remaining unknown pointers
@@ -469,7 +471,8 @@ addDecl (symbol * sym, int type, sym_link * p)
        {
          sym->etype = sym->etype->next = newLink (SPECIFIER);
        }
-      
+
+      SPEC_SCLS (sym->etype) = SPEC_SCLS (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;
@@ -557,14 +560,7 @@ sym_link *
 mergeSpec (sym_link * dest, sym_link * src, char *name)
 {
   if (!IS_SPEC(dest) || !IS_SPEC(src)) {
-#if 0
-    werror (E_INTERNAL_ERROR, __FILE__, __LINE__, "cannot merge declarator");
-    exit (1);
-#else
     werror (E_SYNTAX_ERROR, yytext);
-    // the show must go on
-    return newIntLink();
-#endif
   }
 
   if (SPEC_NOUN(src)) {
@@ -593,17 +589,6 @@ mergeSpec (sym_link * dest, sym_link * src, char *name)
 
   /* copy all the specifications  */
 
-  // we really should do: 
-#if 0
-  if (SPEC_what(src)) {
-    if (SPEC_what(dest)) {
-      werror(W_DUPLICATE_SPEC, "what");
-    }
-    SPEC_what(dst)|=SPEC_what(src);
-  }
-#endif
-  // but there are more important thing right now
-
   SPEC_LONG (dest) |= SPEC_LONG (src);
   dest->select.s._short|=src->select.s._short;
   SPEC_USIGN (dest) |= SPEC_USIGN (src);
@@ -1170,13 +1155,17 @@ checkSClass (symbol * sym, int isProto)
       !IS_FUNC(sym->type)) {
     SPEC_SCLS (sym->etype) = S_CODE;
   }
-  
+
   /* global variable in code space is a constant */
   if (sym->level == 0 &&
       SPEC_SCLS (sym->etype) == S_CODE &&
-      port->mem.code_ro)
-    SPEC_CONST (sym->etype) = 1;
-  
+      port->mem.code_ro) {
+    if (IS_SPEC(sym->type)) {
+      SPEC_CONST (sym->type) = 1;
+    } else {
+      DCL_PTR_CONST (sym->type) = 1;
+    }
+  }
 
   /* if bit variable then no storage class can be */
   /* specified since bit is already a storage */
@@ -1933,6 +1922,7 @@ printTypeChain (sym_link * start, FILE * of)
 {
   int nlr = 0;
   sym_link * type, * search;
+  STORAGE_CLASS scls;
 
   if (!of)
     {
@@ -1945,16 +1935,44 @@ printTypeChain (sym_link * start, FILE * of)
     return;
   }
 
-  /* print the chain as it is written in the source: */
-  /* start with the last entry                       */
+  /* Print the chain as it is written in the source: */
+  /* start with the last entry.                      */
+  /* However, the storage class at the end of the    */
+  /* chain reall applies to the first in the chain!  */
+
   for (type = start; type && type->next; type = type->next)
     ;
+  scls=SPEC_SCLS(type);
   while (type)
     {
+      if (type==start) {
+       switch (scls) 
+         {
+         case S_DATA: fprintf (of, "data-"); break;
+         case S_XDATA: fprintf (of, "xdata-"); break;
+         case S_SFR: fprintf (of, "sfr-"); break;
+         case S_SBIT: fprintf (of, "sbit-"); break;
+         case S_CODE: fprintf (of, "code-"); break;
+         case S_IDATA: fprintf (of, "idata-"); break;
+         case S_PDATA: fprintf (of, "pdata-"); break;
+         case S_LITERAL: fprintf (of, "literal-"); break;
+         case S_STACK: fprintf (of, "stack-"); break;
+         case S_XSTACK: fprintf (of, "xstack-"); break;
+         case S_BIT: fprintf (of, "bit-"); break;
+         case S_EEPROM: fprintf (of, "eeprom-"); break;
+         default: break;
+         }
+      }
+
       if (IS_DECL (type))
        {
-         if (DCL_PTR_VOLATILE (type)) {
-           fprintf (of, "volatile ");
+         if (!IS_FUNC(type)) {
+           if (DCL_PTR_VOLATILE (type)) {
+             fprintf (of, "volatile-");
+           }
+           if (DCL_PTR_CONST (type)) {
+             fprintf (of, "const-");
+           }
          }
          switch (DCL_TYPE (type))
            {
@@ -1964,45 +1982,28 @@ printTypeChain (sym_link * start, FILE * of)
                       (IFFUNC_ISJAVANATIVE(type) ? "_JavaNative" : " "));
              break;
            case GPOINTER:
-             if (DCL_PTR_CONST (type))
-               fprintf (of, "const ");
-             fprintf (of, "generic * ");
+             fprintf (of, "generic* ");
              break;
            case CPOINTER:
-             if (DCL_PTR_CONST (type))
-               fprintf (of, "const ");
-             fprintf (of, "code * ");
+             fprintf (of, "code* ");
              break;
            case FPOINTER:
-             if (DCL_PTR_CONST (type))
-               fprintf (of, "const ");
-             fprintf (of, "xdata * ");
+             fprintf (of, "xdata* ");
              break;
            case EEPPOINTER:
-             if (DCL_PTR_CONST (type))
-               fprintf (of, "const ");
-             fprintf (of, "eeprom * ");
+             fprintf (of, "eeprom* ");
              break;
-
            case POINTER:
-             if (DCL_PTR_CONST (type))
-               fprintf (of, "const ");
-             fprintf (of, "near *");
+             fprintf (of, "near* ");
              break;
            case IPOINTER:
-             if (DCL_PTR_CONST (type))
-               fprintf (of, "const ");
-             fprintf (of, "idata * ");
+             fprintf (of, "idata* ");
              break;
            case PPOINTER:
-             if (DCL_PTR_CONST (type))
-               fprintf (of, "const ");
-             fprintf (of, "pdata * ");
+             fprintf (of, "pdata* ");
              break;
            case UPOINTER:
-             if (DCL_PTR_CONST (type))
-               fprintf (of, "const ");
-             fprintf (of, "unkown * ");
+             fprintf (of, "unkown* ");
              break;
            case ARRAY:
              if (DCL_ELEM(type)) {
@@ -2015,34 +2016,17 @@ printTypeChain (sym_link * start, FILE * of)
        }
       else
        {
-         switch (SPEC_SCLS(type)) 
-           {
-           case S_DATA: fprintf (of, "data "); break;
-           case S_XDATA: fprintf (of, "xdata "); break;
-           case S_SFR: fprintf (of, "sfr "); break;
-           case S_SBIT: fprintf (of, "sbit "); break;
-           case S_CODE: fprintf (of, "code "); break;
-           case S_IDATA: fprintf (of, "idata "); break;
-           case S_PDATA: fprintf (of, "pdata "); break;
-           case S_LITERAL: fprintf (of, "literal "); break;
-           case S_STACK: fprintf (of, "stack "); break;
-           case S_XSTACK: fprintf (of, "xstack "); break;
-           case S_BIT: fprintf (of, "bit "); break;
-           case S_EEPROM: fprintf (of, "eeprom "); break;
-           default: break;
-           }
-
          if (SPEC_VOLATILE (type))
-           fprintf (of, "volatile ");
-         if (SPEC_USIGN (type))
-           fprintf (of, "unsigned ");
+           fprintf (of, "volatile-");
          if (SPEC_CONST (type))
-           fprintf (of, "const ");
+           fprintf (of, "const-");
+         if (SPEC_USIGN (type))
+           fprintf (of, "unsigned-");
          switch (SPEC_NOUN (type))
            {
            case V_INT:
              if (IS_LONG (type))
-               fprintf (of, "long ");
+               fprintf (of, "long-");
              fprintf (of, "int");
              break;
 
index 687a2a3f34cba86ca943687f11d2e008966663ba..d944b5c8cd38ec6fed8f35ac4946bc1250d6854b 100644 (file)
@@ -1537,6 +1537,7 @@ 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;
@@ -1607,6 +1608,7 @@ 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;