a fix for the initialized structs and some others, see
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 30 Jun 2001 19:59:45 +0000 (19:59 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 30 Jun 2001 19:59:45 +0000 (19:59 +0000)
http://www.geocrawler.com/lists/3/SourceForge/1557/0/6076926

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@981 4a8a32a2-be11-0410-ad9d-d568d2c75423

14 files changed:
src/SDCCast.c
src/SDCCcse.c
src/SDCCglue.c
src/SDCCicode.c
src/SDCCmain.c
src/SDCCopt.c
src/SDCCsymt.c
src/SDCCsymt.h
src/avr/ralloc.c
src/ds390/ralloc.c
src/mcs51/ralloc.c
src/pic/ralloc.c
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index df6cccffaba0b7064b7d3b9211a721d5885f2fed..6b384a7e77b929368aa5a4e4a4f55a84eec1466f 100644 (file)
@@ -738,7 +738,7 @@ processParms (ast * func,
     }
 
   /* the parameter type must be at least castable */
-  if (checkType (defParm->type, actParm->ftype) == 0)
+  if (compareType (defParm->type, actParm->ftype) == 0)
     {
       werror (E_TYPE_MISMATCH_PARM, *parmNumber);
       werror (E_CONTINUE, "defined type ");
@@ -750,7 +750,7 @@ processParms (ast * func,
     }
 
   /* if the parameter is castable then add the cast */
-  if (checkType (defParm->type, actParm->ftype) < 0)
+  if (compareType (defParm->type, actParm->ftype) < 0)
     {
       ast *pTree = resolveSymbols (copyAst (actParm));
 
@@ -2724,7 +2724,7 @@ decorateType (ast * tree)
       /* if they are pointers they must be castable */
       if (IS_PTR (LTYPE (tree)) && IS_PTR (RTYPE (tree)))
        {
-         if (checkType (LTYPE (tree), RTYPE (tree)) == 0)
+         if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
            {
              werror (E_COMPARE_OP);
              fprintf (stderr, "comparing type ");
@@ -2741,7 +2741,7 @@ decorateType (ast * tree)
          if (!((IS_PTR (LTYPE (tree)) && IS_LITERAL (RTYPE (tree))) ||
                (IS_PTR (RTYPE (tree)) && IS_LITERAL (LTYPE (tree)))))
 
-           if (checkType (LTYPE (tree), RTYPE (tree)) == 0)
+           if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
              {
                werror (E_COMPARE_OP);
                fprintf (stderr, "comparing type ");
@@ -2798,7 +2798,7 @@ decorateType (ast * tree)
 
     case ':':
       /* if they don't match we have a problem */
-      if (checkType (LTYPE (tree), RTYPE (tree)) == 0)
+      if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
        {
          werror (E_TYPE_MISMATCH, "conditional operator", " ");
          goto errorTreeReturn;
@@ -2963,7 +2963,7 @@ decorateType (ast * tree)
        }
 
       /* they should either match or be castable */
-      if (checkType (LTYPE (tree), RTYPE (tree)) == 0)
+      if (compareType (LTYPE (tree), RTYPE (tree)) == 0)
        {
          werror (E_TYPE_MISMATCH, "assignment", " ");
          fprintf (stderr, "type --> '");
@@ -3053,7 +3053,7 @@ decorateType (ast * tree)
       if (!tree->right)
        goto voidcheck;
 
-      if (checkType (currFunc->type->next, RTYPE (tree)) == 0)
+      if (compareType (currFunc->type->next, RTYPE (tree)) == 0)
        {
          werror (E_RETURN_MISMATCH);
          goto errorTreeReturn;
@@ -3068,7 +3068,7 @@ decorateType (ast * tree)
        }
 
       /* if there is going to be a casing required then add it */
-      if (checkType (currFunc->type->next, RTYPE (tree)) < 0)
+      if (compareType (currFunc->type->next, RTYPE (tree)) < 0)
        {
 #if 0 && defined DEMAND_INTEGER_PROMOTION
          if (IS_INTEGRAL (currFunc->type->next))
index 8d059f92d1da5bc85215c0cb5fce2f6429a91e36..0434ea0190362064cd917ed4dd270071c03524bd 100644 (file)
@@ -821,7 +821,7 @@ algebraicOpts (iCode * ic)
          SET_ISADDR (IC_RESULT (ic), 0);
        }
       /* if casting to the same */
-      if (checkType (operandType (IC_RESULT (ic)),
+      if (compareType (operandType (IC_RESULT (ic)),
                     operandType (IC_RIGHT (ic))) == 1)
        {
          ic->op = '=';
@@ -1224,7 +1224,7 @@ fixUpTypes (iCode * ic)
   /* for pointer_gets if the types of result & left r the
      same then change it type of result to next */
   if (IS_PTR (t1) &&
-      checkType (t2 = operandType (IC_RESULT (ic)), t1) == 1)
+      compareType (t2 = operandType (IC_RESULT (ic)), t1) == 1)
     {
       setOperandType (IC_RESULT (ic), t2->next);
     }
@@ -1496,7 +1496,7 @@ cseBBlock (eBBlock * ebb, int computeOnly,
          !computeOnly)
        {
          applyToSet (cseSet, findPrevIc, ic, &pdic);
-         if (pdic && checkType (operandType (IC_RESULT (pdic)),
+         if (pdic && compareType (operandType (IC_RESULT (pdic)),
                                 operandType (IC_RESULT (ic))) != 1)
            pdic = NULL;
        }
index 3ef90f226a734238ceadc7a7d8f5b5b4018a7832..6552a80f46717ba5ced20e57058940ed14b0bc9c 100644 (file)
@@ -160,6 +160,7 @@ static void
 emitRegularMap (memmap * map, bool addPublics, bool arFlag)
 {
   symbol *sym;
+  ast *ival = NULL;
 
   if (addPublics)
     {
@@ -254,7 +255,6 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
          it is a global variable */
       if (sym->ival && sym->level == 0)
        {
-         ast *ival = NULL;
 
          if (IS_AGGREGATE (sym->type))
            ival = initAggregates (sym, sym->ival, NULL);
@@ -263,6 +263,10 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                     decorateType (resolveSymbols (list2expr (sym->ival))));
          codeOutFile = statsg->oFile;
          allocInfo = 0;
+
+         // set ival's lineno to where the symbol was defined
+         ival->lineno=sym->lineDef;
+
          eBBlockFromiCode (iCodeFromAst (ival));
          allocInfo = 1;
          sym->ival = NULL;
@@ -431,7 +435,7 @@ printChar (FILE * ofile, char *s, int plen)
 /* return the generic pointer high byte for a given pointer type.  */
 /*-----------------------------------------------------------------*/
 int 
-pointerTypeToGPByte (const int p_type)
+pointerTypeToGPByte (const int p_type, const char *iname, const char *oname)
 {
   switch (p_type)
     {
@@ -442,6 +446,9 @@ pointerTypeToGPByte (const int p_type)
       /* hack - if we get a generic pointer, we just assume
        * it's an FPOINTER (i.e. in XDATA space).
        */
+      werror (E_CANNOT_USE_GENERIC_POINTER, iname, oname);
+      exit (1);
+      // fall through
     case FPOINTER:
       return 1;
     case CPOINTER:
@@ -487,11 +494,11 @@ printPointerType (FILE * oFile, const char *name)
 /* printGPointerType - generates ival for generic pointer type     */
 /*-----------------------------------------------------------------*/
 void 
-printGPointerType (FILE * oFile, const char *name,
+printGPointerType (FILE * oFile, const char *iname, const char *oname,
                   const unsigned int type)
 {
-  _printPointerType (oFile, name);
-  fprintf (oFile, ",#0x%02x\n", pointerTypeToGPByte (type));
+  _printPointerType (oFile, iname);
+  fprintf (oFile, ",#0x%02x\n", pointerTypeToGPByte (type, iname, oname));
 }
 
 /*-----------------------------------------------------------------*/
@@ -719,7 +726,7 @@ printIvalFuncPtr (sym_link * type, initList * ilist, FILE * oFile)
 
   val = list2val (ilist);
   /* check the types   */
-  if ((dLvl = checkType (val->type, type->next)) <= 0)
+  if ((dLvl = compareType (val->type, type->next)) <= 0)
     {
       tfprintf (oFile, "\t!dw !constword\n", 0);
       return;
@@ -783,10 +790,17 @@ printIvalCharPtr (symbol * sym, sym_link * type, value * val, FILE * oFile)
        }
       else if (size == GPTRSIZE)
        {
-         /* PENDING: 0x02 or 0x%02x, CDATA? */
-         printGPointerType (oFile, val->name,
-                            (IS_PTR (val->type) ? DCL_TYPE (val->type) :
-                             PTR_TYPE (SPEC_OCLS (val->etype))));
+         int type;
+         if (IS_PTR (val->type)) {
+           type = DCL_TYPE (val->type);
+         } else {
+           type = PTR_TYPE (SPEC_OCLS (val->etype));
+         }
+         if (val->sym && val->sym->isstrlit) {
+           // this is a literal string
+           type=CPOINTER;
+         }
+         printGPointerType (oFile, val->name, sym->name, type);
        }
       else
        {
@@ -855,7 +869,7 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
       return;
 
   /* check the type      */
-  if (checkType (type, val->type) == 0)
+  if (compareType (type, val->type) == 0)
     werror (E_INIT_WRONG);
 
   /* if val is literal */
@@ -896,7 +910,7 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
     }
   else if (size == GPTRSIZE)
     {
-      printGPointerType (oFile, val->name,
+      printGPointerType (oFile, val->name, sym->name,
                         (IS_PTR (val->type) ? DCL_TYPE (val->type) :
                          PTR_TYPE (SPEC_OCLS (val->etype))));
     }
index c1b48ed8583914429878f857e5b7188f9cee105d..ea4f48d5cab440e51eddf7a1b91bce73fdc8d5fd 100644 (file)
@@ -1021,7 +1021,7 @@ isOperandEqual (operand * left, operand * right)
       return (floatFromVal (left->operand.valOperand) ==
              floatFromVal (right->operand.valOperand));
     case TYPE:
-      if (checkType (left->operand.typeOperand,
+      if (compareType (left->operand.typeOperand,
                     right->operand.typeOperand) == 1)
        return 1;
     }
@@ -1513,7 +1513,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
     }
 
   /* if the operand is already the desired type then do nothing */
-  if (checkType (type, optype) == 1)
+  if (compareType (type, optype) == 1)
     return op;
 
   /* if this is a literal then just change the type & return */
@@ -1529,7 +1529,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
       !IS_GENPTR (type))
     {
       werror (E_INCOMPAT_CAST);
-      werror (E_CONTINUE, "from type '");
+      fprintf (stderr, "from type '");
       printTypeChain (optype, stderr);
       fprintf (stderr, "' to type '");
       printTypeChain (type, stderr);
@@ -2501,12 +2501,12 @@ geniCodeAssign (operand * left, operand * right, int nosupdate)
 
   /* first check the type for pointer assignement */
   if (left->isaddr && IS_PTR (ltype) && IS_ITEMP (left) &&
-      checkType (ltype, rtype) < 0)
+      compareType (ltype, rtype) < 0)
     {
-      if (checkType (ltype->next, rtype) < 0)
+      if (compareType (ltype->next, rtype) < 0)
        right = geniCodeCast (ltype->next, right, TRUE);
     }
-  else if (checkType (ltype, rtype) < 0)
+  else if (compareType (ltype, rtype) < 0)
     right = geniCodeCast (ltype, right, TRUE);
 
   /* if left is a true symbol & ! volatile
@@ -3286,7 +3286,7 @@ ast2iCode (ast * tree,int lvl)
        sym_link *rtype = operandType (right);
        sym_link *ltype = operandType (left);
        if (IS_PTR (rtype) && IS_ITEMP (right)
-           && right->isaddr && checkType (rtype->next, ltype) == 1)
+           && right->isaddr && compareType (rtype->next, ltype) == 1)
          right = geniCodeRValue (right, TRUE);
        else
          right = geniCodeRValue (right, FALSE);
@@ -3318,7 +3318,7 @@ ast2iCode (ast * tree,int lvl)
        sym_link *rtype = operandType (right);
        sym_link *ltype = operandType (left);
        if (IS_PTR (rtype) && IS_ITEMP (right)
-           && right->isaddr && checkType (rtype->next, ltype) == 1)
+           && right->isaddr && compareType (rtype->next, ltype) == 1)
          right = geniCodeRValue (right, TRUE);
        else
          right = geniCodeRValue (right, FALSE);
@@ -3334,7 +3334,7 @@ ast2iCode (ast * tree,int lvl)
        sym_link *rtype = operandType (right);
        sym_link *ltype = operandType (left);
        if (IS_PTR (rtype) && IS_ITEMP (right)
-           && right->isaddr && checkType (rtype->next, ltype) == 1)
+           && right->isaddr && compareType (rtype->next, ltype) == 1)
          {
            right = geniCodeRValue (right, TRUE);
          }
index 31d5fdca5c64fdbebacdeb2d88839a3e49ab772e..3479f6c6b453f1e164aa76d26d2ba135106237ed 100644 (file)
@@ -1261,8 +1261,7 @@ _findPort (int argc, char **argv)
 {
   _validatePorts ();
 
-  argc--;
-  while (argc)
+  while (argc--)
     {
       if (!strncmp (*argv, "-m", 2))
        {
@@ -1270,7 +1269,6 @@ _findPort (int argc, char **argv)
          return;
        }
       argv++;
-      argc--;
     }
   /* Use the first in the list */
   port = _ports[0];
index cb7c6bc3d6885b4704f9002eeba603162bf2fb13..c6160ccf28c5bd10d48b2a5f93556b96041f1f23 100644 (file)
@@ -193,7 +193,7 @@ cnvToFloatCast (iCode * ic, eBBlock * ebp)
     {
       for (su = 0; su < 2; su++)
        {
-         if (checkType (type, __multypes[bwd][su]) == 1)
+         if (compareType (type, __multypes[bwd][su]) == 1)
            {
              func = __conv[0][bwd][su];
              goto found;
@@ -262,7 +262,7 @@ cnvFromFloatCast (iCode * ic, eBBlock * ebp)
     {
       for (su = 0; su < 2; su++)
        {
-         if (checkType (type, __multypes[bwd][su]) == 1)
+         if (compareType (type, __multypes[bwd][su]) == 1)
            {
              func = __conv[1][bwd][su];
              goto found;
@@ -332,7 +332,7 @@ convilong (iCode * ic, eBBlock * ebp, sym_link * type, int op)
     {
       for (su = 0; su < 2; su++)
        {
-         if (checkType (type, __multypes[bwd][su]) == 1)
+         if (compareType (type, __multypes[bwd][su]) == 1)
            {
              if (op == '*')
                func = __muldiv[0][bwd][su];
index 98fd50febec73a622060274a4e75d3e0e6ec89b6..51e3e844520b5e26d682207021777512c12076e7 100644 (file)
@@ -935,7 +935,7 @@ addSymChain (symbol * symHead)
          if (IS_EXTERN (csym->etype))
            {
              /* do types match ? */
-             if (checkType (csym->type, sym->type) != 1)
+             if (compareType (csym->type, sym->type) != 1)
                /* no then error */
                werror (E_DUPLICATE, csym->name);
 
@@ -956,7 +956,7 @@ addSymChain (symbol * symHead)
          /* then check the type with the current one         */
          if (IS_EXTERN (csym->etype))
            {
-             if (checkType (csym->type, sym->type) <= 0)
+             if (compareType (csym->type, sym->type) <= 0)
                werror (W_EXTERN_MISMATCH, csym->name);
            }
        }
@@ -1428,10 +1428,10 @@ computeType (sym_link * type1, sym_link * type2)
 }
 
 /*------------------------------------------------------------------*/
-/* checkType - will do type check return 1 if match                 */
+/* compareType - will do type check return 1 if match                 */
 /*------------------------------------------------------------------*/
 int 
-checkType (sym_link * dest, sym_link * src)
+compareType (sym_link * dest, sym_link * src)
 {
   if (!dest && !src)
     return 1;
@@ -1448,13 +1448,13 @@ checkType (sym_link * dest, sym_link * src)
       if (IS_DECL (src))
        {
          if (DCL_TYPE (src) == DCL_TYPE (dest))
-           return checkType (dest->next, src->next);
+           return compareType (dest->next, src->next);
          else if (IS_PTR (src) && IS_PTR (dest))
            return -1;
          else if (IS_PTR (dest) && IS_ARRAY (src))
            return -1;
          else if (IS_PTR (dest) && IS_FUNC (dest->next) && IS_FUNC (src))
-           return -1 * checkType (dest->next, src);
+           return -1 * compareType (dest->next, src);
          else
            return 0;
        }
@@ -1660,7 +1660,7 @@ checkFunction (symbol * sym)
     }
 
   /* check the return value type   */
-  if (checkType (csym->type, sym->type) <= 0)
+  if (compareType (csym->type, sym->type) <= 0)
     {
       werror (E_PREV_DEF_CONFLICT, csym->name, "type");
       werror (E_CONTINUE, "previous definition type ");
@@ -1716,7 +1716,7 @@ checkFunction (symbol * sym)
          checkValue = acargs;
        }
 
-      if (checkType (exargs->type, checkValue->type) <= 0)
+      if (compareType (exargs->type, checkValue->type) <= 0)
        {
          werror (E_ARG_TYPE, argCnt);
          return 0;
index a2859937eaf4f16ff1f053899363364968b4ede2..7033b2cdfde01f98a706637328c0a6a23c43dfaa 100644 (file)
@@ -427,7 +427,7 @@ unsigned int bitsForType (sym_link *);
 sym_link *newIntLink ();
 sym_link *newCharLink ();
 sym_link *newLongLink ();
-int checkType (sym_link *, sym_link *);
+int compareType (sym_link *, sym_link *);
 int checkFunction (symbol *);
 void cleanUpLevel (bucket **, int);
 void cleanUpBlock (bucket **, int);
index 5e42b7ad7692b5245fd9a8675ef4006181b894b6..b3d2a81f7e5296e2a382333759fd79c1016a9447 100644 (file)
@@ -2133,7 +2133,7 @@ packRegisters (eBBlock * ebp)
 
                                /* if the type from and type to are the same
                                   then if this is the only use then packit */
-                               if (checkType (operandType (IC_RIGHT (ic)),
+                               if (compareType (operandType (IC_RIGHT (ic)),
                                               operandType (IC_LEFT (ic))) ==
                                    1) {
                                        iCode *dic =
index b2aa0866c80bbe948e11d831c408ecc3dccebd6c..e030c416b89bbf2a78336b474ebcb6ef1ea32411 100644 (file)
@@ -2443,7 +2443,7 @@ packRegisters (eBBlock * ebp)
 
              /* if the type from and type to are the same
                 then if this is the only use then packit */
-             if (checkType (operandType (IC_RIGHT (ic)),
+             if (compareType (operandType (IC_RIGHT (ic)),
                             operandType (IC_LEFT (ic))) == 1)
                {
                  iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
index 2bdf5298bbcec6859318fe1e5fe66948083ed818..1c8d487bdc67407d1878341b82cd38d8aeb0ad70 100644 (file)
@@ -2442,7 +2442,7 @@ packRegisters (eBBlock * ebp)
 
              /* if the type from and type to are the same
                 then if this is the only use then packit */
-             if (checkType (operandType (IC_RIGHT (ic)),
+             if (compareType (operandType (IC_RIGHT (ic)),
                             operandType (IC_LEFT (ic))) == 1)
                {
                  iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
index 0e391bb83b94e6a87321f87783fa1dc94654edbc..dcda469f175490e57b975c23d116994c3f108eef 100644 (file)
@@ -2924,7 +2924,7 @@ packRegisters (eBBlock * ebp)
 
              /* if the type from and type to are the same
                 then if this is the only use then packit */
-             if (checkType (operandType (IC_RIGHT (ic)),
+             if (compareType (operandType (IC_RIGHT (ic)),
                             operandType (IC_LEFT (ic))) == 1)
                {
                  iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
index 617e7c3f8970cdedb108f8788fcf911d5cd577d5..e92f339f304a4111c11f6ed56c7117d5c3a4e19c 100644 (file)
@@ -355,6 +355,8 @@ struct
     "stray '\\' at column %d" },
 { W_NEWLINE_IN_STRING, ERROR_LEVEL_WARNING,
     "newline in string constant" },
+{ E_CANNOT_USE_GENERIC_POINTER, ERROR_LEVEL_ERROR,
+    "cannot use generic pointer %s to initialize %s" },
 };
 
 /*
index 94d461706873ec24e29be81cb50fd0c15ef08e4d..8fcfa411514d37dec419a34b22524cdb509161df 100644 (file)
@@ -166,6 +166,7 @@ SDCCERR - SDCC Standard error handler
 #define        E_ARGUMENT_MISSING      148     /* Option requires an argument. */
 #define W_STRAY_BACKSLASH 149
 #define W_NEWLINE_IN_STRING 150 
+#define E_CANNOT_USE_GENERIC_POINTER 151
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.