[hackers] [scc] Add compile time calculation of constant ?: || Roberto E. Vargas Caballero
commit cb8b536d8b84402c372f610efed3e1a6e852f65d
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Jul 29 10:01:29 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Jul 29 10:01:29 2015 +0200
Add compile time calculation of constant ?:
diff --git a/cc1/expr.c b/cc1/expr.c
index 0c2e53b..015c0fb 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -1065,6 +1065,18 @@ ternary(void)
expect(':');
ifno = promote(ternary());
typeconv(&ifyes, &ifno);
+ if (cond->constant) {
+ TINT i = cond->sym->u.i;
+
+ freetree(cond);
+ if (i == 0) {
+ freetree(ifyes);
+ return ifno;
+ } else {
+ freetree(ifno);
+ return ifyes;
+ }
+ }
np = node(OCOLON, ifyes->type, ifyes, ifno);
cond = node(OASK, np->type, cond, np);
}
Received on Wed Jul 29 2015 - 18:01:32 CEST
This archive was generated by hypermail 2.3.0
: Wed Jul 29 2015 - 18:12:12 CEST