- value *val;
- ast *expr = list2expr (ilist);
-
- if (!expr)
- goto wrong;
-
- /* try it the oldway first */
- if ((val = constExprValue (expr, FALSE)))
- return val;
-
- /* ( ptr + constant ) */
- if (IS_AST_OP (expr) &&
- (expr->opval.op == '+' || expr->opval.op == '-') &&
- IS_AST_SYM_VALUE (expr->left) &&
- (IS_ARRAY(expr->left->ftype) || IS_PTR(expr->left->ftype)) &&
- compareType(toType, expr->left->ftype) &&
- IS_AST_LIT_VALUE (expr->right)) {
- return valForCastAggr (expr->left, expr->left->ftype,
- expr->right,
- expr->opval.op);
- }
-
- /* (char *)&a */
- if (IS_AST_OP(expr) && expr->opval.op==CAST &&
- IS_AST_OP(expr->right) && expr->right->opval.op=='&') {
- if (compareType(toType, expr->left->ftype)!=1) {
- werror (W_INIT_WRONG);
- printFromToType(expr->left->ftype, toType);
- }
- // skip the cast ???
- expr=expr->right;
- }
-
- /* no then we have to do these cludgy checks */
- /* pointers can be initialized with address of
- a variable or address of an array element */
- if (IS_AST_OP (expr) && expr->opval.op == '&') {
- /* address of symbol */
- if (IS_AST_SYM_VALUE (expr->left)) {
- val = copyValue (AST_VALUE (expr->left));
- val->type = newLink (DECLARATOR);
- if (SPEC_SCLS (expr->left->etype) == S_CODE) {
- DCL_TYPE (val->type) = CPOINTER;
- DCL_PTR_CONST (val->type) = port->mem.code_ro;
- }
- else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
- DCL_TYPE (val->type) = FPOINTER;
- else if (SPEC_SCLS (expr->left->etype) == S_XSTACK)
- DCL_TYPE (val->type) = PPOINTER;
- else if (SPEC_SCLS (expr->left->etype) == S_IDATA)
- DCL_TYPE (val->type) = IPOINTER;
- else if (SPEC_SCLS (expr->left->etype) == S_EEPROM)
- DCL_TYPE (val->type) = EEPPOINTER;
- else
- DCL_TYPE (val->type) = POINTER;
- val->type->next = expr->left->ftype;
- val->etype = getSpec (val->type);
- return val;
- }
-
- /* if address of indexed array */
- if (IS_AST_OP (expr->left) && expr->left->opval.op == '[')
- return valForArray (expr->left);
-
- /* if address of structure element then
- case 1. a.b ; */
- if (IS_AST_OP (expr->left) &&
- expr->left->opval.op == '.') {
- return valForStructElem (expr->left->left,
- expr->left->right);
- }
-
- /* case 2. (&a)->b ;
- (&some_struct)->element */
- if (IS_AST_OP (expr->left) &&
- expr->left->opval.op == PTR_OP &&
- IS_ADDRESS_OF_OP (expr->left->left)) {
- return valForStructElem (expr->left->left->left,
- expr->left->right);
- }
- }
- /* case 3. (((char *) &a) +/- constant) */
- if (IS_AST_OP (expr) &&
- (expr->opval.op == '+' || expr->opval.op == '-') &&
- IS_AST_OP (expr->left) && expr->left->opval.op == CAST &&
- IS_AST_OP (expr->left->right) &&
- expr->left->right->opval.op == '&' &&
- IS_AST_LIT_VALUE (expr->right)) {
-
- return valForCastAggr (expr->left->right->left,
- expr->left->left->opval.lnk,
- expr->right, expr->opval.op);
-
- }
- /* case 4. (char *)(array type) */
- if (IS_CAST_OP(expr) && IS_AST_SYM_VALUE (expr->right) &&
- IS_ARRAY(expr->right->ftype)) {
-
- val = copyValue (AST_VALUE (expr->right));
- val->type = newLink (DECLARATOR);
- if (SPEC_SCLS (expr->right->etype) == S_CODE) {
- DCL_TYPE (val->type) = CPOINTER;
- DCL_PTR_CONST (val->type) = port->mem.code_ro;
- }
- else if (SPEC_SCLS (expr->right->etype) == S_XDATA)
- DCL_TYPE (val->type) = FPOINTER;
- else if (SPEC_SCLS (expr->right->etype) == S_XSTACK)
- DCL_TYPE (val->type) = PPOINTER;
- else if (SPEC_SCLS (expr->right->etype) == S_IDATA)
- DCL_TYPE (val->type) = IPOINTER;
- else if (SPEC_SCLS (expr->right->etype) == S_EEPROM)
- DCL_TYPE (val->type) = EEPPOINTER;
- else
- DCL_TYPE (val->type) = POINTER;
- val->type->next = expr->right->ftype->next;
- val->etype = getSpec (val->type);
- return val;
- }
+ value *val;
+ ast *expr;
+
+ if (!ilist) {
+ return valCastLiteral(toType, 0.0);
+ }
+
+ expr = list2expr (ilist);
+
+ if (!expr)
+ goto wrong;
+
+ /* try it the old way first */
+ if ((val = constExprValue (expr, FALSE)))
+ return val;
+
+ /* ( ptr + constant ) */
+ if (IS_AST_OP (expr) &&
+ (expr->opval.op == '+' || expr->opval.op == '-') &&
+ IS_AST_SYM_VALUE (expr->left) &&
+ (IS_ARRAY(expr->left->ftype) || IS_PTR(expr->left->ftype)) &&
+ compareType(toType, expr->left->ftype) &&
+ IS_AST_LIT_VALUE (expr->right)) {
+ return valForCastAggr (expr->left, expr->left->ftype,
+ expr->right,
+ expr->opval.op);
+ }
+
+ /* (char *)&a */
+ if (IS_AST_OP(expr) && expr->opval.op==CAST &&
+ IS_AST_OP(expr->right) && expr->right->opval.op=='&') {
+ if (compareType(toType, expr->left->ftype)!=1) {
+ werror (W_INIT_WRONG);
+ printFromToType(expr->left->ftype, toType);
+ }
+ // skip the cast ???
+ expr=expr->right;
+ }
+
+ /* no then we have to do these cludgy checks */
+ /* pointers can be initialized with address of
+ a variable or address of an array element */
+ if (IS_AST_OP (expr) && expr->opval.op == '&') {
+ /* address of symbol */
+ if (IS_AST_SYM_VALUE (expr->left)) {
+ val = AST_VALUE (expr->left);
+ val->type = newLink (DECLARATOR);
+ if (SPEC_SCLS (expr->left->etype) == S_CODE) {
+ DCL_TYPE (val->type) = CPOINTER;
+ DCL_PTR_CONST (val->type) = port->mem.code_ro;
+ }
+ else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
+ DCL_TYPE (val->type) = FPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_XSTACK)
+ DCL_TYPE (val->type) = PPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_IDATA)
+ DCL_TYPE (val->type) = IPOINTER;
+ else if (SPEC_SCLS (expr->left->etype) == S_EEPROM)
+ DCL_TYPE (val->type) = EEPPOINTER;
+ else
+ DCL_TYPE (val->type) = POINTER;
+ val->type->next = expr->left->ftype;
+ val->etype = getSpec (val->type);
+ return val;
+ }
+
+ /* if address of indexed array */
+ if (IS_AST_OP (expr->left) && expr->left->opval.op == '[')
+ return valForArray (expr->left);
+
+ /* if address of structure element then
+ case 1. a.b ; */
+ if (IS_AST_OP (expr->left) &&
+ expr->left->opval.op == '.') {
+ return valForStructElem (expr->left->left,
+ expr->left->right);
+ }
+
+ /* case 2. (&a)->b ;
+ (&some_struct)->element */
+ if (IS_AST_OP (expr->left) &&
+ expr->left->opval.op == PTR_OP &&
+ IS_ADDRESS_OF_OP (expr->left->left)) {
+ return valForStructElem (expr->left->left->left,
+ expr->left->right);
+ }
+ }
+ /* case 3. (((char *) &a) +/- constant) */
+ if (IS_AST_OP (expr) &&
+ (expr->opval.op == '+' || expr->opval.op == '-') &&
+ IS_AST_OP (expr->left) && expr->left->opval.op == CAST &&
+ IS_AST_OP (expr->left->right) &&
+ expr->left->right->opval.op == '&' &&
+ IS_AST_LIT_VALUE (expr->right)) {
+
+ return valForCastAggr (expr->left->right->left,
+ expr->left->left->opval.lnk,
+ expr->right, expr->opval.op);
+
+ }
+ /* case 4. (char *)(array type) */
+ if (IS_CAST_OP(expr) && IS_AST_SYM_VALUE (expr->right) &&
+ IS_ARRAY(expr->right->ftype)) {
+
+ val = copyValue (AST_VALUE (expr->right));
+ val->type = newLink (DECLARATOR);
+ if (SPEC_SCLS (expr->right->etype) == S_CODE) {
+ DCL_TYPE (val->type) = CPOINTER;
+ DCL_PTR_CONST (val->type) = port->mem.code_ro;
+ }
+ else if (SPEC_SCLS (expr->right->etype) == S_XDATA)
+ DCL_TYPE (val->type) = FPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_XSTACK)
+ DCL_TYPE (val->type) = PPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_IDATA)
+ DCL_TYPE (val->type) = IPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_EEPROM)
+ DCL_TYPE (val->type) = EEPPOINTER;
+ else
+ DCL_TYPE (val->type) = POINTER;
+ val->type->next = expr->right->ftype->next;
+ val->etype = getSpec (val->type);
+ return val;
+ }