feat(core): 重构词法分析器流接口并迁移至 core 库
将 lexer_stream 抽象为 core_stream,统一运行时核心组件的输入流模型。 移除了旧的 `lexer_stream.h` 定义,并将其功能完整迁移至 `core_stream.h` 中。 更新了内存流实现以适配新的 core_stream 接口,并修复部分资源释放问题。 同时调整日志模块包含方式,增强模块间解耦能力。 此变更影响词法分析器对输入流的操作方式,所有涉及 stream 的类型与函数均已替换为 core 前缀版本。 测试用例同步更新并验证通过。
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "core_type.h"
|
||||
#include "core_impl.h"
|
||||
#include "log.h"
|
||||
#include "core_log.h"
|
||||
|
||||
typedef struct cstring {
|
||||
char* data;
|
||||
@@ -37,16 +37,16 @@ static inline cstring_t cstring_from_cstr(const char* s) {
|
||||
if (s == null) {
|
||||
return cstring_new();
|
||||
}
|
||||
|
||||
|
||||
usize len = 0;
|
||||
const char* p = s;
|
||||
while (*p++) len++;
|
||||
|
||||
|
||||
char* data = (char*)smcc_malloc(len + 1);
|
||||
Assert(data != null);
|
||||
smcc_memcpy(data, s, len);
|
||||
data[len] = '\0';
|
||||
|
||||
|
||||
return (cstring_t) { .data = data, .len = len, .cap = len };
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ static inline cstring_t cstring_from_cstr(const char* s) {
|
||||
* 释放字符串资源
|
||||
*/
|
||||
static inline void cstring_free(cstring_t* str) {
|
||||
if (str && str->data) {
|
||||
if (str && str->data && str->cap != 0) {
|
||||
smcc_free(str->data);
|
||||
str->data = null;
|
||||
str->len = 0;
|
||||
@@ -65,11 +65,11 @@ static inline void cstring_free(cstring_t* str) {
|
||||
/**
|
||||
* 向字符串追加内容
|
||||
*/
|
||||
static inline void cstring_push_str(cstring_t* str, const char* data, usize len) {
|
||||
static inline void cstring_push_cstr(cstring_t* str, const char* data, usize len) {
|
||||
if (str == null || data == null || len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 如果需要扩容
|
||||
if (str->len + len + 1 > str->cap) {
|
||||
// FIXME c string 兼容性问题 bad practice a lot of `+ 1`
|
||||
@@ -81,7 +81,7 @@ static inline void cstring_push_str(cstring_t* str, const char* data, usize len)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char* new_data = str->data ?
|
||||
(char*)smcc_realloc(str->data, new_cap) :
|
||||
(char*)smcc_malloc(new_cap);
|
||||
@@ -90,7 +90,7 @@ static inline void cstring_push_str(cstring_t* str, const char* data, usize len)
|
||||
str->data = new_data;
|
||||
str->cap = new_cap;
|
||||
}
|
||||
|
||||
|
||||
smcc_memcpy(str->data + str->len, data, len);
|
||||
str->len += len;
|
||||
str->data[str->len] = '\0'; // 保证 C 字符串兼容性
|
||||
@@ -100,7 +100,7 @@ static inline void cstring_push_str(cstring_t* str, const char* data, usize len)
|
||||
* 向字符串追加单个字符
|
||||
*/
|
||||
static inline void cstring_push(cstring_t* str, char ch) {
|
||||
cstring_push_str(str, &ch, 1);
|
||||
cstring_push_cstr(str, &ch, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user