Mercurial > hg > CbC > old > device
diff mc-codegen.c @ 446:6654aa80851b
fix array pointer in decl_data and cast
author | kono |
---|---|
date | Mon, 22 Nov 2004 14:53:28 +0900 |
parents | 5ec2a88b9f4d |
children | c55363eff5e5 |
line wrap: on
line diff
--- a/mc-codegen.c Sun Nov 21 19:20:18 2004 +0900 +++ b/mc-codegen.c Mon Nov 22 14:53:28 2004 +0900 @@ -91,11 +91,6 @@ if (chk) return INT; gexpr_init(); use = use0; -#if 0 - if(lineno==2862) { - return g_expr0(e1); /*break here*/ - } -#endif return g_expr0(e1); } @@ -2720,6 +2715,13 @@ { int ass,sz,bfd; + if (car(e)==ADDRESS||car(e)==GVAR) { + if (scalar(t)) { + t = list2(POINTER,VOID); // fake + } else { + error(TYERR); + } + } if(mode==GDECL) { emit_data(e,t,n); } else if(mode==STADECL) { @@ -3549,31 +3551,44 @@ extern int correct_type(int e,int t) { - int t1; /* e = rvalue(e); */ #if BIT_FIELD_CODE if (type==BIT_FIELD) e = rvalue(e); #endif - if (type==FLOAT && t==DOTS) { t=DOUBLE;} // fall thru - if (type==CHAR && t==DOTS) { t=INT;} // fall thru - if (t==DOTS) return e; - else if (t==UNSIGNED) e = unsigned_value(e); - else if (t==CHAR) { e = char_value(e); t = INT; } - else if (t==UCHAR) { e = uchar_value(e); t = UNSIGNED; } - else if (t==SHORT) { e = short_value(e); t = INT; } - else if (t==USHORT) { e = ushort_value(e); t = UNSIGNED; } - else if (integral(t)) e = int_value(e); + if (t==DOTS) { + if (type==FLOAT) t=DOUBLE; + else if (type==CHAR) t=INT; + else if (type==UCHAR) t=UNSIGNED; + } + if (type>0 && car(type)==ARRAY && car(e)==GVAR) { + e=list2(ADDRESS,e); + } + if (t>0) { + switch(car(t)) { + case STRUCT: case UNION: + if(size(t)!=size(type)) error(TYERR); + break; + } + } else { + switch(t) { + case DOTS: return e; + case UNSIGNED: e = unsigned_value(e); break; + case CHAR: e = char_value(e); t = INT; break; + case UCHAR: e = uchar_value(e); t = UNSIGNED; break; + case SHORT: e = short_value(e); t = INT; break; + case USHORT: e = ushort_value(e); t = UNSIGNED; break; #if FLOAT_CODE - else if (t==FLOAT) e = float_value(e); - else if (t==DOUBLE) e = double_value(e); + case FLOAT: e = float_value(e); break; + case DOUBLE: e = double_value(e); break; #endif #if LONGLONG_CODE - else if (t==LONGLONG) e = longlong_value(e); - else if (t==ULONGLONG) e = ulonglong_value(e); + case LONGLONG: e = longlong_value(e); break; + case ULONGLONG: e = ulonglong_value(e); break; #endif - else if ((t1=car(t))==STRUCT||t1==UNION) { - if(size(t)!=size(type)) error(TYERR); - } /* else error(TYERR); */ + default: + if (integral(t)) e = int_value(e); + } + } type = t; return e; }