diff --git a/libs/README.md b/libs/README.md index 9b4b272..43e35e7 100644 --- a/libs/README.md +++ b/libs/README.md @@ -1,9 +1,22 @@ lexer 词法分析 -parse 语法分析 + +pproc 预处理器 + +parser 语法分析 sema 语义分析 + ast 抽象语法树 -sema 语义分析 + ir 中间代码标识 + +- ast2ir + +- ir2mcode + opt 优化器 -codegen 代码生成 + +mcode 机器码 + +sccf 统一输出格式 + target 目标平台支持 diff --git a/libs/pproc/src/pproc_directive.c b/libs/pproc/src/pproc_directive.c index 549c7d1..95122c6 100644 --- a/libs/pproc/src/pproc_directive.c +++ b/libs/pproc/src/pproc_directive.c @@ -119,7 +119,8 @@ void scc_pproc_parse_function_macro(scc_pproc_t *pp, if (idx++ % 2 != 1) { LOG_FATAL("ERROR"); } - } else if (arg->type == SCC_TOK_IDENT) { + } else if (scc_get_tok_subtype(arg->type) == + SCC_TOK_SUBTYPE_IDENTIFIER) { if (idx++ % 2 != 0) { LOG_FATAL("ERROR"); } diff --git a/libs/pproc/src/scc_pproc.c b/libs/pproc/src/scc_pproc.c index 6ac163a..9575f06 100644 --- a/libs/pproc/src/scc_pproc.c +++ b/libs/pproc/src/scc_pproc.c @@ -52,7 +52,7 @@ CONTINUE: scc_ring_next_consume(*stream, *out, ok); pp->at_line_start = true; return true; - } else if (tok.type == SCC_TOK_IDENT) { + } else if (scc_get_tok_subtype(tok.type) == SCC_TOK_SUBTYPE_IDENTIFIER) { // maybe expanded scc_pproc_macro_t *macro = scc_pproc_macro_table_get(&pp->macro_table, &tok.lexeme); diff --git a/libs/pproc/tests/test_pproc_unit.c b/libs/pproc/tests/test_pproc_unit.c index 5548e05..df4bea3 100644 --- a/libs/pproc/tests/test_pproc_unit.c +++ b/libs/pproc/tests/test_pproc_unit.c @@ -181,6 +181,19 @@ static void test_define_nested_macros(void) { "#define x 2\n" "g(z)\n", "f(2 * (z))\n"); + + TEST_CASE("with keyword as macro name or parameter name"); + CHECK_PP_OUTPUT_EXACT( + "#define ASSIGN_PTR_OR_DEFAULT(assigned_val, value, default)\\\n" + "assigned_val = value ? value : default\n" + "ASSIGN_PTR_OR_DEFAULT(parser->sema_callbacks.on_decl," + "callbacks->on_decl, dummy_sema_callback);\n", + "parser->sema_callbacks.on_decl = callbacks->on_decl ? " + "callbacks->on_decl : dummy_sema_callback;\n"); + + CHECK_PP_OUTPUT_EXACT("#define default a\n" + "default\n", + "a\n"); } static void test_undef_macros(void) { diff --git a/runtime/scc_core/include/printf/printf.c b/runtime/scc_core/include/scc_printf/printf.c similarity index 100% rename from runtime/scc_core/include/printf/printf.c rename to runtime/scc_core/include/scc_printf/printf.c diff --git a/runtime/scc_core/include/printf/printf.h b/runtime/scc_core/include/scc_printf/printf.h similarity index 100% rename from runtime/scc_core/include/printf/printf.h rename to runtime/scc_core/include/scc_printf/printf.h diff --git a/runtime/scc_core/src/core_impl.c b/runtime/scc_core/src/core_impl.c index 31e59d3..4c8d5a0 100644 --- a/runtime/scc_core/src/core_impl.c +++ b/runtime/scc_core/src/core_impl.c @@ -1,5 +1,5 @@ // IMPLEMENT -#include +#include #include #define __SCC_LOG_IMPL_IMPORT_SRC__ @@ -16,15 +16,7 @@ scc_file_t scc_fopen(const char *path, scc_fmode_t mode) { void scc_fclose(scc_file_t file) { scc_pal_fclose(file); } -usize scc_fread(scc_file_t file, void *buffer, usize size) { - return scc_pal_fread(file, buffer, size); -} - -usize scc_fwrite(scc_file_t file, const void *buffer, usize size) { - return scc_pal_fwrite(file, buffer, size); -} - -usize scc_fsize(scc_pal_file_t file) { +usize scc_fsize(scc_file_t file) { if (scc_pal_fseek(file, 0, SCC_SEEK_PAL_END) != 0) { LOG_ERROR("fseek failed"); return 0; @@ -37,6 +29,14 @@ usize scc_fsize(scc_pal_file_t file) { return fsize; } +usize scc_fread(scc_file_t file, void *buffer, usize size) { + return scc_pal_fread(file, buffer, size); +} + +usize scc_fwrite(scc_file_t file, const void *buffer, usize size) { + return scc_pal_fwrite(file, buffer, size); +} + cbool scc_fexists(const char *path) { scc_file_t fp = scc_fopen(path, SCC_FILE_READ); if (!fp)