From 9388b031d56edbb7a48626d6fb573d3a411f61fd Mon Sep 17 00:00:00 2001 From: johanknol Date: Sat, 30 Jun 2001 19:59:45 +0000 Subject: [PATCH] a fix for the initialized structs and some others, see 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 --- src/SDCCast.c | 16 ++++++++-------- src/SDCCcse.c | 6 +++--- src/SDCCglue.c | 38 ++++++++++++++++++++++++++------------ src/SDCCicode.c | 18 +++++++++--------- src/SDCCmain.c | 4 +--- src/SDCCopt.c | 6 +++--- src/SDCCsymt.c | 16 ++++++++-------- src/SDCCsymt.h | 2 +- src/avr/ralloc.c | 2 +- src/ds390/ralloc.c | 2 +- src/mcs51/ralloc.c | 2 +- src/pic/ralloc.c | 2 +- support/Util/SDCCerr.c | 2 ++ support/Util/SDCCerr.h | 1 + 14 files changed, 66 insertions(+), 51 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index df6cccff..6b384a7e 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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)) diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 8d059f92..0434ea01 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -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; } diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 3ef90f22..6552a80f 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -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)))); } diff --git a/src/SDCCicode.c b/src/SDCCicode.c index c1b48ed8..ea4f48d5 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -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); } diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 31d5fdca..3479f6c6 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -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]; diff --git a/src/SDCCopt.c b/src/SDCCopt.c index cb7c6bc3..c6160ccf 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -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]; diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 98fd50fe..51e3e844 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -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; diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index a2859937..7033b2cd 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -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); diff --git a/src/avr/ralloc.c b/src/avr/ralloc.c index 5e42b7ad..b3d2a81f 100644 --- a/src/avr/ralloc.c +++ b/src/avr/ralloc.c @@ -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 = diff --git a/src/ds390/ralloc.c b/src/ds390/ralloc.c index b2aa0866..e030c416 100644 --- a/src/ds390/ralloc.c +++ b/src/ds390/ralloc.c @@ -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); diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 2bdf5298..1c8d487b 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -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); diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 0e391bb8..dcda469f 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -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); diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 617e7c3f..e92f339f 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -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" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 94d46170..8fcfa411 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -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. -- 2.30.2