1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:34:39 -07:00

runtime: handle string + char literals in goc2c

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
This commit is contained in:
Russ Cox 2011-08-31 07:11:31 -04:00
parent 4304de6e0c
commit 5f40c5b384

View File

@ -196,13 +196,14 @@ getchar_skipping_comments(void)
} }
/* /*
* Read and return a token. Tokens are delimited by whitespace or by * Read and return a token. Tokens are string or character literals
* [(),{}]. The latter are all returned as single characters. * or else delimited by whitespace or by [(),{}].
* The latter are all returned as single characters.
*/ */
static char * static char *
read_token(void) read_token(void)
{ {
int c; int c, q;
char *buf; char *buf;
unsigned int alc, off; unsigned int alc, off;
const char* delims = "(),{}"; const char* delims = "(),{}";
@ -217,7 +218,26 @@ read_token(void)
alc = 16; alc = 16;
buf = xmalloc(alc + 1); buf = xmalloc(alc + 1);
off = 0; 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; buf[off] = c;
++off; ++off;
} else { } else {