]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: handle string + char literals in goc2c
authorRuss Cox <rsc@golang.org>
Wed, 31 Aug 2011 11:11:31 +0000 (07:11 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 31 Aug 2011 11:11:31 +0000 (07:11 -0400)
My string literal was being rewritten from
"runtime.SysReserve(%p, %D) = error %d"
to
"runtime.SysReserve ( %p , %D ) = error %d"

R=iant
CC=golang-dev
https://golang.org/cl/4972051

src/pkg/runtime/goc2c.c

index 61236e226f5bb0dc2339b6174c2026f33222a09b..fcac9c0600a7fe34eba11112b33229116b4c7e87 100644 (file)
@@ -196,13 +196,14 @@ getchar_skipping_comments(void)
 }
 
 /*
- * Read and return a token.  Tokens are delimited by whitespace or by
- * [(),{}].  The latter are all returned as single characters.
+ * Read and return a token.  Tokens are string or character literals
+ * or else delimited by whitespace or by [(),{}].
+ * The latter are all returned as single characters.
  */
 static char *
 read_token(void)
 {
-       int c;
+       int c, q;
        char *buf;
        unsigned int alc, off;
        const char* delims = "(),{}";
@@ -217,7 +218,26 @@ read_token(void)
        alc = 16;
        buf = xmalloc(alc + 1);
        off = 0;
-       if (strchr(delims, c) != NULL) {
+       if(c == '"' || c == '\'') {
+               q = c;
+               buf[off] = c;
+               ++off;
+               while (1) {
+                       if (off+2 >= alc) { // room for c and maybe next char
+                               alc *= 2;
+                               buf = xrealloc(buf, alc + 1);
+                       }
+                       c = getchar_no_eof();
+                       buf[off] = c;
+                       ++off;
+                       if(c == q)
+                               break;
+                       if(c == '\\') {
+                               buf[off] = getchar_no_eof();
+                               ++off;
+                       }
+               }
+       } else if (strchr(delims, c) != NULL) {
                buf[off] = c;
                ++off;
        } else {