[pypy-commit] pypy reflex-support: templated methods support for CINT backend

wlav noreply at buildbot.pypy.org
Sat Mar 23 01:49:12 CET 2013


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r62675:0fc3d6fef5b2
Date: 2013-03-22 16:25 -0700
http://bitbucket.org/pypy/pypy/changeset/0fc3d6fef5b2/

Log:	templated methods support for CINT backend

diff --git a/pypy/module/cppyy/src/cintcwrapper.cxx b/pypy/module/cppyy/src/cintcwrapper.cxx
--- a/pypy/module/cppyy/src/cintcwrapper.cxx
+++ b/pypy/module/cppyy/src/cintcwrapper.cxx
@@ -675,7 +675,13 @@
 
 char* cppyy_method_name(cppyy_scope_t handle, cppyy_index_t idx) {
     TFunction* f = type_get_method(handle, idx);
-    return cppstring_to_cstring(f->GetName());
+    std::string name = f->GetName();
+    TClassRef& cr = type_from_handle(handle);
+    if (cr.GetClass() && cppyy_is_constructor(handle, idx))
+        return cppstring_to_cstring(name);
+    if (cppyy_method_is_template(handle, idx))
+       return cppstring_to_cstring(name.substr(0, name.find('<')));
+    return cppstring_to_cstring(name);
 }
 
 char* cppyy_method_result_type(cppyy_scope_t handle, cppyy_index_t idx) {
@@ -726,6 +732,29 @@
 }
 
 
+int cppyy_method_is_template(cppyy_scope_t handle, cppyy_index_t idx) {
+    TClassRef& cr = type_from_handle(handle);
+    TFunction* f = type_get_method(handle, idx);
+    std::string name = f->GetName();
+    return (name[name.size()-1] == '>') && (name.find('<') != std::string::npos);
+}
+
+int cppyy_method_num_template_args(cppyy_scope_t /*handle*/, cppyy_index_t /*idx*/) {
+// TODO: somehow count from the actual arguments
+    return 1;
+}
+
+char* cppyy_method_template_arg_name(
+        cppyy_scope_t handle, cppyy_index_t idx, cppyy_index_t /*iarg*/) {
+// TODO: return only the name for the requested arg
+    TClassRef& cr = type_from_handle(handle);
+    TFunction* f = type_get_method(handle, idx);
+    std::string name = f->GetName();
+    std::string::size_type pos = name.find('<');
+    return cppstring_to_cstring(resolve_typedef(name.substr(pos+1, name.size()-pos-2)));
+}
+
+
 cppyy_method_t cppyy_get_method(cppyy_scope_t handle, cppyy_index_t idx) {
     TClassRef& cr = type_from_handle(handle);
     TFunction* f = type_get_method(handle, idx);
diff --git a/pypy/module/cppyy/src/reflexcwrapper.cxx b/pypy/module/cppyy/src/reflexcwrapper.cxx
--- a/pypy/module/cppyy/src/reflexcwrapper.cxx
+++ b/pypy/module/cppyy/src/reflexcwrapper.cxx
@@ -386,7 +386,7 @@
         name = s.Name(Reflex::FINAL);   // to get proper name for templates
     else if (m.IsTemplateInstance()) {
         name = m.Name();
-        std::string::size_type pos = name.find("<");
+        std::string::size_type pos = name.find('<');
         name = name.substr(0, pos);     // strip template argument portion for overload
     } else
         name = m.Name();
@@ -448,6 +448,7 @@
     return cppstring_to_cstring(sig.str());
 }
 
+
 int cppyy_method_is_template(cppyy_scope_t handle, cppyy_index_t method_index) {
     Reflex::Scope s = scope_from_handle(handle);
     Reflex::Member m = s.FunctionMemberAt(method_index);
@@ -470,6 +471,7 @@
        m.TemplateArgumentAt(iarg).Name(Reflex::SCOPED|Reflex::QUALIFIED));
 }
 
+
 cppyy_method_t cppyy_get_method(cppyy_scope_t handle, cppyy_index_t method_index) {
     Reflex::Scope s = scope_from_handle(handle);
     Reflex::Member m = s.FunctionMemberAt(method_index);
diff --git a/pypy/module/cppyy/test/advancedcpp_LinkDef.h b/pypy/module/cppyy/test/advancedcpp_LinkDef.h
--- a/pypy/module/cppyy/test/advancedcpp_LinkDef.h
+++ b/pypy/module/cppyy/test/advancedcpp_LinkDef.h
@@ -66,4 +66,10 @@
 
 #pragma link C++ class new_overloader;
 
+#pragma link C++ class my_templated_class<std::vector<float> >;
+#pragma link C++ function my_templated_function<char>(char);
+#pragma link C++ function my_templated_function<double>(double);
+#pragma link C++ class my_templated_method_class;
+#pragma link C++ typedef my_typedef_t;
+
 #endif


More information about the pypy-commit mailing list