changeset 77:123168887da8

Clean out old not-really-working nested comment handling.
author David A. Holland
date Mon, 10 Jun 2013 20:12:37 -0400
parents 7dba4436cff9
children 4cc1c575951f
files directive.c
diffstat 1 files changed, 26 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/directive.c	Mon Jun 10 19:57:28 2013 -0400
+++ b/directive.c	Mon Jun 10 20:12:37 2013 -0400
@@ -50,7 +50,6 @@
 };
 
 static struct ifstate *ifstate;
-static bool in_multiline_comment;
 
 ////////////////////////////////////////////////////////////
 // common parsing bits
@@ -468,142 +467,69 @@
 }
 
 /*
- * If desired, warn about a nested comment. The comment begins at
- * offset POS from the place P.
- */
-static
-void
-warn_nestcomment(const struct place *p, size_t pos)
-{
-	struct place p2;
-
-	if (warns.nestcomment) {
-		p2 = *p;
-		p2.column += pos;
-		complain(p, "Warning: %c%c within comment",
-			 '/', '*');
-		if (mode.werror) {
-			complain_failed();
-		}
-	}
-}
-
-/*
- * Check for comment delimiters in LINE. If a multi-line comment is
- * continuing or ending, set ACOMM to its length. If a multi-line
- * comment is starting, set BCOMM to its length. Set TEXT to the
- * length of text that is not commented out, or that contains comments
- * that both begin and end on this line. ACOMM + TEXT + BCOMM == LEN.
- *
- * Updates in_multiline_comment to the appropriate state for after
- * this line is handled.
+ * Check for nested comment delimiters in LINE.
  */
 static
 size_t
-directive_scancomments(const struct place *p, char *line, size_t len,
-		       size_t *acomm, size_t *text, size_t *bcomm)
+directive_scancomments(const struct place *p, char *line, size_t len)
 {
 	size_t pos;
-	size_t first_commentend;
-	size_t last_commentstart;
 	bool incomment;
+	struct place p2;
 
-	first_commentend = len;
-	last_commentstart = len;
-	incomment = in_multiline_comment;
+	p2 = *p;
+	incomment = 0;
 	for (pos = 0; pos+1 < len; pos++) {
 		if (line[pos] == '/' && line[pos+1] == '*') {
 			if (incomment) {
-				warn_nestcomment(p, pos);
+				complain(&p2, "Warning: %c%c within comment",
+					 '/', '*');
+				if (mode.werror) {
+					complain_failed();
+				}
 			} else {
 				incomment = true;
-				last_commentstart = pos;
 			}
 		} else if (line[pos] == '*' && line[pos+1] == '/') {
 			if (incomment) {
 				incomment = false;
-				if (first_commentend == len) {
-					first_commentend = pos;
-				}
-				last_commentstart = len;
 			} else {
 				/* stray end-comment; should we care? */
 			}
 		}
+		if (line[pos] == '\n') {
+			p2.line++;
+			p2.column = 0;
+		} else {
+			p2.column++;
+		}
 	}
 
-	if (in_multiline_comment && first_commentend < last_commentstart) {
-		/* multiline comment ends */
-		/* first_commentend points to the star, adjust */
-		*acomm = first_commentend + 2;
-		*text = len - *acomm;
-	} else if (in_multiline_comment) {
-		/* comment did not end, so another one cannot have started */
-		assert(last_commentstart == len);
-		*acomm = len;
-		*text = 0;
-	} else {
-		*acomm = 0;
-		*text = len;
-	}
-
-	*bcomm = len - last_commentstart;
-	*text -= *bcomm;
-
-	in_multiline_comment = incomment;
+	/* multiline comments are supposed to arrive in a single buffer */
+	assert(!incomment);
 	return len;
 }
 
 void
 directive_gotline(struct place *p, char *line, size_t len)
 {
-	size_t acomm;	/* length of comment ending on this line */
-	size_t text;	/* length of non-multi-line-comment text */
-	size_t bcomm;	/* length of comment beginning on this line */
 	size_t skip;
 
-	directive_scancomments(p, line, len, &acomm, &text, &bcomm);
-
-	if (acomm > 0) {
-		if (mode.output_retain_comments && ifstate->curtrue) {
-			/*
-			 * Do not expand the comment; send it straight
-			 * to the output. This will cause it to appear
-			 * first if we're partway through collecting a
-			 * macro argument. Too bad. This isn't a
-			 * standard mode anyway.
-			 */
-			output(p, line, acomm);
-		}
-		p->column += acomm;
+	if (warns.nestcomment) {
+		directive_scancomments(p, line, len);
 	}
 
 	/* check if we have a directive line (# exactly in column 0) */
-	if (acomm == 0 && line[0] == '#') {
-		char ch;
-
+	if (line[0] == '#') {
 		skip = 1 + strspn(line + 1, ws);
-		assert(skip <= text);
+		assert(skip <= len);
 		p->column += skip;
 		assert(line[len] == '\0');
-		/* ensure null termination for directives */
-		ch = line[text];
-		if (ch != '\0') {
-			line[text] = '\0';
-		}
-		directive_gotdirective(p, line+skip /*, length = text-skip */);
-		line[text] = ch;
-		p->column += text-skip;
+		directive_gotdirective(p, line+skip /*, length = len-skip */);
+		p->column += len-skip;
 	} else if (ifstate->curtrue) {
-		macro_sendline(p, line + acomm, text);
-		p->column += text;
-	}
-
-	if (bcomm > 0) {
-		if (mode.output_retain_comments && ifstate->curtrue) {
-			output(p, line + acomm + text, bcomm);
-		}
-		p->column += bcomm;
+		macro_sendline(p, line, len);
+		p->column += len;
 	}
 }