shithub: scc

Download patch

ref: 54e92032ca6a63fe2175a9784eaa656e09b03774
parent: 3674aab1851afa91ffb0715055c0cf1d0ccc0058
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 8 10:45:54 EDT 2014

Remove link() and getroot()

These functions only checked the correct state of the stack
and the list of expressions, so it was a non sense to have
these functions that were only used in expression.

--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -75,14 +75,6 @@
 	return *--stackp;
 }
 
-static void
-link(Node *np)
-{
-	if (listp == &listexp[NR_EXPRESSIONS])
-		error(EEXPROV);
-	*listp++ = np;
-}
-
 static char
 gettype(char *type)
 {
@@ -163,15 +155,6 @@
 	push(np);
 }
 
-static Node *
-getroot(void)
-{
-	Node *np = *--stackp;
-	if (stackp != stack)
-		error(EEXPBAL);
-	return np;
-}
-
 static void (*optbl[])(char *) = {
 	['+'] = operator,
 	['-'] = operator,
@@ -188,6 +171,7 @@
 static void
 expression(char *token)
 {
+	Node *np;
 	void (*fun)(char *);
 
 	do {
@@ -196,7 +180,12 @@
 		(*fun)(token);
 	} while ((token = strtok(NULL, "\t")) != NULL);
 
-	link(getroot());
+	np = pop();
+	if (stackp != stack)
+		error(EEXPBAL);
+	if (listp == &listexp[NR_EXPRESSIONS])
+		error(EEXPROV);
+	*listp++ = np;
 }
 
 static void