changeset 343:11f8f2e6bb72

fix eof and multi-file, mc-parse else-if switch
author kono
date Sun, 27 Jun 2004 10:39:18 +0900
parents 3e0b1183983d
children b7f07df0c0f8
files Changes mc-codegen.c mc-macro.c mc-parse.c
diffstat 4 files changed, 121 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Sat Jun 26 12:35:35 2004 +0900
+++ b/Changes	Sun Jun 27 10:39:18 2004 +0900
@@ -5202,3 +5202,21 @@
      bit.r == 1 を、and 0x100 にコンパイルする
 
 とかいろいろやることはあるけど、意味ないよな...
+
+Sat Jun 26 16:32:57 JST 2004
+
+で、local 変数の扱いだけど....
+
+    大域変数、局所変数、タグ名、フィールド名、型名、ラベル
+
+とあるわけだよね。で、スコープを任意にしたいわけだ。
+
+     nptr を、局所->局所->大域 にlinkするようにすれば良い
+
+malloc するようにする? それともlinkするようにするか。
+
+うーん、hash 計算無しで lsearch しているところがあるな。
+hash は別関数になってないし。
+
+
+
--- a/mc-codegen.c	Sat Jun 26 12:35:35 2004 +0900
+++ b/mc-codegen.c	Sun Jun 27 10:39:18 2004 +0900
@@ -427,6 +427,7 @@
     case ASS: case CASS: case SASS:
 	assign(e1);
 	return INT;
+    case SASSOP: case SUASSOP:
     case ASSOP: case CASSOP: case CUASSOP:
 	iassop(e1);
 	return INT;
@@ -1578,7 +1579,6 @@
 	switch(type) {
 	case DOUBLE: break;
 	case FLOAT: e2 =  list3(CONV,rvalue(e2),F2D); break;
-	case INT:
 	case UNSIGNED: e2 =  list3(CONV,rvalue(e2),U2D); break;
 	case LONGLONG: e2 =  list3(CONV,rvalue(e2),LL2D); break;
 	case ULONGLONG: e2 =  list3(CONV,rvalue(e2),ULL2D); break;
@@ -1611,7 +1611,6 @@
 	case ULONGLONG: e2 = list3(CONV,rvalue(e2),ULL2F); break;
 	case FLOAT: break;
 	case DOUBLE: e2 =  list3(CONV,rvalue(e2),D2F); break;
-	case INT:
 	case UNSIGNED: e2 =  list3(CONV,rvalue(e2),U2F); break;
 	default:
 	    if(integral(type)) e2 =  list3(CONV,rvalue(e2),I2F);
@@ -2403,9 +2402,11 @@
 		if (endian) n->dsp += size_of_int-size_of_short;
 	    }
 	    args += size_of_int;
+#if  0
 	} else if(type>0&&(type==UNION||type==STRUCT)) {
 	    n->dsp = args;
 	    args += ((sz+(size_of_int-1))&~(size_of_int-1));
+#endif
 	} else {
 	    /* if (n->dsp==0) (argument list in ADECL is useless, type
                list can be found in type ) */
--- a/mc-macro.c	Sat Jun 26 12:35:35 2004 +0900
+++ b/mc-macro.c	Sun Jun 27 10:39:18 2004 +0900
@@ -163,12 +163,18 @@
     return 0;
 }
 
+static int next_eof;
+
 extern void
 getline(void)
 {
     int i;
     int c;
 
+    if (next_eof) {
+	next_eof=0;
+	error(EOFERR);
+    }
     do {
 	if (chinput) {
 	    if (! *chinput) {
@@ -188,13 +194,14 @@
 	    while ((*chptr++ = c = getc(filep->fcb)) != '\n') {
 		if (++i > LBUFSIZE-2) error(LNERR);
 		if (c==EOF) {
-			error(EOFERR);
-			--chptr;
+		    next_eof=1;
+		    --chptr;
+		    break;
 		}
 	    }
 	}
 	*chptr = '\0';
-	if (lsrc && !asmf && !macro_if_skip) gen_comment(linebuf);
+	if (lsrc && !asmf && !macro_if_skip && linebuf[0]) gen_comment(linebuf);
 	if (*(chptr = linebuf) == '#' && !in_comment && !in_quote) {
 	    if (macro_processing()) return;
 	}
--- a/mc-parse.c	Sat Jun 26 12:35:35 2004 +0900
+++ b/mc-parse.c	Sun Jun 27 10:39:18 2004 +0900
@@ -917,38 +917,43 @@
 size(int t)
 {
     if (t<0) {
-	if(t==CHAR) return 1;
-	if(t==UCHAR) return 1;
-	if(t==VOID) return 0;
-	if(t==SHORT) return size_of_short;
-	if(t==USHORT) return size_of_short;
-	if(t==REGISTER) return size_of_int;
-	if(t==DREGISTER) return size_of_double;
-	if(t==FREGISTER) return size_of_float;
-	if(t==LREGISTER) return size_of_longlong;
-	if(scalar(t)) return size_of_int;
-	if(t==FLOAT) return size_of_float;
-	if(t==DOUBLE) return size_of_double;
-	if(t==LONGLONG) return size_of_longlong;
-	if(t==ULONGLONG) return size_of_longlong;
-	if(t==ENUM) return size_of_int;
-	error(DCERR);
+	switch(t) {
+	case CHAR: return 1;
+	case UCHAR: return 1;
+	case VOID: return 1;  /* not 0 */
+	case SHORT: return size_of_short;
+	case USHORT: return size_of_short;
+	case REGISTER: return size_of_int;
+	case DREGISTER: return size_of_double;
+	case FREGISTER: return size_of_float;
+	case LREGISTER: return size_of_longlong;
+	case FLOAT: return size_of_float;
+	case DOUBLE: return size_of_double;
+	case LONGLONG: return size_of_longlong;
+	case ULONGLONG: return size_of_longlong;
+	case ENUM: return size_of_int;
+	default:
+	    if(scalar(t)) return size_of_int;
+	    error(DCERR);
+	}
     } 
     /* type represented in a list */
-    if(car(t)==STRUCT||car(t)==UNION) {
+    switch(car(t)) {
+    case STRUCT:
+    case UNION:
 	if(cadr(t)==-1) error(DCERR);
 	return(cadr(t));
-    }
-    if(car(t)==ARRAY)
+    case ARRAY:
 	return(size(cadr(t))*caddr(t));
-    else if(car(t)==CODE)
+    case CODE:
+	return size_of_int;
+    case FUNCTION:
 	return size_of_int;
-    else if(car(t)==FUNCTION)
+    case POINTER:
 	return size_of_int;
-    else if(car(t)==POINTER)
-	return size_of_int;
-    else
+    default:
 	error(DCERR);
+    }
     return 0;
 }
 
@@ -2236,31 +2241,34 @@
 	getsym(0);
 	lcheck(e=expr13());
 	dir = op==INC?1:-1;
-	if(type==CHAR) {
+	switch(type) {
+	case CHAR:
 	    type= INT;  return(list4(PREINC,e,dir,1));
-	} else if(type==UCHAR) {
+	case UCHAR:
 	    type= UNSIGNED; return(list4(UPREINC,e,dir,1));
-	} else if(type==SHORT) {
+	case SHORT:
 	    type= INT;  return(list4(PREINC,e,dir,size_of_short));
-	} else if(type==USHORT) {
+	case USHORT:
 	    type= UNSIGNED;  return(list4(UPREINC,e,dir,size_of_short));
-	} else if(type==INT) {
-	    type= INT;  return(list4(PREINC,e,dir,size_of_int));
+	case INT:
+	    return(list4(PREINC,e,dir,size_of_int));
+	case UNSIGNED:
+	    return(list4(UPREINC,e,dir,size_of_int));
 #if LONGLONG_CODE
-	} else if(type==LONGLONG) {
-	    type= LONGLONG;  return(list4(LPREINC,e,dir,size_of_longlong));
-	} else if(type==ULONGLONG) {
-	    type= ULONGLONG;  return(list4(LUPREINC,e,dir,size_of_longlong));
+	case LONGLONG:
+	    return(list4(LPREINC,e,dir,size_of_longlong));
+	case ULONGLONG:
+	    return(list4(LUPREINC,e,dir,size_of_longlong));
 #endif
+#if FLOAT_CODE
+	case FLOAT:
+	    return(list3(FPREINC,e,dir));
+	case DOUBLE:
+	    return(list3(DPREINC,e,dir));
 	}
+#endif
 	if(integral(type))
 	    return(list4(PREINC,e,dir,size_of_int));
-#if FLOAT_CODE
-	if(type==FLOAT)
-	    return(list3(FPREINC,e,dir));
-	if(type==DOUBLE)
-	    return(list3(DPREINC,e,dir));
-#endif
 	if(type>0 && car(type)==BIT_FIELD) {
 	    e = list4(BPREINC,e,dir,type);
 	    type = cadr(type);
@@ -2268,8 +2276,7 @@
 	}
 	if(car(type)!=POINTER)
 	    error(TYERR);
-	return(list4(UPREINC,e,
-	    op==INC?size(cadr(type)):-size(cadr(type)),size_of_int ));
+	return(list4(UPREINC,e,dir*size(cadr(type)),size_of_int ));
     case MUL: /* *p */
 	conv->prefix_(sym);
 	getsym(0);
@@ -2362,12 +2369,17 @@
 		if(sym==INC||sym==DEC) {   
                     /* after this operation, type is extended */
 		    getsym(0);
-		    if(type==CHAR) type=INT;
-		    else if(type==SHORT) type=INT;
-		    else if(type==UCHAR) type=UNSIGNED;
-		    else if(type==USHORT) type=UNSIGNED;
-		    else if(!scalar(type)&&type!=FLOAT&&type!=DOUBLE)
-			error(TYERR);
+		    switch(type) {
+		    case CHAR:   type=INT; break;
+		    case SHORT:  type=INT; break;
+		    case UCHAR:  type=UNSIGNED; break;
+		    case USHORT: type=UNSIGNED; break;
+		    case FLOAT:
+		    case DOUBLE: break;
+		    default:
+			if(!scalar(type))
+			    error(TYERR);
+		    }
 		}
 	    }
 	} else
@@ -2386,31 +2398,24 @@
 	getsym(0);
 
 	dir = op==INC?1:-1;
-	if(type==CHAR) {
-	    type= INT;  return(list4(POSTINC,e,dir,1));
-	} else if(type==UCHAR) {
-	    type= UNSIGNED; return(list4(UPOSTINC,e,dir,1));
-	} else if(type==SHORT) {
-	    type= INT;  return(list4(POSTINC,e,dir,size_of_short));
-	} else if(type==USHORT) {
-	    type= UNSIGNED;  return(list4(UPOSTINC,e,dir,size_of_short));
-	} else if(type==INT) {
-	    type= INT;  return(list4(POSTINC,e,dir,size_of_int));
+	switch(type) {
+	case CHAR:   type= INT;      return(list4(POSTINC,e,dir,1));
+	case UCHAR:  type= UNSIGNED; return(list4(UPOSTINC,e,dir,1));
+	case SHORT:  type= INT;      return(list4(POSTINC,e,dir,size_of_short));
+	case USHORT: type= UNSIGNED; return(list4(UPOSTINC,e,dir,size_of_short));
+	case INT:                    return(list4(POSTINC,e,dir,size_of_int));
+	case UNSIGNED:               return(list4(UPOSTINC,e,dir,size_of_int));
+#if FLOAT_CODE
+	case FLOAT:                  return(list3(FPOSTINC,e,dir));
+	case DOUBLE:                 return(list3(DPOSTINC,e,dir));
+#endif
+#if LONGLONG_CODE
+	case LONGLONG:               return(list3(LPOSTINC,e,dir));
+	case ULONGLONG:              return(list3(LUPOSTINC,e,dir));
+#endif
 	}
 	if(integral(type))
 	    return(list4(POSTINC,e,dir,size_of_int));
-#if FLOAT_CODE
-	if(type==FLOAT)
-	    return(list3(FPOSTINC,e,dir));
-	if(type==DOUBLE)
-	    return(list3(DPOSTINC,e,dir));
-#endif
-#if LONGLONG_CODE
-	if(type==LONGLONG)
-	    return(list3(LPOSTINC,e,dir));
-	if(type==ULONGLONG)
-	    return(list3(LUPOSTINC,e,dir));
-#endif
 	if(type>0 && car(type)==BIT_FIELD) {
 	    e = list4(BPOSTINC,e,dir,type);
 	    type = cadr(type);
@@ -2720,11 +2725,15 @@
 static int
 typeid(int s)
 {
-    return (integral(s) || s==CODE || s==SHORT ||
-	s==LONG || s==STRUCT || s==UNION || s==ENUM ||
-	s==LONGLONG || s==FLOAT || s==DOUBLE || s==VOID ||
-	s==ULONGLONG  || s==TYPEOF ||
-    (s==IDENT && nptr->sc==TYPE));
+    switch(s) {
+	case CODE  : case SHORT :
+	case LONG  : case STRUCT  : case UNION  : case ENUM :
+	case LONGLONG  : case FLOAT  : case DOUBLE  : case VOID :
+	case ULONGLONG   : case TYPEOF :
+	    return 1;
+	case IDENT: return nptr->sc==TYPE;
+    }
+    return (integral(s));
 }
 
 static int
@@ -3314,18 +3323,12 @@
 	}
 	getch();
 	switch(c) {
-	case 'n':
-	    return '\n';
-	case 't':
-	    return '\t';
-	case 'b':
-	    return '\b';
-	case 'r':
-	    return '\r';
-	case 'f':
-	    return '\f';
-	case '\\':
-	    return '\\';
+	case 'n': return '\n';
+	case 't': return '\t';
+	case 'b': return '\b';
+	case 'r': return '\r';
+	case 'f': return '\f';
+	case '\\': return '\\';
 	case '\n':
 	    if (ch=='"') {
 		return 0;