/** * @file TypeInfo.cpp * @brief 语言类型元数据(machine.toml 别名 + 内建基元解析) * @author * @date 2026-08-21 * * @details type_meta 实现:先按名称(大小写不敏感)命中配置类型行, * 再由 base 解析出内建基元,合成 TypeMeta。 */ #include "compiler/TypeInfo.h" #include namespace compiler { namespace { /** * @brief 转小写。 * @param s 输入串 * @return 全小写副本(逐字符 tolower,逐字节安全) */ std::string lower(const std::string& s) { std::string out = s; for (char& ch : out) { ch = static_cast(std::tolower(static_cast(ch))); } return out; } } // namespace /** * @brief 按语言类型名查元数据。 * @param cfg 机器配置(类型表来源) * @param name 语言类型名 * @return 对应 TypeMeta;未找到返回空 TypeMeta(operator bool 为 false) * @details 比较前两侧都转小写(配置名大写 BOOL/INT/TIME,Linker type_name 小写); * 命中配置行后再用 base 解析内建基元,两者都命中才算有效。 */ TypeMeta type_meta(const MachineConfig& cfg, const std::string& name) { TypeMeta m; const std::string key = lower(name); for (const ConfigType& t : cfg.types()) { if (lower(t.name) == key) { m.config = &t; break; } } if (m.config != nullptr) { m.prim = MachineConfig::find_prim(m.config->base); } return m; } } // namespace compiler