]> Cypherpunks repositories - gostls13.git/commitdiff
init context for composit literals
authorKen Thompson <ken@golang.org>
Tue, 8 Sep 2009 22:52:27 +0000 (15:52 -0700)
committerKen Thompson <ken@golang.org>
Tue, 8 Sep 2009 22:52:27 +0000 (15:52 -0700)
R=rsc
OCL=34462
CL=34462

src/cmd/gc/go.h
src/cmd/gc/sinit.c
src/cmd/gc/walk.c

index 4f58fc00a0259dbfca7470725bcb5f604e58949e..34f5802d30c71cd5a57c7d4e08117d13811bbe50 100644 (file)
@@ -1012,6 +1012,7 @@ NodeList* reorder1(NodeList*);
 NodeList*      reorder3(NodeList*);
 NodeList*      reorder4(NodeList*);
 void   anylit(Node*, Node*, NodeList**);
+int    oaslit(Node*, NodeList**);
 void   heapmoves(void);
 void   walkdeflist(NodeList*);
 void   walkdef(Node*);
index d8d2bc69b27bcdf0ba8eeb0a76482c78a9bf1027..07db731ef013c332d43306aef2d1f6391cc1abcc 100644 (file)
@@ -51,7 +51,7 @@ init1(Node *n, NodeList **out)
                case OAS:
                        if(n->defn->left != n)
                                goto bad;
-                       n->dodata = 1;
+                       n->defn->dodata = 1;
                        init1(n->defn->right, out);
                        if(debug['j'])
                                print("%S\n", n->sym);
index aff91db083d92abff8da78b8f85dffcdce8b35bc..6a4e52eeea97de41b0730c39686330919846ec30 100644 (file)
@@ -572,6 +572,8 @@ walkexpr(Node **np, NodeList **init)
                *init = concat(*init, n->ninit);
                n->ninit = nil;
                walkexpr(&n->left, init);
+               if(oaslit(n, init))
+                       goto ret;
                walkexpr(&n->right, init);
                l = n->left;
                r = n->right;
@@ -2406,6 +2408,50 @@ anylit(Node *n, Node *var, NodeList **init)
        }
 }
 
+int
+oaslit(Node *n, NodeList **init)
+{
+       Type *t;
+
+       if(n->left == N || n->right == N)
+               goto no;
+       if(!simplename(n->left))
+               goto no;
+       if(n->dodata == 1)
+               goto initctxt;
+
+no:
+       // not a special composit literal assignment
+       return 0;
+
+initctxt:
+       switch(n->right->op) {
+       default:
+               goto no;
+
+       case OSTRUCTLIT:
+               structlit(n->right, n->left, 3, init);
+               break;
+
+       case OARRAYLIT:
+               t = n->right->type;
+               if(t == T)
+                       goto no;
+               if(t->bound < 0) {
+                       slicelit(n->right, n->left, init);
+                       break;
+               }
+               arraylit(n->right, n->left, 3, init);
+               break;
+
+       case OMAPLIT:
+               maplit(n->right, n->left, init);
+               break;
+       }
+       n->op = OEMPTY;
+       return 1;
+}
+
 /*
  * walk through argin parameters.
  * generate and return code to allocate