diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-07-21 17:44:22 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-15 10:04:29 +0900 |
| commit | adfe15f9fa0f4e69b343679dca6cf12fc96e3819 (patch) | |
| tree | 8c50b5fe714c4cfb4337e9cbc7a56dc21d394abd | |
| parent | 6daa56323634e1142f2d22a756a77a74382cf3a7 (diff) | |
| download | ducc-adfe15f9fa0f4e69b343679dca6cf12fc96e3819.tar.gz ducc-adfe15f9fa0f4e69b343679dca6cf12fc96e3819.tar.zst ducc-adfe15f9fa0f4e69b343679dca6cf12fc96e3819.zip | |
feat: define __ducc__ macro
| -rw-r--r-- | preprocess.c | 15 | ||||
| -rw-r--r-- | tests/061.sh | 14 |
2 files changed, 28 insertions, 1 deletions
diff --git a/preprocess.c b/preprocess.c index 202ff40..a8b3b91 100644 --- a/preprocess.c +++ b/preprocess.c @@ -48,6 +48,17 @@ PpDefines* pp_defines_new() { return pp_defines; } +void add_predefined_macros(PpDefines* pp_defines) { + PpDefine* pp_define = pp_defines->data + pp_defines->len; + pp_define->name.len = strlen("__ducc__"); + pp_define->name.data = "__ducc__"; + pp_define->tokens = calloc(1, sizeof(PpToken)); + pp_define->tokens[0].kind = PpTokenKind_pp_number; + pp_define->tokens[0].raw.len = strlen("1"); + pp_define->tokens[0].raw.data = "1"; + pp_defines->len += 1; +} + Preprocessor* preprocessor_new(char* src, int include_depth, PpDefines* pp_defines) { if (include_depth >= 32) { fatal_error("include depth limit exceeded"); @@ -427,5 +438,7 @@ PpToken* do_preprocess(char* src, int depth, PpDefines* pp_defines) { } PpToken* preprocess(char* src) { - return do_preprocess(src, 0, pp_defines_new()); + PpDefines* pp_defines = pp_defines_new(); + add_predefined_macros(pp_defines); + return do_preprocess(src, 0, pp_defines); } diff --git a/tests/061.sh b/tests/061.sh new file mode 100644 index 0000000..17c5f6a --- /dev/null +++ b/tests/061.sh @@ -0,0 +1,14 @@ +set -e + +cat <<'EOF' > expected +1 +EOF + +bash ../../test_diff.sh <<'EOF' +int printf(); + +int main() { + printf("%d\n", __ducc__); + return 0; +} +EOF |
