阶段 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:
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file TypeInfo.h
|
||||
* @brief 语言类型元数据(machine.toml 别名 + 内建基元解析)
|
||||
* @author
|
||||
* @date 2026-08-21
|
||||
*
|
||||
* @details 类型定义数据化(配置),运算/类型检查语义代码化:
|
||||
* - 元数据(宽度/符号/浮点/base/range/tag)全部来自 machine.toml + 内建基元表
|
||||
* - 查询大小写不敏感(配置名大写,Linker type_name 小写)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "compiler/MachineConfig.h"
|
||||
|
||||
namespace compiler {
|
||||
|
||||
// 语言类型元数据
|
||||
struct TypeMeta {
|
||||
const ConfigType* config = nullptr; // 配置类型行(别名 + range + tag)
|
||||
const PrimType* prim = nullptr; // 内建基元(宽度/符号/浮点)
|
||||
|
||||
uint32_t width() const { return prim ? prim->width : 0; }
|
||||
bool is_signed() const { return prim ? prim->is_signed : false; }
|
||||
bool is_float() const { return prim ? prim->is_float : false; }
|
||||
uint32_t tag() const { return config ? config->tag : 0; }
|
||||
bool has_range() const { return config ? config->has_range : false; }
|
||||
bool value_in_range(int64_t v) const {
|
||||
return !config || !config->has_range ||
|
||||
(v >= config->range_min && v <= config->range_max);
|
||||
}
|
||||
|
||||
explicit operator bool() const { return config != nullptr && prim != nullptr; }
|
||||
};
|
||||
|
||||
// 按语言类型名查元数据(大小写不敏感;未找到返回空 TypeMeta)
|
||||
TypeMeta type_meta(const MachineConfig& cfg, const std::string& name);
|
||||
}
|
||||
Reference in New Issue
Block a user