From b0bb80a69b13a24479d0212bd0245c510717d702 Mon Sep 17 00:00:00 2001 From: johanknol Date: Sun, 4 Nov 2001 16:31:05 +0000 Subject: [PATCH] more function pointer parameter issues git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1496 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCast.c | 9 +++++++-- src/SDCCast.h | 1 - src/SDCCicode.c | 5 +---- src/SDCCmem.c | 6 +++--- src/SDCCsymt.c | 31 +++++++++++++++++++++---------- src/SDCCsymt.h | 2 +- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index a87ac07a..18921681 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -3094,7 +3094,6 @@ decorateType (ast * tree) if (processParms (tree->left, FUNC_ARGS(tree->left->ftype), tree->right, &parmNumber, TRUE)) { - //fprintf (stderr, "jwk: error in processParms()\n"); goto errorTreeReturn; } @@ -4102,6 +4101,9 @@ createFunction (symbol * name, ast * body) 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; @@ -4132,7 +4134,10 @@ createFunction (symbol * name, ast * body) } 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 */ diff --git a/src/SDCCast.h b/src/SDCCast.h index 32fe4692..3e5f7632 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -100,7 +100,6 @@ typedef struct ast sym_link *ftype; /* start of type chain for this subtree */ sym_link *etype; /* end of type chain for this subtree */ - symbol *argSym; /* argument symbols */ struct ast *left; /* pointer to left tree */ struct ast *right; /* pointer to right tree */ symbol *trueLabel; /* if statement trueLabel */ diff --git a/src/SDCCicode.c b/src/SDCCicode.c index f9470772..7dca929a 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2112,10 +2112,8 @@ geniCodeStruct (operand * left, operand * right, bool islval) SPEC_OCLS (retype) = SPEC_OCLS (etype); SPEC_VOLATILE (retype) |= SPEC_VOLATILE (etype); -#if 1 // jwk if (IS_PTR (element->type)) setOperandType (IC_RESULT (ic), aggrToPtr (operandType (IC_RESULT (ic)), TRUE)); -#endif IC_RESULT (ic)->isaddr = (!IS_AGGREGATE (element->type)); @@ -2734,8 +2732,7 @@ geniCodeParms (ast * parms, value *argVals, int *stack, } /* if register parm then make it a send */ - if ((parms->argSym && IS_REGPARM(parms->argSym->etype)) || - (IS_REGPARM (parms->etype) && !IFFUNC_HASVARARGS(func->type))) + if (IS_REGPARM (parms->etype) && !IFFUNC_HASVARARGS(func->type)) { ic = newiCode (SEND, pval, NULL); ADDTOCHAIN (ic); diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 8b958506..613de3e2 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -370,7 +370,6 @@ allocGlobal (symbol * sym) { /* set the output class */ SPEC_OCLS (sym->etype) = port->mem.default_globl_map; - // jwk: we need to set SPEC_SCLS now !!!! /* generate the symbol */ allocIntoSeg (sym); return; @@ -800,8 +799,9 @@ allocVariables (symbol * symChain) /* then args processing */ if (funcInChain (csym->type)) { - - processFuncArgs (csym, 1); +#if 1 // jwk: TODO should have been done already in addDecl() (oclass????) + processFuncArgs (csym); +#endif /* if register bank specified then update maxRegBank */ if (maxRegBank < FUNC_REGBANK (csym->type)) maxRegBank = FUNC_REGBANK (csym->type); diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 7056cf7e..d19342b5 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -122,14 +122,6 @@ addSym (bucket ** stab, } /* make sure the type is complete and sane */ checkTypeSanity(csym->etype, csym->name); - - // jwk: if this is a function ptr with a void arg, remove it - if (IS_DECL(csym->type) && DCL_TYPE(csym->type)==CPOINTER) { - sym_link *type=csym->type->next; - if (FUNC_ARGS(type) && SPEC_NOUN(FUNC_ARGS(type)->type)==V_VOID) { - FUNC_ARGS(type)=NULL; - } - } } /* prevent overflow of the (r)name buffers */ @@ -418,6 +410,9 @@ addDecl (symbol * sym, int type, sym_link * p) sym_link *tail; sym_link *t; + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "SDCCsymt.c:addDecl(%s,%d,%p)\n", sym->name, type, p); + /* if we are passed a link then set head & tail */ if (p) { @@ -480,6 +475,12 @@ addDecl (symbol * sym, int type, sym_link * p) SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p)); DCL_TSPEC (p) = NULL; } + + // if there is a function in this type chain + if (p && funcInChain(sym->type)) { + processFuncArgs (sym); + } + return; } @@ -1107,10 +1108,12 @@ compStructSize (int su, structdef * sdef) sum += getSize (loop->type); } +#if 0 // jwk: this is done now in addDecl() /* if function then do the arguments for it */ if (funcInChain (loop->type)) { - processFuncArgs (loop, 1); + processFuncArgs (loop); } +#endif loop = loop->next; @@ -1770,12 +1773,20 @@ checkFunction (symbol * sym, symbol *csym) /* processFuncArgs - does some processing with function args */ /*-----------------------------------------------------------------*/ void -processFuncArgs (symbol * func, int ignoreName) +processFuncArgs (symbol * func) { value *val; int pNum = 1; sym_link *funcType=func->type; + if (getenv("SDCC_DEBUG_FUNCTION_POINTERS")) + fprintf (stderr, "SDCCsymt.c:processFuncArgs(%s)\n", func->name); + + // if this is a pointer to a function + if (IS_PTR(funcType)) { + funcType=funcType->next; + } + /* if this function has variable argument list */ /* then make the function a reentrant one */ if (IFFUNC_HASVARARGS(funcType)) diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 6ff6e0a7..9aca2975 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -469,7 +469,7 @@ void addSymChain (symbol *); sym_link *structElemType (sym_link *, value *); symbol *getStructElement (structdef *, symbol *); sym_link *computeType (sym_link *, sym_link *); -void processFuncArgs (symbol *, int); +void processFuncArgs (symbol *); int isSymbolEqual (symbol *, symbol *); int powof2 (unsigned long); void printTypeChain (sym_link *, FILE *); -- 2.30.2