scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 4eff786be3921ff7e1fc90b57e7f0a8932a1fda1
parent 56004d247cb4b3fde3efb52717d570864af2c073
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 16 Jan 2017 13:31:48 +0100

[cc1] Fix character constants in macros

Character tokens were not taking a correct yytext, which
was generating a problem in getdefs() because this function
is based in taking the text of the tokens from yytext.

Diffstat:
Mcc1/cpp.c | 10+++++++---
Mcc1/lex.c | 8+++++++-
2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -182,11 +182,10 @@ parsepars(char *buffer, char **listp, int nargs) return 1; } -/* FIXME: characters in the definition break the macro definition */ static size_t copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[]) { - char prevc, c, *p, *arg, *bp = buffer; + char delim, prevc, c, *p, *arg, *bp = buffer; size_t size; for (prevc = '\0'; c = *s; prevc = c, ++s) { @@ -198,8 +197,13 @@ copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[]) ++s; case '#': break; + case '\'': + delim = '\''; + goto search_delim; case '\"': - for (p = s; *++s != '"'; ) + delim = '"'; + search_delim: + for (p = s; *++s != delim; ) /* nothing */; size = s - p + 1; if (size > bufsiz) diff --git a/cc1/lex.c b/cc1/lex.c @@ -467,9 +467,11 @@ escape(void) static unsigned character(void) { - static char c; + char c, *p; Symbol *sym; + size_t size; + p = input->p; if ((c = *++input->p) == '\\') c = escape(); else @@ -480,6 +482,10 @@ character(void) else ++input->p; + size = input->p - p; + memcpy(yytext, p, size); + yytext[size] = '\0'; + sym = newsym(NS_IDEN, NULL); sym->u.i = c; sym->type = inttype;