aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-03-03 13:17:54 -0500
committerRuss Cox <rsc@golang.org>2011-03-03 13:17:54 -0500
commit44fd7573aacd4780a3a70cec43e7ad8dea542c7f (patch)
tree836838e7b0a6614eba4aaaca4c1a8a57bb2d1d57
parent2d404c4bffa5c70f49483c51120fd83c73fc26c9 (diff)
downloadgo-44fd7573aacd4780a3a70cec43e7ad8dea542c7f.tar.gz
go-44fd7573aacd4780a3a70cec43e7ad8dea542c7f.zip
gc, ld: reflect support for PtrTo
R=ken2 CC=golang-dev https://golang.org/cl/4245055
-rw-r--r--src/cmd/gc/reflect.c30
-rw-r--r--src/cmd/ld/go.c4
2 files changed, 32 insertions, 2 deletions
diff --git a/src/cmd/gc/reflect.c b/src/cmd/gc/reflect.c
index 4dbe9d28d7..8129bf1ce7 100644
--- a/src/cmd/gc/reflect.c
+++ b/src/cmd/gc/reflect.c
@@ -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;
}
@@ -663,6 +672,25 @@ typename(Type *t)
}
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)
{
int ot, n, isddd, dupok;
diff --git a/src/cmd/ld/go.c b/src/cmd/ld/go.c
index 2f5d31e515..3c1e230b4b 100644
--- a/src/cmd/ld/go.c
+++ b/src/cmd/ld/go.c
@@ -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;
}
}