shithub: mc

Download patch

ref: dc6135b7b6b30fb07d2ac661e56f23be8c12f8f7
parent: 49173c584d17208134df412148b84862843f5424
author: Ori Bernstein <[email protected]>
date: Tue Jan 7 09:03:31 EST 2014

Fold array lengths.

--- a/mi/fold.c
+++ b/mi/fold.c
@@ -53,6 +53,7 @@
 Node *fold(Node *n, int foldvar)
 {
     Node **args, *r;
+    Type *t;
     vlong a, b;
     size_t i;
 
@@ -140,6 +141,12 @@
         case Obxor:
             if (islit(args[0], &a) && islit(args[1], &b))
                 r = val(n->line, a ^ b, exprtype(n));
+            break;
+        case Omemb:
+            t = tybase(exprtype(args[0]));
+            /* we only fold lengths right now */
+            if (t->type == Tyarray && !strcmp(namestr(args[1]), "len"))
+                r = t->asize;
             break;
         case Ocast:
             /* FIXME: we currentl assume that the bits of the