summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-07-09 10:18:26 -0700
committerOri Bernstein <ori@eigenstate.org>2017-07-09 10:18:26 -0700
commit95f4d0b36eb2d25889eed6ab48fb025d5b346b67 (patch)
treed5e206f2a9c6713c193911370958826928c91294 /parse
parent25d91f98a97df36e1da381b273219ceedf256a4d (diff)
downloadmc-95f4d0b36eb2d25889eed6ab48fb025d5b346b67.tar.gz
Style(9)-ify.
Diffstat (limited to 'parse')
-rw-r--r--parse/dump.c34
-rw-r--r--parse/err.c12
-rw-r--r--parse/export.c18
-rw-r--r--parse/fold.c21
-rw-r--r--parse/infer.c271
-rw-r--r--parse/node.c156
-rw-r--r--parse/specialize.c65
-rw-r--r--parse/stab.c108
-rw-r--r--parse/tok.c96
-rw-r--r--parse/type.c139
-rw-r--r--parse/use.c104
11 files changed, 678 insertions, 346 deletions
diff --git a/parse/dump.c b/parse/dump.c
index 7cb7713..463c732 100644
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -14,7 +14,8 @@
#include "parse.h"
/* outputs a fully qualified name */
-static void outname(Node *n, FILE *fd)
+static void
+outname(Node *n, FILE *fd)
{
if (n->name.ns)
fprintf(fd, "%s.", n->name.ns);
@@ -24,7 +25,8 @@ static void outname(Node *n, FILE *fd)
/* outputs a sym in a one-line short form (ie,
* the initializer is not printed, and the node is not
* expressed in indented tree. */
-static void outsym(Node *s, FILE *fd, int depth)
+static void
+outsym(Node *s, FILE *fd, int depth)
{
char buf[1024];
@@ -36,9 +38,10 @@ static void outsym(Node *s, FILE *fd, int depth)
fprintf(fd, " : %s\n", tyfmt(buf, 1024, s->decl.type));
}
-void dumpsym(Node *s, FILE *fd) { outsym(s, fd, 0); }
+void
+dumpsym(Node *s, FILE *fd) { outsym(s, fd, 0); }
-/* Outputs a symbol table, and it's sub-tables
+/* Outputs a symbol table, and it's sub-table
* recursively, with a sigil describing the symbol
* type, as follows:
* T type
@@ -47,7 +50,8 @@ void dumpsym(Node *s, FILE *fd) { outsym(s, fd, 0); }
*
* Does not print captured variables.
*/
-static void outstab(Stab *st, FILE *fd, int depth)
+static void
+outstab(Stab *st, FILE *fd, int depth)
{
size_t i, n;
char *name;
@@ -99,9 +103,14 @@ static void outstab(Stab *st, FILE *fd, int depth)
}
}
-void dumpstab(Stab *st, FILE *fd) { outstab(st, fd, 0); }
+void
+dumpstab(Stab *st, FILE *fd)
+{
+ outstab(st, fd, 0);
+}
-void dumpfilestabs(Node *file, int depth, FILE *fd)
+void
+dumpfilestabs(Node *file, int depth, FILE *fd)
{
size_t nk, i;
void **k;
@@ -113,10 +122,11 @@ void dumpfilestabs(Node *file, int depth, FILE *fd)
free(k);
}
-/* Outputs a node in indented tree form. This is
+/* Outputs a node in indented tree form. This i
* not a full serialization, but mainly an aid for
* understanding and debugging. */
-static void outnode(Node *n, FILE *fd, int depth)
+static void
+outnode(Node *n, FILE *fd, int depth)
{
size_t i;
char *ty;
@@ -255,6 +265,8 @@ static void outnode(Node *n, FILE *fd, int depth)
}
}
-void dump(Node *n, FILE *fd) { outnode(n, fd, 0); }
+void
+dump(Node *n, FILE *fd) { outnode(n, fd, 0); }
-void dumpn(Node *n) { dump(n, stdout); }
+void
+dumpn(Node *n) { dump(n, stdout); }
diff --git a/parse/err.c b/parse/err.c
index 82190db..38acbd1 100644
--- a/parse/err.c
+++ b/parse/err.c
@@ -15,7 +15,8 @@
#include "parse.h"
/* errors */
-void die(char *msg, ...)
+void
+die(char *msg, ...)
{
va_list ap;
@@ -26,7 +27,8 @@ void die(char *msg, ...)
abort();
}
-void fatal(Node *n, char *msg, ...)
+void
+fatal(Node *n, char *msg, ...)
{
va_list ap;
@@ -35,7 +37,8 @@ void fatal(Node *n, char *msg, ...)
va_end(ap);
}
-void lfatal(Srcloc l, char *msg, ...)
+void
+lfatal(Srcloc l, char *msg, ...)
{
va_list ap;
@@ -44,7 +47,8 @@ void lfatal(Srcloc l, char *msg, ...)
va_end(ap);
}
-void lfatalv(Srcloc l, char *msg, va_list ap)
+void
+lfatalv(Srcloc l, char *msg, va_list ap)
{
fprintf(stdout, "%s:%d: ", fname(l), lnum(l));
vfprintf(stdout, msg, ap);
diff --git a/parse/export.c b/parse/export.c
index 4f67019..0963361 100644
--- a/parse/export.c
+++ b/parse/export.c
@@ -18,7 +18,8 @@
static void tagtype(Stab *st, Type *t, int ingeneric, int hidelocal);
static void tagnode(Stab *st, Node *n, int ingeneric, int hidelocal);
-void tagreflect(Type *t)
+void
+tagreflect(Type *t)
{
size_t i;
@@ -46,7 +47,8 @@ void tagreflect(Type *t)
}
}
-static void tagtrait(Stab *st, Trait *tr, int ingeneric, int hidelocal)
+static void
+tagtrait(Stab *st, Trait *tr, int ingeneric, int hidelocal)
{
size_t i;
@@ -64,7 +66,8 @@ static void tagtrait(Stab *st, Trait *tr, int ingeneric, int hidelocal)
tagnode(st, tr->proto[i], ingeneric, hidelocal);
}
-static void tagtype(Stab *st, Type *t, int ingeneric, int hidelocal)
+static void
+tagtype(Stab *st, Type *t, int ingeneric, int hidelocal)
{
size_t i;
@@ -100,7 +103,8 @@ static void tagtype(Stab *st, Type *t, int ingeneric, int hidelocal)
}
}
-int isexportinit(Node *n)
+int
+isexportinit(Node *n)
{
if (n->decl.isgeneric && !n->decl.trait)
return 1;
@@ -110,7 +114,8 @@ int isexportinit(Node *n)
return 0;
}
-static void tagnode(Stab *st, Node *n, int ingeneric, int hidelocal)
+static void
+tagnode(Stab *st, Node *n, int ingeneric, int hidelocal)
{
size_t i;
Node *d;
@@ -201,7 +206,8 @@ static void tagnode(Stab *st, Node *n, int ingeneric, int hidelocal)
}
}
-void tagexports(Node *file, int hidelocal)
+void
+tagexports(Node *file, int hidelocal)
{
size_t i, j, n;
Trait *tr;
diff --git a/parse/fold.c b/parse/fold.c
index b931a08..d01ff6a 100644
--- a/parse/fold.c
+++ b/parse/fold.c
@@ -13,7 +13,8 @@
#include "util.h"
#include "parse.h"
-static int getintlit(Node *n, vlong *v)
+static int
+getintlit(Node *n, vlong *v)
{
Node *l;
@@ -26,7 +27,8 @@ static int getintlit(Node *n, vlong *v)
return 1;
}
-static int isintval(Node *n, vlong val)
+static int
+isintval(Node *n, vlong val)
{
vlong v;
@@ -35,7 +37,8 @@ static int isintval(Node *n, vlong val)
return v == val;
}
-static Node *val(Srcloc loc, vlong val, Type *t)
+static Node *
+val(Srcloc loc, vlong val, Type *t)
{
Node *l, *n;
@@ -46,7 +49,8 @@ static Node *val(Srcloc loc, vlong val, Type *t)
return n;
}
-static int issmallconst(Node *dcl)
+static int
+issmallconst(Node *dcl)
{
Type *t;
@@ -60,7 +64,8 @@ static int issmallconst(Node *dcl)
return 0;
}
-static Node *foldcast(Node *n)
+static Node *
+foldcast(Node *n)
{
Type *to, *from;
Node *sub;
@@ -96,7 +101,8 @@ static Node *foldcast(Node *n)
return n;
}
-int idxcmp(const void *pa, const void *pb)
+int
+idxcmp(const void *pa, const void *pb)
{
Node *a, *b;
vlong av, bv;
@@ -116,7 +122,8 @@ int idxcmp(const void *pa, const void *pb)
return 1;
}
-Node *fold(Node *n, int foldvar)
+Node *
+fold(Node *n, int foldvar)
{
Node **args, *r;
Type *t;
diff --git a/parse/infer.c b/parse/infer.c
index cf1e9cd..b94d8d4 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -64,7 +64,8 @@ static Type *unify(Inferstate *st, Node *ctx, Type *a, Type *b);
static Type *tyfix(Inferstate *st, Node *ctx, Type *orig, int noerr);
static void typesub(Inferstate *st, Node *n, int noerr);
-static void ctxstrcall(char *buf, size_t sz, Inferstate *st, Node *n)
+static void
+ctxstrcall(char *buf, size_t sz, Inferstate *st, Node *n)
{
char *p, *end, *sep, *t;
size_t nargs, i;
@@ -103,7 +104,8 @@ static void ctxstrcall(char *buf, size_t sz, Inferstate *st, Node *n)
free(t);
}
-static char *nodetystr(Inferstate *st, Node *n)
+static char *
+nodetystr(Inferstate *st, Node *n)
{
Type *t;
@@ -119,7 +121,8 @@ static char *nodetystr(Inferstate *st, Node *n)
return strdup("unknown");
}
-static void marksrc(Inferstate *st, Type *t, Srcloc l)
+static void
+marksrc(Inferstate *st, Type *t, Srcloc l)
{
t = tf(st, t);
if (t->tid >= st->nusrc) {
@@ -130,7 +133,8 @@ static void marksrc(Inferstate *st, Type *t, Srcloc l)
st->usrc[t->tid] = l;
}
-static char *srcstr(Inferstate *st, Type *ty)
+static char *
+srcstr(Inferstate *st, Type *ty)
{
char src[128];
Srcloc l;
@@ -148,7 +152,8 @@ static char *srcstr(Inferstate *st, Type *ty)
/* Tries to give a good string describing the context
* for the sake of error messages. */
-static char *ctxstr(Inferstate *st, Node *n)
+static char *
+ctxstr(Inferstate *st, Node *n)
{
char *t, *t1, *t2, *t3;
char *s, *d;
@@ -210,7 +215,7 @@ static char *ctxstr(Inferstate *st, Node *n)
case Omemb:
bprintf(buf, sizeof buf, "<%s>.%s", t1, namestr(args[1]));
break;
- default:
+ default:
bprintf(buf, sizeof buf, "%s:%s", d, t);
break;
}
@@ -227,7 +232,8 @@ static char *ctxstr(Inferstate *st, Node *n)
return s;
}
-static void addspecialization(Inferstate *st, Node *n, Stab *stab)
+static void
+addspecialization(Inferstate *st, Node *n, Stab *stab)
{
Node *dcl;
@@ -237,7 +243,8 @@ static void addspecialization(Inferstate *st, Node *n, Stab *stab)
lappend(&st->genericdecls, &st->ngenericdecls, dcl);
}
-static void additerspecializations(Inferstate *st, Node *n, Stab *stab)
+static void
+additerspecializations(Inferstate *st, Node *n, Stab *stab)
{
Trait *tr;
Type *ty;
@@ -259,13 +266,15 @@ static void additerspecializations(Inferstate *st, Node *n, Stab *stab)
}
}
-static void delayedcheck(Inferstate *st, Node *n, Stab *s)
+static void
+delayedcheck(Inferstate *st, Node *n, Stab *s)
{
lappend(&st->postcheck, &st->npostcheck, n);
lappend(&st->postcheckscope, &st->npostcheckscope, s);
}
-static void typeerror(Inferstate *st, Type *a, Type *b, Node *ctx, char *msg)
+static void
+typeerror(Inferstate *st, Type *a, Type *b, Node *ctx, char *msg)
{
char *t1, *t2, *s1, *s2, *c;
@@ -287,7 +296,8 @@ static void typeerror(Inferstate *st, Type *a, Type *b, Node *ctx, char *msg)
/* Set a scope's enclosing scope up correctly.
* We don't do this in the parser for some reason. */
-static void setsuper(Stab *st, Stab *super)
+static void
+setsuper(Stab *st, Stab *super)
{
Stab *s;
@@ -299,7 +309,8 @@ static void setsuper(Stab *st, Stab *super)
/* If the current environment binds a type,
* we return true */
-static int isbound(Inferstate *st, Type *t)
+static int
+isbound(Inferstate *st, Type *t)
{
ssize_t i;
@@ -314,7 +325,8 @@ static int isbound(Inferstate *st, Type *t)
* Recursive types that contain themselves through
* pointers or slices are fine, but any other self-inclusion
* would lead to a value of infinite size */
-static int occurs_rec(Inferstate *st, Type *sub, Bitset *bs)
+static int
+occurs_rec(Inferstate *st, Type *sub, Bitset *bs)
{
size_t i;
@@ -323,7 +335,7 @@ static int occurs_rec(Inferstate *st, Type *sub, Bitset *bs)
bsput(bs, sub->tid);
switch (sub->type) {
case Typtr:
- case Tyslice:
+ case Tyslice:
break;
case Tystruct:
for (i = 0; i < sub->nmemb; i++)
@@ -348,7 +360,8 @@ static int occurs_rec(Inferstate *st, Type *sub, Bitset *bs)
return 0;
}
-static int occursin(Inferstate *st, Type *a, Type *b)
+static int
+occursin(Inferstate *st, Type *a, Type *b)
{
Bitset *bs;
int r;
@@ -360,7 +373,8 @@ static int occursin(Inferstate *st, Type *a, Type *b)
return r;
}
-static int occurs(Inferstate *st, Type *t)
+static int
+occurs(Inferstate *st, Type *t)
{
Bitset *bs;
int r;
@@ -371,7 +385,8 @@ static int occurs(Inferstate *st, Type *t)
return r;
}
-static int needfreshenrec(Inferstate *st, Type *t, Bitset *visited)
+static int
+needfreshenrec(Inferstate *st, Type *t, Bitset *visited)
{
size_t i;
@@ -405,7 +420,8 @@ static int needfreshenrec(Inferstate *st, Type *t, Bitset *visited)
return 0;
}
-static int needfreshen(Inferstate *st, Type *t)
+static int
+needfreshen(Inferstate *st, Type *t)
{
Bitset *visited;
int ret;
@@ -417,7 +433,8 @@ static int needfreshen(Inferstate *st, Type *t)
}
/* Freshens the type of a declaration. */
-static Type *tyfreshen(Inferstate *st, Tysubst *subst, Type *t)
+static Type *
+tyfreshen(Inferstate *st, Tysubst *subst, Type *t)
{
if (!needfreshen(st, t)) {
if (debugopt['u'])
@@ -438,7 +455,8 @@ static Type *tyfreshen(Inferstate *st, Tysubst *subst, Type *t)
}
/* Resolves a type and all its subtypes recursively. */
-static void tyresolve(Inferstate *st, Type *t)
+static void
+tyresolve(Inferstate *st, Type *t)
{
size_t i;
Type *base;
@@ -446,7 +464,7 @@ static void tyresolve(Inferstate *st, Type *t)
if (t->resolved)
return;
- /* type resolution should never throw errors about non-generics
+ /* type resolution should never throw errors about non-generic
* showing up within a generic type, so we push and pop a generic
* around resolution */
st->ingeneric++;
@@ -504,7 +522,8 @@ static void tyresolve(Inferstate *st, Type *t)
st->ingeneric--;
}
-Type *tysearch(Type *t)
+Type *
+tysearch(Type *t)
{
if (!t)
return t;
@@ -513,7 +532,8 @@ Type *tysearch(Type *t)
return t;
}
-static Type *remapping(Type *t)
+static Type *
+remapping(Type *t)
{
Stab *ns;
Type *lu;
@@ -544,7 +564,8 @@ static Type *remapping(Type *t)
}
/* Look up the best type to date in the unification table, returning it */
-static Type *tylookup(Type *t)
+static Type *
+tylookup(Type *t)
{
Type *lu;
@@ -567,7 +588,8 @@ static Type *tylookup(Type *t)
return t;
}
-static Type *tysubstmap(Inferstate *st, Tysubst *subst, Type *t, Type *orig)
+static Type *
+tysubstmap(Inferstate *st, Tysubst *subst, Type *t, Type *orig)
{
size_t i;
@@ -578,7 +600,8 @@ static Type *tysubstmap(Inferstate *st, Tysubst *subst, Type *t, Type *orig)
return t;
}
-static Type *tysubst(Inferstate *st, Type *t, Type *orig)
+static Type *
+tysubst(Inferstate *st, Type *t, Type *orig)
{
Tysubst *subst;
@@ -591,7 +614,8 @@ static Type *tysubst(Inferstate *st, Type *t, Type *orig)
/* find the most accurate type mapping we have (ie,
* the end of the unification chain */
-static Type *tf(Inferstate *st, Type *orig)
+static Type *
+tf(Inferstate *st, Type *orig)
{
int isgeneric;
Type *t;
@@ -617,7 +641,8 @@ static Type *tf(Inferstate *st, Type *orig)
}
/* set the type of any typable node */
-static void settype(Inferstate *st, Node *n, Type *t)
+static void
+settype(Inferstate *st, Node *n, Type *t)
{
t = tf(st, t);
switch (n->type) {
@@ -632,7 +657,8 @@ static void settype(Inferstate *st, Node *n, Type *t)
}
/* Gets the type of a literal value */
-static Type *littype(Node *n)
+static Type *
+littype(Node *n)
{
Type *t;
@@ -653,7 +679,8 @@ static Type *littype(Node *n)
return n->lit.type;
}
-static Type *delayeducon(Inferstate *st, Type *fallback)
+static Type *
+delayeducon(Inferstate *st, Type *fallback)
{
Type *t;
char *from, *to;
@@ -673,7 +700,8 @@ static Type *delayeducon(Inferstate *st, Type *fallback)
}
/* Finds the type of any typable node */
-static Type *type(Inferstate *st, Node *n)
+static Type *
+type(Inferstate *st, Node *n)
{
Type *t;
@@ -690,7 +718,8 @@ static Type *type(Inferstate *st, Node *n)
return tf(st, t);
}
-static Ucon *uconresolve(Inferstate *st, Node *n)
+static Ucon *
+uconresolve(Inferstate *st, Node *n)
{
Ucon *uc;
Node **args;
@@ -712,7 +741,8 @@ static Ucon *uconresolve(Inferstate *st, Node *n)
return uc;
}
-static void putbindingsrec(Inferstate *st, Htab *bt, Type *t, Bitset *visited)
+static void
+putbindingsrec(Inferstate *st, Htab *bt, Type *t, Bitset *visited)
{
size_t i;
@@ -757,7 +787,8 @@ static void putbindingsrec(Inferstate *st, Htab *bt, Type *t, Bitset *visited)
/* Binds the type parameters present in the
* current type into the type environment */
-static void putbindings(Inferstate *st, Htab *bt, Type *t)
+static void
+putbindings(Inferstate *st, Htab *bt, Type *t)
{
Bitset *visited;
@@ -768,7 +799,8 @@ static void putbindings(Inferstate *st, Htab *bt, Type *t)
bsfree(visited);
}
-static void tybindall(Inferstate *st, Type *t)
+static void
+tybindall(Inferstate *st, Type *t)
{
Htab *bt;
@@ -777,7 +809,8 @@ static void tybindall(Inferstate *st, Type *t)
putbindings(st, bt, t);
}
-static void tybind(Inferstate *st, Type *t)
+static void
+tybind(Inferstate *st, Type *t)
{
Htab *bt;
size_t i;
@@ -794,7 +827,8 @@ static void tybind(Inferstate *st, Type *t)
/* Binds the type parameters in the
* declaration into the type environment */
-static void bind(Inferstate *st, Node *n)
+static void
+bind(Inferstate *st, Node *n)
{
Htab *bt;
@@ -813,7 +847,8 @@ static void bind(Inferstate *st, Node *n)
/* Rolls back the binding of type parameters in
* the type environment */
-static void unbind(Inferstate *st, Node *n)
+static void
+unbind(Inferstate *st, Node *n)
{
if(!n->decl.isgeneric)
return;
@@ -822,7 +857,8 @@ static void unbind(Inferstate *st, Node *n)
st->ingeneric--;
}
-static void tyunbind(Inferstate *st)
+static void
+tyunbind(Inferstate *st)
{
htfree(tybindings[ntybindings - 1]);
lpop(&tybindings, &ntybindings);
@@ -832,7 +868,8 @@ static void tyunbind(Inferstate *st)
* type variables, the constraint is added to the required
* constraint list. Otherwise, the type is checked to see
* if it has the required constraint */
-static void constrain(Inferstate *st, Node *ctx, Type *a, Trait *c)
+static void
+constrain(Inferstate *st, Node *ctx, Type *a, Trait *c)
{
if (a->type == Tyvar) {
if (!a->traits)
@@ -844,7 +881,8 @@ static void constrain(Inferstate *st, Node *ctx, Type *a, Trait *c)
}
/* does b satisfy all the constraints of a? */
-static int checktraits(Type *a, Type *b)
+static int
+checktraits(Type *a, Type *b)
{
/* a has no traits to satisfy */
if (!a->traits)
@@ -857,7 +895,8 @@ static int checktraits(Type *a, Type *b)
return bsissubset(a->traits, b->traits);
}
-static void verifytraits(Inferstate *st, Node *ctx, Type *a, Type *b)
+static void
+verifytraits(Inferstate *st, Node *ctx, Type *a, Type *b)
{
size_t i, n;
Srcloc l;
@@ -888,7 +927,8 @@ static void verifytraits(Inferstate *st, Node *ctx, Type *a, Type *b)
}
/* Merges the constraints on types */
-static void mergetraits(Inferstate *st, Node *ctx, Type *a, Type *b)
+static void
+mergetraits(Inferstate *st, Node *ctx, Type *a, Type *b)
{
if (b->type == Tyvar) {
/* make sure that if a = b, both have same traits */
@@ -907,7 +947,8 @@ static void mergetraits(Inferstate *st, Node *ctx, Type *a, Type *b)
* direction should we unify. A lower ranked type
* should be mapped to the higher ranked (ie, more
* specific) type. */
-static int tyrank(Inferstate *st, Type *t)
+static int
+tyrank(Inferstate *st, Type *t)
{
/* plain tyvar */
if (t->type == Tyvar) {
@@ -920,7 +961,8 @@ static int tyrank(Inferstate *st, Type *t)
return 2;
}
-static void unionunify(Inferstate *st, Node *ctx, Type *u, Type *v)
+static void
+unionunify(Inferstate *st, Node *ctx, Type *u, Type *v)
{
size_t i, j;
int found;
@@ -952,7 +994,8 @@ static void unionunify(Inferstate *st, Node *ctx, Type *u, Type *v)
}
}
-static void structunify(Inferstate *st, Node *ctx, Type *u, Type *v)
+static void
+structunify(Inferstate *st, Node *ctx, Type *u, Type *v)
{
size_t i, j;
int found;
@@ -981,7 +1024,8 @@ static void structunify(Inferstate *st, Node *ctx, Type *u, Type *v)
}
}
-static void membunify(Inferstate *st, Node *ctx, Type *u, Type *v)
+static void
+membunify(Inferstate *st, Node *ctx, Type *u, Type *v)
{
if (hthas(st->delayed, u))
u = htget(st->delayed, u);
@@ -995,7 +1039,8 @@ static void membunify(Inferstate *st, Node *ctx, Type *u, Type *v)
structunify(st, ctx, u, v);
}
-static Type *basetype(Inferstate *st, Type *a)
+static Type *
+basetype(Inferstate *st, Type *a)
{
Type *t;
@@ -1011,7 +1056,8 @@ static Type *basetype(Inferstate *st, Type *a)
return t;
}
-static void checksize(Inferstate *st, Node *ctx, Type *a, Type *b)
+static void
+checksize(Inferstate *st, Node *ctx, Type *a, Type *b)
{
if (a->asize)
a->asize = fold(a->asize, 1);
@@ -1033,13 +1079,15 @@ static void checksize(Inferstate *st, Node *ctx, Type *a, Type *b)
tystr(a), tystr(b), ctxstr(st, ctx));
}
-static int hasargs(Type *t)
+static int
+hasargs(Type *t)
{
return t->type == Tyname && t->narg > 0;
}
/* Unifies two types, or errors if the types are not unifiable. */
-static Type *unify(Inferstate *st, Node *ctx, Type *u, Type *v)
+static Type *
+unify(Inferstate *st, Node *ctx, Type *u, Type *v)
{
Type *t, *r;
Type *a, *b;
@@ -1151,7 +1199,8 @@ static Type *unify(Inferstate *st, Node *ctx, Type *u, Type *v)
/* Applies unifications to function calls.
* Funciton application requires a slightly
* different approach to unification. */
-static void unifycall(Inferstate *st, Node *n)
+static void
+unifycall(Inferstate *st, Node *n)
{
size_t i;
Type *ft;
@@ -1191,7 +1240,8 @@ static void unifycall(Inferstate *st, Node *n)
settype(st, n, ft->sub[0]);
}
-static void unifyparams(Inferstate *st, Node *ctx, Type *a, Type *b)
+static void
+unifyparams(Inferstate *st, Node *ctx, Type *a, Type *b)
{
size_t i;
@@ -1212,7 +1262,8 @@ static void unifyparams(Inferstate *st, Node *ctx, Type *a, Type *b)
unify(st, ctx, a->arg[i], b->arg[i]);
}
-static void loaduses(Node *n)
+static void
+loaduses(Node *n)
{
size_t i;
@@ -1221,7 +1272,8 @@ static void loaduses(Node *n)
readuse(n->file.uses[i], n->file.globls, Visintern);
}
-static Type *initvar(Inferstate *st, Node *n, Node *s)
+static Type *
+initvar(Inferstate *st, Node *n, Node *s)
{
Type *t, *param;
Tysubst *subst;
@@ -1272,7 +1324,8 @@ static Type *initvar(Inferstate *st, Node *n, Node *s)
* member. If it is, it transforms it into the variable
* reference we should have, instead of the Omemb expr
* that we do have */
-static Node *checkns(Inferstate *st, Node *n, Node **ret)
+static Node *
+checkns(Inferstate *st, Node *n, Node **ret)
{
Node *var, *name, *nsname;
Node **args;
@@ -1306,7 +1359,8 @@ static Node *checkns(Inferstate *st, Node *n, Node **ret)
return var;
}
-static void inferstruct(Inferstate *st, Node *n, int *isconst)
+static void
+inferstruct(Inferstate *st, Node *n, int *isconst)
{
size_t i;
@@ -1321,7 +1375,8 @@ static void inferstruct(Inferstate *st, Node *n, int *isconst)
settype(st, n, mktyvar(n->loc));
}
-static int64_t arraysize(Inferstate *st, Node *n)
+static int64_t
+arraysize(Inferstate *st, Node *n)
{
int64_t sz, off, i;
Node **args, *idx;
@@ -1351,7 +1406,8 @@ static int64_t arraysize(Inferstate *st, Node *n)
return sz;
}
-static void inferarray(Inferstate *st, Node *n, int *isconst)
+static void
+inferarray(Inferstate *st, Node *n, int *isconst)
{
size_t i;
Type *t;
@@ -1369,7 +1425,8 @@ static void inferarray(Inferstate *st, Node *n, int *isconst)
settype(st, n, t);
}
-static void infertuple(Inferstate *st, Node *n, int *isconst)
+static void
+infertuple(Inferstate *st, Node *n, int *isconst)
{
Type **types;
size_t i;
@@ -1385,7 +1442,8 @@ static void infertuple(Inferstate *st, Node *n, int *isconst)
settype(st, n, mktytuple(n->loc, types, n->expr.nargs));
}
-static void inferucon(Inferstate *st, Node *n, int *isconst)
+static void
+inferucon(Inferstate *st, Node *n, int *isconst)
{
Ucon *uc;
Type *t;
@@ -1410,7 +1468,8 @@ static void inferucon(Inferstate *st, Node *n, int *isconst)
tyunbind(st);
}
-static void inferpat(Inferstate *st, Node **np, Node *val, Node ***bind, size_t *nbind)
+static void
+inferpat(Inferstate *st, Node **np, Node *val, Node ***bind, size_t *nbind)
{
size_t i;
Node **args;
@@ -1484,7 +1543,8 @@ static void inferpat(Inferstate *st, Node **np, Node *val, Node ***bind, size_t
}
}
-void addbindings(Inferstate *st, Node *n, Node **bind, size_t nbind)
+void
+addbindings(Inferstate *st, Node *n, Node **bind, size_t nbind)
{
size_t i;
@@ -1496,7 +1556,8 @@ void addbindings(Inferstate *st, Node *n, Node **bind, size_t nbind)
}
}
-static void infersub(Inferstate *st, Node *n, Type *ret, int *sawret, int *exprconst)
+static void
+infersub(Inferstate *st, Node *n, Type *ret, int *sawret, int *exprconst)
{
Node **args;
size_t i, nargs;
@@ -1523,7 +1584,8 @@ static void infersub(Inferstate *st, Node *n, Type *ret, int *sawret, int *exprc
*exprconst = n->expr.isconst;
}
-static void inferexpr(Inferstate *st, Node **np, Type *ret, int *sawret)
+static void
+inferexpr(Inferstate *st, Node **np, Type *ret, int *sawret)
{
Node **args;
size_t i, nargs;
@@ -1733,7 +1795,7 @@ static void inferexpr(Inferstate *st, Node **np, Type *ret, int *sawret)
fatal(n, "unable to find label %s in function scope\n", args[0]->lit.lblname);
*np = s;
break;
- default:
+ default:
n->expr.isconst = 1;
break;
}
@@ -1786,7 +1848,8 @@ static void inferexpr(Inferstate *st, Node **np, Type *ret, int *sawret)
}
}
-static void inferfunc(Inferstate *st, Node *n)
+static void
+inferfunc(Inferstate *st, Node *n)
{
size_t i;
int sawret;
@@ -1800,7 +1863,8 @@ static void inferfunc(Inferstate *st, Node *n)
unify(st, n, type(st, n)->sub[0], mktype(Zloc, Tyvoid));
}
-static void specializeimpl(Inferstate *st, Node *n)
+static void
+specializeimpl(Inferstate *st, Node *n)
{
Node *dcl, *proto, *name, *sym;
Tysubst *subst;
@@ -1881,7 +1945,8 @@ static void specializeimpl(Inferstate *st, Node *n)
}
}
-static void inferdecl(Inferstate *st, Node *n)
+static void
+inferdecl(Inferstate *st, Node *n)
{
Type *t;
@@ -1899,7 +1964,8 @@ static void inferdecl(Inferstate *st, Node *n)
}
}
-static void inferstab(Inferstate *st, Stab *s)
+static void
+inferstab(Inferstate *st, Stab *s)
{
void **k;
size_t n, i;
@@ -1929,7 +1995,8 @@ static void inferstab(Inferstate *st, Stab *s)
free(k);
}
-static void infernode(Inferstate *st, Node **np, Type *ret, int *sawret)
+static void
+infernode(Inferstate *st, Node **np, Type *ret, int *sawret)
{
size_t i, nbound;
Node **bound, *n, *pat;
@@ -2047,9 +2114,10 @@ static void infernode(Inferstate *st, Node **np, Type *ret, int *sawret)
}
}
-/* returns the final type for t, after all unifications
+/* returns the final type for t, after all unification
* and default constraint selections */
-static Type *tyfix(Inferstate *st, Node *ctx, Type *orig, int noerr)
+static Type *
+tyfix(Inferstate *st, Node *ctx, Type *orig, int noerr)
{
static Type *tyint, *tyflt;
Type *t, *delayed, *base;
@@ -2123,13 +2191,15 @@ static Type *tyfix(Inferstate *st, Node *ctx, Type *orig, int noerr)
return t;
}
-static void checkcast(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
+static void
+checkcast(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
{
- /* FIXME: actually verify the casts. Right now, it's ok to leave this
+ /* FIXME: actually verify the casts. Right now, it's ok to leave thi
* unimplemented because bad casts get caught by the backend. */
}
-static void infercompn(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
+static void
+infercompn(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
{
Node *aggr;
Node *memb;
@@ -2150,7 +2220,7 @@ static void infercompn(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab
constrain(st, n, type(st, n), traittab[Tcint]);
found = 1;
}
- /*
+ /*
* otherwise, we search aggregate types for the member, and unify
* the expression with the member type; ie:
*
@@ -2186,7 +2256,8 @@ static void infercompn(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab
ctxstr(st, memb), ctxstr(st, aggr));
}
-static void checkstruct(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
+static void
+checkstruct(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
{
Type *t, *et;
Node *val, *name;
@@ -2231,7 +2302,8 @@ static void checkstruct(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab
}
}
-static void checkvar(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
+static void
+checkvar(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
{
Node *proto, *dcl;
Type *ty;
@@ -2248,7 +2320,8 @@ static void checkvar(Inferstate *st, Node *n, Node ***rem, size_t *nrem, Stab **
unify(st, n, type(st, n), ty);
}
-static void postcheckpass(Inferstate *st, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
+static void
+postcheckpass(Inferstate *st, Node ***rem, size_t *nrem, Stab ***remscope, size_t *nremscope)
{
size_t i;
Node *n;
@@ -2267,7 +2340,8 @@ static void postcheckpass(Inferstate *st, Node ***rem, size_t *nrem, Stab ***rem
}
}
-static void postcheck(Inferstate *st)
+static void
+postcheck(Inferstate *st)
{
size_t nrem, nremscope;
Stab **remscope;
@@ -2293,7 +2367,8 @@ static void postcheck(Inferstate *st)
/* After inference, replace all
* types in symbol tables with
* the final computed types */
-static void stabsub(Inferstate *st, Stab *s)
+static void
+stabsub(Inferstate *st, Stab *s)
{
void **k;
size_t n, i;
@@ -2328,7 +2403,8 @@ static void stabsub(Inferstate *st, Stab *s)
free(k);
}
-static void checkrange(Inferstate *st, Node *n)
+static void
+checkrange(Inferstate *st, Node *n)
{
Type *t;
int64_t sval;
@@ -2361,7 +2437,8 @@ static void checkrange(Inferstate *st, Node *n)
}
}
-static int initcompatible(Type *t)
+static int
+initcompatible(Type *t)
{
if (t->type != Tyfunc)
return 0;
@@ -2372,7 +2449,8 @@ static int initcompatible(Type *t)
return 1;
}
-static int maincompatible(Type *t)
+static int
+maincompatible(Type *t)
{
if (t->nsub > 2)
return 0;
@@ -2392,7 +2470,8 @@ static int maincompatible(Type *t)
return 1;
}
-static void verifyop(Inferstate *st, Node *n)
+static void
+verifyop(Inferstate *st, Node *n)
{
Type *ty;
@@ -2411,9 +2490,10 @@ static void verifyop(Inferstate *st, Node *n)
}
}
-/* After type inference, replace all types
+/* After type inference, replace all type
* with the final computed type */
-static void typesub(Inferstate *st, Node *n, int noerr)
+static void
+typesub(Inferstate *st, Node *n, int noerr)
{
size_t i;
@@ -2512,7 +2592,8 @@ static void typesub(Inferstate *st, Node *n, int noerr)
}
}
-static Type *itertype(Inferstate *st, Node *n, Type *ret)
+static Type *
+itertype(Inferstate *st, Node *n, Type *ret)
{
Type *it, *val, *itp, *valp, *fn;
@@ -2531,7 +2612,8 @@ static Type *itertype(Inferstate *st, Node *n, Type *ret)
/* Take generics and build new versions of them
* with the type parameters replaced with the
* specialized types */
-static void specialize(Inferstate *st, Node *f)
+static void
+specialize(Inferstate *st, Node *f)
{
Node *d, *n, *name;
Type *ty, *it;
@@ -2574,7 +2656,8 @@ static void specialize(Inferstate *st, Node *f)
}
}
-void applytraits(Inferstate *st, Node *f)
+void
+applytraits(Inferstate *st, Node *f)
{
size_t i, j;
Node *impl, *n;
@@ -2617,7 +2700,8 @@ void applytraits(Inferstate *st, Node *f)
popstab();
}
-void verify(Inferstate *st, Node *f)
+void
+verify(Inferstate *st, Node *f)
{
Node *n;
size_t i;
@@ -2635,7 +2719,8 @@ void verify(Inferstate *st, Node *f)
}
}
-void infer(Node *file)
+void
+infer(Node *file)
{
Inferstate st = {
0,
diff --git a/parse/node.c b/parse/node.c
index 6489c21..d6b2724 100644
--- a/parse/node.c
+++ b/parse/node.c
@@ -18,15 +18,24 @@ size_t nnodes;
Node **decls;
size_t ndecls;
-char *fname(Srcloc l) { return file->file.files[l.file]; }
+char *
+fname(Srcloc l)
+{
+ return file->file.files[l.file];
+}
-int lnum(Srcloc l) { return l.line; }
+int
+lnum(Srcloc l)
+{
+ return l.line;
+}
/*
* Bah, this is going to need to know how to fold things.
* FIXME: teach it.
*/
-uvlong arraysz(Node *sz)
+uvlong
+arraysz(Node *sz)
{
Node *n;
@@ -42,7 +51,8 @@ uvlong arraysz(Node *sz)
return n->lit.intval;
}
-Node *mknode(Srcloc loc, Ntype nt)
+Node *
+mknode(Srcloc loc, Ntype nt)
{
Node *n;
@@ -54,7 +64,8 @@ Node *mknode(Srcloc loc, Ntype nt)
return n;
}
-Node *mkfile(char *name)
+Node *
+mkfile(char *name)
{
Node *n;
@@ -64,7 +75,8 @@ Node *mkfile(char *name)
return n;
}
-Node *mkuse(Srcloc loc, char *use, int islocal)
+Node *
+mkuse(Srcloc loc, char *use, int islocal)
{
Node *n;
@@ -75,7 +87,8 @@ Node *mkuse(Srcloc loc, char *use, int islocal)
return n;
}
-Node *mksliceexpr(Srcloc loc, Node *sl, Node *base, Node *off)
+Node *
+mksliceexpr(Srcloc loc, Node *sl, Node *base, Node *off)
{
if (!base)
base = mkintlit(loc, 0);
@@ -84,7 +97,8 @@ Node *mksliceexpr(Srcloc loc, Node *sl, Node *base, Node *off)
return mkexpr(loc, Oslice, sl, base, off, NULL);
}
-Node *mkexprl(Srcloc loc, Op op, Node **args, size_t nargs)
+Node *
+mkexprl(Srcloc loc, Op op, Node **args, size_t nargs)
{
Node *n;
@@ -95,7 +109,8 @@ Node *mkexprl(Srcloc loc, Op op, Node **args, size_t nargs)
return n;
}
-Node *mkexpr(Srcloc loc, int op, ...)
+Node *
+mkexpr(Srcloc loc, int op, ...)
{
Node *n;
va_list ap;
@@ -111,7 +126,8 @@ Node *mkexpr(Srcloc loc, int op, ...)
return n;
}
-Node *mkcall(Srcloc loc, Node *fn, Node **args, size_t nargs)
+Node *
+mkcall(Srcloc loc, Node *fn, Node **args, size_t nargs)
{
Node *n;
size_t i;
@@ -122,7 +138,8 @@ Node *mkcall(Srcloc loc, Node *fn, Node **args, size_t nargs)
return n;
}
-Node *mkifstmt(Srcloc loc, Node *cond, Node *iftrue, Node *iffalse)
+Node *
+mkifstmt(Srcloc loc, Node *cond, Node *iftrue, Node *iffalse)
{
Node *n;
@@ -134,7 +151,8 @@ Node *mkifstmt(Srcloc loc, Node *cond, Node *iftrue, Node *iffalse)
return n;
}
-Node *mkloopstmt(Srcloc loc, Node *init, Node *cond, Node *incr, Node *body)
+Node *
+mkloopstmt(Srcloc loc, Node *init, Node *cond, Node *incr, Node *body)
{
Node *n;
@@ -148,7 +166,8 @@ Node *mkloopstmt(Srcloc loc, Node *init, Node *cond, Node *incr, Node *body)
return n;
}
-Node *mkiterstmt(Srcloc loc, Node *elt, Node *seq, Node *body)
+Node *
+mkiterstmt(Srcloc loc, Node *elt, Node *seq, Node *body)
{
Node *n;
@@ -160,7 +179,8 @@ Node *mkiterstmt(Srcloc loc, Node *elt, Node *seq, Node *body)
return n;
}
-Node *mkmatchstmt(Srcloc loc, Node *val, Node **matches, size_t nmatches)
+Node *
+mkmatchstmt(Srcloc loc, Node *val, Node **matches, size_t nmatches)
{
Node *n;
@@ -171,7 +191,8 @@ Node *mkmatchstmt(Srcloc loc, Node *val, Node **matches, size_t nmatches)
return n;
}
-Node *mkmatch(Srcloc loc, Node *pat, Node *body)
+Node *
+mkmatch(Srcloc loc, Node *pat, Node *body)
{
Node *n;
@@ -181,7 +202,8 @@ Node *mkmatch(Srcloc loc, Node *pat, Node *body)
return n;
}
-Node *mkfunc(Srcloc loc, Node **args, size_t nargs, Type *ret, Node *body)
+Node *
+mkfunc(Srcloc loc, Node **args, size_t nargs, Type *ret, Node *body)
{
Node *n;
Node *f;
@@ -205,7 +227,8 @@ Node *mkfunc(Srcloc loc, Node **args, size_t nargs, Type *ret, Node *body)
return n;
}
-Node *mkblock(Srcloc loc, Stab *scope)
+Node *
+mkblock(Srcloc loc, Stab *scope)
{
Node *n;
@@ -214,7 +237,8 @@ Node *mkblock(Srcloc loc, Stab *scope)
return n;
}
-Node *mkimplstmt(Srcloc loc, Node *name, Type *t, Type **aux, size_t naux, Node **decls, size_t ndecls)
+Node *
+mkimplstmt(Srcloc loc, Node *name, Type *t, Type **aux, size_t naux, Node **decls, size_t ndecls)
{
Node *n;
@@ -229,7 +253,8 @@ Node *mkimplstmt(Srcloc loc, Node *name, Type *t, Type **aux, size_t naux, Node
return n;
}
-Node *mklbl(Srcloc loc, char *lbl)
+Node *
+mklbl(Srcloc loc, char *lbl)
{
Node *n;
@@ -241,7 +266,8 @@ Node *mklbl(Srcloc loc, char *lbl)
return mkexpr(loc, Olit, n, NULL);
}
-char *genlblstr(char *buf, size_t sz, char *suffix)
+char *
+genlblstr(char *buf, size_t sz, char *suffix)
{
static int nextlbl;
size_t len;
@@ -251,7 +277,8 @@ char *genlblstr(char *buf, size_t sz, char *suffix)
return buf;
}
-Node *genlbl(Srcloc loc)
+Node *
+genlbl(Srcloc loc)
{
char buf[128];
@@ -259,7 +286,8 @@ Node *genlbl(Srcloc loc)
return mklbl(loc, buf);
}
-Node *mkstr(Srcloc loc, Str val)
+Node *
+mkstr(Srcloc loc, Str val)
{
Node *n;
@@ -272,7 +300,8 @@ Node *mkstr(Srcloc loc, Str val)
return n;
}
-Node *mkint(Srcloc loc, uvlong val)
+Node *
+mkint(Srcloc loc, uvlong val)
{
Node *n;
@@ -283,11 +312,13 @@ Node *mkint(Srcloc loc, uvlong val)
return n;
}
-Node *mkintlit(Srcloc loc, uvlong val) {
+Node *
+mkintlit(Srcloc loc, uvlong val) {
return mkexpr(loc, Olit, mkint(loc, val), NULL);
}
-Node *mkchar(Srcloc loc, uint32_t val)
+Node *
+mkchar(Srcloc loc, uint32_t val)
{
Node *n;
@@ -298,7 +329,8 @@ Node *mkchar(Srcloc loc, uint32_t val)
return n;
}
-Node *mkfloat(Srcloc loc, double val)
+Node *
+mkfloat(Srcloc loc, double val)
{
Node *n;
@@ -309,13 +341,15 @@ Node *mkfloat(Srcloc loc, double val)
return n;
}
-Node *mkidxinit(Srcloc loc, Node *idx, Node *init)
+Node *
+mkidxinit(Srcloc loc, Node *idx, Node *init)
{
init->expr.idx = idx;
return init;
}
-Node *mkname(Srcloc loc, char *name)
+Node *
+mkname(Srcloc loc, char *name)
{
Node *n;
@@ -325,7 +359,8 @@ Node *mkname(Srcloc loc, char *name)
return n;
}
-Node *mknsname(Srcloc loc, char *ns, char *name)
+Node *
+mknsname(Srcloc loc, char *ns, char *name)
{
Node *n;
@@ -337,7 +372,8 @@ Node *mknsname(Srcloc loc, char *ns, char *name)
return n;
}
-Node *mkdecl(Srcloc loc, Node *name, Type *ty)
+Node *
+mkdecl(Srcloc loc, Node *name, Type *ty)
{
Node *n;
@@ -349,7 +385,8 @@ Node *mkdecl(Srcloc loc, Node *name, Type *ty)
return n;
}
-Node *gentemp(Srcloc loc, Type *ty, Node **dcl)
+Node *
+gentemp(Srcloc loc, Type *ty, Node **dcl)
{
char buf[128];
static int nexttmp;
@@ -366,7 +403,8 @@ Node *gentemp(Srcloc loc, Type *ty, Node **dcl)
return r;
}
-Ucon *mkucon(Srcloc loc, Node *name, Type *ut, Type *et)
+Ucon *
+mkucon(Srcloc loc, Node *name, Type *ut, Type *et)
{
Ucon *uc;
@@ -378,7 +416,8 @@ Ucon *mkucon(Srcloc loc, Node *name, Type *ut, Type *et)
return uc;
}
-Node *mkbool(Srcloc loc, int val)
+Node *
+mkbool(Srcloc loc, int val)
{
Node *n;
@@ -389,7 +428,8 @@ Node *mkbool(Srcloc loc, int val)
return n;
}
-Node *mkboollit(Srcloc loc, int val) {
+Node *
+mkboollit(Srcloc loc, int val) {
Node *e;
e = mkexpr(loc, Olit, mkbool(loc, val), NULL);
@@ -397,7 +437,8 @@ Node *mkboollit(Srcloc loc, int val) {
return e;
}
-Node *mkvoid(Srcloc loc)
+Node *
+mkvoid(Srcloc loc)
{
Node *n;
@@ -406,7 +447,8 @@ Node *mkvoid(Srcloc loc)
return n;
}
-char *declname(Node *n)
+char *
+declname(Node *n)
{
Node *name;
assert(n->type == Ndecl);
@@ -414,19 +456,22 @@ char *declname(Node *n)
return name->name.name;
}
-Type *decltype(Node * n)
+Type *
+decltype(Node * n)
{
assert(n->type == Ndecl);
return nodetype(n);
}
-Type *exprtype(Node *n)
+Type *
+exprtype(Node *n)
{
assert(n->type == Nexpr);
return nodetype(n);
}
-Type *nodetype(Node *n)
+Type *
+nodetype(Node *n)
{
switch (n->type) {
case Ndecl: return n->decl.type; break;
@@ -437,12 +482,14 @@ Type *nodetype(Node *n)
return NULL;
}
-int liteq(Node *a, Node *b)
+int
+liteq(Node *a, Node *b)
{
return litvaleq(a, b) && tyeq(a->lit.type, b->lit.type);
}
-int litvaleq(Node *a, Node *b)
+int
+litvaleq(Node *a, Node *b)
{
assert(a->type == Nlit && b->type == Nlit);
if (a->lit.littype != b->lit.littype)
@@ -463,7 +510,8 @@ int litvaleq(Node *a, Node *b)
}
/* name hashing */
-ulong namehash(void *p)
+ulong
+namehash(void *p)
{
Node *n;
@@ -471,7 +519,8 @@ ulong namehash(void *p)
return strhash(namestr(n)) ^ strhash(n->name.ns);
}
-int nameeq(void *p1, void *p2)
+int
+nameeq(void *p1, void *p2)
{
Node *a, *b;
a = p1;
@@ -482,7 +531,8 @@ int nameeq(void *p1, void *p2)
return streq(namestr(a), namestr(b)) && streq(a->name.ns, b->name.ns);
}
-void setns(Node *n, char *ns)
+void
+setns(Node *n, char *ns)
{
assert(!ns || !n->name.ns || !strcmp(n->name.ns, ns));
@@ -491,13 +541,15 @@ void setns(Node *n, char *ns)
n->name.ns = strdup(ns);
}
-Op exprop(Node *e)
+Op
+exprop(Node *e)
{
assert(e->type == Nexpr);
return e->expr.op;
}
-char *namestr(Node *name)
+char *
+namestr(Node *name)
{
if (!name)
return "";
@@ -505,7 +557,8 @@ char *namestr(Node *name)
return name->name.name;
}
-char *lblstr(Node *n)
+char *
+lblstr(Node *n)
{
assert(exprop(n) == Olit);
assert(n->expr.args[0]->type == Nlit);
@@ -513,7 +566,8 @@ char *lblstr(Node *n)
return n->expr.args[0]->lit.lblval;
}
-static size_t did(Node *n)
+static size_t
+did(Node *n)
{
if (n->type == Ndecl) {
return n->decl.did;
@@ -527,11 +581,13 @@ static size_t did(Node *n)
}
/* Hashes a Ovar expr or an Ndecl */
-ulong varhash(void *dcl)
+ulong
+varhash(void *dcl)
{
/* large-prime hash. meh. */
return did(dcl) * 366787;
}
/* Checks if the did of two vars are equal */
-int vareq(void *a, void *b) { return did(a) == did(b); }
+int
+vareq(void *a, void *b) { return did(a) == did(b); }
diff --git a/parse/specialize.c b/parse/specialize.c
index dbc2d07..0fa1a0d 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -15,7 +15,8 @@
static Node *specializenode(Node *g, Tysubst *tsmap);
-Tysubst *mksubst()
+Tysubst *
+mksubst()
{
Tysubst *subst;
@@ -24,7 +25,8 @@ Tysubst *mksubst()
return subst;
}
-void substfree(Tysubst *subst)
+void
+substfree(Tysubst *subst)
{
size_t i;
@@ -33,12 +35,14 @@ void substfree(Tysubst *subst)
lfree(&subst->subst, &subst->nsubst);
}
-void substpush(Tysubst *subst)
+void
+substpush(Tysubst *subst)
{
lappend(&subst->subst, &subst->nsubst, mkht(tyhash, tyeq));
}
-void substpop(Tysubst *subst)
+void
+substpop(Tysubst *subst)
{
Htab *ht;
@@ -46,12 +50,14 @@ void substpop(Tysubst *subst)
htfree(ht);
}
-void substput(Tysubst *subst, Type *from, Type *to)
+void
+substput(Tysubst *subst, Type *from, Type *to)
{
htput(subst->subst[subst->nsubst - 1], from, to);
}
-Type *substget(Tysubst *subst, Type *from)
+Type *
+substget(Tysubst *subst, Type *from)
{
Type *t;
size_t i;
@@ -65,7 +71,8 @@ Type *substget(Tysubst *subst, Type *from)
return t;
}
-void addtraits(Type *t, Bitset *traits)
+void
+addtraits(Type *t, Bitset *traits)
{
size_t b;
@@ -76,14 +83,15 @@ void addtraits(Type *t, Bitset *traits)
/*
* Duplicates the type 't', with all bound type
- * parameters substituted with the substitions
+ * parameters substituted with the substition
* described in 'tsmap'
*
* Returns a fresh type with all unbound type
* parameters (type schemes in most literature)
* replaced with type variables that we can unify
* against */
-Type *tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
+Type *
+tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
{
Type *t, *ret, *tmp, *var, *base;
Type **arg;
@@ -162,7 +170,7 @@ Type *tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
if (delayed && hthas(delayed, t)) {
tmp = htget(delayed, t);
htput(delayed, ret, tyspecialize(tmp, tsmap, delayed, trbase));
- }
+ }
break;
default:
if (t->nsub > 0) {
@@ -178,10 +186,11 @@ Type *tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
return ret;
}
-/* Checks if the type 't' is generic, and if it is
+/* Checks if the type 't' is generic, and if it i
* substitutes the types. This is here for efficiency,
* so we don't gratuitously duplicate types */
-static Type *tysubst(Type *t, Tysubst *tsmap)
+static Type *
+tysubst(Type *t, Tysubst *tsmap)
{
if (hasparams(t))
return tyspecialize(t, tsmap, NULL, NULL);
@@ -193,7 +202,8 @@ static Type *tysubst(Type *t, Tysubst *tsmap)
* Fills the substitution map with a mapping from
* the type parameter 'from' to it's substititon 'to'
*/
-static void fillsubst(Tysubst *tsmap, Type *to, Type *from)
+static void
+fillsubst(Tysubst *tsmap, Type *to, Type *from)
{
size_t i;
@@ -216,7 +226,8 @@ static void fillsubst(Tysubst *tsmap, Type *to, Type *from)
* Fixes up nodes. This involves fixing up the
* declaration identifiers once we specialize
*/
-static void fixup(Node *n)
+static void
+fixup(Node *n)
{
size_t i;
Node *d;
@@ -312,7 +323,8 @@ static void fixup(Node *n)
* need to be specialized to make it concrete
* instead of generic, and returns it.
*/
-static Node *specializenode(Node *n, Tysubst *tsmap)
+static Node *
+specializenode(Node *n, Tysubst *tsmap)
{
Node *r;
size_t i;
@@ -437,7 +449,8 @@ static Node *specializenode(Node *n, Tysubst *tsmap)
return r;
}
-Node *genericname(Node *n, Type *param, Type *t)
+Node *
+genericname(Node *n, Type *param, Type *t)
{
char buf[1024];
char *p;
@@ -462,7 +475,8 @@ Node *genericname(Node *n, Type *param, Type *t)
}
/* this doesn't walk through named types, so it can't recurse infinitely. */
-int matchquality(Type *pat, Type *to)
+int
+matchquality(Type *pat, Type *to)
{
int match, q;
size_t i;
@@ -543,7 +557,8 @@ int matchquality(Type *pat, Type *to)
return match;
}
-Node *bestimpl(Node *n, Type *to)
+Node *
+bestimpl(Node *n, Type *to)
{
Node **gimpl, **ambig, *match;
size_t ngimpl, nambig, i;
@@ -577,10 +592,11 @@ Node *bestimpl(Node *n, Type *to)
/*
* Takes a generic declaration, and creates a specialized
- * duplicate of it with type 'to'. It also generates
+ * duplicate of it with type 'to'. It also generate
* a name for this specialized node, and returns it in '*name'.
*/
-Node *specializedcl(Node *gnode, Type *param, Type *to, Node **name)
+Node *
+specializedcl(Node *gnode, Type *param, Type *to, Node **name)
{
extern int stabstkoff;
Tysubst *tsmap;
@@ -648,7 +664,8 @@ Node *specializedcl(Node *gnode, Type *param, Type *to, Node **name)
* ...
* }
*/
-static Node *initdecl(Node *file, Node *name, Type *tyvoidfn)
+static Node *
+initdecl(Node *file, Node *name, Type *tyvoidfn)
{
Node *dcl;
@@ -665,7 +682,8 @@ static Node *initdecl(Node *file, Node *name, Type *tyvoidfn)
return dcl;
}
-static void callinit(Node *block, Node *init, Type *tyvoid, Type *tyvoidfn)
+static void
+callinit(Node *block, Node *init, Type *tyvoid, Type *tyvoidfn)
{
Node *call, *var;
@@ -679,7 +697,8 @@ static void callinit(Node *block, Node *init, Type *tyvoid, Type *tyvoidfn)
lappend(&block->block.stmts, &block->block.nstmts, call);
}
-void geninit(Node *file)
+void
+geninit(Node *file)
{
Node *name, *decl, *func, *block, *init;
Type *tyvoid, *tyvoidfn;
diff --git a/parse/stab.c b/parse/stab.c
index e380afd..cf622b3 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -33,19 +33,22 @@ static Stab *stabstk[Maxstabdepth];
int stabstkoff;
/* scope management */
-Stab *curstab()
+Stab *
+curstab()
{
assert(stabstkoff > 0);
return stabstk[stabstkoff - 1];
}
-void pushstab(Stab *st)
+void
+pushstab(Stab *st)
{
assert(stabstkoff < Maxstabdepth);
stabstk[stabstkoff++] = st;
}
-void popstab(void)
+void
+popstab(void)
{
assert(stabstkoff > 0);
stabstkoff--;
@@ -54,17 +57,20 @@ void popstab(void)
/* name hashing: we want namespaced lookups to find the
* name even if we haven't set the namespace up, since
* we can update it after the fact. */
-ulong nsnamehash(void *n)
+ulong
+nsnamehash(void *n)
{
return strhash(namestr(n));
}
-int nsnameeq(void *a, void *b)
+int
+nsnameeq(void *a, void *b)
{
return a == b || !strcmp(namestr(a), namestr(b));
}
-static ulong implhash(void *p)
+static ulong
+implhash(void *p)
{
Node *n;
ulong h;
@@ -75,7 +81,8 @@ static ulong implhash(void *p)
return h;
}
-Stab *findstab(Stab *st, Node *n)
+Stab *
+findstab(Stab *st, Node *n)
{
Stab *ns;
@@ -90,7 +97,8 @@ Stab *findstab(Stab *st, Node *n)
return st;
}
-static int impleq(void *pa, void *pb)
+static int
+impleq(void *pa, void *pb)
{
Node *a, *b;
@@ -101,7 +109,8 @@ static int impleq(void *pa, void *pb)
return 0;
}
-Stab *mkstab(int isfunc)
+Stab *
+mkstab(int isfunc)
{
Stab *st;
@@ -119,7 +128,8 @@ Stab *mkstab(int isfunc)
return st;
}
-Node *getclosed(Stab *st, Node *n)
+Node *
+getclosed(Stab *st, Node *n)
{
while (st && !st->env)
st = st->super;
@@ -128,7 +138,8 @@ Node *getclosed(Stab *st, Node *n)
return NULL;
}
-Node **getclosure(Stab *st, size_t *n)
+Node **
+getclosure(Stab *st, size_t *n)
{
size_t nkeys, i;
void **keys;
@@ -153,15 +164,16 @@ Node **getclosure(Stab *st, size_t *n)
/*
* Searches for declarations from current
- * scope, and all enclosing scopes. Does
+ * scope, and all enclosing scopes. Doe
* not resolve namespaces -- that is the job
* of the caller of this function.
*
- * If a resoved name is not global, and is
+ * If a resoved name is not global, and i
* not in the current scope, it is recorded
* in the scope's closure.
*/
-Node *getdcl(Stab *st, Node *n)
+Node *
+getdcl(Stab *st, Node *n)
{
Node *s;
Stab *fn;
@@ -182,7 +194,8 @@ Node *getdcl(Stab *st, Node *n)
return NULL;
}
-void putlbl(Stab *st, char *name, Node *lbl)
+void
+putlbl(Stab *st, char *name, Node *lbl)
{
assert(st && st->isfunc);
if (hthas(st->lbl, name))
@@ -190,7 +203,8 @@ void putlbl(Stab *st, char *name, Node *lbl)
htput(st->lbl, name, lbl);
}
-Node *getlbl(Stab *st, Srcloc loc, char *name)
+Node *
+getlbl(Stab *st, Srcloc loc, char *name)
{
while (st && !st->isfunc)
st = st->super;
@@ -199,7 +213,8 @@ Node *getlbl(Stab *st, Srcloc loc, char *name)
return htget(st->lbl, name);
}
-Type *gettype_l(Stab *st, Node *n)
+Type *
+gettype_l(Stab *st, Node *n)
{
Tydefn *t;
@@ -208,7 +223,8 @@ Type *gettype_l(Stab *st, Node *n)
return NULL;
}
-Type *gettype(Stab *st, Node *n)
+Type *
+gettype(Stab *st, Node *n)
{
Tydefn *t;
@@ -220,7 +236,8 @@ Type *gettype(Stab *st, Node *n)
return NULL;
}
-int hastype(Stab *st, Node *n)
+int
+hastype(Stab *st, Node *n)
{
do {
if (hthas(st->ty, n))
@@ -230,7 +247,8 @@ int hastype(Stab *st, Node *n)
return 0;
}
-Ucon *getucon(Stab *st, Node *n)
+Ucon *
+getucon(Stab *st, Node *n)
{
Ucon *uc;
@@ -242,7 +260,8 @@ Ucon *getucon(Stab *st, Node *n)
return NULL;
}
-Trait *gettrait(Stab *st, Node *n)
+Trait *
+gettrait(Stab *st, Node *n)
{
Traitdefn *c;
@@ -256,11 +275,13 @@ Trait *gettrait(Stab *st, Node *n)
return NULL;
}
-Stab *getns(Node *file, char *name) {
+Stab *
+getns(Node *file, char *name) {
return htget(file->file.ns, name);
}
-static int mergedecl(Node *old, Node *new)
+static int
+mergedecl(Node *old, Node *new)
{
Node *e, *g;
@@ -320,14 +341,16 @@ static int mergedecl(Node *old, Node *new)
return 1;
}
-void forcedcl(Stab *st, Node *s)
+void
+forcedcl(Stab *st, Node *s)
{
setns(s->decl.name, st->name);
htput(st->dcl, s->decl.name, s);
assert(htget(st->dcl, s->decl.name) != NULL);
}
-void putdcl(Stab *st, Node *s)
+void
+putdcl(Stab *st, Node *s)
{
Node *old;
@@ -340,7 +363,8 @@ void putdcl(Stab *st, Node *s)
lnum(s->loc));
}
-void updatetype(Stab *st, Node *n, Type *t)
+void
+updatetype(Stab *st, Node *n, Type *t)
{
Tydefn *td;
@@ -350,7 +374,8 @@ void updatetype(Stab *st, Node *n, Type *t)
td->type = t;
}
-int mergetype(Type *old, Type *new)
+int
+mergetype(Type *old, Type *new)
{
if (!new) {
lfatal(old->loc, "double prototyping of %s", tystr(old));
@@ -370,7 +395,8 @@ int mergetype(Type *old, Type *new)
return 0;
}
-void puttype(Stab *st, Node *n, Type *t)
+void
+puttype(Stab *st, Node *n, Type *t)
{
Tydefn *td;
Type *ty;
@@ -398,7 +424,8 @@ void puttype(Stab *st, Node *n, Type *t)
}
}
-void putucon(Stab *st, Ucon *uc)
+void
+putucon(Stab *st, Ucon *uc)
{
Ucon *old;
@@ -410,7 +437,8 @@ void putucon(Stab *st, Ucon *uc)
htput(st->uc, uc->name, uc);
}
-static int mergetrait(Trait *old, Trait *new)
+static int
+mergetrait(Trait *old, Trait *new)
{
if (old->isproto && !new->isproto)
*old = *new;
@@ -421,7 +449,8 @@ static int mergetrait(Trait *old, Trait *new)
return 1;
}
-void puttrait(Stab *st, Node *n, Trait *c)
+void
+puttrait(Stab *st, Node *n, Trait *c)
{
Traitdefn *td;
Trait *t;
@@ -444,7 +473,8 @@ void puttrait(Stab *st, Node *n, Trait *c)
htput(st->tr, td->name, td);
}
-static int mergeimpl(Node *old, Node *new)
+static int
+mergeimpl(Node *old, Node *new)
{
Vis vis;
@@ -466,7 +496,8 @@ static int mergeimpl(Node *old, Node *new)
return 1;
}
-void putimpl(Stab *st, Node *n)
+void
+putimpl(Stab *st, Node *n)
{
Node *impl;
@@ -484,7 +515,8 @@ void putimpl(Stab *st, Node *n)
htput(st->impl, n, n);
}
-Node *getimpl(Stab *st, Node *n)
+Node *
+getimpl(Stab *st, Node *n)
{
Node *imp;
@@ -496,7 +528,8 @@ Node *getimpl(Stab *st, Node *n)
return NULL;
}
-void putns(Node *file, Stab *scope)
+void
+putns(Node *file, Stab *scope)
{
Stab *s;
@@ -508,10 +541,11 @@ void putns(Node *file, Stab *scope)
/*
* Sets the namespace of a symbol table, and
- * changes the namespace of all contained symbols
+ * changes the namespace of all contained symbol
* to match it.
*/
-void updatens(Stab *st, char *name)
+void
+updatens(Stab *st, char *name)
{
void **k;
size_t i, nk;
diff --git a/parse/tok.c b/parse/tok.c
index 4723368..2290fae 100644
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -27,7 +27,8 @@ static int fidx;
static int fbufsz;
static char *fbuf;
-static int peekn(int n)
+static int
+peekn(int n)
{
if (fidx + n >= fbufsz)
return End;
@@ -35,9 +36,14 @@ static int peekn(int n)
return fbuf[fidx + n];
}
-static int peek(void) { return peekn(0); }
+static int
+peek(void)
+{
+ return peekn(0);
+}
-static int next(void)
+static int
+next(void)
{
int c;
@@ -46,7 +52,8 @@ static int next(void)
return c;
}
-static void unget(void)
+static void
+unget(void)
{
fidx--;
assert(fidx >= 0);
@@ -58,7 +65,8 @@ static void unget(void)
* returns true if there was a match,
* false otherwise.
*/
-static int match(char c)
+static int
+match(char c)
{
if (peek() == c) {
next();
@@ -68,7 +76,8 @@ static int match(char c)
}
}
-static Tok *mktok(int tt)
+static Tok *
+mktok(int tt)
{
Tok *t;
@@ -78,11 +87,13 @@ static Tok *mktok(int tt)
return t;
}
-static int identchar(int c) {
+static int
+identchar(int c) {
return isalnum(c) || c == '_' || c == '$';
}
-static void eatcomment(void)
+static void
+eatcomment(void)
{
int depth;
int startln;
@@ -121,7 +132,8 @@ static void eatcomment(void)
* we also consume '\n'. ';' is still
* accepted as a line ending.
*/
-static void eatspace(void)
+static void
+eatspace(void)
{
int c;
int ignorenl;
@@ -157,7 +169,8 @@ static void eatspace(void)
* token type to use for the
* identifier.
*/
-static int kwd(char *s)
+static int
+kwd(char *s)
{
static const struct {
char *kw;
@@ -211,7 +224,8 @@ static int kwd(char *s)
return Tident;
}
-static int identstr(char *buf, size_t sz)
+static int
+identstr(char *buf, size_t sz)
{
size_t i;
char c;
@@ -225,7 +239,8 @@ static int identstr(char *buf, size_t sz)
return i;
}
-static Tok *kwident(void)
+static Tok *
+kwident(void)
{
char buf[1024];
Tok *t;
@@ -237,7 +252,8 @@ static Tok *kwident(void)
return t;
}
-static void append(char **buf, size_t *len, size_t *sz, int c)
+static void
+append(char **buf, size_t *len, size_t *sz, int c)
{
if (!*sz) {
*sz = 16;
@@ -252,7 +268,8 @@ static void append(char **buf, size_t *len, size_t *sz, int c)
(*len)++;
}
-static void encode(char *buf, size_t len, uint32_t c)
+static void
+encode(char *buf, size_t len, uint32_t c)
{
int mark;
size_t i;
@@ -273,7 +290,8 @@ static void encode(char *buf, size_t len, uint32_t c)
* Appends a unicode codepoint 'c' to a growable buffer 'buf',
* resizing if needed.
*/
-static void appendc(char **buf, size_t *len, size_t *sz, uint32_t c)
+static void
+appendc(char **buf, size_t *len, size_t *sz, uint32_t c)
{
size_t i, charlen;
char charbuf[5] = {0};
@@ -294,7 +312,8 @@ static void appendc(char **buf, size_t *len, size_t *sz, uint32_t c)
append(buf, len, sz, charbuf[i]);
}
-static int ishexval(char c)
+static int
+ishexval(char c)
{
if (c >= 'a' && c <= 'f')
return 1;
@@ -308,7 +327,8 @@ static int ishexval(char c)
/*
* Converts a character to its hex value.
*/
-static int hexval(char c)
+static int
+hexval(char c)
{
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
@@ -321,7 +341,8 @@ static int hexval(char c)
}
/* \u{abc} */
-static int32_t unichar(void)
+static int32_t
+unichar(void)
{
uint32_t v;
int c;
@@ -346,7 +367,8 @@ static int32_t unichar(void)
* shared between strings and characters.
* Unknown escape codes are ignored.
*/
-static int decode(char **buf, size_t *len, size_t *sz)
+static int
+decode(char **buf, size_t *len, size_t *sz)
{
char c, c1, c2;
int32_t v;
@@ -382,7 +404,8 @@ static int decode(char **buf, size_t *len, size_t *sz)
return v;
}
-static Tok *strlit(void)
+static Tok *
+strlit(void)
{
Tok *t;
int c;
@@ -418,7 +441,8 @@ static Tok *strlit(void)
return t;
}
-static uint32_t readutf(char c, char **buf, size_t *buflen, size_t *sz)
+static uint32_t
+readutf(char c, char **buf, size_t *buflen, size_t *sz)
{
size_t i, len;
uint32_t val;
@@ -446,7 +470,8 @@ static uint32_t readutf(char c, char **buf, size_t *buflen, size_t *sz)
return val;
}
-static Tok *charlit(void)
+static Tok *
+charlit(void)
{
Tok *t;
int c;
@@ -479,7 +504,8 @@ static Tok *charlit(void)
return t;
}
-static Tok *oper(void)
+static Tok *
+oper(void)
{
int tt;
char c;
@@ -623,7 +649,8 @@ static Tok *oper(void)
return mktok(tt);
}
-static Tok *number(int base)
+static Tok *
+number(int base)
{
Tok *t;
int start;
@@ -694,7 +721,8 @@ static Tok *number(int base)
* b -> 8 bit
*/
unsignedval = 0;
-nextsuffix:
+nextsuffix
+:
switch (peek()) {
case 'u':
if (unsignedval == 1)
@@ -741,7 +769,8 @@ nextsuffix:
return t;
}
-static Tok *numlit(void)
+static Tok *
+numlit(void)
{
Tok *t;
@@ -764,7 +793,8 @@ static Tok *numlit(void)
return t;
}
-static Tok *typaram(void)
+static Tok *
+typaram(void)
{
Tok *t;
char buf[1024];
@@ -779,7 +809,8 @@ static Tok *typaram(void)
return t;
}
-static Tok *toknext(void)
+static Tok *
+toknext(void)
{
Tok *t;
int c;
@@ -811,7 +842,8 @@ static Tok *toknext(void)
return t;
}
-void tokinit(char *file)
+void
+tokinit(char *file)
{
int fd;
int n;
@@ -845,14 +877,16 @@ void tokinit(char *file)
}
/* Interface to yacc */
-int yylex(void)
+int
+yylex(void)
{
curtok = toknext();
yylval.tok = curtok;
return curtok->type;
}
-void yyerror(const char *s)
+void
+yyerror(const char *s)
{
fprintf(stderr, "%s:%d: %s", filename, curloc.line, s);
if (curtok->id)
diff --git a/parse/type.c b/parse/type.c
index ca927ca..62fa34f 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -39,9 +39,14 @@ char stackness[] = {
#undef Ty
};
-int isstacktype(Type *t) { return stackness[tybase(t)->type]; }
+int
+isstacktype(Type *t)
+{
+ return stackness[tybase(t)->type];
+}
-Type *tydedup(Type *ty)
+Type *
+tydedup(Type *ty)
{
Type *had;
@@ -55,7 +60,8 @@ Type *tydedup(Type *ty)
return had;
}
-Type *mktype(Srcloc loc, Ty ty)
+Type *
+mktype(Srcloc loc, Ty ty)
{
Type *t;
int i;
@@ -91,7 +97,8 @@ Type *mktype(Srcloc loc, Ty ty)
* Shallowly duplicates a type, so we can frob
* its internals later
*/
-Type *tydup(Type *t)
+Type *
+tydup(Type *t)
{
Type *r;
@@ -125,7 +132,8 @@ Type *tydup(Type *t)
* Creates a Tyvar with the same
* constrants as the 'like' type
*/
-Type *mktylike(Srcloc loc, Ty like)
+Type *
+mktylike(Srcloc loc, Ty like)
{
Type *t;
int i;
@@ -137,7 +145,8 @@ Type *mktylike(Srcloc loc, Ty like)
}
/* steals memb, funcs */
-Trait *mktrait(Srcloc loc, Node *name, Type *param,
+Trait *
+mktrait(Srcloc loc, Node *name, Type *param,
Type **aux, size_t naux,
Node **proto, size_t nproto,
int isproto)
@@ -163,7 +172,8 @@ Trait *mktrait(Srcloc loc, Node *name, Type *param,
return t;
}
-Type *mktyvar(Srcloc loc)
+Type *
+mktyvar(Srcloc loc)
{
Type *t;
@@ -171,7 +181,8 @@ Type *mktyvar(Srcloc loc)
return t;
}
-Type *mktyparam(Srcloc loc, char *name)
+Type *
+mktyparam(Srcloc loc, char *name)
{
Type *t;
@@ -180,7 +191,8 @@ Type *mktyparam(Srcloc loc, char *name)
return t;
}
-Type *mktyunres(Srcloc loc, Node *name, Type **arg, size_t narg)
+Type *
+mktyunres(Srcloc loc, Node *name, Type **arg, size_t narg)
{
Type *t;
@@ -192,7 +204,8 @@ Type *mktyunres(Srcloc loc, Node *name, Type **arg, size_t narg)
return t;
}
-Type *mktygeneric(Srcloc loc, Node *name, Type **param, size_t nparam, Type *base)
+Type *
+mktygeneric(Srcloc loc, Node *name, Type **param, size_t nparam, Type *base)
{
Type *t;
@@ -207,7 +220,8 @@ Type *mktygeneric(Srcloc loc, Node *name, Type **param, size_t nparam, Type *bas
return t;
}
-Type *mktyname(Srcloc loc, Node *name, Type *base)
+Type *
+mktyname(Srcloc loc, Node *name, Type *base)
{
Type *t;
@@ -220,7 +234,8 @@ Type *mktyname(Srcloc loc, Node *name, Type *base)
return t;
}
-Type *mktyarray(Srcloc loc, Type *base, Node *sz)
+Type *
+mktyarray(Srcloc loc, Type *base, Node *sz)
{
Type *t;
@@ -234,7 +249,8 @@ Type *mktyarray(Srcloc loc, Type *base, Node *sz)
return t;
}
-Type *mktyslice(Srcloc loc, Type *base)
+Type *
+mktyslice(Srcloc loc, Type *base)
{
Type *t;
@@ -245,7 +261,8 @@ Type *mktyslice(Srcloc loc, Type *base)
return t;
}
-Type *mktyptr(Srcloc loc, Type *base)
+Type *
+mktyptr(Srcloc loc, Type *base)
{
Type *t;
@@ -256,7 +273,8 @@ Type *mktyptr(Srcloc loc, Type *base)
return t;
}
-Type *mktytuple(Srcloc loc, Type **sub, size_t nsub)
+Type *
+mktytuple(Srcloc loc, Type **sub, size_t nsub)
{
Type *t;
size_t i;
@@ -269,7 +287,8 @@ Type *mktytuple(Srcloc loc, Type **sub, size_t nsub)
return t;
}
-Type *mktyfunc(Srcloc loc, Node **args, size_t nargs, Type *ret)
+Type *
+mktyfunc(Srcloc loc, Node **args, size_t nargs, Type *ret)
{
Type *t;
size_t i;
@@ -283,7 +302,8 @@ Type *mktyfunc(Srcloc loc, Node **args, size_t nargs, Type *ret)
return t;
}
-Type *mktystruct(Srcloc loc, Node **decls, size_t ndecls)
+Type *
+mktystruct(Srcloc loc, Node **decls, size_t ndecls)
{
Type *t;
Htab *ht;
@@ -307,7 +327,8 @@ Type *mktystruct(Srcloc loc, Node **decls, size_t ndecls)
return t;
}
-Type *mktyunion(Srcloc loc, Ucon **decls, size_t ndecls)
+Type *
+mktyunion(Srcloc loc, Ucon **decls, size_t ndecls)
{
Type *t;
@@ -317,7 +338,8 @@ Type *mktyunion(Srcloc loc, Ucon **decls, size_t ndecls)
return t;
}
-Ucon *finducon(Type *ty, Node *name)
+Ucon *
+finducon(Type *ty, Node *name)
{
size_t i;
@@ -328,7 +350,8 @@ Ucon *finducon(Type *ty, Node *name)
return NULL;
}
-int istyunsigned(Type *t)
+int
+istyunsigned(Type *t)
{
switch (tybase(t)->type) {
case Tybyte:
@@ -343,7 +366,8 @@ int istyunsigned(Type *t)
}
}
-int istysigned(Type *t)
+int
+istysigned(Type *t)
{
switch (tybase(t)->type) {
case Tyint8:
@@ -355,19 +379,22 @@ int istysigned(Type *t)
}
}
-int istyfloat(Type *t)
+int
+istyfloat(Type *t)
{
t = tybase(t);
return t->type == Tyflt32 || t->type == Tyflt64;
}
-int istyprimitive(Type *t) { return istysigned(t) || istyunsigned(t) || istyfloat(t); }
+int
+istyprimitive(Type *t) { return istysigned(t) || istyunsigned(t) || istyfloat(t); }
/*
* Checks if a type contains any type
* parameers at all (ie, if it generic).
*/
-int hasparamsrec(Type *t, Bitset *visited)
+int
+hasparamsrec(Type *t, Bitset *visited)
{
size_t i;
@@ -406,7 +433,8 @@ int hasparamsrec(Type *t, Bitset *visited)
return 0;
}
-int hasparams(Type *t)
+int
+hasparams(Type *t)
{
Bitset *visited;
@@ -418,7 +446,8 @@ int hasparams(Type *t)
return t->hasparams;
}
-Type *tybase(Type *t)
+Type *
+tybase(Type *t)
{
assert(t != NULL);
while (t->type == Tyname || t->type == Tygeneric)
@@ -426,7 +455,8 @@ Type *tybase(Type *t)
return t;
}
-static int namefmt(char *buf, size_t len, Node *n)
+static int
+namefmt(char *buf, size_t len, Node *n)
{
char *p;
char *end;
@@ -439,7 +469,8 @@ static int namefmt(char *buf, size_t len, Node *n)
return len - (end - p);
}
-int settrait(Type *t, Trait *c)
+int
+settrait(Type *t, Trait *c)
{
if (!t->traits)
t->traits = mkbs();
@@ -447,9 +478,11 @@ int settrait(Type *t, Trait *c)
return 1;
}
-int hastrait(Type *t, Trait *c) { return t->traits && bshas(t->traits, c->uid); }
+int
+hastrait(Type *t, Trait *c) { return t->traits && bshas(t->traits, c->uid); }
-int traitfmt(char *buf, size_t len, Type *t)
+int
+traitfmt(char *buf, size_t len, Type *t)
{
size_t i;
char *p;
@@ -473,7 +506,8 @@ int traitfmt(char *buf, size_t len, Type *t)
return p - buf;
}
-static int fmtstruct(char *buf, size_t len, Bitset *visited, Type *t)
+static int
+fmtstruct(char *buf, size_t len, Bitset *visited, Type *t)
{
size_t i;
char *end, *p;
@@ -492,7 +526,8 @@ static int fmtstruct(char *buf, size_t len, Bitset *visited, Type *t)
return p - buf;
}
-static int fmtunion(char *buf, size_t len, Bitset *visited, Type *t)
+static int
+fmtunion(char *buf, size_t len, Bitset *visited, Type *t)
{
char subbuf[512];
char *name, *ns, *sep;
@@ -524,7 +559,8 @@ static int fmtunion(char *buf, size_t len, Bitset *visited, Type *t)
return p - buf;
}
-static int fmtlist(char *buf, size_t len, Bitset *visited, Type **arg, size_t narg)
+static int
+fmtlist(char *buf, size_t len, Bitset *visited, Type **arg, size_t narg)
{
char *end, *p, *sep;
size_t i;
@@ -542,7 +578,8 @@ static int fmtlist(char *buf, size_t len, Bitset *visited, Type **arg, size_t na
return p - buf;
}
-static int tybfmt(char *buf, size_t len, Bitset *visited, Type *t)
+static int
+tybfmt(char *buf, size_t len, Bitset *visited, Type *t)
{
size_t i;
char *p;
@@ -658,7 +695,8 @@ static int tybfmt(char *buf, size_t len, Bitset *visited, Type *t)
return p - buf;
}
-char *tyfmt(char *buf, size_t len, Type *t)
+char *
+tyfmt(char *buf, size_t len, Type *t)
{
Bitset *bs;
@@ -668,21 +706,24 @@ char *tyfmt(char *buf, size_t len, Type *t)
return buf;
}
-char *traitstr(Type *t)
+char *
+traitstr(Type *t)
{
char buf[1024];
traitfmt(buf, 1024, t);
return strdup(buf);
}
-char *tystr(Type *t)
+char *
+tystr(Type *t)
{
char buf[1024];
tyfmt(buf, 1024, t);
return strdup(buf);
}
-ulong tyhash(void *ty)
+ulong
+tyhash(void *ty)
{
size_t i;
Type *t;
@@ -703,7 +744,8 @@ ulong tyhash(void *ty)
return hash;
}
-int tyeq_rec(Type *a, Type *b, Bitset *avisited, Bitset *bvisited, int search)
+int
+tyeq_rec(Type *a, Type *b, Bitset *avisited, Bitset *bvisited, int search)
{
Type *x, *y;
size_t i;
@@ -804,7 +846,8 @@ int tyeq_rec(Type *a, Type *b, Bitset *avisited, Bitset *bvisited, int search)
return ret;
}
-int tystricteq(void *a, void *b)
+int
+tystricteq(void *a, void *b)
{
Bitset *avisited, *bvisited;
int eq;
@@ -819,7 +862,8 @@ int tystricteq(void *a, void *b)
return eq;
}
-int tyeq(void *a, void *b)
+int
+tyeq(void *a, void *b)
{
Bitset *avisited, *bvisited;
int eq;
@@ -834,7 +878,8 @@ int tyeq(void *a, void *b)
return eq;
}
-size_t tyidfmt(char *buf, size_t sz, Type *ty)
+size_t
+tyidfmt(char *buf, size_t sz, Type *ty)
{
size_t i;
char *p, *end;
@@ -919,7 +964,8 @@ size_t tyidfmt(char *buf, size_t sz, Type *ty)
return p - buf;
}
-void iterableinit(Stab *st, Trait *tr)
+void
+iterableinit(Stab *st, Trait *tr)
{
Node *func, *arg, **args;
Type *ty;
@@ -942,7 +988,7 @@ void iterableinit(Stab *st, Trait *tr)
func = mkdecl(Zloc, mkname(Zloc, "__iternext__"), ty);
func->decl.trait = tr;
- func->decl.impls = mkht(tyhash, tyeq);
+ func->decl.impls = mkht(tyhash, tyeq);
func->decl.isgeneric = 1;
func->decl.isconst = 1;
func->decl.isglobl = 1;
@@ -962,7 +1008,7 @@ void iterableinit(Stab *st, Trait *tr)
func = mkdecl(Zloc, mkname(Zloc, "__iterfin__"), ty);
func->decl.trait = tr;
- func->decl.impls = mkht(tyhash, tyeq);
+ func->decl.impls = mkht(tyhash, tyeq);
func->decl.isgeneric = 1;
func->decl.isconst = 1;
func->decl.isglobl = 1;
@@ -972,7 +1018,8 @@ void iterableinit(Stab *st, Trait *tr)
putdcl(st, func);
}
-void tyinit(Stab *st)
+void
+tyinit(Stab *st)
{
int i;
Type *ty;
diff --git a/parse/use.c b/parse/use.c
index 4c95500..e9a169c 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -38,9 +38,9 @@ static Node *unpickle(FILE *fd);
/* type fixup list */
static Htab *tydeduptab; /* map from name -> type, contains all Tynames loaded ever */
static Htab *trdeduptab; /* map from name -> type, contains all Tynames loaded ever */
-static Htab *tidmap; /* map from tid -> type */
-static Htab *trmap; /* map from trait id -> trait */
-static Htab *initmap; /* map from init name -> int */
+static Htab *tidmap; /* map from tid -> type */
+static Htab *trmap; /* map from trait id -> trait */
+static Htab *initmap; /* map from init name -> int */
#define Builtinmask (1 << 30)
static Typefix *typefix; /* list of types we need to replace */
@@ -49,10 +49,11 @@ static size_t ntypefix; /* size of replacement list */
static Traitfix *traitfix; /* list of traits we need to replace */
static size_t ntraitfix; /* size of replacement list */
-static Node **implfix; /* list of impls we need to fix up */
+static Node **implfix; /* list of impls we need to fix up */
static size_t nimplfix; /* size of replacement list */
-void addextlibs(Node *file, char **libs, size_t nlibs)
+void
+addextlibs(Node *file, char **libs, size_t nlibs)
{
size_t i, j;
@@ -65,9 +66,10 @@ void addextlibs(Node *file, char **libs, size_t nlibs)
}
/* Outputs a symbol table to file in a way that can be
- * read back usefully. Only writes declarations, types
+ * read back usefully. Only writes declarations, type
* and sub-namespaces. Captured variables are ommitted. */
-static void wrstab(FILE *fd, Stab *val)
+static void
+wrstab(FILE *fd, Stab *val)
{
size_t n, i;
void **keys;
@@ -93,7 +95,8 @@ static void wrstab(FILE *fd, Stab *val)
/* Reads a symbol table from file. The converse
* of wrstab. */
-static Stab *rdstab(FILE *fd, int isfunc)
+static Stab *
+rdstab(FILE *fd, int isfunc)
{
Stab *st;
Type *ty;
@@ -118,7 +121,8 @@ static Stab *rdstab(FILE *fd, int isfunc)
return st;
}
-static void wrucon(FILE *fd, Ucon *uc)
+static void
+wrucon(FILE *fd, Ucon *uc)
{
wrint(fd, uc->loc.line);
wrint(fd, uc->id);
@@ -129,7 +133,8 @@ static void wrucon(FILE *fd, Ucon *uc)
wrtype(fd, uc->etype);
}
-static Ucon *rducon(FILE *fd, Type *ut)
+static Ucon *
+rducon(FILE *fd, Type *ut)
{
Type *et;
Node *name;
@@ -154,10 +159,11 @@ static Ucon *rducon(FILE *fd, Type *ut)
}
/* Writes the name and type of a variable,
- * but only writes its intializer for things
+ * but only writes its intializer for thing
* we want to inline cross-file (currently,
* the only cross-file inline is generics) */
-static void wrsym(FILE *fd, Node *val)
+static void
+wrsym(FILE *fd, Node *val)
{
/* sym */
wrint(fd, val->loc.line);
@@ -177,7 +183,8 @@ static void wrsym(FILE *fd, Node *val)
pickle(fd, val->decl.init);
}
-static Node *rdsym(FILE *fd, Trait *ctx)
+static Node *
+rdsym(FILE *fd, Trait *ctx)
{
int line;
Node *name;
@@ -209,7 +216,8 @@ static Node *rdsym(FILE *fd, Trait *ctx)
/* Writes types to a file. Errors on
* internal only types like Tyvar that
* will not be meaningful in another file*/
-static void typickle(FILE *fd, Type *ty)
+static void
+typickle(FILE *fd, Type *ty)
{
size_t i;
@@ -221,7 +229,7 @@ static void typickle(FILE *fd, Type *ty)
wrbyte(fd, ty->vis);
/* tid is generated; don't write */
/* FIXME: since we only support hardcoded traits, we just write
- * out the set of them. we should write out the trait list as
+ * out the set of them. we should write out the trait list a
* well */
if (!ty->traits) {
wrint(fd, 0);
@@ -277,7 +285,8 @@ static void typickle(FILE *fd, Type *ty)
}
}
-static void traitpickle(FILE *fd, Trait *tr)
+static void
+traitpickle(FILE *fd, Trait *tr)
{
size_t i;
@@ -293,7 +302,8 @@ static void traitpickle(FILE *fd, Trait *tr)
wrsym(fd, tr->proto[i]);
}
-static void wrtype(FILE *fd, Type *ty)
+static void
+wrtype(FILE *fd, Type *ty)
{
if (ty->tid >= Builtinmask)
die("Type id %d for %s too big", ty->tid, tystr(ty));
@@ -303,7 +313,8 @@ static void wrtype(FILE *fd, Type *ty)
wrint(fd, ty->tid);
}
-static void rdtype(FILE *fd, Type **dest)
+static void
+rdtype(FILE *fd, Type **dest)
{
uintptr_t tid;
@@ -316,7 +327,8 @@ static void rdtype(FILE *fd, Type **dest)
}
}
-static void rdtrait(FILE *fd, Trait **dest, Type *ty)
+static void
+rdtrait(FILE *fd, Trait **dest, Type *ty)
{
uintptr_t tid;
@@ -335,7 +347,8 @@ static void rdtrait(FILE *fd, Trait **dest, Type *ty)
/* Writes types to a file. Errors on
* internal only types like Tyvar that
* will not be meaningful in another file */
-static Type *tyunpickle(FILE *fd)
+static Type *
+tyunpickle(FILE *fd)
{
size_t i, n;
Type *ty;
@@ -401,7 +414,8 @@ static Type *tyunpickle(FILE *fd)
return ty;
}
-Trait *traitunpickle(FILE *fd)
+Trait *
+traitunpickle(FILE *fd)
{
Trait *tr;
Node *proto;
@@ -409,7 +423,7 @@ Trait *traitunpickle(FILE *fd)
intptr_t uid;
/* create an empty trait */
- tr = mktrait(Zloc, NULL, NULL,
+ tr = mktrait(Zloc, NULL, NULL,
NULL, 0,
NULL, 0,
0);
@@ -439,7 +453,8 @@ Trait *traitunpickle(FILE *fd)
* in-memory representation. Minimal
* checking is done, so a bad type can
* crash the compiler */
-static void pickle(FILE *fd, Node *n)
+static void
+pickle(FILE *fd, Node *n)
{
size_t i;
@@ -572,7 +587,8 @@ static void pickle(FILE *fd, Node *n)
/* Unpickles a node from a file. Minimal checking
* is done. Specifically, no checks are done for
* sane arities, a bad file can crash the compiler */
-static Node *unpickle(FILE *fd)
+static Node *
+unpickle(FILE *fd)
{
size_t i;
Ntype type;
@@ -722,7 +738,8 @@ static Node *unpickle(FILE *fd)
return n;
}
-static Stab *findstab(Stab *st, char *pkg)
+static Stab *
+findstab(Stab *st, char *pkg)
{
Stab *s;
@@ -742,7 +759,8 @@ static Stab *findstab(Stab *st, char *pkg)
return s;
}
-static int isspecialization(Type *t1, Type *t2)
+static int
+isspecialization(Type *t1, Type *t2)
{
if ((t1->type != Tygeneric || t2->type != Tyname) &&
(t1->type != Tyname || t2->type != Tygeneric) &&
@@ -752,7 +770,8 @@ static int isspecialization(Type *t1, Type *t2)
return nameeq(t1->name, t2->name);
}
-static void fixtypemappings(Stab *st)
+static void
+fixtypemappings(Stab *st)
{
size_t i;
Type *t, *u, *old;
@@ -760,7 +779,7 @@ static void fixtypemappings(Stab *st)
/*
* merge duplicate definitions.
* This allows us to compare named types by id, instead
- * of doing a deep walk through the type. This ability is
+ * of doing a deep walk through the type. This ability i
* depended on when we do type inference.
*/
for (i = 0; i < ntypefix; i++) {
@@ -796,7 +815,8 @@ static void fixtypemappings(Stab *st)
lfree(&typefix, &ntypefix);
}
-static void fixtraitmappings(Stab *st)
+static void
+fixtraitmappings(Stab *st)
{
size_t i;
Trait *t, *tr;
@@ -804,7 +824,7 @@ static void fixtraitmappings(Stab *st)
/*
* merge duplicate definitions.
* This allows us to compare named types by id, instead
- * of doing a deep walk through the type. This ability is
+ * of doing a deep walk through the type. This ability i
* depended on when we do type inference.
*/
for (i = 0; i < ntraitfix; i++) {
@@ -828,7 +848,8 @@ static void fixtraitmappings(Stab *st)
ntraitfix = 0;
}
-static void protomap(Trait *tr, Type *ty, Node *dcl)
+static void
+protomap(Trait *tr, Type *ty, Node *dcl)
{
size_t i, len;
char *protoname, *dclname, *p;
@@ -852,7 +873,8 @@ static void protomap(Trait *tr, Type *ty, Node *dcl)
}
}
-static void fiximplmappings(Stab *st)
+static void
+fiximplmappings(Stab *st)
{
Node *impl;
Trait *tr;
@@ -882,7 +904,8 @@ static void fiximplmappings(Stab *st)
* D<picled-decl>
* G<pickled-decl><pickled-initializer>
*/
-int loaduse(char *path, FILE *f, Stab *st, Vis vis)
+int
+loaduse(char *path, FILE *f, Stab *st, Vis vis)
{
intptr_t tid;
size_t i;
@@ -946,7 +969,8 @@ int loaduse(char *path, FILE *f, Stab *st, Vis vis)
/* break out of both loop and switch */
goto foundlib;
lappend(&file->file.libdeps, &file->file.nlibdeps, lib);
-foundlib:
+foundlib
+:
break;
case 'X':
lib = rdstr(f);
@@ -955,7 +979,8 @@ foundlib:
/* break out of both loop and switch */
goto foundextlib;
lappend(&file->file.extlibs, &file->file.nextlibs, lib);
-foundextlib:
+foundextlib
+:
break;
case 'F': lappend(&file->file.files, &file->file.nfiles, rdstr(f)); break;
case 'G':
@@ -1029,7 +1054,8 @@ foundextlib:
return 1;
}
-int hassuffix(char *str, char *suff)
+int
+hassuffix(char *str, char *suff)
{
size_t nstr, nsuff;
@@ -1040,7 +1066,8 @@ int hassuffix(char *str, char *suff)
return !strcmp(str + nstr - nsuff, suff);
}
-void readuse(Node *use, Stab *st, Vis vis)
+void
+readuse(Node *use, Stab *st, Vis vis)
{
size_t i;
FILE *fd;
@@ -1102,7 +1129,8 @@ void readuse(Node *use, Stab *st, Vis vis)
* G<pickled-decl><pickled-initializer>
* Z
*/
-void writeuse(FILE *f, Node *file)
+void
+writeuse(FILE *f, Node *file)
{
Stab *st;
void **k;