[hackers] [scc] use content() in array() || Roberto E. Vargas Caballero

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

commit f93cb9bc73732b8af7db62172406de5a08be4b30
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Sep 4 16:03:55 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Sep 4 16:03:55 2015 +0200

    use content() in array()
    
    Array() takes the content of some address, that is the same made by content(),
    which has the optimization of *&, so the best way of handling it is calling
    to content().

diff --git a/cc1/expr.c b/cc1/expr.c
index 4611721..3d26622 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -399,19 +399,40 @@ field(Node *np)
 }
 
 static Node *
+content(char op, Node *np)
+{
+ switch (BTYPE(np)) {
+ case ARY:
+ case FTN:
+ case PTR:
+ if (np->op == OADDR) {
+ Node *new = np->left;
+ new->type = np->type->type;
+ free(np);
+ np = new;
+ } else {
+ np = node(op, np->type->type, np, NULL);
+ }
+ np->lvalue = 1;
+ return np;
+ default:
+ error("invalid argument of memory indirection");
+ }
+}
+
+static Node *
 array(Node *lp, Node *rp)
 {
         Type *tp;
+ Node *np;
 
         if (BTYPE(lp) != INT && BTYPE(rp) != INT)
                 error("array subscript is not an integer");
- lp = arithmetic(OADD, lp, rp);
- tp = lp->type;
+ np = arithmetic(OADD, lp, rp);
+ tp = np->type;
         if (tp->op != PTR)
                 errorp("subscripted value is neither array nor pointer");
- lp = node(OPTR, tp->type, lp, NULL);
- lp->lvalue = 1;
- return lp;
+ return content(OPTR, np);
 }
 
 static Node *
_AT_@ -468,26 +489,6 @@ address(char op, Node *np)
 }
 
 static Node *
-content(char op, Node *np)
-{
- switch (BTYPE(np)) {
- case ARY:
- case FTN:
- case PTR:
- if (np->op == OADDR) {
- Node *new = np->left;
- free(np);
- return new;
- }
- np = node(op, np->type->type, np, NULL);
- np->lvalue = 1;
- return np;
- default:
- error("invalid argument of unary '*'");
- }
-}
-
-static Node *
 negation(char op, Node *np)
 {
         switch (BTYPE(np)) {
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:14 CEST