undo Johan's changes for the moment
[fw/sdcc] / src / SDCCval.c
index 1da5f3eca83145517f20462138a1926a804405e9..83885665f266151e9e66c5b5e037f0ff599ea79e 100644 (file)
@@ -27,6 +27,7 @@
 #include <math.h>
 #include <stdlib.h>
 #include <limits.h>
+#include "newalloc.h"
 
 int            cNestLevel ;
 
@@ -37,7 +38,7 @@ value *newValue ()
 {
     value *val ;
     
-    ALLOC(val,sizeof(value));
+    val = Safe_calloc(sizeof(value));
     
     return val ;
 }
@@ -50,7 +51,7 @@ initList *newiList ( int type, void *ilist)
     initList *nilist;
     
     
-    ALLOC(nilist,sizeof(initList));    
+    nilist = Safe_calloc(sizeof(initList));    
     
     nilist->type = type        ;
     nilist->lineno = yylineno ;
@@ -402,7 +403,7 @@ value *strVal  ( char       *s )
     SPEC_NOUN(val->etype)   =  V_CHAR   ;
     SPEC_SCLS(val->etype)   =  S_LITERAL;
     
-    ALLOC_ATOMIC(SPEC_CVAL(val->etype).v_char,strlen(s)+1);
+    SPEC_CVAL(val->etype).v_char = Safe_calloc(strlen(s)+1);
     copyStr (SPEC_CVAL(val->etype).v_char,s);
     return val;
 }
@@ -413,8 +414,8 @@ value *strVal  ( char       *s )
 /*------------------------------------------------------------------*/
 value  *reverseValWithType ( value *val )
 {
-    link *type ;
-    link *etype;
+    sym_link *type ;
+    sym_link *etype;
     
     if (!val) 
        return NULL ;
@@ -562,7 +563,7 @@ value *charVal ( char *s )
 /*------------------------------------------------------------------*/
 /* valFromType - creates a value from type given                    */
 /*------------------------------------------------------------------*/
-value *valFromType ( link *type)
+value *valFromType ( sym_link *type)
 {
     value *val = newValue();
     val->type = copyLinkChain(type);
@@ -1082,7 +1083,7 @@ value *valLogicAndOr (value  *lval, value *rval, int op)
 /*------------------------------------------------------------------*/
 /* valCastLiteral - casts a literal value to another type           */
 /*------------------------------------------------------------------*/
-value *valCastLiteral (link *dtype, double fval)
+value *valCastLiteral (sym_link *dtype, double fval)
 {
     value *val ;
 
@@ -1121,9 +1122,9 @@ value *valCastLiteral (link *dtype, double fval)
 /*------------------------------------------------------------------*/
 /* getNelements - determines # of elements from init list           */
 /*------------------------------------------------------------------*/
-int getNelements (link *type,initList *ilist)
+int getNelements (sym_link *type,initList *ilist)
 {
-    link *etype = getSpec(type);
+    sym_link *etype = getSpec(type);
     int i;
 
     if (! ilist)
@@ -1201,7 +1202,7 @@ value *valForArray (ast *arrExpr)
     val->type = newLink();    
     if (SPEC_SCLS(arrExpr->left->etype) == S_CODE) {
        DCL_TYPE(val->type) = CPOINTER ;
-       DCL_PTR_CONST(val->type) = 1;
+       DCL_PTR_CONST(val->type) = port->mem.code_ro;
     }
     else
        if (SPEC_SCLS(arrExpr->left->etype) == S_XDATA)
@@ -1213,8 +1214,8 @@ value *valForArray (ast *arrExpr)
                if (SPEC_SCLS(arrExpr->left->etype) == S_IDATA)
                    DCL_TYPE(val->type) = IPOINTER ;
                else
-                   if (SPEC_SCLS(arrExpr->left->etype) == S_FLASH)
-                       DCL_TYPE(val->type) = FLPOINTER ;
+                   if (SPEC_SCLS(arrExpr->left->etype) == S_EEPROM)
+                       DCL_TYPE(val->type) = EEPPOINTER ;
                    else
                        DCL_TYPE(val->type) = POINTER ;
     val->type->next = arrExpr->left->ftype;
@@ -1270,7 +1271,7 @@ value *valForStructElem(ast *structT, ast *elemT)
     val->type = newLink();
     if (SPEC_SCLS(structT->etype) == S_CODE) {
        DCL_TYPE(val->type) = CPOINTER ;
-       DCL_PTR_CONST(val->type) = 1;
+       DCL_PTR_CONST(val->type) = port->mem.code_ro;
     }
     else
        if (SPEC_SCLS(structT->etype) == S_XDATA)
@@ -1282,11 +1283,33 @@ value *valForStructElem(ast *structT, ast *elemT)
                if (SPEC_SCLS(structT->etype) == S_IDATA)
                    DCL_TYPE(val->type) = IPOINTER ;
                else
-                   if (SPEC_SCLS(structT->etype) == S_FLASH)
-                       DCL_TYPE(val->type) = FLPOINTER ;
+                   if (SPEC_SCLS(structT->etype) == S_EEPROM)
+                       DCL_TYPE(val->type) = EEPPOINTER ;
                    else
                        DCL_TYPE(val->type) = POINTER ;
     val->type->next = sym->type;
     val->etype = getSpec(val->type);
     return val; 
 }
+
+/*-----------------------------------------------------------------*/
+/* valForCastAggr - will return value for a cast of an aggregate   */
+/*                  plus minus a constant                          */
+/*-----------------------------------------------------------------*/
+value *valForCastAggr (ast *aexpr, sym_link *type, ast *cnst, int op)
+{
+    value *val;
+
+    if (!IS_AST_SYM_VALUE(aexpr)) return NULL;
+    if (!IS_AST_LIT_VALUE(cnst)) return NULL;
+
+    val = newValue();
+
+    sprintf(val->name,"(%s %c %d)",
+          AST_SYMBOL(aexpr)->rname, op,
+          getSize(type->next)*(int)AST_LIT_VALUE(cnst));
+
+    val->type = type;
+    val->etype = getSpec(val->type);
+    return val;
+}