[cfe-dev] vector function return type

Eli Friedman eli.friedman at gmail.com
Wed Dec 2 19:12:50 PST 2009


On Wed, Dec 2, 2009 at 6:34 PM, John Thompson
<john.thompson.jtsoftware at gmail.com> wrote:
> I'm looking at bug 5650 about using vector return types on functions, which
> is kind of difficult, not knowing all the ramifications of the type system.
>
> For example, I need to change the return type of a function declaration, but
> there aren't any accessors for that.  Is that because it's complicated?

It's not ridiculously complicated, but it's messy enough that you'll
want to write a helper method; something like the following should
work (not compiled, but should be approximately correct):
QualType NewResultTy; /* Your new result type */
QualType NewType;
if (const FunctionProtoType* FPT = FD->getType()-->getAs<FunctionProtoType>())
  NewType = Context.getFunctionType(NewResultTy,
FPT->arg_type_begin(), FPT->getNumArgs(), FPT->isVariadic(), 0,
FPT->hasExceptionSpec(), FPT->hasAnyxceptionSpec(),
FPT->getNumExceptions(), FPT->exception_begin(),
FPT->getNoReturnAttr());
else
  NewType = Context.getFunctionTypeNoProto(NewResultType,
FD->getType()->getAs<FunctionType>()->getNoReturnAttr());
FD->setType(NewType);

> Anyway, I've taken a stab at the bug fix, but I'm guessing it's not the
> right approach.  I added a couple of setters to FunctionDecl and
> FunctionType for the return type, not know if this is doable.  In the
> vector_size handler, I don't try to handle all the other types that need
> handling at this point, just wanting to get the vector return types to work
> as a first step.

You can't add a setter to FunctionType because the type system depends
on types being immutable.

-Eli




More information about the cfe-dev mailing list