feat(lexer): 改进预处理器token测试用例并修复##符号处理
- 将"##" token从SCC_TOK_SHARP修正为SCC_TOK_SHARP_SHARP - 添加更多预处理器指令测试用例,包括宏定义、错误和警告指令 - 修正序列测试中的##符号处理 fix(pproc): 完善预处理器指令处理逻辑 - 实现#error和#warning指令的具体处理逻辑 - 添加对字符串字面量的错误和警告消息输出 - 优化未处理指令的错误处理流程 fix(pproc): 修复词法分析器流处理边界条件 - 在scc_pproc.c中添加对token获取失败的检查 - 防止在流结束时出现未处理的边界情况
This commit is contained in:
@@ -281,13 +281,38 @@ void scc_pproc_handle_directive(scc_pproc_t *pp) {
|
||||
case SCC_PP_TOK_ENDIF:
|
||||
case SCC_PP_TOK_LINE:
|
||||
case SCC_PP_TOK_EMBED:
|
||||
goto ERROR;
|
||||
case SCC_PP_TOK_ERROR:
|
||||
scc_lexer_tok_drop(&tok);
|
||||
while (1) {
|
||||
ok = scc_lexer_next_non_blank(pp->cur_ring, &tok);
|
||||
if (tok.type == SCC_TOK_ENDLINE || ok == false) {
|
||||
return;
|
||||
}
|
||||
if (scc_get_tok_subtype(tok.type) == SCC_TOK_SUBTYPE_LITERAL) {
|
||||
LOG_ERROR(scc_cstring_as_cstr(&tok.lexeme));
|
||||
}
|
||||
scc_lexer_tok_drop(&tok);
|
||||
}
|
||||
case SCC_PP_TOK_WARNING:
|
||||
scc_lexer_tok_drop(&tok);
|
||||
while (1) {
|
||||
ok = scc_lexer_next_non_blank(pp->cur_ring, &tok);
|
||||
if (tok.type == SCC_TOK_ENDLINE || ok == false) {
|
||||
return;
|
||||
}
|
||||
if (scc_get_tok_subtype(tok.type) == SCC_TOK_SUBTYPE_LITERAL) {
|
||||
LOG_WARN(scc_cstring_as_cstr(&tok.lexeme));
|
||||
}
|
||||
scc_lexer_tok_drop(&tok);
|
||||
}
|
||||
case SCC_PP_TOK_PRAGMA:
|
||||
LOG_WARN("Pragma ignored");
|
||||
break;
|
||||
default:
|
||||
LOG_WARN("Unhandled directive: %s", scc_cstring_as_cstr(&tok.lexeme));
|
||||
break;
|
||||
}
|
||||
ERROR:
|
||||
LOG_WARN("Unhandled directive: %s", scc_cstring_as_cstr(&tok.lexeme));
|
||||
scc_lexer_skip_until_newline(pp->cur_ring);
|
||||
}
|
||||
@@ -15,6 +15,9 @@ CONTINUE:
|
||||
}
|
||||
}
|
||||
scc_ring_peek(*stream, tok, ok);
|
||||
if (ok == false) {
|
||||
return false;
|
||||
}
|
||||
if (tok.type == SCC_TOK_ENDLINE) {
|
||||
scc_ring_next_consume(*stream, *out, ok);
|
||||
pp->at_line_start = true;
|
||||
|
||||
Reference in New Issue
Block a user