if (!bitsize)
bitsize = BITVAR_PAD;
$$->bitVar = bitsize;
+ $$->bitUnnamed = 1;
}
| declarator ':' constant_expr
{
/* createIvalStruct - generates initial value for structures */
/*-----------------------------------------------------------------*/
static ast *
-createIvalStruct (ast * sym, sym_link * type, initList * ilist, ast *rootValue)
+createIvalStruct (ast *sym, sym_link *type, initList *ilist, ast *rootValue)
{
ast *rast = NULL;
ast *lAst;
initList *iloop;
sym_link * etype = getSpec (type);
- sflds = SPEC_STRUCT (type)->fields;
if (ilist && ilist->type != INIT_DEEP)
{
werror (E_INIT_STRUCT, "");
iloop = ilist ? ilist->init.deep : NULL;
- for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL))
+ for (sflds = SPEC_STRUCT (type)->fields; sflds; sflds = sflds->next)
{
/* if we have come to end */
if (!iloop && (!AST_SYMBOL (rootValue)->islocal || SPEC_STAT (etype)))
+ break;
+
+ if (!IS_BITFIELD (sflds->type) || !SPEC_BUNNAMED (sflds->etype))
{
- break;
+ sflds->implicit = 1;
+ lAst = newNode (PTR_OP, newNode ('&', sym, NULL), newAst_VALUE (symbolVal (sflds)));
+ lAst = decorateType (resolveSymbols (lAst), RESULT_TYPE_NONE);
+ rast = decorateType (resolveSymbols (createIval (lAst, sflds->type, iloop, rast, rootValue)), RESULT_TYPE_NONE);
+ iloop = iloop ? iloop->next : NULL;
}
-
- sflds->implicit = 1;
- lAst = newNode (PTR_OP, newNode ('&', sym, NULL), newAst_VALUE (symbolVal (sflds)));
- lAst = decorateType (resolveSymbols (lAst), RESULT_TYPE_NONE);
- rast = decorateType (resolveSymbols (createIval (lAst, sflds->type,
- iloop, rast, rootValue)),
- RESULT_TYPE_NONE);
}
if (iloop)
sym->opval.val->sym->name);
else
werrorfl (sym->filename, sym->lineno, E_INIT_COUNT);
- }
+ }
return rast;
}
/*-----------------------------------------------------------------*/
/* printIvalBitFields - generate initializer for bitfields */
/*-----------------------------------------------------------------*/
-void printIvalBitFields(symbol **sym, initList **ilist, struct dbuf_s * oBuf)
+static void
+printIvalBitFields (symbol **sym, initList **ilist, struct dbuf_s * oBuf)
{
- value *val ;
symbol *lsym = *sym;
- initList *lilist = *ilist ;
+ initList *lilist = *ilist;
unsigned long ival = 0;
int size = 0;
- do
+ while (lsym)
{
- unsigned long i;
- val = list2val (lilist);
- if (size)
+
+ if (0 == SPEC_BLEN (lsym->etype))
{
- if (SPEC_BLEN (lsym->etype) > 8)
- {
- size += ((SPEC_BLEN (lsym->etype) / 8) +
- (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
- }
+ /* bit-field structure member with a width of 0 */
+ break;
}
- else
+ else if (!SPEC_BUNNAMED (lsym->etype))
{
- size = ((SPEC_BLEN (lsym->etype) / 8) +
- (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
- }
+ /* not an unnamed bit-field structure member */
+ value *val = list2val (lilist);
+ int bit_length = SPEC_BLEN (lsym->etype);
- /* check if the literal value is within bounds */
- if (val &&
- checkConstantRange (lsym->etype, val->etype, '=', FALSE) == CCR_OVL &&
- !options.lessPedantic)
- {
- werror (W_LIT_OVERFLOW);
- }
+ if (size)
+ {
+ if (bit_length > 8)
+ size += (bit_length + 7) / 8;
+ }
+ else
+ size = (bit_length + 7) / 8;
- 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;
+ /* check if the literal value is within bounds */
+ if (val &&
+ checkConstantRange (lsym->etype, val->etype, '=', FALSE) == CCR_OVL &&
+ !options.lessPedantic)
+ {
+ werror (W_LIT_OVERFLOW);
+ }
+
+ ival |= (ulFromVal (val) & ((1ul << bit_length) - 1ul)) << SPEC_BSTR (lsym->etype);
+ lilist = lilist ? lilist->next : NULL;
+ }
lsym = lsym->next;
- lilist = lilist ? lilist->next : NULL;
}
- while (1);
switch (size)
- {
- case 1:
- dbuf_tprintf (oBuf, "\t!db !constbyte\n", ival);
- break;
+ {
+ case 1:
+ dbuf_tprintf (oBuf, "\t!db !constbyte\n", ival);
+ break;
- case 2:
- dbuf_tprintf (oBuf, "\t!dw !constword\n", ival);
- break;
+ case 2:
+ dbuf_tprintf (oBuf, "\t!dw !constword\n", ival);
+ break;
- case 4:
- dbuf_tprintf (oBuf, "\t!dw !constword,!constword\n",
- (ival >> 16) & 0xffff, (ival & 0xffff));
- break;
- }
+ case 4:
+ dbuf_tprintf (oBuf, "\t!dw !constword,!constword\n",
+ (ival >> 16) & 0xffff, (ival & 0xffff));
+ break;
+ }
*sym = lsym;
*ilist = lilist;
}
/*-----------------------------------------------------------------*/
/* printIvalStruct - generates initial value for structures */
/*-----------------------------------------------------------------*/
-void
+static void
printIvalStruct (symbol * sym, sym_link * type,
initList * ilist, struct dbuf_s * oBuf)
{
sflds = SPEC_STRUCT (type)->fields;
- if (ilist) {
- if (ilist->type != INIT_DEEP) {
- werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
- return;
- }
+ if (ilist)
+ {
+ if (ilist->type != INIT_DEEP)
+ {
+ werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
+ return;
+ }
- iloop = ilist->init.deep;
- }
+ iloop = ilist->init.deep;
+ }
- if (SPEC_STRUCT (type)->type == UNION) {
- 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, TRUE);
- }
+ if (SPEC_STRUCT (type)->type == UNION)
+ {
+ printIval (sym, sflds->type, iloop, oBuf, 1);
+ iloop = iloop ? iloop->next : NULL;
}
- }
- if (iloop) {
+ else
+ {
+ while (sflds)
+ {
+ if (IS_BITFIELD (sflds->type))
+ printIvalBitFields(&sflds, &iloop, oBuf);
+ else
+ printIval (sym, sflds->type, iloop, oBuf, 1);
+ sflds = sflds->next;
+ iloop = iloop ? iloop->next : NULL;
+ }
+ }
+
+ if (iloop)
werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "struct", sym->name);
- }
- return;
}
/*-----------------------------------------------------------------*/
{
if (!size)
{
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "size should never be 0");
+
/* we have not been given a size, but now we know it */
size = strlen (SPEC_CVAL (val->etype).v_char) + 1;
/* but first check, if it's a flexible array */
/* if this is a bit field */
if (loop->bitVar) {
+ SPEC_BUNNAMED (loop->etype) = loop->bitUnnamed;
+
/* change it to a unsigned bit */
SPEC_NOUN (loop->etype) = V_BITFIELD;
/* ISO/IEC 9899 J.3.9 implementation defined behaviour: */
#define GPTYPE_XSTACK 0x60
#define GPTYPE_CODE 0x80
#else
-#define GPTYPE_FAR (port->gp_tags.tag_far)
-#define GPTYPE_NEAR (port->gp_tags.tag_near)
-#define GPTYPE_XSTACK (port->gp_tags.tag_xstack)
-#define GPTYPE_CODE (port->gp_tags.tag_code)
+#define GPTYPE_FAR (port->gp_tags.tag_far)
+#define GPTYPE_NEAR (port->gp_tags.tag_near)
+#define GPTYPE_XSTACK (port->gp_tags.tag_xstack)
+#define GPTYPE_CODE (port->gp_tags.tag_code)
#endif
#define HASHTAB_SIZE 256
unsigned b_typedef:1; /* is typedefed */
unsigned b_isregparm:1; /* is the first parameter */
unsigned b_isenum:1; /* is an enumerated type */
- unsigned _addr; /* address of symbol */
- unsigned _stack; /* stack offset for stacked v */
+ unsigned b_bitUnnamed:1; /* is an unnamed bit-field */
unsigned _bitStart; /* bit start position */
int _bitLength; /* bit length */
+ unsigned _addr; /* address of symbol */
+ unsigned _stack; /* stack offset for stacked v */
int argreg; /* reg no for regparm */
union
{ /* Values if constant or enum */
struct set *itmpStack; /* symbols spilt @ this stack location */
}
usl;
- short bitVar; /* this is a bit variable */
+ char bitVar; /* if bitVar != 0: this is a bit variable, bitVar is the size in bits */
+ char bitUnnamed:1; /* unnamed bit variable */
unsigned offset; /* offset from top if struct */
int lineDef; /* defined line number */
#define SPEC_CVAL(x) validateLink(x, "SPEC_CVAL", #x, SPECIFIER, __FILE__, __LINE__)->select.s.const_val
#define SPEC_BSTR(x) validateLink(x, "SPEC_BSTR", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
#define SPEC_BLEN(x) validateLink(x, "SPEC_BLEN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitLength
+#define SPEC_BUNNAMED(x) validateLink(x, "SPEC_BLEN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_bitUnnamed
/* Sleaze: SPEC_ISR_SAVED_BANKS is only used on
* function type symbols, which obviously cannot
/* pic16_printIvalBitFields - generate initializer for bitfields */
/*-----------------------------------------------------------------*/
static void
-pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
+pic16_printIvalBitFields (symbol **sym, initList **ilist, char ptype, void *p)
{
- value *val ;
symbol *lsym = *sym;
- initList *lilist = *ilist ;
+ initList *lilist = *ilist;
unsigned long ival = 0;
+ int size = 0;
unsigned long i;
- int size =0;
#if DEBUG_PRINTIVAL
#endif
- do {
- 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));
+ while (lsym)
+ {
+ if (0 == SPEC_BLEN (lsym->etype))
+ {
+ /* bit-field structure member with a width of 0 */
+ break;
+ }
+ else if (!SPEC_BUNNAMED (lsym->etype))
+ {
+ /* not an unnamed bit-field structure member */
+ value *val = list2val (lilist);
+ int bit_length = SPEC_BLEN (lsym->etype);
+
+ if (size)
+ {
+ if (bit_length > 8)
+ size += (bit_length + 7) / 8;
+ }
+ else
+ size = (bit_length + 7) / 8;
+
+ ival |= (ulFromVal (val) & ((1ul << bit_length) - 1ul)) << SPEC_BSTR (lsym->etype);
+ lilist = lilist->next;
+ }
+ lsym = lsym->next;
}
- i = (ulFromVal (val) & ((1ul << SPEC_BLEN (lsym->etype)) - 1ul));
- i <<= SPEC_BSTR (lsym->etype);
- ival |= i;
- if (! ( lsym->next &&
- (lilist && lilist->next) &&
- (IS_BITFIELD(lsym->next->type)) &&
- (SPEC_BSTR(lsym->next->etype)))) break;
- lsym = lsym->next;
- lilist = lilist->next;
- } while (1);
-
- for (i = 0; i < size; i++) {
- pic16_emitDB(BYTE_IN_LONG(ival, i), ptype, p);
- } // for
+
+ for (i = 0; i < size; i++)
+ pic16_emitDB (BYTE_IN_LONG (ival, i), ptype, p);
*sym = lsym;
*ilist = lilist;
sflds = SPEC_STRUCT (type)->fields;
- if (ilist) {
- if (ilist->type != INIT_DEEP) {
- werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
- return;
- }
+ if (ilist)
+ {
+ if (ilist->type != INIT_DEEP)
+ {
+ werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
+ return;
+ }
- iloop = ilist->init.deep;
- }
+ iloop = ilist->init.deep;
+ }
- for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
-// fprintf(stderr, "%s:%d sflds: %p\tiloop = %p\n", __FILE__, __LINE__, sflds, iloop);
- if (IS_BITFIELD(sflds->type)) {
- pic16_printIvalBitFields(&sflds, &iloop, ptype, p);
- } else {
- pic16_printIval (sym, sflds->type, iloop, ptype, p);
+ while (sflds)
+ {
+// fprintf(stderr, "%s:%d sflds: %p\tiloop = %p\n", __FILE__, __LINE__, sflds, iloop);
+ if (IS_BITFIELD (sflds->type))
+ {
+ pic16_printIvalBitFields (&sflds, &iloop, ptype, p);
+ }
+ else
+ {
+ pic16_printIval (sym, sflds->type, iloop, ptype, p);
+ sflds = sflds->next;
+ iloop = iloop ? iloop->next : NULL;
+ }
}
- }
- if (iloop) {
+ if (iloop)
werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "struct", sym->name);
- }
- return;
}
/*-----------------------------------------------------------------*/