Improved testing for missing required parameters in function calls
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 6 Feb 2001 17:52:35 +0000 (17:52 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 6 Feb 2001 17:52:35 +0000 (17:52 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@593 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
support/Util/SDCCerr.c

index 53702f36dc4c8e10a743b100daa69b1c50d1f397..1f09d811f5ad8d5c3b7829d5ca7df66c08157f12 100644 (file)
@@ -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))) {
index 7cd6602a909a78dbb963786b7e1499fea202d9ae..4a2c175beee6f390844ff081eba2208cfa9507fd 100644 (file)
@@ -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"},