ClangASTType.h revision f95fc9e09fa0a32de0a3904a1517266df37e8bff
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 static uint64_t 114 GetClangTypeByteSize (clang::ASTContext *ast_context, 115 lldb::clang_type_t clang_type); 116 117 uint64_t 118 GetClangTypeBitWidth (); 119 120 static uint64_t 121 GetClangTypeBitWidth (clang::ASTContext *ast_context, lldb::clang_type_t opaque_clang_qual_type); 122 123 size_t 124 GetTypeBitAlign (); 125 126 static size_t 127 GetTypeBitAlign (clang::ASTContext *ast_context, lldb::clang_type_t clang_type); 128 129 lldb::LanguageType 130 GetMinimumLanguage (); 131 132 static lldb::LanguageType 133 GetMinimumLanguage (clang::ASTContext *ctx, 134 lldb::clang_type_t clang_type); 135 136 static lldb::TypeClass 137 GetTypeClass (clang::ASTContext *ast_context, 138 lldb::clang_type_t clang_type); 139 140 void 141 DumpValue (ExecutionContext *exe_ctx, 142 Stream *s, 143 lldb::Format format, 144 const DataExtractor &data, 145 lldb::offset_t data_offset, 146 size_t data_byte_size, 147 uint32_t bitfield_bit_size, 148 uint32_t bitfield_bit_offset, 149 bool show_types, 150 bool show_summary, 151 bool verbose, 152 uint32_t depth); 153 154 static void 155 DumpValue (clang::ASTContext *ast_context, 156 lldb::clang_type_t opaque_clang_qual_type, 157 ExecutionContext *exe_ctx, 158 Stream *s, 159 lldb::Format format, 160 const DataExtractor &data, 161 lldb::offset_t data_offset, 162 size_t data_byte_size, 163 uint32_t bitfield_bit_size, 164 uint32_t bitfield_bit_offset, 165 bool show_types, 166 bool show_summary, 167 bool verbose, 168 uint32_t depth); 169 170 bool 171 DumpTypeValue (Stream *s, 172 lldb::Format format, 173 const DataExtractor &data, 174 lldb::offset_t data_offset, 175 size_t data_byte_size, 176 uint32_t bitfield_bit_size, 177 uint32_t bitfield_bit_offset, 178 ExecutionContextScope *exe_scope); 179 180 181 static bool 182 DumpTypeValue (clang::ASTContext *ast_context, 183 lldb::clang_type_t opaque_clang_qual_type, 184 Stream *s, 185 lldb::Format format, 186 const DataExtractor &data, 187 lldb::offset_t data_offset, 188 size_t data_byte_size, 189 uint32_t bitfield_bit_size, 190 uint32_t bitfield_bit_offset, 191 ExecutionContextScope *exe_scope); 192 193 void 194 DumpSummary (ExecutionContext *exe_ctx, 195 Stream *s, 196 const DataExtractor &data, 197 lldb::offset_t data_offset, 198 size_t data_byte_size); 199 200 201 static void 202 DumpSummary (clang::ASTContext *ast_context, 203 lldb::clang_type_t opaque_clang_qual_type, 204 ExecutionContext *exe_ctx, 205 Stream *s, 206 const DataExtractor &data, 207 lldb::offset_t data_offset, 208 size_t data_byte_size); 209 210 void 211 DumpTypeDescription (); // Dump to stdout 212 213 void 214 DumpTypeDescription (Stream *s); 215 216 static void 217 DumpTypeDescription (clang::ASTContext *ast_context, 218 lldb::clang_type_t opaque_clang_qual_type, 219 Stream *s); 220 221 lldb::Encoding 222 GetEncoding (uint64_t &count); 223 224 static lldb::Encoding 225 GetEncoding (lldb::clang_type_t opaque_clang_qual_type, uint64_t &count); 226 227 lldb::Format 228 GetFormat (); 229 230 static lldb::Format 231 GetFormat (lldb::clang_type_t opaque_clang_qual_type); 232 233 uint64_t 234 GetTypeByteSize() const; 235 236 static uint64_t 237 GetTypeByteSize(clang::ASTContext *ast_context, 238 lldb::clang_type_t opaque_clang_qual_type); 239 240 bool 241 GetValueAsScalar (const DataExtractor &data, 242 lldb::offset_t data_offset, 243 size_t data_byte_size, 244 Scalar &value); 245 246 static bool 247 GetValueAsScalar (clang::ASTContext *ast_context, 248 lldb::clang_type_t opaque_clang_qual_type, 249 const DataExtractor &data, 250 lldb::offset_t data_offset, 251 size_t data_byte_size, 252 Scalar &value); 253 254 255 bool 256 IsDefined(); 257 258 static bool 259 IsDefined (lldb::clang_type_t opaque_clang_qual_type); 260 261 bool 262 IsConst(); 263 264 static bool 265 IsConst (lldb::clang_type_t opaque_clang_qual_type); 266 267 bool 268 SetValueFromScalar (const Scalar &value, 269 Stream &strm); 270 271 static bool 272 SetValueFromScalar (clang::ASTContext *ast_context, 273 lldb::clang_type_t opaque_clang_qual_type, 274 const Scalar &value, 275 Stream &strm); 276 277 void 278 SetClangType (clang::ASTContext *ast, lldb::clang_type_t type) 279 { 280 m_type = type; 281 m_ast = ast; 282 } 283 284 bool 285 ReadFromMemory (ExecutionContext *exe_ctx, 286 lldb::addr_t addr, 287 AddressType address_type, 288 DataExtractor &data); 289 290 static bool 291 ReadFromMemory (clang::ASTContext *ast_context, 292 lldb::clang_type_t opaque_clang_qual_type, 293 ExecutionContext *exe_ctx, 294 lldb::addr_t addr, 295 AddressType address_type, 296 DataExtractor &data); 297 298 bool 299 WriteToMemory (ExecutionContext *exe_ctx, 300 lldb::addr_t addr, 301 AddressType address_type, 302 StreamString &new_value); 303 304 static bool 305 WriteToMemory (clang::ASTContext *ast_context, 306 lldb::clang_type_t opaque_clang_qual_type, 307 ExecutionContext *exe_ctx, 308 lldb::addr_t addr, 309 AddressType address_type, 310 StreamString &new_value); 311 312 lldb::clang_type_t 313 GetPointeeType (); 314 315 static lldb::clang_type_t 316 GetPointeeType (lldb::clang_type_t opaque_clang_qual_type); 317 318 lldb::clang_type_t 319 GetArrayElementType (uint64_t& stride); 320 321 static lldb::clang_type_t 322 GetArrayElementType (clang::ASTContext* ast, 323 lldb::clang_type_t opaque_clang_qual_type, 324 uint64_t& stride); 325 326 lldb::clang_type_t 327 GetPointerType () const; 328 329 static lldb::clang_type_t 330 GetPointerType (clang::ASTContext *ast_context, 331 lldb::clang_type_t opaque_clang_qual_type); 332 333 static lldb::clang_type_t 334 RemoveFastQualifiers (lldb::clang_type_t); 335 336 static clang::CXXRecordDecl * 337 GetAsCXXRecordDecl (lldb::clang_type_t opaque_clang_qual_type); 338 339 void 340 Clear() 341 { 342 m_type = NULL; 343 m_ast = NULL; 344 } 345 346private: 347 lldb::clang_type_t m_type; 348 clang::ASTContext *m_ast; 349}; 350 351bool operator == (const ClangASTType &lhs, const ClangASTType &rhs); 352bool operator != (const ClangASTType &lhs, const ClangASTType &rhs); 353 354 355} // namespace lldb_private 356 357#endif // #ifndef liblldb_ClangASTType_h_ 358