Skip to content

Commit 6a9ae67

Browse files
Update Cppyy::GetScope to handle nested namespaces and templates
1 parent bfea6ba commit 6a9ae67

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

clingwrapper/src/clingwrapper.cxx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,32 @@ Cppyy::TCppScope_t Cppyy::GetScope(const std::string& name,
571571
+ name + "'\n");
572572
#endif // NDEBUG
573573

574-
return Cpp::GetScope(name, parent_scope);
574+
Cppyy::TCppScope_t scope = Cpp::GetScope(name, parent_scope);
575+
if (!scope && (parent_scope == nullptr || parent_scope == Cpp::GetGlobalScope()))
576+
scope = Cpp::GetScopeFromCompleteName(name);
577+
if (scope)
578+
return scope;
579+
580+
if (name.find('<') != std::string::npos) {
581+
// Templated Type; May need instantiation
582+
size_t start = name.find('<');
583+
size_t end = name.rfind('>');
584+
std::string params = name.substr(start + 1, end - start - 1);
585+
586+
std::string pure_name = name.substr(0, start);
587+
scope = Cpp::GetScope(pure_name, parent_scope);
588+
if (!scope && (parent_scope == nullptr || parent_scope == Cpp::GetGlobalScope()))
589+
scope = Cpp::GetScopeFromCompleteName(pure_name);
590+
if (!scope)
591+
return nullptr;
592+
593+
if (Cppyy::IsTemplate(scope)) {
594+
std::vector<Cpp::TemplateArgInfo> templ_params;
595+
if (!Cppyy::AppendTypesSlow(params, templ_params))
596+
return Cpp::InstantiateTemplate(scope, templ_params.data(), templ_params.size());
597+
}
598+
}
599+
return nullptr;
575600
}
576601

577602
Cppyy::TCppScope_t Cppyy::GetFullScope(const std::string& name)

0 commit comments

Comments
 (0)