forked from Mirrors/tinycc
cleanup: stop abuse of sym->c for #define tokenstreams
parent
d0b432ab38
commit
bed17847bd
3
libtcc.c
3
libtcc.c
|
@ -1059,6 +1059,9 @@ static Sym *sym_push2(Sym **ps, int v, int t, long c)
|
||||||
s = sym_malloc();
|
s = sym_malloc();
|
||||||
s->v = v;
|
s->v = v;
|
||||||
s->type.t = t;
|
s->type.t = t;
|
||||||
|
#ifdef _WIN64
|
||||||
|
s->d = NULL;
|
||||||
|
#endif
|
||||||
s->c = c;
|
s->c = c;
|
||||||
s->next = NULL;
|
s->next = NULL;
|
||||||
/* add in stack */
|
/* add in stack */
|
||||||
|
|
5
tcc.h
5
tcc.h
|
@ -198,7 +198,10 @@ typedef struct SValue {
|
||||||
typedef struct Sym {
|
typedef struct Sym {
|
||||||
int v; /* symbol token */
|
int v; /* symbol token */
|
||||||
long r; /* associated register */
|
long r; /* associated register */
|
||||||
long c; /* associated number */
|
union {
|
||||||
|
long c; /* associated number */
|
||||||
|
int *d; /* define token stream */
|
||||||
|
};
|
||||||
CType type; /* associated type */
|
CType type; /* associated type */
|
||||||
struct Sym *next; /* next related symbol */
|
struct Sym *next; /* next related symbol */
|
||||||
struct Sym *prev; /* prev symbol in stack */
|
struct Sym *prev; /* prev symbol in stack */
|
||||||
|
|
18
tccpp.c
18
tccpp.c
|
@ -860,7 +860,8 @@ static inline void define_push(int v, int macro_type, int *str, Sym *first_arg)
|
||||||
{
|
{
|
||||||
Sym *s;
|
Sym *s;
|
||||||
|
|
||||||
s = sym_push2(&define_stack, v, macro_type, (long)str);
|
s = sym_push2(&define_stack, v, macro_type, 0);
|
||||||
|
s->d = str;
|
||||||
s->next = first_arg;
|
s->next = first_arg;
|
||||||
table_ident[v - TOK_IDENT]->sym_define = s;
|
table_ident[v - TOK_IDENT]->sym_define = s;
|
||||||
}
|
}
|
||||||
|
@ -893,8 +894,8 @@ static void free_defines(Sym *b)
|
||||||
while (top != b) {
|
while (top != b) {
|
||||||
top1 = top->prev;
|
top1 = top->prev;
|
||||||
/* do not free args or predefined defines */
|
/* do not free args or predefined defines */
|
||||||
if (top->c)
|
if (top->d)
|
||||||
tok_str_free((int *)top->c);
|
tok_str_free(top->d);
|
||||||
v = top->v;
|
v = top->v;
|
||||||
if (v >= TOK_IDENT && v < tok_ident)
|
if (v >= TOK_IDENT && v < tok_ident)
|
||||||
table_ident[v - TOK_IDENT]->sym_define = NULL;
|
table_ident[v - TOK_IDENT]->sym_define = NULL;
|
||||||
|
@ -2364,7 +2365,7 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args)
|
||||||
s = sym_find2(args, t);
|
s = sym_find2(args, t);
|
||||||
if (s) {
|
if (s) {
|
||||||
cstr_new(&cstr);
|
cstr_new(&cstr);
|
||||||
st = (int *)s->c;
|
st = s->d;
|
||||||
spc = 0;
|
spc = 0;
|
||||||
while (*st) {
|
while (*st) {
|
||||||
TOK_GET(t, st, cval);
|
TOK_GET(t, st, cval);
|
||||||
|
@ -2386,7 +2387,7 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args)
|
||||||
} else if (t >= TOK_IDENT) {
|
} else if (t >= TOK_IDENT) {
|
||||||
s = sym_find2(args, t);
|
s = sym_find2(args, t);
|
||||||
if (s) {
|
if (s) {
|
||||||
st = (int *)s->c;
|
st = s->d;
|
||||||
/* if '##' is present before or after, no arg substitution */
|
/* if '##' is present before or after, no arg substitution */
|
||||||
if (*macro_str == TOK_TWOSHARPS || last_tok == TOK_TWOSHARPS) {
|
if (*macro_str == TOK_TWOSHARPS || last_tok == TOK_TWOSHARPS) {
|
||||||
/* special case for var arg macros : ## eats the
|
/* special case for var arg macros : ## eats the
|
||||||
|
@ -2487,7 +2488,7 @@ static int macro_subst_tok(TokenString *tok_str,
|
||||||
tok_str_add2(tok_str, t1, &cval);
|
tok_str_add2(tok_str, t1, &cval);
|
||||||
cstr_free(&cstr);
|
cstr_free(&cstr);
|
||||||
} else {
|
} else {
|
||||||
mstr = (int *)s->c;
|
mstr = s->d;
|
||||||
mstr_allocated = 0;
|
mstr_allocated = 0;
|
||||||
if (s->type.t == MACRO_FUNC) {
|
if (s->type.t == MACRO_FUNC) {
|
||||||
/* NOTE: we do not use next_nomacro to avoid eating the
|
/* NOTE: we do not use next_nomacro to avoid eating the
|
||||||
|
@ -2552,7 +2553,8 @@ static int macro_subst_tok(TokenString *tok_str,
|
||||||
}
|
}
|
||||||
str.len -= spc;
|
str.len -= spc;
|
||||||
tok_str_add(&str, 0);
|
tok_str_add(&str, 0);
|
||||||
sym_push2(&args, sa->v & ~SYM_FIELD, sa->type.t, (long)str.str);
|
sa1 = sym_push2(&args, sa->v & ~SYM_FIELD, sa->type.t, 0);
|
||||||
|
sa1->d = str.str;
|
||||||
sa = sa->next;
|
sa = sa->next;
|
||||||
if (tok == ')') {
|
if (tok == ')') {
|
||||||
/* special case for gcc var args: add an empty
|
/* special case for gcc var args: add an empty
|
||||||
|
@ -2577,7 +2579,7 @@ static int macro_subst_tok(TokenString *tok_str,
|
||||||
sa = args;
|
sa = args;
|
||||||
while (sa) {
|
while (sa) {
|
||||||
sa1 = sa->prev;
|
sa1 = sa->prev;
|
||||||
tok_str_free((int *)sa->c);
|
tok_str_free(sa->d);
|
||||||
sym_free(sa);
|
sym_free(sa);
|
||||||
sa = sa1;
|
sa = sa1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue