refactor(dev): unify compiler error logging

This commit is contained in:
Lane0218
2026-03-11 21:25:07 +08:00
parent f9fde30d12
commit 9070775187
5 changed files with 81 additions and 28 deletions

View File

@@ -1,11 +1,20 @@
// 轻量日志接口。
#pragma once
#include <cstddef>
#include <exception>
#include <iosfwd>
#include <iostream>
#include <string>
#include <string_view>
#define LOG_INFO(msg) std::cerr << "[info] " << msg << "\n"
#define LOG_ERROR(msg) std::cerr << "[error] " << msg << "\n"
void LogInfo(std::string_view msg, std::ostream& os);
void LogError(std::string_view msg, std::ostream& os);
std::string FormatError(std::string_view stage, std::string_view msg);
std::string FormatErrorAt(std::string_view stage, std::size_t line,
std::size_t column, std::string_view msg);
bool HasErrorPrefix(std::string_view msg, std::string_view stage);
void PrintException(std::ostream& os, const std::exception& ex);
// 打印命令行帮助信息(用于 `compiler --help`)。
void PrintHelp(std::ostream& os);