cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 6400c868e2b320cac821581ed4bc6a65e2a216fc
parent 2afeff7d9e6a0a735f80bae9e932df376bc42590
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 25 Jun 2019 12:26:26 -0700

Implement prefixed character constants

Diffstat:
Mcc.h | 1+
Mexpr.c | 12+++++++++---
Mtarg.c | 2++
3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/cc.h b/cc.h @@ -410,6 +410,7 @@ extern struct type typevalist, typevalistptr; struct target { const char *name; + struct type *typewchar; }; extern struct target *targ; diff --git a/expr.c b/expr.c @@ -415,6 +415,7 @@ primaryexpr(struct scope *s) { struct expr *e; struct decl *d; + struct type *t; char *src, *dst, *end; int base; @@ -453,10 +454,15 @@ primaryexpr(struct scope *s) break; case TCHARCONST: src = tok.lit; - if (*src != '\'') - fatal("wide character constant not yet implemented"); + t = &typeint; + switch (*src) { + case 'L': ++src; t = targ->typewchar; break; + case 'u': ++src; t = &typeushort; break; + case 'U': ++src; t = &typeuint; break; + } + assert(*src == '\''); ++src; - e = mkconstexpr(&typeint, unescape(&src)); + e = mkconstexpr(t, unescape(&src)); if (*src != '\'') error(&tok.loc, "character constant contains more than one character: %c", *src); next(); diff --git a/targ.c b/targ.c @@ -8,9 +8,11 @@ struct target *targ; static struct target alltargs[] = { { .name = "x86_64", + .typewchar = &typeint, }, { .name = "aarch64", + .typewchar = &typeuint, }, };