summaryrefslogtreecommitdiff
path: root/src/cmd/gc/reflect.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-01-24 23:33:59 -0800
committerRuss Cox <rsc@golang.org>2010-01-24 23:33:59 -0800
commite221161a5fcccdfdfff0483283d4c538cb32857b (patch)
tree2c9b6b8a197575b0b88c1607094357bd11aa0371 /src/cmd/gc/reflect.c
parent8b391f1ae442367ec0480d8f03c845187e7804da (diff)
downloadgolang-e221161a5fcccdfdfff0483283d4c538cb32857b.tar.gz
gc: record full package paths in runtime type data
detect compilation of special package runtime with compiler flag instead of package name. R=ken2 CC=golang-dev http://codereview.appspot.com/193080
Diffstat (limited to 'src/cmd/gc/reflect.c')
-rw-r--r--src/cmd/gc/reflect.c54
1 files changed, 47 insertions, 7 deletions
diff --git a/src/cmd/gc/reflect.c b/src/cmd/gc/reflect.c
index 0e9ece92f..97217af7c 100644
--- a/src/cmd/gc/reflect.c
+++ b/src/cmd/gc/reflect.c
@@ -267,12 +267,42 @@ dgopkgpath(Sym *s, int ot, Pkg *pkg)
if(pkg == nil)
return dgostringptr(s, ot, nil);
- // PGNS: This needs to be import path instead of pkg->name,
- // but we need to figure out how to fill it in during 6l when
- // trying to refer to localpkg.
+ // Emit reference to go.importpath.""., which 6l will
+ // rewrite using the correct import path. Every package
+ // that imports this one directly defines the symbol.
+ if(pkg == localpkg) {
+ static Sym *ns;
+
+ if(ns == nil)
+ ns = pkglookup("importpath.\"\".", mkpkg(strlit("go")));
+ return dsymptr(s, ot, ns, 0);
+ }
+
return dgostringptr(s, ot, pkg->name);
}
+static void
+dimportpath(Pkg *p)
+{
+ static Pkg *gopkg;
+ char *nam;
+ Node *n;
+
+ if(gopkg == nil) {
+ gopkg = mkpkg(strlit("go"));
+ gopkg->name = "go";
+ }
+ nam = smprint("importpath.%s.", p->prefix);
+
+ n = nod(ONAME, N, N);
+ n->sym = pkglookup(nam, gopkg);
+ free(nam);
+ n->class = PEXTERN;
+ n->xoffset = 0;
+
+ gdatastring(n, p->path);
+ ggloblsym(n->sym, types[TSTRING]->width, 1);
+}
/*
* uncommonType
@@ -626,8 +656,7 @@ dtypesym(Type *t)
else
tsym = t->sym;
- // PGNS: Fixme
- if(strcmp(localpkg->name, "runtime") == 0) {
+ if(compiling_runtime) {
if(t == types[t->etype])
goto ok;
if(t1 && t1 == types[t1->etype])
@@ -784,6 +813,7 @@ dumptypestructs(void)
NodeList *l;
Node *n;
Type *t;
+ Pkg *p;
// copy types from externdcl list to signatlist
for(l=externdcl; l; l=l->next) {
@@ -804,17 +834,27 @@ dumptypestructs(void)
dtypesym(ptrto(t));
}
+ // generate import strings for imported packages
+ for(i=0; i<nelem(phash); i++)
+ for(p=phash[i]; p; p=p->link)
+ if(p->direct)
+ dimportpath(p);
+
// do basic types if compiling package runtime.
// they have to be in at least one package,
- // and reflect is always loaded implicitly,
+ // and runtime is always loaded implicitly,
// so this is as good as any.
// another possible choice would be package main,
// but using runtime means fewer copies in .6 files.
- if(strcmp(localpkg->name, "runtime") == 0) { // PGNS: fixme
+ if(compiling_runtime) {
for(i=1; i<=TBOOL; i++)
dtypesym(ptrto(types[i]));
dtypesym(ptrto(types[TSTRING]));
dtypesym(typ(TDDD));
dtypesym(ptrto(pkglookup("Pointer", unsafepkg)->def->type));
+
+ // add paths for runtime and main, which 6l imports implicitly.
+ dimportpath(runtimepkg);
+ dimportpath(mkpkg(strlit("main")));
}
}