mirror of
https://github.com/rui314/chibicc
synced 2024-11-25 07:40:48 +03:00
[GNU] Add "#pragma once"
This commit is contained in:
parent
d48d9e5ae3
commit
a6c662207d
11
preprocess.c
11
preprocess.c
@ -67,6 +67,7 @@ struct Hideset {
|
||||
|
||||
static HashMap macros;
|
||||
static CondIncl *cond_incl;
|
||||
static HashMap pragma_once;
|
||||
|
||||
static Token *preprocess2(Token *tok);
|
||||
static Macro *find_macro(Token *tok);
|
||||
@ -781,6 +782,10 @@ static char *detect_include_guard(Token *tok) {
|
||||
}
|
||||
|
||||
static Token *include_file(Token *tok, char *path, Token *filename_tok) {
|
||||
// Check for "#pragma once"
|
||||
if (hashmap_get(&pragma_once, path))
|
||||
return tok;
|
||||
|
||||
// If we read the same file before, and if the file was guarded
|
||||
// by the usual #ifndef ... #endif pattern, we may be able to
|
||||
// skip the file without opening it.
|
||||
@ -939,6 +944,12 @@ static Token *preprocess2(Token *tok) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (equal(tok, "pragma") && equal(tok->next, "once")) {
|
||||
hashmap_put(&pragma_once, tok->file->name, (void *)1);
|
||||
tok = skip_line(tok->next->next);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (equal(tok, "pragma")) {
|
||||
do {
|
||||
tok = tok->next;
|
||||
|
10
test/pragma-once.c
Normal file
10
test/pragma-once.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include "test.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "test/pragma-once.c"
|
||||
|
||||
int main() {
|
||||
printf("OK\n");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user