refactor(pprocessor): rename macro table type and update function names
- Change `scc_macro_table_t` to `scc_pp_macro_table_t` for consistency - Rename `scc_pp_macro_create` to `scc_pp_macro_new` for naming convention - Remove unused `scc_pp_compress_whitespace` function - Update macro table function names: `scc_pp_find_macro` → `scc_pp_macro_table_get`, `scc_pp_remove_macro` → `scc_pp_macro_table_remove` - Add new `scc_pp_macro_table_set` function for setting macros - Update all function signatures to use new type name - Remove commented-out whitespace compression code from implementation
This commit is contained in:
@@ -193,7 +193,7 @@ static cbool safe_skip_backspace_if_endline(scc_probe_stream_t *stream,
|
||||
}
|
||||
|
||||
void scc_pp_parse_directive(scc_probe_stream_t *stream, scc_pos_t *pos,
|
||||
scc_macro_table_t *macros) {
|
||||
scc_pp_macro_table_t *macros) {
|
||||
Assert(stream != null);
|
||||
|
||||
scc_probe_stream_reset(stream);
|
||||
@@ -264,7 +264,7 @@ void scc_pp_parse_directive(scc_probe_stream_t *stream, scc_pos_t *pos,
|
||||
case SCC_PP_TOK_UNDEF: {
|
||||
if (scc_lex_parse_identifier(stream, pos, &name)) {
|
||||
// TODO ret value
|
||||
scc_pp_remove_macro(macros, &name);
|
||||
scc_pp_macro_table_remove(macros, &name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -283,7 +283,6 @@ void scc_pp_parse_directive(scc_probe_stream_t *stream, scc_pos_t *pos,
|
||||
case SCC_PP_TOK_WARNING:
|
||||
case SCC_PP_TOK_PRAMA:
|
||||
// 暂时跳过这一行
|
||||
TODO();
|
||||
scc_lex_parse_skip_line(stream, pos);
|
||||
break;
|
||||
default:
|
||||
@@ -390,11 +389,14 @@ cbool scc_pp_expand_function_macro(scc_pp_macro_t *macro,
|
||||
return true;
|
||||
}
|
||||
|
||||
cbool scc_pp_expand_macro(scc_probe_stream_t *stream, scc_macro_table_t *macros,
|
||||
cbool scc_pp_expand_macro(scc_probe_stream_t *stream,
|
||||
scc_pp_macro_table_t *macros,
|
||||
scc_pp_macro_table_t *expand_stack,
|
||||
scc_probe_stream_t **out_stream, int depth) {
|
||||
// TODO self position and it maybe is a stack on #include ?
|
||||
// 递归扫描
|
||||
if (depth <= 0) {
|
||||
*out_stream = null;
|
||||
return false;
|
||||
}
|
||||
Assert(stream != null && macros != null && out_stream != null);
|
||||
@@ -406,9 +408,11 @@ cbool scc_pp_expand_macro(scc_probe_stream_t *stream, scc_macro_table_t *macros,
|
||||
ret = scc_lex_parse_identifier(stream, &pos, &identifier);
|
||||
Assert(ret == true);
|
||||
|
||||
scc_pp_macro_t *macro = scc_pp_find_macro(macros, &identifier);
|
||||
if (macro == null) {
|
||||
// 不是宏,直接输出标识符
|
||||
scc_pp_macro_t *macro = scc_pp_macro_table_get(macros, &identifier);
|
||||
// 1. 不是宏,直接输出标识符
|
||||
// 2. 检查到重复展开跳过
|
||||
if (macro == null ||
|
||||
scc_pp_macro_table_get(expand_stack, ¯o->name) != null) {
|
||||
*out_stream =
|
||||
scc_mem_probe_stream_new(scc_cstring_as_cstr(&identifier),
|
||||
scc_cstring_len(&identifier), false);
|
||||
@@ -436,15 +440,24 @@ cbool scc_pp_expand_macro(scc_probe_stream_t *stream, scc_macro_table_t *macros,
|
||||
Assert(ret == true);
|
||||
}
|
||||
|
||||
// 已经展开的将被标记并入栈
|
||||
scc_pp_macro_table_set(expand_stack,
|
||||
scc_pp_macro_new(¯o->name, macro->type));
|
||||
|
||||
// 将展开内容变换成stream
|
||||
scc_probe_stream_t *tmp_stream = scc_mem_probe_stream_new(
|
||||
scc_cstring_as_cstr(&tmp_buff), scc_cstring_len(&tmp_buff), false);
|
||||
|
||||
int ch;
|
||||
scc_cstring_t real_buff = scc_cstring_new();
|
||||
|
||||
while ((ch = scc_probe_stream_peek(tmp_stream)) != scc_stream_eof) {
|
||||
if (scc_lex_parse_is_identifier_prefix(ch)) {
|
||||
// 递归检查
|
||||
scc_probe_stream_t *tmp_out_stream;
|
||||
scc_pp_expand_macro(tmp_stream, macros, &tmp_out_stream, depth - 1);
|
||||
if (scc_pp_expand_macro(tmp_stream, macros, expand_stack,
|
||||
&tmp_out_stream, depth - 1) == false) {
|
||||
return false;
|
||||
}
|
||||
// scc_cstring_append_cstr();
|
||||
Assert(tmp_out_stream != null);
|
||||
while (scc_probe_stream_peek(tmp_out_stream) != scc_stream_eof) {
|
||||
@@ -462,6 +475,9 @@ cbool scc_pp_expand_macro(scc_probe_stream_t *stream, scc_macro_table_t *macros,
|
||||
scc_probe_stream_drop(tmp_stream);
|
||||
*out_stream = scc_mem_probe_stream_new(scc_cstring_as_cstr(&real_buff),
|
||||
scc_cstring_len(&real_buff), false);
|
||||
|
||||
// 已经展开的将被标记并出栈
|
||||
scc_pp_macro_table_remove(expand_stack, ¯o->name);
|
||||
return true;
|
||||
ERR:
|
||||
*out_stream = null;
|
||||
|
||||
Reference in New Issue
Block a user