[hackers] [scc] Convert chkternary() o use the new fields in type || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 8 Jan 2016 13:13:59 +0100 (CET)

commit 45da2d1eff24fc3c0393d5ffbea087d1507b598c
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Jan 7 23:15:51 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Jan 8 10:49:29 2016 +0100

    Convert chkternary() o use the new fields in type

diff --git a/cc1/expr.c b/cc1/expr.c
index dc59ea1..39e9096 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -126,51 +126,48 @@ set_p1_p2:
 }
 
 static Node *
-chkternary(Node *ifyes, Node *ifno)
+chkternary(Node *yes, Node *no)
 {
- int arithy = 0, aithn = 0;
- Type *tyes, *tno;
+ yes = decay(yes);
+ no = decay(no);
+
+ /*
+ * FIXME:
+ * We are ignoring type qualifiers here,
+ * but the standard has strong rules about this.
+ * take a look to 6.5.15
+ */
+
+ if (!eqtype(yes->type, no->type)) {
+ if (yes->type->arith && no->type->arith) {
+ arithconv(&yes, &no);
+ } else if (yes->type->op != PTR && no->type->op != PTR) {
+ goto wrong_type;
+ } else {
+ if (yes->type->integer && cmpnode(yes, 0))
+ yes = convert(yes, no->type, 0);
+ if (no->type->integer && cmpnode(no, 0))
+ no = convert(no, no->type, 0);
 
- tyes = ifyes->type, tno = ifno->type;
+ if (yes->type->op != PTR || no->type->op != PTR)
+ goto wrong_type;
 
- switch (tyes->op) {
- case ENUM:
- case INT:
- case FLOAT:
- switch (tno->op) {
- case ENUM:
- case INT:
- case FLOAT:
- arithconv(&ifyes, &ifno);
- break;
- default:
- goto wrong_type;
+ if (yes->type == pvoidtype)
+ yes = convert(yes, no->type, 0);
+ if (no->type == pvoidtype)
+ no = convert(no, no->type, 0);
+
+ if (!eqtype(yes->type, no->type))
+ goto wrong_type;
                 }
- break;
- case ARY:
- case FTN:
- ifyes = decay(ifyes);
- tyes = ifyes->type;
- ifno = decay(ifno);
- tno = ifno->type;
- case PTR:
- if ((ifno = convert(ifno, tyes, 0)) == NULL)
- goto wrong_type;
- break;
- case VOID:
- case STRUCT:
- case UNION:
- if (!eqtype(tyes, tno))
- goto wrong_type;
- break;
- default:
- abort();
         }
- return node(OCOLON, ifyes->type, ifyes, ifno);
+ return node(OCOLON, yes->type, yes, yes);
 
 wrong_type:
         errorp("type mismatch in conditional expression");
- return node(OCOLON, ifyes->type, ifyes, ifyes);
+ freetree(yes);
+ freetree(no);
+ return constnode(zero);
 }
 
 static void
Received on Fri Jan 08 2016 - 13:13:59 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 08 2016 - 13:24:55 CET