Selaa lähdekoodia

allow __py__ functions for python-only optimizations

David Rose 15 vuotta sitten
vanhempi
sitoutus
d51e49516a
1 muutettua tiedostoa jossa 33 lisäystä ja 24 poistoa
  1. 33 24
      dtool/src/interrogate/interfaceMakerPythonNative.cxx

+ 33 - 24
dtool/src/interrogate/interfaceMakerPythonNative.cxx

@@ -275,52 +275,61 @@ std::string nonClassNameFromCppName(const std::string &cppName_in)
 }
 ///////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////
-std::string  methodNameFromCppName(const std::string &cppName, const std::string &className) {
-    std::string methodName;
-    const std::string  badChars("!@#$%^&*()<>,.-=+~{}?");
-    int nextCap = 0;
-    for(std::string::const_iterator  chr = cppName.begin(); chr != cppName.end(); chr++)
+std::string
+methodNameFromCppName(const std::string &cppName, const std::string &className) {
+  std::string origName = cppName;
+
+  if (origName.substr(0, 6) == "__py__") {
+    // By convention, a leading prefix of "__py__" is stripped.  This
+    // indicates a Python-specific variant of a particular method.
+    origName = origName.substr(6);
+  }
+
+  std::string methodName;
+  const std::string  badChars("!@#$%^&*()<>,.-=+~{}?");
+  int nextCap = 0;
+  for(std::string::const_iterator  chr = origName.begin(); chr != origName.end(); chr++)
     {
-        if (badChars.find(*chr) != std::string::npos)
+      if (badChars.find(*chr) != std::string::npos)
         {
         }
-        else if (*chr == '_' || *chr == ' ')
+      else if (*chr == '_' || *chr == ' ')
         {
-            nextCap = 1;
+          nextCap = 1;
         }
-        else if (nextCap)
+      else if (nextCap)
         {
-            methodName += toupper(*chr);
-            nextCap = 0;
+          methodName += toupper(*chr);
+          nextCap = 0;
         }
-        else
+      else
         {
-            methodName += *chr;
+          methodName += *chr;
         }
     }
 
-    for(int x = 0; methodRenameDictionary[x]._from != NULL; x++)
+  for(int x = 0; methodRenameDictionary[x]._from != NULL; x++)
     {
-        if(cppName == methodRenameDictionary[x]._from)
+      if(origName == methodRenameDictionary[x]._from)
         {
-            methodName = methodRenameDictionary[x]._to;
+          methodName = methodRenameDictionary[x]._to;
         }
     }
 
-    if(className.size() > 0)
+  if(className.size() > 0)
     {
-        string LookUpName = className + '.' + cppName;
-        for(int x = 0; classRenameDictionary[x]._from != NULL; x++)
+      string LookUpName = className + '.' + cppName;
+      for(int x = 0; classRenameDictionary[x]._from != NULL; x++)
         {
-            if(LookUpName == methodRenameDictionary[x]._from)
-                methodName = methodRenameDictionary[x]._to;
+          if(LookUpName == methodRenameDictionary[x]._from)
+            methodName = methodRenameDictionary[x]._to;
         }
     }
  
 
-//    # Mangle names that happen to be python keywords so they are not anymore
-    methodName = checkKeyword(methodName);
-    return methodName;
+  //    # Mangle names that happen to be python keywords so they are not anymore
+  methodName = checkKeyword(methodName);
+  return methodName;
 }
 
 std::string  methodNameFromCppName(InterfaceMaker::Function *func, const std::string &className)