From 082f775a5ac946a74ba526eeaf6ec0fa1148432b Mon Sep 17 00:00:00 2001 From: kvigor Date: Tue, 6 Feb 2001 17:52:35 +0000 Subject: [PATCH] Improved testing for missing required parameters in function calls git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@593 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCast.c | 47 ++++++++++++++++++++++++------------------ support/Util/SDCCerr.c | 8 +++---- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index 53702f36..1f09d811 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -556,9 +556,11 @@ void reverseParms (ast *ptree) /* processParms - makes sure the parameters are okay and do some */ /* processing with them */ /*-----------------------------------------------------------------*/ -int processParms (ast *func, value *defParm, - ast *actParm, - int *parmNumber) +int processParms (ast *func, + value *defParm, + ast *actParm, + int *parmNumber, + bool rightmost) { sym_link *fetype = func->etype; @@ -633,8 +635,8 @@ int processParms (ast *func, value *defParm, } else if ( actParm->type == EX_OP && actParm->opval.op == PARAM) { - return (processParms (func,NULL,actParm->left,parmNumber) || - processParms (func,NULL,actParm->right,parmNumber) ); + return (processParms(func,NULL,actParm->left,parmNumber,FALSE) || + processParms(func,NULL,actParm->right,parmNumber,rightmost)); } return 0; } @@ -647,22 +649,27 @@ int processParms (ast *func, value *defParm, resolveSymbols(actParm); /* if this is a PARAM node then match left & right */ - if ( actParm->type == EX_OP && actParm->opval.op == PARAM) { - return (processParms (func,defParm,actParm->left,parmNumber) || - processParms (func,defParm->next, actParm->right,parmNumber) ); + if ( actParm->type == EX_OP && actParm->opval.op == PARAM) + { + return (processParms(func,defParm,actParm->left,parmNumber,FALSE) || + processParms(func,defParm->next, actParm->right,parmNumber,rightmost)); } -#if 0 - /* Pending discussion with Johan. */ - else { - /* if more defined parameters present but no more actual parameters */ - if (defParm->next) { - werror(E_TOO_FEW_PARMS); - return 1; - } + else + { + /* If we have found a value node by following only right-hand links, + * then we know that there are no more values after us. + * + * Therefore, if there are more defined parameters, the caller didn't + * supply enough. + */ + if (rightmost && defParm->next) + { + werror(E_TOO_FEW_PARMS); + return 1; + } } -#endif - - /* the parameter type must be atleast castable */ + + /* the parameter type must be at least castable */ if (checkType(defParm->type,actParm->ftype) == 0) { werror(E_TYPE_MISMATCH_PARM,*parmNumber); werror(E_CONTINUE,"defined type "); @@ -2768,7 +2775,7 @@ ast *decorateType (ast *tree) if (processParms (tree->left, tree->left->args, - tree->right,&parmNumber)) + tree->right,&parmNumber,TRUE)) goto errorTreeReturn ; if (options.stackAuto || IS_RENT(LETYPE(tree))) { diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 7cd6602a..4a2c175b 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -42,15 +42,15 @@ struct { char *errText ; } ErrTab [] = { -{ ERROR ,"error *** Duplicate symbol '%s', symbol IGNORED\n" }, -{ ERROR ,"error *** Syntax Error Declaration ingonerd\n" }, +{ ERROR ,"error *** Duplicate symbol '%s', symbol IGNORED\n" }, +{ ERROR ,"error *** Syntax Error Declaration ignored\n" }, { ERROR ,"error *** Constant Expected Found Variable\n" }, { ERROR ,"error *** 'malloc' failed file '%s' for size %ld\n" }, { ERROR ,"error *** 'fopen' failed on file '%s'\n" }, { ERROR ,"error *** Internal Error Oclass invalid '%s'\n" }, { ERROR ,"error *** Cannot allocate variable '%s'.\n" }, { ERROR ,"error *** Old style C declaration. IGNORED '%s'\n" }, -{ ERROR ,"error *** Out of stack Space. '%s' not allocted\n" }, +{ ERROR ,"error *** Out of stack Space. '%s' not allocated\n" }, { ERROR ,"error *** FATAL Compiler Internal Error in file '%s' line number '%d' : %s \nContact Author with source code\n" }, { ERROR ,"error *** 'lvalue' required for '%s' operation .\n" }, { ERROR ,"error *** Creation of temp file failed\n" }, @@ -144,7 +144,7 @@ struct { { ERROR ,"error *** variable '%s' declared in code space must have initialiser\n" }, { ERROR ,"error *** operands not integral for assignment operation\n" }, { ERROR ,"error *** too many parameters \n" }, -{ ERROR ,"error *** to few parameters\n" }, +{ ERROR ,"error *** too few parameters\n" }, { ERROR ,"error *** code not generated for '%s' due to previous errors\n"}, { WARNING,"warning *** type mismatch for parameter number %d\n"}, { ERROR ,"error *** invalid float constant '%s'\n"}, -- 2.47.2