TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestTypedefs)) { FileSpec fspec(m_types_test_exe.c_str(), false); ArchSpec aspec("i686-pc-windows"); lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec); SymbolVendor *plugin = module->GetSymbolVendor(); SymbolFilePDB *symfile = static_cast<SymbolFilePDB *>(plugin->GetSymbolFile()); const llvm::pdb::IPDBSession &session = symfile->GetPDBSession(); SymbolContext sc; llvm::DenseSet<SymbolFile *> searched_files; TypeMap results; const char *TypedefsToCheck[] = {"ClassTypedef", "NSClassTypedef"}; for (auto Typedef : TypedefsToCheck) { TypeMap results; EXPECT_EQ(1u, symfile->FindTypes(sc, ConstString(Typedef), nullptr, false, 0, searched_files, results)); EXPECT_EQ(1u, results.GetSize()); lldb::TypeSP typedef_type = results.GetTypeAtIndex(0); EXPECT_EQ(ConstString(Typedef), typedef_type->GetName()); CompilerType compiler_type = typedef_type->GetFullCompilerType(); ClangASTContext *clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(compiler_type.GetTypeSystem()); EXPECT_TRUE( clang_type_system->IsTypedefType(compiler_type.GetOpaqueQualType())); std::string sizeof_var = "sizeof_"; sizeof_var.append(Typedef); EXPECT_EQ(GetGlobalConstantInteger(session, sizeof_var.c_str()), typedef_type->GetByteSize()); } }
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestEnumTypes)) { FileSpec fspec(m_types_test_exe.c_str(), false); ArchSpec aspec("i686-pc-windows"); lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec); SymbolVendor *plugin = module->GetSymbolVendor(); SymbolFilePDB *symfile = static_cast<SymbolFilePDB *>(plugin->GetSymbolFile()); const llvm::pdb::IPDBSession &session = symfile->GetPDBSession(); SymbolContext sc; llvm::DenseSet<SymbolFile *> searched_files; const char *EnumsToCheck[] = {"Enum", "ShortEnum"}; for (auto Enum : EnumsToCheck) { TypeMap results; EXPECT_EQ(1u, symfile->FindTypes(sc, ConstString(Enum), nullptr, false, 0, searched_files, results)); EXPECT_EQ(1u, results.GetSize()); lldb::TypeSP enum_type = results.GetTypeAtIndex(0); EXPECT_EQ(ConstString(Enum), enum_type->GetName()); CompilerType compiler_type = enum_type->GetFullCompilerType(); EXPECT_TRUE(ClangASTContext::IsEnumType(compiler_type.GetOpaqueQualType())); clang::EnumDecl *enum_decl = ClangASTContext::GetAsEnumDecl(compiler_type); EXPECT_NE(nullptr, enum_decl); EXPECT_EQ(2, std::distance(enum_decl->enumerator_begin(), enum_decl->enumerator_end())); std::string sizeof_var = "sizeof_"; sizeof_var.append(Enum); EXPECT_EQ(GetGlobalConstantInteger(session, sizeof_var.c_str()), enum_type->GetByteSize()); } }
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestMaxMatches)) { FileSpec fspec(m_types_test_exe.c_str(), false); ArchSpec aspec("i686-pc-windows"); lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec); SymbolVendor *plugin = module->GetSymbolVendor(); SymbolFilePDB *symfile = static_cast<SymbolFilePDB *>(plugin->GetSymbolFile()); SymbolContext sc; llvm::DenseSet<SymbolFile *> searched_files; TypeMap results; uint32_t num_results = symfile->FindTypes(sc, ConstString(".*"), nullptr, false, 0, searched_files, results); // Try to limit ourselves from 1 to 10 results, otherwise we could be doing // this thousands of times. // The idea is just to make sure that for a variety of values, the number of // limited results always // comes out to the number we are expecting. uint32_t iterations = std::min(num_results, 10u); for (uint32_t i = 1; i <= iterations; ++i) { uint32_t num_limited_results = symfile->FindTypes( sc, ConstString(".*"), nullptr, false, i, searched_files, results); EXPECT_EQ(i, num_limited_results); EXPECT_EQ(num_limited_results, results.GetSize()); } }
int main() { TypeMap bin; fillBin("Trash.dat", bin); // Sorting happens TypeMap::iterator it; for (it = bin.begin(); it != bin.end(); it++) sumValue((*it).second); } ///:~
Type* Protobuf::GetType(const Descriptor* descriptor) { TypeMap::iterator it = mTypeMap.find(descriptor); if (it != mTypeMap.end()) return it->second; Type* result = mTypeMap[descriptor] = new Type(this, factory.GetPrototype(descriptor)->New(), TypeTemplate->GetFunction()->NewInstance(), handles.size()); handles.push_back(result); Handle<Array> types = handle_->GetInternalField(1).As<Array>(); types->Set(types->Length(), result->handle_); return result; }
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestNullName)) { FileSpec fspec(m_types_test_exe.c_str(), false); ArchSpec aspec("i686-pc-windows"); lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec); SymbolVendor *plugin = module->GetSymbolVendor(); SymbolFilePDB *symfile = static_cast<SymbolFilePDB *>(plugin->GetSymbolFile()); SymbolContext sc; llvm::DenseSet<SymbolFile *> searched_files; TypeMap results; uint32_t num_results = symfile->FindTypes(sc, ConstString(), nullptr, false, 0, searched_files, results); EXPECT_EQ(0u, num_results); EXPECT_EQ(0u, results.GetSize()); }
void bind( Y something, TypeInfoP interface){ if( found(get(interface))) throwOrBreak< M>(); bindings.insert( std::pair< std::type_index, Y> ( std::type_index(*interface), something)); }
size_t SymbolFile::FindTypes (const std::vector<CompilerContext> &context, bool append, TypeMap& types) { if (!append) types.Clear(); return 0; }
uint32_t SymbolFile::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeMap& types) { if (!append) types.Clear(); return 0; }
static std::pair<typename ContainerTraits<TypeMap>::Iterator, typename ContainerTraits<TypeMap>::Iterator> getOverlappingTypeInfos(TypeMap& tmap, size_t from, size_t len) { typedef typename ContainerTraits<TypeMap>::Iterator Iterator; Iterator first = tmap.begin(); Iterator last = tmap.end(); Iterator ub = tmap.lower_bound(from + len); // the same for the beginning, but there we need the previous map entry Iterator lb = tmap.lower_bound(from); lb = adjustPosOnOverlap(first, lb, from); return std::make_pair(lb, ub); }
uint32_t SymbolFile::FindTypes( const SymbolContext &sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, TypeMap &types) { if (!append) types.Clear(); return 0; }
size_t SymbolVendor::FindTypes(const std::vector<CompilerContext> &context, bool append, TypeMap &types) { ModuleSP module_sp(GetModule()); if (module_sp) { std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindTypes(context, append, types); } if (!append) types.Clear(); return 0; }
TEST_F(SymbolFilePDBTests, REQUIRES_DIA_SDK(TestClassInNamespace)) { FileSpec fspec(m_types_test_exe.c_str(), false); ArchSpec aspec("i686-pc-windows"); lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec); SymbolVendor *plugin = module->GetSymbolVendor(); SymbolFilePDB *symfile = static_cast<SymbolFilePDB *>(plugin->GetSymbolFile()); const llvm::pdb::IPDBSession &session = symfile->GetPDBSession(); SymbolContext sc; llvm::DenseSet<SymbolFile *> searched_files; TypeMap results; EXPECT_EQ(1u, symfile->FindTypes(sc, ConstString("NS::NSClass"), nullptr, false, 0, searched_files, results)); EXPECT_EQ(1u, results.GetSize()); lldb::TypeSP udt_type = results.GetTypeAtIndex(0); EXPECT_EQ(ConstString("NS::NSClass"), udt_type->GetName()); CompilerType compiler_type = udt_type->GetForwardCompilerType(); EXPECT_TRUE(ClangASTContext::IsClassType(compiler_type.GetOpaqueQualType())); EXPECT_EQ(GetGlobalConstantInteger(session, "sizeof_NSClass"), udt_type->GetByteSize()); }
TypeMap mapWithCommonTypes() { TypeMap m; m.emplace(typeid(short), MPI_SHORT); m.emplace(typeid(unsigned short), MPI_UNSIGNED_SHORT); m.emplace(typeid(int), MPI_INT); m.emplace(typeid(unsigned int), MPI_UNSIGNED); m.emplace(typeid(long long), MPI_LONG_LONG_INT); m.emplace(typeid(unsigned long long), MPI_UNSIGNED_LONG_LONG); return m; }
size_t SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, TypeMap& types) { ModuleSP module_sp(GetModule()); if (module_sp) { lldb_private::Mutex::Locker locker(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindTypes(sc, name, parent_decl_ctx, append, max_matches, types); } if (!append) types.Clear(); return 0; }
size_t SymbolVendor::FindTypes (const std::vector<CompilerContext> &context, bool append, TypeMap& types) { ModuleSP module_sp(GetModule()); if (module_sp) { lldb_private::Mutex::Locker locker(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindTypes(context, append, types); } if (!append) types.Clear(); return 0; }
DataTypeFactory::TypeMap DataTypeFactory::typeMap() { static TypeMap typeMap; if (typeMap.isEmpty()) { typeMap.insert(Type::Integer, "Integer"); typeMap.insert(Type::Gauge32, "Gauge32"); typeMap.insert(Type::Counter32, "Counter32"); typeMap.insert(Type::OctetString, "String"); typeMap.insert(Type::IpAddress, "IpAddress"); typeMap.insert(Type::NullObject, "Unknown type"); } return typeMap; }
static bool has_task_or_graph_type(TypeMap<bool>& cache, const Type* type) { if (cache.emplace(type, false).second) { if (is_task_type(type) || is_graph_type(type)) return cache[type] = true; bool contains = false; for (auto op : type->ops()) { if (has_task_or_graph_type(cache, op)) { contains = true; break; } } return cache[type] = contains; } return cache[type]; }
size_t SymbolVendor::FindTypes( const SymbolContext &sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, TypeMap &types) { ModuleSP module_sp(GetModule()); if (module_sp) { std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); if (m_sym_file_ap.get()) return m_sym_file_ap->FindTypes(sc, name, parent_decl_ctx, append, max_matches, searched_symbol_files, types); } if (!append) types.Clear(); return 0; }
void SymbolContext::SortTypeList(TypeMap &type_map, TypeList &type_list ) const { Block * curr_block = block; bool isInlinedblock = false; if (curr_block != nullptr && curr_block->GetContainingInlinedBlock() != nullptr) isInlinedblock = true; while (curr_block != nullptr && !isInlinedblock) { TypeMoveMatchingBlock callbackBlock (curr_block, type_map, type_list); type_map.ForEach(callbackBlock); curr_block = curr_block->GetParent(); } if(function != nullptr && type_map.GetSize() > 0) { TypeMoveMatchingFunction callbackFunction (function, type_map, type_list); type_map.ForEach(callbackFunction); } if(comp_unit != nullptr && type_map.GetSize() > 0) { TypeMoveMatchingCompileUnit callbackCompileUnit (comp_unit, type_map, type_list); type_map.ForEach(callbackCompileUnit); } if(module_sp && type_map.GetSize() > 0) { TypeMoveMatchingModule callbackModule (module_sp, type_map, type_list); type_map.ForEach(callbackModule); } if(type_map.GetSize() > 0) { TypeMaptoList callbackM2L (type_map, type_list); type_map.ForEach(callbackM2L); } return ; }
// forech-able necessary methods. typename TypeMap::iterator begin() { return bindings.begin(); }
void remove( TypeInfoP interface){ auto it = bindings.find( std::type_index(*interface) ); if(it!=bindings.end()){ bindings.erase( it); } }
typename TypeMap::iterator get( TypeInfoP interface){ return bindings.find( std::type_index(*interface)); }
Y getVal( std::type_index idx){ return bindings.find( idx)->second; }
typename TypeMap::iterator get( std::type_index & interface){ return bindings.find( interface); }
bool found(typename TypeMap::iterator it){ return it != bindings.end(); }
/*! Get the number of elements in the data set. \return number of elements */ static size_t get_count() { return _valuemap.size(); }
typename TypeMap::const_iterator begin() const { return bindings.begin(); }
typename TypeMap::iterator end() { return bindings.end(); }
typename TypeMap::const_iterator end() const { return bindings.end(); }