summaryrefslogtreecommitdiff
path: root/parse/node.c
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/node.c
parent25d91f98a97df36e1da381b273219ceedf256a4d (diff)
downloadmc-95f4d0b36eb2d25889eed6ab48fb025d5b346b67.tar.gz
Style(9)-ify.
Diffstat (limited to 'parse/node.c')
-rw-r--r--parse/node.c156
1 files changed, 106 insertions, 50 deletions
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); }