[feat]类初始化

This commit is contained in:
2025-12-22 17:38:52 +08:00
parent cff6bb77a3
commit 34a56beb90
13 changed files with 294 additions and 107 deletions

View File

@@ -20,6 +20,8 @@ namespace Fig
std::unordered_map<std::size_t, FunctionStruct> functions;
std::unordered_map<std::size_t, FString> functionNames;
std::unordered_map<std::size_t, FString> structTypeNames;
public:
ContextPtr parent;
@@ -129,6 +131,11 @@ namespace Fig
functions[fn.id] = fn;
functionNames[fn.id] = name;
}
if (ti == ValueType::StructType)
{
auto &st = value.as<StructType>().getValue();
structTypeNames[st.id] = name;
}
}
std::optional<FunctionStruct> getFunction(std::size_t id)
{
@@ -162,6 +169,22 @@ namespace Fig
return std::nullopt;
}
}
std::optional<FString> getStructName(std::size_t id)
{
auto it = structTypeNames.find(id);
if (it != structTypeNames.end())
{
return it->second;
}
else if (parent)
{
return parent->getFunctionName(id);
}
else
{
return std::nullopt;
}
}
bool contains(const FString &name)
{
if (variables.contains(name))