@@ -1367,33 +1367,58 @@ std::string Cppyy::GetMethodArgDefault(TCppMethod_t method, TCppIndex_t iarg)
13671367 return Cpp::GetFunctionArgDefault (method, iarg);
13681368}
13691369
1370+ static inline Cppyy::TCppIndex_t ArgSimilarityScore (Cppyy::TCppType_t argqtp,
1371+ Cppyy::TCppType_t reqqtp) {
1372+ // This scoring is not based on any particular rules
1373+ if (Cpp::IsSameType (argqtp, reqqtp))
1374+ return 0 ; // Best match
1375+ else if ((Cpp::IsSignedIntegerType (argqtp) &&
1376+ Cpp::IsSignedIntegerType (reqqtp)) ||
1377+ (Cpp::IsUnsignedIntegerType (argqtp) &&
1378+ Cpp::IsUnsignedIntegerType (reqqtp)) ||
1379+ (Cpp::IsFloatingType (argqtp) && Cpp::IsFloatingType (reqqtp)))
1380+ return 1 ;
1381+ else if ((Cpp::IsSignedIntegerType (argqtp) &&
1382+ Cpp::IsUnsignedIntegerType (reqqtp)) ||
1383+ (Cpp::IsFloatingType (argqtp) && Cpp::IsUnsignedIntegerType (reqqtp)))
1384+ return 2 ;
1385+ else if ((Cpp::IsIntegerType (argqtp) && Cpp::IsIntegerType (reqqtp)))
1386+ return 3 ;
1387+ else if ((Cpp::IsIntegralType (argqtp) && Cpp::IsIntegralType (reqqtp)))
1388+ return 4 ;
1389+ else if ((Cpp::IsVoidPointerType (argqtp) && Cpp::IsPointerType (reqqtp)))
1390+ return 5 ;
1391+ else
1392+ return 10 ; // Penalize heavily for no possible match
1393+ }
1394+
13701395Cppyy::TCppIndex_t Cppyy::CompareMethodArgType (TCppMethod_t method, TCppIndex_t iarg, const std::string &req_type)
13711396{
1372- // if (method) {
1373- // TFunction* f = m2f (method);
1374- // TMethodArg* arg = (TMethodArg *)f->GetListOfMethodArgs()->At((int)iarg );
1375- // void *argqtp = gInterpreter->TypeInfo_QualTypePtr(arg->GetTypeInfo());
1376-
1377- // TypeInfo_t *reqti = gInterpreter->TypeInfo_Factory(req_type.c_str() );
1378- // void *reqqtp = gInterpreter->TypeInfo_QualTypePtr(reqti);
1379-
1380- // if (ArgSimilarityScore(argqtp, reqqtp) < 10) {
1381- // return ArgSimilarityScore(argqtp, reqqtp);
1382- // }
1383- // else { // Match using underlying types
1384- // if(gInterpreter->IsPointerType(argqtp))
1385- // argqtp = gInterpreter->TypeInfo_QualTypePtr(gInterpreter->GetPointerType(argqtp) );
1386-
1387- // // Handles reference types and strips qualifiers
1388- // TypeInfo_t *arg_ul = gInterpreter->GetNonReferenceType(argqtp );
1389- // TypeInfo_t *req_ul = gInterpreter->GetNonReferenceType(reqqtp) ;
1390- // argqtp = gInterpreter->TypeInfo_QualTypePtr(gInterpreter->GetUnqualifiedType(gInterpreter->TypeInfo_QualTypePtr(arg_ul)));
1391- // reqqtp = gInterpreter->TypeInfo_QualTypePtr(gInterpreter->GetUnqualifiedType(gInterpreter->TypeInfo_QualTypePtr(req_ul)) );
1392-
1393- // return ArgSimilarityScore(argqtp, reqqtp );
1394- // }
1395- // }
1396- return 0 ; // Method is not valid
1397+ if (method) {
1398+ Cppyy::TCppType_t type_a = GetMethodArgType (method, iarg );
1399+ Cppyy::TCppType_t type_b = GetType (req_type );
1400+
1401+ if ( ArgSimilarityScore (type_a, type_b) < 10 ) {
1402+ return ArgSimilarityScore (type_a, type_b );
1403+ } else { // Match using underlying types
1404+ if ( Cpp::IsPointerType (type_a))
1405+ type_a = Cpp::GetPointeeType (type_a);
1406+
1407+ if ( ArgSimilarityScore (type_a, type_b) > 10 ) {
1408+ // Handles reference types and strips qualifiers
1409+ type_a = Cpp::GetNonReferenceType (type_a);
1410+ type_b = Cpp::GetNonReferenceType (type_b );
1411+ if ( ArgSimilarityScore (type_a, type_b) > 10 ) {
1412+ type_a = Cpp::GetUnqualifiedType (type_a);
1413+ type_b = Cpp::GetUnqualifiedType (type_b );
1414+ return ( bool ) ArgSimilarityScore (type_a, type_b) < 10 ;
1415+ }
1416+ return ArgSimilarityScore (type_a, type_b );
1417+ }
1418+ return ArgSimilarityScore (type_a, type_b );
1419+ }
1420+ }
1421+ return 100 ; // Method is not valid
13971422}
13981423
13991424std::string Cppyy::GetMethodSignature (TCppMethod_t method, bool show_formal_args, TCppIndex_t max_args)
0 commit comments