Skip to content

Commit ce32d49

Browse files
add ReduceReturnType (#164)
this wrappers the given function by typecasting the return to reduce type this is required for test01_reduce_binary
1 parent bf8374e commit ce32d49

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

clingwrapper/src/clingwrapper.cxx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ Cppyy::TCppType_t Cppyy::ResolveEnumPointerType(TCppType_t type) {
486486
}
487487

488488
Cppyy::TCppType_t Cppyy::ResolveType(TCppType_t type) {
489+
if (!type) return type;
490+
489491
Cppyy::TCppType_t canonType = Cpp::GetCanonicalType(type);
490492

491493
if (Cpp::IsEnumType(canonType)) {
@@ -1975,6 +1977,33 @@ bool Cppyy::IsConstVar(TCppScope_t var)
19751977
return Cpp::IsConstVariable(var);
19761978
}
19771979

1980+
Cppyy::TCppScope_t Cppyy::ReduceReturnType(TCppScope_t fn, TCppType_t reduce) {
1981+
std::string fn_name = Cpp::GetQualifiedCompleteName(fn);
1982+
std::string signature = Cppyy::GetMethodSignature(fn, true);
1983+
std::string result_type = Cppyy::GetTypeAsString(reduce);
1984+
1985+
std::ostringstream call;
1986+
call << "(";
1987+
for (size_t i = 0, n = Cppyy::GetMethodNumArgs(fn); i < n; i++) {
1988+
call << Cppyy::GetMethodArgName(fn, i);
1989+
if (i != n - 1)
1990+
call << ", ";
1991+
}
1992+
call << ")";
1993+
1994+
std::ostringstream code;
1995+
static int i = 0;
1996+
std::string name = "reduced_function_" + std::to_string(++i);
1997+
code << "namespace __cppyy_internal_wrap_g {\n"
1998+
<< result_type << " " << name << signature << "{" << "return (" << result_type << ")::" << fn_name << call.str() << "; }\n"
1999+
<< "}\n";
2000+
if (Cppyy::Compile(code.str().c_str())) {
2001+
TCppScope_t res = Cpp::GetNamed(name, Cpp::GetScope("__cppyy_internal_wrap_g"));
2002+
if (res) return res;
2003+
}
2004+
return fn;
2005+
}
2006+
19782007
// bool Cppyy::IsEnumData(TCppScope_t scope, TCppIndex_t idata)
19792008
// {
19802009
// // TODO: currently, ROOT/meta does not properly distinguish between variables of enum

clingwrapper/src/cpp_cppyy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ namespace Cppyy {
380380
bool IsStaticDatamember(TCppScope_t var);
381381
RPY_EXPORTED
382382
bool IsConstVar(TCppScope_t var);
383+
RPY_EXPORTED
384+
TCppScope_t ReduceReturnType(TCppScope_t fn, TCppType_t reduce);
383385
// RPY_EXPORTED
384386
// bool IsEnumData(TCppScope_t scope, TCppIndex_t idata);
385387
RPY_EXPORTED

0 commit comments

Comments
 (0)