authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-08 23:40:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-08 23:40:39-05:00
log85d23e68eecc8b2af89a3836296ac0689ec7a5b9
tree242fcbc0d84a0ba155a7b13833114948e21d893e
parent91955dee587214722daa09e6f3dbff059ac3752e

fix .d file parsing and string literal ast rendering


2 files changed, 6 insertions(+), 5 deletions(-)

src/ast_render.cpp+4-4
...@@ -317,7 +317,7 @@ static bool is_digit(uint8_t c) {...@@ -317,7 +317,7 @@ static bool is_digit(uint8_t c) {
317317
318static bool is_printable(uint8_t c) {318static bool is_printable(uint8_t c) {
319 static const uint8_t printables[] =319 static const uint8_t printables[] =
320 " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.~`!@#$%^&*()_-+=\\{}[];'\"?/<>,";320 " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.~`!@#$%^&*()_-+=\\{}[];'\"?/<>,:";
321 for (size_t i = 0; i < array_length(printables); i += 1) {321 for (size_t i = 0; i < array_length(printables); i += 1) {
322 if (c == printables[i]) return true;322 if (c == printables[i]) return true;
323 }323 }
...@@ -328,9 +328,7 @@ static void string_literal_escape(Buf *source, Buf *dest) {...@@ -328,9 +328,7 @@ static void string_literal_escape(Buf *source, Buf *dest) {
328 buf_resize(dest, 0);328 buf_resize(dest, 0);
329 for (size_t i = 0; i < buf_len(source); i += 1) {329 for (size_t i = 0; i < buf_len(source); i += 1) {
330 uint8_t c = *((uint8_t*)buf_ptr(source) + i);330 uint8_t c = *((uint8_t*)buf_ptr(source) + i);
331 if (is_printable(c)) {331 if (c == '\'') {
332 buf_append_char(dest, c);
333 } else if (c == '\'') {
334 buf_append_str(dest, "\\'");332 buf_append_str(dest, "\\'");
335 } else if (c == '"') {333 } else if (c == '"') {
336 buf_append_str(dest, "\\\"");334 buf_append_str(dest, "\\\"");
...@@ -350,6 +348,8 @@ static void string_literal_escape(Buf *source, Buf *dest) {...@@ -350,6 +348,8 @@ static void string_literal_escape(Buf *source, Buf *dest) {
350 buf_append_str(dest, "\\t");348 buf_append_str(dest, "\\t");
351 } else if (c == '\v') {349 } else if (c == '\v') {
352 buf_append_str(dest, "\\v");350 buf_append_str(dest, "\\v");
351 } else if (is_printable(c)) {
352 buf_append_char(dest, c);
353 } else {353 } else {
354 buf_appendf(dest, "\\x%x", (int)c);354 buf_appendf(dest, "\\x%x", (int)c);
355 }355 }
src/cache_hash.cpp+2-1
...@@ -472,10 +472,11 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {...@@ -472,10 +472,11 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
472 }472 }
473 } else {473 } else {
474 // sometimes there are multiple files on the same line; we actually need space tokenization.474 // sometimes there are multiple files on the same line; we actually need space tokenization.
475 SplitIterator line_it = memSplit(opt_line.value, str(" \t\\"));475 SplitIterator line_it = memSplit(opt_line.value, str(" \t"));
476 Slice<uint8_t> filename;476 Slice<uint8_t> filename;
477 while (SplitIterator_next(&line_it).unwrap(&filename)) {477 while (SplitIterator_next(&line_it).unwrap(&filename)) {
478 Buf *filename_buf = buf_create_from_slice(filename);478 Buf *filename_buf = buf_create_from_slice(filename);
479 if (buf_eql_str(filename_buf, "\\")) continue;
479 if ((err = cache_add_file(ch, filename_buf))) {480 if ((err = cache_add_file(ch, filename_buf))) {
480 if (verbose) {481 if (verbose) {
481 fprintf(stderr, "unable to add %s to cache: %s\n", buf_ptr(filename_buf), err_str(err));482 fprintf(stderr, "unable to add %s to cache: %s\n", buf_ptr(filename_buf), err_str(err));