TypeList.cpp revision 3f5ee7fd6991891f0892bd71537763d9b59acd12
1//===-- TypeList.cpp --------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10 11// C Includes 12// C++ Includes 13#include <vector> 14 15// Other libraries and framework includes 16#include "clang/AST/ASTConsumer.h" 17#include "clang/AST/ASTContext.h" 18#include "clang/AST/Decl.h" 19#include "clang/AST/DeclCXX.h" 20#include "clang/AST/DeclGroup.h" 21 22#include "clang/Basic/Builtins.h" 23#include "clang/Basic/IdentifierTable.h" 24#include "clang/Basic/LangOptions.h" 25#include "clang/Basic/SourceManager.h" 26#include "clang/Basic/TargetInfo.h" 27 28#include "llvm/Support/FormattedStream.h" 29#include "llvm/Support/raw_ostream.h" 30 31// Project includes 32#include "lldb/Symbol/ClangASTContext.h" 33#include "lldb/Symbol/SymbolFile.h" 34#include "lldb/Symbol/SymbolVendor.h" 35#include "lldb/Symbol/Type.h" 36#include "lldb/Symbol/TypeList.h" 37 38using namespace lldb; 39using namespace lldb_private; 40using namespace clang; 41 42TypeList::TypeList(const char *target_triple) : 43 m_ast (target_triple), 44 m_types () 45{ 46} 47 48//---------------------------------------------------------------------- 49// Destructor 50//---------------------------------------------------------------------- 51TypeList::~TypeList() 52{ 53} 54 55void 56TypeList::Insert (TypeSP& type_sp) 57{ 58 // Just push each type on the back for now. We will worry about uniquing later 59 if (type_sp) 60 m_types.insert(std::make_pair(type_sp->GetID(), type_sp)); 61} 62 63 64bool 65TypeList::InsertUnique (TypeSP& type_sp) 66{ 67 if (type_sp) 68 { 69 user_id_t type_uid = type_sp->GetID(); 70 iterator pos, end = m_types.end(); 71 72 for (pos = m_types.find(type_uid); pos != end && pos->second->GetID() == type_uid; ++pos) 73 { 74 if (pos->second.get() == type_sp.get()) 75 return false; 76 } 77 } 78 Insert (type_sp); 79 return true; 80} 81 82//---------------------------------------------------------------------- 83// Find a base type by its unique ID. 84//---------------------------------------------------------------------- 85TypeSP 86TypeList::FindType(lldb::user_id_t uid) 87{ 88 iterator pos = m_types.find(uid); 89 if (pos != m_types.end()) 90 return pos->second; 91 return TypeSP(); 92} 93 94//---------------------------------------------------------------------- 95// Find a type by name. 96//---------------------------------------------------------------------- 97TypeList 98TypeList::FindTypes (const ConstString &name) 99{ 100 // Do we ever need to make a lookup by name map? Here we are doing 101 // a linear search which isn't going to be fast. 102 TypeList types(m_ast.getTargetInfo()->getTriple().getTriple().c_str()); 103 iterator pos, end; 104 for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) 105 if (pos->second->GetName() == name) 106 types.Insert (pos->second); 107 return types; 108} 109 110void 111TypeList::Clear() 112{ 113 m_types.clear(); 114} 115 116uint32_t 117TypeList::GetSize() const 118{ 119 return m_types.size(); 120} 121 122// GetTypeAtIndex isn't used a lot for large type lists, currently only for 123// type lists that are returned for "image dump -t TYPENAME" commands and other 124// simple symbol queries that grab the first result... 125 126TypeSP 127TypeList::GetTypeAtIndex(uint32_t idx) 128{ 129 iterator pos, end; 130 uint32_t i = idx; 131 for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) 132 { 133 if (i == 0) 134 return pos->second; 135 --i; 136 } 137 return TypeSP(); 138} 139 140void 141TypeList::Dump(Stream *s, bool show_context) 142{ 143 for (iterator pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) 144 { 145 pos->second->Dump(s, show_context); 146 } 147} 148 149 150ClangASTContext & 151TypeList::GetClangASTContext () 152{ 153 return m_ast; 154} 155 156void * 157TypeList::CreateClangPointerType (Type *type) 158{ 159 assert(type); 160 return m_ast.CreatePointerType(type->GetClangForwardType()); 161} 162 163void * 164TypeList::CreateClangTypedefType (Type *typedef_type, Type *base_type) 165{ 166 assert(typedef_type && base_type); 167 return m_ast.CreateTypedefType (typedef_type->GetName().AsCString(), 168 base_type->GetClangForwardType(), 169 typedef_type->GetSymbolFile()->GetClangDeclContextForTypeUID(typedef_type->GetID())); 170} 171 172void * 173TypeList::CreateClangLValueReferenceType (Type *type) 174{ 175 assert(type); 176 return m_ast.CreateLValueReferenceType(type->GetClangForwardType()); 177} 178 179void * 180TypeList::CreateClangRValueReferenceType (Type *type) 181{ 182 assert(type); 183 return m_ast.CreateRValueReferenceType (type->GetClangForwardType()); 184} 185 186 187 188