TypeList.cpp revision b01000fd063629facd45044f137446fb748ee179
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/SymbolFile.h" 33#include "lldb/Symbol/SymbolVendor.h" 34#include "lldb/Symbol/Type.h" 35#include "lldb/Symbol/TypeList.h" 36 37using namespace lldb; 38using namespace lldb_private; 39using namespace clang; 40 41TypeList::TypeList() : 42 m_types () 43{ 44} 45 46//---------------------------------------------------------------------- 47// Destructor 48//---------------------------------------------------------------------- 49TypeList::~TypeList() 50{ 51} 52 53void 54TypeList::Insert (TypeSP& type_sp) 55{ 56 // Just push each type on the back for now. We will worry about uniquing later 57 if (type_sp) 58 m_types.insert(std::make_pair(type_sp->GetID(), type_sp)); 59} 60 61 62bool 63TypeList::InsertUnique (TypeSP& type_sp) 64{ 65 if (type_sp) 66 { 67 user_id_t type_uid = type_sp->GetID(); 68 iterator pos, end = m_types.end(); 69 70 for (pos = m_types.find(type_uid); pos != end && pos->second->GetID() == type_uid; ++pos) 71 { 72 if (pos->second.get() == type_sp.get()) 73 return false; 74 } 75 } 76 Insert (type_sp); 77 return true; 78} 79 80//---------------------------------------------------------------------- 81// Find a base type by its unique ID. 82//---------------------------------------------------------------------- 83TypeSP 84TypeList::FindType(lldb::user_id_t uid) 85{ 86 iterator pos = m_types.find(uid); 87 if (pos != m_types.end()) 88 return pos->second; 89 return TypeSP(); 90} 91 92//---------------------------------------------------------------------- 93// Find a type by name. 94//---------------------------------------------------------------------- 95//TypeList 96//TypeList::FindTypes (const ConstString &name) 97//{ 98// // Do we ever need to make a lookup by name map? Here we are doing 99// // a linear search which isn't going to be fast. 100// TypeList types(m_ast.getTargetInfo()->getTriple().getTriple().c_str()); 101// iterator pos, end; 102// for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) 103// if (pos->second->GetName() == name) 104// types.Insert (pos->second); 105// return types; 106//} 107 108void 109TypeList::Clear() 110{ 111 m_types.clear(); 112} 113 114uint32_t 115TypeList::GetSize() const 116{ 117 return m_types.size(); 118} 119 120// GetTypeAtIndex isn't used a lot for large type lists, currently only for 121// type lists that are returned for "image dump -t TYPENAME" commands and other 122// simple symbol queries that grab the first result... 123 124TypeSP 125TypeList::GetTypeAtIndex(uint32_t idx) 126{ 127 iterator pos, end; 128 uint32_t i = idx; 129 for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) 130 { 131 if (i == 0) 132 return pos->second; 133 --i; 134 } 135 return TypeSP(); 136} 137 138void 139TypeList::Dump(Stream *s, bool show_context) 140{ 141 for (iterator pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) 142 { 143 pos->second->Dump(s, show_context); 144 } 145} 146 147//void * 148//TypeList::CreateClangPointerType (Type *type) 149//{ 150// assert(type); 151// return m_ast.CreatePointerType(type->GetClangForwardType()); 152//} 153// 154//void * 155//TypeList::CreateClangTypedefType (Type *typedef_type, Type *base_type) 156//{ 157// assert(typedef_type && base_type); 158// return m_ast.CreateTypedefType (typedef_type->GetName().AsCString(), 159// base_type->GetClangForwardType(), 160// typedef_type->GetSymbolFile()->GetClangDeclContextForTypeUID(typedef_type->GetID())); 161//} 162// 163//void * 164//TypeList::CreateClangLValueReferenceType (Type *type) 165//{ 166// assert(type); 167// return m_ast.CreateLValueReferenceType(type->GetClangForwardType()); 168//} 169// 170//void * 171//TypeList::CreateClangRValueReferenceType (Type *type) 172//{ 173// assert(type); 174// return m_ast.CreateRValueReferenceType (type->GetClangForwardType()); 175//} 176// 177 178 179