{
initList *nilist;
-
nilist = Safe_alloc (sizeof (initList));
nilist->type = type;
- nilist->lineno = lexLineno;
nilist->filename = lexFilename;
+ nilist->lineno = lexLineno;
switch (type)
{
}
/*------------------------------------------------------------------*/
-/* revinit - reverses the initial values for a value chain */
+/* revinit - reverses the initial values for a value chain */
/*------------------------------------------------------------------*/
initList *
revinit (initList * val)
}
bool
-convertIListToConstList(initList *src, literalList **lList)
+convertIListToConstList(initList *src, literalList **lList, int size)
{
+ int cnt = 0;
initList *iLoop;
literalList *head, *last, *newL;
head = last = NULL;
- if (!src || src->type != INIT_DEEP)
+ if (src && src->type != INIT_DEEP)
{
return FALSE;
}
- iLoop = src->init.deep;
+ iLoop = src ? src->init.deep : NULL;
while (iLoop)
{
return FALSE;
}
iLoop = iLoop->next;
+ cnt++;
+ }
+ if (!size)
+ {
+ size = cnt;
}
/* We've now established that the initializer list contains only literal values. */
- iLoop = src->init.deep;
- while (iLoop)
+ iLoop = src ? src->init.deep : NULL;
+ while (size--)
{
- double val = AST_FLOAT_VALUE(iLoop->init.node);
+ double val = iLoop ? AST_FLOAT_VALUE(iLoop->init.node) : 0;
if (last && last->literalValue == val)
{
}
last = newL;
}
- iLoop = iLoop->next;
+ iLoop = iLoop ? iLoop->next : NULL;
}
if (!head)
/*------------------------------------------------------------------*/
-/* copyIlist - copy initializer list */
+/* copyIlist - copy initializer list */
/*------------------------------------------------------------------*/
initList *
copyIlist (initList * src)
ast *
list2expr (initList * ilist)
{
+ if (!ilist)
+ return NULL;
if (ilist->type == INIT_DEEP)
return list2expr (ilist->init.deep);
return ilist->init.node;
value *constVal (const char *s)
{
value *val;
- bool hex = FALSE, octal = FALSE;
char *p;
double dval;
+ bool is_integral = 0;
val = newValue (); /* alloc space for value */
SPEC_NOUN (val->type) = V_CHAR;
SPEC_USIGN (val->type) = 0;
- if (s[0] == '0')
- {
- if (s[1] == 'x' || s[1] == 'X')
- hex = TRUE;
- else if (isdigit(s[1]))
- octal = TRUE;
- }
-
errno = 0;
- if (hex || octal)
+ if (s[0] == '0')
{
- dval = strtoul (s, &p, 0);
- if (errno)
- {
- dval = 4294967295.0;
- werror (W_INVALID_INT_CONST, s, dval);
- }
+ if (s[1] == 'b' || s[1] == 'B')
+ dval = strtoul (s + 2, &p, 2);
+ else
+ dval = strtoul (s, &p, 0);
+ is_integral = 1;
}
else
+ dval = strtod (s, &p);
+
+ if (errno)
{
- dval = strtod(s, &p);
+ dval = 4294967295.0;
+ werror (W_INVALID_INT_CONST, s, dval);
}
/* Setup the flags first */
}
else if (dval > 0x7fff && !SPEC_USIGN (val->type))
{ /* check if we have to promote to long int */
- if ((hex || octal) && /* hex or octal constants may be stored in unsigned type */
+ if (is_integral && /* integral (hex, octal and binary) constants may be stored in unsigned type */
dval <= 0xffff)
{
SPEC_USIGN (val->type) = 1;
if (IS_FLOAT (val->type))
SPEC_CVAL (val->type).v_float = floatFromVal (lval) / floatFromVal (rval);
- else
- if (IS_FIXED16X16 (val->type))
+ else if (IS_FIXED16X16 (val->type))
SPEC_CVAL (val->type).v_fixed16x16 = fixed16x16FromDouble( floatFromVal (lval) / floatFromVal (rval) );
else if (SPEC_LONG (val->type))
{