Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cppyy::GetScope to handle nested namespaces and templates #116

Merged
Merged
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
31 changes: 25 additions & 6 deletions clingwrapper/src/clingwrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,32 @@ Cppyy::TCppScope_t Cppyy::GetUnderlyingScope(TCppScope_t scope)
Cppyy::TCppScope_t Cppyy::GetScope(const std::string& name,
TCppScope_t parent_scope)
{
#ifndef NDEBUG
if (name.find("::") != std::string::npos)
throw std::runtime_error("Calling Cppyy::GetScope with qualified name '"
+ name + "'\n");
#endif // NDEBUG
if (Cppyy::TCppScope_t scope = Cpp::GetScope(name, parent_scope))
return scope;
if (!parent_scope || parent_scope == Cpp::GetGlobalScope())
if (Cppyy::TCppScope_t scope = Cpp::GetScopeFromCompleteName(name))
return scope;

return Cpp::GetScope(name, parent_scope);
// FIXME: avoid string parsing here
if (name.find('<') != std::string::npos) {
// Templated Type; May need instantiation
size_t start = name.find('<');
size_t end = name.rfind('>');
std::string params = name.substr(start + 1, end - start - 1);

std::string pure_name = name.substr(0, start);
Cppyy::TCppScope_t scope = Cpp::GetScope(pure_name, parent_scope);
if (!scope && (!parent_scope || parent_scope == Cpp::GetGlobalScope()))
scope = Cpp::GetScopeFromCompleteName(pure_name);
Comment on lines +582 to +584
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cppyy::TCppScope_t scope = Cpp::GetScope(pure_name, parent_scope);
if (!scope && (!parent_scope || parent_scope == Cpp::GetGlobalScope()))
scope = Cpp::GetScopeFromCompleteName(pure_name);
Cppyy::TCppScope_t scope = Cpp::GetScope(pure_name, parent_scope)
if (scope)
return scope;
if (!parent_scope || parent_scope == Cpp::GetGlobalScope())
scope = Cpp::GetScopeFromCompleteName(pure_name);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not returning the scope here. We are using scope to InstantiateTemplate and returning the template.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok, good point..


if (Cppyy::IsTemplate(scope)) {
std::vector<Cpp::TemplateArgInfo> templ_params;
if (!Cppyy::AppendTypesSlow(params, templ_params))
return Cpp::InstantiateTemplate(scope, templ_params.data(),
templ_params.size());
}
}
return nullptr;
}

Cppyy::TCppScope_t Cppyy::GetFullScope(const std::string& name)
Expand Down
Loading