shithub: scc

Download patch

ref: 7c3cd98f410be4dfea41213eb55c6ff88b09b280
parent: 35257df51f4fed44e2eb1cb815a9f1f45f74bd78
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu May 7 10:47:15 EDT 2015

Add discard() to cc1

This function discard all the input data until the next secure point
in the code.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -261,6 +261,7 @@
 extern uint8_t ahead(void);
 extern uint8_t next(void);
 extern void expect(uint8_t tok);
+extern void discard(void);
 #define accept(t) ((yytoken == (t)) ? next() : 0)
 
 /* code.c */
--- a/cc1/error.c
+++ b/cc1/error.c
@@ -1,5 +1,4 @@
 
-#include <setjmp.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -9,10 +8,7 @@
 #include "cc1.h"
 
 extern uint8_t failure;
-extern jmp_buf recover;
 
-static uint8_t safe;
-
 static void
 warn_helper(int8_t flag, char *fmt, va_list va)
 {
@@ -40,15 +36,8 @@
 }
 
 void
-setsafe(uint8_t type)
-{
-	safe = type;
-}
-
-void
 error(char *fmt, ...)
 {
-	int c;
 	va_list va;
 
 	va_start(va, fmt);
@@ -55,32 +44,7 @@
 	warn_helper(-1, fmt, va);
 	va_end(va);
 	failure = 1;
-
-	c = yytoken;
-	do {
-		switch (safe) {
-		case END_COMP:
-			if (c == '}')
-				goto jump;
-			goto semicolon;
-		case END_COND:
-			if (c == ')')
-				goto jump;
-			break;
-		case END_LDECL:
-			if (c == ',')
-				goto jump;
-		case END_DECL:
-		semicolon:
-			if (c == ';')
-				goto jump;
-			break;
-		}
-	} while ((c = getchar()) != EOF);
-
-jump:
-	yytoken = c;
-	longjmp(recover, 1);
+	discard();
 }
 
 void
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -1,5 +1,6 @@
 
 #include <inttypes.h>
+#include <setjmp.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -16,7 +17,9 @@
 uint8_t yytoken;
 struct yystype yylval;
 char yytext[IDENTSIZ + 1];
+static uint8_t safe;
 
+
 static uint8_t
 integer(char *s, char base)
 {
@@ -420,4 +423,43 @@
 		filename = file;
 	}
 	linenum = 1;
+}
+
+void
+setsafe(uint8_t type)
+{
+	safe = type;
+}
+
+void
+discard(void)
+{
+	extern jmp_buf recover;
+	int c;
+
+	c = yytoken;
+	do {
+		switch (safe) {
+		case END_COMP:
+			if (c == '}')
+				goto jump;
+			goto semicolon;
+		case END_COND:
+			if (c == ')')
+				goto jump;
+			break;
+		case END_LDECL:
+			if (c == ',')
+				goto jump;
+		case END_DECL:
+		semicolon:
+			if (c == ';')
+				goto jump;
+			break;
+		}
+	} while ((c = getchar()) != EOF);
+
+jump:
+	yytoken = c;
+	longjmp(recover, 1);
 }