changeset 488:62f3c801b6ac

correct_type fix. type attribute.
author kono
date Sat, 17 Dec 2005 10:32:34 +0900
parents b4d9809d6ee2
children 79fef53141b4
files Changes mc-codegen.c mc-parse.c mc-parse.h test/basic.c
diffstat 5 files changed, 66 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Fri Dec 16 20:27:34 2005 +0900
+++ b/Changes	Sat Dec 17 10:32:34 2005 +0900
@@ -7414,3 +7414,11 @@
     get_type_attr(type)
 
 かな。type_value みたいなのもいるかも。
+
+Fri Dec 16 20:57:40 JST 2005
+
+うーん、やっぱり、結構変更が大きいなぁ。しかも、テストルーチンが
+あんまり用意されてないし。
+
+correct_type のエラーかぁ。
+
--- a/mc-codegen.c	Fri Dec 16 20:27:34 2005 +0900
+++ b/mc-codegen.c	Sat Dec 17 10:32:34 2005 +0900
@@ -795,12 +795,12 @@
     if (ret_type==CHAR) ret_type=INT;
 
     /* check argments type is DOTS? */
-    t = caddr(e1);
-    if (/* t==0 || */ type_value(t)==DOTS) *dots = 1;
+    t = type_value(caddr(e1));
+    if (/* t==0 || */ t==DOTS) *dots = 1;
     else {
         *dots = 0;
-        for(;t;t = cadr(t)) {
-            if (type_value(car(t))==DOTS) *dots = 1;
+        for(;t;t = type_value(cadr(t))) {
+            if (car(t)==DOTS) *dots = 1;
         }
     }
 
@@ -1788,14 +1788,14 @@
     case FCONST:
 	e2 = dlist2(DCONST,dcadr(e2)); break;
     default:
-	switch(t) {
+	switch(type_value(type)) {
 	case DOUBLE: break;
 	case FLOAT: e2 =  list3(CONV,rvalue(e2),F2D); break;
 	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;
 	default:
-	    if(integral(t)) e2 =  list3(CONV,rvalue(e2),I2D);
+	    if(integral(type)) e2 =  list3(CONV,rvalue(e2),I2D);
 	    else { error(TYERR); e2 =  dlist2(DCONST,1.0); }
 	}
     }
@@ -1815,14 +1815,14 @@
     else if (car(e2)==CONST)  e2 = dlist2(FCONST,(double)cadr(e2));
     else if (car(e2)==DCONST)  e2 = dlist2(FCONST,dcadr(e2));
     else {
-	switch(t) {
+	switch(type_value(type)) {
 	case LONGLONG: e2 = list3(CONV,rvalue(e2),LL2F); break;
 	case ULONGLONG: e2 = list3(CONV,rvalue(e2),ULL2F); break;
 	case FLOAT: break;
 	case DOUBLE: e2 =  list3(CONV,rvalue(e2),D2F); break;
 	case UNSIGNED: e2 =  list3(CONV,rvalue(e2),U2F); break;
 	default:
-	    if(integral(t)) e2 =  list3(CONV,rvalue(e2),I2F);
+	    if(integral(type)) e2 =  list3(CONV,rvalue(e2),I2F);
 	    else { error(TYERR); e2 =  dlist2(DCONST,1.0); }
 	}
     }
@@ -1845,14 +1845,14 @@
         e2 = llist2(LCONST,(long long)dcadr(e2));
 #endif
     else {
-	switch(t) {
+	switch(type_value(type)) {
 	case FLOAT: e2 = list3(CONV,rvalue(e2),F2LL); break;
 	case DOUBLE: e2 = list3(CONV,rvalue(e2),D2LL); break;
 	case UNSIGNED: e2 = list3(CONV,rvalue(e2),U2LL); break;
 	case LONGLONG: break;
 	case ULONGLONG: break;
 	default:
-	    if(integral(t)) e2 = list3(CONV,rvalue(e2),I2LL);
+	    if(integral(type)) e2 = list3(CONV,rvalue(e2),I2LL);
 	    else { error(TYERR); e2 = llist2(LCONST,0LL); }
 	}
     }
@@ -1873,14 +1873,14 @@
         e2 = llist2(LCONST,(unsigned long long)dcadr(e2));
 #endif
     else {
-	switch(type) {
+	switch(type_value(type)) {
 	case FLOAT: e2 = list3(CONV,rvalue(e2),F2ULL); break;
 	case DOUBLE: e2 = list3(CONV,rvalue(e2),D2ULL); break;
 	case UNSIGNED: e2 = list3(CONV,rvalue(e2),U2ULL); break;
 	case LONGLONG: break;
 	case ULONGLONG: break;
 	default:
-	    if(integral(t)) e2 = list3(CONV,rvalue(e2),I2ULL);
+	    if(integral(type)) e2 = list3(CONV,rvalue(e2),I2ULL);
 	    else { error(TYERR); e2 = llist2(LCONST,0LL); }
 	}
     }
@@ -1893,7 +1893,7 @@
 int_value(int e2)
 {
     int t = type_value(type);
-    if (t>0&&car(t)==BIT_FIELD) e2=rvalue(e2);
+    if (t>0&&car(t)==BIT_FIELD) { e2=rvalue(e2); t=type_value(type); }
     if (0);
     else if(t>0&&car(t)==ARRAY) return e2;
     else if(scalar(t)) return e2;
@@ -1943,7 +1943,7 @@
 unsigned_value(int e2)
 {
     int t = type_value(type);
-    if (t>0&&car(t)==BIT_FIELD) e2=rvalue(e2);
+    if (t>0&&car(t)==BIT_FIELD) { e2=rvalue(e2); t=type_value(type); }
     else if(t>0&&car(t)==ARRAY) return e2;
     if (0);
     else if(scalar(t)) return e2;
@@ -2011,6 +2011,7 @@
 extern int
 assign_expr(int e1,int e2,int t) {
     /* we should check const / assign violation here */
+    t = type_value(t);
     switch(t) {
     case VOID:
 	break;
@@ -3835,7 +3836,7 @@
 	else if (type==CHAR) t=INT;
 	else if (type==UCHAR) t=UNSIGNED;
     }
-    if (type>0 && car(type)==ARRAY && car(e)==GVAR) {
+    if (type_value(type)>0 && car(type_value(type))==ARRAY && car(e)==GVAR) {
 	e=list2(ADDRESS,e);
     }
     if (t>0) {
@@ -3864,7 +3865,7 @@
 	    if (integral(t)) e = int_value(e);
 	}
     }
-    type = t0;
+    type = set_type_with_attr(t,t0);
     return e;
 }
 
--- a/mc-parse.c	Fri Dec 16 20:27:34 2005 +0900
+++ b/mc-parse.c	Sat Dec 17 10:32:34 2005 +0900
@@ -953,7 +953,7 @@
     }
     qualifiers();
     if (ctmode) {
-	t = set_type_attr(t,ctmode);
+	t = gset_type_attr(t,ctmode);
     }
     return t;
 }
@@ -3366,16 +3366,18 @@
 expr15(int e1)
 {
     int t,arglist,e,sz,argtypes,at,ftype;
+    int type0 = type_value(type);
 
     /* function call target */
 
-    if(type>0 && car(type)==POINTER) {
-	if (car(cadr(type))==FUNCTION||car(cadr(type))==CODE) {
+    if(type0>0 && car(type0)==POINTER) {
+	if (car(cadr(type0))==FUNCTION||car(cadr(type0))==CODE) {
 	    e1=rvalue(e1);
-	    type=cadr(type);
+	    type=set_type_with_attr(cadr(type0),type);
+	    type0 = type_value(type);
 	} /* else error */
     }
-    if(integral(type)||type<0|| ((car(type)!=FUNCTION)&&(car(type)!=CODE))) {
+    if(integral(type0)||type0<0|| ((car(type0)!=FUNCTION)&&(car(type0)!=CODE))) {
 	error(TYERR);
     }
     ftype = type;
@@ -3383,8 +3385,8 @@
 
     /* function argments */
 
-    argtypes = caddr(type);
-    if ((t=cadr(type))>=0 && (car(t)==STRUCT||car(t)==UNION)) {
+    argtypes = caddr(type_value(type));
+    if ((t=type_value(cadr(type0)))>=0 && (car(t)==STRUCT||car(t)==UNION)) {
 	/* skip return struct pointer */
 	if (argtypes==0) error(-1);
 	argtypes = cadr(argtypes);
@@ -3405,16 +3407,18 @@
     checksym(RPAR);
     conv->funcall_args_();
     if(t<0 && t==CODE) {
+	// code segment has no return type
 	type = ftype;
-	return list4(FUNCTION,e1,arglist,ftype);
+	return list4(FUNCTION,e1,arglist,ftype); // should be CODE?
     }
 
     /* return type */
 
     type = cadr(ftype); 
-    if(type==CHAR||type==SHORT) type=INT;
-    else if(type==UCHAR||type==USHORT) type=UNSIGNED;
-    else if(type>0 && (car(type)==STRUCT||car(type)==UNION)) {
+    type0 = type_value(type);
+    if(type0==CHAR||type0==SHORT) type=set_type_with_attr(INT,type);
+    else if(type0==UCHAR||type0==USHORT) type=set_type_with_attr(UNSIGNED,type);
+    else if(type0>0 && (car(type0)==STRUCT||car(type0)==UNION)) {
 	/* make temporary struct for return value */
 	/* but it is better to see we can reuse old one */
 	if (tmp_struct) {
@@ -4668,6 +4672,17 @@
 }
 
 extern int
+gset_type_attr(int type,int attr)
+{
+    if (type>0 && car(type)==ATTRIBUTE) {
+	caddr(type) = attr;
+    } else {
+	type = glist3(ATTRIBUTE,type,attr);
+    }
+    return type;
+}
+
+extern int
 get_type_attr(int type)
 {
     if (type>0 && car(type)==ATTRIBUTE) {
@@ -4691,7 +4706,17 @@
 set_type_with_attr(int type,int type_with_attr)
 {
     if (type_with_attr>0 && car(type_with_attr)==ATTRIBUTE) {
-	return list3(ATTRIBUTE,type_value(type),get_type_attr(type_with_attr));
+	return list3(ATTRIBUTE,type_value(type),caddr(type_with_attr));
+    } else {
+	return type;
+    }
+}
+
+extern int
+gset_type_with_attr(int type,int type_with_attr)
+{
+    if (type_with_attr>0 && car(type_with_attr)==ATTRIBUTE) {
+	return glist3(ATTRIBUTE,type_value(type),caddr(type_with_attr));
     } else {
 	return type;
     }
--- a/mc-parse.h	Fri Dec 16 20:27:34 2005 +0900
+++ b/mc-parse.h	Sat Dec 17 10:32:34 2005 +0900
@@ -118,9 +118,11 @@
 extern int attr_value(NMTBL *n,int attr);
 extern void set_attr(NMTBL *n,int attr,int value);
 extern int set_type_attr(int type,int attr);
+extern int gset_type_attr(int type,int attr);
 extern int get_type_attr(int type);
 extern int type_value(int type);
 extern int set_type_with_attr(int type,int type_with_attr);
+extern int gset_type_with_attr(int type,int type_with_attr);
 
 
 #if LONGLONG_CODE
--- a/test/basic.c	Fri Dec 16 20:27:34 2005 +0900
+++ b/test/basic.c	Sat Dec 17 10:32:34 2005 +0900
@@ -39,6 +39,7 @@
     dd = (int*) &f;
     printf("#0036:f %g\n",f);
     printf("#0037:dx %08x \n",*(dd));
+    return 1;
 }
 
 void
@@ -163,7 +164,7 @@
 
 }
 
-
+int
 main() {
     print(1.0);
     print(0.1234);