commit 475fdec2b580ce32a5e53a3d33c139e23d977b07
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Sep 1 20:09:06 2015 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Sep 1 20:09:06 2015 +0200

    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.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 5a3e8b2..628c931 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -362,7 +362,7 @@ extern void freetree(Node *np);
 
 /* 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);
diff --git a/cc1/expr.c b/cc1/expr.c
index 777b72c..55b482f 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -151,12 +151,9 @@ Node *
 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 @@ convert(Node *np, Type *newtp, char iscast)
        default:
                        return NULL;
        }
-       return node(OCAST, newtp, np, NULL);
+       return castcode(np, newtp);
 }
 
 static Node *
diff --git a/cc1/fold.c b/cc1/fold.c
index e56a88b..78600ed 100644
--- a/cc1/fold.c
+++ b/cc1/fold.c
@@ -375,14 +375,16 @@ simplify(int op, Type *tp, Node *lp, Node *rp)
 }
 
 /* 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,14 +407,14 @@ constconv(Node *np, Type *newtp)
                                aux.u.u = osym->u.f;
                        break;
                default:
-                       return NULL;
+                       goto noconstant;
                }
                break;
        case FLOAT:
                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 @@ constconv(Node *np, Type *newtp)
        sym->u = aux.u;
 
        return np;
+
+noconstant:
+       return node(OCAST, newtp, np, NULL);
 }

Reply via email to