Mercurial > hg > CbC > old > device
diff mc-codegen.c @ 498:574856cee9da
printf double/int mix
cond operator fix
author | kono |
---|---|
date | Thu, 22 Dec 2005 11:50:32 +0900 |
parents | cc1a5f764782 |
children | d2570c00ca54 |
line wrap: on
line diff
--- a/mc-codegen.c Thu Dec 22 00:21:01 2005 +0900 +++ b/mc-codegen.c Thu Dec 22 11:50:32 2005 +0900 @@ -2017,6 +2017,33 @@ assign_expr(int e1,int e2,int t) { /* we should check const / assign violation here */ t = type_value(t); + if (t>0) { + switch(car(type_value(t))) { + case BIT_FIELD: + // type = list4(BIT_FIELD,type, + // list3(type /*store type*/,0 /*bit offset*/,bitsize)); + e2 = correct_type(e2,cadr(t)); /* value type */ + return(list4(BASS,e1,e2,list2(BASS,t))); + case STRUCT:case UNION: + if (size(t)!=size(type)) error(TYERR); + type=t; // dispose attr + if(car(e2)==RSTRUCT && car(cadr(e2))==FUNCTION) { + replace_return_struct(cadr(e2),e1); + return cadr(e2); + } else { + return (list4(STASS,e1,e2,size(t))); + } + default: + if(scalar(t)) { + if (car(t)!=POINTER) { + e2=(type_value(t)==UNSIGNED)? + unsigned_value(e2):int_value(e2); + } + return(list3(ASS,e1,e2)); + } + error(TYERR); return list3(ASS,e1,e2); + } + } switch(t) { case VOID: break; @@ -2026,6 +2053,9 @@ case SHORT:case USHORT: e2=(t==USHORT)?unsigned_value(e2):int_value(e2); return(list3(SASS,e1,e2)); + case INT:case UNSIGNED: case ENUM: + e2=(t==UNSIGNED)?unsigned_value(e2):int_value(e2); + return(list3(ASS,e1,e2)); #if FLOAT_CODE case DOUBLE: e2=double_value(e2); @@ -2042,27 +2072,6 @@ e2=ulonglong_value(e2); return(list3(LASS,e1,e2)); #endif - default: - if(scalar(t)) { - e2=(type_value(t)==UNSIGNED)?unsigned_value(e2):int_value(e2); - return(list3(ASS,e1,e2)); - } - switch(car(type_value(t))) { - case BIT_FIELD: - // type = list4(BIT_FIELD,type, - // list3(type /*store type*/,0 /*bit offset*/,bitsize)); - e2 = correct_type(e2,cadr(t)); /* value type */ - return(list4(BASS,e1,e2,list2(BASS,t))); - case STRUCT:case UNION: - if (size(t)!=size(type)) error(TYERR); - type=t; // dispose attr - if(car(e2)==RSTRUCT && car(cadr(e2))==FUNCTION) { - replace_return_struct(cadr(e2),e1); - return cadr(e2); - } else { - return (list4(STASS,e1,e2,size(t))); - } - } } error(TYERR); return list3(ASS,e1,e2); } @@ -3256,7 +3265,7 @@ case VOID: break; case CHAR: op=COP; type=set_type_with_attr(INT,type); break; case UCHAR: op=COP+US; type=set_type_with_attr(UNSIGNED,type); break; - case SHORT: op=SOP; type=set_type_with_attr(SIGNED,type); break; + case SHORT: op=SOP; type=set_type_with_attr(SHORT,type); break; case USHORT: op=SOP+US; type=set_type_with_attr(UNSIGNED,type); break; case LONGLONG: op=LOP; break; case ULONGLONG: op=LOP+US; break;