ClangASTType.h revision 585660cc442f7faf8d2cbd936e4c92ac689c30e5
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 "lldb/lldb-include.h" 14#include "lldb/Core/ClangForward.h" 15 16namespace lldb_private { 17 18//---------------------------------------------------------------------- 19// A class that can carry around a clang ASTContext and a opaque clang 20// QualType. A clang::QualType can be easily reconstructed from an 21// opaque clang type and often the ASTContext is needed when doing 22// various type related tasks, so this class allows both items to travel 23// in a single very lightweight class that can be used. There are many 24// static equivalents of the member functions that allow the ASTContext 25// and the opaque clang QualType to be specified for ease of use and 26// to avoid code duplication. 27//---------------------------------------------------------------------- 28class ClangASTType 29{ 30protected: 31 ClangASTType (void *type, clang::ASTContext *ast_context) : 32 m_type (type), 33 m_ast (ast_context) 34 { 35 } 36 37 ClangASTType (const ClangASTType &tw) : 38 m_type (tw.m_type), 39 m_ast (tw.m_ast) 40 { 41 } 42 43 ClangASTType () : 44 m_type (0), 45 m_ast (0) 46 { 47 } 48 49 ~ClangASTType(); 50 51 const ClangASTType & 52 operator= (const ClangASTType &atb) 53 { 54 m_type = atb.m_type; 55 m_ast = atb.m_ast; 56 return *this; 57 } 58 59public: 60 void * 61 GetOpaqueQualType() const 62 { 63 return m_type; 64 } 65 66 clang::ASTContext * 67 GetASTContext() const 68 { 69 return m_ast; 70 } 71 72 ConstString 73 GetClangTypeName (); 74 75 static ConstString 76 GetClangTypeName (void *clang_type); 77 78 uint64_t 79 GetClangTypeBitWidth (); 80 81 static uint64_t 82 GetClangTypeBitWidth (clang::ASTContext *ast_context, void *opaque_clang_qual_type); 83 84 size_t 85 GetTypeBitAlign (); 86 87 static size_t 88 GetTypeBitAlign (clang::ASTContext *ast_context, void *clang_type); 89 90 void 91 DumpValue (ExecutionContext *exe_ctx, 92 Stream *s, 93 lldb::Format format, 94 const DataExtractor &data, 95 uint32_t data_offset, 96 size_t data_byte_size, 97 uint32_t bitfield_bit_size, 98 uint32_t bitfield_bit_offset, 99 bool show_types, 100 bool show_summary, 101 bool verbose, 102 uint32_t depth); 103 104 static void 105 DumpValue (clang::ASTContext *ast_context, 106 void *opaque_clang_qual_type, 107 ExecutionContext *exe_ctx, 108 Stream *s, 109 lldb::Format format, 110 const DataExtractor &data, 111 uint32_t data_offset, 112 size_t data_byte_size, 113 uint32_t bitfield_bit_size, 114 uint32_t bitfield_bit_offset, 115 bool show_types, 116 bool show_summary, 117 bool verbose, 118 uint32_t depth); 119 120 bool 121 DumpTypeValue (Stream *s, 122 lldb::Format format, 123 const DataExtractor &data, 124 uint32_t data_offset, 125 size_t data_byte_size, 126 uint32_t bitfield_bit_size, 127 uint32_t bitfield_bit_offset); 128 129 130 static bool 131 DumpTypeValue (clang::ASTContext *ast_context, 132 void *opaque_clang_qual_type, 133 Stream *s, 134 lldb::Format format, 135 const DataExtractor &data, 136 uint32_t data_offset, 137 size_t data_byte_size, 138 uint32_t bitfield_bit_size, 139 uint32_t bitfield_bit_offset); 140 141 void 142 DumpSummary (ExecutionContext *exe_ctx, 143 Stream *s, 144 const DataExtractor &data, 145 uint32_t data_offset, 146 size_t data_byte_size); 147 148 149 static void 150 DumpSummary (clang::ASTContext *ast_context, 151 void *opaque_clang_qual_type, 152 ExecutionContext *exe_ctx, 153 Stream *s, 154 const DataExtractor &data, 155 uint32_t data_offset, 156 size_t data_byte_size); 157 158 void 159 DumpTypeDescription (Stream *s); 160 161 static void 162 DumpTypeDescription (clang::ASTContext *ast_context, 163 void *opaque_clang_qual_type, 164 Stream *s); 165 166 lldb::Encoding 167 GetEncoding (uint32_t &count); 168 169 static lldb::Encoding 170 GetEncoding (void *opaque_clang_qual_type, uint32_t &count); 171 172 lldb::Format 173 GetFormat (); 174 175 static lldb::Format 176 GetFormat (void *opaque_clang_qual_type); 177 178 bool 179 GetValueAsScalar (const DataExtractor &data, 180 uint32_t data_offset, 181 size_t data_byte_size, 182 Scalar &value); 183 184 static bool 185 GetValueAsScalar (clang::ASTContext *ast_context, 186 void *opaque_clang_qual_type, 187 const DataExtractor &data, 188 uint32_t data_offset, 189 size_t data_byte_size, 190 Scalar &value); 191 192 bool 193 SetValueFromScalar (const Scalar &value, 194 Stream &strm); 195 196 static bool 197 SetValueFromScalar (clang::ASTContext *ast_context, 198 void *opaque_clang_qual_type, 199 const Scalar &value, 200 Stream &strm); 201 202 bool 203 ReadFromMemory (ExecutionContext *exe_ctx, 204 lldb::addr_t addr, 205 lldb::AddressType address_type, 206 DataExtractor &data); 207 208 static bool 209 ReadFromMemory (clang::ASTContext *ast_context, 210 void *opaque_clang_qual_type, 211 ExecutionContext *exe_ctx, 212 lldb::addr_t addr, 213 lldb::AddressType address_type, 214 DataExtractor &data); 215 216 bool 217 WriteToMemory (ExecutionContext *exe_ctx, 218 lldb::addr_t addr, 219 lldb::AddressType address_type, 220 StreamString &new_value); 221 222 static bool 223 WriteToMemory (clang::ASTContext *ast_context, 224 void *opaque_clang_qual_type, 225 ExecutionContext *exe_ctx, 226 lldb::addr_t addr, 227 lldb::AddressType address_type, 228 StreamString &new_value); 229 230 void * 231 GetPointeeType (); 232 233 static void * 234 GetPointeeType (void *opaque_clang_qual_type); 235 236private: 237 void *m_type; 238 clang::ASTContext *m_ast; 239}; 240 241 242} // namespace lldb_private 243 244#endif // #ifndef liblldb_ClangASTType_h_ 245