]> Cypherpunks repositories - gostls13.git/commitdiff
gc, ld: reflect support for PtrTo
authorRuss Cox <rsc@golang.org>
Thu, 3 Mar 2011 18:17:54 +0000 (13:17 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 3 Mar 2011 18:17:54 +0000 (13:17 -0500)
R=ken2
CC=golang-dev
https://golang.org/cl/4245055

src/cmd/gc/reflect.c
src/cmd/ld/go.c

index 4dbe9d28d7ff3380bb938b017a3ce09eb42a0d06..8129bf1ce7dc41c83accaab7391285774e1e5a0b 100644 (file)
@@ -10,6 +10,7 @@
 
 static NodeList*       signatlist;
 static Sym*    dtypesym(Type*);
+static Sym*    weaktypesym(Type*);
 
 static int
 sigcmp(Sig *a, Sig *b)
@@ -570,9 +571,17 @@ dcommontype(Sym *s, int ot, Type *t)
 {
        int i;
        Sym *s1;
+       Sym *sptr;
        char *p;
 
        dowidth(t);
+       
+       sptr = nil;
+       if(t->sym != nil && !isptr[t->etype])
+               sptr = dtypesym(ptrto(t));
+       else
+               sptr = weaktypesym(ptrto(t));
+
        s1 = dextratype(t);
 
        // empty interface pointing at this type.
@@ -617,7 +626,7 @@ dcommontype(Sym *s, int ot, Type *t)
                ot = dsymptr(s, ot, s1, 0);     // extraType
        else
                ot = duintptr(s, ot, 0);
-       ot = duintptr(s, ot, 0);  // ptr type (placeholder for now)
+       ot = dsymptr(s, ot, sptr, 0);  // ptr to type
        return ot;
 }
 
@@ -662,6 +671,25 @@ typename(Type *t)
        return n;
 }
 
+static Sym*
+weaktypesym(Type *t)
+{
+       char *p;
+       Sym *s;
+       static Pkg *weak;
+       
+       if(weak == nil) {
+               weak = mkpkg(strlit("weak.type"));
+               weak->name = "weak.type";
+               weak->prefix = "weak.type";  // not weak%2etype
+       }
+       
+       p = smprint("%#-T", t);
+       s = pkglookup(p, weak);
+       free(p);
+       return s;
+}
+
 static Sym*
 dtypesym(Type *t)
 {
index 2f5d31e515445c0affc3fc96551eaeadaba1c8c4..3c1e230b4b68e4f5472b98c957b2cfa79a118f50 100644 (file)
@@ -680,8 +680,10 @@ doweak(void)
                        if(t->type != 0 && t->reachable) {
                                s->value = t->value;
                                s->type = t->type;
-                       } else
+                       } else {
+                               s->type = SCONST;
                                s->value = 0;
+                       }
                        continue;
                }
        }