commit 7c3cd98f410be4dfea41213eb55c6ff88b09b280
parent 35257df51f4fed44e2eb1cb815a9f1f45f74bd78
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 7 May 2015 14:47:15 +0200
Add discard() to cc1
This function discard all the input data until the next secure point
in the code.
Diffstat:
3 files changed, 44 insertions(+), 37 deletions(-)
diff --git a/cc1/cc1.h b/cc1/cc1.h
@@ -261,6 +261,7 @@ extern void extdecl(void), decl(void);
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 */
diff --git 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,9 +8,6 @@
#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,47 +36,15 @@ warn(char *fmt, ...)
}
void
-setsafe(uint8_t type)
-{
- safe = type;
-}
-
-void
error(char *fmt, ...)
{
- int c;
va_list va;
va_start(va, fmt);
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
diff --git 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,6 +17,8 @@ unsigned linenum;
uint8_t yytoken;
struct yystype yylval;
char yytext[IDENTSIZ + 1];
+static uint8_t safe;
+
static uint8_t
integer(char *s, char base)
@@ -421,3 +424,42 @@ lexfile(const char *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);
+}