summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-08-31 07:11:31 -0400
committerRuss Cox <rsc@golang.org>2011-08-31 07:11:31 -0400
commitbe4b94ca9da97cda58451ae4225529ca859b7e88 (patch)
tree951c266534a99233fd86bf92f48c82278259eabb
parentdceda39b97d1066da7caea11c0256151cded5141 (diff)
downloadgo-be4b94ca9da97cda58451ae4225529ca859b7e88.tar.gz
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 http://codereview.appspot.com/4972051
-rw-r--r--src/pkg/runtime/goc2c.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/pkg/runtime/goc2c.c b/src/pkg/runtime/goc2c.c
index 61236e226..fcac9c060 100644
--- a/src/pkg/runtime/goc2c.c
+++ b/src/pkg/runtime/goc2c.c
@@ -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 {