diff dmd2/lexer.c @ 847:356e65836fb5

Merged DMD 2.021 frontend. Removed generated files from dmd/dmd2 dirs.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 13 Dec 2008 16:14:37 +0100
parents f04dde6e882c
children 638d16625da2
line wrap: on
line diff
--- a/dmd2/lexer.c	Sat Dec 13 13:15:31 2008 +0100
+++ b/dmd2/lexer.c	Sat Dec 13 16:14:37 2008 +0100
@@ -2656,10 +2656,13 @@
 
 void Lexer::getDocComment(Token *t, unsigned lineComment)
 {
-    OutBuffer buf;
+    /* ct tells us which kind of comment it is: '/', '*', or '+'
+     */
     unsigned char ct = t->ptr[2];
+
+    /* Start of comment text skips over / * *, / + +, or / / /
+     */
     unsigned char *q = t->ptr + 3;	// start of comment text
-    int linestart = 0;
 
     unsigned char *qend = p;
     if (ct == '*' || ct == '+')
@@ -2684,6 +2687,12 @@
 	}
     }
 
+    /* Comment is now [q .. qend].
+     * Canonicalize it into buf[].
+     */
+    OutBuffer buf;
+    int linestart = 0;
+
     for (; q < qend; q++)
     {
 	unsigned char c = *q;
@@ -2760,11 +2769,14 @@
 }
 
 /********************************************
- * Combine two document comments into one.
+ * Combine two document comments into one,
+ * separated by a newline.
  */
 
 unsigned char *Lexer::combineComments(unsigned char *c1, unsigned char *c2)
 {
+    //printf("Lexer::combineComments('%s', '%s')\n", c1, c2);
+
     unsigned char *c = c2;
 
     if (c1)
@@ -2775,9 +2787,12 @@
 
 	    c = (unsigned char *)mem.malloc(len1 + 1 + len2 + 1);
 	    memcpy(c, c1, len1);
-	    c[len1] = '\n';
-	    memcpy(c + len1 + 1, c2, len2);
-	    c[len1 + 1 + len2] = 0;
+	    if (len1 && c1[len1 - 1] != '\n')
+	    {	c[len1] = '\n';
+		len1++;
+	    }
+	    memcpy(c + len1, c2, len2);
+	    c[len1 + len2] = 0;
 	}
     }
     return c;
@@ -2912,7 +2927,6 @@
     {	"static",	TOKstatic	},
     {	"final",	TOKfinal	},
     {	"const",	TOKconst	},
-    {	"immutable",	TOKimmutable	},
     {	"typedef",	TOKtypedef	},
     {	"alias",	TOKalias	},
     {	"override",	TOKoverride	},
@@ -2952,6 +2966,7 @@
     {	"__FILE__",	TOKfile		},
     {	"__LINE__",	TOKline		},
     {	"shared",	TOKshared	},
+    {	"immutable",	TOKimmutable	},
 #endif
 };