shithub: mc

Download patch

ref: e22c4b573a6d0d71a8781ef655a7249f8b1921a4
parent: ffc55ee721c02d1caede8d7fbad9e8b687f01306
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Dec 31 20:30:17 EST 2015

Fix style.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -360,8 +360,7 @@
 		subst = mkht(tyhash, tyeq);
 		t = tyspecialize(t, subst, st->delayed);
 		htfree(subst);
-	}
-	else {
+	} else {
 		t = tyspecialize(t, subst, st->delayed);
 	}
 	tyunbind(st, t);
@@ -394,8 +393,7 @@
 		for (i = 0; i < t->nmemb; i++)
 			infernode(st, &t->sdecls[i], NULL, NULL);
 		st->inaggr--;
-	}
-	else if (t->type == Tyunion) {
+	} else if (t->type == Tyunion) {
 		st->inaggr++;
 		for (i = 0; i < t->nmemb; i++) {
 			t->udecls[i]->utype = t;
@@ -406,13 +404,11 @@
 			}
 		}
 		st->inaggr--;
-	}
-	else if (t->type == Tyarray) {
+	} else if (t->type == Tyarray) {
 		if (!st->inaggr && !t->asize)
 			lfatal(t->loc, "unsized array type outside of struct");
 		infernode(st, &t->asize, NULL, NULL);
-	}
-	else if (t->type == Typaram && st->innamed) {
+	} else if (t->type == Typaram && st->innamed) {
 		if (!isbound(st, t))
 			lfatal(
 					t->loc, "type parameter %s is undefined in generic context", tystr(t));
@@ -731,8 +727,7 @@
 		if (!a->traits)
 			a->traits = mkbs();
 		settrait(a, c);
-	}
-	else if (!a->traits || !bshas(a->traits, c->uid)) {
+	} else if (!a->traits || !bshas(a->traits, c->uid)) {
 		fatal(ctx, "%s needs %s near %s", tystr(a), namestr(c->name), ctxstr(st, ctx));
 	}
 }
@@ -784,8 +779,7 @@
 			b->traits = bsdup(a->traits);
 		else if (b->traits)
 			a->traits = bsdup(b->traits);
-	}
-	else {
+	} else {
 		verifytraits(st, ctx, a, b);
 	}
 }
@@ -1014,8 +1008,7 @@
 			htput(st->delayed, b, htget(st->delayed, a));
 		else if (hthas(st->delayed, b) && !hthas(st->delayed, a))
 			htput(st->delayed, a, htget(st->delayed, b));
-	}
-	else if (hthas(st->delayed, a)) {
+	} else if (hthas(st->delayed, a)) {
 		unify(st, ctx, htget(st->delayed, a), tybase(b));
 	}
 
@@ -1037,8 +1030,7 @@
 		/* the first arg is the function itself, so it shouldn't be counted */
 		ft = mktyfunc(n->loc, &n->expr.args[1], n->expr.nargs - 1, mktyvar(n->loc));
 		unify(st, n, ft, type(st, n->expr.args[0]));
-	}
-	else if (tybase(ft)->type != Tyfunc) {
+	} else if (tybase(ft)->type != Tyfunc) {
 		fatal(n, "calling uncallable type %s", tystr(ft));
 	}
 	/* first arg: function itself */
@@ -1126,12 +1118,10 @@
 		if (t->type == Tyvar) {
 			settype(st, n, mktyvar(n->loc));
 			delayedcheck(st, n, curstab());
-		}
-		else {
+		} else {
 			settype(st, n, t);
 		}
-	}
-	else {
+	} else {
 		settype(st, n, t);
 	}
 	return t;
@@ -1295,8 +1285,7 @@
 			else
 				fatal(n, "pattern shadows variable declared on %s:%d near %s",
 						fname(s->loc), lnum(s->loc), ctxstr(st, s));
-		}
-		else {
+		} else {
 			t = mktyvar(n->loc);
 			s = mkdecl(n->loc, n->expr.args[0], t);
 			s->decl.init = val;
@@ -1707,8 +1696,7 @@
 		unify(st, n, type(st, n), type(st, n->decl.init));
 		if (n->decl.isconst && !n->decl.init->expr.isconst)
 			fatal(n, "non-const initializer for \"%s\"", ctxstr(st, n));
-	}
-	else {
+	} else {
 		if ((n->decl.isconst || n->decl.isgeneric) && !n->decl.isextern)
 			fatal(n, "non-extern \"%s\" has no initializer", ctxstr(st, n));
 	}
@@ -1879,19 +1867,16 @@
 			t = tyint;
 		if (hastrait(t, traittab[Tcfloat]) && checktraits(t, tyflt))
 			t = tyflt;
-	}
-	else if (!t->fixed) {
+	} else if (!t->fixed) {
 		t->fixed = 1;
 		if (t->type == Tyarray) {
 			typesub(st, t->asize, noerr);
-		}
-		else if (t->type == Tystruct) {
+		} else if (t->type == Tystruct) {
 			st->inaggr++;
 			for (i = 0; i < t->nmemb; i++)
 				typesub(st, t->sdecls[i], noerr);
 			st->inaggr--;
-		}
-		else if (t->type == Tyunion) {
+		} else if (t->type == Tyunion) {
 			for (i = 0; i < t->nmemb; i++) {
 				if (t->udecls[i]->etype) {
 					tyresolve(st, t->udecls[i]->etype);
@@ -1899,8 +1884,7 @@
 						tyfix(st, ctx, t->udecls[i]->etype, noerr);
 				}
 			}
-		}
-		else if (t->type == Tyname) {
+		} else if (t->type == Tyname) {
 			for (i = 0; i < t->narg; i++)
 				t->arg[i] = tyfix(st, ctx, t->arg[i], noerr);
 		}
@@ -1959,8 +1943,7 @@
 		 *	 ---------------------------------------
 		 *			   x.y : membtype
 		 */
-	}
-	else {
+	} else {
 		if (tybase(t)->type == Typtr)
 			t = tybase(tf(st, t->sub[0]));
 		if (tybase(t)->type != Tystruct) {
@@ -2115,8 +2098,7 @@
 		sval = n->lit.intval;
 		if (sval < svranges[t->type][0] || sval > svranges[t->type][1])
 			fatal(n, "literal value %lld out of range for type \"%s\"", sval, tystr(t));
-	}
-	else if ((t->type >= Tybyte && t->type <= Tyint64) || t->type == Tychar) {
+	} else if ((t->type >= Tybyte && t->type <= Tyint64) || t->type == Tychar) {
 		uval = n->lit.intval;
 		if (uval < uvranges[t->type][0] || uval > uvranges[t->type][1])
 			fatal(n, "literal value %llu out of range for type \"%s\"", uval, tystr(t));
@@ -2419,8 +2401,7 @@
 			t->isreflect = 1;
 			for (j = 0; j < t->narg; j++)
 				taghidden(t->arg[j]);
-		}
-		else if (t->type == Tygeneric) {
+		} else if (t->type == Tygeneric) {
 			for (j = 0; j < t->ngparam; j++)
 				taghidden(t->gparam[j]);
 		}
--- a/parse/node.c
+++ b/parse/node.c
@@ -507,8 +507,7 @@
 {
 	if (n->type == Ndecl) {
 		return n->decl.did;
-	}
-	else if (n->type == Nexpr) {
+	} else if (n->type == Nexpr) {
 		assert(exprop(n) == Ovar);
 		return n->expr.did;
 	}
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -90,8 +90,7 @@
 			ret = tydup(t);
 			tmp = htget(delayed, t);
 			htput(delayed, ret, tyspecialize(tmp, tsmap, delayed));
-		}
-		else {
+		} else {
 			ret = t;
 		}
 		break;
@@ -101,8 +100,7 @@
 			htput(tsmap, t, ret);
 			for (i = 0; i < t->nsub; i++)
 				ret->sub[i] = tyspecialize(t->sub[i], tsmap, delayed);
-		}
-		else {
+		} else {
 			ret = t;
 		}
 		break;
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -250,12 +250,10 @@
 	if (old->decl.vis == Visexport && new->decl.vis != Visexport) {
 		e = old;
 		g = new;
-	}
-	else if (new->decl.vis == Visexport && old->decl.vis != Visexport) {
+	} else if (new->decl.vis == Visexport && old->decl.vis != Visexport) {
 		e = new;
 		g = old;
-	}
-	else {
+	} else {
 		return 0;
 	}
 	old->decl.vis = Visexport;
@@ -329,15 +327,13 @@
 {
 	if (!new) {
 		lfatal(old->loc, "double prototyping of %s", tystr(old));
-	}
-	else if (old->vis == Visexport && new->vis != Visexport) {
+	} else if (old->vis == Visexport && new->vis != Visexport) {
 		if (!old->sub && new->sub) {
 			old->sub = new->sub;
 			old->nsub = new->nsub;
 			return 1;
 		}
-	}
-	else if (new->vis == Visexport && old->vis != Visexport) {
+	} else if (new->vis == Visexport && old->vis != Visexport) {
 		if (!new->sub && old->sub) {
 			new->sub = old->sub;
 			new->nsub = old->nsub;
@@ -362,8 +358,7 @@
 		if (t && hastype(st, n)) {
 			t->vis = Visexport;
 			updatetype(st, n, t);
-		}
-		else {
+		} else {
 			td = xalloc(sizeof(Tydefn));
 			td->loc = n->loc;
 			td->name = n;
@@ -370,8 +365,7 @@
 			td->type = t;
 			htput(st->ty, td->name, td);
 		}
-	}
-	else if (!mergetype(ty, t)) {
+	} else if (!mergetype(ty, t)) {
 		fatal(n, "Type %s already declared on %s:%d", tystr(ty), fname(ty->loc),
 				lnum(ty->loc));
 	}
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -62,8 +62,7 @@
 	if (peek() == c) {
 		next();
 		return 1;
-	}
-	else {
+	} else {
 		return 0;
 	}
 }
@@ -512,13 +511,11 @@
 		  if (match('.')) {
 			  if (match('.')) {
 				  tt = Tellipsis;
-			  }
-			  else {
+			  } else {
 				  unget();
 				  tt = Tdot;
 			  }
-		  }
-		  else {
+		  } else {
 			  tt = Tdot;
 		  }
 		  break;
@@ -589,14 +586,12 @@
 	case '<':
 		  if (match('=')) {
 			  tt = Tle;
-		  }
-		  else if (match('<')) {
+		  } else if (match('<')) {
 			  if (match('='))
 				  tt = Tbsleq;
 			  else
 				  tt = Tbsl;
-		  }
-		  else {
+		  } else {
 			  tt = Tlt;
 		  }
 		  break;
@@ -603,14 +598,12 @@
 	case '>':
 		  if (match('=')) {
 			  tt = Tge;
-		  }
-		  else if (match('>')) {
+		  } else if (match('>')) {
 			  if (match('='))
 				  tt = Tbsreq;
 			  else
 				  tt = Tbsr;
-		  }
-		  else {
+		  } else {
 			  tt = Tgt;
 		  }
 		  break;
@@ -667,8 +660,7 @@
 		t = mktok(Tfloatlit);
 		t->id = strdupn(&fbuf[start], fidx - start);
 		t->fltval = strtod(buf, NULL);
-	}
-	else {
+	} else {
 		t = mktok(Tintlit);
 		t->id = strdupn(&fbuf[start], fidx - start);
 		t->intval = strtoull(buf, NULL, base);
@@ -741,8 +733,7 @@
 			t = number(8);
 		else
 			t = number(10);
-	}
-	else {
+	} else {
 		t = number(10);
 	}
 
@@ -773,28 +764,21 @@
 	c = peek();
 	if (c == End) {
 		t = mktok(0);
-	}
-	else if (c == '\n') {
+	} else if (c == '\n') {
 		curloc.line++;
 		next();
 		t = mktok(Tendln);
-	}
-	else if (isalpha(c) || c == '_' || c == '$') {
+	} else if (isalpha(c) || c == '_' || c == '$') {
 		t = kwident();
-	}
-	else if (c == '"') {
+	} else if (c == '"') {
 		t = strlit();
-	}
-	else if (c == '\'') {
+	} else if (c == '\'') {
 		t = charlit();
-	}
-	else if (isdigit(c)) {
+	} else if (isdigit(c)) {
 		t = numlit();
-	}
-	else if (c == '@') {
+	} else if (c == '@') {
 		t = typaram();
-	}
-	else {
+	} else {
 		t = oper();
 	}
 
--- a/parse/type.c
+++ b/parse/type.c
@@ -488,8 +488,7 @@
 			ty = tystr(t->udecls[i]->etype);
 			p += bprintf(p, end - p, "\t`%s %s\n", name, ty);
 			free(ty);
-		}
-		else {
+		} else {
 			p += bprintf(p, end - p, "\t`%s\n", name);
 		}
 	}
@@ -563,8 +562,7 @@
 		if (t->asize) {
 			i = t->asize->expr.args[0]->lit.intval;
 			p += bprintf(p, end - p, "[%zd]", i);
-		}
-		else {
+		} else {
 			p += bprintf(p, end - p, "[]");
 		}
 		break;
--- a/parse/use.c
+++ b/parse/use.c
@@ -216,8 +216,7 @@
 	 * well */
 	if (!ty->traits) {
 		wrint(fd, 0);
-	}
-	else {
+	} else {
 		wrint(fd, bscount(ty->traits));
 		for (i = 0; bsiter(ty->traits, &i); i++) {
 			if (i < Ntraits)
@@ -305,8 +304,7 @@
 	tid = rdint(fd);
 	if (tid & Builtinmask) {
 		*dest = mktype(Zloc, tid & ~Builtinmask);
-	}
-	else {
+	} else {
 		lappend(&typefixdest, &ntypefixdest, dest);
 		lappend(&typefixid, &ntypefixid, itop(tid));
 	}
@@ -322,8 +320,7 @@
 			*dest = traittab[tid & ~Builtinmask];
 		if (ty)
 			settrait(ty, traittab[tid & ~Builtinmask]);
-	}
-	else {
+	} else {
 		lappend(&traitfixdest, &ntraitfixdest, dest);
 		lappend(&traitfixtype, &ntraitfixtype, ty);
 		lappend(&traitfixid, &ntraitfixid, itop(tid));
@@ -887,16 +884,13 @@
 	if (st->name) {
 		if (pkg && !strcmp(pkg, st->name)) {
 			s = st;
-		}
-		else {
+		} else {
 			s = findstab(st, pkg);
 		}
-	}
-	else {
+	} else {
 		if (pkg) {
 			s = findstab(st, pkg);
-		}
-		else {
+		} else {
 			s = st;
 		}
 	}
@@ -971,8 +965,7 @@
 					  ty->ishidden = 1;
 				  if (!gettype(s, ty->name) && !ty->ishidden)
 					  puttype(s, ty->name, ty);
-			  }
-			  else if (ty->type == Tyunion) {
+			  } else if (ty->type == Tyunion) {
 				  for (i = 0; i < ty->nmemb; i++)
 					  if (!getucon(s, ty->udecls[i]->name) &&
 							  !ty->udecls[i]->synth)
@@ -1014,8 +1007,7 @@
 		p = strdup(use->use.name);
 		fd = fopen(p, "r");
 		/* nonlocal (barename) uses are always searched on the include path */
-	}
-	else {
+	} else {
 		for (i = 0; i < nincpaths; i++) {
 			t = strjoin(incpaths[i], "/");
 			p = strjoin(t, use->use.name);
--- a/parse/util.c
+++ b/parse/util.c
@@ -302,8 +302,7 @@
 
 	if (!val) {
 		wrint(fd, -1);
-	}
-	else {
+	} else {
 		wrint(fd, strlen(val));
 		len = strlen(val);
 		wrbuf(fd, val, len);
@@ -318,8 +317,7 @@
 	len = rdint(fd);
 	if (len == -1) {
 		return NULL;
-	}
-	else {
+	} else {
 		s = xalloc(len + 1);
 		rdbuf(fd, s, len);
 		s[len] = '\0';
@@ -404,8 +402,7 @@
 	if (suflen < slen && !strcmp(suf, &s[slen - suflen])) {
 		strncat(buf, s, slen - suflen);
 		strncat(buf, swap, swaplen);
-	}
-	else {
+	} else {
 		bprintf(buf, sz, "%s%s", s, swap);
 	}
 
@@ -472,13 +469,11 @@
 				*take = 1;
 				*mand = 1;
 				return 1;
-			}
-			else if (*s == '?') {
+			} else if (*s == '?') {
 				*take = 1;
 				*mand = 0;
 				return 1;
-			}
-			else {
+			} else {
 				*take = 0;
 				*mand = 0;
 				return 1;
@@ -538,17 +533,14 @@
 		if (*ctx->curarg) {
 			ctx->optarg = ctx->curarg;
 			ctx->curarg += strlen(ctx->optarg);
-		}
-		else if (ctx->argidx < ctx->noptargs - 1) {
+		} else if (ctx->argidx < ctx->noptargs - 1) {
 			ctx->optarg = ctx->optargs[ctx->argidx + 1];
 			ctx->argidx++;
-		}
-		else if (mand) {
+		} else if (mand) {
 			fprintf(stderr, "expected argument for %c\n", *ctx->curarg);
 		}
 		findnextopt(ctx);
-	}
-	else {
+	} else {
 		if (*ctx->curarg == '\0')
 			findnextopt(ctx);
 	}