harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 760442a0e917c516282418074a9d584a1ff71df5
parent 0e7cb88592e1ec0fbb322e0e239a6b4535cbc374
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 16 Feb 2021 16:25:46 -0500

typedefs: emit str constants

Diffstat:
Msrc/typedef.c | 14+++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/typedef.c b/src/typedef.c @@ -1,4 +1,5 @@ #include <assert.h> +#include <ctype.h> #include <inttypes.h> #include <stdio.h> #include <stdlib.h> @@ -92,11 +93,22 @@ emit_const(const struct expression *expr, FILE *out) case TYPE_STORAGE_RUNE: fprintf(out, "\'\\U%08" PRIx32 "\'", (uint32_t)val->uval); break; + case TYPE_STORAGE_STRING: + fprintf(out, "\""); + for (size_t i = 0; i < val->string.len; i += 1) { + char c = val->string.value[i]; + if (isalnum(c)) { + fprintf(out, "%c", c); + } else { + fprintf(out, "\\x%02X", c); + } + }; + fprintf(out, "\""); + break; case TYPE_STORAGE_ALIAS: case TYPE_STORAGE_ARRAY: case TYPE_STORAGE_ENUM: case TYPE_STORAGE_SLICE: - case TYPE_STORAGE_STRING: case TYPE_STORAGE_STRUCT: case TYPE_STORAGE_TUPLE: case TYPE_STORAGE_UNION: