~mcf/cproc

6400c868e2b320cac821581ed4bc6a65e2a216fc — Michael Forney 1 year, 5 months ago 2afeff7
Implement prefixed character constants
3 files changed, 12 insertions(+), 3 deletions(-)

M cc.h
M expr.c
M targ.c
M cc.h => cc.h +1 -0
@@ 410,6 410,7 @@ extern struct type typevalist, typevalistptr;

struct target {
	const char *name;
	struct type *typewchar;
};

extern struct target *targ;

M expr.c => expr.c +9 -3
@@ 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();

M targ.c => targ.c +2 -0
@@ 8,9 8,11 @@ struct target *targ;
static struct target alltargs[] = {
	{
		.name = "x86_64",
		.typewchar = &typeint,
	},
	{
		.name = "aarch64",
		.typewchar = &typeuint,
	},
};