feat(lex_parser, pprocessor): replace consume with next and remove stream resets
- Replace `scc_probe_stream_consume` with `scc_probe_stream_next` for consistent stream advancement - Remove redundant `scc_probe_stream_reset` calls before peeking, as `next` and `peek` handle state - Update `scc_cstring_new` to `scc_cstring_create` and `scc_pos_init` to `scc_pos_create` for naming consistency - Change `scc_pp_macro_get` parameter to `const scc_cstring_t*` for better const-correctness - Improves code clarity and maintains proper stream position tracking
This commit is contained in:
@@ -10,8 +10,8 @@ typedef struct scc_pos {
|
||||
usize offset;
|
||||
} scc_pos_t;
|
||||
|
||||
static inline scc_pos_t scc_pos_init() {
|
||||
return (scc_pos_t){scc_cstring_new(), 1, 1, 0};
|
||||
static inline scc_pos_t scc_pos_create() {
|
||||
return (scc_pos_t){scc_cstring_create(), 1, 1, 0};
|
||||
}
|
||||
|
||||
static inline void scc_pos_next(scc_pos_t *pos) {
|
||||
|
||||
@@ -20,11 +20,17 @@ typedef struct scc_cstring {
|
||||
*
|
||||
* @return cstring_t 初始化后的对象
|
||||
*/
|
||||
// FIXME need using `init` beacuse it not malloc
|
||||
static inline scc_cstring_t scc_cstring_new(void) {
|
||||
static inline scc_cstring_t scc_cstring_create(void) {
|
||||
return (scc_cstring_t){.data = null, .size = 0, .cap = 0};
|
||||
}
|
||||
|
||||
static inline void scc_cstring_init(scc_cstring_t *string) {
|
||||
Assert(string != null);
|
||||
string->data = null;
|
||||
string->size = 0;
|
||||
string->cap = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从 C 风格字符串创建一个动态字符串副本
|
||||
*
|
||||
@@ -33,7 +39,7 @@ static inline scc_cstring_t scc_cstring_new(void) {
|
||||
*/
|
||||
static inline scc_cstring_t scc_cstring_from_cstr(const char *s) {
|
||||
if (s == null) {
|
||||
return scc_cstring_new();
|
||||
return scc_cstring_create();
|
||||
}
|
||||
|
||||
usize len = 0;
|
||||
|
||||
@@ -123,8 +123,8 @@ scc_probe_stream_t *scc_mem_probe_stream_init(scc_mem_probe_stream_t *stream,
|
||||
* @param owned 是否拥有数据(如果拥有将会自动释放)
|
||||
* @return scc_probe_stream_t*
|
||||
*/
|
||||
scc_probe_stream_t *scc_mem_probe_stream_new(const char *data, usize length,
|
||||
cbool owned);
|
||||
scc_probe_stream_t *scc_mem_probe_stream_alloc(const char *data, usize length,
|
||||
cbool owned);
|
||||
#endif
|
||||
|
||||
#endif /* __SMCC_CORE_PROBE_STREAM_H__ */
|
||||
|
||||
Reference in New Issue
Block a user