[hackers] [scc] Add condexpr() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 4 Sep 2015 20:22:39 +0200 (CEST)

commit 3eae8536814569284d81bae4e5bdae82b1b9b3e8
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Sep 4 19:41:54 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Sep 4 19:41:54 2015 +0200

    Add condexpr()
    
    There are two kind of conditional expressions, with and without
    parentheses, but it is a good idea to handle them with the same
    base function, and have the same warning in both cases.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 168862a..1c0897f 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -367,8 +367,7 @@ extern Node *castcode(Node *np, Type *newtp);
 /* expr.c */
 extern Node *expr(void), *negate(Node *np), *constexpr(void);
 extern Node *convert(Node *np, Type *tp1, char iscast);
-extern Node *eval(Node *np), *iconstexpr(void), *condition(void);
-extern Node *exp2cond(Node *np, char neg);
+extern Node *eval(Node *np), *iconstexpr(void), *condexpr(void);
 extern bool isnodecmp(int op);
 extern int negop(int op);
 extern bool cmpnode(Node *np, TUINT val);
diff --git a/cc1/expr.c b/cc1/expr.c
index b8c9f1d..6c9a257 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -353,7 +353,7 @@ negate(Node *np)
         return np;
 }
 
-Node *
+static Node *
 exp2cond(Node *np, char neg)
 {
         np = decay(np);
_AT_@ -977,15 +977,12 @@ expr(void)
 }
 
 Node *
-condition(void)
+condexpr(void)
 {
         Node *np;
 
- expect('(');
         np = exp2cond(expr(), 0);
         if (np->constant)
                 warn("conditional expression is constant");
- expect(')');
-
         return np;
 }
diff --git a/cc1/stmt.c b/cc1/stmt.c
index 617e68b..3c668fe 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -49,6 +49,18 @@ stmtexp(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
         expect(';');
 }
 
+static Node *
+condition(void)
+{
+ Node *np;
+
+ expect('(');
+ np = condexpr();
+ expect(')');
+
+ return np;
+}
+
 static void
 While(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
 {
_AT_@ -86,7 +98,7 @@ For(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
         expect('(');
         einit = (yytoken != ';') ? expr() : NULL;
         expect(';');
- econd = (yytoken != ';') ? exp2cond(expr(), 0) : NULL;
+ econd = (yytoken != ';') ? condexpr() : NULL;
         expect(';');
         einc = (yytoken != ')') ? expr() : NULL;
         expect(')');
Received on Fri Sep 04 2015 - 20:22:39 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 04 2015 - 20:24:24 CEST