[hackers] [scc] Fix cast() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 14 Aug 2015 18:21:21 +0200 (CEST)

commit 080e69990174ad65f1611d8169a6b1f0f03414ea
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Aug 14 18:13:50 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Aug 14 18:13:50 2015 +0200

    Fix cast()
    
    Cast() is a problematic function because we need see two tokens
    of the input, but the second token can be a typename, so we can
    not use ahead() because it only can return the next character
    of the input. The solution is to duplicate the rules.
    When cast() sees a '(' it means that can be a cast, or can be a
    parentheses expression, so it accepts the '(' and calls expr(),
    but due to the lost of recursivity the actions of postfix were
    not applied, so the solution is to call a modified version of
    postfix() before returning.

diff --git a/cc1/expr.c b/cc1/expr.c
index 7eebc53..93fea6c 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -779,11 +779,12 @@ bad_type:
 }
 
 static Node *
-postfix(void)
+postfix(Node *lp)
 {
- Node *lp, *rp;
+ Node *rp;
 
- lp = primary();
+ if (!lp)
+ lp = primary();
         for (;;) {
                 switch (yytoken) {
                 case '[':
_AT_@ -869,7 +870,7 @@ unary(void)
         case '~': op = OCPL; fun = integeruop; break;
         case '&': op = OADDR; fun = address; break;
         case '*': op = OPTR; fun = content; break;
- default: return postfix();
+ default: return postfix(NULL);
         }
 
         next();
_AT_@ -906,6 +907,7 @@ cast(void)
         default:
                 rp = expr();
                 expect(')');
+ rp = postfix(rp);
                 break;
         }
 
Received on Fri Aug 14 2015 - 18:21:21 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 14 2015 - 18:24:10 CEST