Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,9 +1966,24 @@ void collect_type_info(const FunctionDecl* FD, QualType& QT,
PrintingPolicy Policy(C.getPrintingPolicy());
Policy.SuppressElaboration = true;
refType = kNotReference;
if (QT->isRecordType() && forArgument) {
get_type_as_string(QT, type_name, C, Policy);
return;
if (QT->isRecordType()) {
if (forArgument) {
get_type_as_string(QT, type_name, C, Policy);
return;
}
if (auto* CXXRD = QT->getAsCXXRecordDecl()) {
if (CXXRD->isLambda()) {
std::string fn_name;
llvm::raw_string_ostream stream(fn_name);
Policy.FullyQualifiedName = true;
Policy.SuppressUnwrittenScope = true;
FD->getNameForDiagnostic(stream, Policy,
/*Qualified=*/false);
type_name = "__internal_CppInterOp::function<decltype(" + fn_name +
")>::result_type";
return;
}
}
}
if (QT->isFunctionPointerType()) {
std::string fp_typedef_name;
Expand Down Expand Up @@ -3223,6 +3238,17 @@ TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/,
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
}

I->declare(R"(
namespace __internal_CppInterOp {
template <typename Signature>
struct function;
template <typename Res, typename... ArgTypes>
struct function<Res(ArgTypes...)> {
typedef Res result_type;
};
} // namespace __internal_CppInterOp
)");

sInterpreters->emplace_back(I, /*Owned=*/true);

return I;
Expand Down
13 changes: 13 additions & 0 deletions unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,19 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
EXPECT_TRUE(obj);
Cpp::Destruct(obj, MyNameSpace_TemplatedEnum_instantiated);
obj = nullptr;

Cpp::Declare(R"(
auto get_fn(int x) { return [x](int y){ return x + y; }; }
)");

Cpp::TCppScope_t get_fn = Cpp::GetNamed("get_fn");
EXPECT_TRUE(get_fn);

auto get_fn_callable = Cpp::MakeFunctionCallable(get_fn);
EXPECT_EQ(get_fn_callable.getKind(), Cpp::JitCall::kGenericCall);

EXPECT_TRUE(Cpp::IsLambdaClass(Cpp::GetFunctionReturnType(get_fn)));
EXPECT_FALSE(Cpp::IsLambdaClass(Cpp::GetFunctionReturnType(bar)));
}

TEST(FunctionReflectionTest, IsConstMethod) {
Expand Down
Loading