From 4c90c650131ea141bf6a9319604716ce4b2abd49 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Thu, 17 Jun 2010 18:25:50 +0430 Subject: [PATCH] let tok_num() return the bt --- ncc.c | 6 ++++-- tok.c | 19 +++++++++++++++---- tok.h | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ncc.c b/ncc.c index 330a474..17a7806 100644 --- a/ncc.c +++ b/ncc.c @@ -511,8 +511,10 @@ static void readprimary(void) { int i; if (!tok_jmp(TOK_NUM)) { - ts_push_bt(4 | BT_SIGNED); - o_num(tok_num(), 4 | BT_SIGNED); + long n; + int bt = tok_num(&n); + ts_push_bt(bt); + o_num(n, bt); return; } if (!tok_jmp(TOK_STR)) { diff --git a/tok.c b/tok.c index 473b4a1..76acb04 100644 --- a/tok.c +++ b/tok.c @@ -2,6 +2,7 @@ #include #include #include +#include "gen.h" #include "tok.h" extern int cpp_read(char *s); @@ -95,15 +96,18 @@ static int esc_char(int *c, char *s) } static long num; +static int num_bt; -long tok_num(void) +int tok_num(long *n) { - return num; + *n = num; + return num_bt; } static void readnum(void) { int base = 10; + num_bt = 4 | BT_SIGNED; if (buf[cur] == '0' && buf[cur + 1] == 'x') { base = 16; cur += 2; @@ -119,9 +123,16 @@ static void readnum(void) cur++; } num = result; - while (cur < len && tolower(buf[cur]) == 'u' || - tolower(buf[cur]) == 'l') + while (cur < len) { + int c = tolower(buf[cur]); + if (c != 'u' && c != 'l') + break; + if (c == 'u') + num_bt &= ~BT_SIGNED; + if (c == 'l') + num_bt = (num_bt & BT_SIGNED) | 8; cur++; + } return; } if (buf[cur] == '\'') { diff --git a/tok.h b/tok.h index 4e6b033..8b1d297 100644 --- a/tok.h +++ b/tok.h @@ -42,7 +42,7 @@ void tok_init(char *path); int tok_see(void); int tok_get(void); char *tok_id(void); -long tok_num(void); +int tok_num(long *n); int tok_str(char *out); long tok_addr(void); void tok_jump(long addr); -- 2.11.4.GIT