mirror of https://github.com/rui314/chibicc
Add -U option
This commit is contained in:
parent
fc69f5c6f9
commit
be8b6f6d31
|
@ -101,6 +101,7 @@ Token *tokenize_file(char *filename);
|
|||
|
||||
void init_macros(void);
|
||||
void define_macro(char *name, char *buf);
|
||||
void undef_macro(char *name);
|
||||
Token *preprocess(Token *tok);
|
||||
|
||||
//
|
||||
|
|
10
main.c
10
main.c
|
@ -110,6 +110,16 @@ static void parse_args(int argc, char **argv) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[i], "-U")) {
|
||||
undef_macro(argv[++i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strncmp(argv[i], "-U", 2)) {
|
||||
undef_macro(argv[i] + 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[i], "-cc1-input")) {
|
||||
base_file = argv[++i];
|
||||
continue;
|
||||
|
|
10
preprocess.c
10
preprocess.c
|
@ -752,11 +752,8 @@ static Token *preprocess2(Token *tok) {
|
|||
tok = tok->next;
|
||||
if (tok->kind != TK_IDENT)
|
||||
error_tok(tok, "macro name must be an identifier");
|
||||
char *name = strndup(tok->loc, tok->len);
|
||||
undef_macro(strndup(tok->loc, tok->len));
|
||||
tok = skip_line(tok->next);
|
||||
|
||||
Macro *m = add_macro(name, true, NULL);
|
||||
m->deleted = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -836,6 +833,11 @@ void define_macro(char *name, char *buf) {
|
|||
add_macro(name, true, tok);
|
||||
}
|
||||
|
||||
void undef_macro(char *name) {
|
||||
Macro *m = add_macro(name, true, NULL);
|
||||
m->deleted = true;
|
||||
}
|
||||
|
||||
static Macro *add_builtin(char *name, macro_handler_fn *fn) {
|
||||
Macro *m = add_macro(name, true, NULL);
|
||||
m->handler = fn;
|
||||
|
|
|
@ -99,4 +99,8 @@ check -D
|
|||
echo foo | $chibicc -Dfoo=bar -E - | grep -q bar
|
||||
check -D
|
||||
|
||||
# -U
|
||||
echo foo | $chibicc -Dfoo=bar -Ufoo -E - | grep -q foo
|
||||
check -U
|
||||
|
||||
echo OK
|
||||
|
|
Loading…
Reference in New Issue