ClangASTType.h revision 017c16aa483e6edabdbbee1bdcd1ce3f8e8a12d1
1//===-- ClangASTType.h ------------------------------------------*- 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#ifndef liblldb_ClangASTType_h_ 11#define liblldb_ClangASTType_h_ 12 13#include <string> 14#include "lldb/lldb-private.h" 15#include "lldb/Core/ClangForward.h" 16 17namespace lldb_private { 18 19//---------------------------------------------------------------------- 20// A class that can carry around a clang ASTContext and a opaque clang 21// QualType. A clang::QualType can be easily reconstructed from an 22// opaque clang type and often the ASTContext is needed when doing 23// various type related tasks, so this class allows both items to travel 24// in a single very lightweight class that can be used. There are many 25// static equivalents of the member functions that allow the ASTContext 26// and the opaque clang QualType to be specified for ease of use and 27// to avoid code duplication. 28//---------------------------------------------------------------------- 29class ClangASTType 30{ 31public: 32 33 ClangASTType (clang::ASTContext *ast_context, lldb::clang_type_t type) : 34 m_type (type), 35 m_ast (ast_context) 36 { 37 } 38 39 ClangASTType (const ClangASTType &tw) : 40 m_type (tw.m_type), 41 m_ast (tw.m_ast) 42 { 43 } 44 45 ClangASTType () : 46 m_type (0), 47 m_ast (0) 48 { 49 } 50 51 virtual ~ClangASTType(); 52 53 const ClangASTType & 54 operator= (const ClangASTType &atb) 55 { 56 m_type = atb.m_type; 57 m_ast = atb.m_ast; 58 return *this; 59 } 60 61 bool 62 IsValid () const 63 { 64 return m_type != NULL && m_ast != NULL; 65 } 66 67 lldb::clang_type_t 68 GetOpaqueQualType() const 69 { 70 return m_type; 71 } 72 73 clang::ASTContext * 74 GetASTContext() const 75 { 76 return m_ast; 77 } 78 79 ConstString 80 GetConstTypeName (); 81 82 ConstString 83 GetConstQualifiedTypeName (); 84 85 static lldb::BasicType 86 GetBasicTypeEnumeration (const ConstString &name); 87 88 static ClangASTType 89 GetBasicType (clang::ASTContext *ast, lldb::BasicType type); 90 91 static ClangASTType 92 GetBasicType (clang::ASTContext *ast, const ConstString &name); 93 94 static ConstString 95 GetConstTypeName (clang::ASTContext *ast, 96 lldb::clang_type_t clang_type); 97 98 static ConstString 99 GetConstQualifiedTypeName (clang::ASTContext *ast, 100 lldb::clang_type_t clang_type); 101 102 static std::string 103 GetTypeNameForQualType (clang::ASTContext *ast, 104 clang::QualType qual_type); 105 106 static std::string 107 GetTypeNameForOpaqueQualType (clang::ASTContext *ast, 108 lldb::clang_type_t opaque_qual_type); 109 110 uint64_t 111 GetClangTypeByteSize (); 112 113 uint64_t 114 GetClangTypeBitWidth (); 115 116 static uint64_t 117 GetClangTypeBitWidth (clang::ASTContext *ast_context, lldb::clang_type_t opaque_clang_qual_type); 118 119 size_t 120 GetTypeBitAlign (); 121 122 static size_t 123 GetTypeBitAlign (clang::ASTContext *ast_context, lldb::clang_type_t clang_type); 124 125 lldb::LanguageType 126 GetMinimumLanguage (); 127 128 static lldb::LanguageType 129 GetMinimumLanguage (clang::ASTContext *ctx, 130 lldb::clang_type_t clang_type); 131 132 static lldb::TypeClass 133 GetTypeClass (clang::ASTContext *ast_context, 134 lldb::clang_type_t clang_type); 135 136 void 137 DumpValue (ExecutionContext *exe_ctx, 138 Stream *s, 139 lldb::Format format, 140 const DataExtractor &data, 141 lldb::offset_t data_offset, 142 size_t data_byte_size, 143 uint32_t bitfield_bit_size, 144 uint32_t bitfield_bit_offset, 145 bool show_types, 146 bool show_summary, 147 bool verbose, 148 uint32_t depth); 149 150 static void 151 DumpValue (clang::ASTContext *ast_context, 152 lldb::clang_type_t opaque_clang_qual_type, 153 ExecutionContext *exe_ctx, 154 Stream *s, 155 lldb::Format format, 156 const DataExtractor &data, 157 lldb::offset_t data_offset, 158 size_t data_byte_size, 159 uint32_t bitfield_bit_size, 160 uint32_t bitfield_bit_offset, 161 bool show_types, 162 bool show_summary, 163 bool verbose, 164 uint32_t depth); 165 166 bool 167 DumpTypeValue (Stream *s, 168 lldb::Format format, 169 const DataExtractor &data, 170 lldb::offset_t data_offset, 171 size_t data_byte_size, 172 uint32_t bitfield_bit_size, 173 uint32_t bitfield_bit_offset, 174 ExecutionContextScope *exe_scope); 175 176 177 static bool 178 DumpTypeValue (clang::ASTContext *ast_context, 179 lldb::clang_type_t opaque_clang_qual_type, 180 Stream *s, 181 lldb::Format format, 182 const DataExtractor &data, 183 lldb::offset_t data_offset, 184 size_t data_byte_size, 185 uint32_t bitfield_bit_size, 186 uint32_t bitfield_bit_offset, 187 ExecutionContextScope *exe_scope); 188 189 void 190 DumpSummary (ExecutionContext *exe_ctx, 191 Stream *s, 192 const DataExtractor &data, 193 lldb::offset_t data_offset, 194 size_t data_byte_size); 195 196 197 static void 198 DumpSummary (clang::ASTContext *ast_context, 199 lldb::clang_type_t opaque_clang_qual_type, 200 ExecutionContext *exe_ctx, 201 Stream *s, 202 const DataExtractor &data, 203 lldb::offset_t data_offset, 204 size_t data_byte_size); 205 206 void 207 DumpTypeDescription (); // Dump to stdout 208 209 void 210 DumpTypeDescription (Stream *s); 211 212 static void 213 DumpTypeDescription (clang::ASTContext *ast_context, 214 lldb::clang_type_t opaque_clang_qual_type, 215 Stream *s); 216 217 lldb::Encoding 218 GetEncoding (uint64_t &count); 219 220 static lldb::Encoding 221 GetEncoding (lldb::clang_type_t opaque_clang_qual_type, uint64_t &count); 222 223 lldb::Format 224 GetFormat (); 225 226 static lldb::Format 227 GetFormat (lldb::clang_type_t opaque_clang_qual_type); 228 229 uint64_t 230 GetTypeByteSize() const; 231 232 static uint64_t 233 GetTypeByteSize(clang::ASTContext *ast_context, 234 lldb::clang_type_t opaque_clang_qual_type); 235 236 bool 237 GetValueAsScalar (const DataExtractor &data, 238 lldb::offset_t data_offset, 239 size_t data_byte_size, 240 Scalar &value); 241 242 static bool 243 GetValueAsScalar (clang::ASTContext *ast_context, 244 lldb::clang_type_t opaque_clang_qual_type, 245 const DataExtractor &data, 246 lldb::offset_t data_offset, 247 size_t data_byte_size, 248 Scalar &value); 249 250 251 bool 252 IsDefined(); 253 254 static bool 255 IsDefined (lldb::clang_type_t opaque_clang_qual_type); 256 257 bool 258 IsConst(); 259 260 static bool 261 IsConst (lldb::clang_type_t opaque_clang_qual_type); 262 263 bool 264 SetValueFromScalar (const Scalar &value, 265 Stream &strm); 266 267 static bool 268 SetValueFromScalar (clang::ASTContext *ast_context, 269 lldb::clang_type_t opaque_clang_qual_type, 270 const Scalar &value, 271 Stream &strm); 272 273 void 274 SetClangType (clang::ASTContext *ast, lldb::clang_type_t type) 275 { 276 m_type = type; 277 m_ast = ast; 278 } 279 280 bool 281 ReadFromMemory (ExecutionContext *exe_ctx, 282 lldb::addr_t addr, 283 AddressType address_type, 284 DataExtractor &data); 285 286 static bool 287 ReadFromMemory (clang::ASTContext *ast_context, 288 lldb::clang_type_t opaque_clang_qual_type, 289 ExecutionContext *exe_ctx, 290 lldb::addr_t addr, 291 AddressType address_type, 292 DataExtractor &data); 293 294 bool 295 WriteToMemory (ExecutionContext *exe_ctx, 296 lldb::addr_t addr, 297 AddressType address_type, 298 StreamString &new_value); 299 300 static bool 301 WriteToMemory (clang::ASTContext *ast_context, 302 lldb::clang_type_t opaque_clang_qual_type, 303 ExecutionContext *exe_ctx, 304 lldb::addr_t addr, 305 AddressType address_type, 306 StreamString &new_value); 307 308 lldb::clang_type_t 309 GetPointeeType (); 310 311 static lldb::clang_type_t 312 GetPointeeType (lldb::clang_type_t opaque_clang_qual_type); 313 314 lldb::clang_type_t 315 GetArrayElementType (uint64_t& stride); 316 317 static lldb::clang_type_t 318 GetArrayElementType (clang::ASTContext* ast, 319 lldb::clang_type_t opaque_clang_qual_type, 320 uint64_t& stride); 321 322 lldb::clang_type_t 323 GetPointerType () const; 324 325 static lldb::clang_type_t 326 GetPointerType (clang::ASTContext *ast_context, 327 lldb::clang_type_t opaque_clang_qual_type); 328 329 static lldb::clang_type_t 330 RemoveFastQualifiers (lldb::clang_type_t); 331 332 static clang::CXXRecordDecl * 333 GetAsCXXRecordDecl (lldb::clang_type_t opaque_clang_qual_type); 334 335 void 336 Clear() 337 { 338 m_type = NULL; 339 m_ast = NULL; 340 } 341 342private: 343 lldb::clang_type_t m_type; 344 clang::ASTContext *m_ast; 345}; 346 347bool operator == (const ClangASTType &lhs, const ClangASTType &rhs); 348bool operator != (const ClangASTType &lhs, const ClangASTType &rhs); 349 350 351} // namespace lldb_private 352 353#endif // #ifndef liblldb_ClangASTType_h_ 354