Mercurial > hg > CbC > old > device
comparison mc-codegen.c @ 828:d0f48d1ea798
rvalue_t separation
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 27 Nov 2010 14:14:17 +0900 |
parents | d7b3dc41972f |
children | d5dfc30826ba |
comparison
equal
deleted
inserted
replaced
827:d7b3dc41972f | 828:d0f48d1ea798 |
---|---|
4437 | 4437 |
4438 /* | 4438 /* |
4439 right value with preserving type global variable | 4439 right value with preserving type global variable |
4440 */ | 4440 */ |
4441 extern int | 4441 extern int |
4442 rvalue_t(int e,int t) | 4442 rvalue_t(int e,int type0) |
4443 { | 4443 { |
4444 int stype = type; | 4444 int op,c; |
4445 type = t; | 4445 NMTBL *n; |
4446 e = rvalue(e); | 4446 |
4447 type = stype; | 4447 if (e==0) error(-1); |
4448 return e; | 4448 op = 0; |
4449 switch(type0) { | |
4450 case INT: | |
4451 break; | |
4452 case UNSIGNED: op=US; break; | |
4453 case VOID: break; | |
4454 case CHAR: op=COP; break; | |
4455 case UCHAR: op=COP+US; break; | |
4456 case SHORT: op=SOP; break; | |
4457 case USHORT: op=SOP+US; break; | |
4458 case LONGLONG: op=LOP; break; | |
4459 case ULONGLONG: op=LOP+US; break; | |
4460 case FLOAT: op=FOP; break; | |
4461 case DOUBLE: op=DOP; break; | |
4462 case CODE: return e; | |
4463 case 0: error(-1); return e; | |
4464 default: | |
4465 if (type0>0) { | |
4466 if (car(type0)==POINTER) { | |
4467 if (lp64) op=LOP; | |
4468 } else error(-1); | |
4469 } else error(-1); | |
4470 } | |
4471 switch(OP(car(e))) { | |
4472 case GVAR: | |
4473 n = ncaddr(e); | |
4474 if (cadr(e)==0 && (c=attr_value(n,KONST))) { | |
4475 if (!has_attr(n,VOLATILE)) | |
4476 return c; | |
4477 } | |
4478 return(list3n(RGVAR+op,cadr(e),ncaddr(e))); | |
4479 case LVAR: | |
4480 n = ncaddr(e); | |
4481 if (cadr(e)==0 && n && (c=attr_value(n,KONST))) { | |
4482 if (!has_attr(n,VOLATILE)) | |
4483 return c; | |
4484 } | |
4485 return(list3n(RLVAR+op,cadr(e),ncaddr(e))); | |
4486 case INDIRECT: | |
4487 return(indirect(RINDIRECT+op,cadr(e),type0)); // cadr(e)? | |
4488 case IVAR: case ARRAY: case PERIOD: case ARROW: | |
4489 return(indirect(RINDIRECT+op,e,type0)); // RIVAR? | |
4490 case CAST: | |
4491 op = rvalue_t(cadr(e),cadddr(e)); | |
4492 e = list4(CAST,op,caddr(e),cadddr(e)); // should be RCAST? | |
4493 default:return(e); /* idempotent case? */ | |
4494 } | |
4449 } | 4495 } |
4450 | 4496 |
4451 /* | 4497 /* |
4452 left value check. Can we assign a value to it? | 4498 left value check. Can we assign a value to it? |
4453 */ | 4499 */ |