fixed __LINE__ token type

This commit is contained in:
bellard 2004-10-07 20:15:50 +00:00
parent ec7d36326d
commit c50af8399d

17
tcc.c
View file

@ -645,7 +645,7 @@ static char tok_two_chars[] = "<=\236>=\235!=\225&&\240||\241++\244--\242==\224<
#define TOK_ASM_int TOK_INT #define TOK_ASM_int TOK_INT
enum { enum tcc_token {
TOK_LAST = TOK_IDENT - 1, TOK_LAST = TOK_IDENT - 1,
#define DEF(id, str) id, #define DEF(id, str) id,
#include "tcctok.h" #include "tcctok.h"
@ -3808,26 +3808,27 @@ static int macro_subst_tok(TokenString *tok_str,
Sym **nested_list, Sym *s, int can_read_stream) Sym **nested_list, Sym *s, int can_read_stream)
{ {
Sym *args, *sa, *sa1; Sym *args, *sa, *sa1;
int mstr_allocated, parlevel, *mstr, t; int mstr_allocated, parlevel, *mstr, t, t1;
TokenString str; TokenString str;
char *cstrval; char *cstrval;
CValue cval; CValue cval;
CString cstr; CString cstr;
char buf[32];
/* if symbol is a macro, prepare substitution */ /* if symbol is a macro, prepare substitution */
/* special macros */ /* special macros */
if (tok == TOK___LINE__) { if (tok == TOK___LINE__) {
cval.i = file->line_num; snprintf(buf, sizeof(buf), "%d", file->line_num);
tok_str_add2(tok_str, TOK_CINT, &cval); cstrval = buf;
t1 = TOK_PPNUM;
goto add_cstr1;
} else if (tok == TOK___FILE__) { } else if (tok == TOK___FILE__) {
cstrval = file->filename; cstrval = file->filename;
goto add_cstr; goto add_cstr;
tok_str_add2(tok_str, TOK_STR, &cval);
} else if (tok == TOK___DATE__ || tok == TOK___TIME__) { } else if (tok == TOK___DATE__ || tok == TOK___TIME__) {
time_t ti; time_t ti;
struct tm *tm; struct tm *tm;
char buf[64];
time(&ti); time(&ti);
tm = localtime(&ti); tm = localtime(&ti);
@ -3840,11 +3841,13 @@ static int macro_subst_tok(TokenString *tok_str,
} }
cstrval = buf; cstrval = buf;
add_cstr: add_cstr:
t1 = TOK_STR;
add_cstr1:
cstr_new(&cstr); cstr_new(&cstr);
cstr_cat(&cstr, cstrval); cstr_cat(&cstr, cstrval);
cstr_ccat(&cstr, '\0'); cstr_ccat(&cstr, '\0');
cval.cstr = &cstr; cval.cstr = &cstr;
tok_str_add2(tok_str, TOK_STR, &cval); tok_str_add2(tok_str, t1, &cval);
cstr_free(&cstr); cstr_free(&cstr);
} else { } else {
mstr = (int *)s->c; mstr = (int *)s->c;