tbv2: fix thrift isset with ClangTypeParser

Some of the logic that makes Thrift isset work for TreeBuilder-v2 in DrgnParser
(JIT OIL) wasn't ported to ClangTypeParser meaning it doesn't work in
Ahead-of-Time (AoT) OIL.

Add the template parameter name reconstruction for enum values to
ClangTypeParser.

Test plan:
- Tested with Thrift isset enabled on an internal type. Doesn't build before,
  does build after.
This commit is contained in:
Jake Hillion 2024-01-17 14:05:58 +00:00 committed by Jake Hillion
parent 40af807d8b
commit 819914beca

View File

@ -235,9 +235,29 @@ std::optional<TemplateParam> ClangTypeParser::enumerateTemplateParam(
} }
case clang::TemplateArgument::Integral: { case clang::TemplateArgument::Integral: {
auto& ty = enumerateType(*p.getIntegralType()); auto& ty = enumerateType(*p.getIntegralType());
llvm::SmallString<32> val;
p.getAsIntegral().toString(val); std::string value;
return TemplateParam{ty, std::string(val)}; if (const auto* e = dynamic_cast<const Enum*>(&ty)) {
const auto& eTy =
llvm::cast<const clang::EnumType>(*p.getIntegralType());
for (const auto* enumerator : eTy.getDecl()->enumerators()) {
if (enumerator->getInitVal() == p.getAsIntegral()) {
value = e->inputName();
value += "::";
value += enumerator->getName();
break;
}
}
if (value.empty()) {
throw std::runtime_error("unable to find enum name for value");
}
} else {
llvm::SmallString<32> val;
p.getAsIntegral().toString(val);
value = std::string{val};
}
return TemplateParam{ty, value};
} }
case clang::TemplateArgument::Template: { case clang::TemplateArgument::Template: {
return enumerateTemplateTemplateParam(p.getAsTemplate()); return enumerateTemplateTemplateParam(p.getAsTemplate());