shithub: scc

Download patch

ref: d3960dec0c54014b6a7072a7646d35ee7cb86533
parent: 6981fdf248be1f4a15a9b8fd0296111fba9ae2dd
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Jul 17 18:42:37 EDT 2014

Parse function headers in cc2

This commits only parses the name of the function and ignores
all the remaining characters.

--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -5,6 +5,9 @@
 #include <cc.h>
 #include <sizes.h>
 
+#define STR(x) XSTR(x)
+#define XSTR(x) #x
+
 #define NR_STACKSIZ 32
 #define NR_NODEPOOL 128
 #define NR_EXPRESSIONS 64
@@ -196,20 +199,33 @@
 }
 
 static void
+chop(void)
+{
+	int c;
+
+	while ((c = getchar()) != EOF && c != '\n')
+		/* nothing */;
+}
+
+static void
 deflabel(void)
 {
 	Symbol *sym = &symtbl[getid()];
 
 	sym->u.l.addr = listp - listexp;
+	chop();
 }
 
-int
-parse(void)
+static void
+function(void)
 {
 	int c;
+	char name[IDENTSIZ + 1];
 
-	while ((c = getchar()) != EOF) {
-		switch (c) {
+	scanf("%" STR(IDENTSIZ) "s", name);
+	chop();
+	for (;;) {
+		switch (c = getchar()) {
 		case '\t':
 			expression();
 			break;
@@ -219,12 +235,37 @@
 		case 'S':
 			/* struct */
 			break;
-		case 'T': case 'A': case 'G': case 'R':
+		case 'T': case 'A': case 'R':
 			declaration(c);
 			break;
+		case '}':
+			chop();
+			return;
 		default:
 			esyntax();
 			break;
+		}
+	}
+}
+
+int
+parse(void)
+{
+	int c;
+
+	for (;;) {
+		switch (c = getchar()) {
+		case 'G':
+			declaration(c);
+			break;
+		case 'X':
+			function();
+			break;
+		case EOF:
+			return;
+			break;
+		default:
+			esyntax();
 		}
 	}
 }