TypeGraphParser: Fix lifetimes of ContainerInfo objects

Containers store references to ContainerInfos, so the ContainerInfos
must live beyond the stack they were created on. Use static variables
for simplicity.
This commit is contained in:
Alastair Robertson 2023-07-18 05:10:44 -07:00 committed by Alastair Robertson
parent 4d96848bdb
commit b4b3e86c47

View File

@ -53,23 +53,23 @@ Primitive::Kind getKind(std::string_view kindStr) {
std::string{kindStr}}; std::string{kindStr}};
} }
ContainerInfo getContainerInfo(std::string_view name) { ContainerInfo& getContainerInfo(std::string_view name) {
if (name == "std::vector") { if (name == "std::vector") {
ContainerInfo info{"std::vector", SEQ_TYPE, "vector"}; static ContainerInfo info{"std::vector", SEQ_TYPE, "vector"};
info.stubTemplateParams = {1}; info.stubTemplateParams = {1};
return info; return info;
} }
if (name == "std::map") { if (name == "std::map") {
ContainerInfo info{"std::map", STD_MAP_TYPE, "utility"}; static ContainerInfo info{"std::map", STD_MAP_TYPE, "utility"};
info.stubTemplateParams = {2, 3}; info.stubTemplateParams = {2, 3};
return info; return info;
} }
if (name == "std::pair") { if (name == "std::pair") {
ContainerInfo info{"std::pair", SEQ_TYPE, "utility"}; static ContainerInfo info{"std::pair", SEQ_TYPE, "utility"};
return info; return info;
} }
if (name == "std::allocator") { if (name == "std::allocator") {
ContainerInfo info{"std::allocator", DUMMY_TYPE, "memory"}; static ContainerInfo info{"std::allocator", DUMMY_TYPE, "memory"};
return info; return info;
} }
throw TypeGraphParserError{"Unsupported container: " + std::string{name}}; throw TypeGraphParserError{"Unsupported container: " + std::string{name}};
@ -242,7 +242,7 @@ Type& TypeGraphParser::parseType(std::string_view& input, size_t rootIndent) {
auto nameEndPos = line.find('(', nameStartPos + 1); auto nameEndPos = line.find('(', nameStartPos + 1);
auto name = line.substr(nameStartPos, nameEndPos - nameStartPos - 1); auto name = line.substr(nameStartPos, nameEndPos - nameStartPos - 1);
auto info = getContainerInfo(name); auto& info = getContainerInfo(name);
auto size = parseIntAttribute(line, nodeTypeName, "size: "); auto size = parseIntAttribute(line, nodeTypeName, "size: ");