Skip to content

Take function pointer types from the AST instead of parsing type strings - #152

Open
guitargeek wants to merge 1 commit into
compiler-research:mainfrom
guitargeek:fnptr-types-from-ast
Open

guitargeek wants to merge 1 commit into
compiler-research:mainfrom
guitargeek:fnptr-types-from-ast

Conversation

@guitargeek

Copy link
Copy Markdown
Collaborator

The function pointer branches of CreateExecutor() and CreateConverter() sliced the printed type string (e.g. "int (*)(double, char)") to recover the return type and the argument list, as flagged by a "find better way of finding the type" TODO. Replace this with a new interop::GetFnTypeSigAsString(), built on GetFnTypeSig(), which asks clang for the pointee function prototype's return and parameter types. GetFnTypeSig() now guards against non-prototype types, as Cpp::GetFnTypeSignature() crashes on those.

This fixes two bugs of the string parsing:

  • the type-based executor path removed all spaces before slicing, so any multi-word return type such as unsigned int (*)() broke with an attempt to compile std::function<unsignedint()>;
  • member function pointers matched the "::*)" check and produced a bogus std::function. They are not function pointers and are now rejected (returning one yields None as before, a data member of that type is reported as unconvertible).

The string-based overloads keep the type from the lookup that ResolveName() performed anyway, and the regex used by the string-based CreateConverter() is dropped.

The function pointer branches of CreateExecutor() and CreateConverter()
sliced the printed type string (e.g. "int (*)(double, char)") to recover
the return type and the argument list, as flagged by a "find better way
of finding the type" TODO. Replace this with a new
interop::GetFnTypeSigAsString(), built on GetFnTypeSig(), which asks
clang for the pointee function prototype's return and parameter types.
GetFnTypeSig() now guards against non-prototype types, as
Cpp::GetFnTypeSignature() crashes on those.

This fixes two bugs of the string parsing:

- the type-based executor path removed all spaces before slicing, so
  any multi-word return type such as `unsigned int (*)()` broke with
  an attempt to compile `std::function<unsignedint()>`;
- member function pointers matched the "::*)" check and produced a
  bogus std::function. They are not function pointers and are now
  rejected (returning one yields None as before, a data member of that
  type is reported as unconvertible).

The string-based overloads keep the type from the lookup that
ResolveName() performed anyway, and the regex used by the string-based
CreateConverter() is dropped.
@guitargeek guitargeek self-assigned this Oct 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant