tree->opval.val->etype = tree->opval.val->etype;
tree->opval.val->type = tree->opval.val->sym->type;
werror (W_IMPLICIT_FUNC, tree->opval.val->sym->name);
+ allocVariables (tree->opval.val->sym);
}
else
{
/* have parameters */
if (func->type != EX_VALUE && !IS_RENT (fetype) && !options.stackAuto)
{
- werror (E_NONRENT_ARGS);
+ werror (W_NONRENT_ARGS);
return 1;
}
}
}
+
/* the parameter type must be at least castable */
- if (compareType (defParm->type, actParm->ftype) == 0)
- {
- werror (E_TYPE_MISMATCH_PARM, *parmNumber);
- werror (E_CONTINUE, "defined type ");
- printTypeChain (defParm->type, stderr);
- fprintf (stderr, "\n");
- werror (E_CONTINUE, "actual type ");
- printTypeChain (actParm->ftype, stderr);
- fprintf (stderr, "\n");
- }
+ if (compareType (defParm->type, actParm->ftype) == 0) {
+ werror (W_INCOMPAT_CAST);
+ fprintf (stderr, "type --> '");
+ printTypeChain (actParm->ftype, stderr);
+ fprintf (stderr, "' ");
+ fprintf (stderr, "assigned to type --> '");
+ printTypeChain (defParm->type, stderr);
+ fprintf (stderr, "'\n");
+ }
/* if the parameter is castable then add the cast */
if (compareType (defParm->type, actParm->ftype) < 0)
{
ast *aSym;
- aSym = newNode ('[', sym, newAst_VALUE (valueFromLit ((float) (++size))));
+ aSym = newNode ('[', sym, newAst_VALUE (valueFromLit ((float) (size++))));
aSym = decorateType (resolveSymbols (aSym));
rast = createIval (aSym, type->next, iloop, rast);
iloop = (iloop ? iloop->next : NULL);
/* if type is SPECIFIER */
if (IS_SPEC (type))
rast = createIvalType (sym, type, ilist);
+
if (wid)
return decorateType (resolveSymbols (newNode (NULLOP, wid, rast)));
else
/*-----------------------------------------------------------------*/
/* initAggregates - initialises aggregate variables with initv */
/*-----------------------------------------------------------------*/
-ast *
-initAggregates (symbol * sym, initList * ival, ast * wid)
-{
+
+/* this has to go */ void printIval (symbol *, sym_link *, initList *, FILE *);
+
+ast * initAggregates (symbol * sym, initList * ival, ast * wid) {
+ ast *ast;
+ symbol *newSym;
+
+ if (getenv("TRY_THE_NEW_INITIALIZER")) {
+
+ if (!TARGET_IS_MCS51 || !(options.model==MODEL_LARGE)) {
+ fprintf (stderr, "Can't \"TRY_THE_NEW_INITIALIZER\" unless "
+ "with -mmcs51 and --model-large");
+ exit(404);
+ }
+
+ if (SPEC_OCLS(sym->etype)==xdata &&
+ getSize(sym->type) > 16) { // else it isn't worth it: do it the old way
+
+ // copy this symbol
+ newSym=copySymbol (sym);
+ SPEC_OCLS(newSym->etype)=code;
+ sprintf (newSym->name, "%s_init__", sym->name);
+ sprintf (newSym->rname,"%s_init__", sym->rname);
+ addSym (SymbolTab, newSym, newSym->name, 0, 0, 1);
+
+ // emit it in the static segment
+ addSet(&statsg->syms, newSym);
+
+ // now memcpy() the entire array from cseg
+ ast=newNode (ARRAYINIT, // ASSIGN_AGGREGATE
+ newAst_VALUE (symbolVal (sym)),
+ newAst_VALUE (symbolVal (newSym)));
+ return decorateType(resolveSymbols(ast));
+ }
+ }
+
return createIval (newAst_VALUE (symbolVal (sym)), sym->type, ival, wid);
}
if (action == ALLOCATE)
{
- autoInit = gatherAutoInit (tree->values.sym);
*stack += allocVariables (tree->values.sym);
+ autoInit = gatherAutoInit (tree->values.sym);
/* if there are auto inits then do them */
if (autoInit)
if (check)
werror (E_CONST_EXPECTED, "found expression");
- return NULL;
+ return constVal("0");
}
/* return the value */
else
return FALSE;
}
-
+
return astHasSymbol (tree->left, sym) ||
astHasSymbol (tree->right, sym);
}
+/*-----------------------------------------------------------------*/
+/* astHasDeref - return true if the ast has an indirect access */
+/*-----------------------------------------------------------------*/
+static bool
+astHasDeref (ast * tree)
+{
+ if (!tree || IS_AST_LINK (tree) || IS_AST_VALUE(tree))
+ return FALSE;
+
+ if (tree->opval.op == '*' && tree->right == NULL) return TRUE;
+
+ return astHasDeref (tree->left) || astHasDeref (tree->right);
+}
+
/*-----------------------------------------------------------------*/
/* isConformingBody - the loop body has to conform to a set of rules */
/* for the loop to be considered reversible read on for rules */
if (astHasVolatile (pbody->left))
return FALSE;
+
+ if (astHasDeref(pbody->right)) return FALSE;
return isConformingBody (pbody->left, sym, body) &&
isConformingBody (pbody->right, sym, body);
}
-#define DEMAND_INTEGER_PROMOTION
+//#define DEMAND_INTEGER_PROMOTION
#ifdef DEMAND_INTEGER_PROMOTION
switch (tree->opval.op)
{
-/*------------------------------------------------------------------*/
-/*----------------------------*/
- /* array node */
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
+ /* array node */
+ /*----------------------------*/
case '[':
/* determine which is the array & which the index */
}
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* struct/union */
-/*----------------------------*/
+ /*----------------------------*/
case '.':
/* if this is not a structure */
if (!IS_STRUCT (LTYPE (tree)))
TETYPE (tree) = getSpec (TTYPE (tree));
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* struct/union pointer */
-/*----------------------------*/
+ /*----------------------------*/
case PTR_OP:
/* if not pointer to a structure */
if (!IS_PTR (LTYPE (tree)))
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
werror (E_BITWISE_OP);
- werror (E_CONTINUE, "left & right types are ");
+ werror (W_CONTINUE, "left & right types are ");
printTypeChain (LTYPE (tree), stderr);
fprintf (stderr, ",");
printTypeChain (RTYPE (tree), stderr);
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
werror (E_BITWISE_OP);
- werror (E_CONTINUE, "left & right types are ");
+ werror (W_CONTINUE, "left & right types are ");
printTypeChain (LTYPE (tree), stderr);
fprintf (stderr, ",");
printTypeChain (RTYPE (tree), stderr);
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (RTYPE (tree)))
{
werror (E_BITWISE_OP);
- werror (E_CONTINUE, "left & right types are ");
+ werror (W_CONTINUE, "left & right types are ");
printTypeChain (LTYPE (tree), stderr);
fprintf (stderr, ",");
printTypeChain (RTYPE (tree), stderr);
if (!IS_INTEGRAL (LTYPE (tree)) || !IS_INTEGRAL (tree->left->etype))
{
werror (E_SHIFT_OP_INVALID);
- werror (E_CONTINUE, "left & right types are ");
+ werror (W_CONTINUE, "left & right types are ");
printTypeChain (LTYPE (tree), stderr);
fprintf (stderr, ",");
printTypeChain (RTYPE (tree), stderr);
}
return tree;
-/*------------------------------------------------------------------*/
-/*----------------------------*/
+ /*------------------------------------------------------------------*/
+ /*----------------------------*/
/* casting */
-/*----------------------------*/
+ /*----------------------------*/
case CAST: /* change the type */
/* cannot cast to an aggregate type */
if (IS_AGGREGATE (LTYPE (tree)))
/* make sure the type is complete and sane */
checkTypeSanity(LETYPE(tree), "(cast)");
+#if 1
/* if the right is a literal replace the tree */
- if (IS_LITERAL (RETYPE (tree)) && !IS_PTR (LTYPE (tree)))
- {
- tree->type = EX_VALUE;
- tree->opval.val =
- valCastLiteral (LTYPE (tree),
- floatFromVal (valFromType (RETYPE (tree))));
- tree->left = NULL;
- tree->right = NULL;
- TTYPE (tree) = tree->opval.val->type;
- tree->values.literalFromCast = 1;
- }
- else
- {
- TTYPE (tree) = LTYPE (tree);
- LRVAL (tree) = 1;
- }
+ if (IS_LITERAL (RETYPE (tree))) {
+ if (!IS_PTR (LTYPE (tree))) {
+ tree->type = EX_VALUE;
+ tree->opval.val =
+ valCastLiteral (LTYPE (tree),
+ floatFromVal (valFromType (RETYPE (tree))));
+ tree->left = NULL;
+ tree->right = NULL;
+ TTYPE (tree) = tree->opval.val->type;
+ tree->values.literalFromCast = 1;
+ } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) &&
+ ((int)floatFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ {
+ sym_link *rest = LTYPE(tree)->next;
+ werror(W_LITERAL_GENERIC);
+ TTYPE(tree) = newLink();
+ DCL_TYPE(TTYPE(tree)) = FPOINTER;
+ TTYPE(tree)->next = rest;
+ tree->left->opval.lnk = TTYPE(tree);
+ LRVAL (tree) = 1;
+ } else {
+ TTYPE (tree) = LTYPE (tree);
+ LRVAL (tree) = 1;
+ }
+ } else {
+ TTYPE (tree) = LTYPE (tree);
+ LRVAL (tree) = 1;
+ }
+#else
+ /* if the right is a literal replace the tree */
+ if (IS_LITERAL (RETYPE (tree)) && !IS_PTR (LTYPE (tree))) {
+ tree->type = EX_VALUE;
+ tree->opval.val =
+ valCastLiteral (LTYPE (tree),
+ floatFromVal (valFromType (RETYPE (tree))));
+ tree->left = NULL;
+ tree->right = NULL;
+ TTYPE (tree) = tree->opval.val->type;
+ tree->values.literalFromCast = 1;
+ } else {
+ TTYPE (tree) = LTYPE (tree);
+ LRVAL (tree) = 1;
+ }
+#endif
TETYPE (tree) = getSpec (TTYPE (tree));
if (compareType (currFunc->type->next, RTYPE (tree)) == 0)
{
- werror (E_RETURN_MISMATCH);
+ werror (W_RETURN_MISMATCH);
goto errorTreeReturn;
}