Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 1 | //===-- Type.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_Type_h_ |
| 11 | #define liblldb_Type_h_ |
| 12 | |
| 13 | #include "lldb/lldb-private.h" |
| 14 | #include "lldb/Core/ClangForward.h" |
| 15 | #include "lldb/Core/UserID.h" |
| 16 | #include "lldb/Symbol/Declaration.h" |
| 17 | #include <set> |
| 18 | |
| 19 | namespace lldb_private { |
| 20 | |
| 21 | class Type : public UserID |
| 22 | { |
| 23 | public: |
| 24 | typedef enum |
| 25 | { |
| 26 | eTypeInvalid, |
| 27 | eIsTypeWithUID, ///< This type is the type whose UID is m_encoding_uid |
| 28 | eIsConstTypeWithUID, ///< This type is the type whose UID is m_encoding_uid with the const qualifier added |
| 29 | eIsRestrictTypeWithUID, ///< This type is the type whose UID is m_encoding_uid with the restrict qualifier added |
| 30 | eIsVolatileTypeWithUID, ///< This type is the type whose UID is m_encoding_uid with the volatile qualifier added |
| 31 | eTypedefToTypeWithUID, ///< This type is pointer to a type whose UID is m_encoding_uid |
| 32 | ePointerToTypeWithUID, ///< This type is pointer to a type whose UID is m_encoding_uid |
| 33 | eLValueReferenceToTypeWithUID, ///< This type is L value reference to a type whose UID is m_encoding_uid |
| 34 | eRValueReferenceToTypeWithUID, ///< This type is R value reference to a type whose UID is m_encoding_uid |
| 35 | eTypeUIDSynthetic |
| 36 | } EncodingUIDType; |
| 37 | |
| 38 | Type(lldb::user_id_t uid, |
| 39 | SymbolFile* symbol_file, |
| 40 | const ConstString &name, |
| 41 | uint64_t byte_size, |
| 42 | SymbolContextScope *context, |
| 43 | lldb::user_id_t encoding_uid, |
| 44 | EncodingUIDType encoding_type, |
| 45 | const Declaration& decl, |
| 46 | void *clang_qual_type); |
| 47 | |
| 48 | // This makes an invalid type. Used for functions that return a Type when they |
| 49 | // get an error. |
| 50 | Type(); |
| 51 | |
| 52 | const Type& |
| 53 | operator= (const Type& rhs); |
| 54 | |
| 55 | void |
| 56 | Dump(Stream *s, bool show_context); |
| 57 | |
| 58 | void |
| 59 | DumpTypeName(Stream *s); |
| 60 | |
| 61 | SymbolFile * |
| 62 | GetSymbolFile() |
| 63 | { |
| 64 | return m_symbol_file; |
| 65 | } |
| 66 | const SymbolFile * |
| 67 | GetSymbolFile() const |
| 68 | { |
| 69 | return m_symbol_file; |
| 70 | } |
| 71 | |
| 72 | TypeList* |
| 73 | GetTypeList(); |
| 74 | |
| 75 | const ConstString& |
| 76 | GetName(); |
| 77 | |
| 78 | uint64_t |
| 79 | GetByteSize(); |
| 80 | |
| 81 | uint32_t |
| 82 | GetNumChildren (bool omit_empty_base_classes); |
| 83 | |
| 84 | bool |
| 85 | IsAggregateType (); |
| 86 | |
| 87 | bool |
| 88 | IsValidType () |
| 89 | { |
| 90 | return m_encoding_uid_type != eTypeInvalid; |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | SetByteSize(uint32_t byte_size); |
| 95 | |
| 96 | const ConstString & |
| 97 | GetName () const |
| 98 | { |
| 99 | return m_name; |
| 100 | } |
| 101 | |
| 102 | static ConstString |
| 103 | GetClangTypeName (void *clang_qual_type); |
| 104 | |
| 105 | static void |
| 106 | DumpValue(ExecutionContext *exe_ctx, |
| 107 | clang::ASTContext *ast_context, |
| 108 | void *clang_qual_type, |
| 109 | Stream *s, |
| 110 | lldb::Format format, |
| 111 | const DataExtractor &data, |
| 112 | uint32_t data_offset, |
| 113 | size_t data_byte_size, |
| 114 | uint32_t bitfield_bit_size, |
| 115 | uint32_t bitfield_bit_offset, |
| 116 | bool show_types, |
| 117 | bool show_summary, |
| 118 | bool verbose, |
| 119 | uint32_t depth); |
| 120 | |
| 121 | static void |
| 122 | DumpSummary (ExecutionContext *exe_ctx, |
| 123 | clang::ASTContext *ast_context, |
| 124 | void *clang_qual_type, |
| 125 | Stream *s, |
| 126 | const DataExtractor &data, |
| 127 | uint32_t data_offset, |
| 128 | size_t data_byte_size); |
| 129 | |
| 130 | |
| 131 | void |
| 132 | DumpValue(ExecutionContext *exe_ctx, |
| 133 | Stream *s, |
| 134 | const DataExtractor &data, |
| 135 | uint32_t data_offset, |
| 136 | bool show_type, |
| 137 | bool show_summary, |
| 138 | bool verbose, |
| 139 | lldb::Format format = lldb::eFormatDefault); |
| 140 | |
| 141 | bool |
| 142 | DumpValueInMemory(ExecutionContext *exe_ctx, |
| 143 | Stream *s, |
| 144 | lldb::addr_t address, |
| 145 | lldb::AddressType address_type, |
| 146 | bool show_types, |
| 147 | bool show_summary, |
| 148 | bool verbose); |
| 149 | |
| 150 | static bool |
| 151 | DumpTypeValue ( Stream *s, |
| 152 | clang::ASTContext *ast_context, |
| 153 | void *clang_qual_type, |
| 154 | lldb::Format format, |
| 155 | const DataExtractor &data, |
| 156 | uint32_t data_offset, |
| 157 | size_t data_byte_size, |
| 158 | uint32_t bitfield_bit_size, |
| 159 | uint32_t bitfield_bit_offset); |
| 160 | |
| 161 | static bool |
| 162 | GetValueAsScalar (clang::ASTContext *ast_context, |
| 163 | void *clang_qual_type, |
| 164 | const DataExtractor &data, |
| 165 | uint32_t data_offset, |
| 166 | size_t data_byte_size, |
| 167 | Scalar &value); |
| 168 | |
| 169 | static bool |
| 170 | SetValueFromScalar (clang::ASTContext *ast_context, |
| 171 | void *clang_qual_type, |
| 172 | const Scalar &value, |
| 173 | Stream &strm); |
| 174 | |
| 175 | bool |
| 176 | ReadFromMemory (ExecutionContext *exe_ctx, |
| 177 | lldb::addr_t address, |
| 178 | lldb::AddressType address_type, |
| 179 | DataExtractor &data); |
| 180 | |
| 181 | bool |
| 182 | WriteToMemory (ExecutionContext *exe_ctx, |
| 183 | lldb::addr_t address, |
| 184 | lldb::AddressType address_type, |
| 185 | DataExtractor &data); |
| 186 | |
| 187 | |
| 188 | static bool |
| 189 | ReadFromMemory (ExecutionContext *exe_ctx, |
| 190 | clang::ASTContext *ast_context, |
| 191 | void *clang_qual_type, |
| 192 | lldb::addr_t addr, |
| 193 | lldb::AddressType address_type, |
| 194 | DataExtractor &data); |
| 195 | |
| 196 | static bool |
| 197 | WriteToMemory (ExecutionContext *exe_ctx, |
| 198 | clang::ASTContext *ast_context, |
| 199 | void *clang_qual_type, |
| 200 | lldb::addr_t addr, |
| 201 | lldb::AddressType address_type, |
| 202 | StreamString &new_value); |
| 203 | |
| 204 | bool |
| 205 | GetIsDeclaration() const; |
| 206 | |
| 207 | void |
| 208 | SetIsDeclaration(bool b); |
| 209 | |
| 210 | bool |
| 211 | GetIsExternal() const; |
| 212 | |
| 213 | void |
| 214 | SetIsExternal(bool b); |
| 215 | |
| 216 | lldb::Format |
| 217 | GetFormat (); |
| 218 | |
| 219 | lldb::Encoding |
| 220 | GetEncoding (uint32_t &count); |
| 221 | |
| 222 | static lldb::Encoding |
| 223 | GetEncoding (void *clang_qual_type, uint32_t &count); |
| 224 | |
| 225 | SymbolContextScope * |
| 226 | GetSymbolContextScope() |
| 227 | { |
| 228 | return m_context; |
| 229 | } |
| 230 | const SymbolContextScope * |
| 231 | GetSymbolContextScope() const |
| 232 | { |
| 233 | return m_context; |
| 234 | } |
| 235 | void |
| 236 | SetSymbolContextScope(SymbolContextScope *context) |
| 237 | { |
| 238 | m_context = context; |
| 239 | } |
| 240 | |
| 241 | void * |
| 242 | GetOpaqueClangQualType (); |
| 243 | |
| 244 | clang::ASTContext * |
| 245 | GetClangAST (); |
| 246 | |
| 247 | ClangASTContext & |
| 248 | GetClangASTContext (); |
| 249 | |
| 250 | void * |
| 251 | GetChildClangTypeAtIndex (const char *parent_name, |
| 252 | uint32_t idx, |
| 253 | bool transparent_pointers, |
| 254 | bool omit_empty_base_classes, |
| 255 | ConstString& name, |
| 256 | uint32_t &child_byte_size, |
| 257 | int32_t &child_byte_offset, |
| 258 | uint32_t &child_bitfield_bit_size, |
| 259 | uint32_t &child_bitfield_bit_offset); |
| 260 | |
| 261 | static int |
| 262 | Compare(const Type &a, const Type &b); |
| 263 | |
| 264 | static lldb::Format |
| 265 | GetFormat (void *clang_qual_type); |
| 266 | |
| 267 | static int |
| 268 | DumpClangTypeName(Stream *s, void *clang_qual_type); |
| 269 | |
| 270 | protected: |
| 271 | ConstString m_name; |
| 272 | uint64_t m_byte_size; |
| 273 | SymbolFile *m_symbol_file; |
| 274 | SymbolContextScope *m_context; // The symbol context in which this type is defined |
| 275 | lldb::user_id_t m_encoding_uid; |
| 276 | EncodingUIDType m_encoding_uid_type; |
| 277 | Declaration m_decl; |
| 278 | void *m_clang_qual_type; |
| 279 | |
| 280 | bool ResolveClangType(); |
| 281 | }; |
| 282 | |
| 283 | } // namespace lldb_private |
| 284 | |
| 285 | #endif // liblldb_Type_h_ |
| 286 | |