fixed macro bug and dummy float constant parsing

tcc-xref
bellard 2001-12-13 23:20:55 +00:00
parent 25618c0430
commit cb44835e94
1 changed files with 27 additions and 8 deletions

35
tcc.c
View File

@ -316,6 +316,10 @@ enum {
TOK_MAIN, TOK_MAIN,
}; };
/* XXX: need to define this to use them in non ISOC99 context */
extern float strtof (const char *__nptr, char **__endptr);
extern long double strtold (const char *__nptr, char **__endptr);
void sum(int l); void sum(int l);
void next(void); void next(void);
void next_nomacro(void); void next_nomacro(void);
@ -894,7 +898,7 @@ int expr_preprocess(void)
return c != 0; return c != 0;
} }
#ifdef DEBUG #if defined(DEBUG)
void tok_print(int *str) void tok_print(int *str)
{ {
int t; int t;
@ -1007,6 +1011,11 @@ void preprocess()
strcpy(buf, get_tok_str(tok, &tokc)); strcpy(buf, get_tok_str(tok, &tokc));
c = '\"'; c = '\"';
} }
/* eat all spaces and comments after include */
/* XXX: slightly incorrect */
while (ch1 != '\n' && ch1 != -1)
inp();
if (include_stack_ptr >= include_stack + INCLUDE_STACK_SIZE) if (include_stack_ptr >= include_stack + INCLUDE_STACK_SIZE)
error("memory full"); error("memory full");
if (c == '\"') { if (c == '\"') {
@ -1389,12 +1398,10 @@ void parse_number(void)
if (t == 'F') { if (t == 'F') {
cinp(); cinp();
tok = TOK_CFLOAT; tok = TOK_CFLOAT;
/* XXX: this is an ISOC99 function */
cval.f = strtof(token_buf, NULL); cval.f = strtof(token_buf, NULL);
} else if (t == 'L') { } else if (t == 'L') {
cinp(); cinp();
tok = TOK_CLDOUBLE; tok = TOK_CLDOUBLE;
/* XXX: this is an ISOC99 function */
cval.ld = strtold(token_buf, NULL); cval.ld = strtold(token_buf, NULL);
} else { } else {
tok = TOK_CDOUBLE; tok = TOK_CDOUBLE;
@ -1638,7 +1645,7 @@ int *macro_twosharps(int *macro_str)
next_nomacro(); next_nomacro();
if (tok == 0) if (tok == 0)
break; break;
if (*macro_ptr == TOK_TWOSHARPS) { while (*macro_ptr == TOK_TWOSHARPS) {
macro_ptr++; macro_ptr++;
macro_ptr1 = macro_ptr; macro_ptr1 = macro_ptr;
t = *macro_ptr; t = *macro_ptr;
@ -1654,16 +1661,16 @@ int *macro_twosharps(int *macro_str)
p = get_tok_str(t, &cval); p = get_tok_str(t, &cval);
strcat(token_buf, p); strcat(token_buf, p);
ts = tok_alloc(token_buf, 0); ts = tok_alloc(token_buf, 0);
tok_add(&macro_str1, &macro_str1_len, ts->tok); tok = ts->tok; /* modify current token */
} else { } else {
/* cannot merge tokens: skip '##' */ /* cannot merge tokens: skip '##' */
macro_ptr = macro_ptr1; macro_ptr = macro_ptr1;
break;
}
} }
} }
} else {
tok_add2(&macro_str1, &macro_str1_len, tok, &tokc); tok_add2(&macro_str1, &macro_str1_len, tok, &tokc);
} }
}
tok_add(&macro_str1, &macro_str1_len, 0); tok_add(&macro_str1, &macro_str1_len, 0);
return macro_str1; return macro_str1;
} }
@ -2842,7 +2849,19 @@ void unary(void)
GFuncContext gf; GFuncContext gf;
if (tok == TOK_NUM || tok == TOK_CCHAR || tok == TOK_LCHAR) { if (tok == TOK_NUM || tok == TOK_CCHAR || tok == TOK_LCHAR) {
vset(VT_CONST, tokc.i); vset(VT_CONST | VT_INT, tokc.i);
next();
} else if (tok == TOK_CFLOAT) {
/* currently, cannot do more */
vset(VT_CONST | VT_FLOAT, 0);
next();
} else if (tok == TOK_CDOUBLE) {
/* currently, cannot do more */
vset(VT_CONST | VT_DOUBLE, 0);
next();
} else if (tok == TOK_CLDOUBLE) {
/* currently, cannot do more */
vset(VT_CONST | VT_LDOUBLE, 0);
next(); next();
} else if (tok == TOK___FUNC__) { } else if (tok == TOK___FUNC__) {
/* special function name identifier */ /* special function name identifier */