ref: d667281e1d2da0c39a21505bcc383af7a30b01b8
parent: 6ef4f09df64f4215213545cc9d1da748c830362b
author: Ori Bernstein <[email protected]>
date: Sun May 26 12:44:12 EDT 2013
Tag exported types.
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -51,6 +51,13 @@
} Tc;
typedef enum {
+ Visintern,
+ Visexport,
+ Vishidden,
+ Visbuiltin,
+} Vis;
+
+typedef enum {
Dclconst = 1 << 0,
Dclextern = 1 << 1,
} Dclflags;
@@ -97,6 +104,7 @@
Ty type;
int tid;
int line;
+ Vis vis;
int resolved; /* Have we resolved the subtypes? Prevents infinite recursion. */
int fixed; /* Have we fixed the subtypes? Prevents infinite recursion. */
@@ -255,6 +263,7 @@
extern int line; /* the last line number we tokenized */
extern Node *file; /* the current file we're compiling */
extern Type **tytab; /* type -> type map used by inference. size maintained by type creation code */
+extern Type **types;
extern size_t ntypes;
extern Cstr **cstrtab; /* int -> cstr map */
extern size_t ncstrs;
--- a/parse/type.c
+++ b/parse/type.c
@@ -18,6 +18,7 @@
};
Type **tytab = NULL;
+Type **types = NULL;
size_t ntypes;
Cstr **cstrtab;
size_t ncstrs;
@@ -36,6 +37,10 @@
t->line = line;
tytab = xrealloc(tytab, ntypes*sizeof(Type*));
tytab[t->tid] = NULL;
+ types = xrealloc(types, ntypes*sizeof(Type*));
+ types[t->tid] = t;
+ if (ty <= Tyvalist) /* the last builtin atomic type */
+ t->vis = Visbuiltin;
for(i = 0; tycstrs[ty][i]; i++)
setcstr(t, tycstrs[ty][i]);
--- a/parse/use.c
+++ b/parse/use.c
@@ -211,6 +211,11 @@
}
}
+static void typickle(Type *t, FILE *fd)
+{
+ wrtype(fd, t);
+}
+
/* Writes types to a file. Errors on
* internal only types like Tyvar that
* will not be meaningful in another file */
@@ -627,11 +632,55 @@
die("Could not load usefile %s", use->use.name);
}
+void taghidden(Type *t)
+{
+ size_t i;
+
+ if (t->vis != Visintern)
+ return;
+ t->vis = Vishidden;
+ for (i = 0; i < t->nsub; i++) {
+ taghidden(t->sub[i]);
+ }
+ if (t->type == Tystruct) {
+ for (i = 0; i < t->nmemb; i++)
+ taghidden(decltype(t->sdecls[i]));
+ } else if (t->type == Tyunion) {
+ for (i = 0; i < t->nmemb; i++) {
+ if (t->udecls[i]->etype)
+ taghidden(t->udecls[i]->etype);
+ }
+ }
+}
+
+void tagexports(Stab *st)
+{
+ void **k;
+ Type *t;
+ size_t i, j, n;
+
+ k = htkeys(st->ty, &n);
+ for (i = 0; i < n; i++) {
+ t = gettype(st, k[i]);
+ t->vis = Visexport;
+ for (j = 0; j < t->nsub; j++)
+ taghidden(t->sub[j]);
+ }
+ free(k);
+}
+
+
+/* Usefile format:
+ * U<pkgname>
+ * T<pickled-type>
+ * D<picled-decl>
+ * G<pickled-decl><pickled-initializer>
+ * Z
+ */
void writeuse(FILE *f, Node *file)
{
Stab *st;
void **k;
- Type *t;
Node *s;
size_t i, n;
@@ -642,14 +691,14 @@
else
wrstr(f, NULL);
- k = htkeys(st->ty, &n);
- for (i = 0; i < n; i++) {
- t = gettype(st, k[i]);
- assert(t->type == Tyname || t->type == Tygeneric);
+ tagexports(st);
+ for (i = 0; i < ntypes; i++) {
+ if (types[i]->vis != Visexport)
+ continue;
+ assert(types[i]->type == Tyname || types[i]->type == Tygeneric);
wrbyte(f, 'T');
- wrtype(f, t);
+ typickle(types[i], f);
}
- free(k);
k = htkeys(st->dcl, &n);
for (i = 0; i < n; i++) {
s = getdcl(st, k[i]);