ref: 475fdec2b580ce32a5e53a3d33c139e23d977b07
parent: eadc7784288c38da564aa1f11602d0c195f5dabb
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Sep 1 16:09:06 EDT 2015
Transform constconv() to constcode() The work was duplicated between convert() and constconv(), and it fact, it is a bit duplicated, but this version is better than the previous one.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -362,7 +362,7 @@
/* fold.c */
extern Node *simplify(int op, Type *tp, Node *lp, Node *rp);
-extern Node *constconv(Node *np, Type *newtp);
+extern Node *castcode(Node *np, Type *newtp);
/* expr.c */
extern Node *expr(void), *negate(Node *np), *constexpr(void);
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -151,12 +151,9 @@
convert(Node *np, Type *newtp, char iscast)
{
Type *oldtp = np->type;
- Node *p;
if (eqtype(newtp, oldtp))
return np;
- if (np->constant && (p = constconv(np, newtp)) != NULL)
- return p;
switch (oldtp->op) {
case ENUM:
@@ -202,7 +199,7 @@
default:
return NULL;
}
- return node(OCAST, newtp, np, NULL);
+ return castcode(np, newtp);
}
static Node *
--- a/cc1/fold.c
+++ b/cc1/fold.c
@@ -375,14 +375,16 @@
}
/* TODO: check validity of types */
-/* TODO: Integrate it with simplify */
Node *
-constconv(Node *np, Type *newtp)
+castcode(Node *np, Type *newtp)
{
Type *oldtp = np->type;
Symbol aux, *sym, *osym = np->sym;
+ if (!np->constant)
+ goto noconstant;
+
switch (newtp->op) {
case PTR:
case INT:
@@ -405,7 +407,7 @@
aux.u.u = osym->u.f;
break;
default:
- return NULL;
+ goto noconstant;
}
break;
case FLOAT:
@@ -412,7 +414,7 @@
aux.u.f = (oldtp->sign) ? osym->u.i : osym->u.u;
break;
default:
- return NULL;
+ goto noconstant;
}
sym = newsym(NS_IDEN);
@@ -421,4 +423,7 @@
sym->u = aux.u;
return np;
+
+noconstant:
+ return node(OCAST, newtp, np, NULL);
}