ast *optimizeRRCRLC (ast *);
ast *optimizeGetHbit (ast *);
ast *backPatchLabels (ast *, symbol *, symbol *);
+void PA(ast *t);
int inInitMode = 0;
memmap *GcurMemmap=NULL; /* points to the memmap that's currently active */
FILE *codeOutFile;
dest->level = src->level;
dest->funcName = src->funcName;
+ if (src->ftype)
+ dest->etype = getSpec (dest->ftype = copyLinkChain (src->ftype));
+
/* if this is a leaf */
/* if value */
if (src->type == EX_VALUE)
/* if this is a node that has special values */
copyAstValues (dest, src);
- if (src->ftype)
- dest->etype = getSpec (dest->ftype = copyLinkChain (src->ftype));
-
dest->trueLabel = copySymbol (src->trueLabel);
dest->falseLabel = copySymbol (src->falseLabel);
dest->left = copyAst (src->left);
value *defParm,
ast * actParm,
int *parmNumber, // unused, although updated
- bool rightmost) // double checked?
+ bool rightmost)
{
/* if none of them exist */
if (!defParm && !actParm)
return 1;
}
+ if (IS_VOID(actParm->ftype)) {
+ werror (E_VOID_VALUE_USED);
+ return 1;
+ }
+
/* If this is a varargs function... */
if (!defParm && actParm && IFFUNC_HASVARARGS(func->ftype))
{
if (newType)
{
/* cast required; change this op to a cast. */
- ast *parmCopy = resolveSymbols (copyAst (actParm));
+ ast *parmCopy = decorateType(resolveSymbols (copyAst (actParm)));
actParm->type = EX_OP;
actParm->opval.op = CAST;
}
/* if defined parameters ended but actual has not & */
- /* stackAuto */
+ /* reentrant */
if (!defParm && actParm &&
(options.stackAuto || IFFUNC_ISREENT (func->ftype)))
return 0;
* Therefore, if there are more defined parameters, the caller didn't
* supply enough.
*/
- if (0 && rightmost && defParm->next)
+ if (rightmost && defParm->next)
{
werror (E_TOO_FEW_PARMS);
return 1;
/* the parameter type must be at least castable */
if (compareType (defParm->type, actParm->ftype) == 0) {
werror (E_INCOMPAT_TYPES);
- fprintf (stderr, "type --> '");
- printTypeChain (actParm->ftype, stderr);
- fprintf (stderr, "' ");
- fprintf (stderr, "assigned to type --> '");
- printTypeChain (defParm->type, stderr);
- fprintf (stderr, "'\n");
+ printFromToType (actParm->ftype, defParm->type);
return 1;
}
/* if the parameter is castable then add the cast */
if (compareType (defParm->type, actParm->ftype) < 0)
{
- ast *pTree = resolveSymbols (copyAst (actParm));
+ ast *pTree = decorateType(resolveSymbols (copyAst (actParm)));
/* now change the current one to a cast */
actParm->type = EX_OP;
actParm->right = pTree;
actParm->etype = defParm->etype;
actParm->ftype = defParm->type;
+ actParm->decorated=0; /* force typechecking */
+ decorateType (actParm);
}
/* make a copy and change the regparm type to the defined parm */
createIvalStruct (ast * sym, sym_link * type, initList * ilist)
{
ast *rast = NULL;
+ ast *lAst;
symbol *sflds;
initList *iloop;
for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL))
{
- ast *lAst;
-
/* if we have come to end */
if (!iloop)
break;
if (!TARGET_IS_MCS51 || !(options.model==MODEL_LARGE)) {
fprintf (stderr, "Can't \"TRY_THE_NEW_INITIALIZER\" unless "
- "with -mmcs51 and --model-large");
+ "with -mmcs51 and --model-large\n");
exit(404);
}
/* if bit field then error */
if (IS_BITVAR (tree->left->etype))
{
- werror (E_ILLEGAL_ADDR, "addrress of bit variable");
+ werror (E_ILLEGAL_ADDR, "address of bit variable");
goto errorTreeReturn;
}
goto errorTreeReturn;
}
- if (LRVAL (tree))
+ if (IS_LITERAL(LTYPE(tree)))
+ {
+ werror (E_ILLEGAL_ADDR, "address of literal");
+ goto errorTreeReturn;
+ }
+
+ if (LRVAL (tree))
{
werror (E_LVALUE_REQUIRED, "address of");
goto errorTreeReturn;
LRVAL (tree) = 1;
}
#else
+ /* if pointer to struct then check names */
+ if (IS_PTR(LTYPE(tree)) && IS_STRUCT(LTYPE(tree)->next) &&
+ IS_PTR(RTYPE(tree)) && IS_STRUCT(RTYPE(tree)->next) &&
+ strcmp(SPEC_STRUCT(LETYPE(tree))->tag,SPEC_STRUCT(RETYPE(tree))->tag)) {
+ werror(W_CAST_STRUCT_PTR,SPEC_STRUCT(RETYPE(tree))->tag,SPEC_STRUCT(LETYPE(tree))->tag);
+ }
/* if the right is a literal replace the tree */
if (IS_LITERAL (RETYPE (tree)) && !IS_PTR (LTYPE (tree))) {
tree->type = EX_VALUE;
TTYPE (tree) = LTYPE (tree);
LRVAL (tree) = 1;
}
-#endif
-
+#endif
TETYPE (tree) = getSpec (TTYPE (tree));
return tree;
if (IS_VOID (LTYPE (tree)))
{
werror (E_CAST_ZERO);
- fprintf (stderr, "type --> '");
- printTypeChain (RTYPE (tree), stderr);
- fprintf (stderr, "' ");
- fprintf (stderr, "assigned to type --> '");
- printTypeChain (LTYPE (tree), stderr);
- fprintf (stderr, "'\n");
+ printFromToType(RTYPE(tree), LTYPE(tree));
}
TETYPE (tree) = getSpec (TTYPE (tree) =
if (processParms (tree->left,
FUNC_ARGS(tree->left->ftype),
- tree->right, &parmNumber, TRUE))
+ tree->right, &parmNumber, TRUE)) {
goto errorTreeReturn;
+ }
if (options.stackAuto || IFFUNC_ISREENT (LTYPE (tree)))
{
- //IFFUNC_ARGS(tree->left->ftype) =
- //reverseVal (IFFUNC_ARGS(tree->left->ftype));
+ //FUNC_ARGS(tree->left->ftype) =
+ //reverseVal (FUNC_ARGS(tree->left->ftype));
reverseParms (tree->right);
}
if (compareType (currFunc->type->next, RTYPE (tree)) == 0)
{
werror (W_RETURN_MISMATCH);
- fprintf (stderr, "from type '");
- printTypeChain (RTYPE(tree), stderr);
- fprintf (stderr, "' to type '");
- printTypeChain (currFunc->type->next, stderr);
- fprintf (stderr, "'\n");
+ printFromToType (RTYPE(tree), currFunc->type->next);
goto errorTreeReturn;
}
sym_link *fetype;
iCode *piCode = NULL;
+ if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
+ fprintf (stderr, "SDCCast.c:createFunction(%s)\n", name->name);
+
/* if check function return 0 then some problem */
if (checkFunction (name, NULL) == 0)
return NULL;
}
name->lastLine = yylineno;
currFunc = name;
- processFuncArgs (currFunc, 0);
+
+#if 0 // jwk: this is now done in addDecl()
+ processFuncArgs (currFunc);
+#endif
/* set the stack pointer */
/* PENDING: check this for the mcs51 */
body = resolveSymbols (body); /* resolve the symbols */
body = decorateType (body); /* propagateType & do semantic checks */
- ex = newAst_VALUE (symbolVal (name)); /* create name */
+ ex = newAst_VALUE (symbolVal (name)); /* create name */
ex = newNode (FUNCTION, ex, body);
ex->values.args = FUNC_ARGS(name->type);
-
+ ex->decorated=1;
+ if (options.dump_tree) PA(ex);
if (fatalError)
{
werror (E_FUNC_NO_CODE, name->name);
}
if (tree->opval.op == FUNCTION) {
- fprintf(outfile,"FUNCTION (%p) type (",tree);
+ int arg=0;
+ value *args=FUNC_ARGS(tree->left->opval.val->type);
+ fprintf(outfile,"FUNCTION (%s=%p) type (",
+ tree->left->opval.val->name, tree);
printTypeChain (tree->ftype,outfile);
+ fprintf(outfile,") args (");
+ do {
+ if (arg) {
+ fprintf (outfile, ", ");
+ }
+ printTypeChain (args ? args->type : NULL, outfile);
+ arg++;
+ args= args ? args->next : NULL;
+ } while (args);
fprintf(outfile,")\n");
- ast_print(tree->left,outfile,indent+4);
- ast_print(tree->right,outfile,indent+4);
+ ast_print(tree->left,outfile,indent);
+ ast_print(tree->right,outfile,indent);
return ;
}
if (tree->opval.op == BLOCK) {
symbol *decls = tree->values.sym;
+ INDENT(indent,outfile);
fprintf(outfile,"{\n");
while (decls) {
INDENT(indent+4,outfile);
- fprintf(outfile,"DECLARE SYMBOL %s, type(",decls->name);
+ fprintf(outfile,"DECLARE SYMBOL (%s=%p) type (",
+ decls->name, decls);
printTypeChain(decls->type,outfile);
fprintf(outfile,")\n");
decls = decls->next;
}
ast_print(tree->right,outfile,indent+4);
+ INDENT(indent,outfile);
fprintf(outfile,"}\n");
return;
}
} else {
fprintf(outfile,"SYMBOL ");
}
- fprintf(outfile,"(%p) name= %s ",tree,tree->opval.val->sym->name);
+ fprintf(outfile,"(%s=%p)",
+ tree->opval.val->sym->name,tree);
}
if (tree->ftype) {
fprintf(outfile," type (");
/* casting */
/*----------------------------*/
case CAST: /* change the type */
- fprintf(outfile,"CAST (%p) type (",tree);
+ fprintf(outfile,"CAST (%p) from type (",tree);
+ printTypeChain(tree->right->ftype,outfile);
+ fprintf(outfile,") to type (");
printTypeChain(tree->ftype,outfile);
fprintf(outfile,")\n");
ast_print(tree->right,outfile,indent+4);
ast_print(tree->right,outfile,indent+4);
return;
case PARAM:
- fprintf(outfile,"PARM ");
+ fprintf(outfile,"PARMS\n");
ast_print(tree->left,outfile,indent+4);
if (tree->right && !IS_AST_PARAM(tree->right)) {
- fprintf(outfile,"PARM ");
ast_print(tree->right,outfile,indent+4);
}
return ;
/* ifx Statement */
/*----------------------------*/
case IFX:
- ast_print(tree->left,outfile,indent);
- INDENT(indent,outfile);
fprintf(outfile,"IF (%p) \n",tree);
+ ast_print(tree->left,outfile,indent+4);
if (tree->trueLabel) {
INDENT(indent,outfile);
- fprintf(outfile,"NE(==) 0 goto %s\n",tree->trueLabel->name);
+ fprintf(outfile,"NE(!=) 0 goto %s\n",tree->trueLabel->name);
}
if (tree->falseLabel) {
INDENT(indent,outfile);
fprintf(outfile,"EQ(==) 0 goto %s\n",tree->falseLabel->name);
}
- ast_print(tree->right,outfile,indent);
+ ast_print(tree->right,outfile,indent+4);
return ;
/*------------------------------------------------------------------*/
/*----------------------------*/
void PA(ast *t)
{
- ast_print(t,stdout,1);
+ ast_print(t,stdout,0);
}