阶段 B 步骤 5:类型元数据配置化(TypeInfo)。

- TypeInfo.h/cpp:TypeMeta(配置别名 + 内建基元解析),查询大小写不敏感;
  提供 width/is_signed/is_float/tag/has_range/value_in_range
- Codegen:layout_data 初值按 type_meta 的基元宽度/浮点写(删除手写宽度分支);
  const_id 的 tag 改查 type_meta
- machine_test:+10 断言(BOOL 1B/range[0,1]/tag0、INT 2B 有符号、TIME 8B、大小写不敏感、未定义空)
- 验收:line1 224 字节 hash 0xc3fe4ae74ad45900 不变、ctest 12/12
This commit is contained in:
2026-08-21 22:16:48 +08:00
parent 447a8d0119
commit e187ed7b03
5 changed files with 127 additions and 11 deletions
+41
View File
@@ -0,0 +1,41 @@
/**
* @file TypeInfo.cpp
* @brief 语言类型元数据(machine.toml 别名 + 内建基元解析)
* @author
* @date 2026-08-21
*/
#include "compiler/TypeInfo.h"
#include <cctype>
namespace compiler {
namespace {
std::string lower(const std::string& s) {
std::string out = s;
for (char& ch : out) {
ch = static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
}
return out;
}
} // namespace
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