changeset 523:009289571b54

*** empty log message ***
author kono
date Tue, 27 Dec 2005 17:57:24 +0900
parents a513979e5495
children 135afeb2e134
files mc-parse.c mc.h test/too-long-argument.c
diffstat 3 files changed, 48 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mc-parse.c	Tue Dec 27 17:19:49 2005 +0900
+++ b/mc-parse.c	Tue Dec 27 17:57:24 2005 +0900
@@ -268,6 +268,31 @@
     error handler
     when EOF, process next file
  */
+
+static int
+serious(int n)
+{
+    switch(n) {
+    case DCERR:  // "Declaration syntax" :
+    case STERR:  // "Statement syntax" :
+    case EXERR:  // "Expression syntax" :
+    case CNERR:  // "Constant required" :
+    case CHERR:  // "Illegal character" :
+    case MCERR:  // "Macro syntax" :
+    case INCERR:  // "Include syntax" :
+    case TYERR:  // "Type mismatch" :
+    case LVERR:  // "Lvalue required" :
+    case UDERR:  // "Undeclared identifier" :
+    case OPTION:  // "Illegal option" :
+    case INERR:  // "bad initialization" :
+    case AGERR:  // "wrong number of arguments" :
+    case CODE_ERR:  // "goto is necessary" :
+    case ILERR:  // "inline error" :
+    return 0;
+    }
+    return 1;
+}
+
 extern void
 error(int n)
 {
@@ -321,11 +346,13 @@
 	(n==RGERR) ? "too many register usage (internal error)" :
 	(n==REG_ERR) ? "illegal register var" :
 	(n==INERR) ? "bad initialization" :
+	(n==AGERR) ? "wrong number of arguments" :
 	(n==CODE_ERR) ? "goto is necessary" :
 	(n==ILERR) ? "inline error" :
 	"Bug of compiler");
     errmsg();
-    exit(1);
+    if (serious(n))
+	exit(1);
 }
 
 static void
@@ -3408,6 +3435,7 @@
 {
     int t,arglist,e,sz,argtypes,at,ftype;
     int type0 = type_value(type);
+    int dots;
 
     /* function call target */
 
@@ -3426,7 +3454,10 @@
 
     /* function argments */
 
-    argtypes = caddr(type_value(type));
+    function_type(ftype,&dots);
+
+    argtypes = caddr(type0);
+    if (!argtypes) dots=1;
     if ((t=type_value(cadr(type0)))>=0 && (car(t)==STRUCT||car(t)==UNION)) {
 	/* skip return struct pointer */
 	if (argtypes==0) error(-1);
@@ -3436,8 +3467,12 @@
     getsym(0);
     while(sym!=RPAR) {
 	e=rvalue(expr1());
-	if(argtypes==0) at=DOTS;
-	else if(car(argtypes)==DOTS) at=DOTS;
+	if(argtypes==0) {
+	    at=DOTS;
+	    if (!dots) {
+		error(AGERR);
+	    }
+	} else if(car(argtypes)==DOTS) at=DOTS;
         else { at=car(argtypes); argtypes=cadr(argtypes); }
 	e = correct_type(e,at);
 	arglist=list3(e,arglist,type);
@@ -3445,6 +3480,9 @@
 	conv->comma_();
 	getsym(0);
     }
+    if (!dots && argtypes && car(argtypes)!=VOID) {
+	error(AGERR);
+    }
     checksym(RPAR);
     conv->funcall_args_();
     if(t<0 && t==CODE) {
--- a/mc.h	Tue Dec 27 17:19:49 2005 +0900
+++ b/mc.h	Tue Dec 27 17:57:24 2005 +0900
@@ -459,7 +459,8 @@
 #define NMERR   26
 #define MMERR   27
 #define INERR   28
-#define ILERR   29
+#define AGERR   29
+#define ILERR   30
 
 /* error number end */
 
--- a/test/too-long-argument.c	Tue Dec 27 17:19:49 2005 +0900
+++ b/test/too-long-argument.c	Tue Dec 27 17:57:24 2005 +0900
@@ -30,14 +30,16 @@
 tcode4(int x,int y,CCC junction,code(*ret)(int),void *env)
 {
 
-     goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env);
+     // goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env);
+     goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,ret,env);
 }
 
 code
 tcode0(int x,int y,code(*junction)(int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,code(*)(int),void *),code(*ret)(int),void *env)
 {
 
-     goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env);
+     // goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,ret,env);
+     goto junction(0,1,2,3,4,5,6,7,8,9,10,11,12,13,ret,env);
 }
 
 int