feat(parser): 添加声明列表支持并重构解析逻辑

- 添加 SCC_AST_DECL_LIST 节点类型用于表示声明列表
- 实现 scc_ast_decl_list_init 函数来初始化声明列表节点
- 重构 scc_parse_declaration 函数以支持逗号分隔的多个变量声明
- 分离类型说明符解析到独立的 scc_parse_declaration_specifiers 函数
- 支持 typedef 和多变量声明如 'int a, b;' 和 'int a = 1, b = 2;'
- 在 ast_dump 中添加对声明列表节点的打印支持

refactor(ast): 统一使用 scc_vec_foreach 宏替换手动循环

- 将 ast_dump.c 中的多个手动索引循环改为使用 scc_vec_foreach
- 提高代码可读性和安全性
- 避免索引越界错误

fix(parser): 修复语义分析中结构体符号表冲突

- 为结构体、联合体和枚举符号名添加前缀避免命名冲突
- 使用 '$S_'、'$U_'、'$E_' 前缀分别标识结构体、联合体和枚举

refactor(log): 统一终止处理方式

- 将 log_exit 替换为 log_abort 以更准确反映行为
- 更新相关依赖模块的实现

style(parser): 移除未使用的参数和清理代码

- 在 argparse.c 中添加 (void) 参数注释处理未使用的参数
- 清理 parse_expr.c 中未使用的函数声明
- 优化 parse_type.c 中的错误处理流程
This commit is contained in:
zzy
2026-03-14 14:04:24 +08:00
parent 8fcfeda14e
commit eb969cdbf7
26 changed files with 344 additions and 165 deletions

View File

@@ -60,7 +60,7 @@ int log_default_handler(logger_t *module, log_level_t level, const char *file,
(void)color_code;
(void)level_str;
if (level & LOG_LEVEL_FATAL) {
log_exit(-LOG_LEVEL_FATAL);
log_abort();
}
return 0;
}

View File

@@ -14,7 +14,7 @@
#include <stdlib.h>
#define log_vsnprintf vsnprintf
#define log_puts puts
#define log_exit scc_exit
#define log_abort abort
#endif
#ifdef __GNUC__ // GCC, Clang
@@ -37,9 +37,9 @@
#warning "log_puts not defined"
#endif
#ifndef log_exit
#define log_exit(...)
#warning "log_exit not defined"
#ifndef log_abort
#define log_abort(...)
#warning "log_abort not defined"
#endif
/**
@@ -155,7 +155,7 @@ void log_set_handler(logger_t *logger, log_handler handler);
((void)((cond) || \
(__default_logger_root.handler(SCC_LOG_HANDLE_ARGS( \
&__default_logger_root, LOG_LEVEL_FATAL, __VA_ARGS__)), \
log_exit(1), __scc_log_unreachable(), 0)))
log_abort(), __scc_log_unreachable(), 0)))
/// @name 断言工具宏
/// @{

View File

@@ -9,6 +9,7 @@
#define scc_realloc scc_pal_realloc
#define scc_free scc_pal_free
#define scc_exit scc_pal_exit
#define scc_abort scc_pal_abort
typedef void *scc_file_t;
typedef enum {

View File

@@ -9,8 +9,8 @@
#define log_puts(str) scc_printf("%s", str)
#endif
#ifndef log_exit
#define log_exit scc_exit
#ifndef log_abort
#define log_abort scc_abort
#endif
#include <log.h>

View File

@@ -17,6 +17,9 @@ void scc_pal_free(void *ptr);
// Required
void scc_pal_exit(int code);
// Option
void scc_pal_abort();
/* IO */
// Required

View File

@@ -58,7 +58,7 @@
} \
usize phys_tail = _scc_ring_phys(ring, (ring).tail); \
if ((ring).fill == null || \
!(ring).fill(&(ring).data[phys_tail], (ring).userdata)) { \
!(ring).fill(&((ring).data[phys_tail]), (ring).userdata)) { \
ok = 0; \
break; \
} \
@@ -104,7 +104,7 @@
#define scc_ring_init(ring, _cap, fill_func, _userdata) \
do { \
(ring).data = \
(_cap) ? scc_malloc((_cap) * sizeof(*(ring).data)) : null; \
(_cap) != 0 ? scc_malloc((_cap) * sizeof(*(ring).data)) : null; \
(ring).cap = (_cap); \
(ring).head = 0; \
(ring).probe = 0; \

View File

@@ -35,10 +35,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* clang-format off */
#ifndef PRINTF_H_
#define PRINTF_H_
#define PRINTF_INCLUDE_CONFIG_H
#ifdef PRINTF_INCLUDE_CONFIG_H
#include "printf_config.h"
#endif

View File

@@ -0,0 +1,10 @@
/* clang-format off */
/* Support for the decimal notation floating point conversion specifiers (%f, %F) */
#ifndef PRINTF_SUPPORT_DECIMAL_SPECIFIERS
#define PRINTF_SUPPORT_DECIMAL_SPECIFIERS 0
#endif
/* Support for the exponential notation floating point conversion specifiers (%e, %g, %E, %G) */
#ifndef PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS
#define PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS 0
#endif

View File

@@ -74,12 +74,15 @@ size_t scc_pal_fseek(scc_pal_file_t f, size_t offset,
void scc_pal_exit(int code) { exit(code); }
void scc_pal_abort() { abort(); }
void scc_pal_putchar(char c) { putchar(c); }
void scc_pal_eputchar(char c) { fputc(c, stderr); }
void scc_pal_write(const char *data, size_t len) {
int res = fputs(data, stdout);
(void)len; // FIXME maybe using len to check return value
if (res != 0) {
fprintf(stderr, "\nError writing to stdout [%d]\n", res);
scc_pal_exit(1);
@@ -88,6 +91,7 @@ void scc_pal_write(const char *data, size_t len) {
void scc_pal_ewrite(const char *data, size_t len) {
int res = fputs(data, stderr);
(void)len; // FIXME maybe using len to check return value
if (res != 0) {
fprintf(stderr, "\nError writing to stderr [%d]\n", res);
scc_pal_exit(1);

View File

@@ -5,13 +5,22 @@
#define __SCC_LOG_IMPL_IMPORT_SRC__
#include <scc_core_log.h>
void putchar_(char ch) { LOG_FATAL("you can't use printf.c directly"); }
void putchar_(char ch) {
(void)ch;
LOG_FATAL("you can't use printf.c directly");
}
scc_file_t scc_fopen(const char *path, scc_fmode_t mode) {
return scc_pal_fopen(path, (scc_pal_fmode_t)mode); // FIXME
}
void scc_fclose(scc_file_t file) { scc_pal_fclose(file); }
void scc_fclose(scc_file_t file) {
if (file == scc_stdout || file == scc_stderr) {
return;
} else {
scc_pal_fclose(file);
}
}
usize scc_fsize(scc_file_t file) {
if (scc_pal_fseek(file, 0, SCC_SEEK_PAL_END) != 0) {