@@ -719,48 +719,41 @@ namespace Cpp {
719719 return ComputeBaseOffset (getSema ().getASTContext (), DCXXRD, Paths.front ());
720720 }
721721
722- void GetClassMethods (TCppScope_t klass, std::vector<TCppFunction_t> &methods) {
723- if (!klass) return ;
724-
725- auto *D = (clang::Decl *) klass;
726-
727- if (auto *TD = dyn_cast<TypedefNameDecl>(D))
728- D = GetScopeFromType (TD->getUnderlyingType ());
729-
730- if (D && isa<CXXRecordDecl>(D)) {
731- auto * CXXRD = dyn_cast<CXXRecordDecl>(D);
732- getSema ().ForceDeclarationOfImplicitMembers (CXXRD);
733- for (Decl* DI : CXXRD->decls ()) {
734- if (auto * MD = dyn_cast<CXXMethodDecl>(DI))
735- methods.push_back (MD);
736- else if (auto * USD = dyn_cast<UsingShadowDecl>(DI))
737- if (auto * MD = dyn_cast<CXXMethodDecl>(USD->getTargetDecl ()))
738- methods.push_back (MD);
739- }
740- }
741- }
742-
743- void GetFunctionTemplatedDecls (TCppScope_t klass, std::vector<TCppFunction_t> &methods) {
744- if (!klass) return ;
722+ template <typename DeclType>
723+ static void GetClassDecls (TCppScope_t klass,
724+ std::vector<TCppFunction_t>& methods) {
725+ if (!klass)
726+ return ;
745727
746728 auto * D = (clang::Decl*)klass;
747729
748730 if (auto * TD = dyn_cast<TypedefNameDecl>(D))
749731 D = GetScopeFromType (TD->getUnderlyingType ());
750732
751- if (D && isa<CXXRecordDecl>(D)) {
752- auto * CXXRD = dyn_cast<CXXRecordDecl>(D);
753- getSema ().ForceDeclarationOfImplicitMembers (CXXRD);
754- for (Decl* DI : CXXRD->decls ()) {
755- if (auto * MD = dyn_cast<FunctionTemplateDecl>(DI))
733+ if (!D || !isa<CXXRecordDecl>(D))
734+ return ;
735+
736+ auto * CXXRD = dyn_cast<CXXRecordDecl>(D);
737+ getSema ().ForceDeclarationOfImplicitMembers (CXXRD);
738+ for (Decl* DI : CXXRD->decls ()) {
739+ if (auto * MD = dyn_cast<DeclType>(DI))
740+ methods.push_back (MD);
741+ else if (auto * USD = dyn_cast<UsingShadowDecl>(DI))
742+ if (auto * MD = dyn_cast<DeclType>(USD->getTargetDecl ()))
756743 methods.push_back (MD);
757- else if (auto * USD = dyn_cast<UsingShadowDecl>(DI))
758- if (auto * MD = dyn_cast<FunctionTemplateDecl>(USD->getTargetDecl ()))
759- methods.push_back (MD);
760- }
761744 }
762745 }
763746
747+ void GetClassMethods (TCppScope_t klass,
748+ std::vector<TCppFunction_t>& methods) {
749+ GetClassDecls<CXXMethodDecl>(klass, methods);
750+ }
751+
752+ void GetFunctionTemplatedDecls (TCppScope_t klass,
753+ std::vector<TCppFunction_t>& methods) {
754+ GetClassDecls<FunctionTemplateDecl>(klass, methods);
755+ }
756+
764757 bool HasDefaultConstructor (TCppScope_t scope) {
765758 auto *D = (clang::Decl *) scope;
766759
@@ -883,9 +876,7 @@ namespace Cpp {
883876 return 0 ;
884877 }
885878
886- std::string GetFunctionSignature (
887- TCppFunction_t func) { // FIXME : Doesn't work for template functions as
888- // it does in cling
879+ std::string GetFunctionSignature (TCppFunction_t func) {
889880 if (!func)
890881 return " <unknown>" ;
891882
@@ -903,18 +894,6 @@ namespace Cpp {
903894 return Signature;
904895 }
905896
906- // FIXME: else if (auto *FD = llvm::dyn_cast<FunctionTemplateDecl>(D)) {
907- // std::string Signature;
908- // raw_string_ostream SS(Signature);
909- // PrintingPolicy Policy = getASTContext().getPrintingPolicy();
910- // // Skip printing the body
911- // Policy.TerseOutput = true;
912- // Policy.FullyQualifiedName = true;
913- // Policy.SuppressDefaultTemplateArgs = false;
914- // FD->print(SS, Policy);
915- // SS.flush();
916- // return Signature;
917- // }
918897 return " <unknown>" ;
919898 }
920899
@@ -954,7 +933,7 @@ namespace Cpp {
954933 {
955934 DeclContext *Within = 0 ;
956935 if (parent) {
957- auto * D = (Decl *)parent;
936+ auto * D = (Decl*)parent;
958937 Within = llvm::dyn_cast<DeclContext>(D);
959938 }
960939
@@ -970,17 +949,16 @@ namespace Cpp {
970949 return true ;
971950 }
972951
973- std::vector<TCppFunction_t> GetTemplatedMethods (const std::string& name,
974- TCppScope_t parent ) {
952+ void GetClassTemplatedMethods (const std::string& name, TCppScope_t parent ,
953+ std::vector<TCppFunction_t>& funcs ) {
975954
976955 auto * D = (Decl*)parent;
977956
978957 if (!parent || name.empty ())
979- return {} ;
958+ return ;
980959
981960 D = GetUnderlyingScope (D);
982961
983- std::vector<TCppFunction_t> funcs;
984962 llvm::StringRef Name (name);
985963 auto & S = getSema ();
986964 DeclarationName DName = &getASTContext ().Idents .get (name);
@@ -990,34 +968,26 @@ namespace Cpp {
990968 Cpp_utils::Lookup::Named (&S, R, Decl::castToDeclContext (D));
991969
992970 if (R.empty ())
993- return {} ;
971+ return ;
994972
995973 R.resolveKind ();
996974
997- for (auto * Found : R) {
975+ for (auto * Found : R)
998976 if (llvm::isa<FunctionTemplateDecl>(Found))
999977 funcs.push_back (Found);
1000- }
1001-
1002- if (!funcs.empty ())
1003- return funcs;
1004-
1005- return {};
1006978 }
1007979
1008980 TCppFunction_t
1009981 BestTemplateFunctionMatch (const std::vector<TCppFunction_t>& candidates,
1010982 const std::vector<TemplateArgInfo>& explicit_types,
1011983 const std::vector<TemplateArgInfo>& arg_types) {
1012984
1013- int k = 1 ;
1014985 for (const auto & candidate : candidates) {
1015986 auto * TFD = (FunctionTemplateDecl*)candidate;
1016987 clang::TemplateParameterList* tpl = TFD->getTemplateParameters ();
1017988
1018989 if (tpl->size () < explicit_types.size ()) {
1019990 // template parameter size does not match
1020- ++k;
1021991 continue ;
1022992 }
1023993
@@ -1029,7 +999,6 @@ namespace Cpp {
1029999
10301000 // Check if number of function parameters match
10311001 if (func->getNumParams () != arg_types.size ()) {
1032- ++k;
10331002 continue ;
10341003 }
10351004
@@ -1051,7 +1020,6 @@ namespace Cpp {
10511020 return instantiated;
10521021
10531022 else {
1054- k++;
10551023 continue ;
10561024 }
10571025 }
0 commit comments