shithub: scc

Download patch

ref: db85440bb52b69b15dc485069a639ef92a4d50fd
parent: 867af16e5a690b302707c010ca5b4b8f41a28845
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 21 11:12:32 EDT 2015

Improve the longjmp logic

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -1,7 +1,7 @@
 
 
-extern void error(const char *fmt, ...);
-extern void warn(const char *fmt, ...);
+extern void error(char *fmt, ...);
+extern void warn(char *fmt, ...);
 extern void unexpected(void);
 
 /* definitions of types */
--- a/cc1/error.c
+++ b/cc1/error.c
@@ -8,29 +8,26 @@
 #include "../inc/cc.h"
 #include "cc1.h"
 
+extern uint8_t failure;
+extern jmp_buf recover;
+
 static void
-warn_helper(int8_t flag, const char *fmt, va_list va)
+warn_helper(int8_t flag, char *fmt, va_list va)
 {
 	extern unsigned linenum;
 	extern unsigned columnum;
 	extern const char *filename;
-	extern uint8_t failure;
-	extern jmp_buf recover;
 
 	if (!flag)
 		return;
 	fprintf(stderr, "%s:%s:%u: ",
-		(flag < 0) ? "warning" : "error", filename, linenum);
+		(flag < 0) ? "error" : "warning", filename, linenum);
 	vfprintf(stderr, fmt, va);
 	putc('\n', stderr);
-	if (flag < 0) {
-		failure = 1;
-		longjmp(recover, 1);
-	}
 }
 
 void
-warn(const char *fmt, ...)
+warn(char *fmt, ...)
 {
 	extern uint8_t warnings;
 
@@ -41,12 +38,15 @@
 }
 
 void
-error(const char *fmt, ...)
+error(char *fmt, ...)
 {
 	va_list va;
 	va_start(va, fmt);
 	warn_helper(-1, fmt, va);
 	va_end(va);
+
+	failure = 1;
+	longjmp(recover, 1);
 }
 
 void
@@ -54,4 +54,3 @@
 {
 	error("unexpected '%s'", yytext);
 }
-