diff directive.c @ 164:f14f5352956c

Merge upstream into Joerg's changes.
author David A. Holland
date Fri, 12 Jun 2015 01:00:38 -0400
parents d6e6b3940780 a2c2fe8dbea3
children cc6d6f27d6ee
line wrap: on
line diff
--- a/directive.c	Fri Feb 27 13:44:39 2015 +0100
+++ b/directive.c	Fri Jun 12 01:00:38 2015 -0400
@@ -175,7 +175,7 @@
 
 static
 void
-d_if(struct place *p, struct place *p2, struct place *np, char *line)
+d_if(struct lineplace *lp, struct place *p2, char *line)
 {
 	char *expr;
 	bool val;
@@ -194,38 +194,38 @@
 	} else {
 		val = 0;
 	}
-	ifstate_push(p, val);
+	ifstate_push(&lp->current, val);
 	dostrfree(expr);
 }
 
 static
 void
-d_ifdef(struct place *p, struct place *p2, struct place *np, char *line)
+d_ifdef(struct lineplace *lp, struct place *p2, char *line)
 {
 	uncomment(line);
 	oneword("#ifdef", p2, line);
-	ifstate_push(p, macro_isdefined(line));
+	ifstate_push(&lp->current, macro_isdefined(line));
 }
 
 static
 void
-d_ifndef(struct place *p, struct place *p2, struct place *np, char *line)
+d_ifndef(struct lineplace *lp, struct place *p2, char *line)
 {
 	uncomment(line);
 	oneword("#ifndef", p2, line);
-	ifstate_push(p, !macro_isdefined(line));
+	ifstate_push(&lp->current, !macro_isdefined(line));
 }
 
 static
 void
-d_elif(struct place *p, struct place *p2, struct place *np, char *line)
+d_elif(struct lineplace *lp, struct place *p2, char *line)
 {
 	char *expr;
 	struct place p3 = *p2;
 	size_t oldlen;
 
 	if (ifstate->seenelse) {
-		complain(p, "#elif after #else");
+		complain(&lp->current, "#elif after #else");
 		complain_fail();
 	}
 
@@ -247,13 +247,14 @@
 
 static
 void
-d_else(struct place *p, struct place *p2, struct place *np, char *line)
+d_else(struct lineplace *lp, struct place *p2, char *line)
 {
 	(void)p2;
 	(void)line;
 
 	if (ifstate->seenelse) {
-		complain(p, "Multiple #else directives in one conditional");
+		complain(&lp->current,
+			 "Multiple #else directives in one conditional");
 		complain_fail();
 	}
 
@@ -264,13 +265,13 @@
 
 static
 void
-d_endif(struct place *p, struct place *p2, struct place *np, char *line)
+d_endif(struct lineplace *lp, struct place *p2, char *line)
 {
 	(void)p2;
 	(void)line;
 
 	if (ifstate->prev == NULL) {
-		complain(p, "Unmatched #endif");
+		complain(&lp->current, "Unmatched #endif");
 		complain_fail();
 	} else {
 		ifstate_pop();
@@ -282,12 +283,12 @@
 
 static
 void
-d_define(struct place *p, struct place *p2, struct place *np, char *line)
+d_define(struct lineplace *lp, struct place *p2, char *line)
 {
 	size_t pos, argpos;
 	struct place p3, p4;
 
-	(void)p;
+	(void)lp;
 
 	/*
 	 * line may be:
@@ -347,9 +348,9 @@
 
 static
 void
-d_undef(struct place *p, struct place *p2, struct place *np, char *line)
+d_undef(struct lineplace *lp, struct place *p2, char *line)
 {
-	(void)p;
+	(void)lp;
 
 	uncomment(line);
 	oneword("#undef", p2, line);
@@ -383,13 +384,13 @@
 
 static
 void
-d_include(struct place *p, struct place *p2, struct place *np, char *line)
+d_include(struct lineplace *lp, struct place *p2, char *line)
 {
 	char *text;
 	size_t oldlen;
 
 	uncomment(line);
-	if (tryinclude(p, line)) {
+	if (tryinclude(&lp->current, line)) {
 		return;
 	}
 	text = macroexpand(p2, line, strlen(line), false);
@@ -399,20 +400,20 @@
 	/* trim to fit, so the malloc debugging won't complain */
 	text = dorealloc(text, oldlen + 1, strlen(text) + 1);
 
-	if (tryinclude(p, text)) {
+	if (tryinclude(&lp->current, text)) {
 		dostrfree(text);
 		return;
 	}
-	complain(p, "Illegal #include directive");
-	complain(p, "Before macro expansion: #include %s", line);
-	complain(p, "After macro expansion: #include %s", text);
+	complain(&lp->current, "Illegal #include directive");
+	complain(&lp->current, "Before macro expansion: #include %s", line);
+	complain(&lp->current, "After macro expansion: #include %s", text);
 	dostrfree(text);
 	complain_fail();
 }
 
 static
 void
-d_line(struct place *p, struct place *p2, struct place *np, char *line)
+d_line(struct lineplace *lp, struct place *p2, char *line)
 {
 	char *text;
 	size_t oldlen;
@@ -455,19 +456,19 @@
 			goto illegal_line;
 		}
 	}
-	np->line = atoi(start_lineno);
+	lp->nextline.line = atoi(start_lineno);
 	if (len_filename) {
 		char *filename = dostrndup(start_filename, len_filename);
-		place_setfile(np, filename);
+		place_setfile(&lp->nextline, filename);
 		dostrfree(filename);
 	}
 	dostrfree(text);
 	return;
 
 illegal_line:
-	complain(p, "Illegal #line directive");
-	complain(p, "Before macro expansion: #include %s", line);
-	complain(p, "After macro expansion: #include %s", text);
+	complain(&lp->current, "Illegal #line directive");
+	complain(&lp->current, "Before macro expansion: #include %s", line);
+	complain(&lp->current, "After macro expansion: #include %s", text);
 	dostrfree(text);
 }
 
@@ -476,12 +477,12 @@
 
 static
 void
-d_warning(struct place *p, struct place *p2, struct place *np, char *line)
+d_warning(struct lineplace *lp, struct place *p2, char *line)
 {
 	char *msg;
 
 	msg = macroexpand(p2, line, strlen(line), false);
-	complain(p, "#warning: %s", msg);
+	complain(&lp->current, "#warning: %s", msg);
 	if (mode.werror) {
 		complain_fail();
 	}
@@ -490,12 +491,12 @@
 
 static
 void
-d_error(struct place *p, struct place *p2, struct place *np, char *line)
+d_error(struct lineplace *lp, struct place *p2, char *line)
 {
 	char *msg;
 
 	msg = macroexpand(p2, line, strlen(line), false);
-	complain(p, "#error: %s", msg);
+	complain(&lp->current, "#error: %s", msg);
 	complain_fail();
 	dostrfree(msg);
 }
@@ -505,11 +506,11 @@
 
 static
 void
-d_pragma(struct place *p, struct place *p2, struct place *np, char *line)
+d_pragma(struct lineplace *lp, struct place *p2, char *line)
 {
 	(void)p2;
 
-	complain(p, "#pragma %s", line);
+	complain(&lp->current, "#pragma %s", line);
 	complain_fail();
 }
 
@@ -519,8 +520,7 @@
 static const struct {
 	const char *name;
 	bool ifskip;
-	void (*func)(struct place *, struct place *, struct place *,
-		     char *line);
+	void (*func)(struct lineplace *, struct place *, char *line);
 } directives[] = {
 	{ "define",  true,  d_define },
 	{ "elif",    false, d_elif },
@@ -540,13 +540,13 @@
 
 static
 void
-directive_gotdirective(struct place *p, struct place *np, char *line)
+directive_gotdirective(struct lineplace *lp, char *line)
 {
 	struct place p2;
 	size_t len, skip;
 	unsigned i;
 
-	p2 = *p;
+	p2 = lp->current;
 	for (i=0; i<numdirectives; i++) {
 		len = strlen(directives[i].name);
 		if (!strncmp(line, directives[i].name, len) &&
@@ -563,7 +563,7 @@
 			if (len < strlen(line)) {
 				line[len] = '\0';
 			}
-			directives[i].func(p, &p2, np, line);
+			directives[i].func(lp, &p2, line);
 			return;
 		}
 	}
@@ -574,7 +574,7 @@
 	}
 
 	skip = strcspn(line, ws);
-	complain(p, "Unknown directive #%.*s", (int)skip, line);
+	complain(&lp->current, "Unknown directive #%.*s", (int)skip, line);
 	complain_fail();
 }
 
@@ -583,13 +583,13 @@
  */
 static
 size_t
-directive_scancomments(const struct place *p, char *line, size_t len)
+directive_scancomments(const struct lineplace *lp, char *line, size_t len)
 {
 	size_t pos;
 	bool incomment;
 	struct place p2;
 
-	p2 = *p;
+	p2 = lp->current;
 	incomment = 0;
 	for (pos = 0; pos+1 < len; pos++) {
 		if (line[pos] == '/' && line[pos+1] == '*') {
@@ -625,25 +625,25 @@
 }
 
 void
-directive_gotline(struct place *p, struct place *np, char *line, size_t len)
+directive_gotline(struct lineplace *lp, char *line, size_t len)
 {
 	size_t skip;
 
 	if (warns.nestcomment) {
-		directive_scancomments(p, line, len);
+		directive_scancomments(lp, line, len);
 	}
 
 	/* check if we have a directive line (# exactly in column 0) */
 	if (line[0] == '#') {
 		skip = 1 + strspn(line + 1, ws);
 		assert(skip <= len);
-		p->column += skip;
+		lp->current.column += skip;
 		assert(line[len] == '\0');
-		directive_gotdirective(p, np, line+skip);
-		p->column += len-skip;
+		directive_gotdirective(lp, line+skip /*, length = len-skip */);
+		lp->current.column += len-skip;
 	} else if (ifstate->curtrue) {
-		macro_sendline(p, line, len);
-		p->column += len;
+		macro_sendline(&lp->current, line, len);
+		lp->current.column += len;
 	}
 }