shithub: scc

Download patch

ref: 3a12c295a9d0c2e5d61428bde365bb3fb6cad1f2
parent: fbd8dfe6829353e38efd2cade078e3a7ae3ddef3
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Feb 24 14:53:02 EST 2017

[cc1] Move print of #line to cpp

When cc1 is working with -E it has to control the current line
number and emit #line directives when there is a discrepancy,
and it was done directly in moreinput(), but this is a job that
is better done in a funciton located in cpp.c, specially near
of outcpp(), because both functions are going to generate the
output at the same time.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -456,6 +456,7 @@
 extern void outcpp(void);
 extern void defdefine(char *macro, char *val, char *source);
 extern void undefmacro(char *s);
+extern void ppragmaln(void);
 
 /* builtin.c */
 extern void ibuilts(void);
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -781,6 +781,27 @@
 }
 
 void
+ppragmaln(void)
+{
+	static char file[FILENAME_MAX];
+	static unsigned nline;
+	char *s;
+	int i;
+
+	putchar('\n');
+	if (strcmp(file, filenam)) {
+		strcpy(file, filenam);
+		s = "#line %u %s\n";
+	} else if (nline+1 != lineno) {
+		s = "#line %u\n";
+	} else {
+		s = "";
+	}
+	nline = lineno;
+	printf(s, nline, file);
+}
+
+void
 outcpp(void)
 {
 	char c, *s, *t;
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -304,23 +304,8 @@
 		}
 	}
 
-	if (onlycpp && !wasexpand) {
-		static char file[FILENAME_MAX];
-		static unsigned nline;
-		char *s;
-
-		putchar('\n');
-		if (strcmp(file, filenam)) {
-			strcpy(file, filenam);
-			s = "#line %u %s\n";
-		} else if (nline+1 != lineno) {
-			s = "#line %u\n";
-		} else {
-			s = "";
-		}
-		nline = lineno;
-		printf(s, nline, file);
-	}
+	if (onlycpp && !wasexpand)
+		ppragmaln();
 	return 1;
 }