feat: rename core types to scc prefix for consistency
Updated type names from `core_*` to `scc_*` across lex_parser and stream modules to maintain naming consistency within the SCC codebase. This includes changes to function signatures and internal usage of types like `core_probe_stream_t`, `core_pos_t`, and `cstring_t` to their `scc_*` counterparts.
This commit is contained in:
@@ -3,12 +3,13 @@
|
||||
#endif
|
||||
|
||||
#include <core_impl.h>
|
||||
#define __SMCC_LOG_IMPORT_SRC__
|
||||
#define log_snprintf smcc_snprintf
|
||||
#define log_printf smcc_printf
|
||||
#define log_exit smcc_exit
|
||||
#define __SCC_LOG_IMPORT_SRC__
|
||||
#define log_snprintf scc_snprintf
|
||||
#define log_printf scc_printf
|
||||
#define log_exit scc_exit
|
||||
#include <log.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -16,77 +17,77 @@
|
||||
|
||||
/* ====== 内存管理核心接口实现 ====== */
|
||||
|
||||
void *smcc_malloc(usize size) { return malloc(size); }
|
||||
void *scc_malloc(usize size) { return malloc(size); }
|
||||
|
||||
void *smcc_calloc(usize count, usize size) { return calloc(count, size); }
|
||||
void *scc_calloc(usize count, usize size) { return calloc(count, size); }
|
||||
|
||||
void *smcc_realloc(void *ptr, usize new_size) { return realloc(ptr, new_size); }
|
||||
void *scc_realloc(void *ptr, usize new_size) { return realloc(ptr, new_size); }
|
||||
|
||||
void smcc_free(void *ptr) { free(ptr); }
|
||||
void scc_free(void *ptr) { free(ptr); }
|
||||
|
||||
/* ====== 文件系统核心接口实现 ====== */
|
||||
|
||||
static const char *get_file_mode_string(smcc_file_mode_t mode) {
|
||||
static const char *get_file_mode_string(scc_fmode_t mode) {
|
||||
switch (mode) {
|
||||
case SMCC_FILE_READ:
|
||||
case SCC_FILE_READ:
|
||||
return "rb";
|
||||
case SMCC_FILE_WRITE:
|
||||
case SCC_FILE_WRITE:
|
||||
return "wb";
|
||||
case SMCC_FILE_APPEND:
|
||||
case SCC_FILE_APPEND:
|
||||
return "ab";
|
||||
default:
|
||||
return "rb";
|
||||
}
|
||||
}
|
||||
|
||||
smcc_file_t smcc_fopen(const char *path, smcc_file_mode_t mode) {
|
||||
scc_file_t scc_fopen(const char *path, scc_fmode_t mode) {
|
||||
const char *mode_str = get_file_mode_string(mode);
|
||||
return (smcc_file_t)fopen(path, mode_str);
|
||||
return (scc_file_t)fopen(path, mode_str);
|
||||
}
|
||||
|
||||
void smcc_fclose(smcc_file_t file) {
|
||||
void scc_fclose(scc_file_t file) {
|
||||
if (file) {
|
||||
fclose((FILE *)file);
|
||||
}
|
||||
}
|
||||
|
||||
usize smcc_fread(smcc_file_t file, void *buffer, usize size) {
|
||||
usize scc_fread(scc_file_t file, void *buffer, usize size) {
|
||||
if (!file || !buffer)
|
||||
return 0;
|
||||
return fread(buffer, 1, size, (FILE *)file);
|
||||
}
|
||||
|
||||
usize smcc_fwrite(smcc_file_t file, const void *buffer, usize size) {
|
||||
usize scc_fwrite(scc_file_t file, const void *buffer, usize size) {
|
||||
if (!file || !buffer)
|
||||
return 0;
|
||||
return fwrite(buffer, 1, size, (FILE *)file);
|
||||
}
|
||||
|
||||
cbool smcc_fexists(const char *path) {
|
||||
smcc_file_t fp = smcc_fopen(path, SMCC_FILE_READ);
|
||||
cbool scc_fexists(const char *path) {
|
||||
scc_file_t fp = scc_fopen(path, SCC_FILE_READ);
|
||||
if (!fp)
|
||||
return false;
|
||||
smcc_fclose(fp);
|
||||
scc_fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ====== 输入输出核心接口实现 ====== */
|
||||
|
||||
void smcc_snprintf(char *buf, usize size, const char *format, ...) {
|
||||
void scc_snprintf(char *buf, usize size, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buf, size, format, args); // NOLINT
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void smcc_printf(const char *format, ...) {
|
||||
void scc_printf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(stdout, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void smcc_eprintf(const char *format, ...) {
|
||||
void scc_eprintf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
@@ -95,4 +96,4 @@ void smcc_eprintf(const char *format, ...) {
|
||||
|
||||
/* ====== 系统核心接口实现 ====== */
|
||||
|
||||
void smcc_exit(int code) { exit(code); }
|
||||
void scc_exit(int code) { exit(code); }
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <core_mem.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// 判断是否支持非对齐访问(x86/x64 支持)
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \
|
||||
@@ -9,7 +8,7 @@
|
||||
#define UNALIGNED_ACCESS_ALLOWED 0
|
||||
#endif
|
||||
|
||||
void *smcc_memcpy(void *dest, const void *restrict src, usize n) {
|
||||
void *scc_memcpy(void *dest, const void *restrict src, usize n) {
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
@@ -74,7 +73,7 @@ void *smcc_memcpy(void *dest, const void *restrict src, usize n) {
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *smcc_memmove(void *dest, const void *src, usize n) {
|
||||
void *scc_memmove(void *dest, const void *src, usize n) {
|
||||
char *d = (char *)dest;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
@@ -85,7 +84,7 @@ void *smcc_memmove(void *dest, const void *src, usize n) {
|
||||
|
||||
// 内存区域无重叠或前向拷贝
|
||||
if (d < s || d >= s + n) {
|
||||
return smcc_memcpy(d, s, n);
|
||||
return scc_memcpy(d, s, n);
|
||||
} else {
|
||||
// 后向拷贝处理重叠情况
|
||||
d += n;
|
||||
@@ -98,7 +97,7 @@ void *smcc_memmove(void *dest, const void *src, usize n) {
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *smcc_memset(void *s, int c, usize n) {
|
||||
void *scc_memset(void *s, int c, usize n) {
|
||||
unsigned char *p = (unsigned char *)s;
|
||||
unsigned char byte_val = (unsigned char)c;
|
||||
|
||||
@@ -167,7 +166,7 @@ void *smcc_memset(void *s, int c, usize n) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int smcc_memcmp(const void *s1, const void *s2, usize n) {
|
||||
int scc_memcmp(const void *s1, const void *s2, usize n) {
|
||||
const unsigned char *p1 = (const unsigned char *)s1;
|
||||
const unsigned char *p2 = (const unsigned char *)s2;
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <core_log.h>
|
||||
#include <core_stream.h>
|
||||
|
||||
#ifndef __SMCC_CORE_NO_MEM_PROBE_STREAM__
|
||||
#ifndef __SCC_CORE_NO_MEM_PROBE_STREAM__
|
||||
|
||||
static int mem_probe_stream_consume(core_probe_stream_t *_stream) {
|
||||
static int mem_probe_stream_consume(scc_probe_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
if (stream->curr_pos >= stream->data_length) {
|
||||
return core_stream_eof;
|
||||
@@ -19,9 +19,9 @@ static int mem_probe_stream_consume(core_probe_stream_t *_stream) {
|
||||
return (int)ch;
|
||||
}
|
||||
|
||||
static int mem_probe_stream_peek(core_probe_stream_t *_stream) {
|
||||
static int mem_probe_stream_peek(scc_probe_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
if (stream->probe_pos >= stream->data_length) {
|
||||
return core_stream_eof;
|
||||
@@ -31,9 +31,9 @@ static int mem_probe_stream_peek(core_probe_stream_t *_stream) {
|
||||
return (int)(unsigned char)stream->data[stream->probe_pos];
|
||||
}
|
||||
|
||||
static int mem_probe_stream_next(core_probe_stream_t *_stream) {
|
||||
static int mem_probe_stream_next(scc_probe_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
if (stream->probe_pos >= stream->data_length) {
|
||||
return core_stream_eof;
|
||||
@@ -45,9 +45,9 @@ static int mem_probe_stream_next(core_probe_stream_t *_stream) {
|
||||
return ch;
|
||||
}
|
||||
|
||||
static void mem_probe_stream_sync(core_probe_stream_t *_stream) {
|
||||
static void mem_probe_stream_sync(scc_probe_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
// 移动头指针到探针位置(消费已查看的字符)
|
||||
if (stream->probe_pos > stream->curr_pos) {
|
||||
@@ -55,9 +55,9 @@ static void mem_probe_stream_sync(core_probe_stream_t *_stream) {
|
||||
}
|
||||
}
|
||||
|
||||
static cbool mem_probe_stream_back(core_probe_stream_t *_stream) {
|
||||
static cbool mem_probe_stream_back(scc_probe_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
// 只能回退一个字符,且不能回退到探针位置之前
|
||||
if (stream->curr_pos == 0 || stream->curr_pos <= stream->probe_pos) {
|
||||
@@ -68,10 +68,10 @@ static cbool mem_probe_stream_back(core_probe_stream_t *_stream) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static usize mem_probe_stream_read_buf(core_probe_stream_t *_stream,
|
||||
static usize mem_probe_stream_read_buf(scc_probe_stream_t *_stream,
|
||||
char *buffer, usize count) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
if (buffer == null) {
|
||||
LOG_WARN("Buffer is null");
|
||||
@@ -82,7 +82,7 @@ static usize mem_probe_stream_read_buf(core_probe_stream_t *_stream,
|
||||
usize to_read = (remaining < count) ? remaining : count;
|
||||
|
||||
if (to_read > 0) {
|
||||
smcc_memcpy(buffer, stream->data + stream->curr_pos, to_read);
|
||||
scc_memcpy(buffer, stream->data + stream->curr_pos, to_read);
|
||||
stream->curr_pos += to_read;
|
||||
// 更新探针位置
|
||||
if (stream->probe_pos < stream->curr_pos) {
|
||||
@@ -96,36 +96,36 @@ static usize mem_probe_stream_read_buf(core_probe_stream_t *_stream,
|
||||
return to_read;
|
||||
}
|
||||
|
||||
static void mem_probe_stream_reset(core_probe_stream_t *_stream) {
|
||||
static void mem_probe_stream_reset(scc_probe_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
// 重置探针位置到头指针位置
|
||||
stream->probe_pos = stream->curr_pos;
|
||||
}
|
||||
|
||||
static cbool mem_probe_stream_is_at_end(core_probe_stream_t *_stream) {
|
||||
static cbool mem_probe_stream_is_at_end(scc_probe_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
return stream->curr_pos >= stream->data_length;
|
||||
}
|
||||
|
||||
static void mem_probe_stream_destroy(core_probe_stream_t *_stream) {
|
||||
static void mem_probe_stream_destroy(scc_probe_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_probe_stream_t *stream = (core_mem_probe_stream_t *)_stream;
|
||||
scc_mem_probe_stream_t *stream = (scc_mem_probe_stream_t *)_stream;
|
||||
|
||||
cstring_free(&stream->stream.name);
|
||||
scc_cstring_free(&stream->stream.name);
|
||||
|
||||
if (stream->owned) {
|
||||
smcc_free((void *)stream->data);
|
||||
scc_free((void *)stream->data);
|
||||
stream->data = null;
|
||||
}
|
||||
}
|
||||
|
||||
core_probe_stream_t *core_mem_probe_stream_init(core_mem_probe_stream_t *stream,
|
||||
const char *data, usize length,
|
||||
cbool need_copy) {
|
||||
scc_probe_stream_t *scc_mem_probe_stream_init(scc_mem_probe_stream_t *stream,
|
||||
const char *data, usize length,
|
||||
cbool need_copy) {
|
||||
if (stream == null || data == null) {
|
||||
LOG_ERROR("param error");
|
||||
return null;
|
||||
@@ -138,13 +138,13 @@ core_probe_stream_t *core_mem_probe_stream_init(core_mem_probe_stream_t *stream,
|
||||
|
||||
stream->owned = need_copy;
|
||||
if (need_copy) {
|
||||
char *buf = (char *)smcc_malloc(length);
|
||||
char *buf = (char *)scc_malloc(length);
|
||||
if (buf == null) {
|
||||
LOG_ERROR("malloc error");
|
||||
return null;
|
||||
}
|
||||
|
||||
smcc_memcpy(buf, data, length);
|
||||
scc_memcpy(buf, data, length);
|
||||
stream->data = buf;
|
||||
} else {
|
||||
stream->data = data;
|
||||
@@ -153,7 +153,7 @@ core_probe_stream_t *core_mem_probe_stream_init(core_mem_probe_stream_t *stream,
|
||||
stream->curr_pos = 0;
|
||||
stream->probe_pos = 0;
|
||||
|
||||
stream->stream.name = cstring_from_cstr("mem_probe_stream");
|
||||
stream->stream.name = scc_cstring_from_cstr("mem_probe_stream");
|
||||
|
||||
// 设置函数指针
|
||||
stream->stream.consume = mem_probe_stream_consume;
|
||||
@@ -166,7 +166,7 @@ core_probe_stream_t *core_mem_probe_stream_init(core_mem_probe_stream_t *stream,
|
||||
stream->stream.is_at_end = mem_probe_stream_is_at_end;
|
||||
stream->stream.drop = mem_probe_stream_destroy;
|
||||
|
||||
return (core_probe_stream_t *)stream;
|
||||
return (scc_probe_stream_t *)stream;
|
||||
}
|
||||
|
||||
#endif /* __SMCC_CORE_NO_MEM_PROBE_STREAM__ */
|
||||
#endif /* __SCC_CORE_NO_MEM_PROBE_STREAM__ */
|
||||
|
||||
Reference in New Issue
Block a user