mirror of https://github.com/rui314/chibicc
Expand macros in the #if and #elif argument context
This commit is contained in:
parent
9ad60e41d5
commit
2651448084
|
@ -20,6 +20,8 @@ struct CondIncl {
|
|||
static Macro *macros;
|
||||
static CondIncl *cond_incl;
|
||||
|
||||
static Token *preprocess2(Token *tok);
|
||||
|
||||
static bool is_hash(Token *tok) {
|
||||
return tok->at_bol && equal(tok, "#");
|
||||
}
|
||||
|
@ -113,6 +115,7 @@ static Token *copy_line(Token **rest, Token *tok) {
|
|||
static long eval_const_expr(Token **rest, Token *tok) {
|
||||
Token *start = tok;
|
||||
Token *expr = copy_line(rest, tok->next);
|
||||
expr = preprocess2(expr);
|
||||
|
||||
if (expr->kind == TK_EOF)
|
||||
error_tok(start, "no expression");
|
||||
|
|
16
test/macro.c
16
test/macro.c
|
@ -128,6 +128,22 @@ int main() {
|
|||
|
||||
if (0);
|
||||
|
||||
#define M 5
|
||||
#if M
|
||||
m = 5;
|
||||
#else
|
||||
m = 6;
|
||||
#endif
|
||||
assert(5, m, "m");
|
||||
|
||||
#define M 5
|
||||
#if M-5
|
||||
m = 6;
|
||||
#elif M
|
||||
m = 5;
|
||||
#endif
|
||||
assert(5, m, "m");
|
||||
|
||||
printf("OK\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue