Fix extra commentability on prototype return value

This commit is contained in:
Ivan Krysak
2026-04-30 12:54:09 +00:00
committed by Pietro Fezzardi
parent 381c834cce
commit ae17e8987a
+10 -2
View File
@@ -82,10 +82,18 @@ private:
return Name;
}
std::optional<ptml::CTokenEmitter::Region> commentableReturnValueGuard() {
std::optional<ptml::CTokenEmitter::Region>
commentableReturnValueGuard(DeclaratorInfo const *Declarator) {
if (OutermostFunctionType == nullptr)
return std::nullopt;
// Only emitting the return value guard when parameters are available might
// look weird at the first sight, but when we are emitting a prototype
// without parameter information (the typedef), it's weird to allow adding
// comments to a return type that will show up elsewhere.
if (not Declarator->Parameters)
return std::nullopt;
auto FTHandle = OutermostFunctionType.getHandle();
auto FTLoc = pipeline::locationFromString(revng::ranks::TypeDefinition,
FTHandle);
@@ -141,7 +149,7 @@ private:
}
{
auto Guard = commentableReturnValueGuard();
auto Guard = commentableReturnValueGuard(Declarator);
// Recurse through the declaration, pushing each level onto the stack
// until a terminal type is encountered. Primitive types as well as