File tree Expand file tree Collapse file tree 3 files changed +17
-15
lines changed
include/clang/Interpreter Expand file tree Collapse file tree 3 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 12
12
13
13
#include < cassert>
14
14
#include < cstdint>
15
+ #include < set>
15
16
#include < string>
16
17
#include < vector>
17
18
@@ -668,7 +669,8 @@ namespace Cpp {
668
669
const std::vector<TemplateArgInfo>& explicit_types,
669
670
const std::vector<TemplateArgInfo>& arg_types);
670
671
671
- CPPINTEROP_API std::vector<std::string> GetAllCppNames (TCppScope_t scope);
672
+ CPPINTEROP_API void GetAllCppNames (TCppScope_t scope,
673
+ std::set<std::string>& names);
672
674
673
675
CPPINTEROP_API void DumpScope (TCppScope_t scope);
674
676
Original file line number Diff line number Diff line change 34
34
#include " llvm/Support/Debug.h"
35
35
#include " llvm/Support/raw_os_ostream.h"
36
36
37
+ #include < set>
37
38
#include < sstream>
38
39
#include < string>
39
40
@@ -3108,7 +3109,7 @@ namespace Cpp {
3108
3109
return nullptr ;
3109
3110
}
3110
3111
3111
- std::vector <std::string> GetAllCppNames (TCppScope_t scope ) {
3112
+ void GetAllCppNames (TCppScope_t scope, std::set <std::string>& names ) {
3112
3113
auto *D = (clang::Decl *)scope;
3113
3114
clang::DeclContext *DC;
3114
3115
clang::DeclContext::decl_iterator decl;
@@ -3124,17 +3125,14 @@ namespace Cpp {
3124
3125
DC = clang::TranslationUnitDecl::castToDeclContext (TUD);
3125
3126
decl = DC->decls_begin ();
3126
3127
} else {
3127
- return {} ;
3128
+ return ;
3128
3129
}
3129
3130
3130
- std::vector<std::string> names;
3131
3131
for (/* decl set above */ ; decl != DC->decls_end (); decl++) {
3132
3132
if (auto *ND = llvm::dyn_cast_or_null<NamedDecl>(*decl)) {
3133
- names.push_back (ND->getNameAsString ());
3133
+ names.insert (ND->getNameAsString ());
3134
3134
}
3135
3135
}
3136
-
3137
- return names;
3138
3136
}
3139
3137
3140
3138
void GetEnums (TCppScope_t scope, std::vector<std::string>& Result) {
Original file line number Diff line number Diff line change @@ -716,14 +716,16 @@ TEST(ScopeReflectionTest, GetAllCppNames) {
716
716
717
717
GetAllTopLevelDecls (code, Decls);
718
718
719
- auto test_get_all_cpp_names = [](Decl *D, const std::vector<std::string> &truth_names) {
720
- auto names = Cpp::GetAllCppNames (D);
721
- EXPECT_EQ (names.size (), truth_names.size ());
722
-
723
- for (unsigned i = 0 ; i < truth_names.size () && i < names.size (); i++) {
724
- EXPECT_EQ (names[i], truth_names[i]);
725
- }
726
- };
719
+ auto test_get_all_cpp_names =
720
+ [](Decl* D, const std::vector<std::string>& truth_names) {
721
+ std::set<std::string> names;
722
+ Cpp::GetAllCppNames (D, names);
723
+ EXPECT_EQ (names.size (), truth_names.size ());
724
+
725
+ for (unsigned i = 0 ; i < truth_names.size () && i < names.size (); i++) {
726
+ EXPECT_TRUE (names.find (truth_names[i]) != names.end ());
727
+ }
728
+ };
727
729
728
730
test_get_all_cpp_names (Decls[0 ], {" a" });
729
731
test_get_all_cpp_names (Decls[1 ], {" b" });
You can’t perform that action at this time.
0 commit comments