symbol *interrupts[INTNO_MAX+1];
-void printIval (symbol *, sym_link *, initList *, struct dbuf_s *);
+void printIval (symbol *, sym_link *, initList *, struct dbuf_s *, bool check);
set *publics = NULL; /* public variables */
set *externs = NULL; /* Variables that are declared as extern */
++noAlloc;
resolveIvalSym (sym->ival, sym->type);
++noInit;
- printIval (sym, sym->type, sym->ival, &tmpBuf);
+ printIval (sym, sym->type, sym->ival, &tmpBuf, TRUE);
--noInit;
--noAlloc;
dbuf_destroy(&tmpBuf);
symbol *lsym = *sym;
initList *lilist = *ilist ;
unsigned long ival = 0;
- int size =0;
-
- do {
- unsigned long i;
- val = list2val(lilist);
- if (size) {
- if (SPEC_BLEN(lsym->etype) > 8) {
- size += ((SPEC_BLEN (lsym->etype) / 8) +
- (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
- }
- } else {
- size = ((SPEC_BLEN (lsym->etype) / 8) +
- (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
- }
+ int size = 0;
- /* check if the literal value is within bounds */
- if (checkConstantRange (lsym->etype, val->etype, '=', FALSE) == CCR_OVL &&
+ do
+ {
+ unsigned long i;
+ val = list2val (lilist);
+ if (size)
+ {
+ if (SPEC_BLEN (lsym->etype) > 8)
+ {
+ size += ((SPEC_BLEN (lsym->etype) / 8) +
+ (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
+ }
+ }
+ else
+ {
+ size = ((SPEC_BLEN (lsym->etype) / 8) +
+ (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
+ }
+
+ /* check if the literal value is within bounds */
+ if (val &&
+ checkConstantRange (lsym->etype, val->etype, '=', FALSE) == CCR_OVL &&
!options.lessPedantic)
- {
- werror (W_LIT_OVERFLOW);
- }
- i = ulFromVal(val);
- i &= (1 << SPEC_BLEN (lsym->etype)) - 1;
- i <<= SPEC_BSTR (lsym->etype);
- ival |= i;
- if (! ( lsym->next &&
- (IS_BITFIELD(lsym->next->type)) &&
- (SPEC_BSTR(lsym->next->etype)))) break;
- lsym = lsym->next;
- lilist = lilist ? lilist->next : NULL;
- } while (1);
- switch (size) {
+ {
+ werror (W_LIT_OVERFLOW);
+ }
+
+ i = ulFromVal (val);
+ i &= (1 << SPEC_BLEN (lsym->etype)) - 1;
+ i <<= SPEC_BSTR (lsym->etype);
+ ival |= i;
+ if (!(lsym->next &&
+ (IS_BITFIELD (lsym->next->type)) &&
+ (SPEC_BSTR (lsym->next->etype))))
+ break;
+ lsym = lsym->next;
+ lilist = lilist ? lilist->next : NULL;
+ }
+ while (1);
+
+ switch (size)
+ {
case 1:
- dbuf_tprintf (oBuf, "\t!db !constbyte\n",ival);
+ dbuf_tprintf (oBuf, "\t!db !constbyte\n", ival);
break;
case 2:
- dbuf_tprintf (oBuf, "\t!dw !constword\n",ival);
+ dbuf_tprintf (oBuf, "\t!dw !constword\n", ival);
break;
+
case 4:
dbuf_tprintf (oBuf, "\t!dw !constword,!constword\n",
- (ival >> 16) & 0xffff, (ival & 0xffff));
+ (ival >> 16) & 0xffff, (ival & 0xffff));
break;
}
*sym = lsym;
}
if (SPEC_STRUCT (type)->type == UNION) {
- printIval (sym, sflds->type, iloop, oBuf);
+ printIval (sym, sflds->type, iloop, oBuf, TRUE);
iloop = iloop ? iloop->next : NULL;
} else {
for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
if (IS_BITFIELD(sflds->type)) {
printIvalBitFields(&sflds, &iloop, oBuf);
} else {
- printIval (sym, sflds->type, iloop, oBuf);
+ printIval (sym, sflds->type, iloop, oBuf, TRUE);
}
}
}
/* printIvalChar - generates initital value for character array */
/*-----------------------------------------------------------------*/
int
-printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s)
+printIvalChar (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, char *s, bool check)
{
value *val;
unsigned int size = DCL_ELEM (type);
DCL_ELEM (type) = size;
}
+ if (check && DCL_ELEM (val->type) > size)
+ werror (W_EXCESS_INITIALIZERS, "array of chars", sym->name, sym->lineDef);
+
printChar (oBuf, SPEC_CVAL (val->etype).v_char, size);
return 1;
/*-----------------------------------------------------------------*/
void
printIvalArray (symbol * sym, sym_link * type, initList * ilist,
- struct dbuf_s * oBuf)
+ struct dbuf_s * oBuf, bool check)
{
value *val;
initList *iloop;
}
if (printIvalChar (sym, type,
(ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
- oBuf, SPEC_CVAL (sym->etype).v_char))
+ oBuf, SPEC_CVAL (sym->etype).v_char, check))
return;
}
/* not the special case */
werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "array", sym->name);
break;
}
- printIval (sym, type->next, iloop, oBuf);
+ printIval (sym, type->next, iloop, oBuf, TRUE);
}
}
/* printIval - generates code for initial value */
/*-----------------------------------------------------------------*/
void
-printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf)
+printIval (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * oBuf, bool check)
{
sym_link *itype;
/* if this is an array */
if (IS_ARRAY (type))
{
- printIvalArray (sym, type, ilist, oBuf);
+ printIvalArray (sym, type, ilist, oBuf, check);
return;
}
dbuf_printf (oBuf, "%s:\n", sym->rname);
++noAlloc;
resolveIvalSym (sym->ival, sym->type);
- printIval (sym, sym->type, sym->ival, oBuf);
+ printIval (sym, sym->type, sym->ival, oBuf, map != xinit);
--noAlloc;
/* if sym is a simple string and sym->ival is a string,
WE don't need it anymore */