Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ClangASTContext.cpp -------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 9 | #include "lldb/Symbol/ClangASTContext.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 11 | #include "llvm/Support/FormatAdapters.h" |
| 12 | #include "llvm/Support/FormatVariadic.h" |
| 13 | |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 14 | #include <mutex> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include <string> |
Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame] | 16 | #include <vector> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 18 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | // Clang headers like to use NDEBUG inside of them to enable/disable debug |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 20 | // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 21 | // or another. This is bad because it means that if clang was built in release |
| 22 | // mode, it assumes that you are building in release mode which is not always |
| 23 | // the case. You can end up with functions that are defined as empty in header |
| 24 | // files when NDEBUG is not defined, and this can cause link errors with the |
| 25 | // clang .a files that you have since you might be missing functions in the .a |
| 26 | // file. So we have to define NDEBUG when including clang headers to avoid any |
| 27 | // mismatches. This is covered by rdar://problem/8691220 |
| 28 | |
Sean Callanan | 3b1d4f6 | 2011-10-26 17:46:51 +0000 | [diff] [blame] | 29 | #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 30 | #define LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 31 | #define NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 32 | // Need to include assert.h so it is as clang would expect it to be (disabled) |
| 33 | #include <assert.h> |
| 34 | #endif |
| 35 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "clang/AST/ASTContext.h" |
| 37 | #include "clang/AST/ASTImporter.h" |
Greg Clayton | f74c403 | 2012-12-03 18:29:55 +0000 | [diff] [blame] | 38 | #include "clang/AST/Attr.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "clang/AST/CXXInheritance.h" |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 40 | #include "clang/AST/DeclObjC.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 41 | #include "clang/AST/DeclTemplate.h" |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 42 | #include "clang/AST/Mangle.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "clang/AST/RecordLayout.h" |
| 44 | #include "clang/AST/Type.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 45 | #include "clang/AST/VTableBuilder.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | #include "clang/Basic/Builtins.h" |
Sean Callanan | 7e2863b | 2012-02-06 21:28:03 +0000 | [diff] [blame] | 47 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileManager.h" |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 49 | #include "clang/Basic/FileSystemOptions.h" |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 50 | #include "clang/Basic/LangStandard.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | #include "clang/Basic/SourceManager.h" |
| 52 | #include "clang/Basic/TargetInfo.h" |
| 53 | #include "clang/Basic/TargetOptions.h" |
| 54 | #include "clang/Frontend/FrontendOptions.h" |
Raphael Isemann | f74a4c1 | 2019-04-30 08:41:35 +0000 | [diff] [blame] | 55 | #include "clang/Sema/Sema.h" |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 56 | |
| 57 | #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 58 | #undef NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 59 | #undef LLDB_DEFINED_NDEBUG_FOR_CLANG |
| 60 | // Need to re-include assert.h so it is as _we_ would expect it to be (enabled) |
| 61 | #include <assert.h> |
| 62 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 64 | #include "llvm/Support/Signals.h" |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 65 | #include "llvm/Support/Threading.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 66 | |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 67 | #include "Plugins/ExpressionParser/Clang/ClangFunctionCaller.h" |
Alex Langford | 9e86561 | 2019-09-09 23:11:43 +0000 | [diff] [blame] | 68 | #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 69 | #include "Plugins/ExpressionParser/Clang/ClangUserExpression.h" |
| 70 | #include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h" |
Pavel Labath | 5f19b90 | 2017-11-13 16:16:33 +0000 | [diff] [blame] | 71 | #include "lldb/Utility/ArchSpec.h" |
Zachary Turner | 01c3243 | 2017-02-14 19:06:07 +0000 | [diff] [blame] | 72 | #include "lldb/Utility/Flags.h" |
| 73 | |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 74 | #include "lldb/Core/DumpDataExtractor.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 75 | #include "lldb/Core/Module.h" |
| 76 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 77 | #include "lldb/Core/StreamFile.h" |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 78 | #include "lldb/Core/ThreadSafeDenseMap.h" |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 79 | #include "lldb/Core/UniqueCStringMap.h" |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 80 | #include "lldb/Symbol/ClangASTImporter.h" |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 81 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" |
Sean Callanan | 3b107b1 | 2011-12-03 03:15:28 +0000 | [diff] [blame] | 82 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 83 | #include "lldb/Symbol/ClangUtil.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 84 | #include "lldb/Symbol/ObjectFile.h" |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 85 | #include "lldb/Symbol/SymbolFile.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 86 | #include "lldb/Target/ExecutionContext.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 87 | #include "lldb/Target/Language.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 88 | #include "lldb/Target/Process.h" |
| 89 | #include "lldb/Target/Target.h" |
Zachary Turner | 666cc0b | 2017-03-04 01:30:05 +0000 | [diff] [blame] | 90 | #include "lldb/Utility/DataExtractor.h" |
Sean Callanan | c530ba9 | 2016-05-02 21:15:31 +0000 | [diff] [blame] | 91 | #include "lldb/Utility/LLDBAssert.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 92 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 93 | #include "lldb/Utility/RegularExpression.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 94 | #include "lldb/Utility/Scalar.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 95 | |
Alex Langford | b5701710 | 2019-07-15 22:56:12 +0000 | [diff] [blame] | 96 | #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h" |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 97 | #include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h" |
Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 98 | #include "Plugins/SymbolFile/PDB/PDBASTParser.h" |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 99 | |
Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 100 | #include <stdio.h> |
| 101 | |
Greg Clayton | 1341baf | 2013-07-11 23:36:31 +0000 | [diff] [blame] | 102 | #include <mutex> |
| 103 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 104 | using namespace lldb; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | using namespace lldb_private; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | using namespace clang; |
Pavel Labath | 6f23a68 | 2019-09-30 13:44:17 +0000 | [diff] [blame] | 107 | using llvm::StringSwitch; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 109 | namespace { |
Pavel Labath | 65a376f | 2019-08-21 13:11:30 +0000 | [diff] [blame] | 110 | #ifdef LLDB_CONFIGURATION_DEBUG |
Alex Langford | b2232a1 | 2019-08-20 22:06:13 +0000 | [diff] [blame] | 111 | static void VerifyDecl(clang::Decl *decl) { |
| 112 | assert(decl && "VerifyDecl called with nullptr?"); |
| 113 | decl->getAccess(); |
| 114 | } |
Pavel Labath | 65a376f | 2019-08-21 13:11:30 +0000 | [diff] [blame] | 115 | #endif |
Alex Langford | b2232a1 | 2019-08-20 22:06:13 +0000 | [diff] [blame] | 116 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | static inline bool |
| 118 | ClangASTContextSupportsLanguage(lldb::LanguageType language) { |
| 119 | return language == eLanguageTypeUnknown || // Clang is the default type system |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 120 | lldb_private::Language::LanguageIsC(language) || |
| 121 | lldb_private::Language::LanguageIsCPlusPlus(language) || |
| 122 | lldb_private::Language::LanguageIsObjC(language) || |
| 123 | lldb_private::Language::LanguageIsPascal(language) || |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | // Use Clang for Rust until there is a proper language plugin for it |
| 125 | language == eLanguageTypeRust || |
Johan Engelen | 0479957 | 2016-11-25 11:01:12 +0000 | [diff] [blame] | 126 | language == eLanguageTypeExtRenderScript || |
| 127 | // Use Clang for D until there is a proper language plugin for it |
Bruce Mitchener | b8233f8 | 2018-11-27 05:37:27 +0000 | [diff] [blame] | 128 | language == eLanguageTypeD || |
| 129 | // Open Dylan compiler debug info is designed to be Clang-compatible |
| 130 | language == eLanguageTypeDylan; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 131 | } |
Aleksandr Urakov | 7d2a74f | 2018-08-14 07:57:44 +0000 | [diff] [blame] | 132 | |
| 133 | // Checks whether m1 is an overload of m2 (as opposed to an override). This is |
| 134 | // called by addOverridesForMethod to distinguish overrides (which share a |
| 135 | // vtable entry) from overloads (which require distinct entries). |
| 136 | bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) { |
| 137 | // FIXME: This should detect covariant return types, but currently doesn't. |
| 138 | lldbassert(&m1->getASTContext() == &m2->getASTContext() && |
| 139 | "Methods should have the same AST context"); |
| 140 | clang::ASTContext &context = m1->getASTContext(); |
| 141 | |
| 142 | const auto *m1Type = llvm::cast<clang::FunctionProtoType>( |
| 143 | context.getCanonicalType(m1->getType())); |
| 144 | |
| 145 | const auto *m2Type = llvm::cast<clang::FunctionProtoType>( |
| 146 | context.getCanonicalType(m2->getType())); |
| 147 | |
| 148 | auto compareArgTypes = [&context](const clang::QualType &m1p, |
| 149 | const clang::QualType &m2p) { |
| 150 | return context.hasSameType(m1p.getUnqualifiedType(), |
| 151 | m2p.getUnqualifiedType()); |
| 152 | }; |
| 153 | |
| 154 | // FIXME: In C++14 and later, we can just pass m2Type->param_type_end() |
| 155 | // as a fourth parameter to std::equal(). |
| 156 | return (m1->getNumParams() != m2->getNumParams()) || |
| 157 | !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(), |
| 158 | m2Type->param_type_begin(), compareArgTypes); |
| 159 | } |
| 160 | |
| 161 | // If decl is a virtual method, walk the base classes looking for methods that |
| 162 | // decl overrides. This table of overridden methods is used by IRGen to |
| 163 | // determine the vtable layout for decl's parent class. |
| 164 | void addOverridesForMethod(clang::CXXMethodDecl *decl) { |
| 165 | if (!decl->isVirtual()) |
| 166 | return; |
| 167 | |
| 168 | clang::CXXBasePaths paths; |
| 169 | |
| 170 | auto find_overridden_methods = |
| 171 | [decl](const clang::CXXBaseSpecifier *specifier, |
| 172 | clang::CXXBasePath &path) { |
| 173 | if (auto *base_record = llvm::dyn_cast<clang::CXXRecordDecl>( |
| 174 | specifier->getType()->getAs<clang::RecordType>()->getDecl())) { |
| 175 | |
| 176 | clang::DeclarationName name = decl->getDeclName(); |
| 177 | |
| 178 | // If this is a destructor, check whether the base class destructor is |
| 179 | // virtual. |
| 180 | if (name.getNameKind() == clang::DeclarationName::CXXDestructorName) |
| 181 | if (auto *baseDtorDecl = base_record->getDestructor()) { |
| 182 | if (baseDtorDecl->isVirtual()) { |
| 183 | path.Decls = baseDtorDecl; |
| 184 | return true; |
| 185 | } else |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | // Otherwise, search for name in the base class. |
| 190 | for (path.Decls = base_record->lookup(name); !path.Decls.empty(); |
| 191 | path.Decls = path.Decls.slice(1)) { |
| 192 | if (auto *method_decl = |
| 193 | llvm::dyn_cast<clang::CXXMethodDecl>(path.Decls.front())) |
| 194 | if (method_decl->isVirtual() && !isOverload(decl, method_decl)) { |
| 195 | path.Decls = method_decl; |
| 196 | return true; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return false; |
| 202 | }; |
| 203 | |
| 204 | if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) { |
| 205 | for (auto *overridden_decl : paths.found_decls()) |
| 206 | decl->addOverriddenMethod( |
| 207 | llvm::cast<clang::CXXMethodDecl>(overridden_decl)); |
| 208 | } |
| 209 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Aleksandr Urakov | 1dc51db | 2018-11-12 16:23:50 +0000 | [diff] [blame] | 212 | static lldb::addr_t GetVTableAddress(Process &process, |
| 213 | VTableContextBase &vtable_ctx, |
| 214 | ValueObject &valobj, |
| 215 | const ASTRecordLayout &record_layout) { |
| 216 | // Retrieve type info |
| 217 | CompilerType pointee_type; |
| 218 | CompilerType this_type(valobj.GetCompilerType()); |
| 219 | uint32_t type_info = this_type.GetTypeInfo(&pointee_type); |
| 220 | if (!type_info) |
| 221 | return LLDB_INVALID_ADDRESS; |
| 222 | |
| 223 | // Check if it's a pointer or reference |
| 224 | bool ptr_or_ref = false; |
| 225 | if (type_info & (eTypeIsPointer | eTypeIsReference)) { |
| 226 | ptr_or_ref = true; |
| 227 | type_info = pointee_type.GetTypeInfo(); |
| 228 | } |
| 229 | |
| 230 | // We process only C++ classes |
| 231 | const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus; |
| 232 | if ((type_info & cpp_class) != cpp_class) |
| 233 | return LLDB_INVALID_ADDRESS; |
| 234 | |
| 235 | // Calculate offset to VTable pointer |
| 236 | lldb::offset_t vbtable_ptr_offset = |
| 237 | vtable_ctx.isMicrosoft() ? record_layout.getVBPtrOffset().getQuantity() |
| 238 | : 0; |
| 239 | |
| 240 | if (ptr_or_ref) { |
| 241 | // We have a pointer / ref to object, so read |
| 242 | // VTable pointer from process memory |
| 243 | |
| 244 | if (valobj.GetAddressTypeOfChildren() != eAddressTypeLoad) |
| 245 | return LLDB_INVALID_ADDRESS; |
| 246 | |
| 247 | auto vbtable_ptr_addr = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS); |
| 248 | if (vbtable_ptr_addr == LLDB_INVALID_ADDRESS) |
| 249 | return LLDB_INVALID_ADDRESS; |
| 250 | |
| 251 | vbtable_ptr_addr += vbtable_ptr_offset; |
| 252 | |
| 253 | Status err; |
| 254 | return process.ReadPointerFromMemory(vbtable_ptr_addr, err); |
| 255 | } |
| 256 | |
| 257 | // We have an object already read from process memory, |
| 258 | // so just extract VTable pointer from it |
| 259 | |
| 260 | DataExtractor data; |
| 261 | Status err; |
| 262 | auto size = valobj.GetData(data, err); |
| 263 | if (err.Fail() || vbtable_ptr_offset + data.GetAddressByteSize() > size) |
| 264 | return LLDB_INVALID_ADDRESS; |
| 265 | |
| 266 | return data.GetPointer(&vbtable_ptr_offset); |
| 267 | } |
| 268 | |
| 269 | static int64_t ReadVBaseOffsetFromVTable(Process &process, |
| 270 | VTableContextBase &vtable_ctx, |
| 271 | lldb::addr_t vtable_ptr, |
| 272 | const CXXRecordDecl *cxx_record_decl, |
| 273 | const CXXRecordDecl *base_class_decl) { |
| 274 | if (vtable_ctx.isMicrosoft()) { |
| 275 | clang::MicrosoftVTableContext &msoft_vtable_ctx = |
| 276 | static_cast<clang::MicrosoftVTableContext &>(vtable_ctx); |
| 277 | |
| 278 | // Get the index into the virtual base table. The |
| 279 | // index is the index in uint32_t from vbtable_ptr |
| 280 | const unsigned vbtable_index = |
| 281 | msoft_vtable_ctx.getVBTableIndex(cxx_record_decl, base_class_decl); |
| 282 | const lldb::addr_t base_offset_addr = vtable_ptr + vbtable_index * 4; |
| 283 | Status err; |
| 284 | return process.ReadSignedIntegerFromMemory(base_offset_addr, 4, INT64_MAX, |
| 285 | err); |
| 286 | } |
| 287 | |
| 288 | clang::ItaniumVTableContext &itanium_vtable_ctx = |
| 289 | static_cast<clang::ItaniumVTableContext &>(vtable_ctx); |
| 290 | |
| 291 | clang::CharUnits base_offset_offset = |
| 292 | itanium_vtable_ctx.getVirtualBaseOffsetOffset(cxx_record_decl, |
| 293 | base_class_decl); |
| 294 | const lldb::addr_t base_offset_addr = |
| 295 | vtable_ptr + base_offset_offset.getQuantity(); |
| 296 | const uint32_t base_offset_size = process.GetAddressByteSize(); |
| 297 | Status err; |
| 298 | return process.ReadSignedIntegerFromMemory(base_offset_addr, base_offset_size, |
| 299 | INT64_MAX, err); |
| 300 | } |
| 301 | |
| 302 | static bool GetVBaseBitOffset(VTableContextBase &vtable_ctx, |
| 303 | ValueObject &valobj, |
| 304 | const ASTRecordLayout &record_layout, |
| 305 | const CXXRecordDecl *cxx_record_decl, |
| 306 | const CXXRecordDecl *base_class_decl, |
| 307 | int32_t &bit_offset) { |
| 308 | ExecutionContext exe_ctx(valobj.GetExecutionContextRef()); |
| 309 | Process *process = exe_ctx.GetProcessPtr(); |
| 310 | if (!process) |
| 311 | return false; |
| 312 | |
| 313 | lldb::addr_t vtable_ptr = |
| 314 | GetVTableAddress(*process, vtable_ctx, valobj, record_layout); |
| 315 | if (vtable_ptr == LLDB_INVALID_ADDRESS) |
| 316 | return false; |
| 317 | |
| 318 | auto base_offset = ReadVBaseOffsetFromVTable( |
| 319 | *process, vtable_ctx, vtable_ptr, cxx_record_decl, base_class_decl); |
| 320 | if (base_offset == INT64_MAX) |
| 321 | return false; |
| 322 | |
| 323 | bit_offset = base_offset * 8; |
| 324 | |
| 325 | return true; |
| 326 | } |
| 327 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 328 | typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, ClangASTContext *> |
| 329 | ClangASTMap; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 330 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 331 | static ClangASTMap &GetASTMap() { |
| 332 | static ClangASTMap *g_map_ptr = nullptr; |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 333 | static llvm::once_flag g_once_flag; |
| 334 | llvm::call_once(g_once_flag, []() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 335 | g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins |
| 336 | }); |
| 337 | return *g_map_ptr; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Raphael Isemann | 2f323fc | 2019-08-28 13:46:01 +0000 | [diff] [blame] | 340 | bool ClangASTContext::IsOperator(llvm::StringRef name, |
Davide Italiano | 7e3ef4d | 2018-03-20 19:46:32 +0000 | [diff] [blame] | 341 | clang::OverloadedOperatorKind &op_kind) { |
Raphael Isemann | 2f323fc | 2019-08-28 13:46:01 +0000 | [diff] [blame] | 342 | // All operators have to start with "operator". |
| 343 | if (!name.consume_front("operator")) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 | return false; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 345 | |
Raphael Isemann | 2f323fc | 2019-08-28 13:46:01 +0000 | [diff] [blame] | 346 | // Remember if there was a space after "operator". This is necessary to |
| 347 | // check for collisions with strangely named functions like "operatorint()". |
| 348 | bool space_after_operator = name.consume_front(" "); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 349 | |
Raphael Isemann | 2f323fc | 2019-08-28 13:46:01 +0000 | [diff] [blame] | 350 | op_kind = StringSwitch<clang::OverloadedOperatorKind>(name) |
| 351 | .Case("+", clang::OO_Plus) |
| 352 | .Case("+=", clang::OO_PlusEqual) |
| 353 | .Case("++", clang::OO_PlusPlus) |
| 354 | .Case("-", clang::OO_Minus) |
| 355 | .Case("-=", clang::OO_MinusEqual) |
| 356 | .Case("--", clang::OO_MinusMinus) |
| 357 | .Case("->", clang::OO_Arrow) |
| 358 | .Case("->*", clang::OO_ArrowStar) |
| 359 | .Case("*", clang::OO_Star) |
| 360 | .Case("*=", clang::OO_StarEqual) |
| 361 | .Case("/", clang::OO_Slash) |
| 362 | .Case("/=", clang::OO_SlashEqual) |
| 363 | .Case("%", clang::OO_Percent) |
| 364 | .Case("%=", clang::OO_PercentEqual) |
| 365 | .Case("^", clang::OO_Caret) |
| 366 | .Case("^=", clang::OO_CaretEqual) |
| 367 | .Case("&", clang::OO_Amp) |
| 368 | .Case("&=", clang::OO_AmpEqual) |
| 369 | .Case("&&", clang::OO_AmpAmp) |
| 370 | .Case("|", clang::OO_Pipe) |
| 371 | .Case("|=", clang::OO_PipeEqual) |
| 372 | .Case("||", clang::OO_PipePipe) |
| 373 | .Case("~", clang::OO_Tilde) |
| 374 | .Case("!", clang::OO_Exclaim) |
| 375 | .Case("!=", clang::OO_ExclaimEqual) |
| 376 | .Case("=", clang::OO_Equal) |
| 377 | .Case("==", clang::OO_EqualEqual) |
| 378 | .Case("<", clang::OO_Less) |
| 379 | .Case("<<", clang::OO_LessLess) |
| 380 | .Case("<<=", clang::OO_LessLessEqual) |
| 381 | .Case("<=", clang::OO_LessEqual) |
| 382 | .Case(">", clang::OO_Greater) |
| 383 | .Case(">>", clang::OO_GreaterGreater) |
| 384 | .Case(">>=", clang::OO_GreaterGreaterEqual) |
| 385 | .Case(">=", clang::OO_GreaterEqual) |
| 386 | .Case("()", clang::OO_Call) |
| 387 | .Case("[]", clang::OO_Subscript) |
| 388 | .Case(",", clang::OO_Comma) |
| 389 | .Default(clang::NUM_OVERLOADED_OPERATORS); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 390 | |
Raphael Isemann | 2f323fc | 2019-08-28 13:46:01 +0000 | [diff] [blame] | 391 | // We found a fitting operator, so we can exit now. |
| 392 | if (op_kind != clang::NUM_OVERLOADED_OPERATORS) |
| 393 | return true; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 394 | |
Raphael Isemann | 2f323fc | 2019-08-28 13:46:01 +0000 | [diff] [blame] | 395 | // After the "operator " or "operator" part is something unknown. This means |
| 396 | // it's either one of the named operators (new/delete), a conversion operator |
| 397 | // (e.g. operator bool) or a function which name starts with "operator" |
| 398 | // (e.g. void operatorbool). |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 399 | |
Raphael Isemann | 2f323fc | 2019-08-28 13:46:01 +0000 | [diff] [blame] | 400 | // If it's a function that starts with operator it can't have a space after |
| 401 | // "operator" because identifiers can't contain spaces. |
| 402 | // E.g. "operator int" (conversion operator) |
| 403 | // vs. "operatorint" (function with colliding name). |
| 404 | if (!space_after_operator) |
| 405 | return false; // not an operator. |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 406 | |
Raphael Isemann | 2f323fc | 2019-08-28 13:46:01 +0000 | [diff] [blame] | 407 | // Now the operator is either one of the named operators or a conversion |
| 408 | // operator. |
| 409 | op_kind = StringSwitch<clang::OverloadedOperatorKind>(name) |
| 410 | .Case("new", clang::OO_New) |
| 411 | .Case("new[]", clang::OO_Array_New) |
| 412 | .Case("delete", clang::OO_Delete) |
| 413 | .Case("delete[]", clang::OO_Array_Delete) |
| 414 | // conversion operators hit this case. |
| 415 | .Default(clang::NUM_OVERLOADED_OPERATORS); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 416 | |
| 417 | return true; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 418 | } |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 419 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 420 | clang::AccessSpecifier |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 421 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(AccessType access) { |
| 422 | switch (access) { |
| 423 | default: |
| 424 | break; |
| 425 | case eAccessNone: |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 426 | return AS_none; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 427 | case eAccessPublic: |
| 428 | return AS_public; |
| 429 | case eAccessPrivate: |
| 430 | return AS_private; |
| 431 | case eAccessProtected: |
| 432 | return AS_protected; |
| 433 | } |
| 434 | return AS_none; |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 437 | static void ParseLangArgs(LangOptions &Opts, InputKind IK, const char *triple) { |
| 438 | // FIXME: Cleanup per-file based stuff. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 440 | // Set some properties which depend solely on the input kind; it would be |
| 441 | // nice to move these to the language standard, and have the driver resolve |
| 442 | // the input kind + language standard. |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 443 | if (IK.getLanguage() == clang::Language::Asm) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 444 | Opts.AsmPreprocessor = 1; |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 445 | } else if (IK.isObjectiveC()) { |
Erik Pilkington | fa98390 | 2018-10-30 20:31:30 +0000 | [diff] [blame] | 446 | Opts.ObjC = 1; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 450 | |
| 451 | if (LangStd == LangStandard::lang_unspecified) { |
| 452 | // Based on the base language, pick one. |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 453 | switch (IK.getLanguage()) { |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 454 | case clang::Language::Unknown: |
| 455 | case clang::Language::LLVM_IR: |
| 456 | case clang::Language::RenderScript: |
David Blaikie | a322f36 | 2017-01-06 00:38:06 +0000 | [diff] [blame] | 457 | llvm_unreachable("Invalid input kind!"); |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 458 | case clang::Language::OpenCL: |
Pavel Labath | 4716854 | 2017-04-27 08:49:19 +0000 | [diff] [blame] | 459 | LangStd = LangStandard::lang_opencl10; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 460 | break; |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 461 | case clang::Language::CUDA: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 462 | LangStd = LangStandard::lang_cuda; |
| 463 | break; |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 464 | case clang::Language::Asm: |
| 465 | case clang::Language::C: |
| 466 | case clang::Language::ObjC: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 467 | LangStd = LangStandard::lang_gnu99; |
| 468 | break; |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 469 | case clang::Language::CXX: |
| 470 | case clang::Language::ObjCXX: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | LangStd = LangStandard::lang_gnucxx98; |
| 472 | break; |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 473 | case clang::Language::HIP: |
Benjamin Kramer | 0d97c22 | 2018-04-25 13:22:47 +0000 | [diff] [blame] | 474 | LangStd = LangStandard::lang_hip; |
| 475 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 477 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 478 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 479 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
| 480 | Opts.LineComment = Std.hasLineComments(); |
| 481 | Opts.C99 = Std.isC99(); |
| 482 | Opts.CPlusPlus = Std.isCPlusPlus(); |
| 483 | Opts.CPlusPlus11 = Std.isCPlusPlus11(); |
| 484 | Opts.Digraphs = Std.hasDigraphs(); |
| 485 | Opts.GNUMode = Std.isGNUMode(); |
| 486 | Opts.GNUInline = !Std.isC99(); |
| 487 | Opts.HexFloats = Std.hasHexFloats(); |
| 488 | Opts.ImplicitInt = Std.hasImplicitInt(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 490 | Opts.WChar = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 491 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 492 | // OpenCL has some additional defaults. |
Pavel Labath | 4716854 | 2017-04-27 08:49:19 +0000 | [diff] [blame] | 493 | if (LangStd == LangStandard::lang_opencl10) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 494 | Opts.OpenCL = 1; |
| 495 | Opts.AltiVec = 1; |
| 496 | Opts.CXXOperatorNames = 1; |
Richard Smith | c624510 | 2019-09-13 06:02:15 +0000 | [diff] [blame] | 497 | Opts.setLaxVectorConversions(LangOptions::LaxVectorConversionKind::All); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 498 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 499 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 500 | // OpenCL and C++ both have bool, true, false keywords. |
| 501 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 502 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 503 | Opts.setValueVisibilityMode(DefaultVisibility); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 504 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 505 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs is |
| 506 | // specified, or -std is set to a conforming mode. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 507 | Opts.Trigraphs = !Opts.GNUMode; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 508 | Opts.CharIsSigned = ArchSpec(triple).CharIsSignedByDefault(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 509 | Opts.OptimizeSize = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 511 | // FIXME: Eliminate this dependency. |
| 512 | // unsigned Opt = |
| 513 | // Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags); |
| 514 | // Opts.Optimize = Opt != 0; |
| 515 | unsigned Opt = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 516 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 517 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 518 | // optimization level and -fno-inline, not actually whether the backend has |
| 519 | // inlining enabled. |
| 520 | // |
| 521 | // FIXME: This is affected by other options (-fno-inline). |
| 522 | Opts.NoInlineDefine = !Opt; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Raphael Isemann | d01b4a7 | 2019-10-01 12:28:14 +0000 | [diff] [blame] | 525 | ClangASTContext::ClangASTContext(llvm::StringRef target_triple) |
| 526 | : TypeSystem(TypeSystem::eKindClang) { |
| 527 | if (!target_triple.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 528 | SetTargetTriple(target_triple); |
Raphael Isemann | 2eb963a | 2019-10-02 12:26:08 +0000 | [diff] [blame] | 529 | // The caller didn't pass an ASTContext so create a new one for this |
| 530 | // ClangASTContext. |
| 531 | CreateASTContext(); |
| 532 | } |
| 533 | |
| 534 | ClangASTContext::ClangASTContext(ArchSpec arch) |
| 535 | : TypeSystem(TypeSystem::eKindClang) { |
| 536 | SetTargetTriple(arch.GetTriple().str()); |
| 537 | // The caller didn't pass an ASTContext so create a new one for this |
| 538 | // ClangASTContext. |
| 539 | CreateASTContext(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Raphael Isemann | c73bfc9 | 2019-10-01 12:55:37 +0000 | [diff] [blame] | 542 | ClangASTContext::ClangASTContext(ASTContext &existing_ctxt) |
| 543 | : TypeSystem(TypeSystem::eKindClang) { |
| 544 | SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str()); |
| 545 | |
| 546 | m_ast_up.reset(&existing_ctxt); |
| 547 | GetASTMap().Insert(&existing_ctxt, this); |
| 548 | } |
| 549 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | // Destructor |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 551 | ClangASTContext::~ClangASTContext() { Finalize(); } |
| 552 | |
| 553 | ConstString ClangASTContext::GetPluginNameStatic() { |
| 554 | return ConstString("clang"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 557 | ConstString ClangASTContext::GetPluginName() { |
| 558 | return ClangASTContext::GetPluginNameStatic(); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 561 | uint32_t ClangASTContext::GetPluginVersion() { return 1; } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 562 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 563 | lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language, |
| 564 | lldb_private::Module *module, |
| 565 | Target *target) { |
| 566 | if (ClangASTContextSupportsLanguage(language)) { |
| 567 | ArchSpec arch; |
| 568 | if (module) |
| 569 | arch = module->GetArchitecture(); |
| 570 | else if (target) |
| 571 | arch = target->GetArchitecture(); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 572 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 573 | if (arch.IsValid()) { |
| 574 | ArchSpec fixed_arch = arch; |
| 575 | // LLVM wants this to be set to iOS or MacOSX; if we're working on |
| 576 | // a bare-boards type image, change the triple for llvm's benefit. |
| 577 | if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple && |
| 578 | fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) { |
| 579 | if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm || |
| 580 | fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 || |
Jason Molenda | 7dd7a36 | 2019-10-16 19:14:49 +0000 | [diff] [blame] | 581 | fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64_32 || |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 582 | fixed_arch.GetTriple().getArch() == llvm::Triple::thumb) { |
| 583 | fixed_arch.GetTriple().setOS(llvm::Triple::IOS); |
| 584 | } else { |
| 585 | fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 586 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 587 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 588 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 589 | if (module) { |
Raphael Isemann | 2eb963a | 2019-10-02 12:26:08 +0000 | [diff] [blame] | 590 | std::shared_ptr<ClangASTContext> ast_sp( |
| 591 | new ClangASTContext(fixed_arch)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 592 | return ast_sp; |
| 593 | } else if (target && target->IsValid()) { |
| 594 | std::shared_ptr<ClangASTContextForExpressions> ast_sp( |
Raphael Isemann | 2eb963a | 2019-10-02 12:26:08 +0000 | [diff] [blame] | 595 | new ClangASTContextForExpressions(*target, fixed_arch)); |
| 596 | ast_sp->m_scratch_ast_source_up.reset( |
| 597 | new ClangASTSource(target->shared_from_this())); |
| 598 | lldbassert(ast_sp->getFileManager()); |
| 599 | ast_sp->m_scratch_ast_source_up->InstallASTContext( |
| 600 | *ast_sp->getASTContext(), *ast_sp->getFileManager(), true); |
| 601 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source( |
| 602 | ast_sp->m_scratch_ast_source_up->CreateProxy()); |
| 603 | ast_sp->SetExternalSource(proxy_ast_source); |
| 604 | return ast_sp; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 605 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 606 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 607 | } |
| 608 | return lldb::TypeSystemSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Adrian Prantl | aa97a89 | 2019-08-22 21:45:58 +0000 | [diff] [blame] | 611 | LanguageSet ClangASTContext::GetSupportedLanguagesForTypes() { |
| 612 | LanguageSet languages; |
| 613 | languages.Insert(lldb::eLanguageTypeC89); |
| 614 | languages.Insert(lldb::eLanguageTypeC); |
| 615 | languages.Insert(lldb::eLanguageTypeC11); |
| 616 | languages.Insert(lldb::eLanguageTypeC_plus_plus); |
| 617 | languages.Insert(lldb::eLanguageTypeC99); |
| 618 | languages.Insert(lldb::eLanguageTypeObjC); |
| 619 | languages.Insert(lldb::eLanguageTypeObjC_plus_plus); |
| 620 | languages.Insert(lldb::eLanguageTypeC_plus_plus_03); |
| 621 | languages.Insert(lldb::eLanguageTypeC_plus_plus_11); |
| 622 | languages.Insert(lldb::eLanguageTypeC11); |
| 623 | languages.Insert(lldb::eLanguageTypeC_plus_plus_14); |
| 624 | return languages; |
| 625 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 626 | |
Adrian Prantl | aa97a89 | 2019-08-22 21:45:58 +0000 | [diff] [blame] | 627 | LanguageSet ClangASTContext::GetSupportedLanguagesForExpressions() { |
| 628 | LanguageSet languages; |
| 629 | languages.Insert(lldb::eLanguageTypeC_plus_plus); |
| 630 | languages.Insert(lldb::eLanguageTypeObjC_plus_plus); |
| 631 | languages.Insert(lldb::eLanguageTypeC_plus_plus_03); |
| 632 | languages.Insert(lldb::eLanguageTypeC_plus_plus_11); |
| 633 | languages.Insert(lldb::eLanguageTypeC_plus_plus_14); |
| 634 | return languages; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 637 | void ClangASTContext::Initialize() { |
Adrian Prantl | aa97a89 | 2019-08-22 21:45:58 +0000 | [diff] [blame] | 638 | PluginManager::RegisterPlugin( |
| 639 | GetPluginNameStatic(), "clang base AST context plug-in", CreateInstance, |
| 640 | GetSupportedLanguagesForTypes(), GetSupportedLanguagesForExpressions()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 643 | void ClangASTContext::Terminate() { |
| 644 | PluginManager::UnregisterPlugin(CreateInstance); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 647 | void ClangASTContext::Finalize() { |
Raphael Isemann | 2eb963a | 2019-10-02 12:26:08 +0000 | [diff] [blame] | 648 | assert(m_ast_up); |
| 649 | GetASTMap().Erase(m_ast_up.get()); |
| 650 | if (!m_ast_owned) |
| 651 | m_ast_up.release(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 652 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 653 | m_builtins_up.reset(); |
| 654 | m_selector_table_up.reset(); |
| 655 | m_identifier_table_up.reset(); |
| 656 | m_target_info_up.reset(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 657 | m_target_options_rp.reset(); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 658 | m_diagnostics_engine_up.reset(); |
| 659 | m_source_manager_up.reset(); |
| 660 | m_language_options_up.reset(); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 661 | m_scratch_ast_source_up.reset(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Raphael Isemann | f74a4c1 | 2019-04-30 08:41:35 +0000 | [diff] [blame] | 664 | void ClangASTContext::setSema(Sema *s) { |
| 665 | // Ensure that the new sema actually belongs to our ASTContext. |
| 666 | assert(s == nullptr || &s->getASTContext() == m_ast_up.get()); |
| 667 | m_sema = s; |
| 668 | } |
| 669 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 670 | const char *ClangASTContext::GetTargetTriple() { |
| 671 | return m_target_triple.c_str(); |
| 672 | } |
| 673 | |
Raphael Isemann | d01b4a7 | 2019-10-01 12:28:14 +0000 | [diff] [blame] | 674 | void ClangASTContext::SetTargetTriple(llvm::StringRef target_triple) { |
Raphael Isemann | d01b4a7 | 2019-10-01 12:28:14 +0000 | [diff] [blame] | 675 | m_target_triple = target_triple.str(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 678 | void ClangASTContext::SetExternalSource( |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 679 | llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_up) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 680 | ASTContext *ast = getASTContext(); |
| 681 | if (ast) { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 682 | ast->setExternalSource(ast_source_up); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 683 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 687 | ASTContext *ClangASTContext::getASTContext() { |
Raphael Isemann | 2eb963a | 2019-10-02 12:26:08 +0000 | [diff] [blame] | 688 | assert(m_ast_up); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 689 | return m_ast_up.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Raphael Isemann | 2eb963a | 2019-10-02 12:26:08 +0000 | [diff] [blame] | 692 | void ClangASTContext::CreateASTContext() { |
| 693 | assert(!m_ast_up); |
| 694 | m_ast_owned = true; |
| 695 | m_ast_up.reset(new ASTContext(*getLanguageOptions(), *getSourceManager(), |
| 696 | *getIdentifierTable(), *getSelectorTable(), |
| 697 | *getBuiltinContext())); |
| 698 | |
| 699 | m_ast_up->getDiagnostics().setClient(getDiagnosticConsumer(), false); |
| 700 | |
| 701 | // This can be NULL if we don't know anything about the architecture or if |
| 702 | // the target for an architecture isn't enabled in the llvm/clang that we |
| 703 | // built |
| 704 | TargetInfo *target_info = getTargetInfo(); |
| 705 | if (target_info) |
| 706 | m_ast_up->InitBuiltinTypes(*target_info); |
| 707 | |
| 708 | if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton) { |
| 709 | m_ast_up->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
| 710 | // m_ast_up->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 711 | } |
| 712 | |
| 713 | GetASTMap().Insert(m_ast_up.get(), this); |
| 714 | |
| 715 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_up( |
| 716 | new ClangExternalASTSourceCallbacks( |
| 717 | ClangASTContext::CompleteTagDecl, |
| 718 | ClangASTContext::CompleteObjCInterfaceDecl, nullptr, |
| 719 | ClangASTContext::LayoutRecordType, this)); |
| 720 | SetExternalSource(ast_source_up); |
| 721 | } |
| 722 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 723 | ClangASTContext *ClangASTContext::GetASTContext(clang::ASTContext *ast) { |
| 724 | ClangASTContext *clang_ast = GetASTMap().Lookup(ast); |
| 725 | return clang_ast; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 728 | Builtin::Context *ClangASTContext::getBuiltinContext() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 729 | if (m_builtins_up == nullptr) |
| 730 | m_builtins_up.reset(new Builtin::Context()); |
| 731 | return m_builtins_up.get(); |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 734 | IdentifierTable *ClangASTContext::getIdentifierTable() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 735 | if (m_identifier_table_up == nullptr) |
| 736 | m_identifier_table_up.reset( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 737 | new IdentifierTable(*ClangASTContext::getLanguageOptions(), nullptr)); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 738 | return m_identifier_table_up.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 741 | LangOptions *ClangASTContext::getLanguageOptions() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 742 | if (m_language_options_up == nullptr) { |
| 743 | m_language_options_up.reset(new LangOptions()); |
Rainer Orth | 6ca1707 | 2019-08-05 14:00:43 +0000 | [diff] [blame] | 744 | ParseLangArgs(*m_language_options_up, clang::Language::ObjCXX, |
| 745 | GetTargetTriple()); |
| 746 | // InitializeLangOptions(*m_language_options_up, Language::ObjCXX); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 747 | } |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 748 | return m_language_options_up.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 751 | SelectorTable *ClangASTContext::getSelectorTable() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 752 | if (m_selector_table_up == nullptr) |
| 753 | m_selector_table_up.reset(new SelectorTable()); |
| 754 | return m_selector_table_up.get(); |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 757 | clang::FileManager *ClangASTContext::getFileManager() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 758 | if (m_file_manager_up == nullptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 759 | clang::FileSystemOptions file_system_options; |
Jonas Devlieghere | 9764b65 | 2019-02-18 20:31:18 +0000 | [diff] [blame] | 760 | m_file_manager_up.reset(new clang::FileManager( |
| 761 | file_system_options, FileSystem::Instance().GetVirtualFileSystem())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 762 | } |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 763 | return m_file_manager_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | clang::SourceManager *ClangASTContext::getSourceManager() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 767 | if (m_source_manager_up == nullptr) |
| 768 | m_source_manager_up.reset( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 769 | new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager())); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 770 | return m_source_manager_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | clang::DiagnosticsEngine *ClangASTContext::getDiagnosticsEngine() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 774 | if (m_diagnostics_engine_up == nullptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 775 | llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs()); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 776 | m_diagnostics_engine_up.reset( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 777 | new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions())); |
| 778 | } |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 779 | return m_diagnostics_engine_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | clang::MangleContext *ClangASTContext::getMangleContext() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 783 | if (m_mangle_ctx_up == nullptr) |
| 784 | m_mangle_ctx_up.reset(getASTContext()->createMangleContext()); |
| 785 | return m_mangle_ctx_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | class NullDiagnosticConsumer : public DiagnosticConsumer { |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 789 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 790 | NullDiagnosticConsumer() { |
| 791 | m_log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); |
| 792 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 793 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 794 | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
Raphael Isemann | 1756630 | 2019-05-03 10:03:28 +0000 | [diff] [blame] | 795 | const clang::Diagnostic &info) override { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 796 | if (m_log) { |
| 797 | llvm::SmallVector<char, 32> diag_str(10); |
| 798 | info.FormatDiagnostic(diag_str); |
| 799 | diag_str.push_back('\0'); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 800 | LLDB_LOGF(m_log, "Compiler diagnostic: %s\n", diag_str.data()); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 801 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const { |
| 805 | return new NullDiagnosticConsumer(); |
| 806 | } |
| 807 | |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 808 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 809 | Log *m_log; |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 810 | }; |
| 811 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 812 | DiagnosticConsumer *ClangASTContext::getDiagnosticConsumer() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 813 | if (m_diagnostic_consumer_up == nullptr) |
| 814 | m_diagnostic_consumer_up.reset(new NullDiagnosticConsumer); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 815 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 816 | return m_diagnostic_consumer_up.get(); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 819 | std::shared_ptr<clang::TargetOptions> &ClangASTContext::getTargetOptions() { |
Jonas Devlieghere | 70355ac | 2019-02-12 03:47:39 +0000 | [diff] [blame] | 820 | if (m_target_options_rp == nullptr && !m_target_triple.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 821 | m_target_options_rp = std::make_shared<clang::TargetOptions>(); |
Jonas Devlieghere | 70355ac | 2019-02-12 03:47:39 +0000 | [diff] [blame] | 822 | if (m_target_options_rp != nullptr) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 823 | m_target_options_rp->Triple = m_target_triple; |
| 824 | } |
| 825 | return m_target_options_rp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 828 | TargetInfo *ClangASTContext::getTargetInfo() { |
| 829 | // target_triple should be something like "x86_64-apple-macosx" |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 830 | if (m_target_info_up == nullptr && !m_target_triple.empty()) |
| 831 | m_target_info_up.reset(TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 832 | getTargetOptions())); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 833 | return m_target_info_up.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | #pragma mark Basic Types |
| 837 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 838 | static inline bool QualTypeMatchesBitSize(const uint64_t bit_size, |
| 839 | ASTContext *ast, QualType qual_type) { |
| 840 | uint64_t qual_type_bit_size = ast->getTypeSize(qual_type); |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 841 | return qual_type_bit_size == bit_size; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 842 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 843 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 844 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 845 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding, |
| 846 | size_t bit_size) { |
| 847 | return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize( |
| 848 | getASTContext(), encoding, bit_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 851 | CompilerType ClangASTContext::GetBuiltinTypeForEncodingAndBitSize( |
| 852 | ASTContext *ast, Encoding encoding, uint32_t bit_size) { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 853 | auto *clang_ast_context = ClangASTContext::GetASTContext(ast); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 854 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 855 | return CompilerType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 856 | switch (encoding) { |
| 857 | case eEncodingInvalid: |
| 858 | if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 859 | return CompilerType(clang_ast_context, ast->VoidPtrTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 860 | break; |
| 861 | |
| 862 | case eEncodingUint: |
| 863 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 864 | return CompilerType(clang_ast_context, |
| 865 | ast->UnsignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 866 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 867 | return CompilerType(clang_ast_context, |
| 868 | ast->UnsignedShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 869 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 870 | return CompilerType(clang_ast_context, |
| 871 | ast->UnsignedIntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 872 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 873 | return CompilerType(clang_ast_context, |
| 874 | ast->UnsignedLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 875 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 876 | return CompilerType(clang_ast_context, |
| 877 | ast->UnsignedLongLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 878 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 879 | return CompilerType(clang_ast_context, |
| 880 | ast->UnsignedInt128Ty.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case eEncodingSint: |
| 884 | if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 885 | return CompilerType(clang_ast_context, |
| 886 | ast->SignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 887 | if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 888 | return CompilerType(clang_ast_context, ast->ShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 889 | if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 890 | return CompilerType(clang_ast_context, ast->IntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 891 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 892 | return CompilerType(clang_ast_context, ast->LongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 893 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 894 | return CompilerType(clang_ast_context, ast->LongLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 895 | if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 896 | return CompilerType(clang_ast_context, ast->Int128Ty.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case eEncodingIEEE754: |
| 900 | if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 901 | return CompilerType(clang_ast_context, ast->FloatTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 902 | if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 903 | return CompilerType(clang_ast_context, ast->DoubleTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 904 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 905 | return CompilerType(clang_ast_context, |
| 906 | ast->LongDoubleTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 907 | if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 908 | return CompilerType(clang_ast_context, ast->HalfTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 909 | break; |
| 910 | |
| 911 | case eEncodingVector: |
| 912 | // Sanity check that bit_size is a multiple of 8's. |
| 913 | if (bit_size && !(bit_size & 0x7u)) |
| 914 | return CompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 915 | clang_ast_context, |
| 916 | ast->getExtVectorType(ast->UnsignedCharTy, bit_size / 8) |
| 917 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 918 | break; |
| 919 | } |
| 920 | |
| 921 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 924 | lldb::BasicType |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 925 | ClangASTContext::GetBasicTypeEnumeration(ConstString name) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 926 | if (name) { |
| 927 | typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; |
| 928 | static TypeNameToBasicTypeMap g_type_map; |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 929 | static llvm::once_flag g_once_flag; |
| 930 | llvm::call_once(g_once_flag, []() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 931 | // "void" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 932 | g_type_map.Append(ConstString("void"), eBasicTypeVoid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 933 | |
| 934 | // "char" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 935 | g_type_map.Append(ConstString("char"), eBasicTypeChar); |
| 936 | g_type_map.Append(ConstString("signed char"), eBasicTypeSignedChar); |
| 937 | g_type_map.Append(ConstString("unsigned char"), eBasicTypeUnsignedChar); |
| 938 | g_type_map.Append(ConstString("wchar_t"), eBasicTypeWChar); |
| 939 | g_type_map.Append(ConstString("signed wchar_t"), eBasicTypeSignedWChar); |
| 940 | g_type_map.Append(ConstString("unsigned wchar_t"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 941 | eBasicTypeUnsignedWChar); |
| 942 | // "short" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 943 | g_type_map.Append(ConstString("short"), eBasicTypeShort); |
| 944 | g_type_map.Append(ConstString("short int"), eBasicTypeShort); |
| 945 | g_type_map.Append(ConstString("unsigned short"), eBasicTypeUnsignedShort); |
| 946 | g_type_map.Append(ConstString("unsigned short int"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 947 | eBasicTypeUnsignedShort); |
| 948 | |
| 949 | // "int" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 950 | g_type_map.Append(ConstString("int"), eBasicTypeInt); |
| 951 | g_type_map.Append(ConstString("signed int"), eBasicTypeInt); |
| 952 | g_type_map.Append(ConstString("unsigned int"), eBasicTypeUnsignedInt); |
| 953 | g_type_map.Append(ConstString("unsigned"), eBasicTypeUnsignedInt); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 954 | |
| 955 | // "long" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 956 | g_type_map.Append(ConstString("long"), eBasicTypeLong); |
| 957 | g_type_map.Append(ConstString("long int"), eBasicTypeLong); |
| 958 | g_type_map.Append(ConstString("unsigned long"), eBasicTypeUnsignedLong); |
| 959 | g_type_map.Append(ConstString("unsigned long int"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 960 | eBasicTypeUnsignedLong); |
| 961 | |
| 962 | // "long long" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 963 | g_type_map.Append(ConstString("long long"), eBasicTypeLongLong); |
| 964 | g_type_map.Append(ConstString("long long int"), eBasicTypeLongLong); |
| 965 | g_type_map.Append(ConstString("unsigned long long"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 966 | eBasicTypeUnsignedLongLong); |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 967 | g_type_map.Append(ConstString("unsigned long long int"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 968 | eBasicTypeUnsignedLongLong); |
| 969 | |
| 970 | // "int128" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 971 | g_type_map.Append(ConstString("__int128_t"), eBasicTypeInt128); |
| 972 | g_type_map.Append(ConstString("__uint128_t"), eBasicTypeUnsignedInt128); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 973 | |
| 974 | // Miscellaneous |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 975 | g_type_map.Append(ConstString("bool"), eBasicTypeBool); |
| 976 | g_type_map.Append(ConstString("float"), eBasicTypeFloat); |
| 977 | g_type_map.Append(ConstString("double"), eBasicTypeDouble); |
| 978 | g_type_map.Append(ConstString("long double"), eBasicTypeLongDouble); |
| 979 | g_type_map.Append(ConstString("id"), eBasicTypeObjCID); |
| 980 | g_type_map.Append(ConstString("SEL"), eBasicTypeObjCSel); |
| 981 | g_type_map.Append(ConstString("nullptr"), eBasicTypeNullPtr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 982 | g_type_map.Sort(); |
| 983 | }); |
| 984 | |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 985 | return g_type_map.Find(name, eBasicTypeInvalid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 986 | } |
| 987 | return eBasicTypeInvalid; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Raphael Isemann | c502bae | 2019-11-20 12:40:08 +0100 | [diff] [blame^] | 990 | CompilerType ClangASTContext::GetBasicType(ConstString name) { |
| 991 | lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration(name); |
| 992 | return GetBasicType(basic_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | uint32_t ClangASTContext::GetPointerByteSize() { |
| 996 | if (m_pointer_byte_size == 0) |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 997 | if (auto size = GetBasicType(lldb::eBasicTypeVoid) |
| 998 | .GetPointerType() |
| 999 | .GetByteSize(nullptr)) |
| 1000 | m_pointer_byte_size = *size; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1001 | return m_pointer_byte_size; |
| 1002 | } |
| 1003 | |
| 1004 | CompilerType ClangASTContext::GetBasicType(lldb::BasicType basic_type) { |
Raphael Isemann | c502bae | 2019-11-20 12:40:08 +0100 | [diff] [blame^] | 1005 | clang::ASTContext *ast = getASTContext(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1006 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1007 | lldb::opaque_compiler_type_t clang_type = |
| 1008 | GetOpaqueCompilerType(ast, basic_type); |
| 1009 | |
| 1010 | if (clang_type) |
| 1011 | return CompilerType(GetASTContext(ast), clang_type); |
| 1012 | return CompilerType(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1015 | CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize( |
| 1016 | const char *type_name, uint32_t dw_ate, uint32_t bit_size) { |
| 1017 | ASTContext *ast = getASTContext(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1018 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1019 | #define streq(a, b) strcmp(a, b) == 0 |
| 1020 | assert(ast != nullptr); |
| 1021 | if (ast) { |
| 1022 | switch (dw_ate) { |
| 1023 | default: |
| 1024 | break; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1025 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1026 | case DW_ATE_address: |
| 1027 | if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1028 | return CompilerType(this, ast->VoidPtrTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1029 | break; |
Zachary Turner | 9d8a97e | 2016-04-01 23:20:35 +0000 | [diff] [blame] | 1030 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1031 | case DW_ATE_boolean: |
| 1032 | if (QualTypeMatchesBitSize(bit_size, ast, ast->BoolTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1033 | return CompilerType(this, ast->BoolTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1034 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1035 | return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1036 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1037 | return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1038 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1039 | return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1040 | break; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1041 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1042 | case DW_ATE_lo_user: |
| 1043 | // This has been seen to mean DW_AT_complex_integer |
| 1044 | if (type_name) { |
| 1045 | if (::strstr(type_name, "complex")) { |
| 1046 | CompilerType complex_int_clang_type = |
| 1047 | GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed, |
| 1048 | bit_size / 2); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1049 | return CompilerType( |
| 1050 | this, ast->getComplexType( |
| 1051 | ClangUtil::GetQualType(complex_int_clang_type)) |
| 1052 | .getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1053 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1054 | } |
| 1055 | break; |
| 1056 | |
| 1057 | case DW_ATE_complex_float: |
| 1058 | if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatComplexTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1059 | return CompilerType(this, ast->FloatComplexTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1060 | else if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleComplexTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1061 | return CompilerType(this, ast->DoubleComplexTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1062 | else if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleComplexTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1063 | return CompilerType(this, ast->LongDoubleComplexTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1064 | else { |
| 1065 | CompilerType complex_float_clang_type = |
| 1066 | GetBuiltinTypeForDWARFEncodingAndBitSize("float", DW_ATE_float, |
| 1067 | bit_size / 2); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1068 | return CompilerType( |
| 1069 | this, ast->getComplexType( |
| 1070 | ClangUtil::GetQualType(complex_float_clang_type)) |
| 1071 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1072 | } |
| 1073 | break; |
| 1074 | |
| 1075 | case DW_ATE_float: |
| 1076 | if (streq(type_name, "float") && |
| 1077 | QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1078 | return CompilerType(this, ast->FloatTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1079 | if (streq(type_name, "double") && |
| 1080 | QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1081 | return CompilerType(this, ast->DoubleTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1082 | if (streq(type_name, "long double") && |
| 1083 | QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1084 | return CompilerType(this, ast->LongDoubleTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1085 | // Fall back to not requiring a name match |
| 1086 | if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1087 | return CompilerType(this, ast->FloatTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1088 | if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1089 | return CompilerType(this, ast->DoubleTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1090 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1091 | return CompilerType(this, ast->LongDoubleTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1092 | if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1093 | return CompilerType(this, ast->HalfTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1094 | break; |
| 1095 | |
| 1096 | case DW_ATE_signed: |
| 1097 | if (type_name) { |
| 1098 | if (streq(type_name, "wchar_t") && |
| 1099 | QualTypeMatchesBitSize(bit_size, ast, ast->WCharTy) && |
| 1100 | (getTargetInfo() && |
| 1101 | TargetInfo::isTypeSigned(getTargetInfo()->getWCharType()))) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1102 | return CompilerType(this, ast->WCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1103 | if (streq(type_name, "void") && |
| 1104 | QualTypeMatchesBitSize(bit_size, ast, ast->VoidTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1105 | return CompilerType(this, ast->VoidTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1106 | if (strstr(type_name, "long long") && |
| 1107 | QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1108 | return CompilerType(this, ast->LongLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1109 | if (strstr(type_name, "long") && |
| 1110 | QualTypeMatchesBitSize(bit_size, ast, ast->LongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1111 | return CompilerType(this, ast->LongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1112 | if (strstr(type_name, "short") && |
| 1113 | QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1114 | return CompilerType(this, ast->ShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1115 | if (strstr(type_name, "char")) { |
| 1116 | if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1117 | return CompilerType(this, ast->CharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1118 | if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1119 | return CompilerType(this, ast->SignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1120 | } |
| 1121 | if (strstr(type_name, "int")) { |
| 1122 | if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1123 | return CompilerType(this, ast->IntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1124 | if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1125 | return CompilerType(this, ast->Int128Ty.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | // We weren't able to match up a type name, just search by size |
| 1129 | if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1130 | return CompilerType(this, ast->CharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1131 | if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1132 | return CompilerType(this, ast->ShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1133 | if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1134 | return CompilerType(this, ast->IntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1135 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1136 | return CompilerType(this, ast->LongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1137 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1138 | return CompilerType(this, ast->LongLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1139 | if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1140 | return CompilerType(this, ast->Int128Ty.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1141 | break; |
| 1142 | |
| 1143 | case DW_ATE_signed_char: |
| 1144 | if (ast->getLangOpts().CharIsSigned && type_name && |
| 1145 | streq(type_name, "char")) { |
| 1146 | if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1147 | return CompilerType(this, ast->CharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1148 | } |
| 1149 | if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1150 | return CompilerType(this, ast->SignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1151 | break; |
| 1152 | |
| 1153 | case DW_ATE_unsigned: |
| 1154 | if (type_name) { |
| 1155 | if (streq(type_name, "wchar_t")) { |
| 1156 | if (QualTypeMatchesBitSize(bit_size, ast, ast->WCharTy)) { |
| 1157 | if (!(getTargetInfo() && |
| 1158 | TargetInfo::isTypeSigned(getTargetInfo()->getWCharType()))) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1159 | return CompilerType(this, ast->WCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | if (strstr(type_name, "long long")) { |
| 1163 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1164 | return CompilerType(this, ast->UnsignedLongLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1165 | } else if (strstr(type_name, "long")) { |
| 1166 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1167 | return CompilerType(this, ast->UnsignedLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1168 | } else if (strstr(type_name, "short")) { |
| 1169 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1170 | return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1171 | } else if (strstr(type_name, "char")) { |
| 1172 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1173 | return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1174 | } else if (strstr(type_name, "int")) { |
| 1175 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1176 | return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1177 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1178 | return CompilerType(this, ast->UnsignedInt128Ty.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | // We weren't able to match up a type name, just search by size |
| 1182 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1183 | return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1184 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1185 | return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1186 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1187 | return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1188 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1189 | return CompilerType(this, ast->UnsignedLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1190 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1191 | return CompilerType(this, ast->UnsignedLongLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1192 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1193 | return CompilerType(this, ast->UnsignedInt128Ty.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1194 | break; |
| 1195 | |
| 1196 | case DW_ATE_unsigned_char: |
| 1197 | if (!ast->getLangOpts().CharIsSigned && type_name && |
| 1198 | streq(type_name, "char")) { |
| 1199 | if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1200 | return CompilerType(this, ast->CharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1201 | } |
| 1202 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1203 | return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1204 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1205 | return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1206 | break; |
| 1207 | |
| 1208 | case DW_ATE_imaginary_float: |
| 1209 | break; |
| 1210 | |
| 1211 | case DW_ATE_UTF: |
| 1212 | if (type_name) { |
Jonas Devlieghere | c46d39b | 2019-08-21 21:30:55 +0000 | [diff] [blame] | 1213 | if (streq(type_name, "char16_t")) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1214 | return CompilerType(this, ast->Char16Ty.getAsOpaquePtr()); |
Jonas Devlieghere | 6c9dc12 | 2019-08-23 04:11:38 +0000 | [diff] [blame] | 1215 | if (streq(type_name, "char32_t")) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1216 | return CompilerType(this, ast->Char32Ty.getAsOpaquePtr()); |
Jonas Devlieghere | 6c9dc12 | 2019-08-23 04:11:38 +0000 | [diff] [blame] | 1217 | if (streq(type_name, "char8_t")) |
Jonas Devlieghere | c46d39b | 2019-08-21 21:30:55 +0000 | [diff] [blame] | 1218 | return CompilerType(this, ast->Char8Ty.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1219 | } |
| 1220 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1221 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1222 | } |
| 1223 | // This assert should fire for anything that we don't catch above so we know |
| 1224 | // to fix any issues we run into. |
| 1225 | if (type_name) { |
| 1226 | Host::SystemLog(Host::eSystemLogError, "error: need to add support for " |
| 1227 | "DW_TAG_base_type '%s' encoded with " |
| 1228 | "DW_ATE = 0x%x, bit_size = %u\n", |
| 1229 | type_name, dw_ate, bit_size); |
| 1230 | } else { |
| 1231 | Host::SystemLog(Host::eSystemLogError, "error: need to add support for " |
| 1232 | "DW_TAG_base_type encoded with " |
| 1233 | "DW_ATE = 0x%x, bit_size = %u\n", |
| 1234 | dw_ate, bit_size); |
| 1235 | } |
| 1236 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1239 | CompilerType ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast) { |
| 1240 | if (ast) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1241 | return CompilerType(ClangASTContext::GetASTContext(ast), |
| 1242 | ast->UnknownAnyTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1243 | return CompilerType(); |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1246 | CompilerType ClangASTContext::GetCStringType(bool is_const) { |
| 1247 | ASTContext *ast = getASTContext(); |
| 1248 | QualType char_type(ast->CharTy); |
| 1249 | |
| 1250 | if (is_const) |
| 1251 | char_type.addConst(); |
| 1252 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1253 | return CompilerType(this, ast->getPointerType(char_type).getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Zachary Turner | 115209e | 2018-11-05 19:25:39 +0000 | [diff] [blame] | 1256 | clang::DeclContext * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1257 | ClangASTContext::GetTranslationUnitDecl(clang::ASTContext *ast) { |
| 1258 | return ast->getTranslationUnitDecl(); |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1261 | clang::Decl *ClangASTContext::CopyDecl(ASTContext *dst_ast, ASTContext *src_ast, |
| 1262 | clang::Decl *source_decl) { |
| 1263 | FileSystemOptions file_system_options; |
| 1264 | FileManager file_manager(file_system_options); |
| 1265 | ASTImporter importer(*dst_ast, file_manager, *src_ast, file_manager, false); |
| 1266 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1267 | if (llvm::Expected<clang::Decl *> ret_or_error = |
| 1268 | importer.Import(source_decl)) { |
| 1269 | return *ret_or_error; |
| 1270 | } else { |
| 1271 | Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); |
| 1272 | LLDB_LOG_ERROR(log, ret_or_error.takeError(), "Couldn't import decl: {0}"); |
| 1273 | return nullptr; |
| 1274 | } |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1277 | bool ClangASTContext::AreTypesSame(CompilerType type1, CompilerType type2, |
| 1278 | bool ignore_qualifiers) { |
| 1279 | ClangASTContext *ast = |
| 1280 | llvm::dyn_cast_or_null<ClangASTContext>(type1.GetTypeSystem()); |
| 1281 | if (!ast || ast != type2.GetTypeSystem()) |
| 1282 | return false; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1283 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1284 | if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType()) |
| 1285 | return true; |
Greg Clayton | 55995eb | 2012-04-06 17:38:55 +0000 | [diff] [blame] | 1286 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1287 | QualType type1_qual = ClangUtil::GetQualType(type1); |
| 1288 | QualType type2_qual = ClangUtil::GetQualType(type2); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 1289 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1290 | if (ignore_qualifiers) { |
| 1291 | type1_qual = type1_qual.getUnqualifiedType(); |
| 1292 | type2_qual = type2_qual.getUnqualifiedType(); |
| 1293 | } |
| 1294 | |
| 1295 | return ast->getASTContext()->hasSameType(type1_qual, type2_qual); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
Alex Langford | cb68bd7 | 2019-08-23 06:11:32 +0000 | [diff] [blame] | 1298 | CompilerType ClangASTContext::GetTypeForDecl(void *opaque_decl) { |
| 1299 | if (!opaque_decl) |
| 1300 | return CompilerType(); |
| 1301 | |
| 1302 | clang::Decl *decl = static_cast<clang::Decl *>(opaque_decl); |
| 1303 | if (auto *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl)) |
| 1304 | return GetTypeForDecl(named_decl); |
| 1305 | return CompilerType(); |
| 1306 | } |
| 1307 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1308 | CompilerType ClangASTContext::GetTypeForDecl(clang::NamedDecl *decl) { |
| 1309 | if (clang::ObjCInterfaceDecl *interface_decl = |
| 1310 | llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) |
| 1311 | return GetTypeForDecl(interface_decl); |
| 1312 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) |
| 1313 | return GetTypeForDecl(tag_decl); |
| 1314 | return CompilerType(); |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1317 | CompilerType ClangASTContext::GetTypeForDecl(TagDecl *decl) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1318 | // No need to call the getASTContext() accessor (which can create the AST if |
| 1319 | // it isn't created yet, because we can't have created a decl in this |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1320 | // AST if our AST didn't already exist... |
| 1321 | ASTContext *ast = &decl->getASTContext(); |
| 1322 | if (ast) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1323 | return CompilerType(ClangASTContext::GetASTContext(ast), |
| 1324 | ast->getTagDeclType(decl).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1325 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1328 | CompilerType ClangASTContext::GetTypeForDecl(ObjCInterfaceDecl *decl) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1329 | // No need to call the getASTContext() accessor (which can create the AST if |
| 1330 | // it isn't created yet, because we can't have created a decl in this |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1331 | // AST if our AST didn't already exist... |
| 1332 | ASTContext *ast = &decl->getASTContext(); |
| 1333 | if (ast) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1334 | return CompilerType(ClangASTContext::GetASTContext(ast), |
| 1335 | ast->getObjCInterfaceType(decl).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1336 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1339 | #pragma mark Structure, Unions, Classes |
| 1340 | |
shafik | de2c7ca | 2019-10-28 14:26:54 -0700 | [diff] [blame] | 1341 | CompilerType ClangASTContext::CreateRecordType( |
| 1342 | DeclContext *decl_ctx, AccessType access_type, const char *name, int kind, |
| 1343 | LanguageType language, ClangASTMetadata *metadata, bool exports_symbols) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1344 | ASTContext *ast = getASTContext(); |
| 1345 | assert(ast != nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1346 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1347 | if (decl_ctx == nullptr) |
| 1348 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1349 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1350 | if (language == eLanguageTypeObjC || |
| 1351 | language == eLanguageTypeObjC_plus_plus) { |
| 1352 | bool isForwardDecl = true; |
| 1353 | bool isInternal = false; |
| 1354 | return CreateObjCClass(name, decl_ctx, isForwardDecl, isInternal, metadata); |
| 1355 | } |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1356 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1357 | // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1358 | // we will need to update this code. I was told to currently always use the |
| 1359 | // CXXRecordDecl class since we often don't know from debug information if |
| 1360 | // something is struct or a class, so we default to always use the more |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1361 | // complete definition just in case. |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1362 | |
Shafik Yaghmour | 62abe49 | 2019-08-14 22:30:29 +0000 | [diff] [blame] | 1363 | bool has_name = name && name[0]; |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1364 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1365 | CXXRecordDecl *decl = CXXRecordDecl::Create( |
| 1366 | *ast, (TagDecl::TagKind)kind, decl_ctx, SourceLocation(), |
Shafik Yaghmour | 62abe49 | 2019-08-14 22:30:29 +0000 | [diff] [blame] | 1367 | SourceLocation(), has_name ? &ast->Idents.get(name) : nullptr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1368 | |
Shafik Yaghmour | 62abe49 | 2019-08-14 22:30:29 +0000 | [diff] [blame] | 1369 | if (!has_name) { |
| 1370 | // In C++ a lambda is also represented as an unnamed class. This is |
| 1371 | // different from an *anonymous class* that the user wrote: |
| 1372 | // |
| 1373 | // struct A { |
| 1374 | // // anonymous class (GNU/MSVC extension) |
| 1375 | // struct { |
| 1376 | // int x; |
| 1377 | // }; |
| 1378 | // // unnamed class within a class |
| 1379 | // struct { |
| 1380 | // int y; |
| 1381 | // } B; |
| 1382 | // }; |
| 1383 | // |
| 1384 | // void f() { |
| 1385 | // // unammed class outside of a class |
| 1386 | // struct { |
| 1387 | // int z; |
| 1388 | // } C; |
| 1389 | // } |
| 1390 | // |
| 1391 | // Anonymous classes is a GNU/MSVC extension that clang supports. It |
| 1392 | // requires the anonymous class be embedded within a class. So the new |
| 1393 | // heuristic verifies this condition. |
shafik | de2c7ca | 2019-10-28 14:26:54 -0700 | [diff] [blame] | 1394 | if (isa<CXXRecordDecl>(decl_ctx) && exports_symbols) |
Shafik Yaghmour | 62abe49 | 2019-08-14 22:30:29 +0000 | [diff] [blame] | 1395 | decl->setAnonymousStructOrUnion(true); |
Shafik Yaghmour | 62abe49 | 2019-08-14 22:30:29 +0000 | [diff] [blame] | 1396 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1397 | |
| 1398 | if (decl) { |
| 1399 | if (metadata) |
| 1400 | SetMetadata(ast, decl, *metadata); |
| 1401 | |
| 1402 | if (access_type != eAccessNone) |
| 1403 | decl->setAccess(ConvertAccessTypeToAccessSpecifier(access_type)); |
| 1404 | |
| 1405 | if (decl_ctx) |
| 1406 | decl_ctx->addDecl(decl); |
| 1407 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1408 | return CompilerType(this, ast->getTagDeclType(decl).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1409 | } |
| 1410 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1413 | namespace { |
| 1414 | bool IsValueParam(const clang::TemplateArgument &argument) { |
| 1415 | return argument.getKind() == TemplateArgument::Integral; |
| 1416 | } |
| 1417 | } |
| 1418 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1419 | static TemplateParameterList *CreateTemplateParameterList( |
| 1420 | ASTContext *ast, |
| 1421 | const ClangASTContext::TemplateParameterInfos &template_param_infos, |
| 1422 | llvm::SmallVector<NamedDecl *, 8> &template_param_decls) { |
| 1423 | const bool parameter_pack = false; |
| 1424 | const bool is_typename = false; |
| 1425 | const unsigned depth = 0; |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1426 | const size_t num_template_params = template_param_infos.args.size(); |
| 1427 | DeclContext *const decl_context = |
| 1428 | ast->getTranslationUnitDecl(); // Is this the right decl context?, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1429 | for (size_t i = 0; i < num_template_params; ++i) { |
| 1430 | const char *name = template_param_infos.names[i]; |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1431 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1432 | IdentifierInfo *identifier_info = nullptr; |
| 1433 | if (name && name[0]) |
| 1434 | identifier_info = &ast->Idents.get(name); |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1435 | if (IsValueParam(template_param_infos.args[i])) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1436 | template_param_decls.push_back(NonTypeTemplateParmDecl::Create( |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1437 | *ast, decl_context, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1438 | SourceLocation(), SourceLocation(), depth, i, identifier_info, |
| 1439 | template_param_infos.args[i].getIntegralType(), parameter_pack, |
| 1440 | nullptr)); |
| 1441 | |
| 1442 | } else { |
| 1443 | template_param_decls.push_back(TemplateTypeParmDecl::Create( |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1444 | *ast, decl_context, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1445 | SourceLocation(), SourceLocation(), depth, i, identifier_info, |
| 1446 | is_typename, parameter_pack)); |
| 1447 | } |
| 1448 | } |
Eugene Zemtsov | a9d928c | 2017-09-29 03:15:08 +0000 | [diff] [blame] | 1449 | |
Shafik Yaghmour | 1849dd4 | 2019-01-30 21:48:56 +0000 | [diff] [blame] | 1450 | if (template_param_infos.packed_args) { |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1451 | IdentifierInfo *identifier_info = nullptr; |
| 1452 | if (template_param_infos.pack_name && template_param_infos.pack_name[0]) |
| 1453 | identifier_info = &ast->Idents.get(template_param_infos.pack_name); |
| 1454 | const bool parameter_pack_true = true; |
Shafik Yaghmour | 1849dd4 | 2019-01-30 21:48:56 +0000 | [diff] [blame] | 1455 | |
| 1456 | if (!template_param_infos.packed_args->args.empty() && |
| 1457 | IsValueParam(template_param_infos.packed_args->args[0])) { |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1458 | template_param_decls.push_back(NonTypeTemplateParmDecl::Create( |
Shafik Yaghmour | 1849dd4 | 2019-01-30 21:48:56 +0000 | [diff] [blame] | 1459 | *ast, decl_context, SourceLocation(), SourceLocation(), depth, |
| 1460 | num_template_params, identifier_info, |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1461 | template_param_infos.packed_args->args[0].getIntegralType(), |
| 1462 | parameter_pack_true, nullptr)); |
| 1463 | } else { |
| 1464 | template_param_decls.push_back(TemplateTypeParmDecl::Create( |
Shafik Yaghmour | 1849dd4 | 2019-01-30 21:48:56 +0000 | [diff] [blame] | 1465 | *ast, decl_context, SourceLocation(), SourceLocation(), depth, |
| 1466 | num_template_params, identifier_info, is_typename, |
| 1467 | parameter_pack_true)); |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1468 | } |
| 1469 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1470 | clang::Expr *const requires_clause = nullptr; // TODO: Concepts |
| 1471 | TemplateParameterList *template_param_list = TemplateParameterList::Create( |
| 1472 | *ast, SourceLocation(), SourceLocation(), template_param_decls, |
| 1473 | SourceLocation(), requires_clause); |
| 1474 | return template_param_list; |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1477 | clang::FunctionTemplateDecl *ClangASTContext::CreateFunctionTemplateDecl( |
| 1478 | clang::DeclContext *decl_ctx, clang::FunctionDecl *func_decl, |
| 1479 | const char *name, const TemplateParameterInfos &template_param_infos) { |
Adrian Prantl | d8f460e | 2018-05-02 16:55:16 +0000 | [diff] [blame] | 1480 | // /// Create a function template node. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1481 | ASTContext *ast = getASTContext(); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1482 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1483 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1484 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1485 | TemplateParameterList *template_param_list = CreateTemplateParameterList( |
| 1486 | ast, template_param_infos, template_param_decls); |
| 1487 | FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create( |
| 1488 | *ast, decl_ctx, func_decl->getLocation(), func_decl->getDeclName(), |
| 1489 | template_param_list, func_decl); |
| 1490 | |
| 1491 | for (size_t i = 0, template_param_decl_count = template_param_decls.size(); |
| 1492 | i < template_param_decl_count; ++i) { |
| 1493 | // TODO: verify which decl context we should put template_param_decls into.. |
| 1494 | template_param_decls[i]->setDeclContext(func_decl); |
| 1495 | } |
| 1496 | |
| 1497 | return func_tmpl_decl; |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1500 | void ClangASTContext::CreateFunctionTemplateSpecializationInfo( |
| 1501 | FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl, |
| 1502 | const TemplateParameterInfos &infos) { |
Shafik Yaghmour | a0858e2 | 2019-07-17 20:16:13 +0000 | [diff] [blame] | 1503 | TemplateArgumentList *template_args_ptr = |
| 1504 | TemplateArgumentList::CreateCopy(func_decl->getASTContext(), infos.args); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1505 | |
Shafik Yaghmour | a0858e2 | 2019-07-17 20:16:13 +0000 | [diff] [blame] | 1506 | func_decl->setFunctionTemplateSpecialization(func_tmpl_decl, |
| 1507 | template_args_ptr, nullptr); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1510 | ClassTemplateDecl *ClangASTContext::CreateClassTemplateDecl( |
| 1511 | DeclContext *decl_ctx, lldb::AccessType access_type, const char *class_name, |
| 1512 | int kind, const TemplateParameterInfos &template_param_infos) { |
| 1513 | ASTContext *ast = getASTContext(); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1514 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1515 | ClassTemplateDecl *class_template_decl = nullptr; |
| 1516 | if (decl_ctx == nullptr) |
| 1517 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1518 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1519 | IdentifierInfo &identifier_info = ast->Idents.get(class_name); |
| 1520 | DeclarationName decl_name(&identifier_info); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1521 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1522 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1523 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1524 | for (NamedDecl *decl : result) { |
| 1525 | class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1526 | if (class_template_decl) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1527 | return class_template_decl; |
| 1528 | } |
| 1529 | |
| 1530 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
| 1531 | |
| 1532 | TemplateParameterList *template_param_list = CreateTemplateParameterList( |
| 1533 | ast, template_param_infos, template_param_decls); |
| 1534 | |
| 1535 | CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create( |
| 1536 | *ast, (TagDecl::TagKind)kind, |
| 1537 | decl_ctx, // What decl context do we use here? TU? The actual decl |
| 1538 | // context? |
| 1539 | SourceLocation(), SourceLocation(), &identifier_info); |
| 1540 | |
| 1541 | for (size_t i = 0, template_param_decl_count = template_param_decls.size(); |
| 1542 | i < template_param_decl_count; ++i) { |
| 1543 | template_param_decls[i]->setDeclContext(template_cxx_decl); |
| 1544 | } |
| 1545 | |
| 1546 | // With templated classes, we say that a class is templated with |
| 1547 | // specializations, but that the bare class has no functions. |
| 1548 | // template_cxx_decl->startDefinition(); |
| 1549 | // template_cxx_decl->completeDefinition(); |
| 1550 | |
| 1551 | class_template_decl = ClassTemplateDecl::Create( |
| 1552 | *ast, |
| 1553 | decl_ctx, // What decl context do we use here? TU? The actual decl |
| 1554 | // context? |
Pavel Labath | 4294de3 | 2017-01-12 10:44:16 +0000 | [diff] [blame] | 1555 | SourceLocation(), decl_name, template_param_list, template_cxx_decl); |
Richard Smith | 35b007e | 2019-02-15 21:48:09 +0000 | [diff] [blame] | 1556 | template_cxx_decl->setDescribedClassTemplate(class_template_decl); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1557 | |
| 1558 | if (class_template_decl) { |
| 1559 | if (access_type != eAccessNone) |
| 1560 | class_template_decl->setAccess( |
| 1561 | ConvertAccessTypeToAccessSpecifier(access_type)); |
| 1562 | |
| 1563 | // if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx)) |
| 1564 | // CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl)); |
| 1565 | |
| 1566 | decl_ctx->addDecl(class_template_decl); |
| 1567 | |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1568 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1569 | VerifyDecl(class_template_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1570 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1571 | } |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1572 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1573 | return class_template_decl; |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
Frederic Riss | f4e7e52 | 2018-04-02 16:18:32 +0000 | [diff] [blame] | 1576 | TemplateTemplateParmDecl * |
| 1577 | ClangASTContext::CreateTemplateTemplateParmDecl(const char *template_name) { |
| 1578 | ASTContext *ast = getASTContext(); |
| 1579 | |
| 1580 | auto *decl_ctx = ast->getTranslationUnitDecl(); |
| 1581 | |
| 1582 | IdentifierInfo &identifier_info = ast->Idents.get(template_name); |
| 1583 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
| 1584 | |
| 1585 | ClangASTContext::TemplateParameterInfos template_param_infos; |
| 1586 | TemplateParameterList *template_param_list = CreateTemplateParameterList( |
| 1587 | ast, template_param_infos, template_param_decls); |
| 1588 | |
| 1589 | // LLDB needs to create those decls only to be able to display a |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1590 | // type that includes a template template argument. Only the name matters for |
| 1591 | // this purpose, so we use dummy values for the other characterisitcs of the |
| 1592 | // type. |
Frederic Riss | f4e7e52 | 2018-04-02 16:18:32 +0000 | [diff] [blame] | 1593 | return TemplateTemplateParmDecl::Create( |
| 1594 | *ast, decl_ctx, SourceLocation(), |
| 1595 | /*Depth*/ 0, /*Position*/ 0, |
| 1596 | /*IsParameterPack*/ false, &identifier_info, template_param_list); |
| 1597 | } |
| 1598 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1599 | ClassTemplateSpecializationDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1600 | ClangASTContext::CreateClassTemplateSpecializationDecl( |
| 1601 | DeclContext *decl_ctx, ClassTemplateDecl *class_template_decl, int kind, |
| 1602 | const TemplateParameterInfos &template_param_infos) { |
| 1603 | ASTContext *ast = getASTContext(); |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1604 | llvm::SmallVector<clang::TemplateArgument, 2> args( |
| 1605 | template_param_infos.args.size() + |
| 1606 | (template_param_infos.packed_args ? 1 : 0)); |
| 1607 | std::copy(template_param_infos.args.begin(), template_param_infos.args.end(), |
| 1608 | args.begin()); |
| 1609 | if (template_param_infos.packed_args) { |
| 1610 | args[args.size() - 1] = TemplateArgument::CreatePackCopy( |
| 1611 | *ast, template_param_infos.packed_args->args); |
| 1612 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1613 | ClassTemplateSpecializationDecl *class_template_specialization_decl = |
| 1614 | ClassTemplateSpecializationDecl::Create( |
| 1615 | *ast, (TagDecl::TagKind)kind, decl_ctx, SourceLocation(), |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1616 | SourceLocation(), class_template_decl, args, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1617 | nullptr); |
| 1618 | |
| 1619 | class_template_specialization_decl->setSpecializationKind( |
| 1620 | TSK_ExplicitSpecialization); |
| 1621 | |
| 1622 | return class_template_specialization_decl; |
| 1623 | } |
| 1624 | |
| 1625 | CompilerType ClangASTContext::CreateClassTemplateSpecializationType( |
| 1626 | ClassTemplateSpecializationDecl *class_template_specialization_decl) { |
| 1627 | if (class_template_specialization_decl) { |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1628 | ASTContext *ast = getASTContext(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1629 | if (ast) |
| 1630 | return CompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1631 | this, ast->getTagDeclType(class_template_specialization_decl) |
| 1632 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1633 | } |
| 1634 | return CompilerType(); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1637 | static inline bool check_op_param(bool is_method, |
| 1638 | clang::OverloadedOperatorKind op_kind, |
| 1639 | bool unary, bool binary, |
| 1640 | uint32_t num_params) { |
| 1641 | // Special-case call since it can take any number of operands |
| 1642 | if (op_kind == OO_Call) |
| 1643 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1644 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1645 | // The parameter count doesn't include "this" |
| 1646 | if (is_method) |
| 1647 | ++num_params; |
| 1648 | if (num_params == 1) |
| 1649 | return unary; |
| 1650 | if (num_params == 2) |
| 1651 | return binary; |
| 1652 | else |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1653 | return false; |
| 1654 | } |
Daniel Dunbar | dacdfb5 | 2011-10-31 22:50:57 +0000 | [diff] [blame] | 1655 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1656 | bool ClangASTContext::CheckOverloadedOperatorKindParameterCount( |
| 1657 | bool is_method, clang::OverloadedOperatorKind op_kind, |
| 1658 | uint32_t num_params) { |
| 1659 | switch (op_kind) { |
| 1660 | default: |
| 1661 | break; |
| 1662 | // C++ standard allows any number of arguments to new/delete |
| 1663 | case OO_New: |
| 1664 | case OO_Array_New: |
| 1665 | case OO_Delete: |
| 1666 | case OO_Array_Delete: |
| 1667 | return true; |
| 1668 | } |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 1669 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1670 | #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \ |
| 1671 | case OO_##Name: \ |
| 1672 | return check_op_param(is_method, op_kind, Unary, Binary, num_params); |
| 1673 | switch (op_kind) { |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1674 | #include "clang/Basic/OperatorKinds.def" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1675 | default: |
| 1676 | break; |
| 1677 | } |
| 1678 | return false; |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1681 | clang::AccessSpecifier |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1682 | ClangASTContext::UnifyAccessSpecifiers(clang::AccessSpecifier lhs, |
| 1683 | clang::AccessSpecifier rhs) { |
| 1684 | // Make the access equal to the stricter of the field and the nested field's |
| 1685 | // access |
| 1686 | if (lhs == AS_none || rhs == AS_none) |
| 1687 | return AS_none; |
| 1688 | if (lhs == AS_private || rhs == AS_private) |
| 1689 | return AS_private; |
| 1690 | if (lhs == AS_protected || rhs == AS_protected) |
| 1691 | return AS_protected; |
| 1692 | return AS_public; |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1695 | bool ClangASTContext::FieldIsBitfield(FieldDecl *field, |
| 1696 | uint32_t &bitfield_bit_size) { |
Raphael Isemann | 02e9113 | 2019-11-20 12:09:19 +0100 | [diff] [blame] | 1697 | ASTContext *ast = getASTContext(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1698 | if (ast == nullptr || field == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1699 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1700 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1701 | if (field->isBitField()) { |
| 1702 | Expr *bit_width_expr = field->getBitWidth(); |
| 1703 | if (bit_width_expr) { |
| 1704 | llvm::APSInt bit_width_apsint; |
| 1705 | if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast)) { |
| 1706 | bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1707 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1708 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1709 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1710 | } |
| 1711 | return false; |
| 1712 | } |
| 1713 | |
| 1714 | bool ClangASTContext::RecordHasFields(const RecordDecl *record_decl) { |
| 1715 | if (record_decl == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1716 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1717 | |
| 1718 | if (!record_decl->field_empty()) |
| 1719 | return true; |
| 1720 | |
| 1721 | // No fields, lets check this is a CXX record and check the base classes |
| 1722 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 1723 | if (cxx_record_decl) { |
| 1724 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1725 | for (base_class = cxx_record_decl->bases_begin(), |
| 1726 | base_class_end = cxx_record_decl->bases_end(); |
| 1727 | base_class != base_class_end; ++base_class) { |
| 1728 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>( |
| 1729 | base_class->getType()->getAs<RecordType>()->getDecl()); |
| 1730 | if (RecordHasFields(base_class_decl)) |
| 1731 | return true; |
| 1732 | } |
| 1733 | } |
| 1734 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
Adrian Prantl | 4e8be2c | 2018-06-13 16:21:24 +0000 | [diff] [blame] | 1737 | #pragma mark Objective-C Classes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1738 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1739 | CompilerType ClangASTContext::CreateObjCClass(const char *name, |
| 1740 | DeclContext *decl_ctx, |
| 1741 | bool isForwardDecl, |
| 1742 | bool isInternal, |
| 1743 | ClangASTMetadata *metadata) { |
| 1744 | ASTContext *ast = getASTContext(); |
| 1745 | assert(ast != nullptr); |
| 1746 | assert(name && name[0]); |
| 1747 | if (decl_ctx == nullptr) |
| 1748 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1749 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1750 | ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create( |
| 1751 | *ast, decl_ctx, SourceLocation(), &ast->Idents.get(name), nullptr, |
| 1752 | nullptr, SourceLocation(), |
| 1753 | /*isForwardDecl,*/ |
| 1754 | isInternal); |
| 1755 | |
| 1756 | if (decl && metadata) |
| 1757 | SetMetadata(ast, decl, *metadata); |
| 1758 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 1759 | return CompilerType(this, ast->getObjCInterfaceType(decl).getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1762 | static inline bool BaseSpecifierIsEmpty(const CXXBaseSpecifier *b) { |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 1763 | return !ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1766 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1767 | ClangASTContext::GetNumBaseClasses(const CXXRecordDecl *cxx_record_decl, |
| 1768 | bool omit_empty_base_classes) { |
| 1769 | uint32_t num_bases = 0; |
| 1770 | if (cxx_record_decl) { |
| 1771 | if (omit_empty_base_classes) { |
| 1772 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1773 | for (base_class = cxx_record_decl->bases_begin(), |
| 1774 | base_class_end = cxx_record_decl->bases_end(); |
| 1775 | base_class != base_class_end; ++base_class) { |
| 1776 | // Skip empty base classes |
| 1777 | if (omit_empty_base_classes) { |
| 1778 | if (BaseSpecifierIsEmpty(base_class)) |
| 1779 | continue; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1780 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1781 | ++num_bases; |
| 1782 | } |
| 1783 | } else |
| 1784 | num_bases = cxx_record_decl->getNumBases(); |
| 1785 | } |
| 1786 | return num_bases; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1789 | #pragma mark Namespace Declarations |
| 1790 | |
Raphael Isemann | a946997 | 2019-03-12 07:45:04 +0000 | [diff] [blame] | 1791 | NamespaceDecl *ClangASTContext::GetUniqueNamespaceDeclaration( |
| 1792 | const char *name, DeclContext *decl_ctx, bool is_inline) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1793 | NamespaceDecl *namespace_decl = nullptr; |
| 1794 | ASTContext *ast = getASTContext(); |
| 1795 | TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl(); |
| 1796 | if (decl_ctx == nullptr) |
| 1797 | decl_ctx = translation_unit_decl; |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1798 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1799 | if (name) { |
| 1800 | IdentifierInfo &identifier_info = ast->Idents.get(name); |
| 1801 | DeclarationName decl_name(&identifier_info); |
| 1802 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
| 1803 | for (NamedDecl *decl : result) { |
| 1804 | namespace_decl = dyn_cast<clang::NamespaceDecl>(decl); |
| 1805 | if (namespace_decl) |
| 1806 | return namespace_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1807 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1808 | |
| 1809 | namespace_decl = |
Raphael Isemann | a946997 | 2019-03-12 07:45:04 +0000 | [diff] [blame] | 1810 | NamespaceDecl::Create(*ast, decl_ctx, is_inline, SourceLocation(), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1811 | SourceLocation(), &identifier_info, nullptr); |
| 1812 | |
| 1813 | decl_ctx->addDecl(namespace_decl); |
| 1814 | } else { |
| 1815 | if (decl_ctx == translation_unit_decl) { |
| 1816 | namespace_decl = translation_unit_decl->getAnonymousNamespace(); |
| 1817 | if (namespace_decl) |
| 1818 | return namespace_decl; |
| 1819 | |
| 1820 | namespace_decl = |
| 1821 | NamespaceDecl::Create(*ast, decl_ctx, false, SourceLocation(), |
| 1822 | SourceLocation(), nullptr, nullptr); |
| 1823 | translation_unit_decl->setAnonymousNamespace(namespace_decl); |
| 1824 | translation_unit_decl->addDecl(namespace_decl); |
| 1825 | assert(namespace_decl == translation_unit_decl->getAnonymousNamespace()); |
| 1826 | } else { |
| 1827 | NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx); |
| 1828 | if (parent_namespace_decl) { |
| 1829 | namespace_decl = parent_namespace_decl->getAnonymousNamespace(); |
| 1830 | if (namespace_decl) |
| 1831 | return namespace_decl; |
| 1832 | namespace_decl = |
| 1833 | NamespaceDecl::Create(*ast, decl_ctx, false, SourceLocation(), |
| 1834 | SourceLocation(), nullptr, nullptr); |
| 1835 | parent_namespace_decl->setAnonymousNamespace(namespace_decl); |
| 1836 | parent_namespace_decl->addDecl(namespace_decl); |
| 1837 | assert(namespace_decl == |
| 1838 | parent_namespace_decl->getAnonymousNamespace()); |
| 1839 | } else { |
Raphael Isemann | c494481 | 2019-07-04 19:49:31 +0000 | [diff] [blame] | 1840 | assert(false && "GetUniqueNamespaceDeclaration called with no name and " |
| 1841 | "no namespace as decl_ctx"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1842 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1843 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1844 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1845 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1846 | VerifyDecl(namespace_decl); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1847 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1848 | return namespace_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1851 | clang::BlockDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1852 | ClangASTContext::CreateBlockDeclaration(clang::DeclContext *ctx) { |
| 1853 | if (ctx != nullptr) { |
| 1854 | clang::BlockDecl *decl = clang::BlockDecl::Create(*getASTContext(), ctx, |
| 1855 | clang::SourceLocation()); |
| 1856 | ctx->addDecl(decl); |
| 1857 | return decl; |
| 1858 | } |
| 1859 | return nullptr; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1862 | clang::DeclContext *FindLCABetweenDecls(clang::DeclContext *left, |
| 1863 | clang::DeclContext *right, |
| 1864 | clang::DeclContext *root) { |
| 1865 | if (root == nullptr) |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1866 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1867 | |
| 1868 | std::set<clang::DeclContext *> path_left; |
| 1869 | for (clang::DeclContext *d = left; d != nullptr; d = d->getParent()) |
| 1870 | path_left.insert(d); |
| 1871 | |
| 1872 | for (clang::DeclContext *d = right; d != nullptr; d = d->getParent()) |
| 1873 | if (path_left.find(d) != path_left.end()) |
| 1874 | return d; |
| 1875 | |
| 1876 | return nullptr; |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1879 | clang::UsingDirectiveDecl *ClangASTContext::CreateUsingDirectiveDeclaration( |
| 1880 | clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl) { |
| 1881 | if (decl_ctx != nullptr && ns_decl != nullptr) { |
| 1882 | clang::TranslationUnitDecl *translation_unit = |
| 1883 | (clang::TranslationUnitDecl *)GetTranslationUnitDecl(getASTContext()); |
| 1884 | clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create( |
| 1885 | *getASTContext(), decl_ctx, clang::SourceLocation(), |
| 1886 | clang::SourceLocation(), clang::NestedNameSpecifierLoc(), |
| 1887 | clang::SourceLocation(), ns_decl, |
| 1888 | FindLCABetweenDecls(decl_ctx, ns_decl, translation_unit)); |
| 1889 | decl_ctx->addDecl(using_decl); |
| 1890 | return using_decl; |
| 1891 | } |
| 1892 | return nullptr; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | clang::UsingDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1896 | ClangASTContext::CreateUsingDeclaration(clang::DeclContext *current_decl_ctx, |
| 1897 | clang::NamedDecl *target) { |
| 1898 | if (current_decl_ctx != nullptr && target != nullptr) { |
| 1899 | clang::UsingDecl *using_decl = clang::UsingDecl::Create( |
| 1900 | *getASTContext(), current_decl_ctx, clang::SourceLocation(), |
| 1901 | clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(), false); |
| 1902 | clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create( |
| 1903 | *getASTContext(), current_decl_ctx, clang::SourceLocation(), using_decl, |
| 1904 | target); |
| 1905 | using_decl->addShadowDecl(shadow_decl); |
| 1906 | current_decl_ctx->addDecl(using_decl); |
| 1907 | return using_decl; |
| 1908 | } |
| 1909 | return nullptr; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1912 | clang::VarDecl *ClangASTContext::CreateVariableDeclaration( |
| 1913 | clang::DeclContext *decl_context, const char *name, clang::QualType type) { |
| 1914 | if (decl_context != nullptr) { |
| 1915 | clang::VarDecl *var_decl = clang::VarDecl::Create( |
| 1916 | *getASTContext(), decl_context, clang::SourceLocation(), |
| 1917 | clang::SourceLocation(), |
| 1918 | name && name[0] ? &getASTContext()->Idents.getOwn(name) : nullptr, type, |
| 1919 | nullptr, clang::SC_None); |
| 1920 | var_decl->setAccess(clang::AS_public); |
| 1921 | decl_context->addDecl(var_decl); |
| 1922 | return var_decl; |
| 1923 | } |
| 1924 | return nullptr; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
Zachary Turner | 9d8a97e | 2016-04-01 23:20:35 +0000 | [diff] [blame] | 1927 | lldb::opaque_compiler_type_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1928 | ClangASTContext::GetOpaqueCompilerType(clang::ASTContext *ast, |
| 1929 | lldb::BasicType basic_type) { |
| 1930 | switch (basic_type) { |
| 1931 | case eBasicTypeVoid: |
| 1932 | return ast->VoidTy.getAsOpaquePtr(); |
| 1933 | case eBasicTypeChar: |
| 1934 | return ast->CharTy.getAsOpaquePtr(); |
| 1935 | case eBasicTypeSignedChar: |
| 1936 | return ast->SignedCharTy.getAsOpaquePtr(); |
| 1937 | case eBasicTypeUnsignedChar: |
| 1938 | return ast->UnsignedCharTy.getAsOpaquePtr(); |
| 1939 | case eBasicTypeWChar: |
| 1940 | return ast->getWCharType().getAsOpaquePtr(); |
| 1941 | case eBasicTypeSignedWChar: |
| 1942 | return ast->getSignedWCharType().getAsOpaquePtr(); |
| 1943 | case eBasicTypeUnsignedWChar: |
| 1944 | return ast->getUnsignedWCharType().getAsOpaquePtr(); |
| 1945 | case eBasicTypeChar16: |
| 1946 | return ast->Char16Ty.getAsOpaquePtr(); |
| 1947 | case eBasicTypeChar32: |
| 1948 | return ast->Char32Ty.getAsOpaquePtr(); |
| 1949 | case eBasicTypeShort: |
| 1950 | return ast->ShortTy.getAsOpaquePtr(); |
| 1951 | case eBasicTypeUnsignedShort: |
| 1952 | return ast->UnsignedShortTy.getAsOpaquePtr(); |
| 1953 | case eBasicTypeInt: |
| 1954 | return ast->IntTy.getAsOpaquePtr(); |
| 1955 | case eBasicTypeUnsignedInt: |
| 1956 | return ast->UnsignedIntTy.getAsOpaquePtr(); |
| 1957 | case eBasicTypeLong: |
| 1958 | return ast->LongTy.getAsOpaquePtr(); |
| 1959 | case eBasicTypeUnsignedLong: |
| 1960 | return ast->UnsignedLongTy.getAsOpaquePtr(); |
| 1961 | case eBasicTypeLongLong: |
| 1962 | return ast->LongLongTy.getAsOpaquePtr(); |
| 1963 | case eBasicTypeUnsignedLongLong: |
| 1964 | return ast->UnsignedLongLongTy.getAsOpaquePtr(); |
| 1965 | case eBasicTypeInt128: |
| 1966 | return ast->Int128Ty.getAsOpaquePtr(); |
| 1967 | case eBasicTypeUnsignedInt128: |
| 1968 | return ast->UnsignedInt128Ty.getAsOpaquePtr(); |
| 1969 | case eBasicTypeBool: |
| 1970 | return ast->BoolTy.getAsOpaquePtr(); |
| 1971 | case eBasicTypeHalf: |
| 1972 | return ast->HalfTy.getAsOpaquePtr(); |
| 1973 | case eBasicTypeFloat: |
| 1974 | return ast->FloatTy.getAsOpaquePtr(); |
| 1975 | case eBasicTypeDouble: |
| 1976 | return ast->DoubleTy.getAsOpaquePtr(); |
| 1977 | case eBasicTypeLongDouble: |
| 1978 | return ast->LongDoubleTy.getAsOpaquePtr(); |
| 1979 | case eBasicTypeFloatComplex: |
| 1980 | return ast->FloatComplexTy.getAsOpaquePtr(); |
| 1981 | case eBasicTypeDoubleComplex: |
| 1982 | return ast->DoubleComplexTy.getAsOpaquePtr(); |
| 1983 | case eBasicTypeLongDoubleComplex: |
| 1984 | return ast->LongDoubleComplexTy.getAsOpaquePtr(); |
| 1985 | case eBasicTypeObjCID: |
| 1986 | return ast->getObjCIdType().getAsOpaquePtr(); |
| 1987 | case eBasicTypeObjCClass: |
| 1988 | return ast->getObjCClassType().getAsOpaquePtr(); |
| 1989 | case eBasicTypeObjCSel: |
| 1990 | return ast->getObjCSelType().getAsOpaquePtr(); |
| 1991 | case eBasicTypeNullPtr: |
| 1992 | return ast->NullPtrTy.getAsOpaquePtr(); |
| 1993 | default: |
| 1994 | return nullptr; |
| 1995 | } |
Zachary Turner | 9d8a97e | 2016-04-01 23:20:35 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1998 | #pragma mark Function Types |
| 1999 | |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 2000 | clang::DeclarationName |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2001 | ClangASTContext::GetDeclarationName(const char *name, |
| 2002 | const CompilerType &function_clang_type) { |
| 2003 | if (!name || !name[0]) |
| 2004 | return clang::DeclarationName(); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 2005 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2006 | clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS; |
| 2007 | if (!IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS) |
| 2008 | return DeclarationName(&getASTContext()->Idents.get( |
| 2009 | name)); // Not operator, but a regular function. |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 2010 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2011 | // Check the number of operator parameters. Sometimes we have seen bad DWARF |
| 2012 | // that doesn't correctly describe operators and if we try to create a method |
| 2013 | // and add it to the class, clang will assert and crash, so we need to make |
| 2014 | // sure things are acceptable. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2015 | clang::QualType method_qual_type(ClangUtil::GetQualType(function_clang_type)); |
| 2016 | const clang::FunctionProtoType *function_type = |
| 2017 | llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr()); |
| 2018 | if (function_type == nullptr) |
| 2019 | return clang::DeclarationName(); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 2020 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2021 | const bool is_method = false; |
| 2022 | const unsigned int num_params = function_type->getNumParams(); |
| 2023 | if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount( |
| 2024 | is_method, op_kind, num_params)) |
| 2025 | return clang::DeclarationName(); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 2026 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2027 | return getASTContext()->DeclarationNames.getCXXOperatorName(op_kind); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2030 | FunctionDecl *ClangASTContext::CreateFunctionDeclaration( |
| 2031 | DeclContext *decl_ctx, const char *name, |
| 2032 | const CompilerType &function_clang_type, int storage, bool is_inline) { |
| 2033 | FunctionDecl *func_decl = nullptr; |
| 2034 | ASTContext *ast = getASTContext(); |
| 2035 | if (decl_ctx == nullptr) |
| 2036 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2037 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2038 | const bool hasWrittenPrototype = true; |
| 2039 | const bool isConstexprSpecified = false; |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 2040 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2041 | clang::DeclarationName declarationName = |
| 2042 | GetDeclarationName(name, function_clang_type); |
| 2043 | func_decl = FunctionDecl::Create( |
| 2044 | *ast, decl_ctx, SourceLocation(), SourceLocation(), declarationName, |
| 2045 | ClangUtil::GetQualType(function_clang_type), nullptr, |
| 2046 | (clang::StorageClass)storage, is_inline, hasWrittenPrototype, |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 2047 | isConstexprSpecified ? CSK_constexpr : CSK_unspecified); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2048 | if (func_decl) |
| 2049 | decl_ctx->addDecl(func_decl); |
| 2050 | |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 2051 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2052 | VerifyDecl(func_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 2053 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2054 | |
| 2055 | return func_decl; |
| 2056 | } |
| 2057 | |
| 2058 | CompilerType ClangASTContext::CreateFunctionType( |
| 2059 | ASTContext *ast, const CompilerType &result_type, const CompilerType *args, |
Aleksandr Urakov | bc4707c | 2018-09-26 09:03:34 +0000 | [diff] [blame] | 2060 | unsigned num_args, bool is_variadic, unsigned type_quals, |
| 2061 | clang::CallingConv cc) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2062 | if (ast == nullptr) |
| 2063 | return CompilerType(); // invalid AST |
| 2064 | |
| 2065 | if (!result_type || !ClangUtil::IsClangType(result_type)) |
| 2066 | return CompilerType(); // invalid return type |
| 2067 | |
| 2068 | std::vector<QualType> qual_type_args; |
| 2069 | if (num_args > 0 && args == nullptr) |
| 2070 | return CompilerType(); // invalid argument array passed in |
| 2071 | |
| 2072 | // Verify that all arguments are valid and the right type |
| 2073 | for (unsigned i = 0; i < num_args; ++i) { |
| 2074 | if (args[i]) { |
| 2075 | // Make sure we have a clang type in args[i] and not a type from another |
| 2076 | // language whose name might match |
| 2077 | const bool is_clang_type = ClangUtil::IsClangType(args[i]); |
| 2078 | lldbassert(is_clang_type); |
| 2079 | if (is_clang_type) |
| 2080 | qual_type_args.push_back(ClangUtil::GetQualType(args[i])); |
| 2081 | else |
| 2082 | return CompilerType(); // invalid argument type (must be a clang type) |
| 2083 | } else |
| 2084 | return CompilerType(); // invalid argument type (empty) |
| 2085 | } |
| 2086 | |
| 2087 | // TODO: Detect calling convention in DWARF? |
| 2088 | FunctionProtoType::ExtProtoInfo proto_info; |
Aleksandr Urakov | bc4707c | 2018-09-26 09:03:34 +0000 | [diff] [blame] | 2089 | proto_info.ExtInfo = cc; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2090 | proto_info.Variadic = is_variadic; |
| 2091 | proto_info.ExceptionSpec = EST_None; |
Mikael Nilsson | 8b3bf6c | 2018-12-13 10:17:26 +0000 | [diff] [blame] | 2092 | proto_info.TypeQuals = clang::Qualifiers::fromFastMask(type_quals); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2093 | proto_info.RefQualifier = RQ_None; |
| 2094 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2095 | return CompilerType(ClangASTContext::GetASTContext(ast), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2096 | ast->getFunctionType(ClangUtil::GetQualType(result_type), |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2097 | qual_type_args, proto_info).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | ParmVarDecl *ClangASTContext::CreateParameterDeclaration( |
Zachary Turner | 6753d2d | 2018-12-12 17:17:53 +0000 | [diff] [blame] | 2101 | clang::DeclContext *decl_ctx, const char *name, |
Shafik Yaghmour | fa5c340 | 2019-08-02 21:41:50 +0000 | [diff] [blame] | 2102 | const CompilerType ¶m_type, int storage, bool add_decl) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2103 | ASTContext *ast = getASTContext(); |
| 2104 | assert(ast != nullptr); |
Zachary Turner | d3d2b9b | 2018-12-13 18:17:51 +0000 | [diff] [blame] | 2105 | auto *decl = |
| 2106 | ParmVarDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(), |
| 2107 | name && name[0] ? &ast->Idents.get(name) : nullptr, |
| 2108 | ClangUtil::GetQualType(param_type), nullptr, |
| 2109 | (clang::StorageClass)storage, nullptr); |
Shafik Yaghmour | fa5c340 | 2019-08-02 21:41:50 +0000 | [diff] [blame] | 2110 | if (add_decl) |
| 2111 | decl_ctx->addDecl(decl); |
| 2112 | |
Zachary Turner | d3d2b9b | 2018-12-13 18:17:51 +0000 | [diff] [blame] | 2113 | return decl; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | void ClangASTContext::SetFunctionParameters(FunctionDecl *function_decl, |
| 2117 | ParmVarDecl **params, |
| 2118 | unsigned num_params) { |
| 2119 | if (function_decl) |
| 2120 | function_decl->setParams(ArrayRef<ParmVarDecl *>(params, num_params)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2123 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2124 | ClangASTContext::CreateBlockPointerType(const CompilerType &function_type) { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 2125 | QualType block_type = m_ast_up->getBlockPointerType( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2126 | clang::QualType::getFromOpaquePtr(function_type.GetOpaqueQualType())); |
Greg Clayton | ceeb521 | 2016-05-26 22:33:25 +0000 | [diff] [blame] | 2127 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2128 | return CompilerType(this, block_type.getAsOpaquePtr()); |
Sean Callanan | c530ba9 | 2016-05-02 21:15:31 +0000 | [diff] [blame] | 2129 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2130 | |
| 2131 | #pragma mark Array Types |
| 2132 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2133 | CompilerType ClangASTContext::CreateArrayType(const CompilerType &element_type, |
| 2134 | size_t element_count, |
| 2135 | bool is_vector) { |
| 2136 | if (element_type.IsValid()) { |
| 2137 | ASTContext *ast = getASTContext(); |
| 2138 | assert(ast != nullptr); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2139 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2140 | if (is_vector) { |
| 2141 | return CompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2142 | this, ast->getExtVectorType(ClangUtil::GetQualType(element_type), |
| 2143 | element_count) |
| 2144 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2145 | } else { |
| 2146 | |
| 2147 | llvm::APInt ap_element_count(64, element_count); |
| 2148 | if (element_count == 0) { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2149 | return CompilerType(this, ast->getIncompleteArrayType( |
| 2150 | ClangUtil::GetQualType(element_type), |
| 2151 | clang::ArrayType::Normal, 0) |
| 2152 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2153 | } else { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2154 | return CompilerType(this, ast->getConstantArrayType( |
| 2155 | ClangUtil::GetQualType(element_type), |
Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 2156 | ap_element_count, nullptr, |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2157 | clang::ArrayType::Normal, 0) |
| 2158 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2159 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2160 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2161 | } |
| 2162 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2165 | CompilerType ClangASTContext::CreateStructForIdentifier( |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 2166 | ConstString type_name, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2167 | const std::initializer_list<std::pair<const char *, CompilerType>> |
| 2168 | &type_fields, |
| 2169 | bool packed) { |
| 2170 | CompilerType type; |
| 2171 | if (!type_name.IsEmpty() && |
| 2172 | (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)) |
| 2173 | .IsValid()) { |
Pavel Labath | f31c9d2 | 2017-01-05 13:18:42 +0000 | [diff] [blame] | 2174 | lldbassert(0 && "Trying to create a type for an existing name"); |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2175 | return type; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | type = CreateRecordType(nullptr, lldb::eAccessPublic, type_name.GetCString(), |
| 2179 | clang::TTK_Struct, lldb::eLanguageTypeC); |
| 2180 | StartTagDeclarationDefinition(type); |
| 2181 | for (const auto &field : type_fields) |
| 2182 | AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic, |
| 2183 | 0); |
| 2184 | if (packed) |
| 2185 | SetIsPacked(type); |
| 2186 | CompleteTagDeclarationDefinition(type); |
| 2187 | return type; |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2188 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2189 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2190 | CompilerType ClangASTContext::GetOrCreateStructForIdentifier( |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 2191 | ConstString type_name, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2192 | const std::initializer_list<std::pair<const char *, CompilerType>> |
| 2193 | &type_fields, |
| 2194 | bool packed) { |
| 2195 | CompilerType type; |
| 2196 | if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid()) |
| 2197 | return type; |
Sean Callanan | c530ba9 | 2016-05-02 21:15:31 +0000 | [diff] [blame] | 2198 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2199 | return CreateStructForIdentifier(type_name, type_fields, packed); |
Sean Callanan | c530ba9 | 2016-05-02 21:15:31 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2202 | #pragma mark Enumeration Types |
| 2203 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2204 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2205 | ClangASTContext::CreateEnumerationType(const char *name, DeclContext *decl_ctx, |
| 2206 | const Declaration &decl, |
Tamas Berghammer | 5976583 | 2017-11-07 10:39:22 +0000 | [diff] [blame] | 2207 | const CompilerType &integer_clang_type, |
| 2208 | bool is_scoped) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2209 | // TODO: Do something intelligent with the Declaration object passed in |
| 2210 | // like maybe filling in the SourceLocation with it... |
| 2211 | ASTContext *ast = getASTContext(); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 2212 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2213 | // TODO: ask about these... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2214 | // const bool IsFixed = false; |
| 2215 | |
| 2216 | EnumDecl *enum_decl = EnumDecl::Create( |
| 2217 | *ast, decl_ctx, SourceLocation(), SourceLocation(), |
| 2218 | name && name[0] ? &ast->Idents.get(name) : nullptr, nullptr, |
Tamas Berghammer | cf6bf4c | 2017-11-07 13:43:55 +0000 | [diff] [blame] | 2219 | is_scoped, // IsScoped |
| 2220 | is_scoped, // IsScopedUsingClassTag |
| 2221 | false); // IsFixed |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2222 | |
| 2223 | if (enum_decl) { |
Aleksandr Urakov | 709426b | 2018-09-10 08:08:43 +0000 | [diff] [blame] | 2224 | if (decl_ctx) |
| 2225 | decl_ctx->addDecl(enum_decl); |
| 2226 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2227 | // TODO: check if we should be setting the promotion type too? |
| 2228 | enum_decl->setIntegerType(ClangUtil::GetQualType(integer_clang_type)); |
| 2229 | |
| 2230 | enum_decl->setAccess(AS_public); // TODO respect what's in the debug info |
| 2231 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2232 | return CompilerType(this, ast->getTagDeclType(enum_decl).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2233 | } |
| 2234 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2237 | CompilerType ClangASTContext::GetIntTypeFromBitSize(clang::ASTContext *ast, |
| 2238 | size_t bit_size, |
| 2239 | bool is_signed) { |
| 2240 | if (ast) { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2241 | auto *clang_ast_context = ClangASTContext::GetASTContext(ast); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2242 | if (is_signed) { |
| 2243 | if (bit_size == ast->getTypeSize(ast->SignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2244 | return CompilerType(clang_ast_context, |
| 2245 | ast->SignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2246 | |
| 2247 | if (bit_size == ast->getTypeSize(ast->ShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2248 | return CompilerType(clang_ast_context, ast->ShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2249 | |
| 2250 | if (bit_size == ast->getTypeSize(ast->IntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2251 | return CompilerType(clang_ast_context, ast->IntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2252 | |
| 2253 | if (bit_size == ast->getTypeSize(ast->LongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2254 | return CompilerType(clang_ast_context, ast->LongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2255 | |
| 2256 | if (bit_size == ast->getTypeSize(ast->LongLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2257 | return CompilerType(clang_ast_context, |
| 2258 | ast->LongLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2259 | |
| 2260 | if (bit_size == ast->getTypeSize(ast->Int128Ty)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2261 | return CompilerType(clang_ast_context, ast->Int128Ty.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2262 | } else { |
| 2263 | if (bit_size == ast->getTypeSize(ast->UnsignedCharTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2264 | return CompilerType(clang_ast_context, |
| 2265 | ast->UnsignedCharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2266 | |
| 2267 | if (bit_size == ast->getTypeSize(ast->UnsignedShortTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2268 | return CompilerType(clang_ast_context, |
| 2269 | ast->UnsignedShortTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2270 | |
| 2271 | if (bit_size == ast->getTypeSize(ast->UnsignedIntTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2272 | return CompilerType(clang_ast_context, |
| 2273 | ast->UnsignedIntTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2274 | |
| 2275 | if (bit_size == ast->getTypeSize(ast->UnsignedLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2276 | return CompilerType(clang_ast_context, |
| 2277 | ast->UnsignedLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2278 | |
| 2279 | if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2280 | return CompilerType(clang_ast_context, |
| 2281 | ast->UnsignedLongLongTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2282 | |
| 2283 | if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty)) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2284 | return CompilerType(clang_ast_context, |
| 2285 | ast->UnsignedInt128Ty.getAsOpaquePtr()); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2286 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2287 | } |
| 2288 | return CompilerType(); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2291 | CompilerType ClangASTContext::GetPointerSizedIntType(clang::ASTContext *ast, |
| 2292 | bool is_signed) { |
| 2293 | if (ast) |
| 2294 | return GetIntTypeFromBitSize(ast, ast->getTypeSize(ast->VoidPtrTy), |
| 2295 | is_signed); |
| 2296 | return CompilerType(); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2297 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2298 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2299 | void ClangASTContext::DumpDeclContextHiearchy(clang::DeclContext *decl_ctx) { |
| 2300 | if (decl_ctx) { |
| 2301 | DumpDeclContextHiearchy(decl_ctx->getParent()); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2302 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2303 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx); |
| 2304 | if (named_decl) { |
| 2305 | printf("%20s: %s\n", decl_ctx->getDeclKindName(), |
| 2306 | named_decl->getDeclName().getAsString().c_str()); |
| 2307 | } else { |
| 2308 | printf("%20s\n", decl_ctx->getDeclKindName()); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2309 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2310 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2313 | void ClangASTContext::DumpDeclHiearchy(clang::Decl *decl) { |
| 2314 | if (decl == nullptr) |
| 2315 | return; |
| 2316 | DumpDeclContextHiearchy(decl->getDeclContext()); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2317 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2318 | clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl); |
| 2319 | if (record_decl) { |
| 2320 | printf("%20s: %s%s\n", decl->getDeclKindName(), |
| 2321 | record_decl->getDeclName().getAsString().c_str(), |
| 2322 | record_decl->isInjectedClassName() ? " (injected class name)" : ""); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2323 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2324 | } else { |
| 2325 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl); |
| 2326 | if (named_decl) { |
| 2327 | printf("%20s: %s\n", decl->getDeclKindName(), |
| 2328 | named_decl->getDeclName().getAsString().c_str()); |
| 2329 | } else { |
| 2330 | printf("%20s\n", decl->getDeclKindName()); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2331 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2332 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2335 | bool ClangASTContext::DeclsAreEquivalent(clang::Decl *lhs_decl, |
| 2336 | clang::Decl *rhs_decl) { |
| 2337 | if (lhs_decl && rhs_decl) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2338 | // Make sure the decl kinds match first |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2339 | const clang::Decl::Kind lhs_decl_kind = lhs_decl->getKind(); |
| 2340 | const clang::Decl::Kind rhs_decl_kind = rhs_decl->getKind(); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2341 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2342 | if (lhs_decl_kind == rhs_decl_kind) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2343 | // Now check that the decl contexts kinds are all equivalent before we |
| 2344 | // have to check any names of the decl contexts... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2345 | clang::DeclContext *lhs_decl_ctx = lhs_decl->getDeclContext(); |
| 2346 | clang::DeclContext *rhs_decl_ctx = rhs_decl->getDeclContext(); |
| 2347 | if (lhs_decl_ctx && rhs_decl_ctx) { |
Jonas Devlieghere | 09ad8c8 | 2019-05-24 00:44:33 +0000 | [diff] [blame] | 2348 | while (true) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2349 | if (lhs_decl_ctx && rhs_decl_ctx) { |
| 2350 | const clang::Decl::Kind lhs_decl_ctx_kind = |
| 2351 | lhs_decl_ctx->getDeclKind(); |
| 2352 | const clang::Decl::Kind rhs_decl_ctx_kind = |
| 2353 | rhs_decl_ctx->getDeclKind(); |
| 2354 | if (lhs_decl_ctx_kind == rhs_decl_ctx_kind) { |
| 2355 | lhs_decl_ctx = lhs_decl_ctx->getParent(); |
| 2356 | rhs_decl_ctx = rhs_decl_ctx->getParent(); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2357 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2358 | if (lhs_decl_ctx == nullptr && rhs_decl_ctx == nullptr) |
| 2359 | break; |
| 2360 | } else |
| 2361 | return false; |
| 2362 | } else |
Tamas Berghammer | fcf334b | 2015-12-02 11:35:54 +0000 | [diff] [blame] | 2363 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2366 | // Now make sure the name of the decls match |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2367 | clang::NamedDecl *lhs_named_decl = |
| 2368 | llvm::dyn_cast<clang::NamedDecl>(lhs_decl); |
| 2369 | clang::NamedDecl *rhs_named_decl = |
| 2370 | llvm::dyn_cast<clang::NamedDecl>(rhs_decl); |
| 2371 | if (lhs_named_decl && rhs_named_decl) { |
| 2372 | clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName(); |
| 2373 | clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName(); |
| 2374 | if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) { |
| 2375 | if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString()) |
| 2376 | return false; |
| 2377 | } else |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2378 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2379 | } else |
| 2380 | return false; |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2381 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2382 | // We know that the decl context kinds all match, so now we need to |
| 2383 | // make sure the names match as well |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2384 | lhs_decl_ctx = lhs_decl->getDeclContext(); |
| 2385 | rhs_decl_ctx = rhs_decl->getDeclContext(); |
Jonas Devlieghere | 09ad8c8 | 2019-05-24 00:44:33 +0000 | [diff] [blame] | 2386 | while (true) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2387 | switch (lhs_decl_ctx->getDeclKind()) { |
| 2388 | case clang::Decl::TranslationUnit: |
| 2389 | // We don't care about the translation unit names |
| 2390 | return true; |
| 2391 | default: { |
| 2392 | clang::NamedDecl *lhs_named_decl = |
| 2393 | llvm::dyn_cast<clang::NamedDecl>(lhs_decl_ctx); |
| 2394 | clang::NamedDecl *rhs_named_decl = |
| 2395 | llvm::dyn_cast<clang::NamedDecl>(rhs_decl_ctx); |
| 2396 | if (lhs_named_decl && rhs_named_decl) { |
| 2397 | clang::DeclarationName lhs_decl_name = |
| 2398 | lhs_named_decl->getDeclName(); |
| 2399 | clang::DeclarationName rhs_decl_name = |
| 2400 | rhs_named_decl->getDeclName(); |
| 2401 | if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) { |
| 2402 | if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString()) |
| 2403 | return false; |
| 2404 | } else |
| 2405 | return false; |
| 2406 | } else |
| 2407 | return false; |
| 2408 | } break; |
| 2409 | } |
| 2410 | lhs_decl_ctx = lhs_decl_ctx->getParent(); |
| 2411 | rhs_decl_ctx = rhs_decl_ctx->getParent(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2412 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2413 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2414 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2415 | } |
| 2416 | return false; |
| 2417 | } |
| 2418 | bool ClangASTContext::GetCompleteDecl(clang::ASTContext *ast, |
| 2419 | clang::Decl *decl) { |
| 2420 | if (!decl) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2421 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2422 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2423 | ExternalASTSource *ast_source = ast->getExternalSource(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2424 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2425 | if (!ast_source) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2426 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2427 | |
| 2428 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) { |
| 2429 | if (tag_decl->isCompleteDefinition()) |
| 2430 | return true; |
| 2431 | |
| 2432 | if (!tag_decl->hasExternalLexicalStorage()) |
| 2433 | return false; |
| 2434 | |
| 2435 | ast_source->CompleteType(tag_decl); |
| 2436 | |
| 2437 | return !tag_decl->getTypeForDecl()->isIncompleteType(); |
| 2438 | } else if (clang::ObjCInterfaceDecl *objc_interface_decl = |
| 2439 | llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) { |
| 2440 | if (objc_interface_decl->getDefinition()) |
| 2441 | return true; |
| 2442 | |
| 2443 | if (!objc_interface_decl->hasExternalLexicalStorage()) |
| 2444 | return false; |
| 2445 | |
| 2446 | ast_source->CompleteType(objc_interface_decl); |
| 2447 | |
| 2448 | return !objc_interface_decl->getTypeForDecl()->isIncompleteType(); |
| 2449 | } else { |
| 2450 | return false; |
| 2451 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2454 | void ClangASTContext::SetMetadataAsUserID(const void *object, |
| 2455 | user_id_t user_id) { |
| 2456 | ClangASTMetadata meta_data; |
| 2457 | meta_data.SetUserID(user_id); |
| 2458 | SetMetadata(object, meta_data); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2461 | void ClangASTContext::SetMetadata(clang::ASTContext *ast, const void *object, |
| 2462 | ClangASTMetadata &metadata) { |
| 2463 | ClangExternalASTSourceCommon *external_source = |
| 2464 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); |
| 2465 | |
| 2466 | if (external_source) |
| 2467 | external_source->SetMetadata(object, metadata); |
| 2468 | } |
| 2469 | |
| 2470 | ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast, |
| 2471 | const void *object) { |
| 2472 | ClangExternalASTSourceCommon *external_source = |
| 2473 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); |
| 2474 | |
| 2475 | if (external_source && external_source->HasMetadata(object)) |
| 2476 | return external_source->GetMetadata(object); |
| 2477 | else |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2478 | return nullptr; |
| 2479 | } |
| 2480 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2481 | bool ClangASTContext::SetTagTypeKind(clang::QualType tag_qual_type, |
| 2482 | int kind) const { |
| 2483 | const clang::Type *clang_type = tag_qual_type.getTypePtr(); |
| 2484 | if (clang_type) { |
| 2485 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(clang_type); |
| 2486 | if (tag_type) { |
| 2487 | clang::TagDecl *tag_decl = |
| 2488 | llvm::dyn_cast<clang::TagDecl>(tag_type->getDecl()); |
| 2489 | if (tag_decl) { |
| 2490 | tag_decl->setTagKind((clang::TagDecl::TagKind)kind); |
| 2491 | return true; |
| 2492 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2493 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2494 | } |
| 2495 | return false; |
| 2496 | } |
| 2497 | |
| 2498 | bool ClangASTContext::SetDefaultAccessForRecordFields( |
| 2499 | clang::RecordDecl *record_decl, int default_accessibility, |
| 2500 | int *assigned_accessibilities, size_t num_assigned_accessibilities) { |
| 2501 | if (record_decl) { |
| 2502 | uint32_t field_idx; |
| 2503 | clang::RecordDecl::field_iterator field, field_end; |
| 2504 | for (field = record_decl->field_begin(), |
| 2505 | field_end = record_decl->field_end(), field_idx = 0; |
| 2506 | field != field_end; ++field, ++field_idx) { |
| 2507 | // If no accessibility was assigned, assign the correct one |
| 2508 | if (field_idx < num_assigned_accessibilities && |
| 2509 | assigned_accessibilities[field_idx] == clang::AS_none) |
| 2510 | field->setAccess((clang::AccessSpecifier)default_accessibility); |
| 2511 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2512 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2513 | } |
| 2514 | return false; |
| 2515 | } |
| 2516 | |
| 2517 | clang::DeclContext * |
| 2518 | ClangASTContext::GetDeclContextForType(const CompilerType &type) { |
| 2519 | return GetDeclContextForType(ClangUtil::GetQualType(type)); |
| 2520 | } |
| 2521 | |
| 2522 | clang::DeclContext * |
| 2523 | ClangASTContext::GetDeclContextForType(clang::QualType type) { |
| 2524 | if (type.isNull()) |
| 2525 | return nullptr; |
| 2526 | |
| 2527 | clang::QualType qual_type = type.getCanonicalType(); |
| 2528 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2529 | switch (type_class) { |
| 2530 | case clang::Type::ObjCInterface: |
| 2531 | return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr()) |
| 2532 | ->getInterface(); |
| 2533 | case clang::Type::ObjCObjectPointer: |
| 2534 | return GetDeclContextForType( |
| 2535 | llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()) |
| 2536 | ->getPointeeType()); |
| 2537 | case clang::Type::Record: |
| 2538 | return llvm::cast<clang::RecordType>(qual_type)->getDecl(); |
| 2539 | case clang::Type::Enum: |
| 2540 | return llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 2541 | case clang::Type::Typedef: |
| 2542 | return GetDeclContextForType(llvm::cast<clang::TypedefType>(qual_type) |
| 2543 | ->getDecl() |
| 2544 | ->getUnderlyingType()); |
| 2545 | case clang::Type::Auto: |
| 2546 | return GetDeclContextForType( |
| 2547 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()); |
| 2548 | case clang::Type::Elaborated: |
| 2549 | return GetDeclContextForType( |
| 2550 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); |
| 2551 | case clang::Type::Paren: |
| 2552 | return GetDeclContextForType( |
| 2553 | llvm::cast<clang::ParenType>(qual_type)->desugar()); |
| 2554 | default: |
| 2555 | break; |
| 2556 | } |
| 2557 | // No DeclContext in this type... |
| 2558 | return nullptr; |
| 2559 | } |
| 2560 | |
| 2561 | static bool GetCompleteQualType(clang::ASTContext *ast, |
| 2562 | clang::QualType qual_type, |
| 2563 | bool allow_completion = true) { |
| 2564 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2565 | switch (type_class) { |
| 2566 | case clang::Type::ConstantArray: |
| 2567 | case clang::Type::IncompleteArray: |
| 2568 | case clang::Type::VariableArray: { |
| 2569 | const clang::ArrayType *array_type = |
| 2570 | llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr()); |
| 2571 | |
| 2572 | if (array_type) |
| 2573 | return GetCompleteQualType(ast, array_type->getElementType(), |
| 2574 | allow_completion); |
| 2575 | } break; |
| 2576 | case clang::Type::Record: { |
| 2577 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 2578 | if (cxx_record_decl) { |
| 2579 | if (cxx_record_decl->hasExternalLexicalStorage()) { |
| 2580 | const bool is_complete = cxx_record_decl->isCompleteDefinition(); |
| 2581 | const bool fields_loaded = |
| 2582 | cxx_record_decl->hasLoadedFieldsFromExternalStorage(); |
| 2583 | if (is_complete && fields_loaded) |
| 2584 | return true; |
| 2585 | |
| 2586 | if (!allow_completion) |
| 2587 | return false; |
| 2588 | |
| 2589 | // Call the field_begin() accessor to for it to use the external source |
| 2590 | // to load the fields... |
| 2591 | clang::ExternalASTSource *external_ast_source = |
| 2592 | ast->getExternalSource(); |
| 2593 | if (external_ast_source) { |
| 2594 | external_ast_source->CompleteType(cxx_record_decl); |
| 2595 | if (cxx_record_decl->isCompleteDefinition()) { |
| 2596 | cxx_record_decl->field_begin(); |
| 2597 | cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true); |
| 2598 | } |
| 2599 | } |
| 2600 | } |
| 2601 | } |
| 2602 | const clang::TagType *tag_type = |
| 2603 | llvm::cast<clang::TagType>(qual_type.getTypePtr()); |
| 2604 | return !tag_type->isIncompleteType(); |
| 2605 | } break; |
| 2606 | |
| 2607 | case clang::Type::Enum: { |
| 2608 | const clang::TagType *tag_type = |
| 2609 | llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 2610 | if (tag_type) { |
| 2611 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 2612 | if (tag_decl) { |
| 2613 | if (tag_decl->getDefinition()) |
| 2614 | return true; |
| 2615 | |
| 2616 | if (!allow_completion) |
| 2617 | return false; |
| 2618 | |
| 2619 | if (tag_decl->hasExternalLexicalStorage()) { |
| 2620 | if (ast) { |
| 2621 | clang::ExternalASTSource *external_ast_source = |
| 2622 | ast->getExternalSource(); |
| 2623 | if (external_ast_source) { |
| 2624 | external_ast_source->CompleteType(tag_decl); |
| 2625 | return !tag_type->isIncompleteType(); |
| 2626 | } |
| 2627 | } |
| 2628 | } |
| 2629 | return false; |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | } break; |
| 2634 | case clang::Type::ObjCObject: |
| 2635 | case clang::Type::ObjCInterface: { |
| 2636 | const clang::ObjCObjectType *objc_class_type = |
| 2637 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 2638 | if (objc_class_type) { |
| 2639 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 2640 | objc_class_type->getInterface(); |
| 2641 | // We currently can't complete objective C types through the newly added |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2642 | // ASTContext because it only supports TagDecl objects right now... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2643 | if (class_interface_decl) { |
| 2644 | if (class_interface_decl->getDefinition()) |
| 2645 | return true; |
| 2646 | |
| 2647 | if (!allow_completion) |
| 2648 | return false; |
| 2649 | |
| 2650 | if (class_interface_decl->hasExternalLexicalStorage()) { |
| 2651 | if (ast) { |
| 2652 | clang::ExternalASTSource *external_ast_source = |
| 2653 | ast->getExternalSource(); |
| 2654 | if (external_ast_source) { |
| 2655 | external_ast_source->CompleteType(class_interface_decl); |
| 2656 | return !objc_class_type->isIncompleteType(); |
| 2657 | } |
| 2658 | } |
| 2659 | } |
| 2660 | return false; |
| 2661 | } |
| 2662 | } |
| 2663 | } break; |
| 2664 | |
| 2665 | case clang::Type::Typedef: |
| 2666 | return GetCompleteQualType(ast, llvm::cast<clang::TypedefType>(qual_type) |
| 2667 | ->getDecl() |
| 2668 | ->getUnderlyingType(), |
| 2669 | allow_completion); |
| 2670 | |
| 2671 | case clang::Type::Auto: |
| 2672 | return GetCompleteQualType( |
| 2673 | ast, llvm::cast<clang::AutoType>(qual_type)->getDeducedType(), |
| 2674 | allow_completion); |
| 2675 | |
| 2676 | case clang::Type::Elaborated: |
| 2677 | return GetCompleteQualType( |
| 2678 | ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(), |
| 2679 | allow_completion); |
| 2680 | |
| 2681 | case clang::Type::Paren: |
| 2682 | return GetCompleteQualType( |
| 2683 | ast, llvm::cast<clang::ParenType>(qual_type)->desugar(), |
| 2684 | allow_completion); |
| 2685 | |
| 2686 | case clang::Type::Attributed: |
| 2687 | return GetCompleteQualType( |
| 2688 | ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(), |
| 2689 | allow_completion); |
| 2690 | |
| 2691 | default: |
| 2692 | break; |
| 2693 | } |
| 2694 | |
| 2695 | return true; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | static clang::ObjCIvarDecl::AccessControl |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2699 | ConvertAccessTypeToObjCIvarAccessControl(AccessType access) { |
| 2700 | switch (access) { |
| 2701 | case eAccessNone: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2702 | return clang::ObjCIvarDecl::None; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2703 | case eAccessPublic: |
| 2704 | return clang::ObjCIvarDecl::Public; |
| 2705 | case eAccessPrivate: |
| 2706 | return clang::ObjCIvarDecl::Private; |
| 2707 | case eAccessProtected: |
| 2708 | return clang::ObjCIvarDecl::Protected; |
| 2709 | case eAccessPackage: |
| 2710 | return clang::ObjCIvarDecl::Package; |
| 2711 | } |
| 2712 | return clang::ObjCIvarDecl::None; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2715 | // Tests |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2716 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2717 | bool ClangASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) { |
| 2718 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2719 | |
| 2720 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2721 | switch (type_class) { |
| 2722 | case clang::Type::IncompleteArray: |
| 2723 | case clang::Type::VariableArray: |
| 2724 | case clang::Type::ConstantArray: |
| 2725 | case clang::Type::ExtVector: |
| 2726 | case clang::Type::Vector: |
| 2727 | case clang::Type::Record: |
| 2728 | case clang::Type::ObjCObject: |
| 2729 | case clang::Type::ObjCInterface: |
| 2730 | return true; |
| 2731 | case clang::Type::Auto: |
| 2732 | return IsAggregateType(llvm::cast<clang::AutoType>(qual_type) |
| 2733 | ->getDeducedType() |
| 2734 | .getAsOpaquePtr()); |
| 2735 | case clang::Type::Elaborated: |
| 2736 | return IsAggregateType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 2737 | ->getNamedType() |
| 2738 | .getAsOpaquePtr()); |
| 2739 | case clang::Type::Typedef: |
| 2740 | return IsAggregateType(llvm::cast<clang::TypedefType>(qual_type) |
| 2741 | ->getDecl() |
| 2742 | ->getUnderlyingType() |
| 2743 | .getAsOpaquePtr()); |
| 2744 | case clang::Type::Paren: |
| 2745 | return IsAggregateType( |
| 2746 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 2747 | default: |
| 2748 | break; |
| 2749 | } |
| 2750 | // The clang type does have a value |
| 2751 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2752 | } |
| 2753 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2754 | bool ClangASTContext::IsAnonymousType(lldb::opaque_compiler_type_t type) { |
| 2755 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2756 | |
| 2757 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2758 | switch (type_class) { |
| 2759 | case clang::Type::Record: { |
| 2760 | if (const clang::RecordType *record_type = |
| 2761 | llvm::dyn_cast_or_null<clang::RecordType>( |
| 2762 | qual_type.getTypePtrOrNull())) { |
| 2763 | if (const clang::RecordDecl *record_decl = record_type->getDecl()) { |
| 2764 | return record_decl->isAnonymousStructOrUnion(); |
| 2765 | } |
Enrico Granata | 7123e2b | 2015-11-07 02:06:57 +0000 | [diff] [blame] | 2766 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2767 | break; |
| 2768 | } |
| 2769 | case clang::Type::Auto: |
| 2770 | return IsAnonymousType(llvm::cast<clang::AutoType>(qual_type) |
| 2771 | ->getDeducedType() |
| 2772 | .getAsOpaquePtr()); |
| 2773 | case clang::Type::Elaborated: |
| 2774 | return IsAnonymousType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 2775 | ->getNamedType() |
| 2776 | .getAsOpaquePtr()); |
| 2777 | case clang::Type::Typedef: |
| 2778 | return IsAnonymousType(llvm::cast<clang::TypedefType>(qual_type) |
| 2779 | ->getDecl() |
| 2780 | ->getUnderlyingType() |
| 2781 | .getAsOpaquePtr()); |
| 2782 | case clang::Type::Paren: |
| 2783 | return IsAnonymousType( |
| 2784 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 2785 | default: |
| 2786 | break; |
| 2787 | } |
| 2788 | // The clang type does have a value |
| 2789 | return false; |
Enrico Granata | 7123e2b | 2015-11-07 02:06:57 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2792 | bool ClangASTContext::IsArrayType(lldb::opaque_compiler_type_t type, |
| 2793 | CompilerType *element_type_ptr, |
| 2794 | uint64_t *size, bool *is_incomplete) { |
| 2795 | clang::QualType qual_type(GetCanonicalQualType(type)); |
Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2796 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2797 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2798 | switch (type_class) { |
| 2799 | default: |
| 2800 | break; |
Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2801 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2802 | case clang::Type::ConstantArray: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2803 | if (element_type_ptr) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2804 | element_type_ptr->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2805 | this, llvm::cast<clang::ConstantArrayType>(qual_type) |
| 2806 | ->getElementType() |
| 2807 | .getAsOpaquePtr()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2808 | if (size) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2809 | *size = llvm::cast<clang::ConstantArrayType>(qual_type) |
| 2810 | ->getSize() |
| 2811 | .getLimitedValue(ULLONG_MAX); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2812 | if (is_incomplete) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2813 | *is_incomplete = false; |
| 2814 | return true; |
| 2815 | |
| 2816 | case clang::Type::IncompleteArray: |
| 2817 | if (element_type_ptr) |
| 2818 | element_type_ptr->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2819 | this, llvm::cast<clang::IncompleteArrayType>(qual_type) |
| 2820 | ->getElementType() |
| 2821 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2822 | if (size) |
| 2823 | *size = 0; |
| 2824 | if (is_incomplete) |
| 2825 | *is_incomplete = true; |
| 2826 | return true; |
| 2827 | |
| 2828 | case clang::Type::VariableArray: |
| 2829 | if (element_type_ptr) |
| 2830 | element_type_ptr->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2831 | this, llvm::cast<clang::VariableArrayType>(qual_type) |
| 2832 | ->getElementType() |
| 2833 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2834 | if (size) |
| 2835 | *size = 0; |
| 2836 | if (is_incomplete) |
| 2837 | *is_incomplete = false; |
| 2838 | return true; |
| 2839 | |
| 2840 | case clang::Type::DependentSizedArray: |
| 2841 | if (element_type_ptr) |
| 2842 | element_type_ptr->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2843 | this, llvm::cast<clang::DependentSizedArrayType>(qual_type) |
| 2844 | ->getElementType() |
| 2845 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2846 | if (size) |
| 2847 | *size = 0; |
| 2848 | if (is_incomplete) |
| 2849 | *is_incomplete = false; |
| 2850 | return true; |
| 2851 | |
| 2852 | case clang::Type::Typedef: |
| 2853 | return IsArrayType(llvm::cast<clang::TypedefType>(qual_type) |
| 2854 | ->getDecl() |
| 2855 | ->getUnderlyingType() |
| 2856 | .getAsOpaquePtr(), |
| 2857 | element_type_ptr, size, is_incomplete); |
| 2858 | case clang::Type::Auto: |
| 2859 | return IsArrayType(llvm::cast<clang::AutoType>(qual_type) |
| 2860 | ->getDeducedType() |
| 2861 | .getAsOpaquePtr(), |
| 2862 | element_type_ptr, size, is_incomplete); |
| 2863 | case clang::Type::Elaborated: |
| 2864 | return IsArrayType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 2865 | ->getNamedType() |
| 2866 | .getAsOpaquePtr(), |
| 2867 | element_type_ptr, size, is_incomplete); |
| 2868 | case clang::Type::Paren: |
| 2869 | return IsArrayType( |
| 2870 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 2871 | element_type_ptr, size, is_incomplete); |
| 2872 | } |
| 2873 | if (element_type_ptr) |
| 2874 | element_type_ptr->Clear(); |
| 2875 | if (size) |
| 2876 | *size = 0; |
| 2877 | if (is_incomplete) |
| 2878 | *is_incomplete = false; |
| 2879 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2880 | } |
| 2881 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2882 | bool ClangASTContext::IsVectorType(lldb::opaque_compiler_type_t type, |
| 2883 | CompilerType *element_type, uint64_t *size) { |
| 2884 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2885 | |
| 2886 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2887 | switch (type_class) { |
| 2888 | case clang::Type::Vector: { |
| 2889 | const clang::VectorType *vector_type = |
| 2890 | qual_type->getAs<clang::VectorType>(); |
| 2891 | if (vector_type) { |
| 2892 | if (size) |
| 2893 | *size = vector_type->getNumElements(); |
| 2894 | if (element_type) |
| 2895 | *element_type = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2896 | CompilerType(this, vector_type->getElementType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2897 | } |
| 2898 | return true; |
| 2899 | } break; |
| 2900 | case clang::Type::ExtVector: { |
| 2901 | const clang::ExtVectorType *ext_vector_type = |
| 2902 | qual_type->getAs<clang::ExtVectorType>(); |
| 2903 | if (ext_vector_type) { |
| 2904 | if (size) |
| 2905 | *size = ext_vector_type->getNumElements(); |
| 2906 | if (element_type) |
| 2907 | *element_type = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 2908 | CompilerType(this, ext_vector_type->getElementType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2909 | } |
| 2910 | return true; |
| 2911 | } |
| 2912 | default: |
| 2913 | break; |
| 2914 | } |
| 2915 | return false; |
| 2916 | } |
| 2917 | |
| 2918 | bool ClangASTContext::IsRuntimeGeneratedType( |
| 2919 | lldb::opaque_compiler_type_t type) { |
| 2920 | clang::DeclContext *decl_ctx = ClangASTContext::GetASTContext(getASTContext()) |
| 2921 | ->GetDeclContextForType(GetQualType(type)); |
| 2922 | if (!decl_ctx) |
| 2923 | return false; |
| 2924 | |
| 2925 | if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx)) |
| 2926 | return false; |
| 2927 | |
| 2928 | clang::ObjCInterfaceDecl *result_iface_decl = |
| 2929 | llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx); |
| 2930 | |
| 2931 | ClangASTMetadata *ast_metadata = |
| 2932 | ClangASTContext::GetMetadata(getASTContext(), result_iface_decl); |
| 2933 | if (!ast_metadata) |
| 2934 | return false; |
| 2935 | return (ast_metadata->GetISAPtr() != 0); |
| 2936 | } |
| 2937 | |
| 2938 | bool ClangASTContext::IsCharType(lldb::opaque_compiler_type_t type) { |
| 2939 | return GetQualType(type).getUnqualifiedType()->isCharType(); |
| 2940 | } |
| 2941 | |
| 2942 | bool ClangASTContext::IsCompleteType(lldb::opaque_compiler_type_t type) { |
| 2943 | const bool allow_completion = false; |
| 2944 | return GetCompleteQualType(getASTContext(), GetQualType(type), |
| 2945 | allow_completion); |
| 2946 | } |
| 2947 | |
| 2948 | bool ClangASTContext::IsConst(lldb::opaque_compiler_type_t type) { |
| 2949 | return GetQualType(type).isConstQualified(); |
| 2950 | } |
| 2951 | |
| 2952 | bool ClangASTContext::IsCStringType(lldb::opaque_compiler_type_t type, |
| 2953 | uint32_t &length) { |
| 2954 | CompilerType pointee_or_element_clang_type; |
| 2955 | length = 0; |
| 2956 | Flags type_flags(GetTypeInfo(type, &pointee_or_element_clang_type)); |
| 2957 | |
| 2958 | if (!pointee_or_element_clang_type.IsValid()) |
| 2959 | return false; |
| 2960 | |
| 2961 | if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer)) { |
| 2962 | if (pointee_or_element_clang_type.IsCharType()) { |
| 2963 | if (type_flags.Test(eTypeIsArray)) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2964 | // We know the size of the array and it could be a C string since it is |
| 2965 | // an array of characters |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2966 | length = llvm::cast<clang::ConstantArrayType>( |
| 2967 | GetCanonicalQualType(type).getTypePtr()) |
| 2968 | ->getSize() |
| 2969 | .getLimitedValue(); |
| 2970 | } |
| 2971 | return true; |
| 2972 | } |
| 2973 | } |
| 2974 | return false; |
| 2975 | } |
| 2976 | |
| 2977 | bool ClangASTContext::IsFunctionType(lldb::opaque_compiler_type_t type, |
| 2978 | bool *is_variadic_ptr) { |
| 2979 | if (type) { |
| 2980 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2981 | |
| 2982 | if (qual_type->isFunctionType()) { |
| 2983 | if (is_variadic_ptr) { |
| 2984 | const clang::FunctionProtoType *function_proto_type = |
| 2985 | llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 2986 | if (function_proto_type) |
| 2987 | *is_variadic_ptr = function_proto_type->isVariadic(); |
| 2988 | else |
| 2989 | *is_variadic_ptr = false; |
| 2990 | } |
| 2991 | return true; |
| 2992 | } |
| 2993 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2994 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2995 | switch (type_class) { |
| 2996 | default: |
| 2997 | break; |
| 2998 | case clang::Type::Typedef: |
| 2999 | return IsFunctionType(llvm::cast<clang::TypedefType>(qual_type) |
| 3000 | ->getDecl() |
| 3001 | ->getUnderlyingType() |
| 3002 | .getAsOpaquePtr(), |
| 3003 | nullptr); |
| 3004 | case clang::Type::Auto: |
| 3005 | return IsFunctionType(llvm::cast<clang::AutoType>(qual_type) |
| 3006 | ->getDeducedType() |
| 3007 | .getAsOpaquePtr(), |
| 3008 | nullptr); |
| 3009 | case clang::Type::Elaborated: |
| 3010 | return IsFunctionType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3011 | ->getNamedType() |
| 3012 | .getAsOpaquePtr(), |
| 3013 | nullptr); |
| 3014 | case clang::Type::Paren: |
| 3015 | return IsFunctionType( |
| 3016 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3017 | nullptr); |
| 3018 | case clang::Type::LValueReference: |
| 3019 | case clang::Type::RValueReference: { |
| 3020 | const clang::ReferenceType *reference_type = |
| 3021 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 3022 | if (reference_type) |
| 3023 | return IsFunctionType(reference_type->getPointeeType().getAsOpaquePtr(), |
| 3024 | nullptr); |
| 3025 | } break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3026 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3027 | } |
| 3028 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | // Used to detect "Homogeneous Floating-point Aggregates" |
| 3032 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3033 | ClangASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, |
| 3034 | CompilerType *base_type_ptr) { |
| 3035 | if (!type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3036 | return 0; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3037 | |
| 3038 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3039 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3040 | switch (type_class) { |
| 3041 | case clang::Type::Record: |
| 3042 | if (GetCompleteType(type)) { |
| 3043 | const clang::CXXRecordDecl *cxx_record_decl = |
| 3044 | qual_type->getAsCXXRecordDecl(); |
| 3045 | if (cxx_record_decl) { |
| 3046 | if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass()) |
| 3047 | return 0; |
| 3048 | } |
| 3049 | const clang::RecordType *record_type = |
| 3050 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3051 | if (record_type) { |
| 3052 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3053 | if (record_decl) { |
| 3054 | // We are looking for a structure that contains only floating point |
| 3055 | // types |
| 3056 | clang::RecordDecl::field_iterator field_pos, |
| 3057 | field_end = record_decl->field_end(); |
| 3058 | uint32_t num_fields = 0; |
| 3059 | bool is_hva = false; |
| 3060 | bool is_hfa = false; |
| 3061 | clang::QualType base_qual_type; |
| 3062 | uint64_t base_bitwidth = 0; |
| 3063 | for (field_pos = record_decl->field_begin(); field_pos != field_end; |
| 3064 | ++field_pos) { |
| 3065 | clang::QualType field_qual_type = field_pos->getType(); |
| 3066 | uint64_t field_bitwidth = getASTContext()->getTypeSize(qual_type); |
| 3067 | if (field_qual_type->isFloatingType()) { |
| 3068 | if (field_qual_type->isComplexType()) |
| 3069 | return 0; |
| 3070 | else { |
| 3071 | if (num_fields == 0) |
| 3072 | base_qual_type = field_qual_type; |
| 3073 | else { |
| 3074 | if (is_hva) |
| 3075 | return 0; |
| 3076 | is_hfa = true; |
| 3077 | if (field_qual_type.getTypePtr() != |
| 3078 | base_qual_type.getTypePtr()) |
| 3079 | return 0; |
| 3080 | } |
| 3081 | } |
| 3082 | } else if (field_qual_type->isVectorType() || |
| 3083 | field_qual_type->isExtVectorType()) { |
| 3084 | if (num_fields == 0) { |
| 3085 | base_qual_type = field_qual_type; |
| 3086 | base_bitwidth = field_bitwidth; |
| 3087 | } else { |
| 3088 | if (is_hfa) |
| 3089 | return 0; |
| 3090 | is_hva = true; |
| 3091 | if (base_bitwidth != field_bitwidth) |
| 3092 | return 0; |
| 3093 | if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr()) |
| 3094 | return 0; |
| 3095 | } |
| 3096 | } else |
| 3097 | return 0; |
| 3098 | ++num_fields; |
| 3099 | } |
| 3100 | if (base_type_ptr) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3101 | *base_type_ptr = CompilerType(this, base_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3102 | return num_fields; |
| 3103 | } |
| 3104 | } |
| 3105 | } |
| 3106 | break; |
| 3107 | |
| 3108 | case clang::Type::Typedef: |
| 3109 | return IsHomogeneousAggregate(llvm::cast<clang::TypedefType>(qual_type) |
| 3110 | ->getDecl() |
| 3111 | ->getUnderlyingType() |
| 3112 | .getAsOpaquePtr(), |
| 3113 | base_type_ptr); |
| 3114 | |
| 3115 | case clang::Type::Auto: |
| 3116 | return IsHomogeneousAggregate(llvm::cast<clang::AutoType>(qual_type) |
| 3117 | ->getDeducedType() |
| 3118 | .getAsOpaquePtr(), |
| 3119 | base_type_ptr); |
| 3120 | |
| 3121 | case clang::Type::Elaborated: |
| 3122 | return IsHomogeneousAggregate(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3123 | ->getNamedType() |
| 3124 | .getAsOpaquePtr(), |
| 3125 | base_type_ptr); |
| 3126 | default: |
| 3127 | break; |
| 3128 | } |
| 3129 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3132 | size_t ClangASTContext::GetNumberOfFunctionArguments( |
| 3133 | lldb::opaque_compiler_type_t type) { |
| 3134 | if (type) { |
| 3135 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3136 | const clang::FunctionProtoType *func = |
| 3137 | llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 3138 | if (func) |
| 3139 | return func->getNumParams(); |
| 3140 | } |
| 3141 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3142 | } |
| 3143 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3144 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3145 | ClangASTContext::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, |
| 3146 | const size_t index) { |
| 3147 | if (type) { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3148 | clang::QualType qual_type(GetQualType(type)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3149 | const clang::FunctionProtoType *func = |
| 3150 | llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 3151 | if (func) { |
| 3152 | if (index < func->getNumParams()) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3153 | return CompilerType(this, func->getParamType(index).getAsOpaquePtr()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3154 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3155 | } |
| 3156 | return CompilerType(); |
| 3157 | } |
| 3158 | |
| 3159 | bool ClangASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type) { |
| 3160 | if (type) { |
| 3161 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3162 | |
| 3163 | if (qual_type->isFunctionPointerType()) |
| 3164 | return true; |
| 3165 | |
| 3166 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3167 | switch (type_class) { |
| 3168 | default: |
| 3169 | break; |
| 3170 | case clang::Type::Typedef: |
| 3171 | return IsFunctionPointerType(llvm::cast<clang::TypedefType>(qual_type) |
| 3172 | ->getDecl() |
| 3173 | ->getUnderlyingType() |
| 3174 | .getAsOpaquePtr()); |
| 3175 | case clang::Type::Auto: |
| 3176 | return IsFunctionPointerType(llvm::cast<clang::AutoType>(qual_type) |
| 3177 | ->getDeducedType() |
| 3178 | .getAsOpaquePtr()); |
| 3179 | case clang::Type::Elaborated: |
| 3180 | return IsFunctionPointerType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3181 | ->getNamedType() |
| 3182 | .getAsOpaquePtr()); |
| 3183 | case clang::Type::Paren: |
| 3184 | return IsFunctionPointerType( |
| 3185 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 3186 | |
| 3187 | case clang::Type::LValueReference: |
| 3188 | case clang::Type::RValueReference: { |
| 3189 | const clang::ReferenceType *reference_type = |
| 3190 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 3191 | if (reference_type) |
| 3192 | return IsFunctionPointerType( |
| 3193 | reference_type->getPointeeType().getAsOpaquePtr()); |
| 3194 | } break; |
| 3195 | } |
| 3196 | } |
| 3197 | return false; |
| 3198 | } |
| 3199 | |
| 3200 | bool ClangASTContext::IsBlockPointerType( |
| 3201 | lldb::opaque_compiler_type_t type, |
| 3202 | CompilerType *function_pointer_type_ptr) { |
| 3203 | if (type) { |
| 3204 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3205 | |
| 3206 | if (qual_type->isBlockPointerType()) { |
| 3207 | if (function_pointer_type_ptr) { |
| 3208 | const clang::BlockPointerType *block_pointer_type = |
| 3209 | qual_type->getAs<clang::BlockPointerType>(); |
| 3210 | QualType pointee_type = block_pointer_type->getPointeeType(); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 3211 | QualType function_pointer_type = m_ast_up->getPointerType(pointee_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3212 | *function_pointer_type_ptr = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3213 | CompilerType(this, function_pointer_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3214 | } |
| 3215 | return true; |
| 3216 | } |
| 3217 | |
| 3218 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3219 | switch (type_class) { |
| 3220 | default: |
| 3221 | break; |
| 3222 | case clang::Type::Typedef: |
| 3223 | return IsBlockPointerType(llvm::cast<clang::TypedefType>(qual_type) |
| 3224 | ->getDecl() |
| 3225 | ->getUnderlyingType() |
| 3226 | .getAsOpaquePtr(), |
| 3227 | function_pointer_type_ptr); |
| 3228 | case clang::Type::Auto: |
| 3229 | return IsBlockPointerType(llvm::cast<clang::AutoType>(qual_type) |
| 3230 | ->getDeducedType() |
| 3231 | .getAsOpaquePtr(), |
| 3232 | function_pointer_type_ptr); |
| 3233 | case clang::Type::Elaborated: |
| 3234 | return IsBlockPointerType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3235 | ->getNamedType() |
| 3236 | .getAsOpaquePtr(), |
| 3237 | function_pointer_type_ptr); |
| 3238 | case clang::Type::Paren: |
| 3239 | return IsBlockPointerType( |
| 3240 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3241 | function_pointer_type_ptr); |
| 3242 | |
| 3243 | case clang::Type::LValueReference: |
| 3244 | case clang::Type::RValueReference: { |
| 3245 | const clang::ReferenceType *reference_type = |
| 3246 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 3247 | if (reference_type) |
| 3248 | return IsBlockPointerType( |
| 3249 | reference_type->getPointeeType().getAsOpaquePtr(), |
| 3250 | function_pointer_type_ptr); |
| 3251 | } break; |
| 3252 | } |
| 3253 | } |
| 3254 | return false; |
| 3255 | } |
| 3256 | |
| 3257 | bool ClangASTContext::IsIntegerType(lldb::opaque_compiler_type_t type, |
| 3258 | bool &is_signed) { |
| 3259 | if (!type) |
| 3260 | return false; |
| 3261 | |
| 3262 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3263 | const clang::BuiltinType *builtin_type = |
| 3264 | llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()); |
| 3265 | |
| 3266 | if (builtin_type) { |
| 3267 | if (builtin_type->isInteger()) { |
| 3268 | is_signed = builtin_type->isSignedInteger(); |
| 3269 | return true; |
| 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | return false; |
| 3274 | } |
| 3275 | |
| 3276 | bool ClangASTContext::IsEnumerationType(lldb::opaque_compiler_type_t type, |
| 3277 | bool &is_signed) { |
| 3278 | if (type) { |
| 3279 | const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>( |
| 3280 | GetCanonicalQualType(type)->getCanonicalTypeInternal()); |
| 3281 | |
| 3282 | if (enum_type) { |
| 3283 | IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(), |
| 3284 | is_signed); |
| 3285 | return true; |
| 3286 | } |
| 3287 | } |
| 3288 | |
| 3289 | return false; |
| 3290 | } |
| 3291 | |
| 3292 | bool ClangASTContext::IsPointerType(lldb::opaque_compiler_type_t type, |
| 3293 | CompilerType *pointee_type) { |
| 3294 | if (type) { |
| 3295 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3296 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3297 | switch (type_class) { |
| 3298 | case clang::Type::Builtin: |
| 3299 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 3300 | default: |
| 3301 | break; |
| 3302 | case clang::BuiltinType::ObjCId: |
| 3303 | case clang::BuiltinType::ObjCClass: |
| 3304 | return true; |
| 3305 | } |
| 3306 | return false; |
| 3307 | case clang::Type::ObjCObjectPointer: |
| 3308 | if (pointee_type) |
| 3309 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3310 | this, llvm::cast<clang::ObjCObjectPointerType>(qual_type) |
| 3311 | ->getPointeeType() |
| 3312 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3313 | return true; |
| 3314 | case clang::Type::BlockPointer: |
| 3315 | if (pointee_type) |
| 3316 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3317 | this, llvm::cast<clang::BlockPointerType>(qual_type) |
| 3318 | ->getPointeeType() |
| 3319 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3320 | return true; |
| 3321 | case clang::Type::Pointer: |
| 3322 | if (pointee_type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3323 | pointee_type->SetCompilerType(this, |
| 3324 | llvm::cast<clang::PointerType>(qual_type) |
| 3325 | ->getPointeeType() |
| 3326 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3327 | return true; |
| 3328 | case clang::Type::MemberPointer: |
| 3329 | if (pointee_type) |
| 3330 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3331 | this, llvm::cast<clang::MemberPointerType>(qual_type) |
| 3332 | ->getPointeeType() |
| 3333 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3334 | return true; |
| 3335 | case clang::Type::Typedef: |
| 3336 | return IsPointerType(llvm::cast<clang::TypedefType>(qual_type) |
| 3337 | ->getDecl() |
| 3338 | ->getUnderlyingType() |
| 3339 | .getAsOpaquePtr(), |
| 3340 | pointee_type); |
| 3341 | case clang::Type::Auto: |
| 3342 | return IsPointerType(llvm::cast<clang::AutoType>(qual_type) |
| 3343 | ->getDeducedType() |
| 3344 | .getAsOpaquePtr(), |
| 3345 | pointee_type); |
| 3346 | case clang::Type::Elaborated: |
| 3347 | return IsPointerType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3348 | ->getNamedType() |
| 3349 | .getAsOpaquePtr(), |
| 3350 | pointee_type); |
| 3351 | case clang::Type::Paren: |
| 3352 | return IsPointerType( |
| 3353 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3354 | pointee_type); |
| 3355 | default: |
| 3356 | break; |
| 3357 | } |
| 3358 | } |
| 3359 | if (pointee_type) |
| 3360 | pointee_type->Clear(); |
| 3361 | return false; |
| 3362 | } |
| 3363 | |
| 3364 | bool ClangASTContext::IsPointerOrReferenceType( |
| 3365 | lldb::opaque_compiler_type_t type, CompilerType *pointee_type) { |
| 3366 | if (type) { |
| 3367 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3368 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3369 | switch (type_class) { |
| 3370 | case clang::Type::Builtin: |
| 3371 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 3372 | default: |
| 3373 | break; |
| 3374 | case clang::BuiltinType::ObjCId: |
| 3375 | case clang::BuiltinType::ObjCClass: |
| 3376 | return true; |
| 3377 | } |
| 3378 | return false; |
| 3379 | case clang::Type::ObjCObjectPointer: |
| 3380 | if (pointee_type) |
| 3381 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3382 | this, llvm::cast<clang::ObjCObjectPointerType>(qual_type) |
| 3383 | ->getPointeeType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3384 | return true; |
| 3385 | case clang::Type::BlockPointer: |
| 3386 | if (pointee_type) |
| 3387 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3388 | this, llvm::cast<clang::BlockPointerType>(qual_type) |
| 3389 | ->getPointeeType() |
| 3390 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3391 | return true; |
| 3392 | case clang::Type::Pointer: |
| 3393 | if (pointee_type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3394 | pointee_type->SetCompilerType(this, |
| 3395 | llvm::cast<clang::PointerType>(qual_type) |
| 3396 | ->getPointeeType() |
| 3397 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3398 | return true; |
| 3399 | case clang::Type::MemberPointer: |
| 3400 | if (pointee_type) |
| 3401 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3402 | this, llvm::cast<clang::MemberPointerType>(qual_type) |
| 3403 | ->getPointeeType() |
| 3404 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3405 | return true; |
| 3406 | case clang::Type::LValueReference: |
| 3407 | if (pointee_type) |
| 3408 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3409 | this, llvm::cast<clang::LValueReferenceType>(qual_type) |
| 3410 | ->desugar() |
| 3411 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3412 | return true; |
| 3413 | case clang::Type::RValueReference: |
| 3414 | if (pointee_type) |
| 3415 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3416 | this, llvm::cast<clang::RValueReferenceType>(qual_type) |
| 3417 | ->desugar() |
| 3418 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3419 | return true; |
| 3420 | case clang::Type::Typedef: |
| 3421 | return IsPointerOrReferenceType(llvm::cast<clang::TypedefType>(qual_type) |
| 3422 | ->getDecl() |
| 3423 | ->getUnderlyingType() |
| 3424 | .getAsOpaquePtr(), |
| 3425 | pointee_type); |
| 3426 | case clang::Type::Auto: |
| 3427 | return IsPointerOrReferenceType(llvm::cast<clang::AutoType>(qual_type) |
| 3428 | ->getDeducedType() |
| 3429 | .getAsOpaquePtr(), |
| 3430 | pointee_type); |
| 3431 | case clang::Type::Elaborated: |
| 3432 | return IsPointerOrReferenceType( |
| 3433 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 3434 | ->getNamedType() |
| 3435 | .getAsOpaquePtr(), |
| 3436 | pointee_type); |
| 3437 | case clang::Type::Paren: |
| 3438 | return IsPointerOrReferenceType( |
| 3439 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3440 | pointee_type); |
| 3441 | default: |
| 3442 | break; |
| 3443 | } |
| 3444 | } |
| 3445 | if (pointee_type) |
| 3446 | pointee_type->Clear(); |
| 3447 | return false; |
| 3448 | } |
| 3449 | |
| 3450 | bool ClangASTContext::IsReferenceType(lldb::opaque_compiler_type_t type, |
| 3451 | CompilerType *pointee_type, |
| 3452 | bool *is_rvalue) { |
| 3453 | if (type) { |
| 3454 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3455 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3456 | |
| 3457 | switch (type_class) { |
| 3458 | case clang::Type::LValueReference: |
| 3459 | if (pointee_type) |
| 3460 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3461 | this, llvm::cast<clang::LValueReferenceType>(qual_type) |
| 3462 | ->desugar() |
| 3463 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3464 | if (is_rvalue) |
| 3465 | *is_rvalue = false; |
| 3466 | return true; |
| 3467 | case clang::Type::RValueReference: |
| 3468 | if (pointee_type) |
| 3469 | pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3470 | this, llvm::cast<clang::RValueReferenceType>(qual_type) |
| 3471 | ->desugar() |
| 3472 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3473 | if (is_rvalue) |
| 3474 | *is_rvalue = true; |
| 3475 | return true; |
| 3476 | case clang::Type::Typedef: |
| 3477 | return IsReferenceType(llvm::cast<clang::TypedefType>(qual_type) |
| 3478 | ->getDecl() |
| 3479 | ->getUnderlyingType() |
| 3480 | .getAsOpaquePtr(), |
| 3481 | pointee_type, is_rvalue); |
| 3482 | case clang::Type::Auto: |
| 3483 | return IsReferenceType(llvm::cast<clang::AutoType>(qual_type) |
| 3484 | ->getDeducedType() |
| 3485 | .getAsOpaquePtr(), |
| 3486 | pointee_type, is_rvalue); |
| 3487 | case clang::Type::Elaborated: |
| 3488 | return IsReferenceType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3489 | ->getNamedType() |
| 3490 | .getAsOpaquePtr(), |
| 3491 | pointee_type, is_rvalue); |
| 3492 | case clang::Type::Paren: |
| 3493 | return IsReferenceType( |
| 3494 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3495 | pointee_type, is_rvalue); |
| 3496 | |
| 3497 | default: |
| 3498 | break; |
| 3499 | } |
| 3500 | } |
| 3501 | if (pointee_type) |
| 3502 | pointee_type->Clear(); |
| 3503 | return false; |
| 3504 | } |
| 3505 | |
| 3506 | bool ClangASTContext::IsFloatingPointType(lldb::opaque_compiler_type_t type, |
| 3507 | uint32_t &count, bool &is_complex) { |
| 3508 | if (type) { |
| 3509 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3510 | |
| 3511 | if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>( |
| 3512 | qual_type->getCanonicalTypeInternal())) { |
| 3513 | clang::BuiltinType::Kind kind = BT->getKind(); |
| 3514 | if (kind >= clang::BuiltinType::Float && |
| 3515 | kind <= clang::BuiltinType::LongDouble) { |
| 3516 | count = 1; |
| 3517 | is_complex = false; |
| 3518 | return true; |
| 3519 | } |
| 3520 | } else if (const clang::ComplexType *CT = |
| 3521 | llvm::dyn_cast<clang::ComplexType>( |
| 3522 | qual_type->getCanonicalTypeInternal())) { |
| 3523 | if (IsFloatingPointType(CT->getElementType().getAsOpaquePtr(), count, |
| 3524 | is_complex)) { |
| 3525 | count = 2; |
| 3526 | is_complex = true; |
| 3527 | return true; |
| 3528 | } |
| 3529 | } else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>( |
| 3530 | qual_type->getCanonicalTypeInternal())) { |
| 3531 | if (IsFloatingPointType(VT->getElementType().getAsOpaquePtr(), count, |
| 3532 | is_complex)) { |
| 3533 | count = VT->getNumElements(); |
| 3534 | is_complex = false; |
| 3535 | return true; |
| 3536 | } |
| 3537 | } |
| 3538 | } |
| 3539 | count = 0; |
| 3540 | is_complex = false; |
| 3541 | return false; |
| 3542 | } |
| 3543 | |
| 3544 | bool ClangASTContext::IsDefined(lldb::opaque_compiler_type_t type) { |
| 3545 | if (!type) |
| 3546 | return false; |
| 3547 | |
| 3548 | clang::QualType qual_type(GetQualType(type)); |
| 3549 | const clang::TagType *tag_type = |
| 3550 | llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 3551 | if (tag_type) { |
| 3552 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 3553 | if (tag_decl) |
| 3554 | return tag_decl->isCompleteDefinition(); |
| 3555 | return false; |
| 3556 | } else { |
| 3557 | const clang::ObjCObjectType *objc_class_type = |
| 3558 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 3559 | if (objc_class_type) { |
| 3560 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 3561 | objc_class_type->getInterface(); |
| 3562 | if (class_interface_decl) |
| 3563 | return class_interface_decl->getDefinition() != nullptr; |
| 3564 | return false; |
| 3565 | } |
| 3566 | } |
| 3567 | return true; |
| 3568 | } |
| 3569 | |
| 3570 | bool ClangASTContext::IsObjCClassType(const CompilerType &type) { |
Raphael Isemann | 79b3cce | 2019-11-08 12:03:28 +0100 | [diff] [blame] | 3571 | if (ClangUtil::IsClangType(type)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3572 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
| 3573 | |
| 3574 | const clang::ObjCObjectPointerType *obj_pointer_type = |
| 3575 | llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); |
| 3576 | |
| 3577 | if (obj_pointer_type) |
| 3578 | return obj_pointer_type->isObjCClassType(); |
| 3579 | } |
| 3580 | return false; |
| 3581 | } |
| 3582 | |
| 3583 | bool ClangASTContext::IsObjCObjectOrInterfaceType(const CompilerType &type) { |
| 3584 | if (ClangUtil::IsClangType(type)) |
| 3585 | return ClangUtil::GetCanonicalQualType(type)->isObjCObjectOrInterfaceType(); |
| 3586 | return false; |
| 3587 | } |
| 3588 | |
| 3589 | bool ClangASTContext::IsClassType(lldb::opaque_compiler_type_t type) { |
| 3590 | if (!type) |
| 3591 | return false; |
| 3592 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3593 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3594 | return (type_class == clang::Type::Record); |
| 3595 | } |
| 3596 | |
| 3597 | bool ClangASTContext::IsEnumType(lldb::opaque_compiler_type_t type) { |
| 3598 | if (!type) |
| 3599 | return false; |
| 3600 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3601 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3602 | return (type_class == clang::Type::Enum); |
| 3603 | } |
| 3604 | |
| 3605 | bool ClangASTContext::IsPolymorphicClass(lldb::opaque_compiler_type_t type) { |
| 3606 | if (type) { |
| 3607 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3608 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3609 | switch (type_class) { |
| 3610 | case clang::Type::Record: |
| 3611 | if (GetCompleteType(type)) { |
| 3612 | const clang::RecordType *record_type = |
| 3613 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3614 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3615 | if (record_decl) { |
| 3616 | const clang::CXXRecordDecl *cxx_record_decl = |
| 3617 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 3618 | if (cxx_record_decl) |
| 3619 | return cxx_record_decl->isPolymorphic(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3620 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3621 | } |
| 3622 | break; |
| 3623 | |
| 3624 | default: |
| 3625 | break; |
| 3626 | } |
| 3627 | } |
| 3628 | return false; |
| 3629 | } |
| 3630 | |
| 3631 | bool ClangASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type, |
| 3632 | CompilerType *dynamic_pointee_type, |
| 3633 | bool check_cplusplus, |
| 3634 | bool check_objc) { |
| 3635 | clang::QualType pointee_qual_type; |
| 3636 | if (type) { |
| 3637 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3638 | bool success = false; |
| 3639 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3640 | switch (type_class) { |
| 3641 | case clang::Type::Builtin: |
| 3642 | if (check_objc && |
| 3643 | llvm::cast<clang::BuiltinType>(qual_type)->getKind() == |
| 3644 | clang::BuiltinType::ObjCId) { |
| 3645 | if (dynamic_pointee_type) |
| 3646 | dynamic_pointee_type->SetCompilerType(this, type); |
| 3647 | return true; |
| 3648 | } |
| 3649 | break; |
| 3650 | |
| 3651 | case clang::Type::ObjCObjectPointer: |
| 3652 | if (check_objc) { |
| 3653 | if (auto objc_pointee_type = |
| 3654 | qual_type->getPointeeType().getTypePtrOrNull()) { |
| 3655 | if (auto objc_object_type = |
| 3656 | llvm::dyn_cast_or_null<clang::ObjCObjectType>( |
| 3657 | objc_pointee_type)) { |
| 3658 | if (objc_object_type->isObjCClass()) |
| 3659 | return false; |
| 3660 | } |
| 3661 | } |
| 3662 | if (dynamic_pointee_type) |
| 3663 | dynamic_pointee_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3664 | this, llvm::cast<clang::ObjCObjectPointerType>(qual_type) |
| 3665 | ->getPointeeType() |
| 3666 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3667 | return true; |
| 3668 | } |
| 3669 | break; |
| 3670 | |
| 3671 | case clang::Type::Pointer: |
| 3672 | pointee_qual_type = |
| 3673 | llvm::cast<clang::PointerType>(qual_type)->getPointeeType(); |
| 3674 | success = true; |
| 3675 | break; |
| 3676 | |
| 3677 | case clang::Type::LValueReference: |
| 3678 | case clang::Type::RValueReference: |
| 3679 | pointee_qual_type = |
| 3680 | llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType(); |
| 3681 | success = true; |
| 3682 | break; |
| 3683 | |
| 3684 | case clang::Type::Typedef: |
| 3685 | return IsPossibleDynamicType(llvm::cast<clang::TypedefType>(qual_type) |
| 3686 | ->getDecl() |
| 3687 | ->getUnderlyingType() |
| 3688 | .getAsOpaquePtr(), |
| 3689 | dynamic_pointee_type, check_cplusplus, |
| 3690 | check_objc); |
| 3691 | |
| 3692 | case clang::Type::Auto: |
| 3693 | return IsPossibleDynamicType(llvm::cast<clang::AutoType>(qual_type) |
| 3694 | ->getDeducedType() |
| 3695 | .getAsOpaquePtr(), |
| 3696 | dynamic_pointee_type, check_cplusplus, |
| 3697 | check_objc); |
| 3698 | |
| 3699 | case clang::Type::Elaborated: |
| 3700 | return IsPossibleDynamicType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3701 | ->getNamedType() |
| 3702 | .getAsOpaquePtr(), |
| 3703 | dynamic_pointee_type, check_cplusplus, |
| 3704 | check_objc); |
| 3705 | |
| 3706 | case clang::Type::Paren: |
| 3707 | return IsPossibleDynamicType( |
| 3708 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3709 | dynamic_pointee_type, check_cplusplus, check_objc); |
| 3710 | default: |
| 3711 | break; |
| 3712 | } |
| 3713 | |
| 3714 | if (success) { |
| 3715 | // Check to make sure what we are pointing too is a possible dynamic C++ |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3716 | // type We currently accept any "void *" (in case we have a class that |
| 3717 | // has been watered down to an opaque pointer) and virtual C++ classes. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3718 | const clang::Type::TypeClass pointee_type_class = |
| 3719 | pointee_qual_type.getCanonicalType()->getTypeClass(); |
| 3720 | switch (pointee_type_class) { |
| 3721 | case clang::Type::Builtin: |
| 3722 | switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) { |
| 3723 | case clang::BuiltinType::UnknownAny: |
| 3724 | case clang::BuiltinType::Void: |
| 3725 | if (dynamic_pointee_type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3726 | dynamic_pointee_type->SetCompilerType( |
| 3727 | this, pointee_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3728 | return true; |
| 3729 | default: |
| 3730 | break; |
| 3731 | } |
| 3732 | break; |
| 3733 | |
| 3734 | case clang::Type::Record: |
| 3735 | if (check_cplusplus) { |
| 3736 | clang::CXXRecordDecl *cxx_record_decl = |
| 3737 | pointee_qual_type->getAsCXXRecordDecl(); |
| 3738 | if (cxx_record_decl) { |
| 3739 | bool is_complete = cxx_record_decl->isCompleteDefinition(); |
| 3740 | |
| 3741 | if (is_complete) |
| 3742 | success = cxx_record_decl->isDynamicClass(); |
| 3743 | else { |
| 3744 | ClangASTMetadata *metadata = ClangASTContext::GetMetadata( |
| 3745 | getASTContext(), cxx_record_decl); |
| 3746 | if (metadata) |
| 3747 | success = metadata->GetIsDynamicCXXType(); |
| 3748 | else { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3749 | is_complete = |
| 3750 | CompilerType(this, pointee_qual_type.getAsOpaquePtr()) |
| 3751 | .GetCompleteType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3752 | if (is_complete) |
| 3753 | success = cxx_record_decl->isDynamicClass(); |
| 3754 | else |
| 3755 | success = false; |
| 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | if (success) { |
| 3760 | if (dynamic_pointee_type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3761 | dynamic_pointee_type->SetCompilerType( |
| 3762 | this, pointee_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3763 | return true; |
| 3764 | } |
| 3765 | } |
| 3766 | } |
| 3767 | break; |
| 3768 | |
| 3769 | case clang::Type::ObjCObject: |
| 3770 | case clang::Type::ObjCInterface: |
| 3771 | if (check_objc) { |
| 3772 | if (dynamic_pointee_type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3773 | dynamic_pointee_type->SetCompilerType( |
| 3774 | this, pointee_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3775 | return true; |
| 3776 | } |
| 3777 | break; |
| 3778 | |
| 3779 | default: |
| 3780 | break; |
| 3781 | } |
| 3782 | } |
| 3783 | } |
| 3784 | if (dynamic_pointee_type) |
| 3785 | dynamic_pointee_type->Clear(); |
| 3786 | return false; |
| 3787 | } |
| 3788 | |
| 3789 | bool ClangASTContext::IsScalarType(lldb::opaque_compiler_type_t type) { |
| 3790 | if (!type) |
| 3791 | return false; |
| 3792 | |
| 3793 | return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0; |
| 3794 | } |
| 3795 | |
| 3796 | bool ClangASTContext::IsTypedefType(lldb::opaque_compiler_type_t type) { |
| 3797 | if (!type) |
| 3798 | return false; |
| 3799 | return GetQualType(type)->getTypeClass() == clang::Type::Typedef; |
| 3800 | } |
| 3801 | |
| 3802 | bool ClangASTContext::IsVoidType(lldb::opaque_compiler_type_t type) { |
| 3803 | if (!type) |
| 3804 | return false; |
| 3805 | return GetCanonicalQualType(type)->isVoidType(); |
| 3806 | } |
| 3807 | |
Alex Langford | a03e2b2 | 2019-06-04 19:29:59 +0000 | [diff] [blame] | 3808 | bool ClangASTContext::CanPassInRegisters(const CompilerType &type) { |
| 3809 | if (auto *record_decl = |
| 3810 | ClangASTContext::GetAsRecordDecl(type)) { |
| 3811 | return record_decl->canPassInRegisters(); |
| 3812 | } |
| 3813 | return false; |
| 3814 | } |
| 3815 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3816 | bool ClangASTContext::SupportsLanguage(lldb::LanguageType language) { |
| 3817 | return ClangASTContextSupportsLanguage(language); |
| 3818 | } |
| 3819 | |
Alex Langford | db54245 | 2019-10-30 12:50:05 -0700 | [diff] [blame] | 3820 | Optional<std::string> |
| 3821 | ClangASTContext::GetCXXClassName(const CompilerType &type) { |
| 3822 | if (!type) |
| 3823 | return llvm::None; |
| 3824 | |
| 3825 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
| 3826 | if (qual_type.isNull()) |
| 3827 | return llvm::None; |
| 3828 | |
| 3829 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 3830 | if (!cxx_record_decl) |
| 3831 | return llvm::None; |
| 3832 | |
| 3833 | return std::string(cxx_record_decl->getIdentifier()->getNameStart()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | bool ClangASTContext::IsCXXClassType(const CompilerType &type) { |
| 3837 | if (!type) |
| 3838 | return false; |
| 3839 | |
| 3840 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 3841 | return !qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | bool ClangASTContext::IsBeingDefined(lldb::opaque_compiler_type_t type) { |
| 3845 | if (!type) |
| 3846 | return false; |
| 3847 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3848 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type); |
| 3849 | if (tag_type) |
| 3850 | return tag_type->isBeingDefined(); |
| 3851 | return false; |
| 3852 | } |
| 3853 | |
| 3854 | bool ClangASTContext::IsObjCObjectPointerType(const CompilerType &type, |
| 3855 | CompilerType *class_type_ptr) { |
Raphael Isemann | 79b3cce | 2019-11-08 12:03:28 +0100 | [diff] [blame] | 3856 | if (!ClangUtil::IsClangType(type)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3857 | return false; |
| 3858 | |
| 3859 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
| 3860 | |
| 3861 | if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) { |
| 3862 | if (class_type_ptr) { |
| 3863 | if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) { |
| 3864 | const clang::ObjCObjectPointerType *obj_pointer_type = |
| 3865 | llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); |
| 3866 | if (obj_pointer_type == nullptr) |
| 3867 | class_type_ptr->Clear(); |
| 3868 | else |
| 3869 | class_type_ptr->SetCompilerType( |
| 3870 | type.GetTypeSystem(), |
| 3871 | clang::QualType(obj_pointer_type->getInterfaceType(), 0) |
| 3872 | .getAsOpaquePtr()); |
| 3873 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3874 | } |
| 3875 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3876 | } |
| 3877 | if (class_type_ptr) |
| 3878 | class_type_ptr->Clear(); |
| 3879 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3882 | // Type Completion |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3883 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3884 | bool ClangASTContext::GetCompleteType(lldb::opaque_compiler_type_t type) { |
| 3885 | if (!type) |
| 3886 | return false; |
| 3887 | const bool allow_completion = true; |
| 3888 | return GetCompleteQualType(getASTContext(), GetQualType(type), |
| 3889 | allow_completion); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3890 | } |
| 3891 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3892 | ConstString ClangASTContext::GetTypeName(lldb::opaque_compiler_type_t type) { |
| 3893 | std::string type_name; |
| 3894 | if (type) { |
| 3895 | clang::PrintingPolicy printing_policy(getASTContext()->getPrintingPolicy()); |
| 3896 | clang::QualType qual_type(GetQualType(type)); |
| 3897 | printing_policy.SuppressTagKeyword = true; |
| 3898 | const clang::TypedefType *typedef_type = |
| 3899 | qual_type->getAs<clang::TypedefType>(); |
| 3900 | if (typedef_type) { |
| 3901 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 3902 | type_name = typedef_decl->getQualifiedNameAsString(); |
| 3903 | } else { |
| 3904 | type_name = qual_type.getAsString(printing_policy); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3905 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3906 | } |
| 3907 | return ConstString(type_name); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3911 | ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type, |
| 3912 | CompilerType *pointee_or_element_clang_type) { |
| 3913 | if (!type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3914 | return 0; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3915 | |
| 3916 | if (pointee_or_element_clang_type) |
| 3917 | pointee_or_element_clang_type->Clear(); |
| 3918 | |
| 3919 | clang::QualType qual_type(GetQualType(type)); |
| 3920 | |
| 3921 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3922 | switch (type_class) { |
Sean Callanan | ddf802a | 2017-06-02 01:24:18 +0000 | [diff] [blame] | 3923 | case clang::Type::Attributed: |
| 3924 | return GetTypeInfo( |
| 3925 | qual_type->getAs<clang::AttributedType>() |
| 3926 | ->getModifiedType().getAsOpaquePtr(), |
| 3927 | pointee_or_element_clang_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3928 | case clang::Type::Builtin: { |
| 3929 | const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>( |
| 3930 | qual_type->getCanonicalTypeInternal()); |
| 3931 | |
| 3932 | uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue; |
| 3933 | switch (builtin_type->getKind()) { |
| 3934 | case clang::BuiltinType::ObjCId: |
| 3935 | case clang::BuiltinType::ObjCClass: |
| 3936 | if (pointee_or_element_clang_type) |
| 3937 | pointee_or_element_clang_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3938 | this, getASTContext()->ObjCBuiltinClassTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3939 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; |
| 3940 | break; |
| 3941 | |
| 3942 | case clang::BuiltinType::ObjCSel: |
| 3943 | if (pointee_or_element_clang_type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3944 | pointee_or_element_clang_type->SetCompilerType( |
| 3945 | this, getASTContext()->CharTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3946 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; |
| 3947 | break; |
| 3948 | |
| 3949 | case clang::BuiltinType::Bool: |
| 3950 | case clang::BuiltinType::Char_U: |
| 3951 | case clang::BuiltinType::UChar: |
| 3952 | case clang::BuiltinType::WChar_U: |
| 3953 | case clang::BuiltinType::Char16: |
| 3954 | case clang::BuiltinType::Char32: |
| 3955 | case clang::BuiltinType::UShort: |
| 3956 | case clang::BuiltinType::UInt: |
| 3957 | case clang::BuiltinType::ULong: |
| 3958 | case clang::BuiltinType::ULongLong: |
| 3959 | case clang::BuiltinType::UInt128: |
| 3960 | case clang::BuiltinType::Char_S: |
| 3961 | case clang::BuiltinType::SChar: |
| 3962 | case clang::BuiltinType::WChar_S: |
| 3963 | case clang::BuiltinType::Short: |
| 3964 | case clang::BuiltinType::Int: |
| 3965 | case clang::BuiltinType::Long: |
| 3966 | case clang::BuiltinType::LongLong: |
| 3967 | case clang::BuiltinType::Int128: |
| 3968 | case clang::BuiltinType::Float: |
| 3969 | case clang::BuiltinType::Double: |
| 3970 | case clang::BuiltinType::LongDouble: |
| 3971 | builtin_type_flags |= eTypeIsScalar; |
| 3972 | if (builtin_type->isInteger()) { |
| 3973 | builtin_type_flags |= eTypeIsInteger; |
| 3974 | if (builtin_type->isSignedInteger()) |
| 3975 | builtin_type_flags |= eTypeIsSigned; |
| 3976 | } else if (builtin_type->isFloatingPoint()) |
| 3977 | builtin_type_flags |= eTypeIsFloat; |
| 3978 | break; |
| 3979 | default: |
| 3980 | break; |
| 3981 | } |
| 3982 | return builtin_type_flags; |
| 3983 | } |
| 3984 | |
| 3985 | case clang::Type::BlockPointer: |
| 3986 | if (pointee_or_element_clang_type) |
| 3987 | pointee_or_element_clang_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 3988 | this, qual_type->getPointeeType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3989 | return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock; |
| 3990 | |
| 3991 | case clang::Type::Complex: { |
| 3992 | uint32_t complex_type_flags = |
| 3993 | eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex; |
| 3994 | const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>( |
| 3995 | qual_type->getCanonicalTypeInternal()); |
| 3996 | if (complex_type) { |
| 3997 | clang::QualType complex_element_type(complex_type->getElementType()); |
| 3998 | if (complex_element_type->isIntegerType()) |
| 3999 | complex_type_flags |= eTypeIsFloat; |
| 4000 | else if (complex_element_type->isFloatingType()) |
| 4001 | complex_type_flags |= eTypeIsInteger; |
| 4002 | } |
| 4003 | return complex_type_flags; |
| 4004 | } break; |
| 4005 | |
| 4006 | case clang::Type::ConstantArray: |
| 4007 | case clang::Type::DependentSizedArray: |
| 4008 | case clang::Type::IncompleteArray: |
| 4009 | case clang::Type::VariableArray: |
| 4010 | if (pointee_or_element_clang_type) |
| 4011 | pointee_or_element_clang_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4012 | this, llvm::cast<clang::ArrayType>(qual_type.getTypePtr()) |
| 4013 | ->getElementType() |
| 4014 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4015 | return eTypeHasChildren | eTypeIsArray; |
| 4016 | |
| 4017 | case clang::Type::DependentName: |
| 4018 | return 0; |
| 4019 | case clang::Type::DependentSizedExtVector: |
| 4020 | return eTypeHasChildren | eTypeIsVector; |
| 4021 | case clang::Type::DependentTemplateSpecialization: |
| 4022 | return eTypeIsTemplate; |
| 4023 | case clang::Type::Decltype: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4024 | return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type) |
| 4025 | ->getUnderlyingType() |
| 4026 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4027 | .GetTypeInfo(pointee_or_element_clang_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4028 | |
| 4029 | case clang::Type::Enum: |
| 4030 | if (pointee_or_element_clang_type) |
| 4031 | pointee_or_element_clang_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4032 | this, llvm::cast<clang::EnumType>(qual_type) |
| 4033 | ->getDecl() |
| 4034 | ->getIntegerType() |
| 4035 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4036 | return eTypeIsEnumeration | eTypeHasValue; |
| 4037 | |
| 4038 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4039 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 4040 | ->getDeducedType() |
| 4041 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4042 | .GetTypeInfo(pointee_or_element_clang_type); |
| 4043 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4044 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 4045 | ->getNamedType() |
| 4046 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4047 | .GetTypeInfo(pointee_or_element_clang_type); |
| 4048 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4049 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 4050 | ->desugar() |
| 4051 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4052 | .GetTypeInfo(pointee_or_element_clang_type); |
| 4053 | |
| 4054 | case clang::Type::FunctionProto: |
| 4055 | return eTypeIsFuncPrototype | eTypeHasValue; |
| 4056 | case clang::Type::FunctionNoProto: |
| 4057 | return eTypeIsFuncPrototype | eTypeHasValue; |
| 4058 | case clang::Type::InjectedClassName: |
| 4059 | return 0; |
| 4060 | |
| 4061 | case clang::Type::LValueReference: |
| 4062 | case clang::Type::RValueReference: |
| 4063 | if (pointee_or_element_clang_type) |
| 4064 | pointee_or_element_clang_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4065 | this, llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()) |
| 4066 | ->getPointeeType() |
| 4067 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4068 | return eTypeHasChildren | eTypeIsReference | eTypeHasValue; |
| 4069 | |
| 4070 | case clang::Type::MemberPointer: |
| 4071 | return eTypeIsPointer | eTypeIsMember | eTypeHasValue; |
| 4072 | |
| 4073 | case clang::Type::ObjCObjectPointer: |
| 4074 | if (pointee_or_element_clang_type) |
| 4075 | pointee_or_element_clang_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4076 | this, qual_type->getPointeeType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4077 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | |
| 4078 | eTypeHasValue; |
| 4079 | |
| 4080 | case clang::Type::ObjCObject: |
| 4081 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 4082 | case clang::Type::ObjCInterface: |
| 4083 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 4084 | |
| 4085 | case clang::Type::Pointer: |
| 4086 | if (pointee_or_element_clang_type) |
| 4087 | pointee_or_element_clang_type->SetCompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4088 | this, qual_type->getPointeeType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4089 | return eTypeHasChildren | eTypeIsPointer | eTypeHasValue; |
| 4090 | |
| 4091 | case clang::Type::Record: |
| 4092 | if (qual_type->getAsCXXRecordDecl()) |
| 4093 | return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus; |
| 4094 | else |
| 4095 | return eTypeHasChildren | eTypeIsStructUnion; |
| 4096 | break; |
| 4097 | case clang::Type::SubstTemplateTypeParm: |
| 4098 | return eTypeIsTemplate; |
| 4099 | case clang::Type::TemplateTypeParm: |
| 4100 | return eTypeIsTemplate; |
| 4101 | case clang::Type::TemplateSpecialization: |
| 4102 | return eTypeIsTemplate; |
| 4103 | |
| 4104 | case clang::Type::Typedef: |
| 4105 | return eTypeIsTypedef | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4106 | CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 4107 | ->getDecl() |
| 4108 | ->getUnderlyingType() |
| 4109 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4110 | .GetTypeInfo(pointee_or_element_clang_type); |
| 4111 | case clang::Type::TypeOfExpr: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4112 | return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type) |
| 4113 | ->getUnderlyingExpr() |
| 4114 | ->getType() |
| 4115 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4116 | .GetTypeInfo(pointee_or_element_clang_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4117 | case clang::Type::TypeOf: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4118 | return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type) |
| 4119 | ->getUnderlyingType() |
| 4120 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4121 | .GetTypeInfo(pointee_or_element_clang_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4122 | case clang::Type::UnresolvedUsing: |
| 4123 | return 0; |
| 4124 | |
| 4125 | case clang::Type::ExtVector: |
| 4126 | case clang::Type::Vector: { |
| 4127 | uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector; |
| 4128 | const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>( |
| 4129 | qual_type->getCanonicalTypeInternal()); |
| 4130 | if (vector_type) { |
| 4131 | if (vector_type->isIntegerType()) |
| 4132 | vector_type_flags |= eTypeIsFloat; |
| 4133 | else if (vector_type->isFloatingType()) |
| 4134 | vector_type_flags |= eTypeIsInteger; |
| 4135 | } |
| 4136 | return vector_type_flags; |
| 4137 | } |
| 4138 | default: |
| 4139 | return 0; |
| 4140 | } |
| 4141 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4142 | } |
| 4143 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4144 | lldb::LanguageType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4145 | ClangASTContext::GetMinimumLanguage(lldb::opaque_compiler_type_t type) { |
| 4146 | if (!type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4147 | return lldb::eLanguageTypeC; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4148 | |
| 4149 | // If the type is a reference, then resolve it to what it refers to first: |
| 4150 | clang::QualType qual_type(GetCanonicalQualType(type).getNonReferenceType()); |
| 4151 | if (qual_type->isAnyPointerType()) { |
| 4152 | if (qual_type->isObjCObjectPointerType()) |
| 4153 | return lldb::eLanguageTypeObjC; |
Adrian Prantl | 1db0f0c | 2019-05-02 23:07:23 +0000 | [diff] [blame] | 4154 | if (qual_type->getPointeeCXXRecordDecl()) |
| 4155 | return lldb::eLanguageTypeC_plus_plus; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4156 | |
| 4157 | clang::QualType pointee_type(qual_type->getPointeeType()); |
Adrian Prantl | 1db0f0c | 2019-05-02 23:07:23 +0000 | [diff] [blame] | 4158 | if (pointee_type->getPointeeCXXRecordDecl()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4159 | return lldb::eLanguageTypeC_plus_plus; |
| 4160 | if (pointee_type->isObjCObjectOrInterfaceType()) |
| 4161 | return lldb::eLanguageTypeObjC; |
| 4162 | if (pointee_type->isObjCClassType()) |
| 4163 | return lldb::eLanguageTypeObjC; |
| 4164 | if (pointee_type.getTypePtr() == |
| 4165 | getASTContext()->ObjCBuiltinIdTy.getTypePtr()) |
| 4166 | return lldb::eLanguageTypeObjC; |
| 4167 | } else { |
| 4168 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 4169 | return lldb::eLanguageTypeObjC; |
| 4170 | if (qual_type->getAsCXXRecordDecl()) |
| 4171 | return lldb::eLanguageTypeC_plus_plus; |
| 4172 | switch (qual_type->getTypeClass()) { |
| 4173 | default: |
| 4174 | break; |
| 4175 | case clang::Type::Builtin: |
| 4176 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 4177 | default: |
| 4178 | case clang::BuiltinType::Void: |
| 4179 | case clang::BuiltinType::Bool: |
| 4180 | case clang::BuiltinType::Char_U: |
| 4181 | case clang::BuiltinType::UChar: |
| 4182 | case clang::BuiltinType::WChar_U: |
| 4183 | case clang::BuiltinType::Char16: |
| 4184 | case clang::BuiltinType::Char32: |
| 4185 | case clang::BuiltinType::UShort: |
| 4186 | case clang::BuiltinType::UInt: |
| 4187 | case clang::BuiltinType::ULong: |
| 4188 | case clang::BuiltinType::ULongLong: |
| 4189 | case clang::BuiltinType::UInt128: |
| 4190 | case clang::BuiltinType::Char_S: |
| 4191 | case clang::BuiltinType::SChar: |
| 4192 | case clang::BuiltinType::WChar_S: |
| 4193 | case clang::BuiltinType::Short: |
| 4194 | case clang::BuiltinType::Int: |
| 4195 | case clang::BuiltinType::Long: |
| 4196 | case clang::BuiltinType::LongLong: |
| 4197 | case clang::BuiltinType::Int128: |
| 4198 | case clang::BuiltinType::Float: |
| 4199 | case clang::BuiltinType::Double: |
| 4200 | case clang::BuiltinType::LongDouble: |
| 4201 | break; |
| 4202 | |
| 4203 | case clang::BuiltinType::NullPtr: |
| 4204 | return eLanguageTypeC_plus_plus; |
| 4205 | |
| 4206 | case clang::BuiltinType::ObjCId: |
| 4207 | case clang::BuiltinType::ObjCClass: |
| 4208 | case clang::BuiltinType::ObjCSel: |
| 4209 | return eLanguageTypeObjC; |
| 4210 | |
| 4211 | case clang::BuiltinType::Dependent: |
| 4212 | case clang::BuiltinType::Overload: |
| 4213 | case clang::BuiltinType::BoundMember: |
| 4214 | case clang::BuiltinType::UnknownAny: |
| 4215 | break; |
| 4216 | } |
| 4217 | break; |
| 4218 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4219 | return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 4220 | ->getDecl() |
| 4221 | ->getUnderlyingType() |
| 4222 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4223 | .GetMinimumLanguage(); |
| 4224 | } |
| 4225 | } |
| 4226 | return lldb::eLanguageTypeC; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | lldb::TypeClass |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4230 | ClangASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) { |
| 4231 | if (!type) |
| 4232 | return lldb::eTypeClassInvalid; |
| 4233 | |
| 4234 | clang::QualType qual_type(GetQualType(type)); |
| 4235 | |
| 4236 | switch (qual_type->getTypeClass()) { |
| 4237 | case clang::Type::UnaryTransform: |
| 4238 | break; |
| 4239 | case clang::Type::FunctionNoProto: |
| 4240 | return lldb::eTypeClassFunction; |
| 4241 | case clang::Type::FunctionProto: |
| 4242 | return lldb::eTypeClassFunction; |
| 4243 | case clang::Type::IncompleteArray: |
| 4244 | return lldb::eTypeClassArray; |
| 4245 | case clang::Type::VariableArray: |
| 4246 | return lldb::eTypeClassArray; |
| 4247 | case clang::Type::ConstantArray: |
| 4248 | return lldb::eTypeClassArray; |
| 4249 | case clang::Type::DependentSizedArray: |
| 4250 | return lldb::eTypeClassArray; |
| 4251 | case clang::Type::DependentSizedExtVector: |
| 4252 | return lldb::eTypeClassVector; |
Fangrui Song | 8f28488 | 2018-07-13 22:40:40 +0000 | [diff] [blame] | 4253 | case clang::Type::DependentVector: |
| 4254 | return lldb::eTypeClassVector; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4255 | case clang::Type::ExtVector: |
| 4256 | return lldb::eTypeClassVector; |
| 4257 | case clang::Type::Vector: |
| 4258 | return lldb::eTypeClassVector; |
| 4259 | case clang::Type::Builtin: |
| 4260 | return lldb::eTypeClassBuiltin; |
| 4261 | case clang::Type::ObjCObjectPointer: |
| 4262 | return lldb::eTypeClassObjCObjectPointer; |
| 4263 | case clang::Type::BlockPointer: |
| 4264 | return lldb::eTypeClassBlockPointer; |
| 4265 | case clang::Type::Pointer: |
| 4266 | return lldb::eTypeClassPointer; |
| 4267 | case clang::Type::LValueReference: |
| 4268 | return lldb::eTypeClassReference; |
| 4269 | case clang::Type::RValueReference: |
| 4270 | return lldb::eTypeClassReference; |
| 4271 | case clang::Type::MemberPointer: |
| 4272 | return lldb::eTypeClassMemberPointer; |
| 4273 | case clang::Type::Complex: |
| 4274 | if (qual_type->isComplexType()) |
| 4275 | return lldb::eTypeClassComplexFloat; |
| 4276 | else |
| 4277 | return lldb::eTypeClassComplexInteger; |
| 4278 | case clang::Type::ObjCObject: |
| 4279 | return lldb::eTypeClassObjCObject; |
| 4280 | case clang::Type::ObjCInterface: |
| 4281 | return lldb::eTypeClassObjCInterface; |
| 4282 | case clang::Type::Record: { |
| 4283 | const clang::RecordType *record_type = |
| 4284 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4285 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4286 | if (record_decl->isUnion()) |
| 4287 | return lldb::eTypeClassUnion; |
| 4288 | else if (record_decl->isStruct()) |
| 4289 | return lldb::eTypeClassStruct; |
| 4290 | else |
| 4291 | return lldb::eTypeClassClass; |
| 4292 | } break; |
| 4293 | case clang::Type::Enum: |
| 4294 | return lldb::eTypeClassEnumeration; |
| 4295 | case clang::Type::Typedef: |
| 4296 | return lldb::eTypeClassTypedef; |
| 4297 | case clang::Type::UnresolvedUsing: |
| 4298 | break; |
| 4299 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4300 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 4301 | ->desugar() |
| 4302 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4303 | .GetTypeClass(); |
| 4304 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4305 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 4306 | ->getDeducedType() |
| 4307 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4308 | .GetTypeClass(); |
| 4309 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4310 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 4311 | ->getNamedType() |
| 4312 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4313 | .GetTypeClass(); |
| 4314 | |
| 4315 | case clang::Type::Attributed: |
| 4316 | break; |
| 4317 | case clang::Type::TemplateTypeParm: |
| 4318 | break; |
| 4319 | case clang::Type::SubstTemplateTypeParm: |
| 4320 | break; |
| 4321 | case clang::Type::SubstTemplateTypeParmPack: |
| 4322 | break; |
| 4323 | case clang::Type::InjectedClassName: |
| 4324 | break; |
| 4325 | case clang::Type::DependentName: |
| 4326 | break; |
| 4327 | case clang::Type::DependentTemplateSpecialization: |
| 4328 | break; |
| 4329 | case clang::Type::PackExpansion: |
| 4330 | break; |
| 4331 | |
| 4332 | case clang::Type::TypeOfExpr: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4333 | return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type) |
| 4334 | ->getUnderlyingExpr() |
| 4335 | ->getType() |
| 4336 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4337 | .GetTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4338 | case clang::Type::TypeOf: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4339 | return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type) |
| 4340 | ->getUnderlyingType() |
| 4341 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4342 | .GetTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4343 | case clang::Type::Decltype: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4344 | return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type) |
| 4345 | ->getUnderlyingType() |
| 4346 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4347 | .GetTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4348 | case clang::Type::TemplateSpecialization: |
| 4349 | break; |
Pavel Labath | 4f19fce2 | 2017-02-17 13:39:50 +0000 | [diff] [blame] | 4350 | case clang::Type::DeducedTemplateSpecialization: |
| 4351 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4352 | case clang::Type::Atomic: |
| 4353 | break; |
| 4354 | case clang::Type::Pipe: |
| 4355 | break; |
| 4356 | |
| 4357 | // pointer type decayed from an array or function type. |
| 4358 | case clang::Type::Decayed: |
| 4359 | break; |
| 4360 | case clang::Type::Adjusted: |
| 4361 | break; |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 4362 | case clang::Type::ObjCTypeParam: |
| 4363 | break; |
Ted Woodward | 66060cf | 2017-10-11 22:42:21 +0000 | [diff] [blame] | 4364 | |
| 4365 | case clang::Type::DependentAddressSpace: |
| 4366 | break; |
Krasimir Georgiev | 435e76a | 2019-05-07 13:59:30 +0000 | [diff] [blame] | 4367 | case clang::Type::MacroQualified: |
| 4368 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4369 | } |
| 4370 | // We don't know hot to display this type... |
| 4371 | return lldb::eTypeClassOther; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4372 | } |
| 4373 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4374 | unsigned ClangASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) { |
| 4375 | if (type) |
| 4376 | return GetQualType(type).getQualifiers().getCVRQualifiers(); |
| 4377 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4380 | // Creating related types |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4381 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4382 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4383 | ClangASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type, |
| 4384 | uint64_t *stride) { |
| 4385 | if (type) { |
| 4386 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4387 | |
| 4388 | const clang::Type *array_eletype = |
| 4389 | qual_type.getTypePtr()->getArrayElementTypeNoTypeQual(); |
| 4390 | |
| 4391 | if (!array_eletype) |
| 4392 | return CompilerType(); |
| 4393 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4394 | CompilerType element_type( |
| 4395 | this, array_eletype->getCanonicalTypeUnqualified().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4396 | |
| 4397 | // TODO: the real stride will be >= this value.. find the real one! |
| 4398 | if (stride) |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 4399 | if (Optional<uint64_t> size = element_type.GetByteSize(nullptr)) |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 4400 | *stride = *size; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4401 | |
| 4402 | return element_type; |
| 4403 | } |
| 4404 | return CompilerType(); |
| 4405 | } |
| 4406 | |
| 4407 | CompilerType ClangASTContext::GetArrayType(lldb::opaque_compiler_type_t type, |
| 4408 | uint64_t size) { |
| 4409 | if (type) { |
| 4410 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4411 | if (clang::ASTContext *ast_ctx = getASTContext()) { |
| 4412 | if (size != 0) |
| 4413 | return CompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4414 | this, ast_ctx |
| 4415 | ->getConstantArrayType( |
Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 4416 | qual_type, llvm::APInt(64, size), nullptr, |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4417 | clang::ArrayType::ArraySizeModifier::Normal, 0) |
| 4418 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4419 | else |
| 4420 | return CompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4421 | this, |
| 4422 | ast_ctx |
| 4423 | ->getIncompleteArrayType( |
| 4424 | qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0) |
| 4425 | .getAsOpaquePtr()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4426 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4430 | } |
| 4431 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4432 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4433 | ClangASTContext::GetCanonicalType(lldb::opaque_compiler_type_t type) { |
| 4434 | if (type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4435 | return CompilerType(this, GetCanonicalQualType(type).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4436 | return CompilerType(); |
| 4437 | } |
| 4438 | |
| 4439 | static clang::QualType GetFullyUnqualifiedType_Impl(clang::ASTContext *ast, |
| 4440 | clang::QualType qual_type) { |
| 4441 | if (qual_type->isPointerType()) |
| 4442 | qual_type = ast->getPointerType( |
| 4443 | GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType())); |
| 4444 | else |
| 4445 | qual_type = qual_type.getUnqualifiedType(); |
| 4446 | qual_type.removeLocalConst(); |
| 4447 | qual_type.removeLocalRestrict(); |
| 4448 | qual_type.removeLocalVolatile(); |
| 4449 | return qual_type; |
Enrico Granata | 639392f | 2016-08-30 20:39:58 +0000 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4453 | ClangASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) { |
| 4454 | if (type) |
| 4455 | return CompilerType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4456 | this, |
| 4457 | GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type)).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4458 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4459 | } |
| 4460 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4461 | int ClangASTContext::GetFunctionArgumentCount( |
| 4462 | lldb::opaque_compiler_type_t type) { |
| 4463 | if (type) { |
| 4464 | const clang::FunctionProtoType *func = |
| 4465 | llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type)); |
| 4466 | if (func) |
| 4467 | return func->getNumParams(); |
| 4468 | } |
| 4469 | return -1; |
| 4470 | } |
| 4471 | |
| 4472 | CompilerType ClangASTContext::GetFunctionArgumentTypeAtIndex( |
| 4473 | lldb::opaque_compiler_type_t type, size_t idx) { |
| 4474 | if (type) { |
| 4475 | const clang::FunctionProtoType *func = |
| 4476 | llvm::dyn_cast<clang::FunctionProtoType>(GetQualType(type)); |
| 4477 | if (func) { |
| 4478 | const uint32_t num_args = func->getNumParams(); |
| 4479 | if (idx < num_args) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4480 | return CompilerType(this, func->getParamType(idx).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4481 | } |
| 4482 | } |
| 4483 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4484 | } |
| 4485 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4486 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4487 | ClangASTContext::GetFunctionReturnType(lldb::opaque_compiler_type_t type) { |
| 4488 | if (type) { |
| 4489 | clang::QualType qual_type(GetQualType(type)); |
| 4490 | const clang::FunctionProtoType *func = |
| 4491 | llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 4492 | if (func) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4493 | return CompilerType(this, func->getReturnType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4494 | } |
| 4495 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | size_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4499 | ClangASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) { |
| 4500 | size_t num_functions = 0; |
| 4501 | if (type) { |
| 4502 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4503 | switch (qual_type->getTypeClass()) { |
| 4504 | case clang::Type::Record: |
| 4505 | if (GetCompleteQualType(getASTContext(), qual_type)) { |
| 4506 | const clang::RecordType *record_type = |
| 4507 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4508 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4509 | assert(record_decl); |
| 4510 | const clang::CXXRecordDecl *cxx_record_decl = |
| 4511 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 4512 | if (cxx_record_decl) |
| 4513 | num_functions = std::distance(cxx_record_decl->method_begin(), |
| 4514 | cxx_record_decl->method_end()); |
| 4515 | } |
| 4516 | break; |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 4517 | |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4518 | case clang::Type::ObjCObjectPointer: { |
| 4519 | const clang::ObjCObjectPointerType *objc_class_type = |
Sean Callanan | 732a6f4 | 2017-05-15 19:55:20 +0000 | [diff] [blame] | 4520 | qual_type->getAs<clang::ObjCObjectPointerType>(); |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4521 | const clang::ObjCInterfaceType *objc_interface_type = |
| 4522 | objc_class_type->getInterfaceType(); |
| 4523 | if (objc_interface_type && |
Davide Italiano | 52ffb53 | 2017-04-17 18:24:18 +0000 | [diff] [blame] | 4524 | GetCompleteType(static_cast<lldb::opaque_compiler_type_t>( |
| 4525 | const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) { |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4526 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 4527 | objc_interface_type->getDecl(); |
| 4528 | if (class_interface_decl) { |
| 4529 | num_functions = std::distance(class_interface_decl->meth_begin(), |
| 4530 | class_interface_decl->meth_end()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4531 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4532 | } |
| 4533 | break; |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4534 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4535 | |
| 4536 | case clang::Type::ObjCObject: |
| 4537 | case clang::Type::ObjCInterface: |
| 4538 | if (GetCompleteType(type)) { |
| 4539 | const clang::ObjCObjectType *objc_class_type = |
| 4540 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4541 | if (objc_class_type) { |
| 4542 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 4543 | objc_class_type->getInterface(); |
| 4544 | if (class_interface_decl) |
| 4545 | num_functions = std::distance(class_interface_decl->meth_begin(), |
| 4546 | class_interface_decl->meth_end()); |
| 4547 | } |
| 4548 | } |
| 4549 | break; |
| 4550 | |
| 4551 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4552 | return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 4553 | ->getDecl() |
| 4554 | ->getUnderlyingType() |
| 4555 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4556 | .GetNumMemberFunctions(); |
| 4557 | |
| 4558 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4559 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 4560 | ->getDeducedType() |
| 4561 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4562 | .GetNumMemberFunctions(); |
| 4563 | |
| 4564 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4565 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 4566 | ->getNamedType() |
| 4567 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4568 | .GetNumMemberFunctions(); |
| 4569 | |
| 4570 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4571 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 4572 | ->desugar() |
| 4573 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4574 | .GetNumMemberFunctions(); |
| 4575 | |
| 4576 | default: |
| 4577 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4578 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4579 | } |
| 4580 | return num_functions; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | TypeMemberFunctionImpl |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4584 | ClangASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, |
| 4585 | size_t idx) { |
| 4586 | std::string name; |
| 4587 | MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown); |
| 4588 | CompilerType clang_type; |
| 4589 | CompilerDecl clang_decl; |
| 4590 | if (type) { |
| 4591 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4592 | switch (qual_type->getTypeClass()) { |
| 4593 | case clang::Type::Record: |
| 4594 | if (GetCompleteQualType(getASTContext(), qual_type)) { |
| 4595 | const clang::RecordType *record_type = |
| 4596 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4597 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4598 | assert(record_decl); |
| 4599 | const clang::CXXRecordDecl *cxx_record_decl = |
| 4600 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 4601 | if (cxx_record_decl) { |
| 4602 | auto method_iter = cxx_record_decl->method_begin(); |
| 4603 | auto method_end = cxx_record_decl->method_end(); |
| 4604 | if (idx < |
| 4605 | static_cast<size_t>(std::distance(method_iter, method_end))) { |
| 4606 | std::advance(method_iter, idx); |
| 4607 | clang::CXXMethodDecl *cxx_method_decl = |
| 4608 | method_iter->getCanonicalDecl(); |
| 4609 | if (cxx_method_decl) { |
| 4610 | name = cxx_method_decl->getDeclName().getAsString(); |
| 4611 | if (cxx_method_decl->isStatic()) |
| 4612 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4613 | else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl)) |
| 4614 | kind = lldb::eMemberFunctionKindConstructor; |
| 4615 | else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl)) |
| 4616 | kind = lldb::eMemberFunctionKindDestructor; |
| 4617 | else |
| 4618 | kind = lldb::eMemberFunctionKindInstanceMethod; |
| 4619 | clang_type = CompilerType( |
| 4620 | this, cxx_method_decl->getType().getAsOpaquePtr()); |
| 4621 | clang_decl = CompilerDecl(this, cxx_method_decl); |
| 4622 | } |
| 4623 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4624 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4625 | } |
| 4626 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4627 | |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4628 | case clang::Type::ObjCObjectPointer: { |
| 4629 | const clang::ObjCObjectPointerType *objc_class_type = |
Sean Callanan | 732a6f4 | 2017-05-15 19:55:20 +0000 | [diff] [blame] | 4630 | qual_type->getAs<clang::ObjCObjectPointerType>(); |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4631 | const clang::ObjCInterfaceType *objc_interface_type = |
| 4632 | objc_class_type->getInterfaceType(); |
| 4633 | if (objc_interface_type && |
Davide Italiano | 52ffb53 | 2017-04-17 18:24:18 +0000 | [diff] [blame] | 4634 | GetCompleteType(static_cast<lldb::opaque_compiler_type_t>( |
| 4635 | const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) { |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4636 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 4637 | objc_interface_type->getDecl(); |
| 4638 | if (class_interface_decl) { |
| 4639 | auto method_iter = class_interface_decl->meth_begin(); |
| 4640 | auto method_end = class_interface_decl->meth_end(); |
| 4641 | if (idx < |
| 4642 | static_cast<size_t>(std::distance(method_iter, method_end))) { |
| 4643 | std::advance(method_iter, idx); |
| 4644 | clang::ObjCMethodDecl *objc_method_decl = |
| 4645 | method_iter->getCanonicalDecl(); |
| 4646 | if (objc_method_decl) { |
| 4647 | clang_decl = CompilerDecl(this, objc_method_decl); |
| 4648 | name = objc_method_decl->getSelector().getAsString(); |
| 4649 | if (objc_method_decl->isClassMethod()) |
| 4650 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4651 | else |
| 4652 | kind = lldb::eMemberFunctionKindInstanceMethod; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4653 | } |
| 4654 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4655 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4656 | } |
| 4657 | break; |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4658 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4659 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4660 | case clang::Type::ObjCObject: |
| 4661 | case clang::Type::ObjCInterface: |
| 4662 | if (GetCompleteType(type)) { |
| 4663 | const clang::ObjCObjectType *objc_class_type = |
| 4664 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4665 | if (objc_class_type) { |
| 4666 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 4667 | objc_class_type->getInterface(); |
| 4668 | if (class_interface_decl) { |
| 4669 | auto method_iter = class_interface_decl->meth_begin(); |
| 4670 | auto method_end = class_interface_decl->meth_end(); |
| 4671 | if (idx < |
| 4672 | static_cast<size_t>(std::distance(method_iter, method_end))) { |
| 4673 | std::advance(method_iter, idx); |
| 4674 | clang::ObjCMethodDecl *objc_method_decl = |
| 4675 | method_iter->getCanonicalDecl(); |
| 4676 | if (objc_method_decl) { |
| 4677 | clang_decl = CompilerDecl(this, objc_method_decl); |
| 4678 | name = objc_method_decl->getSelector().getAsString(); |
| 4679 | if (objc_method_decl->isClassMethod()) |
| 4680 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4681 | else |
| 4682 | kind = lldb::eMemberFunctionKindInstanceMethod; |
| 4683 | } |
| 4684 | } |
| 4685 | } |
Ewan Crawford | 27fc7a7 | 2016-03-15 09:50:16 +0000 | [diff] [blame] | 4686 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4687 | } |
| 4688 | break; |
Ewan Crawford | 27fc7a7 | 2016-03-15 09:50:16 +0000 | [diff] [blame] | 4689 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4690 | case clang::Type::Typedef: |
| 4691 | return GetMemberFunctionAtIndex(llvm::cast<clang::TypedefType>(qual_type) |
| 4692 | ->getDecl() |
| 4693 | ->getUnderlyingType() |
| 4694 | .getAsOpaquePtr(), |
| 4695 | idx); |
Ewan Crawford | 27fc7a7 | 2016-03-15 09:50:16 +0000 | [diff] [blame] | 4696 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4697 | case clang::Type::Auto: |
| 4698 | return GetMemberFunctionAtIndex(llvm::cast<clang::AutoType>(qual_type) |
| 4699 | ->getDeducedType() |
| 4700 | .getAsOpaquePtr(), |
| 4701 | idx); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4702 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4703 | case clang::Type::Elaborated: |
| 4704 | return GetMemberFunctionAtIndex( |
| 4705 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 4706 | ->getNamedType() |
| 4707 | .getAsOpaquePtr(), |
| 4708 | idx); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4709 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4710 | case clang::Type::Paren: |
| 4711 | return GetMemberFunctionAtIndex( |
| 4712 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 4713 | idx); |
| 4714 | |
| 4715 | default: |
| 4716 | break; |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4717 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4718 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4719 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4720 | if (kind == eMemberFunctionKindUnknown) |
| 4721 | return TypeMemberFunctionImpl(); |
| 4722 | else |
| 4723 | return TypeMemberFunctionImpl(clang_type, clang_decl, name, kind); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4726 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4727 | ClangASTContext::GetNonReferenceType(lldb::opaque_compiler_type_t type) { |
| 4728 | if (type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4729 | return CompilerType( |
| 4730 | this, GetQualType(type).getNonReferenceType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4731 | return CompilerType(); |
| 4732 | } |
| 4733 | |
| 4734 | CompilerType ClangASTContext::CreateTypedefType( |
| 4735 | const CompilerType &type, const char *typedef_name, |
| 4736 | const CompilerDeclContext &compiler_decl_ctx) { |
| 4737 | if (type && typedef_name && typedef_name[0]) { |
| 4738 | ClangASTContext *ast = |
| 4739 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 4740 | if (!ast) |
| 4741 | return CompilerType(); |
| 4742 | clang::ASTContext *clang_ast = ast->getASTContext(); |
| 4743 | clang::QualType qual_type(ClangUtil::GetQualType(type)); |
| 4744 | |
| 4745 | clang::DeclContext *decl_ctx = |
| 4746 | ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); |
| 4747 | if (decl_ctx == nullptr) |
| 4748 | decl_ctx = ast->getASTContext()->getTranslationUnitDecl(); |
| 4749 | |
| 4750 | clang::TypedefDecl *decl = clang::TypedefDecl::Create( |
| 4751 | *clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(), |
| 4752 | &clang_ast->Idents.get(typedef_name), |
| 4753 | clang_ast->getTrivialTypeSourceInfo(qual_type)); |
| 4754 | |
| 4755 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier |
| 4756 | |
Aleksandr Urakov | 709426b | 2018-09-10 08:08:43 +0000 | [diff] [blame] | 4757 | decl_ctx->addDecl(decl); |
| 4758 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4759 | // Get a uniqued clang::QualType for the typedef decl type |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4760 | return CompilerType(ast, clang_ast->getTypedefType(decl).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4761 | } |
| 4762 | return CompilerType(); |
| 4763 | } |
| 4764 | |
| 4765 | CompilerType |
| 4766 | ClangASTContext::GetPointeeType(lldb::opaque_compiler_type_t type) { |
| 4767 | if (type) { |
| 4768 | clang::QualType qual_type(GetQualType(type)); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4769 | return CompilerType( |
| 4770 | this, qual_type.getTypePtr()->getPointeeType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4771 | } |
| 4772 | return CompilerType(); |
| 4773 | } |
| 4774 | |
| 4775 | CompilerType |
| 4776 | ClangASTContext::GetPointerType(lldb::opaque_compiler_type_t type) { |
| 4777 | if (type) { |
| 4778 | clang::QualType qual_type(GetQualType(type)); |
| 4779 | |
| 4780 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4781 | switch (type_class) { |
| 4782 | case clang::Type::ObjCObject: |
| 4783 | case clang::Type::ObjCInterface: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4784 | return CompilerType(this, getASTContext() |
| 4785 | ->getObjCObjectPointerType(qual_type) |
| 4786 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4787 | |
| 4788 | default: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4789 | return CompilerType( |
| 4790 | this, getASTContext()->getPointerType(qual_type).getAsOpaquePtr()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4791 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4792 | } |
| 4793 | return CompilerType(); |
| 4794 | } |
| 4795 | |
| 4796 | CompilerType |
| 4797 | ClangASTContext::GetLValueReferenceType(lldb::opaque_compiler_type_t type) { |
| 4798 | if (type) |
| 4799 | return CompilerType(this, getASTContext() |
| 4800 | ->getLValueReferenceType(GetQualType(type)) |
| 4801 | .getAsOpaquePtr()); |
| 4802 | else |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4803 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4806 | CompilerType |
| 4807 | ClangASTContext::GetRValueReferenceType(lldb::opaque_compiler_type_t type) { |
| 4808 | if (type) |
| 4809 | return CompilerType(this, getASTContext() |
| 4810 | ->getRValueReferenceType(GetQualType(type)) |
| 4811 | .getAsOpaquePtr()); |
| 4812 | else |
| 4813 | return CompilerType(); |
| 4814 | } |
| 4815 | |
| 4816 | CompilerType |
| 4817 | ClangASTContext::AddConstModifier(lldb::opaque_compiler_type_t type) { |
| 4818 | if (type) { |
| 4819 | clang::QualType result(GetQualType(type)); |
| 4820 | result.addConst(); |
| 4821 | return CompilerType(this, result.getAsOpaquePtr()); |
| 4822 | } |
| 4823 | return CompilerType(); |
| 4824 | } |
| 4825 | |
| 4826 | CompilerType |
| 4827 | ClangASTContext::AddVolatileModifier(lldb::opaque_compiler_type_t type) { |
| 4828 | if (type) { |
| 4829 | clang::QualType result(GetQualType(type)); |
| 4830 | result.addVolatile(); |
| 4831 | return CompilerType(this, result.getAsOpaquePtr()); |
| 4832 | } |
| 4833 | return CompilerType(); |
| 4834 | } |
| 4835 | |
| 4836 | CompilerType |
| 4837 | ClangASTContext::AddRestrictModifier(lldb::opaque_compiler_type_t type) { |
| 4838 | if (type) { |
| 4839 | clang::QualType result(GetQualType(type)); |
| 4840 | result.addRestrict(); |
| 4841 | return CompilerType(this, result.getAsOpaquePtr()); |
| 4842 | } |
| 4843 | return CompilerType(); |
| 4844 | } |
| 4845 | |
| 4846 | CompilerType |
| 4847 | ClangASTContext::CreateTypedef(lldb::opaque_compiler_type_t type, |
| 4848 | const char *typedef_name, |
| 4849 | const CompilerDeclContext &compiler_decl_ctx) { |
| 4850 | if (type) { |
| 4851 | clang::ASTContext *clang_ast = getASTContext(); |
| 4852 | clang::QualType qual_type(GetQualType(type)); |
| 4853 | |
| 4854 | clang::DeclContext *decl_ctx = |
| 4855 | ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); |
| 4856 | if (decl_ctx == nullptr) |
| 4857 | decl_ctx = getASTContext()->getTranslationUnitDecl(); |
| 4858 | |
| 4859 | clang::TypedefDecl *decl = clang::TypedefDecl::Create( |
| 4860 | *clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(), |
| 4861 | &clang_ast->Idents.get(typedef_name), |
| 4862 | clang_ast->getTrivialTypeSourceInfo(qual_type)); |
| 4863 | |
| 4864 | clang::TagDecl *tdecl = nullptr; |
| 4865 | if (!qual_type.isNull()) { |
| 4866 | if (const clang::RecordType *rt = qual_type->getAs<clang::RecordType>()) |
| 4867 | tdecl = rt->getDecl(); |
| 4868 | if (const clang::EnumType *et = qual_type->getAs<clang::EnumType>()) |
| 4869 | tdecl = et->getDecl(); |
| 4870 | } |
| 4871 | |
| 4872 | // Check whether this declaration is an anonymous struct, union, or enum, |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 4873 | // hidden behind a typedef. If so, we try to check whether we have a |
| 4874 | // typedef tag to attach to the original record declaration |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4875 | if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl()) |
| 4876 | tdecl->setTypedefNameForAnonDecl(decl); |
| 4877 | |
| 4878 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier |
| 4879 | |
| 4880 | // Get a uniqued clang::QualType for the typedef decl type |
| 4881 | return CompilerType(this, clang_ast->getTypedefType(decl).getAsOpaquePtr()); |
| 4882 | } |
| 4883 | return CompilerType(); |
| 4884 | } |
| 4885 | |
| 4886 | CompilerType |
| 4887 | ClangASTContext::GetTypedefedType(lldb::opaque_compiler_type_t type) { |
| 4888 | if (type) { |
| 4889 | const clang::TypedefType *typedef_type = |
| 4890 | llvm::dyn_cast<clang::TypedefType>(GetQualType(type)); |
| 4891 | if (typedef_type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4892 | return CompilerType( |
| 4893 | this, typedef_type->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4894 | } |
| 4895 | return CompilerType(); |
| 4896 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4897 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4898 | // Create related types using the current type's AST |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4899 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4900 | CompilerType ClangASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) { |
Raphael Isemann | c502bae | 2019-11-20 12:40:08 +0100 | [diff] [blame^] | 4901 | return ClangASTContext::GetBasicType(basic_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4902 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4903 | // Exploring the type |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4904 | |
Alex Langford | b482db6 | 2019-09-06 21:05:21 +0000 | [diff] [blame] | 4905 | const llvm::fltSemantics & |
| 4906 | ClangASTContext::GetFloatTypeSemantics(size_t byte_size) { |
| 4907 | if (auto *ast = getASTContext()) { |
| 4908 | const size_t bit_size = byte_size * 8; |
| 4909 | if (bit_size == ast->getTypeSize(ast->FloatTy)) |
| 4910 | return ast->getFloatTypeSemantics(ast->FloatTy); |
| 4911 | else if (bit_size == ast->getTypeSize(ast->DoubleTy)) |
| 4912 | return ast->getFloatTypeSemantics(ast->DoubleTy); |
| 4913 | else if (bit_size == ast->getTypeSize(ast->LongDoubleTy)) |
| 4914 | return ast->getFloatTypeSemantics(ast->LongDoubleTy); |
| 4915 | else if (bit_size == ast->getTypeSize(ast->HalfTy)) |
| 4916 | return ast->getFloatTypeSemantics(ast->HalfTy); |
| 4917 | } |
| 4918 | return llvm::APFloatBase::Bogus(); |
| 4919 | } |
| 4920 | |
Adrian Prantl | 2ee7b88 | 2019-01-16 21:19:20 +0000 | [diff] [blame] | 4921 | Optional<uint64_t> |
| 4922 | ClangASTContext::GetBitSize(lldb::opaque_compiler_type_t type, |
| 4923 | ExecutionContextScope *exe_scope) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4924 | if (GetCompleteType(type)) { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4925 | clang::QualType qual_type(GetCanonicalQualType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4926 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4927 | switch (type_class) { |
| 4928 | case clang::Type::Record: |
| 4929 | if (GetCompleteType(type)) |
| 4930 | return getASTContext()->getTypeSize(qual_type); |
| 4931 | else |
Adrian Prantl | 2ee7b88 | 2019-01-16 21:19:20 +0000 | [diff] [blame] | 4932 | return None; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4933 | break; |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 4934 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4935 | case clang::Type::ObjCInterface: |
| 4936 | case clang::Type::ObjCObject: { |
| 4937 | ExecutionContext exe_ctx(exe_scope); |
| 4938 | Process *process = exe_ctx.GetProcessPtr(); |
| 4939 | if (process) { |
Alex Langford | e823bbe | 2019-06-10 20:53:23 +0000 | [diff] [blame] | 4940 | ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4941 | if (objc_runtime) { |
| 4942 | uint64_t bit_size = 0; |
| 4943 | if (objc_runtime->GetTypeBitSize( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 4944 | CompilerType(this, qual_type.getAsOpaquePtr()), bit_size)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4945 | return bit_size; |
| 4946 | } |
| 4947 | } else { |
| 4948 | static bool g_printed = false; |
| 4949 | if (!g_printed) { |
| 4950 | StreamString s; |
| 4951 | DumpTypeDescription(type, &s); |
| 4952 | |
| 4953 | llvm::outs() << "warning: trying to determine the size of type "; |
| 4954 | llvm::outs() << s.GetString() << "\n"; |
| 4955 | llvm::outs() << "without a valid ExecutionContext. this is not " |
| 4956 | "reliable. please file a bug against LLDB.\n"; |
| 4957 | llvm::outs() << "backtrace:\n"; |
| 4958 | llvm::sys::PrintStackTrace(llvm::outs()); |
| 4959 | llvm::outs() << "\n"; |
| 4960 | g_printed = true; |
| 4961 | } |
| 4962 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4963 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4964 | LLVM_FALLTHROUGH; |
| 4965 | default: |
| 4966 | const uint32_t bit_size = getASTContext()->getTypeSize(qual_type); |
| 4967 | if (bit_size == 0) { |
| 4968 | if (qual_type->isIncompleteArrayType()) |
| 4969 | return getASTContext()->getTypeSize( |
| 4970 | qual_type->getArrayElementTypeNoTypeQual() |
| 4971 | ->getCanonicalTypeUnqualified()); |
| 4972 | } |
| 4973 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 4974 | return bit_size + |
| 4975 | getASTContext()->getTypeSize( |
| 4976 | getASTContext()->ObjCBuiltinClassTy); |
Adrian Prantl | 2ee7b88 | 2019-01-16 21:19:20 +0000 | [diff] [blame] | 4977 | // Function types actually have a size of 0, that's not an error. |
| 4978 | if (qual_type->isFunctionProtoType()) |
| 4979 | return bit_size; |
| 4980 | if (bit_size) |
| 4981 | return bit_size; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4982 | } |
| 4983 | } |
Adrian Prantl | 2ee7b88 | 2019-01-16 21:19:20 +0000 | [diff] [blame] | 4984 | return None; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4985 | } |
| 4986 | |
Davide Italiano | 36f13e4 | 2019-08-12 20:03:19 +0000 | [diff] [blame] | 4987 | llvm::Optional<size_t> |
Davide Italiano | 7f9bbe0 | 2019-08-12 21:49:54 +0000 | [diff] [blame] | 4988 | ClangASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type, |
| 4989 | ExecutionContextScope *exe_scope) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4990 | if (GetCompleteType(type)) |
| 4991 | return getASTContext()->getTypeAlign(GetQualType(type)); |
Davide Italiano | 36f13e4 | 2019-08-12 20:03:19 +0000 | [diff] [blame] | 4992 | return {}; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | lldb::Encoding ClangASTContext::GetEncoding(lldb::opaque_compiler_type_t type, |
| 4996 | uint64_t &count) { |
| 4997 | if (!type) |
| 4998 | return lldb::eEncodingInvalid; |
| 4999 | |
| 5000 | count = 1; |
| 5001 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5002 | |
| 5003 | switch (qual_type->getTypeClass()) { |
| 5004 | case clang::Type::UnaryTransform: |
| 5005 | break; |
| 5006 | |
| 5007 | case clang::Type::FunctionNoProto: |
| 5008 | case clang::Type::FunctionProto: |
| 5009 | break; |
| 5010 | |
| 5011 | case clang::Type::IncompleteArray: |
| 5012 | case clang::Type::VariableArray: |
| 5013 | break; |
| 5014 | |
| 5015 | case clang::Type::ConstantArray: |
| 5016 | break; |
| 5017 | |
Fangrui Song | 8f28488 | 2018-07-13 22:40:40 +0000 | [diff] [blame] | 5018 | case clang::Type::DependentVector: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5019 | case clang::Type::ExtVector: |
| 5020 | case clang::Type::Vector: |
| 5021 | // TODO: Set this to more than one??? |
| 5022 | break; |
| 5023 | |
| 5024 | case clang::Type::Builtin: |
| 5025 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 5026 | case clang::BuiltinType::Void: |
| 5027 | break; |
| 5028 | |
| 5029 | case clang::BuiltinType::Bool: |
| 5030 | case clang::BuiltinType::Char_S: |
| 5031 | case clang::BuiltinType::SChar: |
| 5032 | case clang::BuiltinType::WChar_S: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5033 | case clang::BuiltinType::Short: |
| 5034 | case clang::BuiltinType::Int: |
| 5035 | case clang::BuiltinType::Long: |
| 5036 | case clang::BuiltinType::LongLong: |
| 5037 | case clang::BuiltinType::Int128: |
| 5038 | return lldb::eEncodingSint; |
| 5039 | |
| 5040 | case clang::BuiltinType::Char_U: |
| 5041 | case clang::BuiltinType::UChar: |
| 5042 | case clang::BuiltinType::WChar_U: |
Richard Smith | 51d12d8 | 2018-05-02 02:43:22 +0000 | [diff] [blame] | 5043 | case clang::BuiltinType::Char8: |
| 5044 | case clang::BuiltinType::Char16: |
| 5045 | case clang::BuiltinType::Char32: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5046 | case clang::BuiltinType::UShort: |
| 5047 | case clang::BuiltinType::UInt: |
| 5048 | case clang::BuiltinType::ULong: |
| 5049 | case clang::BuiltinType::ULongLong: |
| 5050 | case clang::BuiltinType::UInt128: |
| 5051 | return lldb::eEncodingUint; |
| 5052 | |
Ilya Biryukov | fc48ac6 | 2018-06-05 10:07:07 +0000 | [diff] [blame] | 5053 | // Fixed point types. Note that they are currently ignored. |
| 5054 | case clang::BuiltinType::ShortAccum: |
| 5055 | case clang::BuiltinType::Accum: |
| 5056 | case clang::BuiltinType::LongAccum: |
| 5057 | case clang::BuiltinType::UShortAccum: |
| 5058 | case clang::BuiltinType::UAccum: |
| 5059 | case clang::BuiltinType::ULongAccum: |
Fangrui Song | a5e59c5 | 2018-06-14 18:19:40 +0000 | [diff] [blame] | 5060 | case clang::BuiltinType::ShortFract: |
Fangrui Song | a5e59c5 | 2018-06-14 18:19:40 +0000 | [diff] [blame] | 5061 | case clang::BuiltinType::Fract: |
| 5062 | case clang::BuiltinType::LongFract: |
| 5063 | case clang::BuiltinType::UShortFract: |
| 5064 | case clang::BuiltinType::UFract: |
| 5065 | case clang::BuiltinType::ULongFract: |
| 5066 | case clang::BuiltinType::SatShortAccum: |
| 5067 | case clang::BuiltinType::SatAccum: |
| 5068 | case clang::BuiltinType::SatLongAccum: |
| 5069 | case clang::BuiltinType::SatUShortAccum: |
| 5070 | case clang::BuiltinType::SatUAccum: |
| 5071 | case clang::BuiltinType::SatULongAccum: |
| 5072 | case clang::BuiltinType::SatShortFract: |
| 5073 | case clang::BuiltinType::SatFract: |
| 5074 | case clang::BuiltinType::SatLongFract: |
| 5075 | case clang::BuiltinType::SatUShortFract: |
| 5076 | case clang::BuiltinType::SatUFract: |
| 5077 | case clang::BuiltinType::SatULongFract: |
Ilya Biryukov | fc48ac6 | 2018-06-05 10:07:07 +0000 | [diff] [blame] | 5078 | break; |
| 5079 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5080 | case clang::BuiltinType::Half: |
| 5081 | case clang::BuiltinType::Float: |
Ted Woodward | 4355c7c | 2017-09-20 19:16:53 +0000 | [diff] [blame] | 5082 | case clang::BuiltinType::Float16: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5083 | case clang::BuiltinType::Float128: |
| 5084 | case clang::BuiltinType::Double: |
| 5085 | case clang::BuiltinType::LongDouble: |
| 5086 | return lldb::eEncodingIEEE754; |
| 5087 | |
| 5088 | case clang::BuiltinType::ObjCClass: |
| 5089 | case clang::BuiltinType::ObjCId: |
| 5090 | case clang::BuiltinType::ObjCSel: |
| 5091 | return lldb::eEncodingUint; |
| 5092 | |
| 5093 | case clang::BuiltinType::NullPtr: |
| 5094 | return lldb::eEncodingUint; |
| 5095 | |
| 5096 | case clang::BuiltinType::Kind::ARCUnbridgedCast: |
| 5097 | case clang::BuiltinType::Kind::BoundMember: |
| 5098 | case clang::BuiltinType::Kind::BuiltinFn: |
| 5099 | case clang::BuiltinType::Kind::Dependent: |
| 5100 | case clang::BuiltinType::Kind::OCLClkEvent: |
| 5101 | case clang::BuiltinType::Kind::OCLEvent: |
| 5102 | case clang::BuiltinType::Kind::OCLImage1dRO: |
| 5103 | case clang::BuiltinType::Kind::OCLImage1dWO: |
| 5104 | case clang::BuiltinType::Kind::OCLImage1dRW: |
| 5105 | case clang::BuiltinType::Kind::OCLImage1dArrayRO: |
| 5106 | case clang::BuiltinType::Kind::OCLImage1dArrayWO: |
| 5107 | case clang::BuiltinType::Kind::OCLImage1dArrayRW: |
| 5108 | case clang::BuiltinType::Kind::OCLImage1dBufferRO: |
| 5109 | case clang::BuiltinType::Kind::OCLImage1dBufferWO: |
| 5110 | case clang::BuiltinType::Kind::OCLImage1dBufferRW: |
| 5111 | case clang::BuiltinType::Kind::OCLImage2dRO: |
| 5112 | case clang::BuiltinType::Kind::OCLImage2dWO: |
| 5113 | case clang::BuiltinType::Kind::OCLImage2dRW: |
| 5114 | case clang::BuiltinType::Kind::OCLImage2dArrayRO: |
| 5115 | case clang::BuiltinType::Kind::OCLImage2dArrayWO: |
| 5116 | case clang::BuiltinType::Kind::OCLImage2dArrayRW: |
| 5117 | case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO: |
| 5118 | case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO: |
| 5119 | case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW: |
| 5120 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO: |
| 5121 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO: |
| 5122 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW: |
| 5123 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO: |
| 5124 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO: |
| 5125 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW: |
| 5126 | case clang::BuiltinType::Kind::OCLImage2dDepthRO: |
| 5127 | case clang::BuiltinType::Kind::OCLImage2dDepthWO: |
| 5128 | case clang::BuiltinType::Kind::OCLImage2dDepthRW: |
| 5129 | case clang::BuiltinType::Kind::OCLImage2dMSAARO: |
| 5130 | case clang::BuiltinType::Kind::OCLImage2dMSAAWO: |
| 5131 | case clang::BuiltinType::Kind::OCLImage2dMSAARW: |
| 5132 | case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO: |
| 5133 | case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO: |
| 5134 | case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW: |
| 5135 | case clang::BuiltinType::Kind::OCLImage3dRO: |
| 5136 | case clang::BuiltinType::Kind::OCLImage3dWO: |
| 5137 | case clang::BuiltinType::Kind::OCLImage3dRW: |
| 5138 | case clang::BuiltinType::Kind::OCLQueue: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5139 | case clang::BuiltinType::Kind::OCLReserveID: |
| 5140 | case clang::BuiltinType::Kind::OCLSampler: |
| 5141 | case clang::BuiltinType::Kind::OMPArraySection: |
| 5142 | case clang::BuiltinType::Kind::Overload: |
| 5143 | case clang::BuiltinType::Kind::PseudoObject: |
| 5144 | case clang::BuiltinType::Kind::UnknownAny: |
| 5145 | break; |
Jorge Gorbe Moya | a6e6c18 | 2018-11-08 22:04:58 +0000 | [diff] [blame] | 5146 | |
| 5147 | case clang::BuiltinType::OCLIntelSubgroupAVCMcePayload: |
| 5148 | case clang::BuiltinType::OCLIntelSubgroupAVCImePayload: |
| 5149 | case clang::BuiltinType::OCLIntelSubgroupAVCRefPayload: |
| 5150 | case clang::BuiltinType::OCLIntelSubgroupAVCSicPayload: |
| 5151 | case clang::BuiltinType::OCLIntelSubgroupAVCMceResult: |
| 5152 | case clang::BuiltinType::OCLIntelSubgroupAVCImeResult: |
| 5153 | case clang::BuiltinType::OCLIntelSubgroupAVCRefResult: |
| 5154 | case clang::BuiltinType::OCLIntelSubgroupAVCSicResult: |
| 5155 | case clang::BuiltinType::OCLIntelSubgroupAVCImeResultSingleRefStreamout: |
| 5156 | case clang::BuiltinType::OCLIntelSubgroupAVCImeResultDualRefStreamout: |
| 5157 | case clang::BuiltinType::OCLIntelSubgroupAVCImeSingleRefStreamin: |
| 5158 | case clang::BuiltinType::OCLIntelSubgroupAVCImeDualRefStreamin: |
| 5159 | break; |
Raphael Isemann | 339b5d1 | 2019-08-09 09:58:47 +0000 | [diff] [blame] | 5160 | |
| 5161 | case clang::BuiltinType::SveBool: |
| 5162 | case clang::BuiltinType::SveInt8: |
| 5163 | case clang::BuiltinType::SveInt16: |
| 5164 | case clang::BuiltinType::SveInt32: |
| 5165 | case clang::BuiltinType::SveInt64: |
| 5166 | case clang::BuiltinType::SveUint8: |
| 5167 | case clang::BuiltinType::SveUint16: |
| 5168 | case clang::BuiltinType::SveUint32: |
| 5169 | case clang::BuiltinType::SveUint64: |
| 5170 | case clang::BuiltinType::SveFloat16: |
| 5171 | case clang::BuiltinType::SveFloat32: |
| 5172 | case clang::BuiltinType::SveFloat64: |
| 5173 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5174 | } |
| 5175 | break; |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 5176 | // All pointer types are represented as unsigned integer encodings. We may |
| 5177 | // nee to add a eEncodingPointer if we ever need to know the difference |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5178 | case clang::Type::ObjCObjectPointer: |
| 5179 | case clang::Type::BlockPointer: |
| 5180 | case clang::Type::Pointer: |
| 5181 | case clang::Type::LValueReference: |
| 5182 | case clang::Type::RValueReference: |
| 5183 | case clang::Type::MemberPointer: |
| 5184 | return lldb::eEncodingUint; |
| 5185 | case clang::Type::Complex: { |
| 5186 | lldb::Encoding encoding = lldb::eEncodingIEEE754; |
| 5187 | if (qual_type->isComplexType()) |
| 5188 | encoding = lldb::eEncodingIEEE754; |
| 5189 | else { |
| 5190 | const clang::ComplexType *complex_type = |
| 5191 | qual_type->getAsComplexIntegerType(); |
| 5192 | if (complex_type) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5193 | encoding = |
| 5194 | CompilerType(this, complex_type->getElementType().getAsOpaquePtr()) |
| 5195 | .GetEncoding(count); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5196 | else |
| 5197 | encoding = lldb::eEncodingSint; |
| 5198 | } |
| 5199 | count = 2; |
| 5200 | return encoding; |
| 5201 | } |
| 5202 | |
| 5203 | case clang::Type::ObjCInterface: |
| 5204 | break; |
| 5205 | case clang::Type::Record: |
| 5206 | break; |
| 5207 | case clang::Type::Enum: |
| 5208 | return lldb::eEncodingSint; |
| 5209 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5210 | return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 5211 | ->getDecl() |
| 5212 | ->getUnderlyingType() |
| 5213 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5214 | .GetEncoding(count); |
| 5215 | |
| 5216 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5217 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 5218 | ->getDeducedType() |
| 5219 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5220 | .GetEncoding(count); |
| 5221 | |
| 5222 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5223 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 5224 | ->getNamedType() |
| 5225 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5226 | .GetEncoding(count); |
| 5227 | |
| 5228 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5229 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 5230 | ->desugar() |
| 5231 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5232 | .GetEncoding(count); |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5233 | case clang::Type::TypeOfExpr: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5234 | return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type) |
| 5235 | ->getUnderlyingExpr() |
| 5236 | ->getType() |
| 5237 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5238 | .GetEncoding(count); |
| 5239 | case clang::Type::TypeOf: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5240 | return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type) |
| 5241 | ->getUnderlyingType() |
| 5242 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5243 | .GetEncoding(count); |
| 5244 | case clang::Type::Decltype: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5245 | return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type) |
| 5246 | ->getUnderlyingType() |
| 5247 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5248 | .GetEncoding(count); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5249 | case clang::Type::DependentSizedArray: |
| 5250 | case clang::Type::DependentSizedExtVector: |
| 5251 | case clang::Type::UnresolvedUsing: |
| 5252 | case clang::Type::Attributed: |
| 5253 | case clang::Type::TemplateTypeParm: |
| 5254 | case clang::Type::SubstTemplateTypeParm: |
| 5255 | case clang::Type::SubstTemplateTypeParmPack: |
| 5256 | case clang::Type::InjectedClassName: |
| 5257 | case clang::Type::DependentName: |
| 5258 | case clang::Type::DependentTemplateSpecialization: |
| 5259 | case clang::Type::PackExpansion: |
| 5260 | case clang::Type::ObjCObject: |
| 5261 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5262 | case clang::Type::TemplateSpecialization: |
Pavel Labath | 4f19fce2 | 2017-02-17 13:39:50 +0000 | [diff] [blame] | 5263 | case clang::Type::DeducedTemplateSpecialization: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5264 | case clang::Type::Atomic: |
| 5265 | case clang::Type::Adjusted: |
| 5266 | case clang::Type::Pipe: |
| 5267 | break; |
| 5268 | |
| 5269 | // pointer type decayed from an array or function type. |
| 5270 | case clang::Type::Decayed: |
| 5271 | break; |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 5272 | case clang::Type::ObjCTypeParam: |
| 5273 | break; |
Ted Woodward | 66060cf | 2017-10-11 22:42:21 +0000 | [diff] [blame] | 5274 | |
| 5275 | case clang::Type::DependentAddressSpace: |
| 5276 | break; |
Krasimir Georgiev | 435e76a | 2019-05-07 13:59:30 +0000 | [diff] [blame] | 5277 | case clang::Type::MacroQualified: |
| 5278 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5279 | } |
| 5280 | count = 0; |
| 5281 | return lldb::eEncodingInvalid; |
| 5282 | } |
| 5283 | |
| 5284 | lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) { |
| 5285 | if (!type) |
| 5286 | return lldb::eFormatDefault; |
| 5287 | |
| 5288 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5289 | |
| 5290 | switch (qual_type->getTypeClass()) { |
| 5291 | case clang::Type::UnaryTransform: |
| 5292 | break; |
| 5293 | |
| 5294 | case clang::Type::FunctionNoProto: |
| 5295 | case clang::Type::FunctionProto: |
| 5296 | break; |
| 5297 | |
| 5298 | case clang::Type::IncompleteArray: |
| 5299 | case clang::Type::VariableArray: |
| 5300 | break; |
| 5301 | |
| 5302 | case clang::Type::ConstantArray: |
| 5303 | return lldb::eFormatVoid; // no value |
| 5304 | |
Fangrui Song | 8f28488 | 2018-07-13 22:40:40 +0000 | [diff] [blame] | 5305 | case clang::Type::DependentVector: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5306 | case clang::Type::ExtVector: |
| 5307 | case clang::Type::Vector: |
| 5308 | break; |
| 5309 | |
| 5310 | case clang::Type::Builtin: |
| 5311 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 5312 | // default: assert(0 && "Unknown builtin type!"); |
| 5313 | case clang::BuiltinType::UnknownAny: |
| 5314 | case clang::BuiltinType::Void: |
| 5315 | case clang::BuiltinType::BoundMember: |
| 5316 | break; |
| 5317 | |
| 5318 | case clang::BuiltinType::Bool: |
| 5319 | return lldb::eFormatBoolean; |
| 5320 | case clang::BuiltinType::Char_S: |
| 5321 | case clang::BuiltinType::SChar: |
| 5322 | case clang::BuiltinType::WChar_S: |
| 5323 | case clang::BuiltinType::Char_U: |
| 5324 | case clang::BuiltinType::UChar: |
| 5325 | case clang::BuiltinType::WChar_U: |
| 5326 | return lldb::eFormatChar; |
| 5327 | case clang::BuiltinType::Char16: |
| 5328 | return lldb::eFormatUnicode16; |
| 5329 | case clang::BuiltinType::Char32: |
| 5330 | return lldb::eFormatUnicode32; |
| 5331 | case clang::BuiltinType::UShort: |
| 5332 | return lldb::eFormatUnsigned; |
| 5333 | case clang::BuiltinType::Short: |
| 5334 | return lldb::eFormatDecimal; |
| 5335 | case clang::BuiltinType::UInt: |
| 5336 | return lldb::eFormatUnsigned; |
| 5337 | case clang::BuiltinType::Int: |
| 5338 | return lldb::eFormatDecimal; |
| 5339 | case clang::BuiltinType::ULong: |
| 5340 | return lldb::eFormatUnsigned; |
| 5341 | case clang::BuiltinType::Long: |
| 5342 | return lldb::eFormatDecimal; |
| 5343 | case clang::BuiltinType::ULongLong: |
| 5344 | return lldb::eFormatUnsigned; |
| 5345 | case clang::BuiltinType::LongLong: |
| 5346 | return lldb::eFormatDecimal; |
| 5347 | case clang::BuiltinType::UInt128: |
| 5348 | return lldb::eFormatUnsigned; |
| 5349 | case clang::BuiltinType::Int128: |
| 5350 | return lldb::eFormatDecimal; |
| 5351 | case clang::BuiltinType::Half: |
| 5352 | case clang::BuiltinType::Float: |
| 5353 | case clang::BuiltinType::Double: |
| 5354 | case clang::BuiltinType::LongDouble: |
| 5355 | return lldb::eFormatFloat; |
| 5356 | default: |
| 5357 | return lldb::eFormatHex; |
| 5358 | } |
| 5359 | break; |
| 5360 | case clang::Type::ObjCObjectPointer: |
| 5361 | return lldb::eFormatHex; |
| 5362 | case clang::Type::BlockPointer: |
| 5363 | return lldb::eFormatHex; |
| 5364 | case clang::Type::Pointer: |
| 5365 | return lldb::eFormatHex; |
| 5366 | case clang::Type::LValueReference: |
| 5367 | case clang::Type::RValueReference: |
| 5368 | return lldb::eFormatHex; |
| 5369 | case clang::Type::MemberPointer: |
| 5370 | break; |
| 5371 | case clang::Type::Complex: { |
| 5372 | if (qual_type->isComplexType()) |
| 5373 | return lldb::eFormatComplex; |
| 5374 | else |
| 5375 | return lldb::eFormatComplexInteger; |
| 5376 | } |
| 5377 | case clang::Type::ObjCInterface: |
| 5378 | break; |
| 5379 | case clang::Type::Record: |
| 5380 | break; |
| 5381 | case clang::Type::Enum: |
| 5382 | return lldb::eFormatEnum; |
| 5383 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5384 | return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 5385 | ->getDecl() |
| 5386 | ->getUnderlyingType() |
| 5387 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5388 | .GetFormat(); |
| 5389 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5390 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 5391 | ->desugar() |
| 5392 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5393 | .GetFormat(); |
| 5394 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5395 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 5396 | ->desugar() |
| 5397 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5398 | .GetFormat(); |
| 5399 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5400 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 5401 | ->getNamedType() |
| 5402 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5403 | .GetFormat(); |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5404 | case clang::Type::TypeOfExpr: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5405 | return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type) |
| 5406 | ->getUnderlyingExpr() |
| 5407 | ->getType() |
| 5408 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5409 | .GetFormat(); |
| 5410 | case clang::Type::TypeOf: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5411 | return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type) |
| 5412 | ->getUnderlyingType() |
| 5413 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5414 | .GetFormat(); |
| 5415 | case clang::Type::Decltype: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5416 | return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type) |
| 5417 | ->getUnderlyingType() |
| 5418 | .getAsOpaquePtr()) |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5419 | .GetFormat(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5420 | case clang::Type::DependentSizedArray: |
| 5421 | case clang::Type::DependentSizedExtVector: |
| 5422 | case clang::Type::UnresolvedUsing: |
| 5423 | case clang::Type::Attributed: |
| 5424 | case clang::Type::TemplateTypeParm: |
| 5425 | case clang::Type::SubstTemplateTypeParm: |
| 5426 | case clang::Type::SubstTemplateTypeParmPack: |
| 5427 | case clang::Type::InjectedClassName: |
| 5428 | case clang::Type::DependentName: |
| 5429 | case clang::Type::DependentTemplateSpecialization: |
| 5430 | case clang::Type::PackExpansion: |
| 5431 | case clang::Type::ObjCObject: |
| 5432 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5433 | case clang::Type::TemplateSpecialization: |
Pavel Labath | 4f19fce2 | 2017-02-17 13:39:50 +0000 | [diff] [blame] | 5434 | case clang::Type::DeducedTemplateSpecialization: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5435 | case clang::Type::Atomic: |
| 5436 | case clang::Type::Adjusted: |
| 5437 | case clang::Type::Pipe: |
| 5438 | break; |
| 5439 | |
| 5440 | // pointer type decayed from an array or function type. |
| 5441 | case clang::Type::Decayed: |
| 5442 | break; |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 5443 | case clang::Type::ObjCTypeParam: |
| 5444 | break; |
Ted Woodward | 66060cf | 2017-10-11 22:42:21 +0000 | [diff] [blame] | 5445 | |
| 5446 | case clang::Type::DependentAddressSpace: |
| 5447 | break; |
Krasimir Georgiev | 435e76a | 2019-05-07 13:59:30 +0000 | [diff] [blame] | 5448 | case clang::Type::MacroQualified: |
| 5449 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5450 | } |
| 5451 | // We don't know hot to display this type... |
| 5452 | return lldb::eFormatBytes; |
| 5453 | } |
| 5454 | |
| 5455 | static bool ObjCDeclHasIVars(clang::ObjCInterfaceDecl *class_interface_decl, |
| 5456 | bool check_superclass) { |
| 5457 | while (class_interface_decl) { |
| 5458 | if (class_interface_decl->ivar_size() > 0) |
| 5459 | return true; |
| 5460 | |
| 5461 | if (check_superclass) |
| 5462 | class_interface_decl = class_interface_decl->getSuperClass(); |
| 5463 | else |
| 5464 | break; |
| 5465 | } |
| 5466 | return false; |
| 5467 | } |
| 5468 | |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 5469 | static Optional<SymbolFile::ArrayInfo> |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5470 | GetDynamicArrayInfo(ClangASTContext &ast, SymbolFile *sym_file, |
| 5471 | clang::QualType qual_type, |
| 5472 | const ExecutionContext *exe_ctx) { |
| 5473 | if (qual_type->isIncompleteArrayType()) |
| 5474 | if (auto *metadata = ast.GetMetadata(qual_type.getAsOpaquePtr())) |
Pavel Labath | ffec31e | 2018-12-28 13:34:44 +0000 | [diff] [blame] | 5475 | return sym_file->GetDynamicArrayInfoForUID(metadata->GetUserID(), |
| 5476 | exe_ctx); |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5477 | return llvm::None; |
| 5478 | } |
| 5479 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5480 | uint32_t ClangASTContext::GetNumChildren(lldb::opaque_compiler_type_t type, |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5481 | bool omit_empty_base_classes, |
| 5482 | const ExecutionContext *exe_ctx) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5483 | if (!type) |
| 5484 | return 0; |
| 5485 | |
| 5486 | uint32_t num_children = 0; |
| 5487 | clang::QualType qual_type(GetQualType(type)); |
| 5488 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5489 | switch (type_class) { |
| 5490 | case clang::Type::Builtin: |
| 5491 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 5492 | case clang::BuiltinType::ObjCId: // child is Class |
| 5493 | case clang::BuiltinType::ObjCClass: // child is Class |
| 5494 | num_children = 1; |
| 5495 | break; |
| 5496 | |
| 5497 | default: |
| 5498 | break; |
| 5499 | } |
| 5500 | break; |
| 5501 | |
| 5502 | case clang::Type::Complex: |
| 5503 | return 0; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5504 | case clang::Type::Record: |
| 5505 | if (GetCompleteQualType(getASTContext(), qual_type)) { |
| 5506 | const clang::RecordType *record_type = |
| 5507 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 5508 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5509 | assert(record_decl); |
| 5510 | const clang::CXXRecordDecl *cxx_record_decl = |
| 5511 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 5512 | if (cxx_record_decl) { |
| 5513 | if (omit_empty_base_classes) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 5514 | // Check each base classes to see if it or any of its base classes |
| 5515 | // contain any fields. This can help limit the noise in variable |
| 5516 | // views by not having to show base classes that contain no members. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5517 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 5518 | base_class_end; |
| 5519 | for (base_class = cxx_record_decl->bases_begin(), |
| 5520 | base_class_end = cxx_record_decl->bases_end(); |
| 5521 | base_class != base_class_end; ++base_class) { |
| 5522 | const clang::CXXRecordDecl *base_class_decl = |
| 5523 | llvm::cast<clang::CXXRecordDecl>( |
| 5524 | base_class->getType() |
| 5525 | ->getAs<clang::RecordType>() |
| 5526 | ->getDecl()); |
| 5527 | |
| 5528 | // Skip empty base classes |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 5529 | if (!ClangASTContext::RecordHasFields(base_class_decl)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5530 | continue; |
| 5531 | |
| 5532 | num_children++; |
| 5533 | } |
| 5534 | } else { |
| 5535 | // Include all base classes |
| 5536 | num_children += cxx_record_decl->getNumBases(); |
| 5537 | } |
| 5538 | } |
| 5539 | clang::RecordDecl::field_iterator field, field_end; |
| 5540 | for (field = record_decl->field_begin(), |
| 5541 | field_end = record_decl->field_end(); |
| 5542 | field != field_end; ++field) |
| 5543 | ++num_children; |
| 5544 | } |
| 5545 | break; |
| 5546 | |
| 5547 | case clang::Type::ObjCObject: |
| 5548 | case clang::Type::ObjCInterface: |
| 5549 | if (GetCompleteQualType(getASTContext(), qual_type)) { |
| 5550 | const clang::ObjCObjectType *objc_class_type = |
| 5551 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5552 | assert(objc_class_type); |
| 5553 | if (objc_class_type) { |
| 5554 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5555 | objc_class_type->getInterface(); |
| 5556 | |
| 5557 | if (class_interface_decl) { |
| 5558 | |
| 5559 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 5560 | class_interface_decl->getSuperClass(); |
| 5561 | if (superclass_interface_decl) { |
| 5562 | if (omit_empty_base_classes) { |
| 5563 | if (ObjCDeclHasIVars(superclass_interface_decl, true)) |
| 5564 | ++num_children; |
| 5565 | } else |
| 5566 | ++num_children; |
| 5567 | } |
| 5568 | |
| 5569 | num_children += class_interface_decl->ivar_size(); |
| 5570 | } |
| 5571 | } |
| 5572 | } |
| 5573 | break; |
| 5574 | |
| 5575 | case clang::Type::ObjCObjectPointer: { |
| 5576 | const clang::ObjCObjectPointerType *pointer_type = |
| 5577 | llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()); |
| 5578 | clang::QualType pointee_type = pointer_type->getPointeeType(); |
| 5579 | uint32_t num_pointee_children = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5580 | CompilerType(this, pointee_type.getAsOpaquePtr()) |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5581 | .GetNumChildren(omit_empty_base_classes, exe_ctx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5582 | // If this type points to a simple type, then it has 1 child |
| 5583 | if (num_pointee_children == 0) |
| 5584 | num_children = 1; |
| 5585 | else |
| 5586 | num_children = num_pointee_children; |
| 5587 | } break; |
| 5588 | |
| 5589 | case clang::Type::Vector: |
| 5590 | case clang::Type::ExtVector: |
| 5591 | num_children = |
| 5592 | llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements(); |
| 5593 | break; |
| 5594 | |
| 5595 | case clang::Type::ConstantArray: |
| 5596 | num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr()) |
| 5597 | ->getSize() |
| 5598 | .getLimitedValue(); |
| 5599 | break; |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5600 | case clang::Type::IncompleteArray: |
| 5601 | if (auto array_info = |
| 5602 | GetDynamicArrayInfo(*this, GetSymbolFile(), qual_type, exe_ctx)) |
| 5603 | // Only 1-dimensional arrays are supported. |
| 5604 | num_children = array_info->element_orders.size() |
| 5605 | ? array_info->element_orders.back() |
| 5606 | : 0; |
| 5607 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5608 | |
| 5609 | case clang::Type::Pointer: { |
| 5610 | const clang::PointerType *pointer_type = |
| 5611 | llvm::cast<clang::PointerType>(qual_type.getTypePtr()); |
| 5612 | clang::QualType pointee_type(pointer_type->getPointeeType()); |
| 5613 | uint32_t num_pointee_children = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5614 | CompilerType(this, pointee_type.getAsOpaquePtr()) |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5615 | .GetNumChildren(omit_empty_base_classes, exe_ctx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5616 | if (num_pointee_children == 0) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 5617 | // We have a pointer to a pointee type that claims it has no children. We |
| 5618 | // will want to look at |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5619 | num_children = GetNumPointeeChildren(pointee_type); |
| 5620 | } else |
| 5621 | num_children = num_pointee_children; |
| 5622 | } break; |
| 5623 | |
| 5624 | case clang::Type::LValueReference: |
| 5625 | case clang::Type::RValueReference: { |
| 5626 | const clang::ReferenceType *reference_type = |
| 5627 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 5628 | clang::QualType pointee_type = reference_type->getPointeeType(); |
| 5629 | uint32_t num_pointee_children = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5630 | CompilerType(this, pointee_type.getAsOpaquePtr()) |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5631 | .GetNumChildren(omit_empty_base_classes, exe_ctx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5632 | // If this type points to a simple type, then it has 1 child |
| 5633 | if (num_pointee_children == 0) |
| 5634 | num_children = 1; |
| 5635 | else |
| 5636 | num_children = num_pointee_children; |
| 5637 | } break; |
| 5638 | |
| 5639 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5640 | num_children = CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5641 | ->getDecl() |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5642 | ->getUnderlyingType() |
| 5643 | .getAsOpaquePtr()) |
| 5644 | .GetNumChildren(omit_empty_base_classes, exe_ctx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5645 | break; |
| 5646 | |
| 5647 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5648 | num_children = CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 5649 | ->getDeducedType() |
| 5650 | .getAsOpaquePtr()) |
| 5651 | .GetNumChildren(omit_empty_base_classes, exe_ctx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5652 | break; |
| 5653 | |
| 5654 | case clang::Type::Elaborated: |
| 5655 | num_children = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5656 | CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 5657 | ->getNamedType() |
| 5658 | .getAsOpaquePtr()) |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5659 | .GetNumChildren(omit_empty_base_classes, exe_ctx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5660 | break; |
| 5661 | |
| 5662 | case clang::Type::Paren: |
| 5663 | num_children = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5664 | CompilerType( |
| 5665 | this, |
| 5666 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()) |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 5667 | .GetNumChildren(omit_empty_base_classes, exe_ctx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5668 | break; |
| 5669 | default: |
| 5670 | break; |
| 5671 | } |
| 5672 | return num_children; |
| 5673 | } |
| 5674 | |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 5675 | CompilerType ClangASTContext::GetBuiltinTypeByName(ConstString name) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5676 | return GetBasicType(GetBasicTypeEnumeration(name)); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 5677 | } |
| 5678 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5679 | lldb::BasicType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5680 | ClangASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) { |
| 5681 | if (type) { |
| 5682 | clang::QualType qual_type(GetQualType(type)); |
| 5683 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5684 | if (type_class == clang::Type::Builtin) { |
| 5685 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 5686 | case clang::BuiltinType::Void: |
| 5687 | return eBasicTypeVoid; |
| 5688 | case clang::BuiltinType::Bool: |
| 5689 | return eBasicTypeBool; |
| 5690 | case clang::BuiltinType::Char_S: |
| 5691 | return eBasicTypeSignedChar; |
| 5692 | case clang::BuiltinType::Char_U: |
| 5693 | return eBasicTypeUnsignedChar; |
| 5694 | case clang::BuiltinType::Char16: |
| 5695 | return eBasicTypeChar16; |
| 5696 | case clang::BuiltinType::Char32: |
| 5697 | return eBasicTypeChar32; |
| 5698 | case clang::BuiltinType::UChar: |
| 5699 | return eBasicTypeUnsignedChar; |
| 5700 | case clang::BuiltinType::SChar: |
| 5701 | return eBasicTypeSignedChar; |
| 5702 | case clang::BuiltinType::WChar_S: |
| 5703 | return eBasicTypeSignedWChar; |
| 5704 | case clang::BuiltinType::WChar_U: |
| 5705 | return eBasicTypeUnsignedWChar; |
| 5706 | case clang::BuiltinType::Short: |
| 5707 | return eBasicTypeShort; |
| 5708 | case clang::BuiltinType::UShort: |
| 5709 | return eBasicTypeUnsignedShort; |
| 5710 | case clang::BuiltinType::Int: |
| 5711 | return eBasicTypeInt; |
| 5712 | case clang::BuiltinType::UInt: |
| 5713 | return eBasicTypeUnsignedInt; |
| 5714 | case clang::BuiltinType::Long: |
| 5715 | return eBasicTypeLong; |
| 5716 | case clang::BuiltinType::ULong: |
| 5717 | return eBasicTypeUnsignedLong; |
| 5718 | case clang::BuiltinType::LongLong: |
| 5719 | return eBasicTypeLongLong; |
| 5720 | case clang::BuiltinType::ULongLong: |
| 5721 | return eBasicTypeUnsignedLongLong; |
| 5722 | case clang::BuiltinType::Int128: |
| 5723 | return eBasicTypeInt128; |
| 5724 | case clang::BuiltinType::UInt128: |
| 5725 | return eBasicTypeUnsignedInt128; |
| 5726 | |
| 5727 | case clang::BuiltinType::Half: |
| 5728 | return eBasicTypeHalf; |
| 5729 | case clang::BuiltinType::Float: |
| 5730 | return eBasicTypeFloat; |
| 5731 | case clang::BuiltinType::Double: |
| 5732 | return eBasicTypeDouble; |
| 5733 | case clang::BuiltinType::LongDouble: |
| 5734 | return eBasicTypeLongDouble; |
| 5735 | |
| 5736 | case clang::BuiltinType::NullPtr: |
| 5737 | return eBasicTypeNullPtr; |
| 5738 | case clang::BuiltinType::ObjCId: |
| 5739 | return eBasicTypeObjCID; |
| 5740 | case clang::BuiltinType::ObjCClass: |
| 5741 | return eBasicTypeObjCClass; |
| 5742 | case clang::BuiltinType::ObjCSel: |
| 5743 | return eBasicTypeObjCSel; |
| 5744 | default: |
| 5745 | return eBasicTypeOther; |
| 5746 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5747 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5748 | } |
| 5749 | return eBasicTypeInvalid; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5752 | void ClangASTContext::ForEachEnumerator( |
| 5753 | lldb::opaque_compiler_type_t type, |
| 5754 | std::function<bool(const CompilerType &integer_type, |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 5755 | ConstString name, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5756 | const llvm::APSInt &value)> const &callback) { |
| 5757 | const clang::EnumType *enum_type = |
| 5758 | llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)); |
| 5759 | if (enum_type) { |
| 5760 | const clang::EnumDecl *enum_decl = enum_type->getDecl(); |
| 5761 | if (enum_decl) { |
| 5762 | CompilerType integer_type(this, |
| 5763 | enum_decl->getIntegerType().getAsOpaquePtr()); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5764 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5765 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 5766 | for (enum_pos = enum_decl->enumerator_begin(), |
| 5767 | enum_end_pos = enum_decl->enumerator_end(); |
| 5768 | enum_pos != enum_end_pos; ++enum_pos) { |
| 5769 | ConstString name(enum_pos->getNameAsString().c_str()); |
| 5770 | if (!callback(integer_type, name, enum_pos->getInitVal())) |
| 5771 | break; |
| 5772 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5773 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5774 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5775 | } |
| 5776 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5777 | #pragma mark Aggregate Types |
| 5778 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5779 | uint32_t ClangASTContext::GetNumFields(lldb::opaque_compiler_type_t type) { |
| 5780 | if (!type) |
| 5781 | return 0; |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5782 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5783 | uint32_t count = 0; |
| 5784 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5785 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5786 | switch (type_class) { |
| 5787 | case clang::Type::Record: |
| 5788 | if (GetCompleteType(type)) { |
| 5789 | const clang::RecordType *record_type = |
| 5790 | llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 5791 | if (record_type) { |
| 5792 | clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5793 | if (record_decl) { |
| 5794 | uint32_t field_idx = 0; |
| 5795 | clang::RecordDecl::field_iterator field, field_end; |
| 5796 | for (field = record_decl->field_begin(), |
| 5797 | field_end = record_decl->field_end(); |
| 5798 | field != field_end; ++field) |
| 5799 | ++field_idx; |
| 5800 | count = field_idx; |
| 5801 | } |
| 5802 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5803 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5804 | break; |
| 5805 | |
| 5806 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5807 | count = CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 5808 | ->getDecl() |
| 5809 | ->getUnderlyingType() |
| 5810 | .getAsOpaquePtr()) |
| 5811 | .GetNumFields(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5812 | break; |
| 5813 | |
| 5814 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5815 | count = CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 5816 | ->getDeducedType() |
| 5817 | .getAsOpaquePtr()) |
| 5818 | .GetNumFields(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5819 | break; |
| 5820 | |
| 5821 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5822 | count = CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 5823 | ->getNamedType() |
| 5824 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5825 | .GetNumFields(); |
| 5826 | break; |
| 5827 | |
| 5828 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5829 | count = |
| 5830 | CompilerType( |
| 5831 | this, |
| 5832 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()) |
| 5833 | .GetNumFields(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5834 | break; |
| 5835 | |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5836 | case clang::Type::ObjCObjectPointer: { |
| 5837 | const clang::ObjCObjectPointerType *objc_class_type = |
Sean Callanan | 732a6f4 | 2017-05-15 19:55:20 +0000 | [diff] [blame] | 5838 | qual_type->getAs<clang::ObjCObjectPointerType>(); |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5839 | const clang::ObjCInterfaceType *objc_interface_type = |
| 5840 | objc_class_type->getInterfaceType(); |
| 5841 | if (objc_interface_type && |
Davide Italiano | 52ffb53 | 2017-04-17 18:24:18 +0000 | [diff] [blame] | 5842 | GetCompleteType(static_cast<lldb::opaque_compiler_type_t>( |
| 5843 | const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) { |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5844 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5845 | objc_interface_type->getDecl(); |
| 5846 | if (class_interface_decl) { |
| 5847 | count = class_interface_decl->ivar_size(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5848 | } |
| 5849 | } |
| 5850 | break; |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5851 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5852 | |
| 5853 | case clang::Type::ObjCObject: |
| 5854 | case clang::Type::ObjCInterface: |
| 5855 | if (GetCompleteType(type)) { |
| 5856 | const clang::ObjCObjectType *objc_class_type = |
| 5857 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5858 | if (objc_class_type) { |
| 5859 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5860 | objc_class_type->getInterface(); |
| 5861 | |
| 5862 | if (class_interface_decl) |
| 5863 | count = class_interface_decl->ivar_size(); |
| 5864 | } |
| 5865 | } |
| 5866 | break; |
| 5867 | |
| 5868 | default: |
| 5869 | break; |
| 5870 | } |
| 5871 | return count; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5874 | static lldb::opaque_compiler_type_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5875 | GetObjCFieldAtIndex(clang::ASTContext *ast, |
| 5876 | clang::ObjCInterfaceDecl *class_interface_decl, size_t idx, |
| 5877 | std::string &name, uint64_t *bit_offset_ptr, |
| 5878 | uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) { |
| 5879 | if (class_interface_decl) { |
| 5880 | if (idx < (class_interface_decl->ivar_size())) { |
| 5881 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, |
| 5882 | ivar_end = class_interface_decl->ivar_end(); |
| 5883 | uint32_t ivar_idx = 0; |
| 5884 | |
| 5885 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; |
| 5886 | ++ivar_pos, ++ivar_idx) { |
| 5887 | if (ivar_idx == idx) { |
| 5888 | const clang::ObjCIvarDecl *ivar_decl = *ivar_pos; |
| 5889 | |
| 5890 | clang::QualType ivar_qual_type(ivar_decl->getType()); |
| 5891 | |
| 5892 | name.assign(ivar_decl->getNameAsString()); |
| 5893 | |
| 5894 | if (bit_offset_ptr) { |
| 5895 | const clang::ASTRecordLayout &interface_layout = |
| 5896 | ast->getASTObjCInterfaceLayout(class_interface_decl); |
| 5897 | *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx); |
| 5898 | } |
| 5899 | |
| 5900 | const bool is_bitfield = ivar_pos->isBitField(); |
| 5901 | |
| 5902 | if (bitfield_bit_size_ptr) { |
| 5903 | *bitfield_bit_size_ptr = 0; |
| 5904 | |
| 5905 | if (is_bitfield && ast) { |
| 5906 | clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth(); |
Hans Wennborg | 30ce962 | 2018-11-28 14:30:18 +0000 | [diff] [blame] | 5907 | clang::Expr::EvalResult result; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5908 | if (bitfield_bit_size_expr && |
Hans Wennborg | 30ce962 | 2018-11-28 14:30:18 +0000 | [diff] [blame] | 5909 | bitfield_bit_size_expr->EvaluateAsInt(result, *ast)) { |
| 5910 | llvm::APSInt bitfield_apsint = result.Val.getInt(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5911 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 5912 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5913 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5914 | } |
| 5915 | if (is_bitfield_ptr) |
| 5916 | *is_bitfield_ptr = is_bitfield; |
| 5917 | |
| 5918 | return ivar_qual_type.getAsOpaquePtr(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5919 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5920 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5921 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5922 | } |
| 5923 | return nullptr; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5924 | } |
| 5925 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5926 | CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type, |
| 5927 | size_t idx, std::string &name, |
| 5928 | uint64_t *bit_offset_ptr, |
| 5929 | uint32_t *bitfield_bit_size_ptr, |
| 5930 | bool *is_bitfield_ptr) { |
| 5931 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5932 | return CompilerType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5933 | |
| 5934 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5935 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5936 | switch (type_class) { |
| 5937 | case clang::Type::Record: |
| 5938 | if (GetCompleteType(type)) { |
| 5939 | const clang::RecordType *record_type = |
| 5940 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 5941 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5942 | uint32_t field_idx = 0; |
| 5943 | clang::RecordDecl::field_iterator field, field_end; |
| 5944 | for (field = record_decl->field_begin(), |
| 5945 | field_end = record_decl->field_end(); |
| 5946 | field != field_end; ++field, ++field_idx) { |
| 5947 | if (idx == field_idx) { |
| 5948 | // Print the member type if requested |
| 5949 | // Print the member name and equal sign |
| 5950 | name.assign(field->getNameAsString()); |
| 5951 | |
| 5952 | // Figure out the type byte size (field_type_info.first) and |
| 5953 | // alignment (field_type_info.second) from the AST context. |
| 5954 | if (bit_offset_ptr) { |
| 5955 | const clang::ASTRecordLayout &record_layout = |
| 5956 | getASTContext()->getASTRecordLayout(record_decl); |
| 5957 | *bit_offset_ptr = record_layout.getFieldOffset(field_idx); |
| 5958 | } |
| 5959 | |
| 5960 | const bool is_bitfield = field->isBitField(); |
| 5961 | |
| 5962 | if (bitfield_bit_size_ptr) { |
| 5963 | *bitfield_bit_size_ptr = 0; |
| 5964 | |
| 5965 | if (is_bitfield) { |
| 5966 | clang::Expr *bitfield_bit_size_expr = field->getBitWidth(); |
Hans Wennborg | 30ce962 | 2018-11-28 14:30:18 +0000 | [diff] [blame] | 5967 | clang::Expr::EvalResult result; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5968 | if (bitfield_bit_size_expr && |
Hans Wennborg | 30ce962 | 2018-11-28 14:30:18 +0000 | [diff] [blame] | 5969 | bitfield_bit_size_expr->EvaluateAsInt(result, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5970 | *getASTContext())) { |
Hans Wennborg | 30ce962 | 2018-11-28 14:30:18 +0000 | [diff] [blame] | 5971 | llvm::APSInt bitfield_apsint = result.Val.getInt(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5972 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 5973 | } |
| 5974 | } |
| 5975 | } |
| 5976 | if (is_bitfield_ptr) |
| 5977 | *is_bitfield_ptr = is_bitfield; |
| 5978 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 5979 | return CompilerType(this, field->getType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5980 | } |
| 5981 | } |
| 5982 | } |
| 5983 | break; |
| 5984 | |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5985 | case clang::Type::ObjCObjectPointer: { |
| 5986 | const clang::ObjCObjectPointerType *objc_class_type = |
Sean Callanan | 732a6f4 | 2017-05-15 19:55:20 +0000 | [diff] [blame] | 5987 | qual_type->getAs<clang::ObjCObjectPointerType>(); |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5988 | const clang::ObjCInterfaceType *objc_interface_type = |
| 5989 | objc_class_type->getInterfaceType(); |
| 5990 | if (objc_interface_type && |
Davide Italiano | 52ffb53 | 2017-04-17 18:24:18 +0000 | [diff] [blame] | 5991 | GetCompleteType(static_cast<lldb::opaque_compiler_type_t>( |
| 5992 | const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) { |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5993 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5994 | objc_interface_type->getDecl(); |
| 5995 | if (class_interface_decl) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5996 | return CompilerType( |
| 5997 | this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, |
| 5998 | idx, name, bit_offset_ptr, |
| 5999 | bitfield_bit_size_ptr, is_bitfield_ptr)); |
| 6000 | } |
| 6001 | } |
| 6002 | break; |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 6003 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6004 | |
| 6005 | case clang::Type::ObjCObject: |
| 6006 | case clang::Type::ObjCInterface: |
| 6007 | if (GetCompleteType(type)) { |
| 6008 | const clang::ObjCObjectType *objc_class_type = |
| 6009 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 6010 | assert(objc_class_type); |
| 6011 | if (objc_class_type) { |
| 6012 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6013 | objc_class_type->getInterface(); |
| 6014 | return CompilerType( |
| 6015 | this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, |
| 6016 | idx, name, bit_offset_ptr, |
| 6017 | bitfield_bit_size_ptr, is_bitfield_ptr)); |
| 6018 | } |
| 6019 | } |
| 6020 | break; |
| 6021 | |
| 6022 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6023 | return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 6024 | ->getDecl() |
| 6025 | ->getUnderlyingType() |
| 6026 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6027 | .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, |
| 6028 | is_bitfield_ptr); |
| 6029 | |
| 6030 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6031 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 6032 | ->getDeducedType() |
| 6033 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6034 | .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, |
| 6035 | is_bitfield_ptr); |
| 6036 | |
| 6037 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6038 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 6039 | ->getNamedType() |
| 6040 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6041 | .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, |
| 6042 | is_bitfield_ptr); |
| 6043 | |
| 6044 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6045 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 6046 | ->desugar() |
| 6047 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6048 | .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, |
| 6049 | is_bitfield_ptr); |
| 6050 | |
| 6051 | default: |
| 6052 | break; |
| 6053 | } |
| 6054 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6055 | } |
| 6056 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6057 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6058 | ClangASTContext::GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) { |
| 6059 | uint32_t count = 0; |
| 6060 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6061 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6062 | switch (type_class) { |
| 6063 | case clang::Type::Record: |
| 6064 | if (GetCompleteType(type)) { |
| 6065 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6066 | qual_type->getAsCXXRecordDecl(); |
| 6067 | if (cxx_record_decl) |
| 6068 | count = cxx_record_decl->getNumBases(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6069 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6070 | break; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6071 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6072 | case clang::Type::ObjCObjectPointer: |
| 6073 | count = GetPointeeType(type).GetNumDirectBaseClasses(); |
| 6074 | break; |
| 6075 | |
| 6076 | case clang::Type::ObjCObject: |
| 6077 | if (GetCompleteType(type)) { |
| 6078 | const clang::ObjCObjectType *objc_class_type = |
| 6079 | qual_type->getAsObjCQualifiedInterfaceType(); |
| 6080 | if (objc_class_type) { |
| 6081 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6082 | objc_class_type->getInterface(); |
| 6083 | |
| 6084 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 6085 | count = 1; |
| 6086 | } |
| 6087 | } |
| 6088 | break; |
| 6089 | case clang::Type::ObjCInterface: |
| 6090 | if (GetCompleteType(type)) { |
| 6091 | const clang::ObjCInterfaceType *objc_interface_type = |
| 6092 | qual_type->getAs<clang::ObjCInterfaceType>(); |
| 6093 | if (objc_interface_type) { |
| 6094 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6095 | objc_interface_type->getInterface(); |
| 6096 | |
| 6097 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 6098 | count = 1; |
| 6099 | } |
| 6100 | } |
| 6101 | break; |
| 6102 | |
| 6103 | case clang::Type::Typedef: |
| 6104 | count = GetNumDirectBaseClasses(llvm::cast<clang::TypedefType>(qual_type) |
| 6105 | ->getDecl() |
| 6106 | ->getUnderlyingType() |
| 6107 | .getAsOpaquePtr()); |
| 6108 | break; |
| 6109 | |
| 6110 | case clang::Type::Auto: |
| 6111 | count = GetNumDirectBaseClasses(llvm::cast<clang::AutoType>(qual_type) |
| 6112 | ->getDeducedType() |
| 6113 | .getAsOpaquePtr()); |
| 6114 | break; |
| 6115 | |
| 6116 | case clang::Type::Elaborated: |
| 6117 | count = GetNumDirectBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type) |
| 6118 | ->getNamedType() |
| 6119 | .getAsOpaquePtr()); |
| 6120 | break; |
| 6121 | |
| 6122 | case clang::Type::Paren: |
| 6123 | return GetNumDirectBaseClasses( |
| 6124 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 6125 | |
| 6126 | default: |
| 6127 | break; |
| 6128 | } |
| 6129 | return count; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6133 | ClangASTContext::GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) { |
| 6134 | uint32_t count = 0; |
| 6135 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6136 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6137 | switch (type_class) { |
| 6138 | case clang::Type::Record: |
| 6139 | if (GetCompleteType(type)) { |
| 6140 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6141 | qual_type->getAsCXXRecordDecl(); |
| 6142 | if (cxx_record_decl) |
| 6143 | count = cxx_record_decl->getNumVBases(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6144 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6145 | break; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6146 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6147 | case clang::Type::Typedef: |
| 6148 | count = GetNumVirtualBaseClasses(llvm::cast<clang::TypedefType>(qual_type) |
| 6149 | ->getDecl() |
| 6150 | ->getUnderlyingType() |
| 6151 | .getAsOpaquePtr()); |
| 6152 | break; |
| 6153 | |
| 6154 | case clang::Type::Auto: |
| 6155 | count = GetNumVirtualBaseClasses(llvm::cast<clang::AutoType>(qual_type) |
| 6156 | ->getDeducedType() |
| 6157 | .getAsOpaquePtr()); |
| 6158 | break; |
| 6159 | |
| 6160 | case clang::Type::Elaborated: |
| 6161 | count = |
| 6162 | GetNumVirtualBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type) |
| 6163 | ->getNamedType() |
| 6164 | .getAsOpaquePtr()); |
| 6165 | break; |
| 6166 | |
| 6167 | case clang::Type::Paren: |
| 6168 | count = GetNumVirtualBaseClasses( |
| 6169 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 6170 | break; |
| 6171 | |
| 6172 | default: |
| 6173 | break; |
| 6174 | } |
| 6175 | return count; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6176 | } |
| 6177 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6178 | CompilerType ClangASTContext::GetDirectBaseClassAtIndex( |
| 6179 | lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) { |
| 6180 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6181 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6182 | switch (type_class) { |
| 6183 | case clang::Type::Record: |
| 6184 | if (GetCompleteType(type)) { |
| 6185 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6186 | qual_type->getAsCXXRecordDecl(); |
| 6187 | if (cxx_record_decl) { |
| 6188 | uint32_t curr_idx = 0; |
| 6189 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 6190 | base_class_end; |
| 6191 | for (base_class = cxx_record_decl->bases_begin(), |
| 6192 | base_class_end = cxx_record_decl->bases_end(); |
| 6193 | base_class != base_class_end; ++base_class, ++curr_idx) { |
| 6194 | if (curr_idx == idx) { |
| 6195 | if (bit_offset_ptr) { |
| 6196 | const clang::ASTRecordLayout &record_layout = |
| 6197 | getASTContext()->getASTRecordLayout(cxx_record_decl); |
| 6198 | const clang::CXXRecordDecl *base_class_decl = |
| 6199 | llvm::cast<clang::CXXRecordDecl>( |
| 6200 | base_class->getType() |
| 6201 | ->getAs<clang::RecordType>() |
| 6202 | ->getDecl()); |
| 6203 | if (base_class->isVirtual()) |
| 6204 | *bit_offset_ptr = |
| 6205 | record_layout.getVBaseClassOffset(base_class_decl) |
| 6206 | .getQuantity() * |
| 6207 | 8; |
| 6208 | else |
| 6209 | *bit_offset_ptr = |
| 6210 | record_layout.getBaseClassOffset(base_class_decl) |
| 6211 | .getQuantity() * |
| 6212 | 8; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6213 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6214 | return CompilerType(this, base_class->getType().getAsOpaquePtr()); |
| 6215 | } |
| 6216 | } |
| 6217 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6218 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6219 | break; |
| 6220 | |
| 6221 | case clang::Type::ObjCObjectPointer: |
| 6222 | return GetPointeeType(type).GetDirectBaseClassAtIndex(idx, bit_offset_ptr); |
| 6223 | |
| 6224 | case clang::Type::ObjCObject: |
| 6225 | if (idx == 0 && GetCompleteType(type)) { |
| 6226 | const clang::ObjCObjectType *objc_class_type = |
| 6227 | qual_type->getAsObjCQualifiedInterfaceType(); |
| 6228 | if (objc_class_type) { |
| 6229 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6230 | objc_class_type->getInterface(); |
| 6231 | |
| 6232 | if (class_interface_decl) { |
| 6233 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 6234 | class_interface_decl->getSuperClass(); |
| 6235 | if (superclass_interface_decl) { |
| 6236 | if (bit_offset_ptr) |
| 6237 | *bit_offset_ptr = 0; |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6238 | return CompilerType(this, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6239 | getASTContext()->getObjCInterfaceType( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6240 | superclass_interface_decl).getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6241 | } |
| 6242 | } |
| 6243 | } |
| 6244 | } |
| 6245 | break; |
| 6246 | case clang::Type::ObjCInterface: |
| 6247 | if (idx == 0 && GetCompleteType(type)) { |
| 6248 | const clang::ObjCObjectType *objc_interface_type = |
| 6249 | qual_type->getAs<clang::ObjCInterfaceType>(); |
| 6250 | if (objc_interface_type) { |
| 6251 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6252 | objc_interface_type->getInterface(); |
| 6253 | |
| 6254 | if (class_interface_decl) { |
| 6255 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 6256 | class_interface_decl->getSuperClass(); |
| 6257 | if (superclass_interface_decl) { |
| 6258 | if (bit_offset_ptr) |
| 6259 | *bit_offset_ptr = 0; |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6260 | return CompilerType( |
| 6261 | this, getASTContext() |
| 6262 | ->getObjCInterfaceType(superclass_interface_decl) |
| 6263 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6264 | } |
| 6265 | } |
| 6266 | } |
| 6267 | } |
| 6268 | break; |
| 6269 | |
| 6270 | case clang::Type::Typedef: |
| 6271 | return GetDirectBaseClassAtIndex(llvm::cast<clang::TypedefType>(qual_type) |
| 6272 | ->getDecl() |
| 6273 | ->getUnderlyingType() |
| 6274 | .getAsOpaquePtr(), |
| 6275 | idx, bit_offset_ptr); |
| 6276 | |
| 6277 | case clang::Type::Auto: |
| 6278 | return GetDirectBaseClassAtIndex(llvm::cast<clang::AutoType>(qual_type) |
| 6279 | ->getDeducedType() |
| 6280 | .getAsOpaquePtr(), |
| 6281 | idx, bit_offset_ptr); |
| 6282 | |
| 6283 | case clang::Type::Elaborated: |
| 6284 | return GetDirectBaseClassAtIndex( |
| 6285 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 6286 | ->getNamedType() |
| 6287 | .getAsOpaquePtr(), |
| 6288 | idx, bit_offset_ptr); |
| 6289 | |
| 6290 | case clang::Type::Paren: |
| 6291 | return GetDirectBaseClassAtIndex( |
| 6292 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 6293 | idx, bit_offset_ptr); |
| 6294 | |
| 6295 | default: |
| 6296 | break; |
| 6297 | } |
| 6298 | return CompilerType(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6299 | } |
| 6300 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6301 | CompilerType ClangASTContext::GetVirtualBaseClassAtIndex( |
| 6302 | lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) { |
| 6303 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6304 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6305 | switch (type_class) { |
| 6306 | case clang::Type::Record: |
| 6307 | if (GetCompleteType(type)) { |
| 6308 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6309 | qual_type->getAsCXXRecordDecl(); |
| 6310 | if (cxx_record_decl) { |
| 6311 | uint32_t curr_idx = 0; |
| 6312 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 6313 | base_class_end; |
| 6314 | for (base_class = cxx_record_decl->vbases_begin(), |
| 6315 | base_class_end = cxx_record_decl->vbases_end(); |
| 6316 | base_class != base_class_end; ++base_class, ++curr_idx) { |
| 6317 | if (curr_idx == idx) { |
| 6318 | if (bit_offset_ptr) { |
| 6319 | const clang::ASTRecordLayout &record_layout = |
| 6320 | getASTContext()->getASTRecordLayout(cxx_record_decl); |
| 6321 | const clang::CXXRecordDecl *base_class_decl = |
| 6322 | llvm::cast<clang::CXXRecordDecl>( |
| 6323 | base_class->getType() |
| 6324 | ->getAs<clang::RecordType>() |
| 6325 | ->getDecl()); |
| 6326 | *bit_offset_ptr = |
| 6327 | record_layout.getVBaseClassOffset(base_class_decl) |
| 6328 | .getQuantity() * |
| 6329 | 8; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6330 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6331 | return CompilerType(this, base_class->getType().getAsOpaquePtr()); |
| 6332 | } |
| 6333 | } |
| 6334 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6335 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6336 | break; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6337 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6338 | case clang::Type::Typedef: |
| 6339 | return GetVirtualBaseClassAtIndex(llvm::cast<clang::TypedefType>(qual_type) |
| 6340 | ->getDecl() |
| 6341 | ->getUnderlyingType() |
| 6342 | .getAsOpaquePtr(), |
| 6343 | idx, bit_offset_ptr); |
| 6344 | |
| 6345 | case clang::Type::Auto: |
| 6346 | return GetVirtualBaseClassAtIndex(llvm::cast<clang::AutoType>(qual_type) |
| 6347 | ->getDeducedType() |
| 6348 | .getAsOpaquePtr(), |
| 6349 | idx, bit_offset_ptr); |
| 6350 | |
| 6351 | case clang::Type::Elaborated: |
| 6352 | return GetVirtualBaseClassAtIndex( |
| 6353 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 6354 | ->getNamedType() |
| 6355 | .getAsOpaquePtr(), |
| 6356 | idx, bit_offset_ptr); |
| 6357 | |
| 6358 | case clang::Type::Paren: |
| 6359 | return GetVirtualBaseClassAtIndex( |
| 6360 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 6361 | idx, bit_offset_ptr); |
| 6362 | |
| 6363 | default: |
| 6364 | break; |
| 6365 | } |
| 6366 | return CompilerType(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6369 | // If a pointer to a pointee type (the clang_type arg) says that it has no |
| 6370 | // children, then we either need to trust it, or override it and return a |
| 6371 | // different result. For example, an "int *" has one child that is an integer, |
| 6372 | // but a function pointer doesn't have any children. Likewise if a Record type |
| 6373 | // claims it has no children, then there really is nothing to show. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6374 | uint32_t ClangASTContext::GetNumPointeeChildren(clang::QualType type) { |
| 6375 | if (type.isNull()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6376 | return 0; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6377 | |
| 6378 | clang::QualType qual_type(type.getCanonicalType()); |
| 6379 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6380 | switch (type_class) { |
| 6381 | case clang::Type::Builtin: |
| 6382 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 6383 | case clang::BuiltinType::UnknownAny: |
| 6384 | case clang::BuiltinType::Void: |
| 6385 | case clang::BuiltinType::NullPtr: |
| 6386 | case clang::BuiltinType::OCLEvent: |
| 6387 | case clang::BuiltinType::OCLImage1dRO: |
| 6388 | case clang::BuiltinType::OCLImage1dWO: |
| 6389 | case clang::BuiltinType::OCLImage1dRW: |
| 6390 | case clang::BuiltinType::OCLImage1dArrayRO: |
| 6391 | case clang::BuiltinType::OCLImage1dArrayWO: |
| 6392 | case clang::BuiltinType::OCLImage1dArrayRW: |
| 6393 | case clang::BuiltinType::OCLImage1dBufferRO: |
| 6394 | case clang::BuiltinType::OCLImage1dBufferWO: |
| 6395 | case clang::BuiltinType::OCLImage1dBufferRW: |
| 6396 | case clang::BuiltinType::OCLImage2dRO: |
| 6397 | case clang::BuiltinType::OCLImage2dWO: |
| 6398 | case clang::BuiltinType::OCLImage2dRW: |
| 6399 | case clang::BuiltinType::OCLImage2dArrayRO: |
| 6400 | case clang::BuiltinType::OCLImage2dArrayWO: |
| 6401 | case clang::BuiltinType::OCLImage2dArrayRW: |
| 6402 | case clang::BuiltinType::OCLImage3dRO: |
| 6403 | case clang::BuiltinType::OCLImage3dWO: |
| 6404 | case clang::BuiltinType::OCLImage3dRW: |
| 6405 | case clang::BuiltinType::OCLSampler: |
| 6406 | return 0; |
| 6407 | case clang::BuiltinType::Bool: |
| 6408 | case clang::BuiltinType::Char_U: |
| 6409 | case clang::BuiltinType::UChar: |
| 6410 | case clang::BuiltinType::WChar_U: |
| 6411 | case clang::BuiltinType::Char16: |
| 6412 | case clang::BuiltinType::Char32: |
| 6413 | case clang::BuiltinType::UShort: |
| 6414 | case clang::BuiltinType::UInt: |
| 6415 | case clang::BuiltinType::ULong: |
| 6416 | case clang::BuiltinType::ULongLong: |
| 6417 | case clang::BuiltinType::UInt128: |
| 6418 | case clang::BuiltinType::Char_S: |
| 6419 | case clang::BuiltinType::SChar: |
| 6420 | case clang::BuiltinType::WChar_S: |
| 6421 | case clang::BuiltinType::Short: |
| 6422 | case clang::BuiltinType::Int: |
| 6423 | case clang::BuiltinType::Long: |
| 6424 | case clang::BuiltinType::LongLong: |
| 6425 | case clang::BuiltinType::Int128: |
| 6426 | case clang::BuiltinType::Float: |
| 6427 | case clang::BuiltinType::Double: |
| 6428 | case clang::BuiltinType::LongDouble: |
| 6429 | case clang::BuiltinType::Dependent: |
| 6430 | case clang::BuiltinType::Overload: |
| 6431 | case clang::BuiltinType::ObjCId: |
| 6432 | case clang::BuiltinType::ObjCClass: |
| 6433 | case clang::BuiltinType::ObjCSel: |
| 6434 | case clang::BuiltinType::BoundMember: |
| 6435 | case clang::BuiltinType::Half: |
| 6436 | case clang::BuiltinType::ARCUnbridgedCast: |
| 6437 | case clang::BuiltinType::PseudoObject: |
| 6438 | case clang::BuiltinType::BuiltinFn: |
| 6439 | case clang::BuiltinType::OMPArraySection: |
| 6440 | return 1; |
| 6441 | default: |
| 6442 | return 0; |
| 6443 | } |
| 6444 | break; |
| 6445 | |
| 6446 | case clang::Type::Complex: |
| 6447 | return 1; |
| 6448 | case clang::Type::Pointer: |
| 6449 | return 1; |
| 6450 | case clang::Type::BlockPointer: |
| 6451 | return 0; // If block pointers don't have debug info, then no children for |
| 6452 | // them |
| 6453 | case clang::Type::LValueReference: |
| 6454 | return 1; |
| 6455 | case clang::Type::RValueReference: |
| 6456 | return 1; |
| 6457 | case clang::Type::MemberPointer: |
| 6458 | return 0; |
| 6459 | case clang::Type::ConstantArray: |
| 6460 | return 0; |
| 6461 | case clang::Type::IncompleteArray: |
| 6462 | return 0; |
| 6463 | case clang::Type::VariableArray: |
| 6464 | return 0; |
| 6465 | case clang::Type::DependentSizedArray: |
| 6466 | return 0; |
| 6467 | case clang::Type::DependentSizedExtVector: |
| 6468 | return 0; |
| 6469 | case clang::Type::Vector: |
| 6470 | return 0; |
| 6471 | case clang::Type::ExtVector: |
| 6472 | return 0; |
| 6473 | case clang::Type::FunctionProto: |
| 6474 | return 0; // When we function pointers, they have no children... |
| 6475 | case clang::Type::FunctionNoProto: |
| 6476 | return 0; // When we function pointers, they have no children... |
| 6477 | case clang::Type::UnresolvedUsing: |
| 6478 | return 0; |
| 6479 | case clang::Type::Paren: |
| 6480 | return GetNumPointeeChildren( |
| 6481 | llvm::cast<clang::ParenType>(qual_type)->desugar()); |
| 6482 | case clang::Type::Typedef: |
| 6483 | return GetNumPointeeChildren(llvm::cast<clang::TypedefType>(qual_type) |
| 6484 | ->getDecl() |
| 6485 | ->getUnderlyingType()); |
| 6486 | case clang::Type::Auto: |
| 6487 | return GetNumPointeeChildren( |
| 6488 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()); |
| 6489 | case clang::Type::Elaborated: |
| 6490 | return GetNumPointeeChildren( |
| 6491 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); |
| 6492 | case clang::Type::TypeOfExpr: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 6493 | return GetNumPointeeChildren(llvm::cast<clang::TypeOfExprType>(qual_type) |
| 6494 | ->getUnderlyingExpr() |
| 6495 | ->getType()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6496 | case clang::Type::TypeOf: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 6497 | return GetNumPointeeChildren( |
| 6498 | llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6499 | case clang::Type::Decltype: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 6500 | return GetNumPointeeChildren( |
| 6501 | llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6502 | case clang::Type::Record: |
| 6503 | return 0; |
| 6504 | case clang::Type::Enum: |
| 6505 | return 1; |
| 6506 | case clang::Type::TemplateTypeParm: |
| 6507 | return 1; |
| 6508 | case clang::Type::SubstTemplateTypeParm: |
| 6509 | return 1; |
| 6510 | case clang::Type::TemplateSpecialization: |
| 6511 | return 1; |
| 6512 | case clang::Type::InjectedClassName: |
| 6513 | return 0; |
| 6514 | case clang::Type::DependentName: |
| 6515 | return 1; |
| 6516 | case clang::Type::DependentTemplateSpecialization: |
| 6517 | return 1; |
| 6518 | case clang::Type::ObjCObject: |
| 6519 | return 0; |
| 6520 | case clang::Type::ObjCInterface: |
| 6521 | return 0; |
| 6522 | case clang::Type::ObjCObjectPointer: |
| 6523 | return 1; |
| 6524 | default: |
| 6525 | break; |
| 6526 | } |
| 6527 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6528 | } |
| 6529 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6530 | CompilerType ClangASTContext::GetChildCompilerTypeAtIndex( |
| 6531 | lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, |
| 6532 | bool transparent_pointers, bool omit_empty_base_classes, |
| 6533 | bool ignore_array_bounds, std::string &child_name, |
| 6534 | uint32_t &child_byte_size, int32_t &child_byte_offset, |
| 6535 | uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, |
| 6536 | bool &child_is_base_class, bool &child_is_deref_of_parent, |
| 6537 | ValueObject *valobj, uint64_t &language_flags) { |
| 6538 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6539 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6540 | |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 6541 | auto get_exe_scope = [&exe_ctx]() { |
| 6542 | return exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr; |
| 6543 | }; |
| 6544 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6545 | clang::QualType parent_qual_type(GetCanonicalQualType(type)); |
| 6546 | const clang::Type::TypeClass parent_type_class = |
| 6547 | parent_qual_type->getTypeClass(); |
| 6548 | child_bitfield_bit_size = 0; |
| 6549 | child_bitfield_bit_offset = 0; |
| 6550 | child_is_base_class = false; |
| 6551 | language_flags = 0; |
| 6552 | |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 6553 | const bool idx_is_valid = |
| 6554 | idx < GetNumChildren(type, omit_empty_base_classes, exe_ctx); |
Aleksandr Urakov | 7d2a74f | 2018-08-14 07:57:44 +0000 | [diff] [blame] | 6555 | int32_t bit_offset; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6556 | switch (parent_type_class) { |
| 6557 | case clang::Type::Builtin: |
| 6558 | if (idx_is_valid) { |
| 6559 | switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) { |
| 6560 | case clang::BuiltinType::ObjCId: |
| 6561 | case clang::BuiltinType::ObjCClass: |
| 6562 | child_name = "isa"; |
| 6563 | child_byte_size = |
| 6564 | getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) / |
| 6565 | CHAR_BIT; |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6566 | return CompilerType( |
| 6567 | this, getASTContext()->ObjCBuiltinClassTy.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6568 | |
| 6569 | default: |
| 6570 | break; |
| 6571 | } |
| 6572 | } |
| 6573 | break; |
| 6574 | |
| 6575 | case clang::Type::Record: |
| 6576 | if (idx_is_valid && GetCompleteType(type)) { |
| 6577 | const clang::RecordType *record_type = |
| 6578 | llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr()); |
| 6579 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 6580 | assert(record_decl); |
| 6581 | const clang::ASTRecordLayout &record_layout = |
| 6582 | getASTContext()->getASTRecordLayout(record_decl); |
| 6583 | uint32_t child_idx = 0; |
| 6584 | |
| 6585 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6586 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6587 | if (cxx_record_decl) { |
| 6588 | // We might have base classes to print out first |
| 6589 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 6590 | base_class_end; |
| 6591 | for (base_class = cxx_record_decl->bases_begin(), |
| 6592 | base_class_end = cxx_record_decl->bases_end(); |
| 6593 | base_class != base_class_end; ++base_class) { |
| 6594 | const clang::CXXRecordDecl *base_class_decl = nullptr; |
| 6595 | |
| 6596 | // Skip empty base classes |
| 6597 | if (omit_empty_base_classes) { |
| 6598 | base_class_decl = llvm::cast<clang::CXXRecordDecl>( |
| 6599 | base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 6600 | if (!ClangASTContext::RecordHasFields(base_class_decl)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6601 | continue; |
| 6602 | } |
| 6603 | |
| 6604 | if (idx == child_idx) { |
| 6605 | if (base_class_decl == nullptr) |
| 6606 | base_class_decl = llvm::cast<clang::CXXRecordDecl>( |
| 6607 | base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 6608 | |
| 6609 | if (base_class->isVirtual()) { |
| 6610 | bool handled = false; |
| 6611 | if (valobj) { |
Aleksandr Urakov | 1dc51db | 2018-11-12 16:23:50 +0000 | [diff] [blame] | 6612 | clang::VTableContextBase *vtable_ctx = |
| 6613 | getASTContext()->getVTableContext(); |
| 6614 | if (vtable_ctx) |
| 6615 | handled = GetVBaseBitOffset(*vtable_ctx, *valobj, |
| 6616 | record_layout, cxx_record_decl, |
| 6617 | base_class_decl, bit_offset); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6618 | } |
| 6619 | if (!handled) |
| 6620 | bit_offset = record_layout.getVBaseClassOffset(base_class_decl) |
| 6621 | .getQuantity() * |
| 6622 | 8; |
| 6623 | } else |
| 6624 | bit_offset = record_layout.getBaseClassOffset(base_class_decl) |
| 6625 | .getQuantity() * |
| 6626 | 8; |
| 6627 | |
| 6628 | // Base classes should be a multiple of 8 bits in size |
| 6629 | child_byte_offset = bit_offset / 8; |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6630 | CompilerType base_class_clang_type( |
| 6631 | this, base_class->getType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6632 | child_name = base_class_clang_type.GetTypeName().AsCString(""); |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 6633 | Optional<uint64_t> size = |
| 6634 | base_class_clang_type.GetBitSize(get_exe_scope()); |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 6635 | if (!size) |
| 6636 | return {}; |
| 6637 | uint64_t base_class_clang_type_bit_size = *size; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6638 | |
| 6639 | // Base classes bit sizes should be a multiple of 8 bits in size |
| 6640 | assert(base_class_clang_type_bit_size % 8 == 0); |
| 6641 | child_byte_size = base_class_clang_type_bit_size / 8; |
| 6642 | child_is_base_class = true; |
| 6643 | return base_class_clang_type; |
| 6644 | } |
| 6645 | // We don't increment the child index in the for loop since we might |
| 6646 | // be skipping empty base classes |
| 6647 | ++child_idx; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6648 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6649 | } |
| 6650 | // Make sure index is in range... |
| 6651 | uint32_t field_idx = 0; |
| 6652 | clang::RecordDecl::field_iterator field, field_end; |
| 6653 | for (field = record_decl->field_begin(), |
| 6654 | field_end = record_decl->field_end(); |
| 6655 | field != field_end; ++field, ++field_idx, ++child_idx) { |
| 6656 | if (idx == child_idx) { |
| 6657 | // Print the member type if requested |
| 6658 | // Print the member name and equal sign |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 6659 | child_name.assign(field->getNameAsString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6660 | |
| 6661 | // Figure out the type byte size (field_type_info.first) and |
| 6662 | // alignment (field_type_info.second) from the AST context. |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6663 | CompilerType field_clang_type(this, |
| 6664 | field->getType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6665 | assert(field_idx < record_layout.getFieldCount()); |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 6666 | Optional<uint64_t> size = |
| 6667 | field_clang_type.GetByteSize(get_exe_scope()); |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 6668 | if (!size) |
| 6669 | return {}; |
| 6670 | child_byte_size = *size; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6671 | const uint32_t child_bit_size = child_byte_size * 8; |
| 6672 | |
| 6673 | // Figure out the field offset within the current struct/union/class |
| 6674 | // type |
| 6675 | bit_offset = record_layout.getFieldOffset(field_idx); |
Raphael Isemann | 02e9113 | 2019-11-20 12:09:19 +0100 | [diff] [blame] | 6676 | if (FieldIsBitfield(*field, child_bitfield_bit_size)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6677 | child_bitfield_bit_offset = bit_offset % child_bit_size; |
| 6678 | const uint32_t child_bit_offset = |
| 6679 | bit_offset - child_bitfield_bit_offset; |
| 6680 | child_byte_offset = child_bit_offset / 8; |
| 6681 | } else { |
| 6682 | child_byte_offset = bit_offset / 8; |
| 6683 | } |
| 6684 | |
| 6685 | return field_clang_type; |
| 6686 | } |
| 6687 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6688 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6689 | break; |
| 6690 | |
| 6691 | case clang::Type::ObjCObject: |
| 6692 | case clang::Type::ObjCInterface: |
| 6693 | if (idx_is_valid && GetCompleteType(type)) { |
| 6694 | const clang::ObjCObjectType *objc_class_type = |
| 6695 | llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr()); |
| 6696 | assert(objc_class_type); |
| 6697 | if (objc_class_type) { |
| 6698 | uint32_t child_idx = 0; |
| 6699 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6700 | objc_class_type->getInterface(); |
| 6701 | |
| 6702 | if (class_interface_decl) { |
| 6703 | |
| 6704 | const clang::ASTRecordLayout &interface_layout = |
| 6705 | getASTContext()->getASTObjCInterfaceLayout(class_interface_decl); |
| 6706 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 6707 | class_interface_decl->getSuperClass(); |
| 6708 | if (superclass_interface_decl) { |
| 6709 | if (omit_empty_base_classes) { |
| 6710 | CompilerType base_class_clang_type( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6711 | this, getASTContext() |
| 6712 | ->getObjCInterfaceType(superclass_interface_decl) |
| 6713 | .getAsOpaquePtr()); |
Adrian Prantl | eca07c5 | 2018-11-05 20:49:07 +0000 | [diff] [blame] | 6714 | if (base_class_clang_type.GetNumChildren(omit_empty_base_classes, |
| 6715 | exe_ctx) > 0) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6716 | if (idx == 0) { |
| 6717 | clang::QualType ivar_qual_type( |
| 6718 | getASTContext()->getObjCInterfaceType( |
| 6719 | superclass_interface_decl)); |
| 6720 | |
| 6721 | child_name.assign( |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 6722 | superclass_interface_decl->getNameAsString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6723 | |
| 6724 | clang::TypeInfo ivar_type_info = |
| 6725 | getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 6726 | |
| 6727 | child_byte_size = ivar_type_info.Width / 8; |
| 6728 | child_byte_offset = 0; |
| 6729 | child_is_base_class = true; |
| 6730 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6731 | return CompilerType(this, ivar_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | ++child_idx; |
| 6735 | } |
| 6736 | } else |
| 6737 | ++child_idx; |
| 6738 | } |
| 6739 | |
| 6740 | const uint32_t superclass_idx = child_idx; |
| 6741 | |
| 6742 | if (idx < (child_idx + class_interface_decl->ivar_size())) { |
| 6743 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, |
| 6744 | ivar_end = class_interface_decl->ivar_end(); |
| 6745 | |
| 6746 | for (ivar_pos = class_interface_decl->ivar_begin(); |
| 6747 | ivar_pos != ivar_end; ++ivar_pos) { |
| 6748 | if (child_idx == idx) { |
| 6749 | clang::ObjCIvarDecl *ivar_decl = *ivar_pos; |
| 6750 | |
| 6751 | clang::QualType ivar_qual_type(ivar_decl->getType()); |
| 6752 | |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 6753 | child_name.assign(ivar_decl->getNameAsString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6754 | |
| 6755 | clang::TypeInfo ivar_type_info = |
| 6756 | getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 6757 | |
| 6758 | child_byte_size = ivar_type_info.Width / 8; |
| 6759 | |
| 6760 | // Figure out the field offset within the current |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 6761 | // struct/union/class type For ObjC objects, we can't trust the |
| 6762 | // bit offset we get from the Clang AST, since that doesn't |
| 6763 | // account for the space taken up by unbacked properties, or |
| 6764 | // from the changing size of base classes that are newer than |
| 6765 | // this class. So if we have a process around that we can ask |
| 6766 | // about this object, do so. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6767 | child_byte_offset = LLDB_INVALID_IVAR_OFFSET; |
| 6768 | Process *process = nullptr; |
| 6769 | if (exe_ctx) |
| 6770 | process = exe_ctx->GetProcessPtr(); |
| 6771 | if (process) { |
| 6772 | ObjCLanguageRuntime *objc_runtime = |
Alex Langford | e823bbe | 2019-06-10 20:53:23 +0000 | [diff] [blame] | 6773 | ObjCLanguageRuntime::Get(*process); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6774 | if (objc_runtime != nullptr) { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6775 | CompilerType parent_ast_type( |
| 6776 | this, parent_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6777 | child_byte_offset = objc_runtime->GetByteOffsetForIvar( |
| 6778 | parent_ast_type, ivar_decl->getNameAsString().c_str()); |
| 6779 | } |
| 6780 | } |
| 6781 | |
Aleksandr Urakov | ff70172 | 2018-08-20 05:59:27 +0000 | [diff] [blame] | 6782 | // Setting this to INT32_MAX to make sure we don't compute it |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6783 | // twice... |
Aleksandr Urakov | 5345948 | 2018-08-17 07:28:24 +0000 | [diff] [blame] | 6784 | bit_offset = INT32_MAX; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6785 | |
| 6786 | if (child_byte_offset == |
| 6787 | static_cast<int32_t>(LLDB_INVALID_IVAR_OFFSET)) { |
| 6788 | bit_offset = interface_layout.getFieldOffset(child_idx - |
| 6789 | superclass_idx); |
| 6790 | child_byte_offset = bit_offset / 8; |
| 6791 | } |
| 6792 | |
| 6793 | // Note, the ObjC Ivar Byte offset is just that, it doesn't |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 6794 | // account for the bit offset of a bitfield within its |
| 6795 | // containing object. So regardless of where we get the byte |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6796 | // offset from, we still need to get the bit offset for |
| 6797 | // bitfields from the layout. |
| 6798 | |
Raphael Isemann | 02e9113 | 2019-11-20 12:09:19 +0100 | [diff] [blame] | 6799 | if (FieldIsBitfield(ivar_decl, child_bitfield_bit_size)) { |
Aleksandr Urakov | 5345948 | 2018-08-17 07:28:24 +0000 | [diff] [blame] | 6800 | if (bit_offset == INT32_MAX) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6801 | bit_offset = interface_layout.getFieldOffset( |
| 6802 | child_idx - superclass_idx); |
| 6803 | |
| 6804 | child_bitfield_bit_offset = bit_offset % 8; |
| 6805 | } |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6806 | return CompilerType(this, ivar_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6807 | } |
| 6808 | ++child_idx; |
| 6809 | } |
| 6810 | } |
| 6811 | } |
| 6812 | } |
| 6813 | } |
| 6814 | break; |
| 6815 | |
| 6816 | case clang::Type::ObjCObjectPointer: |
| 6817 | if (idx_is_valid) { |
| 6818 | CompilerType pointee_clang_type(GetPointeeType(type)); |
| 6819 | |
| 6820 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) { |
| 6821 | child_is_deref_of_parent = false; |
| 6822 | bool tmp_child_is_deref_of_parent = false; |
| 6823 | return pointee_clang_type.GetChildCompilerTypeAtIndex( |
| 6824 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6825 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6826 | child_bitfield_bit_size, child_bitfield_bit_offset, |
| 6827 | child_is_base_class, tmp_child_is_deref_of_parent, valobj, |
| 6828 | language_flags); |
| 6829 | } else { |
| 6830 | child_is_deref_of_parent = true; |
| 6831 | const char *parent_name = |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 6832 | valobj ? valobj->GetName().GetCString() : nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6833 | if (parent_name) { |
| 6834 | child_name.assign(1, '*'); |
| 6835 | child_name += parent_name; |
| 6836 | } |
| 6837 | |
| 6838 | // We have a pointer to an simple type |
| 6839 | if (idx == 0 && pointee_clang_type.GetCompleteType()) { |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 6840 | if (Optional<uint64_t> size = |
| 6841 | pointee_clang_type.GetByteSize(get_exe_scope())) { |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 6842 | child_byte_size = *size; |
| 6843 | child_byte_offset = 0; |
| 6844 | return pointee_clang_type; |
| 6845 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6846 | } |
| 6847 | } |
| 6848 | } |
| 6849 | break; |
| 6850 | |
| 6851 | case clang::Type::Vector: |
| 6852 | case clang::Type::ExtVector: |
| 6853 | if (idx_is_valid) { |
| 6854 | const clang::VectorType *array = |
| 6855 | llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr()); |
| 6856 | if (array) { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6857 | CompilerType element_type(this, |
| 6858 | array->getElementType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6859 | if (element_type.GetCompleteType()) { |
| 6860 | char element_name[64]; |
| 6861 | ::snprintf(element_name, sizeof(element_name), "[%" PRIu64 "]", |
| 6862 | static_cast<uint64_t>(idx)); |
| 6863 | child_name.assign(element_name); |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 6864 | if (Optional<uint64_t> size = |
| 6865 | element_type.GetByteSize(get_exe_scope())) { |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 6866 | child_byte_size = *size; |
| 6867 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 6868 | return element_type; |
| 6869 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6870 | } |
| 6871 | } |
| 6872 | } |
| 6873 | break; |
| 6874 | |
| 6875 | case clang::Type::ConstantArray: |
| 6876 | case clang::Type::IncompleteArray: |
| 6877 | if (ignore_array_bounds || idx_is_valid) { |
| 6878 | const clang::ArrayType *array = GetQualType(type)->getAsArrayTypeUnsafe(); |
| 6879 | if (array) { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6880 | CompilerType element_type(this, |
| 6881 | array->getElementType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6882 | if (element_type.GetCompleteType()) { |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 6883 | child_name = llvm::formatv("[{0}]", idx); |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 6884 | if (Optional<uint64_t> size = |
| 6885 | element_type.GetByteSize(get_exe_scope())) { |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 6886 | child_byte_size = *size; |
| 6887 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 6888 | return element_type; |
| 6889 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6890 | } |
| 6891 | } |
| 6892 | } |
| 6893 | break; |
| 6894 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6895 | case clang::Type::Pointer: { |
| 6896 | CompilerType pointee_clang_type(GetPointeeType(type)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6897 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6898 | // Don't dereference "void *" pointers |
| 6899 | if (pointee_clang_type.IsVoidType()) |
| 6900 | return CompilerType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6901 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6902 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) { |
| 6903 | child_is_deref_of_parent = false; |
| 6904 | bool tmp_child_is_deref_of_parent = false; |
| 6905 | return pointee_clang_type.GetChildCompilerTypeAtIndex( |
| 6906 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6907 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6908 | child_bitfield_bit_size, child_bitfield_bit_offset, |
| 6909 | child_is_base_class, tmp_child_is_deref_of_parent, valobj, |
| 6910 | language_flags); |
| 6911 | } else { |
| 6912 | child_is_deref_of_parent = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6913 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6914 | const char *parent_name = |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 6915 | valobj ? valobj->GetName().GetCString() : nullptr; |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6916 | if (parent_name) { |
| 6917 | child_name.assign(1, '*'); |
| 6918 | child_name += parent_name; |
| 6919 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6920 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6921 | // We have a pointer to an simple type |
| 6922 | if (idx == 0) { |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 6923 | if (Optional<uint64_t> size = |
| 6924 | pointee_clang_type.GetByteSize(get_exe_scope())) { |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 6925 | child_byte_size = *size; |
| 6926 | child_byte_offset = 0; |
| 6927 | return pointee_clang_type; |
| 6928 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6929 | } |
| 6930 | } |
| 6931 | break; |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6932 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6933 | |
| 6934 | case clang::Type::LValueReference: |
| 6935 | case clang::Type::RValueReference: |
| 6936 | if (idx_is_valid) { |
| 6937 | const clang::ReferenceType *reference_type = |
| 6938 | llvm::cast<clang::ReferenceType>(parent_qual_type.getTypePtr()); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6939 | CompilerType pointee_clang_type( |
| 6940 | this, reference_type->getPointeeType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6941 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) { |
| 6942 | child_is_deref_of_parent = false; |
| 6943 | bool tmp_child_is_deref_of_parent = false; |
| 6944 | return pointee_clang_type.GetChildCompilerTypeAtIndex( |
| 6945 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6946 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6947 | child_bitfield_bit_size, child_bitfield_bit_offset, |
| 6948 | child_is_base_class, tmp_child_is_deref_of_parent, valobj, |
| 6949 | language_flags); |
| 6950 | } else { |
| 6951 | const char *parent_name = |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 6952 | valobj ? valobj->GetName().GetCString() : nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6953 | if (parent_name) { |
| 6954 | child_name.assign(1, '&'); |
| 6955 | child_name += parent_name; |
| 6956 | } |
| 6957 | |
| 6958 | // We have a pointer to an simple type |
| 6959 | if (idx == 0) { |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 6960 | if (Optional<uint64_t> size = |
| 6961 | pointee_clang_type.GetByteSize(get_exe_scope())) { |
Adrian Prantl | d963a7c | 2019-01-15 18:07:52 +0000 | [diff] [blame] | 6962 | child_byte_size = *size; |
| 6963 | child_byte_offset = 0; |
| 6964 | return pointee_clang_type; |
| 6965 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6966 | } |
| 6967 | } |
| 6968 | } |
| 6969 | break; |
| 6970 | |
| 6971 | case clang::Type::Typedef: { |
| 6972 | CompilerType typedefed_clang_type( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6973 | this, llvm::cast<clang::TypedefType>(parent_qual_type) |
| 6974 | ->getDecl() |
| 6975 | ->getUnderlyingType() |
| 6976 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6977 | return typedefed_clang_type.GetChildCompilerTypeAtIndex( |
| 6978 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6979 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6980 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 6981 | child_is_deref_of_parent, valobj, language_flags); |
| 6982 | } break; |
| 6983 | |
| 6984 | case clang::Type::Auto: { |
| 6985 | CompilerType elaborated_clang_type( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6986 | this, llvm::cast<clang::AutoType>(parent_qual_type) |
| 6987 | ->getDeducedType() |
| 6988 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6989 | return elaborated_clang_type.GetChildCompilerTypeAtIndex( |
| 6990 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6991 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6992 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 6993 | child_is_deref_of_parent, valobj, language_flags); |
| 6994 | } |
| 6995 | |
| 6996 | case clang::Type::Elaborated: { |
| 6997 | CompilerType elaborated_clang_type( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 6998 | this, llvm::cast<clang::ElaboratedType>(parent_qual_type) |
| 6999 | ->getNamedType() |
| 7000 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7001 | return elaborated_clang_type.GetChildCompilerTypeAtIndex( |
| 7002 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 7003 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 7004 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 7005 | child_is_deref_of_parent, valobj, language_flags); |
| 7006 | } |
| 7007 | |
| 7008 | case clang::Type::Paren: { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7009 | CompilerType paren_clang_type(this, |
| 7010 | llvm::cast<clang::ParenType>(parent_qual_type) |
| 7011 | ->desugar() |
| 7012 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7013 | return paren_clang_type.GetChildCompilerTypeAtIndex( |
| 7014 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 7015 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 7016 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 7017 | child_is_deref_of_parent, valobj, language_flags); |
| 7018 | } |
| 7019 | |
| 7020 | default: |
| 7021 | break; |
| 7022 | } |
| 7023 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7024 | } |
| 7025 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7026 | static uint32_t GetIndexForRecordBase(const clang::RecordDecl *record_decl, |
| 7027 | const clang::CXXBaseSpecifier *base_spec, |
| 7028 | bool omit_empty_base_classes) { |
| 7029 | uint32_t child_idx = 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7030 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7031 | const clang::CXXRecordDecl *cxx_record_decl = |
| 7032 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 7033 | |
| 7034 | // const char *super_name = record_decl->getNameAsCString(); |
| 7035 | // const char *base_name = |
| 7036 | // base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString(); |
| 7037 | // printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name); |
| 7038 | // |
| 7039 | if (cxx_record_decl) { |
| 7040 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 7041 | for (base_class = cxx_record_decl->bases_begin(), |
| 7042 | base_class_end = cxx_record_decl->bases_end(); |
| 7043 | base_class != base_class_end; ++base_class) { |
| 7044 | if (omit_empty_base_classes) { |
| 7045 | if (BaseSpecifierIsEmpty(base_class)) |
| 7046 | continue; |
| 7047 | } |
| 7048 | |
| 7049 | // printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", |
| 7050 | // super_name, base_name, |
| 7051 | // child_idx, |
| 7052 | // base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString()); |
| 7053 | // |
| 7054 | // |
| 7055 | if (base_class == base_spec) |
| 7056 | return child_idx; |
| 7057 | ++child_idx; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7058 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7059 | } |
| 7060 | |
| 7061 | return UINT32_MAX; |
| 7062 | } |
| 7063 | |
| 7064 | static uint32_t GetIndexForRecordChild(const clang::RecordDecl *record_decl, |
| 7065 | clang::NamedDecl *canonical_decl, |
| 7066 | bool omit_empty_base_classes) { |
| 7067 | uint32_t child_idx = ClangASTContext::GetNumBaseClasses( |
| 7068 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl), |
| 7069 | omit_empty_base_classes); |
| 7070 | |
| 7071 | clang::RecordDecl::field_iterator field, field_end; |
| 7072 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 7073 | field != field_end; ++field, ++child_idx) { |
| 7074 | if (field->getCanonicalDecl() == canonical_decl) |
| 7075 | return child_idx; |
| 7076 | } |
| 7077 | |
| 7078 | return UINT32_MAX; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7079 | } |
| 7080 | |
| 7081 | // Look for a child member (doesn't include base classes, but it does include |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 7082 | // their members) in the type hierarchy. Returns an index path into |
| 7083 | // "clang_type" on how to reach the appropriate member. |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7084 | // |
| 7085 | // class A |
| 7086 | // { |
| 7087 | // public: |
| 7088 | // int m_a; |
| 7089 | // int m_b; |
| 7090 | // }; |
| 7091 | // |
| 7092 | // class B |
| 7093 | // { |
| 7094 | // }; |
| 7095 | // |
| 7096 | // class C : |
| 7097 | // public B, |
| 7098 | // public A |
| 7099 | // { |
| 7100 | // }; |
| 7101 | // |
| 7102 | // If we have a clang type that describes "class C", and we wanted to looked |
| 7103 | // "m_b" in it: |
| 7104 | // |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7105 | // With omit_empty_base_classes == false we would get an integer array back |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 7106 | // with: { 1, 1 } The first index 1 is the child index for "class A" within |
| 7107 | // class C The second index 1 is the child index for "m_b" within class A |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7108 | // |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 7109 | // With omit_empty_base_classes == true we would get an integer array back |
| 7110 | // with: { 0, 1 } The first index 0 is the child index for "class A" within |
| 7111 | // class C (since class B doesn't have any members it doesn't count) The second |
| 7112 | // index 1 is the child index for "m_b" within class A |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7113 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7114 | size_t ClangASTContext::GetIndexOfChildMemberWithName( |
| 7115 | lldb::opaque_compiler_type_t type, const char *name, |
| 7116 | bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) { |
| 7117 | if (type && name && name[0]) { |
| 7118 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 7119 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7120 | switch (type_class) { |
| 7121 | case clang::Type::Record: |
| 7122 | if (GetCompleteType(type)) { |
| 7123 | const clang::RecordType *record_type = |
| 7124 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 7125 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 7126 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7127 | assert(record_decl); |
| 7128 | uint32_t child_idx = 0; |
| 7129 | |
| 7130 | const clang::CXXRecordDecl *cxx_record_decl = |
| 7131 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 7132 | |
| 7133 | // Try and find a field that matches NAME |
| 7134 | clang::RecordDecl::field_iterator field, field_end; |
| 7135 | llvm::StringRef name_sref(name); |
| 7136 | for (field = record_decl->field_begin(), |
| 7137 | field_end = record_decl->field_end(); |
| 7138 | field != field_end; ++field, ++child_idx) { |
| 7139 | llvm::StringRef field_name = field->getName(); |
| 7140 | if (field_name.empty()) { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7141 | CompilerType field_type(this, field->getType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7142 | child_indexes.push_back(child_idx); |
| 7143 | if (field_type.GetIndexOfChildMemberWithName( |
| 7144 | name, omit_empty_base_classes, child_indexes)) |
| 7145 | return child_indexes.size(); |
| 7146 | child_indexes.pop_back(); |
| 7147 | |
| 7148 | } else if (field_name.equals(name_sref)) { |
| 7149 | // We have to add on the number of base classes to this index! |
| 7150 | child_indexes.push_back( |
| 7151 | child_idx + ClangASTContext::GetNumBaseClasses( |
| 7152 | cxx_record_decl, omit_empty_base_classes)); |
| 7153 | return child_indexes.size(); |
| 7154 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7155 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7156 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7157 | if (cxx_record_decl) { |
| 7158 | const clang::RecordDecl *parent_record_decl = cxx_record_decl; |
| 7159 | |
| 7160 | // printf ("parent = %s\n", parent_record_decl->getNameAsCString()); |
| 7161 | |
| 7162 | // const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl(); |
| 7163 | // Didn't find things easily, lets let clang do its thang... |
| 7164 | clang::IdentifierInfo &ident_ref = |
| 7165 | getASTContext()->Idents.get(name_sref); |
| 7166 | clang::DeclarationName decl_name(&ident_ref); |
| 7167 | |
| 7168 | clang::CXXBasePaths paths; |
| 7169 | if (cxx_record_decl->lookupInBases( |
| 7170 | [decl_name](const clang::CXXBaseSpecifier *specifier, |
| 7171 | clang::CXXBasePath &path) { |
| 7172 | return clang::CXXRecordDecl::FindOrdinaryMember( |
| 7173 | specifier, path, decl_name); |
| 7174 | }, |
| 7175 | paths)) { |
| 7176 | clang::CXXBasePaths::const_paths_iterator path, |
| 7177 | path_end = paths.end(); |
| 7178 | for (path = paths.begin(); path != path_end; ++path) { |
| 7179 | const size_t num_path_elements = path->size(); |
| 7180 | for (size_t e = 0; e < num_path_elements; ++e) { |
| 7181 | clang::CXXBasePathElement elem = (*path)[e]; |
| 7182 | |
| 7183 | child_idx = GetIndexForRecordBase(parent_record_decl, elem.Base, |
| 7184 | omit_empty_base_classes); |
| 7185 | if (child_idx == UINT32_MAX) { |
| 7186 | child_indexes.clear(); |
| 7187 | return 0; |
| 7188 | } else { |
| 7189 | child_indexes.push_back(child_idx); |
| 7190 | parent_record_decl = llvm::cast<clang::RecordDecl>( |
| 7191 | elem.Base->getType() |
| 7192 | ->getAs<clang::RecordType>() |
| 7193 | ->getDecl()); |
| 7194 | } |
| 7195 | } |
| 7196 | for (clang::NamedDecl *path_decl : path->Decls) { |
| 7197 | child_idx = GetIndexForRecordChild( |
| 7198 | parent_record_decl, path_decl, omit_empty_base_classes); |
| 7199 | if (child_idx == UINT32_MAX) { |
| 7200 | child_indexes.clear(); |
| 7201 | return 0; |
| 7202 | } else { |
| 7203 | child_indexes.push_back(child_idx); |
| 7204 | } |
| 7205 | } |
| 7206 | } |
| 7207 | return child_indexes.size(); |
| 7208 | } |
| 7209 | } |
| 7210 | } |
| 7211 | break; |
| 7212 | |
| 7213 | case clang::Type::ObjCObject: |
| 7214 | case clang::Type::ObjCInterface: |
| 7215 | if (GetCompleteType(type)) { |
| 7216 | llvm::StringRef name_sref(name); |
| 7217 | const clang::ObjCObjectType *objc_class_type = |
| 7218 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 7219 | assert(objc_class_type); |
| 7220 | if (objc_class_type) { |
| 7221 | uint32_t child_idx = 0; |
| 7222 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 7223 | objc_class_type->getInterface(); |
| 7224 | |
| 7225 | if (class_interface_decl) { |
| 7226 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, |
| 7227 | ivar_end = class_interface_decl->ivar_end(); |
| 7228 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 7229 | class_interface_decl->getSuperClass(); |
| 7230 | |
| 7231 | for (ivar_pos = class_interface_decl->ivar_begin(); |
| 7232 | ivar_pos != ivar_end; ++ivar_pos, ++child_idx) { |
| 7233 | const clang::ObjCIvarDecl *ivar_decl = *ivar_pos; |
| 7234 | |
| 7235 | if (ivar_decl->getName().equals(name_sref)) { |
| 7236 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 7237 | (omit_empty_base_classes && |
| 7238 | ObjCDeclHasIVars(superclass_interface_decl, true))) |
| 7239 | ++child_idx; |
| 7240 | |
| 7241 | child_indexes.push_back(child_idx); |
| 7242 | return child_indexes.size(); |
| 7243 | } |
| 7244 | } |
| 7245 | |
| 7246 | if (superclass_interface_decl) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 7247 | // The super class index is always zero for ObjC classes, so we |
| 7248 | // push it onto the child indexes in case we find an ivar in our |
| 7249 | // superclass... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7250 | child_indexes.push_back(0); |
| 7251 | |
| 7252 | CompilerType superclass_clang_type( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7253 | this, getASTContext() |
| 7254 | ->getObjCInterfaceType(superclass_interface_decl) |
| 7255 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7256 | if (superclass_clang_type.GetIndexOfChildMemberWithName( |
| 7257 | name, omit_empty_base_classes, child_indexes)) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 7258 | // We did find an ivar in a superclass so just return the |
| 7259 | // results! |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7260 | return child_indexes.size(); |
| 7261 | } |
| 7262 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 7263 | // We didn't find an ivar matching "name" in our superclass, pop |
| 7264 | // the superclass zero index that we pushed on above. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7265 | child_indexes.pop_back(); |
| 7266 | } |
| 7267 | } |
| 7268 | } |
| 7269 | } |
| 7270 | break; |
| 7271 | |
| 7272 | case clang::Type::ObjCObjectPointer: { |
| 7273 | CompilerType objc_object_clang_type( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7274 | this, llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()) |
| 7275 | ->getPointeeType() |
| 7276 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7277 | return objc_object_clang_type.GetIndexOfChildMemberWithName( |
| 7278 | name, omit_empty_base_classes, child_indexes); |
| 7279 | } break; |
| 7280 | |
| 7281 | case clang::Type::ConstantArray: { |
| 7282 | // const clang::ConstantArrayType *array = |
| 7283 | // llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 7284 | // const uint64_t element_count = |
| 7285 | // array->getSize().getLimitedValue(); |
| 7286 | // |
| 7287 | // if (idx < element_count) |
| 7288 | // { |
| 7289 | // std::pair<uint64_t, unsigned> field_type_info = |
| 7290 | // ast->getTypeInfo(array->getElementType()); |
| 7291 | // |
| 7292 | // char element_name[32]; |
| 7293 | // ::snprintf (element_name, sizeof (element_name), |
| 7294 | // "%s[%u]", parent_name ? parent_name : "", idx); |
| 7295 | // |
| 7296 | // child_name.assign(element_name); |
| 7297 | // assert(field_type_info.first % 8 == 0); |
| 7298 | // child_byte_size = field_type_info.first / 8; |
| 7299 | // child_byte_offset = idx * child_byte_size; |
| 7300 | // return array->getElementType().getAsOpaquePtr(); |
| 7301 | // } |
| 7302 | } break; |
| 7303 | |
| 7304 | // case clang::Type::MemberPointerType: |
| 7305 | // { |
| 7306 | // MemberPointerType *mem_ptr_type = |
| 7307 | // llvm::cast<MemberPointerType>(qual_type.getTypePtr()); |
| 7308 | // clang::QualType pointee_type = |
| 7309 | // mem_ptr_type->getPointeeType(); |
| 7310 | // |
| 7311 | // if (ClangASTContext::IsAggregateType |
| 7312 | // (pointee_type.getAsOpaquePtr())) |
| 7313 | // { |
| 7314 | // return GetIndexOfChildWithName (ast, |
| 7315 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 7316 | // name); |
| 7317 | // } |
| 7318 | // } |
| 7319 | // break; |
| 7320 | // |
| 7321 | case clang::Type::LValueReference: |
| 7322 | case clang::Type::RValueReference: { |
| 7323 | const clang::ReferenceType *reference_type = |
| 7324 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 7325 | clang::QualType pointee_type(reference_type->getPointeeType()); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7326 | CompilerType pointee_clang_type(this, pointee_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7327 | |
| 7328 | if (pointee_clang_type.IsAggregateType()) { |
| 7329 | return pointee_clang_type.GetIndexOfChildMemberWithName( |
| 7330 | name, omit_empty_base_classes, child_indexes); |
| 7331 | } |
| 7332 | } break; |
| 7333 | |
| 7334 | case clang::Type::Pointer: { |
| 7335 | CompilerType pointee_clang_type(GetPointeeType(type)); |
| 7336 | |
| 7337 | if (pointee_clang_type.IsAggregateType()) { |
| 7338 | return pointee_clang_type.GetIndexOfChildMemberWithName( |
| 7339 | name, omit_empty_base_classes, child_indexes); |
| 7340 | } |
| 7341 | } break; |
| 7342 | |
| 7343 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7344 | return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 7345 | ->getDecl() |
| 7346 | ->getUnderlyingType() |
| 7347 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7348 | .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, |
| 7349 | child_indexes); |
| 7350 | |
| 7351 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7352 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 7353 | ->getDeducedType() |
| 7354 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7355 | .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, |
| 7356 | child_indexes); |
| 7357 | |
| 7358 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7359 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 7360 | ->getNamedType() |
| 7361 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7362 | .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, |
| 7363 | child_indexes); |
| 7364 | |
| 7365 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7366 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 7367 | ->desugar() |
| 7368 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7369 | .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, |
| 7370 | child_indexes); |
| 7371 | |
| 7372 | default: |
| 7373 | break; |
| 7374 | } |
| 7375 | } |
| 7376 | return 0; |
| 7377 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7378 | |
| 7379 | // Get the index of the child of "clang_type" whose name matches. This function |
| 7380 | // doesn't descend into the children, but only looks one level deep and name |
| 7381 | // matches can include base class names. |
| 7382 | |
| 7383 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7384 | ClangASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, |
| 7385 | const char *name, |
| 7386 | bool omit_empty_base_classes) { |
| 7387 | if (type && name && name[0]) { |
| 7388 | clang::QualType qual_type(GetCanonicalQualType(type)); |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 7389 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7390 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7391 | |
| 7392 | switch (type_class) { |
| 7393 | case clang::Type::Record: |
| 7394 | if (GetCompleteType(type)) { |
| 7395 | const clang::RecordType *record_type = |
| 7396 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 7397 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 7398 | |
| 7399 | assert(record_decl); |
| 7400 | uint32_t child_idx = 0; |
| 7401 | |
| 7402 | const clang::CXXRecordDecl *cxx_record_decl = |
| 7403 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 7404 | |
| 7405 | if (cxx_record_decl) { |
| 7406 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 7407 | base_class_end; |
| 7408 | for (base_class = cxx_record_decl->bases_begin(), |
| 7409 | base_class_end = cxx_record_decl->bases_end(); |
| 7410 | base_class != base_class_end; ++base_class) { |
| 7411 | // Skip empty base classes |
| 7412 | clang::CXXRecordDecl *base_class_decl = |
| 7413 | llvm::cast<clang::CXXRecordDecl>( |
| 7414 | base_class->getType() |
| 7415 | ->getAs<clang::RecordType>() |
| 7416 | ->getDecl()); |
| 7417 | if (omit_empty_base_classes && |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 7418 | !ClangASTContext::RecordHasFields(base_class_decl)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7419 | continue; |
| 7420 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7421 | CompilerType base_class_clang_type( |
| 7422 | this, base_class->getType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7423 | std::string base_class_type_name( |
| 7424 | base_class_clang_type.GetTypeName().AsCString("")); |
Jonas Devlieghere | 8d20cfd | 2018-12-21 22:46:10 +0000 | [diff] [blame] | 7425 | if (base_class_type_name == name) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7426 | return child_idx; |
| 7427 | ++child_idx; |
| 7428 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7429 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7430 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7431 | // Try and find a field that matches NAME |
| 7432 | clang::RecordDecl::field_iterator field, field_end; |
| 7433 | llvm::StringRef name_sref(name); |
| 7434 | for (field = record_decl->field_begin(), |
| 7435 | field_end = record_decl->field_end(); |
| 7436 | field != field_end; ++field, ++child_idx) { |
| 7437 | if (field->getName().equals(name_sref)) |
| 7438 | return child_idx; |
| 7439 | } |
| 7440 | } |
| 7441 | break; |
| 7442 | |
| 7443 | case clang::Type::ObjCObject: |
| 7444 | case clang::Type::ObjCInterface: |
| 7445 | if (GetCompleteType(type)) { |
| 7446 | llvm::StringRef name_sref(name); |
| 7447 | const clang::ObjCObjectType *objc_class_type = |
| 7448 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 7449 | assert(objc_class_type); |
| 7450 | if (objc_class_type) { |
| 7451 | uint32_t child_idx = 0; |
| 7452 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 7453 | objc_class_type->getInterface(); |
| 7454 | |
| 7455 | if (class_interface_decl) { |
| 7456 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, |
| 7457 | ivar_end = class_interface_decl->ivar_end(); |
| 7458 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 7459 | class_interface_decl->getSuperClass(); |
| 7460 | |
| 7461 | for (ivar_pos = class_interface_decl->ivar_begin(); |
| 7462 | ivar_pos != ivar_end; ++ivar_pos, ++child_idx) { |
| 7463 | const clang::ObjCIvarDecl *ivar_decl = *ivar_pos; |
| 7464 | |
| 7465 | if (ivar_decl->getName().equals(name_sref)) { |
| 7466 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 7467 | (omit_empty_base_classes && |
| 7468 | ObjCDeclHasIVars(superclass_interface_decl, true))) |
| 7469 | ++child_idx; |
| 7470 | |
| 7471 | return child_idx; |
| 7472 | } |
| 7473 | } |
| 7474 | |
| 7475 | if (superclass_interface_decl) { |
| 7476 | if (superclass_interface_decl->getName().equals(name_sref)) |
| 7477 | return 0; |
| 7478 | } |
| 7479 | } |
| 7480 | } |
| 7481 | } |
| 7482 | break; |
| 7483 | |
| 7484 | case clang::Type::ObjCObjectPointer: { |
| 7485 | CompilerType pointee_clang_type( |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7486 | this, llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()) |
| 7487 | ->getPointeeType() |
| 7488 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7489 | return pointee_clang_type.GetIndexOfChildWithName( |
| 7490 | name, omit_empty_base_classes); |
| 7491 | } break; |
| 7492 | |
| 7493 | case clang::Type::ConstantArray: { |
| 7494 | // const clang::ConstantArrayType *array = |
| 7495 | // llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 7496 | // const uint64_t element_count = |
| 7497 | // array->getSize().getLimitedValue(); |
| 7498 | // |
| 7499 | // if (idx < element_count) |
| 7500 | // { |
| 7501 | // std::pair<uint64_t, unsigned> field_type_info = |
| 7502 | // ast->getTypeInfo(array->getElementType()); |
| 7503 | // |
| 7504 | // char element_name[32]; |
| 7505 | // ::snprintf (element_name, sizeof (element_name), |
| 7506 | // "%s[%u]", parent_name ? parent_name : "", idx); |
| 7507 | // |
| 7508 | // child_name.assign(element_name); |
| 7509 | // assert(field_type_info.first % 8 == 0); |
| 7510 | // child_byte_size = field_type_info.first / 8; |
| 7511 | // child_byte_offset = idx * child_byte_size; |
| 7512 | // return array->getElementType().getAsOpaquePtr(); |
| 7513 | // } |
| 7514 | } break; |
| 7515 | |
| 7516 | // case clang::Type::MemberPointerType: |
| 7517 | // { |
| 7518 | // MemberPointerType *mem_ptr_type = |
| 7519 | // llvm::cast<MemberPointerType>(qual_type.getTypePtr()); |
| 7520 | // clang::QualType pointee_type = |
| 7521 | // mem_ptr_type->getPointeeType(); |
| 7522 | // |
| 7523 | // if (ClangASTContext::IsAggregateType |
| 7524 | // (pointee_type.getAsOpaquePtr())) |
| 7525 | // { |
| 7526 | // return GetIndexOfChildWithName (ast, |
| 7527 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 7528 | // name); |
| 7529 | // } |
| 7530 | // } |
| 7531 | // break; |
| 7532 | // |
| 7533 | case clang::Type::LValueReference: |
| 7534 | case clang::Type::RValueReference: { |
| 7535 | const clang::ReferenceType *reference_type = |
| 7536 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7537 | CompilerType pointee_type( |
| 7538 | this, reference_type->getPointeeType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7539 | |
| 7540 | if (pointee_type.IsAggregateType()) { |
| 7541 | return pointee_type.GetIndexOfChildWithName(name, |
| 7542 | omit_empty_base_classes); |
| 7543 | } |
| 7544 | } break; |
| 7545 | |
| 7546 | case clang::Type::Pointer: { |
| 7547 | const clang::PointerType *pointer_type = |
| 7548 | llvm::cast<clang::PointerType>(qual_type.getTypePtr()); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7549 | CompilerType pointee_type( |
| 7550 | this, pointer_type->getPointeeType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7551 | |
| 7552 | if (pointee_type.IsAggregateType()) { |
| 7553 | return pointee_type.GetIndexOfChildWithName(name, |
| 7554 | omit_empty_base_classes); |
| 7555 | } else { |
| 7556 | // if (parent_name) |
| 7557 | // { |
| 7558 | // child_name.assign(1, '*'); |
| 7559 | // child_name += parent_name; |
| 7560 | // } |
| 7561 | // |
| 7562 | // // We have a pointer to an simple type |
| 7563 | // if (idx == 0) |
| 7564 | // { |
| 7565 | // std::pair<uint64_t, unsigned> clang_type_info |
| 7566 | // = ast->getTypeInfo(pointee_type); |
| 7567 | // assert(clang_type_info.first % 8 == 0); |
| 7568 | // child_byte_size = clang_type_info.first / 8; |
| 7569 | // child_byte_offset = 0; |
| 7570 | // return pointee_type.getAsOpaquePtr(); |
| 7571 | // } |
| 7572 | } |
| 7573 | } break; |
| 7574 | |
| 7575 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7576 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 7577 | ->getDeducedType() |
| 7578 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7579 | .GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 7580 | |
| 7581 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7582 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 7583 | ->getNamedType() |
| 7584 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7585 | .GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 7586 | |
| 7587 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7588 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 7589 | ->desugar() |
| 7590 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7591 | .GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 7592 | |
| 7593 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7594 | return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 7595 | ->getDecl() |
| 7596 | ->getUnderlyingType() |
| 7597 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7598 | .GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 7599 | |
| 7600 | default: |
| 7601 | break; |
| 7602 | } |
| 7603 | } |
| 7604 | return UINT32_MAX; |
| 7605 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7606 | |
| 7607 | size_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7608 | ClangASTContext::GetNumTemplateArguments(lldb::opaque_compiler_type_t type) { |
| 7609 | if (!type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7610 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7611 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7612 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 7613 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7614 | switch (type_class) { |
| 7615 | case clang::Type::Record: |
| 7616 | if (GetCompleteType(type)) { |
| 7617 | const clang::CXXRecordDecl *cxx_record_decl = |
| 7618 | qual_type->getAsCXXRecordDecl(); |
| 7619 | if (cxx_record_decl) { |
| 7620 | const clang::ClassTemplateSpecializationDecl *template_decl = |
| 7621 | llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>( |
| 7622 | cxx_record_decl); |
| 7623 | if (template_decl) |
| 7624 | return template_decl->getTemplateArgs().size(); |
| 7625 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7626 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7627 | break; |
| 7628 | |
| 7629 | case clang::Type::Typedef: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7630 | return CompilerType(this, llvm::cast<clang::TypedefType>(qual_type) |
| 7631 | ->getDecl() |
| 7632 | ->getUnderlyingType() |
| 7633 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7634 | .GetNumTemplateArguments(); |
| 7635 | |
| 7636 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7637 | return CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 7638 | ->getDeducedType() |
| 7639 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7640 | .GetNumTemplateArguments(); |
| 7641 | |
| 7642 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7643 | return CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 7644 | ->getNamedType() |
| 7645 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7646 | .GetNumTemplateArguments(); |
| 7647 | |
| 7648 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7649 | return CompilerType(this, llvm::cast<clang::ParenType>(qual_type) |
| 7650 | ->desugar() |
| 7651 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7652 | .GetNumTemplateArguments(); |
| 7653 | |
| 7654 | default: |
| 7655 | break; |
| 7656 | } |
| 7657 | |
| 7658 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7659 | } |
| 7660 | |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7661 | const clang::ClassTemplateSpecializationDecl * |
| 7662 | ClangASTContext::GetAsTemplateSpecialization( |
| 7663 | lldb::opaque_compiler_type_t type) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7664 | if (!type) |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7665 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7666 | |
| 7667 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 7668 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7669 | switch (type_class) { |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7670 | case clang::Type::Record: { |
| 7671 | if (! GetCompleteType(type)) |
| 7672 | return nullptr; |
| 7673 | const clang::CXXRecordDecl *cxx_record_decl = |
| 7674 | qual_type->getAsCXXRecordDecl(); |
| 7675 | if (!cxx_record_decl) |
| 7676 | return nullptr; |
| 7677 | return llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>( |
| 7678 | cxx_record_decl); |
| 7679 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7680 | |
| 7681 | case clang::Type::Typedef: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7682 | return GetAsTemplateSpecialization(llvm::cast<clang::TypedefType>(qual_type) |
| 7683 | ->getDecl() |
| 7684 | ->getUnderlyingType() |
| 7685 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7686 | |
| 7687 | case clang::Type::Auto: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7688 | return GetAsTemplateSpecialization(llvm::cast<clang::AutoType>(qual_type) |
| 7689 | ->getDeducedType() |
| 7690 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7691 | |
| 7692 | case clang::Type::Elaborated: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7693 | return GetAsTemplateSpecialization( |
| 7694 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 7695 | ->getNamedType() |
| 7696 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7697 | |
| 7698 | case clang::Type::Paren: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7699 | return GetAsTemplateSpecialization( |
| 7700 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7701 | |
| 7702 | default: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7703 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7704 | } |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7705 | } |
| 7706 | |
| 7707 | lldb::TemplateArgumentKind |
| 7708 | ClangASTContext::GetTemplateArgumentKind(lldb::opaque_compiler_type_t type, |
| 7709 | size_t arg_idx) { |
| 7710 | const clang::ClassTemplateSpecializationDecl *template_decl = |
| 7711 | GetAsTemplateSpecialization(type); |
| 7712 | if (! template_decl || arg_idx >= template_decl->getTemplateArgs().size()) |
| 7713 | return eTemplateArgumentKindNull; |
| 7714 | |
| 7715 | switch (template_decl->getTemplateArgs()[arg_idx].getKind()) { |
| 7716 | case clang::TemplateArgument::Null: |
| 7717 | return eTemplateArgumentKindNull; |
| 7718 | |
| 7719 | case clang::TemplateArgument::NullPtr: |
| 7720 | return eTemplateArgumentKindNullPtr; |
| 7721 | |
| 7722 | case clang::TemplateArgument::Type: |
| 7723 | return eTemplateArgumentKindType; |
| 7724 | |
| 7725 | case clang::TemplateArgument::Declaration: |
| 7726 | return eTemplateArgumentKindDeclaration; |
| 7727 | |
| 7728 | case clang::TemplateArgument::Integral: |
| 7729 | return eTemplateArgumentKindIntegral; |
| 7730 | |
| 7731 | case clang::TemplateArgument::Template: |
| 7732 | return eTemplateArgumentKindTemplate; |
| 7733 | |
| 7734 | case clang::TemplateArgument::TemplateExpansion: |
| 7735 | return eTemplateArgumentKindTemplateExpansion; |
| 7736 | |
| 7737 | case clang::TemplateArgument::Expression: |
| 7738 | return eTemplateArgumentKindExpression; |
| 7739 | |
| 7740 | case clang::TemplateArgument::Pack: |
| 7741 | return eTemplateArgumentKindPack; |
| 7742 | } |
| 7743 | llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind"); |
| 7744 | } |
| 7745 | |
| 7746 | CompilerType |
| 7747 | ClangASTContext::GetTypeTemplateArgument(lldb::opaque_compiler_type_t type, |
| 7748 | size_t idx) { |
| 7749 | const clang::ClassTemplateSpecializationDecl *template_decl = |
| 7750 | GetAsTemplateSpecialization(type); |
| 7751 | if (!template_decl || idx >= template_decl->getTemplateArgs().size()) |
| 7752 | return CompilerType(); |
| 7753 | |
| 7754 | const clang::TemplateArgument &template_arg = |
| 7755 | template_decl->getTemplateArgs()[idx]; |
| 7756 | if (template_arg.getKind() != clang::TemplateArgument::Type) |
| 7757 | return CompilerType(); |
| 7758 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7759 | return CompilerType(this, template_arg.getAsType().getAsOpaquePtr()); |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7760 | } |
| 7761 | |
Adrian Prantl | 2f1fa7a | 2019-01-15 21:04:19 +0000 | [diff] [blame] | 7762 | Optional<CompilerType::IntegralTemplateArgument> |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7763 | ClangASTContext::GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type, |
| 7764 | size_t idx) { |
| 7765 | const clang::ClassTemplateSpecializationDecl *template_decl = |
| 7766 | GetAsTemplateSpecialization(type); |
| 7767 | if (! template_decl || idx >= template_decl->getTemplateArgs().size()) |
Pavel Labath | f59056f | 2017-11-30 10:16:54 +0000 | [diff] [blame] | 7768 | return llvm::None; |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7769 | |
| 7770 | const clang::TemplateArgument &template_arg = |
| 7771 | template_decl->getTemplateArgs()[idx]; |
| 7772 | if (template_arg.getKind() != clang::TemplateArgument::Integral) |
Pavel Labath | f59056f | 2017-11-30 10:16:54 +0000 | [diff] [blame] | 7773 | return llvm::None; |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7774 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 7775 | return { |
| 7776 | {template_arg.getAsIntegral(), |
| 7777 | CompilerType(this, template_arg.getIntegralType().getAsOpaquePtr())}}; |
Enrico Granata | c6bf2e2 | 2015-09-23 01:39:46 +0000 | [diff] [blame] | 7778 | } |
| 7779 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7780 | CompilerType ClangASTContext::GetTypeForFormatters(void *type) { |
| 7781 | if (type) |
| 7782 | return ClangUtil::RemoveFastQualifiers(CompilerType(this, type)); |
| 7783 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7784 | } |
| 7785 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7786 | clang::EnumDecl *ClangASTContext::GetAsEnumDecl(const CompilerType &type) { |
| 7787 | const clang::EnumType *enutype = |
| 7788 | llvm::dyn_cast<clang::EnumType>(ClangUtil::GetCanonicalQualType(type)); |
| 7789 | if (enutype) |
| 7790 | return enutype->getDecl(); |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 7791 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7792 | } |
| 7793 | |
| 7794 | clang::RecordDecl *ClangASTContext::GetAsRecordDecl(const CompilerType &type) { |
| 7795 | const clang::RecordType *record_type = |
| 7796 | llvm::dyn_cast<clang::RecordType>(ClangUtil::GetCanonicalQualType(type)); |
| 7797 | if (record_type) |
| 7798 | return record_type->getDecl(); |
| 7799 | return nullptr; |
| 7800 | } |
| 7801 | |
| 7802 | clang::TagDecl *ClangASTContext::GetAsTagDecl(const CompilerType &type) { |
Zachary Turner | 1639c6b | 2018-12-17 16:15:13 +0000 | [diff] [blame] | 7803 | return ClangUtil::GetAsTagDecl(type); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 7804 | } |
| 7805 | |
Aleksandr Urakov | 709426b | 2018-09-10 08:08:43 +0000 | [diff] [blame] | 7806 | clang::TypedefNameDecl * |
| 7807 | ClangASTContext::GetAsTypedefDecl(const CompilerType &type) { |
| 7808 | const clang::TypedefType *typedef_type = |
| 7809 | llvm::dyn_cast<clang::TypedefType>(ClangUtil::GetQualType(type)); |
| 7810 | if (typedef_type) |
| 7811 | return typedef_type->getDecl(); |
| 7812 | return nullptr; |
| 7813 | } |
| 7814 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7815 | clang::CXXRecordDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7816 | ClangASTContext::GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type) { |
| 7817 | return GetCanonicalQualType(type)->getAsCXXRecordDecl(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7818 | } |
| 7819 | |
| 7820 | clang::ObjCInterfaceDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7821 | ClangASTContext::GetAsObjCInterfaceDecl(const CompilerType &type) { |
| 7822 | const clang::ObjCObjectType *objc_class_type = |
| 7823 | llvm::dyn_cast<clang::ObjCObjectType>( |
| 7824 | ClangUtil::GetCanonicalQualType(type)); |
| 7825 | if (objc_class_type) |
| 7826 | return objc_class_type->getInterface(); |
| 7827 | return nullptr; |
| 7828 | } |
| 7829 | |
| 7830 | clang::FieldDecl *ClangASTContext::AddFieldToRecordType( |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 7831 | const CompilerType &type, llvm::StringRef name, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7832 | const CompilerType &field_clang_type, AccessType access, |
| 7833 | uint32_t bitfield_bit_size) { |
| 7834 | if (!type.IsValid() || !field_clang_type.IsValid()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7835 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7836 | ClangASTContext *ast = |
| 7837 | llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); |
| 7838 | if (!ast) |
| 7839 | return nullptr; |
| 7840 | clang::ASTContext *clang_ast = ast->getASTContext(); |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 7841 | clang::IdentifierInfo *ident = nullptr; |
| 7842 | if (!name.empty()) |
| 7843 | ident = &clang_ast->Idents.get(name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7844 | |
| 7845 | clang::FieldDecl *field = nullptr; |
| 7846 | |
| 7847 | clang::Expr *bit_width = nullptr; |
| 7848 | if (bitfield_bit_size != 0) { |
| 7849 | llvm::APInt bitfield_bit_size_apint( |
| 7850 | clang_ast->getTypeSize(clang_ast->IntTy), bitfield_bit_size); |
| 7851 | bit_width = new (*clang_ast) |
| 7852 | clang::IntegerLiteral(*clang_ast, bitfield_bit_size_apint, |
| 7853 | clang_ast->IntTy, clang::SourceLocation()); |
| 7854 | } |
| 7855 | |
| 7856 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); |
| 7857 | if (record_decl) { |
| 7858 | field = clang::FieldDecl::Create( |
| 7859 | *clang_ast, record_decl, clang::SourceLocation(), |
| 7860 | clang::SourceLocation(), |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 7861 | ident, // Identifier |
| 7862 | ClangUtil::GetQualType(field_clang_type), // Field type |
| 7863 | nullptr, // TInfo * |
| 7864 | bit_width, // BitWidth |
| 7865 | false, // Mutable |
| 7866 | clang::ICIS_NoInit); // HasInit |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7867 | |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 7868 | if (name.empty()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 7869 | // Determine whether this field corresponds to an anonymous struct or |
| 7870 | // union. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7871 | if (const clang::TagType *TagT = |
| 7872 | field->getType()->getAs<clang::TagType>()) { |
| 7873 | if (clang::RecordDecl *Rec = |
| 7874 | llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl())) |
| 7875 | if (!Rec->getDeclName()) { |
| 7876 | Rec->setAnonymousStructOrUnion(true); |
| 7877 | field->setImplicit(); |
| 7878 | } |
| 7879 | } |
| 7880 | } |
| 7881 | |
| 7882 | if (field) { |
| 7883 | field->setAccess( |
| 7884 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(access)); |
| 7885 | |
| 7886 | record_decl->addDecl(field); |
| 7887 | |
| 7888 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7889 | VerifyDecl(field); |
| 7890 | #endif |
| 7891 | } |
| 7892 | } else { |
| 7893 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 7894 | ast->GetAsObjCInterfaceDecl(type); |
| 7895 | |
| 7896 | if (class_interface_decl) { |
| 7897 | const bool is_synthesized = false; |
| 7898 | |
| 7899 | field_clang_type.GetCompleteType(); |
| 7900 | |
| 7901 | field = clang::ObjCIvarDecl::Create( |
| 7902 | *clang_ast, class_interface_decl, clang::SourceLocation(), |
| 7903 | clang::SourceLocation(), |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 7904 | ident, // Identifier |
| 7905 | ClangUtil::GetQualType(field_clang_type), // Field type |
| 7906 | nullptr, // TypeSourceInfo * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7907 | ConvertAccessTypeToObjCIvarAccessControl(access), bit_width, |
| 7908 | is_synthesized); |
| 7909 | |
| 7910 | if (field) { |
| 7911 | class_interface_decl->addDecl(field); |
| 7912 | |
| 7913 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7914 | VerifyDecl(field); |
| 7915 | #endif |
| 7916 | } |
| 7917 | } |
| 7918 | } |
| 7919 | return field; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7920 | } |
| 7921 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7922 | void ClangASTContext::BuildIndirectFields(const CompilerType &type) { |
| 7923 | if (!type) |
| 7924 | return; |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 7925 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7926 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 7927 | if (!ast) |
| 7928 | return; |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 7929 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7930 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 7931 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7932 | if (!record_decl) |
| 7933 | return; |
| 7934 | |
| 7935 | typedef llvm::SmallVector<clang::IndirectFieldDecl *, 1> IndirectFieldVector; |
| 7936 | |
| 7937 | IndirectFieldVector indirect_fields; |
| 7938 | clang::RecordDecl::field_iterator field_pos; |
| 7939 | clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end(); |
| 7940 | clang::RecordDecl::field_iterator last_field_pos = field_end_pos; |
| 7941 | for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; |
| 7942 | last_field_pos = field_pos++) { |
| 7943 | if (field_pos->isAnonymousStructOrUnion()) { |
| 7944 | clang::QualType field_qual_type = field_pos->getType(); |
| 7945 | |
| 7946 | const clang::RecordType *field_record_type = |
| 7947 | field_qual_type->getAs<clang::RecordType>(); |
| 7948 | |
| 7949 | if (!field_record_type) |
| 7950 | continue; |
| 7951 | |
| 7952 | clang::RecordDecl *field_record_decl = field_record_type->getDecl(); |
| 7953 | |
| 7954 | if (!field_record_decl) |
| 7955 | continue; |
| 7956 | |
| 7957 | for (clang::RecordDecl::decl_iterator |
| 7958 | di = field_record_decl->decls_begin(), |
| 7959 | de = field_record_decl->decls_end(); |
| 7960 | di != de; ++di) { |
| 7961 | if (clang::FieldDecl *nested_field_decl = |
| 7962 | llvm::dyn_cast<clang::FieldDecl>(*di)) { |
| 7963 | clang::NamedDecl **chain = |
| 7964 | new (*ast->getASTContext()) clang::NamedDecl *[2]; |
| 7965 | chain[0] = *field_pos; |
| 7966 | chain[1] = nested_field_decl; |
| 7967 | clang::IndirectFieldDecl *indirect_field = |
| 7968 | clang::IndirectFieldDecl::Create( |
| 7969 | *ast->getASTContext(), record_decl, clang::SourceLocation(), |
| 7970 | nested_field_decl->getIdentifier(), |
| 7971 | nested_field_decl->getType(), {chain, 2}); |
| 7972 | |
| 7973 | indirect_field->setImplicit(); |
| 7974 | |
| 7975 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers( |
| 7976 | field_pos->getAccess(), nested_field_decl->getAccess())); |
| 7977 | |
| 7978 | indirect_fields.push_back(indirect_field); |
| 7979 | } else if (clang::IndirectFieldDecl *nested_indirect_field_decl = |
| 7980 | llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) { |
| 7981 | size_t nested_chain_size = |
| 7982 | nested_indirect_field_decl->getChainingSize(); |
| 7983 | clang::NamedDecl **chain = new (*ast->getASTContext()) |
| 7984 | clang::NamedDecl *[nested_chain_size + 1]; |
| 7985 | chain[0] = *field_pos; |
| 7986 | |
| 7987 | int chain_index = 1; |
| 7988 | for (clang::IndirectFieldDecl::chain_iterator |
| 7989 | nci = nested_indirect_field_decl->chain_begin(), |
| 7990 | nce = nested_indirect_field_decl->chain_end(); |
| 7991 | nci < nce; ++nci) { |
| 7992 | chain[chain_index] = *nci; |
| 7993 | chain_index++; |
| 7994 | } |
| 7995 | |
| 7996 | clang::IndirectFieldDecl *indirect_field = |
| 7997 | clang::IndirectFieldDecl::Create( |
| 7998 | *ast->getASTContext(), record_decl, clang::SourceLocation(), |
| 7999 | nested_indirect_field_decl->getIdentifier(), |
| 8000 | nested_indirect_field_decl->getType(), |
| 8001 | {chain, nested_chain_size + 1}); |
| 8002 | |
| 8003 | indirect_field->setImplicit(); |
| 8004 | |
| 8005 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers( |
| 8006 | field_pos->getAccess(), nested_indirect_field_decl->getAccess())); |
| 8007 | |
| 8008 | indirect_fields.push_back(indirect_field); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8009 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8010 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8011 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8012 | } |
| 8013 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 8014 | // Check the last field to see if it has an incomplete array type as its last |
| 8015 | // member and if it does, the tell the record decl about it |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8016 | if (last_field_pos != field_end_pos) { |
| 8017 | if (last_field_pos->getType()->isIncompleteArrayType()) |
| 8018 | record_decl->hasFlexibleArrayMember(); |
| 8019 | } |
| 8020 | |
| 8021 | for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), |
| 8022 | ife = indirect_fields.end(); |
| 8023 | ifi < ife; ++ifi) { |
| 8024 | record_decl->addDecl(*ifi); |
| 8025 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8026 | } |
| 8027 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8028 | void ClangASTContext::SetIsPacked(const CompilerType &type) { |
| 8029 | if (type) { |
| 8030 | ClangASTContext *ast = |
| 8031 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8032 | if (ast) { |
| 8033 | clang::RecordDecl *record_decl = GetAsRecordDecl(type); |
| 8034 | |
| 8035 | if (!record_decl) |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8036 | return; |
| 8037 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8038 | record_decl->addAttr( |
| 8039 | clang::PackedAttr::CreateImplicit(*ast->getASTContext())); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8040 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8041 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8042 | } |
| 8043 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8044 | clang::VarDecl *ClangASTContext::AddVariableToRecordType( |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 8045 | const CompilerType &type, llvm::StringRef name, |
| 8046 | const CompilerType &var_type, AccessType access) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8047 | if (!type.IsValid() || !var_type.IsValid()) |
| 8048 | return nullptr; |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 8049 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8050 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8051 | if (!ast) |
| 8052 | return nullptr; |
| 8053 | |
| 8054 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 8055 | if (!record_decl) |
| 8056 | return nullptr; |
| 8057 | |
| 8058 | clang::VarDecl *var_decl = nullptr; |
| 8059 | clang::IdentifierInfo *ident = nullptr; |
| 8060 | if (!name.empty()) |
| 8061 | ident = &ast->getASTContext()->Idents.get(name); |
| 8062 | |
| 8063 | var_decl = clang::VarDecl::Create( |
| 8064 | *ast->getASTContext(), // ASTContext & |
| 8065 | record_decl, // DeclContext * |
| 8066 | clang::SourceLocation(), // clang::SourceLocation StartLoc |
| 8067 | clang::SourceLocation(), // clang::SourceLocation IdLoc |
| 8068 | ident, // clang::IdentifierInfo * |
| 8069 | ClangUtil::GetQualType(var_type), // Variable clang::QualType |
| 8070 | nullptr, // TypeSourceInfo * |
| 8071 | clang::SC_Static); // StorageClass |
| 8072 | if (!var_decl) |
| 8073 | return nullptr; |
| 8074 | |
| 8075 | var_decl->setAccess( |
| 8076 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(access)); |
| 8077 | record_decl->addDecl(var_decl); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8078 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8079 | #ifdef LLDB_CONFIGURATION_DEBUG |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 8080 | VerifyDecl(var_decl); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8081 | #endif |
Zachary Turner | a3e2ea1 | 2018-10-23 17:22:02 +0000 | [diff] [blame] | 8082 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8083 | return var_decl; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8084 | } |
| 8085 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8086 | clang::CXXMethodDecl *ClangASTContext::AddMethodToCXXRecordType( |
Davide Italiano | 675767a | 2018-03-27 19:40:50 +0000 | [diff] [blame] | 8087 | lldb::opaque_compiler_type_t type, const char *name, const char *mangled_name, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8088 | const CompilerType &method_clang_type, lldb::AccessType access, |
| 8089 | bool is_virtual, bool is_static, bool is_inline, bool is_explicit, |
| 8090 | bool is_attr_used, bool is_artificial) { |
| 8091 | if (!type || !method_clang_type.IsValid() || name == nullptr || |
| 8092 | name[0] == '\0') |
| 8093 | return nullptr; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8094 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8095 | clang::QualType record_qual_type(GetCanonicalQualType(type)); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 8096 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8097 | clang::CXXRecordDecl *cxx_record_decl = |
| 8098 | record_qual_type->getAsCXXRecordDecl(); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 8099 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8100 | if (cxx_record_decl == nullptr) |
| 8101 | return nullptr; |
| 8102 | |
| 8103 | clang::QualType method_qual_type(ClangUtil::GetQualType(method_clang_type)); |
| 8104 | |
| 8105 | clang::CXXMethodDecl *cxx_method_decl = nullptr; |
| 8106 | |
| 8107 | clang::DeclarationName decl_name(&getASTContext()->Idents.get(name)); |
| 8108 | |
| 8109 | const clang::FunctionType *function_type = |
| 8110 | llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr()); |
| 8111 | |
| 8112 | if (function_type == nullptr) |
| 8113 | return nullptr; |
| 8114 | |
| 8115 | const clang::FunctionProtoType *method_function_prototype( |
| 8116 | llvm::dyn_cast<clang::FunctionProtoType>(function_type)); |
| 8117 | |
| 8118 | if (!method_function_prototype) |
| 8119 | return nullptr; |
| 8120 | |
| 8121 | unsigned int num_params = method_function_prototype->getNumParams(); |
| 8122 | |
| 8123 | clang::CXXDestructorDecl *cxx_dtor_decl(nullptr); |
| 8124 | clang::CXXConstructorDecl *cxx_ctor_decl(nullptr); |
| 8125 | |
| 8126 | if (is_artificial) |
| 8127 | return nullptr; // skip everything artificial |
| 8128 | |
Richard Smith | 36851a6 | 2019-05-09 04:40:57 +0000 | [diff] [blame] | 8129 | const clang::ExplicitSpecifier explicit_spec( |
| 8130 | nullptr /*expr*/, is_explicit |
| 8131 | ? clang::ExplicitSpecKind::ResolvedTrue |
| 8132 | : clang::ExplicitSpecKind::ResolvedFalse); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8133 | if (name[0] == '~') { |
| 8134 | cxx_dtor_decl = clang::CXXDestructorDecl::Create( |
| 8135 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 8136 | clang::DeclarationNameInfo( |
| 8137 | getASTContext()->DeclarationNames.getCXXDestructorName( |
| 8138 | getASTContext()->getCanonicalType(record_qual_type)), |
| 8139 | clang::SourceLocation()), |
Raphael Isemann | 15695cd | 2019-09-23 06:59:35 +0000 | [diff] [blame] | 8140 | method_qual_type, nullptr, is_inline, is_artificial, |
| 8141 | ConstexprSpecKind::CSK_unspecified); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8142 | cxx_method_decl = cxx_dtor_decl; |
| 8143 | } else if (decl_name == cxx_record_decl->getDeclName()) { |
| 8144 | cxx_ctor_decl = clang::CXXConstructorDecl::Create( |
| 8145 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 8146 | clang::DeclarationNameInfo( |
| 8147 | getASTContext()->DeclarationNames.getCXXConstructorName( |
| 8148 | getASTContext()->getCanonicalType(record_qual_type)), |
| 8149 | clang::SourceLocation()), |
| 8150 | method_qual_type, |
| 8151 | nullptr, // TypeSourceInfo * |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 8152 | explicit_spec, is_inline, is_artificial, CSK_unspecified); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8153 | cxx_method_decl = cxx_ctor_decl; |
| 8154 | } else { |
| 8155 | clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None; |
| 8156 | clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS; |
| 8157 | |
| 8158 | if (IsOperator(name, op_kind)) { |
| 8159 | if (op_kind != clang::NUM_OVERLOADED_OPERATORS) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 8160 | // Check the number of operator parameters. Sometimes we have seen bad |
| 8161 | // DWARF that doesn't correctly describe operators and if we try to |
| 8162 | // create a method and add it to the class, clang will assert and |
| 8163 | // crash, so we need to make sure things are acceptable. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8164 | const bool is_method = true; |
| 8165 | if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount( |
| 8166 | is_method, op_kind, num_params)) |
| 8167 | return nullptr; |
| 8168 | cxx_method_decl = clang::CXXMethodDecl::Create( |
| 8169 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 8170 | clang::DeclarationNameInfo( |
| 8171 | getASTContext()->DeclarationNames.getCXXOperatorName(op_kind), |
| 8172 | clang::SourceLocation()), |
| 8173 | method_qual_type, |
| 8174 | nullptr, // TypeSourceInfo * |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 8175 | SC, is_inline, CSK_unspecified, clang::SourceLocation()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8176 | } else if (num_params == 0) { |
| 8177 | // Conversion operators don't take params... |
| 8178 | cxx_method_decl = clang::CXXConversionDecl::Create( |
| 8179 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 8180 | clang::DeclarationNameInfo( |
| 8181 | getASTContext()->DeclarationNames.getCXXConversionFunctionName( |
| 8182 | getASTContext()->getCanonicalType( |
| 8183 | function_type->getReturnType())), |
| 8184 | clang::SourceLocation()), |
| 8185 | method_qual_type, |
| 8186 | nullptr, // TypeSourceInfo * |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 8187 | is_inline, explicit_spec, CSK_unspecified, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8188 | clang::SourceLocation()); |
| 8189 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8190 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8191 | |
| 8192 | if (cxx_method_decl == nullptr) { |
| 8193 | cxx_method_decl = clang::CXXMethodDecl::Create( |
| 8194 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 8195 | clang::DeclarationNameInfo(decl_name, clang::SourceLocation()), |
| 8196 | method_qual_type, |
| 8197 | nullptr, // TypeSourceInfo * |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 8198 | SC, is_inline, CSK_unspecified, clang::SourceLocation()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8199 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8200 | } |
| 8201 | |
| 8202 | clang::AccessSpecifier access_specifier = |
| 8203 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(access); |
| 8204 | |
| 8205 | cxx_method_decl->setAccess(access_specifier); |
| 8206 | cxx_method_decl->setVirtualAsWritten(is_virtual); |
| 8207 | |
| 8208 | if (is_attr_used) |
| 8209 | cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext())); |
| 8210 | |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 8211 | if (mangled_name != nullptr) { |
Vedant Kumar | f6bc251 | 2019-09-25 18:00:31 +0000 | [diff] [blame] | 8212 | cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit( |
| 8213 | *getASTContext(), mangled_name, /*literal=*/false)); |
Davide Italiano | 675767a | 2018-03-27 19:40:50 +0000 | [diff] [blame] | 8214 | } |
| 8215 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8216 | // Populate the method decl with parameter decls |
| 8217 | |
| 8218 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; |
| 8219 | |
| 8220 | for (unsigned param_index = 0; param_index < num_params; ++param_index) { |
| 8221 | params.push_back(clang::ParmVarDecl::Create( |
| 8222 | *getASTContext(), cxx_method_decl, clang::SourceLocation(), |
| 8223 | clang::SourceLocation(), |
| 8224 | nullptr, // anonymous |
| 8225 | method_function_prototype->getParamType(param_index), nullptr, |
| 8226 | clang::SC_None, nullptr)); |
| 8227 | } |
| 8228 | |
| 8229 | cxx_method_decl->setParams(llvm::ArrayRef<clang::ParmVarDecl *>(params)); |
| 8230 | |
| 8231 | cxx_record_decl->addDecl(cxx_method_decl); |
| 8232 | |
| 8233 | // Sometimes the debug info will mention a constructor (default/copy/move), |
| 8234 | // destructor, or assignment operator (copy/move) but there won't be any |
| 8235 | // version of this in the code. So we check if the function was artificially |
| 8236 | // generated and if it is trivial and this lets the compiler/backend know |
| 8237 | // that it can inline the IR for these when it needs to and we can avoid a |
| 8238 | // "missing function" error when running expressions. |
| 8239 | |
| 8240 | if (is_artificial) { |
| 8241 | if (cxx_ctor_decl && ((cxx_ctor_decl->isDefaultConstructor() && |
| 8242 | cxx_record_decl->hasTrivialDefaultConstructor()) || |
| 8243 | (cxx_ctor_decl->isCopyConstructor() && |
| 8244 | cxx_record_decl->hasTrivialCopyConstructor()) || |
| 8245 | (cxx_ctor_decl->isMoveConstructor() && |
| 8246 | cxx_record_decl->hasTrivialMoveConstructor()))) { |
| 8247 | cxx_ctor_decl->setDefaulted(); |
| 8248 | cxx_ctor_decl->setTrivial(true); |
| 8249 | } else if (cxx_dtor_decl) { |
| 8250 | if (cxx_record_decl->hasTrivialDestructor()) { |
| 8251 | cxx_dtor_decl->setDefaulted(); |
| 8252 | cxx_dtor_decl->setTrivial(true); |
| 8253 | } |
| 8254 | } else if ((cxx_method_decl->isCopyAssignmentOperator() && |
| 8255 | cxx_record_decl->hasTrivialCopyAssignment()) || |
| 8256 | (cxx_method_decl->isMoveAssignmentOperator() && |
| 8257 | cxx_record_decl->hasTrivialMoveAssignment())) { |
| 8258 | cxx_method_decl->setDefaulted(); |
| 8259 | cxx_method_decl->setTrivial(true); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8260 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8261 | } |
| 8262 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8263 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8264 | VerifyDecl(cxx_method_decl); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8265 | #endif |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8266 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8267 | return cxx_method_decl; |
| 8268 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8269 | |
Aleksandr Urakov | 7d2a74f | 2018-08-14 07:57:44 +0000 | [diff] [blame] | 8270 | void ClangASTContext::AddMethodOverridesForCXXRecordType( |
| 8271 | lldb::opaque_compiler_type_t type) { |
| 8272 | if (auto *record = GetAsCXXRecordDecl(type)) |
| 8273 | for (auto *method : record->methods()) |
| 8274 | addOverridesForMethod(method); |
| 8275 | } |
| 8276 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8277 | #pragma mark C++ Base Classes |
| 8278 | |
Zachary Turner | 970f38e | 2018-10-25 20:44:56 +0000 | [diff] [blame] | 8279 | std::unique_ptr<clang::CXXBaseSpecifier> |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8280 | ClangASTContext::CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type, |
| 8281 | AccessType access, bool is_virtual, |
| 8282 | bool base_of_class) { |
Zachary Turner | 970f38e | 2018-10-25 20:44:56 +0000 | [diff] [blame] | 8283 | if (!type) |
| 8284 | return nullptr; |
| 8285 | |
Jonas Devlieghere | a8f3ae7 | 2019-08-14 22:19:23 +0000 | [diff] [blame] | 8286 | return std::make_unique<clang::CXXBaseSpecifier>( |
Zachary Turner | 970f38e | 2018-10-25 20:44:56 +0000 | [diff] [blame] | 8287 | clang::SourceRange(), is_virtual, base_of_class, |
| 8288 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(access), |
| 8289 | getASTContext()->getTrivialTypeSourceInfo(GetQualType(type)), |
| 8290 | clang::SourceLocation()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8291 | } |
| 8292 | |
Zachary Turner | 970f38e | 2018-10-25 20:44:56 +0000 | [diff] [blame] | 8293 | bool ClangASTContext::TransferBaseClasses( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8294 | lldb::opaque_compiler_type_t type, |
Zachary Turner | 970f38e | 2018-10-25 20:44:56 +0000 | [diff] [blame] | 8295 | std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases) { |
| 8296 | if (!type) |
| 8297 | return false; |
| 8298 | clang::CXXRecordDecl *cxx_record_decl = GetAsCXXRecordDecl(type); |
| 8299 | if (!cxx_record_decl) |
| 8300 | return false; |
| 8301 | std::vector<clang::CXXBaseSpecifier *> raw_bases; |
| 8302 | raw_bases.reserve(bases.size()); |
| 8303 | |
| 8304 | // Clang will make a copy of them, so it's ok that we pass pointers that we're |
| 8305 | // about to destroy. |
| 8306 | for (auto &b : bases) |
| 8307 | raw_bases.push_back(b.get()); |
| 8308 | cxx_record_decl->setBases(raw_bases.data(), raw_bases.size()); |
| 8309 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8310 | } |
| 8311 | |
| 8312 | bool ClangASTContext::SetObjCSuperClass( |
| 8313 | const CompilerType &type, const CompilerType &superclass_clang_type) { |
| 8314 | ClangASTContext *ast = |
| 8315 | llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); |
| 8316 | if (!ast) |
| 8317 | return false; |
| 8318 | clang::ASTContext *clang_ast = ast->getASTContext(); |
| 8319 | |
| 8320 | if (type && superclass_clang_type.IsValid() && |
| 8321 | superclass_clang_type.GetTypeSystem() == type.GetTypeSystem()) { |
| 8322 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 8323 | GetAsObjCInterfaceDecl(type); |
| 8324 | clang::ObjCInterfaceDecl *super_interface_decl = |
| 8325 | GetAsObjCInterfaceDecl(superclass_clang_type); |
| 8326 | if (class_interface_decl && super_interface_decl) { |
| 8327 | class_interface_decl->setSuperClass(clang_ast->getTrivialTypeSourceInfo( |
| 8328 | clang_ast->getObjCInterfaceType(super_interface_decl))); |
| 8329 | return true; |
| 8330 | } |
| 8331 | } |
| 8332 | return false; |
| 8333 | } |
| 8334 | |
| 8335 | bool ClangASTContext::AddObjCClassProperty( |
| 8336 | const CompilerType &type, const char *property_name, |
| 8337 | const CompilerType &property_clang_type, clang::ObjCIvarDecl *ivar_decl, |
| 8338 | const char *property_setter_name, const char *property_getter_name, |
| 8339 | uint32_t property_attributes, ClangASTMetadata *metadata) { |
| 8340 | if (!type || !property_clang_type.IsValid() || property_name == nullptr || |
| 8341 | property_name[0] == '\0') |
| 8342 | return false; |
| 8343 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8344 | if (!ast) |
| 8345 | return false; |
| 8346 | clang::ASTContext *clang_ast = ast->getASTContext(); |
| 8347 | |
| 8348 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); |
| 8349 | |
| 8350 | if (class_interface_decl) { |
| 8351 | CompilerType property_clang_type_to_access; |
| 8352 | |
| 8353 | if (property_clang_type.IsValid()) |
| 8354 | property_clang_type_to_access = property_clang_type; |
| 8355 | else if (ivar_decl) |
| 8356 | property_clang_type_to_access = |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 8357 | CompilerType(ast, ivar_decl->getType().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8358 | |
| 8359 | if (class_interface_decl && property_clang_type_to_access.IsValid()) { |
| 8360 | clang::TypeSourceInfo *prop_type_source; |
| 8361 | if (ivar_decl) |
| 8362 | prop_type_source = |
| 8363 | clang_ast->getTrivialTypeSourceInfo(ivar_decl->getType()); |
| 8364 | else |
| 8365 | prop_type_source = clang_ast->getTrivialTypeSourceInfo( |
| 8366 | ClangUtil::GetQualType(property_clang_type)); |
| 8367 | |
| 8368 | clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create( |
| 8369 | *clang_ast, class_interface_decl, |
| 8370 | clang::SourceLocation(), // Source Location |
| 8371 | &clang_ast->Idents.get(property_name), |
| 8372 | clang::SourceLocation(), // Source Location for AT |
| 8373 | clang::SourceLocation(), // Source location for ( |
| 8374 | ivar_decl ? ivar_decl->getType() |
| 8375 | : ClangUtil::GetQualType(property_clang_type), |
| 8376 | prop_type_source); |
| 8377 | |
| 8378 | if (property_decl) { |
| 8379 | if (metadata) |
| 8380 | ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata); |
| 8381 | |
| 8382 | class_interface_decl->addDecl(property_decl); |
| 8383 | |
| 8384 | clang::Selector setter_sel, getter_sel; |
| 8385 | |
| 8386 | if (property_setter_name != nullptr) { |
| 8387 | std::string property_setter_no_colon( |
| 8388 | property_setter_name, strlen(property_setter_name) - 1); |
| 8389 | clang::IdentifierInfo *setter_ident = |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 8390 | &clang_ast->Idents.get(property_setter_no_colon); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8391 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); |
| 8392 | } else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) { |
| 8393 | std::string setter_sel_string("set"); |
| 8394 | setter_sel_string.push_back(::toupper(property_name[0])); |
| 8395 | setter_sel_string.append(&property_name[1]); |
| 8396 | clang::IdentifierInfo *setter_ident = |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 8397 | &clang_ast->Idents.get(setter_sel_string); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8398 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); |
| 8399 | } |
| 8400 | property_decl->setSetterName(setter_sel); |
| 8401 | property_decl->setPropertyAttributes( |
| 8402 | clang::ObjCPropertyDecl::OBJC_PR_setter); |
| 8403 | |
| 8404 | if (property_getter_name != nullptr) { |
| 8405 | clang::IdentifierInfo *getter_ident = |
| 8406 | &clang_ast->Idents.get(property_getter_name); |
| 8407 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); |
| 8408 | } else { |
| 8409 | clang::IdentifierInfo *getter_ident = |
| 8410 | &clang_ast->Idents.get(property_name); |
| 8411 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); |
| 8412 | } |
| 8413 | property_decl->setGetterName(getter_sel); |
| 8414 | property_decl->setPropertyAttributes( |
| 8415 | clang::ObjCPropertyDecl::OBJC_PR_getter); |
| 8416 | |
| 8417 | if (ivar_decl) |
| 8418 | property_decl->setPropertyIvarDecl(ivar_decl); |
| 8419 | |
| 8420 | if (property_attributes & DW_APPLE_PROPERTY_readonly) |
| 8421 | property_decl->setPropertyAttributes( |
| 8422 | clang::ObjCPropertyDecl::OBJC_PR_readonly); |
| 8423 | if (property_attributes & DW_APPLE_PROPERTY_readwrite) |
| 8424 | property_decl->setPropertyAttributes( |
| 8425 | clang::ObjCPropertyDecl::OBJC_PR_readwrite); |
| 8426 | if (property_attributes & DW_APPLE_PROPERTY_assign) |
| 8427 | property_decl->setPropertyAttributes( |
| 8428 | clang::ObjCPropertyDecl::OBJC_PR_assign); |
| 8429 | if (property_attributes & DW_APPLE_PROPERTY_retain) |
| 8430 | property_decl->setPropertyAttributes( |
| 8431 | clang::ObjCPropertyDecl::OBJC_PR_retain); |
| 8432 | if (property_attributes & DW_APPLE_PROPERTY_copy) |
| 8433 | property_decl->setPropertyAttributes( |
| 8434 | clang::ObjCPropertyDecl::OBJC_PR_copy); |
| 8435 | if (property_attributes & DW_APPLE_PROPERTY_nonatomic) |
| 8436 | property_decl->setPropertyAttributes( |
| 8437 | clang::ObjCPropertyDecl::OBJC_PR_nonatomic); |
| 8438 | if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_nullability) |
| 8439 | property_decl->setPropertyAttributes( |
| 8440 | clang::ObjCPropertyDecl::OBJC_PR_nullability); |
| 8441 | if (property_attributes & |
| 8442 | clang::ObjCPropertyDecl::OBJC_PR_null_resettable) |
| 8443 | property_decl->setPropertyAttributes( |
| 8444 | clang::ObjCPropertyDecl::OBJC_PR_null_resettable); |
| 8445 | if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class) |
| 8446 | property_decl->setPropertyAttributes( |
| 8447 | clang::ObjCPropertyDecl::OBJC_PR_class); |
| 8448 | |
| 8449 | const bool isInstance = |
| 8450 | (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class) == 0; |
| 8451 | |
| 8452 | if (!getter_sel.isNull() && |
| 8453 | !(isInstance |
| 8454 | ? class_interface_decl->lookupInstanceMethod(getter_sel) |
| 8455 | : class_interface_decl->lookupClassMethod(getter_sel))) { |
| 8456 | const bool isVariadic = false; |
Adrian Prantl | 454acae | 2019-11-08 08:58:50 -0800 | [diff] [blame] | 8457 | const bool isPropertyAccessor = false; |
| 8458 | const bool isSynthesizedAccessorStub = false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8459 | const bool isImplicitlyDeclared = true; |
| 8460 | const bool isDefined = false; |
| 8461 | const clang::ObjCMethodDecl::ImplementationControl impControl = |
| 8462 | clang::ObjCMethodDecl::None; |
| 8463 | const bool HasRelatedResultType = false; |
| 8464 | |
| 8465 | clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create( |
| 8466 | *clang_ast, clang::SourceLocation(), clang::SourceLocation(), |
| 8467 | getter_sel, ClangUtil::GetQualType(property_clang_type_to_access), |
| 8468 | nullptr, class_interface_decl, isInstance, isVariadic, |
Adrian Prantl | 454acae | 2019-11-08 08:58:50 -0800 | [diff] [blame] | 8469 | isPropertyAccessor, isSynthesizedAccessorStub, |
| 8470 | isImplicitlyDeclared, isDefined, impControl, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8471 | HasRelatedResultType); |
| 8472 | |
| 8473 | if (getter && metadata) |
| 8474 | ClangASTContext::SetMetadata(clang_ast, getter, *metadata); |
| 8475 | |
| 8476 | if (getter) { |
| 8477 | getter->setMethodParams(*clang_ast, |
| 8478 | llvm::ArrayRef<clang::ParmVarDecl *>(), |
| 8479 | llvm::ArrayRef<clang::SourceLocation>()); |
| 8480 | |
| 8481 | class_interface_decl->addDecl(getter); |
| 8482 | } |
| 8483 | } |
| 8484 | |
| 8485 | if (!setter_sel.isNull() && |
| 8486 | !(isInstance |
| 8487 | ? class_interface_decl->lookupInstanceMethod(setter_sel) |
| 8488 | : class_interface_decl->lookupClassMethod(setter_sel))) { |
| 8489 | clang::QualType result_type = clang_ast->VoidTy; |
| 8490 | const bool isVariadic = false; |
Adrian Prantl | 454acae | 2019-11-08 08:58:50 -0800 | [diff] [blame] | 8491 | const bool isPropertyAccessor = true; |
| 8492 | const bool isSynthesizedAccessorStub = false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8493 | const bool isImplicitlyDeclared = true; |
| 8494 | const bool isDefined = false; |
| 8495 | const clang::ObjCMethodDecl::ImplementationControl impControl = |
| 8496 | clang::ObjCMethodDecl::None; |
| 8497 | const bool HasRelatedResultType = false; |
| 8498 | |
| 8499 | clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create( |
| 8500 | *clang_ast, clang::SourceLocation(), clang::SourceLocation(), |
| 8501 | setter_sel, result_type, nullptr, class_interface_decl, |
Adrian Prantl | 454acae | 2019-11-08 08:58:50 -0800 | [diff] [blame] | 8502 | isInstance, isVariadic, isPropertyAccessor, |
| 8503 | isSynthesizedAccessorStub, isImplicitlyDeclared, isDefined, |
| 8504 | impControl, HasRelatedResultType); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8505 | |
| 8506 | if (setter && metadata) |
| 8507 | ClangASTContext::SetMetadata(clang_ast, setter, *metadata); |
| 8508 | |
| 8509 | llvm::SmallVector<clang::ParmVarDecl *, 1> params; |
| 8510 | |
| 8511 | params.push_back(clang::ParmVarDecl::Create( |
| 8512 | *clang_ast, setter, clang::SourceLocation(), |
| 8513 | clang::SourceLocation(), |
| 8514 | nullptr, // anonymous |
| 8515 | ClangUtil::GetQualType(property_clang_type_to_access), nullptr, |
| 8516 | clang::SC_Auto, nullptr)); |
| 8517 | |
| 8518 | if (setter) { |
| 8519 | setter->setMethodParams( |
| 8520 | *clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(params), |
| 8521 | llvm::ArrayRef<clang::SourceLocation>()); |
| 8522 | |
| 8523 | class_interface_decl->addDecl(setter); |
| 8524 | } |
| 8525 | } |
| 8526 | |
| 8527 | return true; |
| 8528 | } |
| 8529 | } |
| 8530 | } |
| 8531 | return false; |
| 8532 | } |
| 8533 | |
| 8534 | bool ClangASTContext::IsObjCClassTypeAndHasIVars(const CompilerType &type, |
| 8535 | bool check_superclass) { |
| 8536 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); |
| 8537 | if (class_interface_decl) |
| 8538 | return ObjCDeclHasIVars(class_interface_decl, check_superclass); |
| 8539 | return false; |
| 8540 | } |
| 8541 | |
| 8542 | clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType( |
| 8543 | const CompilerType &type, |
| 8544 | const char *name, // the full symbol name as seen in the symbol table |
| 8545 | // (lldb::opaque_compiler_type_t type, "-[NString |
| 8546 | // stringWithCString:]") |
| 8547 | const CompilerType &method_clang_type, lldb::AccessType access, |
| 8548 | bool is_artificial, bool is_variadic) { |
| 8549 | if (!type || !method_clang_type.IsValid()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8550 | return nullptr; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8551 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8552 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); |
| 8553 | |
| 8554 | if (class_interface_decl == nullptr) |
| 8555 | return nullptr; |
| 8556 | ClangASTContext *lldb_ast = |
| 8557 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8558 | if (lldb_ast == nullptr) |
| 8559 | return nullptr; |
| 8560 | clang::ASTContext *ast = lldb_ast->getASTContext(); |
| 8561 | |
| 8562 | const char *selector_start = ::strchr(name, ' '); |
| 8563 | if (selector_start == nullptr) |
| 8564 | return nullptr; |
| 8565 | |
| 8566 | selector_start++; |
| 8567 | llvm::SmallVector<clang::IdentifierInfo *, 12> selector_idents; |
| 8568 | |
| 8569 | size_t len = 0; |
| 8570 | const char *start; |
| 8571 | // printf ("name = '%s'\n", name); |
| 8572 | |
| 8573 | unsigned num_selectors_with_args = 0; |
| 8574 | for (start = selector_start; start && *start != '\0' && *start != ']'; |
| 8575 | start += len) { |
| 8576 | len = ::strcspn(start, ":]"); |
| 8577 | bool has_arg = (start[len] == ':'); |
| 8578 | if (has_arg) |
| 8579 | ++num_selectors_with_args; |
| 8580 | selector_idents.push_back(&ast->Idents.get(llvm::StringRef(start, len))); |
| 8581 | if (has_arg) |
| 8582 | len += 1; |
| 8583 | } |
| 8584 | |
| 8585 | if (selector_idents.size() == 0) |
| 8586 | return nullptr; |
| 8587 | |
| 8588 | clang::Selector method_selector = ast->Selectors.getSelector( |
| 8589 | num_selectors_with_args ? selector_idents.size() : 0, |
| 8590 | selector_idents.data()); |
| 8591 | |
| 8592 | clang::QualType method_qual_type(ClangUtil::GetQualType(method_clang_type)); |
| 8593 | |
| 8594 | // Populate the method decl with parameter decls |
| 8595 | const clang::Type *method_type(method_qual_type.getTypePtr()); |
| 8596 | |
| 8597 | if (method_type == nullptr) |
| 8598 | return nullptr; |
| 8599 | |
| 8600 | const clang::FunctionProtoType *method_function_prototype( |
| 8601 | llvm::dyn_cast<clang::FunctionProtoType>(method_type)); |
| 8602 | |
| 8603 | if (!method_function_prototype) |
| 8604 | return nullptr; |
| 8605 | |
Adrian Prantl | 454acae | 2019-11-08 08:58:50 -0800 | [diff] [blame] | 8606 | const bool isInstance = (name[0] == '-'); |
Adrian Prantl | 8204d9f | 2019-11-08 09:52:58 -0800 | [diff] [blame] | 8607 | const bool isVariadic = is_variadic; |
Adrian Prantl | 454acae | 2019-11-08 08:58:50 -0800 | [diff] [blame] | 8608 | const bool isPropertyAccessor = false; |
| 8609 | const bool isSynthesizedAccessorStub = false; |
| 8610 | /// Force this to true because we don't have source locations. |
| 8611 | const bool isImplicitlyDeclared = true; |
| 8612 | const bool isDefined = false; |
| 8613 | const clang::ObjCMethodDecl::ImplementationControl impControl = |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8614 | clang::ObjCMethodDecl::None; |
Adrian Prantl | 454acae | 2019-11-08 08:58:50 -0800 | [diff] [blame] | 8615 | const bool HasRelatedResultType = false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8616 | |
| 8617 | const unsigned num_args = method_function_prototype->getNumParams(); |
| 8618 | |
| 8619 | if (num_args != num_selectors_with_args) |
| 8620 | return nullptr; // some debug information is corrupt. We are not going to |
| 8621 | // deal with it. |
| 8622 | |
| 8623 | clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create( |
| 8624 | *ast, |
| 8625 | clang::SourceLocation(), // beginLoc, |
| 8626 | clang::SourceLocation(), // endLoc, |
| 8627 | method_selector, method_function_prototype->getReturnType(), |
| 8628 | nullptr, // TypeSourceInfo *ResultTInfo, |
| 8629 | ClangASTContext::GetASTContext(ast)->GetDeclContextForType( |
| 8630 | ClangUtil::GetQualType(type)), |
Adrian Prantl | 454acae | 2019-11-08 08:58:50 -0800 | [diff] [blame] | 8631 | isInstance, isVariadic, isPropertyAccessor, isSynthesizedAccessorStub, |
| 8632 | isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8633 | |
| 8634 | if (objc_method_decl == nullptr) |
| 8635 | return nullptr; |
| 8636 | |
| 8637 | if (num_args > 0) { |
| 8638 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; |
| 8639 | |
| 8640 | for (unsigned param_index = 0; param_index < num_args; ++param_index) { |
| 8641 | params.push_back(clang::ParmVarDecl::Create( |
| 8642 | *ast, objc_method_decl, clang::SourceLocation(), |
| 8643 | clang::SourceLocation(), |
| 8644 | nullptr, // anonymous |
| 8645 | method_function_prototype->getParamType(param_index), nullptr, |
| 8646 | clang::SC_Auto, nullptr)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8647 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8648 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8649 | objc_method_decl->setMethodParams( |
| 8650 | *ast, llvm::ArrayRef<clang::ParmVarDecl *>(params), |
| 8651 | llvm::ArrayRef<clang::SourceLocation>()); |
| 8652 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8653 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8654 | class_interface_decl->addDecl(objc_method_decl); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8655 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8656 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8657 | VerifyDecl(objc_method_decl); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8658 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8659 | |
| 8660 | return objc_method_decl; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8661 | } |
| 8662 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8663 | bool ClangASTContext::SetHasExternalStorage(lldb::opaque_compiler_type_t type, |
| 8664 | bool has_extern) { |
| 8665 | if (!type) |
| 8666 | return false; |
| 8667 | |
| 8668 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 8669 | |
| 8670 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 8671 | switch (type_class) { |
| 8672 | case clang::Type::Record: { |
| 8673 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 8674 | if (cxx_record_decl) { |
| 8675 | cxx_record_decl->setHasExternalLexicalStorage(has_extern); |
| 8676 | cxx_record_decl->setHasExternalVisibleStorage(has_extern); |
| 8677 | return true; |
| 8678 | } |
| 8679 | } break; |
| 8680 | |
| 8681 | case clang::Type::Enum: { |
| 8682 | clang::EnumDecl *enum_decl = |
| 8683 | llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 8684 | if (enum_decl) { |
| 8685 | enum_decl->setHasExternalLexicalStorage(has_extern); |
| 8686 | enum_decl->setHasExternalVisibleStorage(has_extern); |
| 8687 | return true; |
| 8688 | } |
| 8689 | } break; |
| 8690 | |
| 8691 | case clang::Type::ObjCObject: |
| 8692 | case clang::Type::ObjCInterface: { |
| 8693 | const clang::ObjCObjectType *objc_class_type = |
| 8694 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 8695 | assert(objc_class_type); |
| 8696 | if (objc_class_type) { |
| 8697 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 8698 | objc_class_type->getInterface(); |
| 8699 | |
| 8700 | if (class_interface_decl) { |
| 8701 | class_interface_decl->setHasExternalLexicalStorage(has_extern); |
| 8702 | class_interface_decl->setHasExternalVisibleStorage(has_extern); |
| 8703 | return true; |
| 8704 | } |
| 8705 | } |
| 8706 | } break; |
| 8707 | |
| 8708 | case clang::Type::Typedef: |
| 8709 | return SetHasExternalStorage(llvm::cast<clang::TypedefType>(qual_type) |
| 8710 | ->getDecl() |
| 8711 | ->getUnderlyingType() |
| 8712 | .getAsOpaquePtr(), |
| 8713 | has_extern); |
| 8714 | |
| 8715 | case clang::Type::Auto: |
| 8716 | return SetHasExternalStorage(llvm::cast<clang::AutoType>(qual_type) |
| 8717 | ->getDeducedType() |
| 8718 | .getAsOpaquePtr(), |
| 8719 | has_extern); |
| 8720 | |
| 8721 | case clang::Type::Elaborated: |
| 8722 | return SetHasExternalStorage(llvm::cast<clang::ElaboratedType>(qual_type) |
| 8723 | ->getNamedType() |
| 8724 | .getAsOpaquePtr(), |
| 8725 | has_extern); |
| 8726 | |
| 8727 | case clang::Type::Paren: |
| 8728 | return SetHasExternalStorage( |
| 8729 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 8730 | has_extern); |
| 8731 | |
| 8732 | default: |
| 8733 | break; |
| 8734 | } |
| 8735 | return false; |
| 8736 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8737 | |
| 8738 | #pragma mark TagDecl |
| 8739 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8740 | bool ClangASTContext::StartTagDeclarationDefinition(const CompilerType &type) { |
| 8741 | clang::QualType qual_type(ClangUtil::GetQualType(type)); |
| 8742 | if (!qual_type.isNull()) { |
| 8743 | const clang::TagType *tag_type = qual_type->getAs<clang::TagType>(); |
| 8744 | if (tag_type) { |
| 8745 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8746 | if (tag_decl) { |
| 8747 | tag_decl->startDefinition(); |
| 8748 | return true; |
| 8749 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8750 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8751 | |
| 8752 | const clang::ObjCObjectType *object_type = |
| 8753 | qual_type->getAs<clang::ObjCObjectType>(); |
| 8754 | if (object_type) { |
| 8755 | clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface(); |
| 8756 | if (interface_decl) { |
| 8757 | interface_decl->startDefinition(); |
| 8758 | return true; |
| 8759 | } |
| 8760 | } |
| 8761 | } |
| 8762 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8763 | } |
| 8764 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8765 | bool ClangASTContext::CompleteTagDeclarationDefinition( |
| 8766 | const CompilerType &type) { |
| 8767 | clang::QualType qual_type(ClangUtil::GetQualType(type)); |
| 8768 | if (!qual_type.isNull()) { |
| 8769 | // Make sure we use the same methodology as |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 8770 | // ClangASTContext::StartTagDeclarationDefinition() as to how we start/end |
| 8771 | // the definition. Previously we were calling |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8772 | const clang::TagType *tag_type = qual_type->getAs<clang::TagType>(); |
| 8773 | if (tag_type) { |
| 8774 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8775 | if (tag_decl) { |
| 8776 | clang::CXXRecordDecl *cxx_record_decl = |
| 8777 | llvm::dyn_cast_or_null<clang::CXXRecordDecl>(tag_decl); |
| 8778 | |
| 8779 | if (cxx_record_decl) { |
| 8780 | if (!cxx_record_decl->isCompleteDefinition()) |
| 8781 | cxx_record_decl->completeDefinition(); |
| 8782 | cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true); |
| 8783 | cxx_record_decl->setHasExternalLexicalStorage(false); |
| 8784 | cxx_record_decl->setHasExternalVisibleStorage(false); |
| 8785 | return true; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8786 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8787 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8788 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8789 | |
| 8790 | const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>(); |
| 8791 | |
| 8792 | if (enutype) { |
| 8793 | clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8794 | |
| 8795 | if (enum_decl) { |
| 8796 | if (!enum_decl->isCompleteDefinition()) { |
| 8797 | ClangASTContext *lldb_ast = |
| 8798 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8799 | if (lldb_ast == nullptr) |
| 8800 | return false; |
| 8801 | clang::ASTContext *ast = lldb_ast->getASTContext(); |
| 8802 | |
| 8803 | /// TODO This really needs to be fixed. |
| 8804 | |
| 8805 | QualType integer_type(enum_decl->getIntegerType()); |
| 8806 | if (!integer_type.isNull()) { |
| 8807 | unsigned NumPositiveBits = 1; |
| 8808 | unsigned NumNegativeBits = 0; |
| 8809 | |
| 8810 | clang::QualType promotion_qual_type; |
| 8811 | // If the enum integer type is less than an integer in bit width, |
| 8812 | // then we must promote it to an integer size. |
| 8813 | if (ast->getTypeSize(enum_decl->getIntegerType()) < |
| 8814 | ast->getTypeSize(ast->IntTy)) { |
| 8815 | if (enum_decl->getIntegerType()->isSignedIntegerType()) |
| 8816 | promotion_qual_type = ast->IntTy; |
| 8817 | else |
| 8818 | promotion_qual_type = ast->UnsignedIntTy; |
| 8819 | } else |
| 8820 | promotion_qual_type = enum_decl->getIntegerType(); |
| 8821 | |
| 8822 | enum_decl->completeDefinition(enum_decl->getIntegerType(), |
| 8823 | promotion_qual_type, NumPositiveBits, |
| 8824 | NumNegativeBits); |
| 8825 | } |
| 8826 | } |
| 8827 | return true; |
| 8828 | } |
| 8829 | } |
| 8830 | } |
| 8831 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8832 | } |
| 8833 | |
Aleksandr Urakov | 709426b | 2018-09-10 08:08:43 +0000 | [diff] [blame] | 8834 | clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType( |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8835 | const CompilerType &enum_type, const Declaration &decl, const char *name, |
Zachary Turner | 1639c6b | 2018-12-17 16:15:13 +0000 | [diff] [blame] | 8836 | const llvm::APSInt &value) { |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 8837 | |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8838 | if (!enum_type || ConstString(name).IsEmpty()) |
| 8839 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8840 | |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8841 | lldbassert(enum_type.GetTypeSystem() == static_cast<TypeSystem *>(this)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8842 | |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8843 | lldb::opaque_compiler_type_t enum_opaque_compiler_type = |
| 8844 | enum_type.GetOpaqueQualType(); |
| 8845 | |
| 8846 | if (!enum_opaque_compiler_type) |
| 8847 | return nullptr; |
| 8848 | |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8849 | clang::QualType enum_qual_type( |
| 8850 | GetCanonicalQualType(enum_opaque_compiler_type)); |
| 8851 | |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8852 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
| 8853 | |
| 8854 | if (!clang_type) |
| 8855 | return nullptr; |
| 8856 | |
| 8857 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type); |
| 8858 | |
| 8859 | if (!enutype) |
| 8860 | return nullptr; |
| 8861 | |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8862 | clang::EnumConstantDecl *enumerator_decl = clang::EnumConstantDecl::Create( |
| 8863 | *getASTContext(), enutype->getDecl(), clang::SourceLocation(), |
| 8864 | name ? &getASTContext()->Idents.get(name) : nullptr, // Identifier |
Zachary Turner | 1639c6b | 2018-12-17 16:15:13 +0000 | [diff] [blame] | 8865 | clang::QualType(enutype, 0), nullptr, value); |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8866 | |
| 8867 | if (!enumerator_decl) |
| 8868 | return nullptr; |
| 8869 | |
| 8870 | enutype->getDecl()->addDecl(enumerator_decl); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8871 | |
| 8872 | #ifdef LLDB_CONFIGURATION_DEBUG |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8873 | VerifyDecl(enumerator_decl); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8874 | #endif |
| 8875 | |
Shafik Yaghmour | 8c5ec1f | 2018-11-08 18:42:00 +0000 | [diff] [blame] | 8876 | return enumerator_decl; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8877 | } |
| 8878 | |
Zachary Turner | 1639c6b | 2018-12-17 16:15:13 +0000 | [diff] [blame] | 8879 | clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType( |
| 8880 | const CompilerType &enum_type, const Declaration &decl, const char *name, |
| 8881 | int64_t enum_value, uint32_t enum_value_bit_size) { |
| 8882 | CompilerType underlying_type = |
| 8883 | GetEnumerationIntegerType(enum_type.GetOpaqueQualType()); |
| 8884 | bool is_signed = false; |
| 8885 | underlying_type.IsIntegerType(is_signed); |
| 8886 | |
| 8887 | llvm::APSInt value(enum_value_bit_size, is_signed); |
| 8888 | value = enum_value; |
| 8889 | |
| 8890 | return AddEnumerationValueToEnumerationType(enum_type, decl, name, value); |
| 8891 | } |
| 8892 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8893 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8894 | ClangASTContext::GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) { |
| 8895 | clang::QualType enum_qual_type(GetCanonicalQualType(type)); |
| 8896 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
| 8897 | if (clang_type) { |
| 8898 | const clang::EnumType *enutype = |
| 8899 | llvm::dyn_cast<clang::EnumType>(clang_type); |
| 8900 | if (enutype) { |
| 8901 | clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8902 | if (enum_decl) |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 8903 | return CompilerType(this, enum_decl->getIntegerType().getAsOpaquePtr()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8904 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8905 | } |
| 8906 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8907 | } |
| 8908 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8909 | CompilerType |
| 8910 | ClangASTContext::CreateMemberPointerType(const CompilerType &type, |
| 8911 | const CompilerType &pointee_type) { |
| 8912 | if (type && pointee_type.IsValid() && |
| 8913 | type.GetTypeSystem() == pointee_type.GetTypeSystem()) { |
| 8914 | ClangASTContext *ast = |
| 8915 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8916 | if (!ast) |
| 8917 | return CompilerType(); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 8918 | return CompilerType(ast, ast->getASTContext() |
| 8919 | ->getMemberPointerType( |
| 8920 | ClangUtil::GetQualType(pointee_type), |
| 8921 | ClangUtil::GetQualType(type).getTypePtr()) |
| 8922 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8923 | } |
| 8924 | return CompilerType(); |
| 8925 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8926 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8927 | // Dumping types |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8928 | #define DEPTH_INCREMENT 2 |
| 8929 | |
Adrian Prantl | 0c72a42 | 2019-03-07 20:20:02 +0000 | [diff] [blame] | 8930 | #ifndef NDEBUG |
| 8931 | LLVM_DUMP_METHOD void |
| 8932 | ClangASTContext::dump(lldb::opaque_compiler_type_t type) const { |
| 8933 | if (!type) |
| 8934 | return; |
| 8935 | clang::QualType qual_type(GetQualType(type)); |
| 8936 | qual_type.dump(); |
| 8937 | } |
| 8938 | #endif |
| 8939 | |
Zachary Turner | 4911023 | 2018-11-05 17:40:28 +0000 | [diff] [blame] | 8940 | void ClangASTContext::Dump(Stream &s) { |
Zachary Turner | 115209e | 2018-11-05 19:25:39 +0000 | [diff] [blame] | 8941 | Decl *tu = Decl::castFromDeclContext(GetTranslationUnitDecl()); |
Zachary Turner | 4911023 | 2018-11-05 17:40:28 +0000 | [diff] [blame] | 8942 | tu->dump(s.AsRawOstream()); |
| 8943 | } |
| 8944 | |
Shafik Yaghmour | 5f46982 | 2019-10-11 16:36:20 +0000 | [diff] [blame] | 8945 | void ClangASTContext::DumpFromSymbolFile(Stream &s, |
| 8946 | llvm::StringRef symbol_name) { |
| 8947 | SymbolFile *symfile = GetSymbolFile(); |
| 8948 | |
| 8949 | if (!symfile) |
| 8950 | return; |
| 8951 | |
| 8952 | lldb_private::TypeList type_list; |
| 8953 | symfile->GetTypes(nullptr, eTypeClassAny, type_list); |
| 8954 | size_t ntypes = type_list.GetSize(); |
| 8955 | |
| 8956 | for (size_t i = 0; i < ntypes; ++i) { |
| 8957 | TypeSP type = type_list.GetTypeAtIndex(i); |
| 8958 | |
| 8959 | if (!symbol_name.empty()) |
shafik | de2c7ca | 2019-10-28 14:26:54 -0700 | [diff] [blame] | 8960 | if (symbol_name != type->GetName().GetStringRef()) |
Shafik Yaghmour | 5f46982 | 2019-10-11 16:36:20 +0000 | [diff] [blame] | 8961 | continue; |
| 8962 | |
| 8963 | s << type->GetName().AsCString() << "\n"; |
| 8964 | |
| 8965 | if (clang::TagDecl *tag_decl = |
| 8966 | GetAsTagDecl(type->GetFullCompilerType())) |
| 8967 | tag_decl->dump(s.AsRawOstream()); |
| 8968 | else if (clang::TypedefNameDecl *typedef_decl = |
| 8969 | GetAsTypedefDecl(type->GetFullCompilerType())) |
| 8970 | typedef_decl->dump(s.AsRawOstream()); |
| 8971 | else { |
| 8972 | GetCanonicalQualType(type->GetFullCompilerType().GetOpaqueQualType()) |
| 8973 | .dump(s.AsRawOstream()); |
| 8974 | } |
| 8975 | } |
| 8976 | } |
| 8977 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8978 | void ClangASTContext::DumpValue( |
| 8979 | lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream *s, |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 8980 | lldb::Format format, const DataExtractor &data, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8981 | lldb::offset_t data_byte_offset, size_t data_byte_size, |
| 8982 | uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types, |
| 8983 | bool show_summary, bool verbose, uint32_t depth) { |
| 8984 | if (!type) |
| 8985 | return; |
| 8986 | |
| 8987 | clang::QualType qual_type(GetQualType(type)); |
| 8988 | switch (qual_type->getTypeClass()) { |
| 8989 | case clang::Type::Record: |
| 8990 | if (GetCompleteType(type)) { |
| 8991 | const clang::RecordType *record_type = |
| 8992 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 8993 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 8994 | assert(record_decl); |
| 8995 | uint32_t field_bit_offset = 0; |
| 8996 | uint32_t field_byte_offset = 0; |
| 8997 | const clang::ASTRecordLayout &record_layout = |
| 8998 | getASTContext()->getASTRecordLayout(record_decl); |
| 8999 | uint32_t child_idx = 0; |
| 9000 | |
| 9001 | const clang::CXXRecordDecl *cxx_record_decl = |
| 9002 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 9003 | if (cxx_record_decl) { |
| 9004 | // We might have base classes to print out first |
| 9005 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 9006 | base_class_end; |
| 9007 | for (base_class = cxx_record_decl->bases_begin(), |
| 9008 | base_class_end = cxx_record_decl->bases_end(); |
| 9009 | base_class != base_class_end; ++base_class) { |
| 9010 | const clang::CXXRecordDecl *base_class_decl = |
| 9011 | llvm::cast<clang::CXXRecordDecl>( |
| 9012 | base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 9013 | |
| 9014 | // Skip empty base classes |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 9015 | if (!verbose && !ClangASTContext::RecordHasFields(base_class_decl)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9016 | continue; |
| 9017 | |
| 9018 | if (base_class->isVirtual()) |
| 9019 | field_bit_offset = |
| 9020 | record_layout.getVBaseClassOffset(base_class_decl) |
| 9021 | .getQuantity() * |
| 9022 | 8; |
| 9023 | else |
| 9024 | field_bit_offset = record_layout.getBaseClassOffset(base_class_decl) |
| 9025 | .getQuantity() * |
| 9026 | 8; |
| 9027 | field_byte_offset = field_bit_offset / 8; |
| 9028 | assert(field_bit_offset % 8 == 0); |
| 9029 | if (child_idx == 0) |
| 9030 | s->PutChar('{'); |
| 9031 | else |
| 9032 | s->PutChar(','); |
| 9033 | |
| 9034 | clang::QualType base_class_qual_type = base_class->getType(); |
| 9035 | std::string base_class_type_name(base_class_qual_type.getAsString()); |
| 9036 | |
| 9037 | // Indent and print the base class type name |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 9038 | s->Format("\n{0}{1}", llvm::fmt_repeat(" ", depth + DEPTH_INCREMENT), |
| 9039 | base_class_type_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9040 | |
| 9041 | clang::TypeInfo base_class_type_info = |
| 9042 | getASTContext()->getTypeInfo(base_class_qual_type); |
| 9043 | |
| 9044 | // Dump the value of the member |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9045 | CompilerType base_clang_type(this, |
| 9046 | base_class_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9047 | base_clang_type.DumpValue( |
| 9048 | exe_ctx, |
| 9049 | s, // Stream to dump to |
| 9050 | base_clang_type |
| 9051 | .GetFormat(), // The format with which to display the member |
| 9052 | data, // Data buffer containing all bytes for this type |
| 9053 | data_byte_offset + field_byte_offset, // Offset into "data" where |
| 9054 | // to grab value from |
| 9055 | base_class_type_info.Width / 8, // Size of this type in bytes |
| 9056 | 0, // Bitfield bit size |
| 9057 | 0, // Bitfield bit offset |
| 9058 | show_types, // Boolean indicating if we should show the variable |
| 9059 | // types |
| 9060 | show_summary, // Boolean indicating if we should show a summary |
| 9061 | // for the current type |
| 9062 | verbose, // Verbose output? |
| 9063 | depth + DEPTH_INCREMENT); // Scope depth for any types that have |
| 9064 | // children |
| 9065 | |
| 9066 | ++child_idx; |
| 9067 | } |
| 9068 | } |
| 9069 | uint32_t field_idx = 0; |
| 9070 | clang::RecordDecl::field_iterator field, field_end; |
| 9071 | for (field = record_decl->field_begin(), |
| 9072 | field_end = record_decl->field_end(); |
| 9073 | field != field_end; ++field, ++field_idx, ++child_idx) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 9074 | // Print the starting squiggly bracket (if this is the first member) or |
| 9075 | // comma (for member 2 and beyond) for the struct/union/class member. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9076 | if (child_idx == 0) |
| 9077 | s->PutChar('{'); |
| 9078 | else |
| 9079 | s->PutChar(','); |
| 9080 | |
| 9081 | // Indent |
| 9082 | s->Printf("\n%*s", depth + DEPTH_INCREMENT, ""); |
| 9083 | |
| 9084 | clang::QualType field_type = field->getType(); |
| 9085 | // Print the member type if requested |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 9086 | // Figure out the type byte size (field_type_info.first) and alignment |
| 9087 | // (field_type_info.second) from the AST context. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9088 | clang::TypeInfo field_type_info = |
| 9089 | getASTContext()->getTypeInfo(field_type); |
| 9090 | assert(field_idx < record_layout.getFieldCount()); |
| 9091 | // Figure out the field offset within the current struct/union/class |
| 9092 | // type |
| 9093 | field_bit_offset = record_layout.getFieldOffset(field_idx); |
| 9094 | field_byte_offset = field_bit_offset / 8; |
| 9095 | uint32_t field_bitfield_bit_size = 0; |
| 9096 | uint32_t field_bitfield_bit_offset = 0; |
Raphael Isemann | 02e9113 | 2019-11-20 12:09:19 +0100 | [diff] [blame] | 9097 | if (FieldIsBitfield(*field, field_bitfield_bit_size)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9098 | field_bitfield_bit_offset = field_bit_offset % 8; |
| 9099 | |
| 9100 | if (show_types) { |
| 9101 | std::string field_type_name(field_type.getAsString()); |
| 9102 | if (field_bitfield_bit_size > 0) |
| 9103 | s->Printf("(%s:%u) ", field_type_name.c_str(), |
| 9104 | field_bitfield_bit_size); |
| 9105 | else |
| 9106 | s->Printf("(%s) ", field_type_name.c_str()); |
| 9107 | } |
| 9108 | // Print the member name and equal sign |
| 9109 | s->Printf("%s = ", field->getNameAsString().c_str()); |
| 9110 | |
| 9111 | // Dump the value of the member |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9112 | CompilerType field_clang_type(this, field_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9113 | field_clang_type.DumpValue( |
| 9114 | exe_ctx, |
| 9115 | s, // Stream to dump to |
| 9116 | field_clang_type |
| 9117 | .GetFormat(), // The format with which to display the member |
| 9118 | data, // Data buffer containing all bytes for this type |
| 9119 | data_byte_offset + field_byte_offset, // Offset into "data" where to |
| 9120 | // grab value from |
| 9121 | field_type_info.Width / 8, // Size of this type in bytes |
| 9122 | field_bitfield_bit_size, // Bitfield bit size |
| 9123 | field_bitfield_bit_offset, // Bitfield bit offset |
| 9124 | show_types, // Boolean indicating if we should show the variable |
| 9125 | // types |
| 9126 | show_summary, // Boolean indicating if we should show a summary for |
| 9127 | // the current type |
| 9128 | verbose, // Verbose output? |
| 9129 | depth + DEPTH_INCREMENT); // Scope depth for any types that have |
| 9130 | // children |
| 9131 | } |
| 9132 | |
| 9133 | // Indent the trailing squiggly bracket |
| 9134 | if (child_idx > 0) |
| 9135 | s->Printf("\n%*s}", depth, ""); |
| 9136 | } |
| 9137 | return; |
| 9138 | |
| 9139 | case clang::Type::Enum: |
| 9140 | if (GetCompleteType(type)) { |
| 9141 | const clang::EnumType *enutype = |
| 9142 | llvm::cast<clang::EnumType>(qual_type.getTypePtr()); |
| 9143 | const clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 9144 | assert(enum_decl); |
| 9145 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 9146 | lldb::offset_t offset = data_byte_offset; |
| 9147 | const int64_t enum_value = data.GetMaxU64Bitfield( |
| 9148 | &offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 9149 | for (enum_pos = enum_decl->enumerator_begin(), |
| 9150 | enum_end_pos = enum_decl->enumerator_end(); |
| 9151 | enum_pos != enum_end_pos; ++enum_pos) { |
| 9152 | if (enum_pos->getInitVal() == enum_value) { |
| 9153 | s->Printf("%s", enum_pos->getNameAsString().c_str()); |
| 9154 | return; |
| 9155 | } |
| 9156 | } |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 9157 | // If we have gotten here we didn't get find the enumerator in the enum |
| 9158 | // decl, so just print the integer. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9159 | s->Printf("%" PRIi64, enum_value); |
| 9160 | } |
| 9161 | return; |
| 9162 | |
| 9163 | case clang::Type::ConstantArray: { |
| 9164 | const clang::ConstantArrayType *array = |
| 9165 | llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr()); |
| 9166 | bool is_array_of_characters = false; |
| 9167 | clang::QualType element_qual_type = array->getElementType(); |
| 9168 | |
| 9169 | const clang::Type *canonical_type = |
| 9170 | element_qual_type->getCanonicalTypeInternal().getTypePtr(); |
| 9171 | if (canonical_type) |
| 9172 | is_array_of_characters = canonical_type->isCharType(); |
| 9173 | |
| 9174 | const uint64_t element_count = array->getSize().getLimitedValue(); |
| 9175 | |
| 9176 | clang::TypeInfo field_type_info = |
| 9177 | getASTContext()->getTypeInfo(element_qual_type); |
| 9178 | |
| 9179 | uint32_t element_idx = 0; |
| 9180 | uint32_t element_offset = 0; |
| 9181 | uint64_t element_byte_size = field_type_info.Width / 8; |
| 9182 | uint32_t element_stride = element_byte_size; |
| 9183 | |
| 9184 | if (is_array_of_characters) { |
| 9185 | s->PutChar('"'); |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9186 | DumpDataExtractor(data, s, data_byte_offset, lldb::eFormatChar, |
| 9187 | element_byte_size, element_count, UINT32_MAX, |
| 9188 | LLDB_INVALID_ADDRESS, 0, 0); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9189 | s->PutChar('"'); |
| 9190 | return; |
| 9191 | } else { |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9192 | CompilerType element_clang_type(this, element_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9193 | lldb::Format element_format = element_clang_type.GetFormat(); |
| 9194 | |
| 9195 | for (element_idx = 0; element_idx < element_count; ++element_idx) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 9196 | // Print the starting squiggly bracket (if this is the first member) or |
| 9197 | // comman (for member 2 and beyong) for the struct/union/class member. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9198 | if (element_idx == 0) |
| 9199 | s->PutChar('{'); |
| 9200 | else |
| 9201 | s->PutChar(','); |
| 9202 | |
| 9203 | // Indent and print the index |
| 9204 | s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx); |
| 9205 | |
| 9206 | // Figure out the field offset within the current struct/union/class |
| 9207 | // type |
| 9208 | element_offset = element_idx * element_stride; |
| 9209 | |
| 9210 | // Dump the value of the member |
| 9211 | element_clang_type.DumpValue( |
| 9212 | exe_ctx, |
| 9213 | s, // Stream to dump to |
| 9214 | element_format, // The format with which to display the element |
| 9215 | data, // Data buffer containing all bytes for this type |
| 9216 | data_byte_offset + |
| 9217 | element_offset, // Offset into "data" where to grab value from |
| 9218 | element_byte_size, // Size of this type in bytes |
| 9219 | 0, // Bitfield bit size |
| 9220 | 0, // Bitfield bit offset |
| 9221 | show_types, // Boolean indicating if we should show the variable |
| 9222 | // types |
| 9223 | show_summary, // Boolean indicating if we should show a summary for |
| 9224 | // the current type |
| 9225 | verbose, // Verbose output? |
| 9226 | depth + DEPTH_INCREMENT); // Scope depth for any types that have |
| 9227 | // children |
| 9228 | } |
| 9229 | |
| 9230 | // Indent the trailing squiggly bracket |
| 9231 | if (element_idx > 0) |
| 9232 | s->Printf("\n%*s}", depth, ""); |
| 9233 | } |
| 9234 | } |
| 9235 | return; |
| 9236 | |
| 9237 | case clang::Type::Typedef: { |
| 9238 | clang::QualType typedef_qual_type = |
| 9239 | llvm::cast<clang::TypedefType>(qual_type) |
| 9240 | ->getDecl() |
| 9241 | ->getUnderlyingType(); |
| 9242 | |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9243 | CompilerType typedef_clang_type(this, typedef_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9244 | lldb::Format typedef_format = typedef_clang_type.GetFormat(); |
| 9245 | clang::TypeInfo typedef_type_info = |
| 9246 | getASTContext()->getTypeInfo(typedef_qual_type); |
| 9247 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; |
| 9248 | |
| 9249 | return typedef_clang_type.DumpValue( |
| 9250 | exe_ctx, |
| 9251 | s, // Stream to dump to |
| 9252 | typedef_format, // The format with which to display the element |
| 9253 | data, // Data buffer containing all bytes for this type |
| 9254 | data_byte_offset, // Offset into "data" where to grab value from |
| 9255 | typedef_byte_size, // Size of this type in bytes |
| 9256 | bitfield_bit_size, // Bitfield bit size |
| 9257 | bitfield_bit_offset, // Bitfield bit offset |
| 9258 | show_types, // Boolean indicating if we should show the variable types |
| 9259 | show_summary, // Boolean indicating if we should show a summary for the |
| 9260 | // current type |
| 9261 | verbose, // Verbose output? |
| 9262 | depth); // Scope depth for any types that have children |
| 9263 | } break; |
| 9264 | |
| 9265 | case clang::Type::Auto: { |
| 9266 | clang::QualType elaborated_qual_type = |
| 9267 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType(); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9268 | CompilerType elaborated_clang_type(this, |
| 9269 | elaborated_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9270 | lldb::Format elaborated_format = elaborated_clang_type.GetFormat(); |
| 9271 | clang::TypeInfo elaborated_type_info = |
| 9272 | getASTContext()->getTypeInfo(elaborated_qual_type); |
| 9273 | uint64_t elaborated_byte_size = elaborated_type_info.Width / 8; |
| 9274 | |
| 9275 | return elaborated_clang_type.DumpValue( |
| 9276 | exe_ctx, |
| 9277 | s, // Stream to dump to |
| 9278 | elaborated_format, // The format with which to display the element |
| 9279 | data, // Data buffer containing all bytes for this type |
| 9280 | data_byte_offset, // Offset into "data" where to grab value from |
| 9281 | elaborated_byte_size, // Size of this type in bytes |
| 9282 | bitfield_bit_size, // Bitfield bit size |
| 9283 | bitfield_bit_offset, // Bitfield bit offset |
| 9284 | show_types, // Boolean indicating if we should show the variable types |
| 9285 | show_summary, // Boolean indicating if we should show a summary for the |
| 9286 | // current type |
| 9287 | verbose, // Verbose output? |
| 9288 | depth); // Scope depth for any types that have children |
| 9289 | } break; |
| 9290 | |
| 9291 | case clang::Type::Elaborated: { |
| 9292 | clang::QualType elaborated_qual_type = |
| 9293 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9294 | CompilerType elaborated_clang_type(this, |
| 9295 | elaborated_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9296 | lldb::Format elaborated_format = elaborated_clang_type.GetFormat(); |
| 9297 | clang::TypeInfo elaborated_type_info = |
| 9298 | getASTContext()->getTypeInfo(elaborated_qual_type); |
| 9299 | uint64_t elaborated_byte_size = elaborated_type_info.Width / 8; |
| 9300 | |
| 9301 | return elaborated_clang_type.DumpValue( |
| 9302 | exe_ctx, |
| 9303 | s, // Stream to dump to |
| 9304 | elaborated_format, // The format with which to display the element |
| 9305 | data, // Data buffer containing all bytes for this type |
| 9306 | data_byte_offset, // Offset into "data" where to grab value from |
| 9307 | elaborated_byte_size, // Size of this type in bytes |
| 9308 | bitfield_bit_size, // Bitfield bit size |
| 9309 | bitfield_bit_offset, // Bitfield bit offset |
| 9310 | show_types, // Boolean indicating if we should show the variable types |
| 9311 | show_summary, // Boolean indicating if we should show a summary for the |
| 9312 | // current type |
| 9313 | verbose, // Verbose output? |
| 9314 | depth); // Scope depth for any types that have children |
| 9315 | } break; |
| 9316 | |
| 9317 | case clang::Type::Paren: { |
| 9318 | clang::QualType desugar_qual_type = |
| 9319 | llvm::cast<clang::ParenType>(qual_type)->desugar(); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9320 | CompilerType desugar_clang_type(this, desugar_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9321 | |
| 9322 | lldb::Format desugar_format = desugar_clang_type.GetFormat(); |
| 9323 | clang::TypeInfo desugar_type_info = |
| 9324 | getASTContext()->getTypeInfo(desugar_qual_type); |
| 9325 | uint64_t desugar_byte_size = desugar_type_info.Width / 8; |
| 9326 | |
| 9327 | return desugar_clang_type.DumpValue( |
| 9328 | exe_ctx, |
| 9329 | s, // Stream to dump to |
| 9330 | desugar_format, // The format with which to display the element |
| 9331 | data, // Data buffer containing all bytes for this type |
| 9332 | data_byte_offset, // Offset into "data" where to grab value from |
| 9333 | desugar_byte_size, // Size of this type in bytes |
| 9334 | bitfield_bit_size, // Bitfield bit size |
| 9335 | bitfield_bit_offset, // Bitfield bit offset |
| 9336 | show_types, // Boolean indicating if we should show the variable types |
| 9337 | show_summary, // Boolean indicating if we should show a summary for the |
| 9338 | // current type |
| 9339 | verbose, // Verbose output? |
| 9340 | depth); // Scope depth for any types that have children |
| 9341 | } break; |
| 9342 | |
| 9343 | default: |
| 9344 | // We are down to a scalar type that we just need to display. |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9345 | DumpDataExtractor(data, s, data_byte_offset, format, data_byte_size, 1, |
| 9346 | UINT32_MAX, LLDB_INVALID_ADDRESS, bitfield_bit_size, |
| 9347 | bitfield_bit_offset); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9348 | |
| 9349 | if (show_summary) |
| 9350 | DumpSummary(type, exe_ctx, s, data, data_byte_offset, data_byte_size); |
| 9351 | break; |
| 9352 | } |
| 9353 | } |
| 9354 | |
Frederic Riss | d6470fb | 2019-10-08 15:35:58 +0000 | [diff] [blame] | 9355 | static bool DumpEnumValue(const clang::QualType &qual_type, Stream *s, |
| 9356 | const DataExtractor &data, lldb::offset_t byte_offset, |
| 9357 | size_t byte_size, uint32_t bitfield_bit_offset, |
| 9358 | uint32_t bitfield_bit_size) { |
| 9359 | const clang::EnumType *enutype = |
| 9360 | llvm::cast<clang::EnumType>(qual_type.getTypePtr()); |
| 9361 | const clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 9362 | assert(enum_decl); |
Frederic Riss | d6470fb | 2019-10-08 15:35:58 +0000 | [diff] [blame] | 9363 | lldb::offset_t offset = byte_offset; |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9364 | const uint64_t enum_svalue = data.GetMaxS64Bitfield( |
Frederic Riss | d6470fb | 2019-10-08 15:35:58 +0000 | [diff] [blame] | 9365 | &offset, byte_size, bitfield_bit_size, bitfield_bit_offset); |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9366 | bool can_be_bitfield = true; |
| 9367 | uint64_t covered_bits = 0; |
| 9368 | int num_enumerators = 0; |
Frederic Riss | d6470fb | 2019-10-08 15:35:58 +0000 | [diff] [blame] | 9369 | |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9370 | // Try to find an exact match for the value. |
| 9371 | // At the same time, we're applying a heuristic to determine whether we want |
| 9372 | // to print this enum as a bitfield. We're likely dealing with a bitfield if |
| 9373 | // every enumrator is either a one bit value or a superset of the previous |
| 9374 | // enumerators. Also 0 doesn't make sense when the enumerators are used as |
| 9375 | // flags. |
Frederic Riss | d6470fb | 2019-10-08 15:35:58 +0000 | [diff] [blame] | 9376 | for (auto enumerator : enum_decl->enumerators()) { |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9377 | uint64_t val = enumerator->getInitVal().getSExtValue(); |
Frederic Riss | 5d415b7 | 2019-10-08 17:59:02 +0000 | [diff] [blame] | 9378 | val = llvm::SignExtend64(val, 8*byte_size); |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9379 | if (llvm::countPopulation(val) != 1 && (val & ~covered_bits) != 0) |
| 9380 | can_be_bitfield = false; |
| 9381 | covered_bits |= val; |
| 9382 | ++num_enumerators; |
| 9383 | if (val == enum_svalue) { |
| 9384 | // Found an exact match, that's all we need to do. |
Frederic Riss | d6470fb | 2019-10-08 15:35:58 +0000 | [diff] [blame] | 9385 | s->PutCString(enumerator->getNameAsString()); |
| 9386 | return true; |
| 9387 | } |
| 9388 | } |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9389 | |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9390 | // Unsigned values make more sense for flags. |
| 9391 | offset = byte_offset; |
| 9392 | const uint64_t enum_uvalue = data.GetMaxU64Bitfield( |
| 9393 | &offset, byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 9394 | |
Frederic Riss | b56e3a1 | 2019-10-08 19:52:01 +0000 | [diff] [blame] | 9395 | // No exact match, but we don't think this is a bitfield. Print the value as |
| 9396 | // decimal. |
| 9397 | if (!can_be_bitfield) { |
| 9398 | if (qual_type->isSignedIntegerOrEnumerationType()) |
| 9399 | s->Printf("%" PRIi64, enum_svalue); |
| 9400 | else |
| 9401 | s->Printf("%" PRIu64, enum_uvalue); |
| 9402 | return true; |
| 9403 | } |
| 9404 | |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9405 | uint64_t remaining_value = enum_uvalue; |
| 9406 | std::vector<std::pair<uint64_t, llvm::StringRef>> values; |
| 9407 | values.reserve(num_enumerators); |
| 9408 | for (auto enumerator : enum_decl->enumerators()) |
| 9409 | if (auto val = enumerator->getInitVal().getZExtValue()) |
| 9410 | values.emplace_back(val, enumerator->getName()); |
| 9411 | |
| 9412 | // Sort in reverse order of the number of the population count, so that in |
| 9413 | // `enum {A, B, ALL = A|B }` we visit ALL first. Use a stable sort so that |
| 9414 | // A | C where A is declared before C is displayed in this order. |
| 9415 | std::stable_sort(values.begin(), values.end(), [](const auto &a, const auto &b) { |
| 9416 | return llvm::countPopulation(a.first) > llvm::countPopulation(b.first); |
| 9417 | }); |
| 9418 | |
| 9419 | for (const auto &val : values) { |
| 9420 | if ((remaining_value & val.first) != val.first) |
| 9421 | continue; |
| 9422 | remaining_value &= ~val.first; |
| 9423 | s->PutCString(val.second); |
| 9424 | if (remaining_value) |
| 9425 | s->PutCString(" | "); |
| 9426 | } |
| 9427 | |
| 9428 | // If there is a remainder that is not covered by the value, print it as hex. |
| 9429 | if (remaining_value) |
| 9430 | s->Printf("0x%" PRIx64, remaining_value); |
| 9431 | |
Frederic Riss | d6470fb | 2019-10-08 15:35:58 +0000 | [diff] [blame] | 9432 | return true; |
| 9433 | } |
| 9434 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9435 | bool ClangASTContext::DumpTypeValue( |
| 9436 | lldb::opaque_compiler_type_t type, Stream *s, lldb::Format format, |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9437 | const DataExtractor &data, lldb::offset_t byte_offset, size_t byte_size, |
| 9438 | uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9439 | ExecutionContextScope *exe_scope) { |
| 9440 | if (!type) |
| 9441 | return false; |
| 9442 | if (IsAggregateType(type)) { |
| 9443 | return false; |
| 9444 | } else { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9445 | clang::QualType qual_type(GetQualType(type)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9446 | |
| 9447 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
Frederic Riss | 41ff396 | 2019-10-08 15:35:59 +0000 | [diff] [blame] | 9448 | |
| 9449 | if (type_class == clang::Type::Elaborated) { |
| 9450 | qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(); |
| 9451 | return DumpTypeValue(qual_type.getAsOpaquePtr(), s, format, data, byte_offset, byte_size, |
| 9452 | bitfield_bit_size, bitfield_bit_offset, exe_scope); |
| 9453 | } |
| 9454 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9455 | switch (type_class) { |
| 9456 | case clang::Type::Typedef: { |
| 9457 | clang::QualType typedef_qual_type = |
| 9458 | llvm::cast<clang::TypedefType>(qual_type) |
| 9459 | ->getDecl() |
| 9460 | ->getUnderlyingType(); |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9461 | CompilerType typedef_clang_type(this, typedef_qual_type.getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9462 | if (format == eFormatDefault) |
| 9463 | format = typedef_clang_type.GetFormat(); |
| 9464 | clang::TypeInfo typedef_type_info = |
| 9465 | getASTContext()->getTypeInfo(typedef_qual_type); |
| 9466 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; |
| 9467 | |
| 9468 | return typedef_clang_type.DumpTypeValue( |
| 9469 | s, |
| 9470 | format, // The format with which to display the element |
| 9471 | data, // Data buffer containing all bytes for this type |
| 9472 | byte_offset, // Offset into "data" where to grab value from |
| 9473 | typedef_byte_size, // Size of this type in bytes |
| 9474 | bitfield_bit_size, // Size in bits of a bitfield value, if zero don't |
| 9475 | // treat as a bitfield |
| 9476 | bitfield_bit_offset, // Offset in bits of a bitfield value if |
| 9477 | // bitfield_bit_size != 0 |
| 9478 | exe_scope); |
| 9479 | } break; |
| 9480 | |
| 9481 | case clang::Type::Enum: |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 9482 | // If our format is enum or default, show the enumeration value as its |
| 9483 | // enumeration string value, else just display it as requested. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9484 | if ((format == eFormatEnum || format == eFormatDefault) && |
Frederic Riss | d6470fb | 2019-10-08 15:35:58 +0000 | [diff] [blame] | 9485 | GetCompleteType(type)) |
| 9486 | return DumpEnumValue(qual_type, s, data, byte_offset, byte_size, |
| 9487 | bitfield_bit_offset, bitfield_bit_size); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9488 | // format was not enum, just fall through and dump the value as |
| 9489 | // requested.... |
| 9490 | LLVM_FALLTHROUGH; |
| 9491 | |
| 9492 | default: |
| 9493 | // We are down to a scalar type that we just need to display. |
| 9494 | { |
| 9495 | uint32_t item_count = 1; |
| 9496 | // A few formats, we might need to modify our size and count for |
| 9497 | // depending |
| 9498 | // on how we are trying to display the value... |
| 9499 | switch (format) { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9500 | default: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9501 | case eFormatBoolean: |
| 9502 | case eFormatBinary: |
| 9503 | case eFormatComplex: |
| 9504 | case eFormatCString: // NULL terminated C strings |
| 9505 | case eFormatDecimal: |
| 9506 | case eFormatEnum: |
| 9507 | case eFormatHex: |
| 9508 | case eFormatHexUppercase: |
| 9509 | case eFormatFloat: |
| 9510 | case eFormatOctal: |
| 9511 | case eFormatOSType: |
| 9512 | case eFormatUnsigned: |
| 9513 | case eFormatPointer: |
| 9514 | case eFormatVectorOfChar: |
| 9515 | case eFormatVectorOfSInt8: |
| 9516 | case eFormatVectorOfUInt8: |
| 9517 | case eFormatVectorOfSInt16: |
| 9518 | case eFormatVectorOfUInt16: |
| 9519 | case eFormatVectorOfSInt32: |
| 9520 | case eFormatVectorOfUInt32: |
| 9521 | case eFormatVectorOfSInt64: |
| 9522 | case eFormatVectorOfUInt64: |
| 9523 | case eFormatVectorOfFloat32: |
| 9524 | case eFormatVectorOfFloat64: |
| 9525 | case eFormatVectorOfUInt128: |
| 9526 | break; |
| 9527 | |
| 9528 | case eFormatChar: |
| 9529 | case eFormatCharPrintable: |
| 9530 | case eFormatCharArray: |
| 9531 | case eFormatBytes: |
| 9532 | case eFormatBytesWithASCII: |
| 9533 | item_count = byte_size; |
| 9534 | byte_size = 1; |
| 9535 | break; |
| 9536 | |
| 9537 | case eFormatUnicode16: |
| 9538 | item_count = byte_size / 2; |
| 9539 | byte_size = 2; |
| 9540 | break; |
| 9541 | |
| 9542 | case eFormatUnicode32: |
| 9543 | item_count = byte_size / 4; |
| 9544 | byte_size = 4; |
| 9545 | break; |
| 9546 | } |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9547 | return DumpDataExtractor(data, s, byte_offset, format, byte_size, |
| 9548 | item_count, UINT32_MAX, LLDB_INVALID_ADDRESS, |
| 9549 | bitfield_bit_size, bitfield_bit_offset, |
| 9550 | exe_scope); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9551 | } |
| 9552 | break; |
| 9553 | } |
| 9554 | } |
Jonas Devlieghere | 09ad8c8 | 2019-05-24 00:44:33 +0000 | [diff] [blame] | 9555 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9556 | } |
| 9557 | |
| 9558 | void ClangASTContext::DumpSummary(lldb::opaque_compiler_type_t type, |
| 9559 | ExecutionContext *exe_ctx, Stream *s, |
| 9560 | const lldb_private::DataExtractor &data, |
| 9561 | lldb::offset_t data_byte_offset, |
| 9562 | size_t data_byte_size) { |
| 9563 | uint32_t length = 0; |
| 9564 | if (IsCStringType(type, length)) { |
| 9565 | if (exe_ctx) { |
| 9566 | Process *process = exe_ctx->GetProcessPtr(); |
| 9567 | if (process) { |
| 9568 | lldb::offset_t offset = data_byte_offset; |
| 9569 | lldb::addr_t pointer_address = data.GetMaxU64(&offset, data_byte_size); |
| 9570 | std::vector<uint8_t> buf; |
| 9571 | if (length > 0) |
| 9572 | buf.resize(length); |
| 9573 | else |
| 9574 | buf.resize(256); |
| 9575 | |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9576 | DataExtractor cstr_data(&buf.front(), buf.size(), |
| 9577 | process->GetByteOrder(), 4); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9578 | buf.back() = '\0'; |
| 9579 | size_t bytes_read; |
| 9580 | size_t total_cstr_len = 0; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 9581 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9582 | while ((bytes_read = process->ReadMemory(pointer_address, &buf.front(), |
| 9583 | buf.size(), error)) > 0) { |
| 9584 | const size_t len = strlen((const char *)&buf.front()); |
| 9585 | if (len == 0) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9586 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9587 | if (total_cstr_len == 0) |
| 9588 | s->PutCString(" \""); |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9589 | DumpDataExtractor(cstr_data, s, 0, lldb::eFormatChar, 1, len, |
| 9590 | UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9591 | total_cstr_len += len; |
| 9592 | if (len < buf.size()) |
| 9593 | break; |
| 9594 | pointer_address += total_cstr_len; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9595 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9596 | if (total_cstr_len > 0) |
| 9597 | s->PutChar('"'); |
| 9598 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9599 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9600 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9601 | } |
| 9602 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9603 | void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) { |
| 9604 | StreamFile s(stdout, false); |
| 9605 | DumpTypeDescription(type, &s); |
| 9606 | ClangASTMetadata *metadata = |
| 9607 | ClangASTContext::GetMetadata(getASTContext(), type); |
| 9608 | if (metadata) { |
| 9609 | metadata->Dump(&s); |
| 9610 | } |
| 9611 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9612 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9613 | void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, |
| 9614 | Stream *s) { |
| 9615 | if (type) { |
| 9616 | clang::QualType qual_type(GetQualType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9617 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9618 | llvm::SmallVector<char, 1024> buf; |
| 9619 | llvm::raw_svector_ostream llvm_ostrm(buf); |
| 9620 | |
| 9621 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 9622 | switch (type_class) { |
| 9623 | case clang::Type::ObjCObject: |
| 9624 | case clang::Type::ObjCInterface: { |
| 9625 | GetCompleteType(type); |
| 9626 | |
| 9627 | const clang::ObjCObjectType *objc_class_type = |
| 9628 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 9629 | assert(objc_class_type); |
| 9630 | if (objc_class_type) { |
| 9631 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 9632 | objc_class_type->getInterface(); |
| 9633 | if (class_interface_decl) { |
| 9634 | clang::PrintingPolicy policy = getASTContext()->getPrintingPolicy(); |
| 9635 | class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9636 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9637 | } |
| 9638 | } break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9639 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9640 | case clang::Type::Typedef: { |
| 9641 | const clang::TypedefType *typedef_type = |
| 9642 | qual_type->getAs<clang::TypedefType>(); |
| 9643 | if (typedef_type) { |
| 9644 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 9645 | std::string clang_typedef_name( |
| 9646 | typedef_decl->getQualifiedNameAsString()); |
| 9647 | if (!clang_typedef_name.empty()) { |
| 9648 | s->PutCString("typedef "); |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 9649 | s->PutCString(clang_typedef_name); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9650 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9651 | } |
| 9652 | } break; |
| 9653 | |
| 9654 | case clang::Type::Auto: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9655 | CompilerType(this, llvm::cast<clang::AutoType>(qual_type) |
| 9656 | ->getDeducedType() |
| 9657 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9658 | .DumpTypeDescription(s); |
| 9659 | return; |
| 9660 | |
| 9661 | case clang::Type::Elaborated: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9662 | CompilerType(this, llvm::cast<clang::ElaboratedType>(qual_type) |
| 9663 | ->getNamedType() |
| 9664 | .getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9665 | .DumpTypeDescription(s); |
| 9666 | return; |
| 9667 | |
| 9668 | case clang::Type::Paren: |
Alex Langford | bddab07 | 2019-08-13 19:40:36 +0000 | [diff] [blame] | 9669 | CompilerType( |
| 9670 | this, |
| 9671 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9672 | .DumpTypeDescription(s); |
| 9673 | return; |
| 9674 | |
| 9675 | case clang::Type::Record: { |
| 9676 | GetCompleteType(type); |
| 9677 | |
| 9678 | const clang::RecordType *record_type = |
| 9679 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 9680 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 9681 | const clang::CXXRecordDecl *cxx_record_decl = |
| 9682 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 9683 | |
| 9684 | if (cxx_record_decl) |
| 9685 | cxx_record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), |
| 9686 | s->GetIndentLevel()); |
| 9687 | else |
| 9688 | record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), |
| 9689 | s->GetIndentLevel()); |
| 9690 | } break; |
| 9691 | |
| 9692 | default: { |
| 9693 | const clang::TagType *tag_type = |
| 9694 | llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 9695 | if (tag_type) { |
| 9696 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 9697 | if (tag_decl) |
| 9698 | tag_decl->print(llvm_ostrm, 0); |
| 9699 | } else { |
| 9700 | std::string clang_type_name(qual_type.getAsString()); |
| 9701 | if (!clang_type_name.empty()) |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 9702 | s->PutCString(clang_type_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9703 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9704 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 9705 | } |
| 9706 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9707 | if (buf.size() > 0) { |
| 9708 | s->Write(buf.data(), buf.size()); |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9709 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9710 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9711 | } |
| 9712 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9713 | void ClangASTContext::DumpTypeName(const CompilerType &type) { |
| 9714 | if (ClangUtil::IsClangType(type)) { |
| 9715 | clang::QualType qual_type( |
| 9716 | ClangUtil::GetCanonicalQualType(ClangUtil::RemoveFastQualifiers(type))); |
| 9717 | |
| 9718 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 9719 | switch (type_class) { |
| 9720 | case clang::Type::Record: { |
| 9721 | const clang::CXXRecordDecl *cxx_record_decl = |
| 9722 | qual_type->getAsCXXRecordDecl(); |
| 9723 | if (cxx_record_decl) |
| 9724 | printf("class %s", cxx_record_decl->getName().str().c_str()); |
| 9725 | } break; |
| 9726 | |
| 9727 | case clang::Type::Enum: { |
| 9728 | clang::EnumDecl *enum_decl = |
| 9729 | llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 9730 | if (enum_decl) { |
| 9731 | printf("enum %s", enum_decl->getName().str().c_str()); |
| 9732 | } |
| 9733 | } break; |
| 9734 | |
| 9735 | case clang::Type::ObjCObject: |
| 9736 | case clang::Type::ObjCInterface: { |
| 9737 | const clang::ObjCObjectType *objc_class_type = |
| 9738 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 9739 | if (objc_class_type) { |
| 9740 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 9741 | objc_class_type->getInterface(); |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 9742 | // We currently can't complete objective C types through the newly |
| 9743 | // added ASTContext because it only supports TagDecl objects right |
| 9744 | // now... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9745 | if (class_interface_decl) |
| 9746 | printf("@class %s", class_interface_decl->getName().str().c_str()); |
| 9747 | } |
| 9748 | } break; |
| 9749 | |
| 9750 | case clang::Type::Typedef: |
| 9751 | printf("typedef %s", llvm::cast<clang::TypedefType>(qual_type) |
| 9752 | ->getDecl() |
| 9753 | ->getName() |
| 9754 | .str() |
| 9755 | .c_str()); |
| 9756 | break; |
| 9757 | |
| 9758 | case clang::Type::Auto: |
| 9759 | printf("auto "); |
| 9760 | return DumpTypeName(CompilerType(type.GetTypeSystem(), |
| 9761 | llvm::cast<clang::AutoType>(qual_type) |
| 9762 | ->getDeducedType() |
| 9763 | .getAsOpaquePtr())); |
| 9764 | |
| 9765 | case clang::Type::Elaborated: |
| 9766 | printf("elaborated "); |
| 9767 | return DumpTypeName(CompilerType( |
| 9768 | type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type) |
| 9769 | ->getNamedType() |
| 9770 | .getAsOpaquePtr())); |
| 9771 | |
| 9772 | case clang::Type::Paren: |
| 9773 | printf("paren "); |
| 9774 | return DumpTypeName(CompilerType( |
| 9775 | type.GetTypeSystem(), |
| 9776 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())); |
| 9777 | |
| 9778 | default: |
| 9779 | printf("ClangASTContext::DumpTypeName() type_class = %u", type_class); |
| 9780 | break; |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9781 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9782 | } |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9783 | } |
| 9784 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9785 | clang::ClassTemplateDecl *ClangASTContext::ParseClassTemplateDecl( |
| 9786 | clang::DeclContext *decl_ctx, lldb::AccessType access_type, |
| 9787 | const char *parent_name, int tag_decl_kind, |
| 9788 | const ClangASTContext::TemplateParameterInfos &template_param_infos) { |
| 9789 | if (template_param_infos.IsValid()) { |
| 9790 | std::string template_basename(parent_name); |
| 9791 | template_basename.erase(template_basename.find('<')); |
| 9792 | |
| 9793 | return CreateClassTemplateDecl(decl_ctx, access_type, |
| 9794 | template_basename.c_str(), tag_decl_kind, |
| 9795 | template_param_infos); |
| 9796 | } |
Konrad Kleine | 248a130 | 2019-05-23 11:14:47 +0000 | [diff] [blame] | 9797 | return nullptr; |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9798 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9799 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9800 | void ClangASTContext::CompleteTagDecl(void *baton, clang::TagDecl *decl) { |
| 9801 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 9802 | SymbolFile *sym_file = ast->GetSymbolFile(); |
| 9803 | if (sym_file) { |
| 9804 | CompilerType clang_type = GetTypeForDecl(decl); |
| 9805 | if (clang_type) |
| 9806 | sym_file->CompleteType(clang_type); |
| 9807 | } |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 9808 | } |
| 9809 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9810 | void ClangASTContext::CompleteObjCInterfaceDecl( |
| 9811 | void *baton, clang::ObjCInterfaceDecl *decl) { |
| 9812 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 9813 | SymbolFile *sym_file = ast->GetSymbolFile(); |
| 9814 | if (sym_file) { |
| 9815 | CompilerType clang_type = GetTypeForDecl(decl); |
| 9816 | if (clang_type) |
| 9817 | sym_file->CompleteType(clang_type); |
| 9818 | } |
Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 9819 | } |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 9820 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9821 | DWARFASTParser *ClangASTContext::GetDWARFParser() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 9822 | if (!m_dwarf_ast_parser_up) |
| 9823 | m_dwarf_ast_parser_up.reset(new DWARFASTParserClang(*this)); |
| 9824 | return m_dwarf_ast_parser_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9825 | } |
| 9826 | |
| 9827 | PDBASTParser *ClangASTContext::GetPDBParser() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 9828 | if (!m_pdb_ast_parser_up) |
| 9829 | m_pdb_ast_parser_up.reset(new PDBASTParser(*this)); |
| 9830 | return m_pdb_ast_parser_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9831 | } |
| 9832 | |
| 9833 | bool ClangASTContext::LayoutRecordType( |
| 9834 | void *baton, const clang::RecordDecl *record_decl, uint64_t &bit_size, |
| 9835 | uint64_t &alignment, |
| 9836 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
| 9837 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
| 9838 | &base_offsets, |
| 9839 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
| 9840 | &vbase_offsets) { |
| 9841 | ClangASTContext *ast = (ClangASTContext *)baton; |
Aleksandr Urakov | 7d2a74f | 2018-08-14 07:57:44 +0000 | [diff] [blame] | 9842 | lldb_private::ClangASTImporter *importer = nullptr; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 9843 | if (ast->m_dwarf_ast_parser_up) |
| 9844 | importer = &ast->m_dwarf_ast_parser_up->GetClangASTImporter(); |
| 9845 | if (!importer && ast->m_pdb_ast_parser_up) |
| 9846 | importer = &ast->m_pdb_ast_parser_up->GetClangASTImporter(); |
Aleksandr Urakov | 7d2a74f | 2018-08-14 07:57:44 +0000 | [diff] [blame] | 9847 | if (!importer) |
| 9848 | return false; |
| 9849 | |
| 9850 | return importer->LayoutRecordType(record_decl, bit_size, alignment, |
| 9851 | field_offsets, base_offsets, vbase_offsets); |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9852 | } |
| 9853 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9854 | // CompilerDecl override functions |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9855 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9856 | ConstString ClangASTContext::DeclGetName(void *opaque_decl) { |
| 9857 | if (opaque_decl) { |
| 9858 | clang::NamedDecl *nd = |
| 9859 | llvm::dyn_cast<NamedDecl>((clang::Decl *)opaque_decl); |
| 9860 | if (nd != nullptr) |
| 9861 | return ConstString(nd->getDeclName().getAsString()); |
| 9862 | } |
| 9863 | return ConstString(); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9864 | } |
| 9865 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9866 | ConstString ClangASTContext::DeclGetMangledName(void *opaque_decl) { |
| 9867 | if (opaque_decl) { |
| 9868 | clang::NamedDecl *nd = |
| 9869 | llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)opaque_decl); |
| 9870 | if (nd != nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd)) { |
| 9871 | clang::MangleContext *mc = getMangleContext(); |
| 9872 | if (mc && mc->shouldMangleCXXName(nd)) { |
| 9873 | llvm::SmallVector<char, 1024> buf; |
| 9874 | llvm::raw_svector_ostream llvm_ostrm(buf); |
| 9875 | if (llvm::isa<clang::CXXConstructorDecl>(nd)) { |
| 9876 | mc->mangleCXXCtor(llvm::dyn_cast<clang::CXXConstructorDecl>(nd), |
| 9877 | Ctor_Complete, llvm_ostrm); |
| 9878 | } else if (llvm::isa<clang::CXXDestructorDecl>(nd)) { |
| 9879 | mc->mangleCXXDtor(llvm::dyn_cast<clang::CXXDestructorDecl>(nd), |
| 9880 | Dtor_Complete, llvm_ostrm); |
| 9881 | } else { |
| 9882 | mc->mangleName(nd, llvm_ostrm); |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9883 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9884 | if (buf.size() > 0) |
| 9885 | return ConstString(buf.data(), buf.size()); |
| 9886 | } |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9887 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9888 | } |
| 9889 | return ConstString(); |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9890 | } |
| 9891 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9892 | CompilerDeclContext ClangASTContext::DeclGetDeclContext(void *opaque_decl) { |
| 9893 | if (opaque_decl) |
| 9894 | return CompilerDeclContext(this, |
| 9895 | ((clang::Decl *)opaque_decl)->getDeclContext()); |
| 9896 | else |
| 9897 | return CompilerDeclContext(); |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9898 | } |
| 9899 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9900 | CompilerType ClangASTContext::DeclGetFunctionReturnType(void *opaque_decl) { |
| 9901 | if (clang::FunctionDecl *func_decl = |
| 9902 | llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) |
| 9903 | return CompilerType(this, func_decl->getReturnType().getAsOpaquePtr()); |
| 9904 | if (clang::ObjCMethodDecl *objc_method = |
| 9905 | llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl)) |
| 9906 | return CompilerType(this, objc_method->getReturnType().getAsOpaquePtr()); |
| 9907 | else |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9908 | return CompilerType(); |
| 9909 | } |
| 9910 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9911 | size_t ClangASTContext::DeclGetFunctionNumArguments(void *opaque_decl) { |
| 9912 | if (clang::FunctionDecl *func_decl = |
| 9913 | llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) |
| 9914 | return func_decl->param_size(); |
| 9915 | if (clang::ObjCMethodDecl *objc_method = |
| 9916 | llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl)) |
| 9917 | return objc_method->param_size(); |
| 9918 | else |
| 9919 | return 0; |
| 9920 | } |
| 9921 | |
| 9922 | CompilerType ClangASTContext::DeclGetFunctionArgumentType(void *opaque_decl, |
| 9923 | size_t idx) { |
| 9924 | if (clang::FunctionDecl *func_decl = |
| 9925 | llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) { |
| 9926 | if (idx < func_decl->param_size()) { |
| 9927 | ParmVarDecl *var_decl = func_decl->getParamDecl(idx); |
| 9928 | if (var_decl) |
| 9929 | return CompilerType(this, var_decl->getOriginalType().getAsOpaquePtr()); |
| 9930 | } |
| 9931 | } else if (clang::ObjCMethodDecl *objc_method = |
| 9932 | llvm::dyn_cast<clang::ObjCMethodDecl>( |
| 9933 | (clang::Decl *)opaque_decl)) { |
| 9934 | if (idx < objc_method->param_size()) |
| 9935 | return CompilerType( |
| 9936 | this, |
| 9937 | objc_method->parameters()[idx]->getOriginalType().getAsOpaquePtr()); |
| 9938 | } |
| 9939 | return CompilerType(); |
| 9940 | } |
| 9941 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9942 | // CompilerDeclContext functions |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9943 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9944 | std::vector<CompilerDecl> ClangASTContext::DeclContextFindDeclByName( |
| 9945 | void *opaque_decl_ctx, ConstString name, const bool ignore_using_decls) { |
| 9946 | std::vector<CompilerDecl> found_decls; |
| 9947 | if (opaque_decl_ctx) { |
| 9948 | DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx; |
| 9949 | std::set<DeclContext *> searched; |
| 9950 | std::multimap<DeclContext *, DeclContext *> search_queue; |
| 9951 | SymbolFile *symbol_file = GetSymbolFile(); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9952 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9953 | for (clang::DeclContext *decl_context = root_decl_ctx; |
| 9954 | decl_context != nullptr && found_decls.empty(); |
| 9955 | decl_context = decl_context->getParent()) { |
| 9956 | search_queue.insert(std::make_pair(decl_context, decl_context)); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9957 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9958 | for (auto it = search_queue.find(decl_context); it != search_queue.end(); |
| 9959 | it++) { |
| 9960 | if (!searched.insert(it->second).second) |
| 9961 | continue; |
| 9962 | symbol_file->ParseDeclsForContext( |
| 9963 | CompilerDeclContext(this, it->second)); |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9964 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9965 | for (clang::Decl *child : it->second->decls()) { |
| 9966 | if (clang::UsingDirectiveDecl *ud = |
| 9967 | llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) { |
| 9968 | if (ignore_using_decls) |
| 9969 | continue; |
| 9970 | clang::DeclContext *from = ud->getCommonAncestor(); |
| 9971 | if (searched.find(ud->getNominatedNamespace()) == searched.end()) |
| 9972 | search_queue.insert( |
| 9973 | std::make_pair(from, ud->getNominatedNamespace())); |
| 9974 | } else if (clang::UsingDecl *ud = |
| 9975 | llvm::dyn_cast<clang::UsingDecl>(child)) { |
| 9976 | if (ignore_using_decls) |
| 9977 | continue; |
| 9978 | for (clang::UsingShadowDecl *usd : ud->shadows()) { |
| 9979 | clang::Decl *target = usd->getTargetDecl(); |
| 9980 | if (clang::NamedDecl *nd = |
| 9981 | llvm::dyn_cast<clang::NamedDecl>(target)) { |
| 9982 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9983 | if (ii != nullptr && |
| 9984 | ii->getName().equals(name.AsCString(nullptr))) |
| 9985 | found_decls.push_back(CompilerDecl(this, nd)); |
| 9986 | } |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9987 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9988 | } else if (clang::NamedDecl *nd = |
| 9989 | llvm::dyn_cast<clang::NamedDecl>(child)) { |
| 9990 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9991 | if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) |
| 9992 | found_decls.push_back(CompilerDecl(this, nd)); |
| 9993 | } |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9994 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9995 | } |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9996 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9997 | } |
| 9998 | return found_decls; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9999 | } |
| 10000 | |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10001 | // Look for child_decl_ctx's lookup scope in frame_decl_ctx and its parents, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10002 | // and return the number of levels it took to find it, or |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 10003 | // LLDB_INVALID_DECL_LEVEL if not found. If the decl was imported via a using |
| 10004 | // declaration, its name and/or type, if set, will be used to check that the |
| 10005 | // decl found in the scope is a match. |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10006 | // |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10007 | // The optional name is required by languages (like C++) to handle using |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 10008 | // declarations like: |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10009 | // |
| 10010 | // void poo(); |
| 10011 | // namespace ns { |
| 10012 | // void foo(); |
| 10013 | // void goo(); |
| 10014 | // } |
| 10015 | // void bar() { |
| 10016 | // using ns::foo; |
| 10017 | // // CountDeclLevels returns 0 for 'foo', 1 for 'poo', and |
| 10018 | // // LLDB_INVALID_DECL_LEVEL for 'goo'. |
| 10019 | // } |
| 10020 | // |
| 10021 | // The optional type is useful in the case that there's a specific overload |
| 10022 | // that we're looking for that might otherwise be shadowed, like: |
| 10023 | // |
| 10024 | // void foo(int); |
| 10025 | // namespace ns { |
| 10026 | // void foo(); |
| 10027 | // } |
| 10028 | // void bar() { |
| 10029 | // using ns::foo; |
| 10030 | // // CountDeclLevels returns 0 for { 'foo', void() }, |
| 10031 | // // 1 for { 'foo', void(int) }, and |
| 10032 | // // LLDB_INVALID_DECL_LEVEL for { 'foo', void(int, int) }. |
| 10033 | // } |
| 10034 | // |
| 10035 | // NOTE: Because file statics are at the TranslationUnit along with globals, a |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10036 | // function at file scope will return the same level as a function at global |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 10037 | // scope. Ideally we'd like to treat the file scope as an additional scope just |
| 10038 | // below the global scope. More work needs to be done to recognise that, if |
| 10039 | // the decl we're trying to look up is static, we should compare its source |
| 10040 | // file with that of the current scope and return a lower number for it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10041 | uint32_t ClangASTContext::CountDeclLevels(clang::DeclContext *frame_decl_ctx, |
| 10042 | clang::DeclContext *child_decl_ctx, |
| 10043 | ConstString *child_name, |
| 10044 | CompilerType *child_type) { |
| 10045 | if (frame_decl_ctx) { |
| 10046 | std::set<DeclContext *> searched; |
| 10047 | std::multimap<DeclContext *, DeclContext *> search_queue; |
| 10048 | SymbolFile *symbol_file = GetSymbolFile(); |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10049 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10050 | // Get the lookup scope for the decl we're trying to find. |
| 10051 | clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent(); |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10052 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10053 | // Look for it in our scope's decl context and its parents. |
| 10054 | uint32_t level = 0; |
| 10055 | for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx != nullptr; |
| 10056 | decl_ctx = decl_ctx->getParent()) { |
| 10057 | if (!decl_ctx->isLookupContext()) |
| 10058 | continue; |
| 10059 | if (decl_ctx == parent_decl_ctx) |
| 10060 | // Found it! |
| 10061 | return level; |
| 10062 | search_queue.insert(std::make_pair(decl_ctx, decl_ctx)); |
| 10063 | for (auto it = search_queue.find(decl_ctx); it != search_queue.end(); |
| 10064 | it++) { |
| 10065 | if (searched.find(it->second) != searched.end()) |
| 10066 | continue; |
| 10067 | |
| 10068 | // Currently DWARF has one shared translation unit for all Decls at top |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 10069 | // level, so this would erroneously find using statements anywhere. So |
| 10070 | // don't look at the top-level translation unit. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10071 | // TODO fix this and add a testcase that depends on it. |
| 10072 | |
| 10073 | if (llvm::isa<clang::TranslationUnitDecl>(it->second)) |
| 10074 | continue; |
| 10075 | |
| 10076 | searched.insert(it->second); |
| 10077 | symbol_file->ParseDeclsForContext( |
| 10078 | CompilerDeclContext(this, it->second)); |
| 10079 | |
| 10080 | for (clang::Decl *child : it->second->decls()) { |
| 10081 | if (clang::UsingDirectiveDecl *ud = |
| 10082 | llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) { |
| 10083 | clang::DeclContext *ns = ud->getNominatedNamespace(); |
| 10084 | if (ns == parent_decl_ctx) |
| 10085 | // Found it! |
| 10086 | return level; |
| 10087 | clang::DeclContext *from = ud->getCommonAncestor(); |
| 10088 | if (searched.find(ns) == searched.end()) |
| 10089 | search_queue.insert(std::make_pair(from, ns)); |
| 10090 | } else if (child_name) { |
| 10091 | if (clang::UsingDecl *ud = |
| 10092 | llvm::dyn_cast<clang::UsingDecl>(child)) { |
| 10093 | for (clang::UsingShadowDecl *usd : ud->shadows()) { |
| 10094 | clang::Decl *target = usd->getTargetDecl(); |
| 10095 | clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target); |
| 10096 | if (!nd) |
| 10097 | continue; |
| 10098 | // Check names. |
| 10099 | IdentifierInfo *ii = nd->getIdentifier(); |
| 10100 | if (ii == nullptr || |
| 10101 | !ii->getName().equals(child_name->AsCString(nullptr))) |
| 10102 | continue; |
| 10103 | // Check types, if one was provided. |
| 10104 | if (child_type) { |
| 10105 | CompilerType clang_type = ClangASTContext::GetTypeForDecl(nd); |
| 10106 | if (!AreTypesSame(clang_type, *child_type, |
| 10107 | /*ignore_qualifiers=*/true)) |
| 10108 | continue; |
| 10109 | } |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10110 | // Found it! |
| 10111 | return level; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10112 | } |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10113 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10114 | } |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10115 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10116 | } |
| 10117 | ++level; |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10118 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10119 | } |
| 10120 | return LLDB_INVALID_DECL_LEVEL; |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 10121 | } |
| 10122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10123 | bool ClangASTContext::DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) { |
| 10124 | if (opaque_decl_ctx) |
| 10125 | return ((clang::DeclContext *)opaque_decl_ctx)->isRecord(); |
| 10126 | else |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10127 | return false; |
| 10128 | } |
| 10129 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10130 | ConstString ClangASTContext::DeclContextGetName(void *opaque_decl_ctx) { |
| 10131 | if (opaque_decl_ctx) { |
| 10132 | clang::NamedDecl *named_decl = |
| 10133 | llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); |
| 10134 | if (named_decl) |
| 10135 | return ConstString(named_decl->getName()); |
| 10136 | } |
| 10137 | return ConstString(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10138 | } |
| 10139 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10140 | ConstString |
| 10141 | ClangASTContext::DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) { |
| 10142 | if (opaque_decl_ctx) { |
| 10143 | clang::NamedDecl *named_decl = |
| 10144 | llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); |
| 10145 | if (named_decl) |
| 10146 | return ConstString( |
| 10147 | llvm::StringRef(named_decl->getQualifiedNameAsString())); |
| 10148 | } |
| 10149 | return ConstString(); |
| 10150 | } |
| 10151 | |
| 10152 | bool ClangASTContext::DeclContextIsClassMethod( |
| 10153 | void *opaque_decl_ctx, lldb::LanguageType *language_ptr, |
| 10154 | bool *is_instance_method_ptr, ConstString *language_object_name_ptr) { |
| 10155 | if (opaque_decl_ctx) { |
| 10156 | clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx; |
| 10157 | if (ObjCMethodDecl *objc_method = |
| 10158 | llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx)) { |
| 10159 | if (is_instance_method_ptr) |
| 10160 | *is_instance_method_ptr = objc_method->isInstanceMethod(); |
| 10161 | if (language_ptr) |
| 10162 | *language_ptr = eLanguageTypeObjC; |
| 10163 | if (language_object_name_ptr) |
| 10164 | language_object_name_ptr->SetCString("self"); |
| 10165 | return true; |
| 10166 | } else if (CXXMethodDecl *cxx_method = |
| 10167 | llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx)) { |
| 10168 | if (is_instance_method_ptr) |
| 10169 | *is_instance_method_ptr = cxx_method->isInstance(); |
| 10170 | if (language_ptr) |
| 10171 | *language_ptr = eLanguageTypeC_plus_plus; |
| 10172 | if (language_object_name_ptr) |
| 10173 | language_object_name_ptr->SetCString("this"); |
| 10174 | return true; |
| 10175 | } else if (clang::FunctionDecl *function_decl = |
| 10176 | llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) { |
| 10177 | ClangASTMetadata *metadata = |
| 10178 | GetMetadata(&decl_ctx->getParentASTContext(), function_decl); |
| 10179 | if (metadata && metadata->HasObjectPtr()) { |
| 10180 | if (is_instance_method_ptr) |
| 10181 | *is_instance_method_ptr = true; |
| 10182 | if (language_ptr) |
| 10183 | *language_ptr = eLanguageTypeObjC; |
| 10184 | if (language_object_name_ptr) |
| 10185 | language_object_name_ptr->SetCString(metadata->GetObjectPtrName()); |
| 10186 | return true; |
| 10187 | } |
| 10188 | } |
| 10189 | } |
| 10190 | return false; |
| 10191 | } |
| 10192 | |
Raphael Isemann | a946997 | 2019-03-12 07:45:04 +0000 | [diff] [blame] | 10193 | bool ClangASTContext::DeclContextIsContainedInLookup( |
| 10194 | void *opaque_decl_ctx, void *other_opaque_decl_ctx) { |
| 10195 | auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx; |
| 10196 | auto *other = (clang::DeclContext *)other_opaque_decl_ctx; |
| 10197 | |
| 10198 | do { |
| 10199 | // A decl context always includes its own contents in its lookup. |
| 10200 | if (decl_ctx == other) |
| 10201 | return true; |
| 10202 | |
| 10203 | // If we have an inline namespace, then the lookup of the parent context |
| 10204 | // also includes the inline namespace contents. |
| 10205 | } while (other->isInlineNamespace() && (other = other->getParent())); |
| 10206 | |
| 10207 | return false; |
| 10208 | } |
| 10209 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10210 | clang::DeclContext * |
| 10211 | ClangASTContext::DeclContextGetAsDeclContext(const CompilerDeclContext &dc) { |
| 10212 | if (dc.IsClang()) |
| 10213 | return (clang::DeclContext *)dc.GetOpaqueDeclContext(); |
| 10214 | return nullptr; |
| 10215 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10216 | |
| 10217 | ObjCMethodDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10218 | ClangASTContext::DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc) { |
| 10219 | if (dc.IsClang()) |
| 10220 | return llvm::dyn_cast<clang::ObjCMethodDecl>( |
| 10221 | (clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 10222 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10223 | } |
| 10224 | |
| 10225 | CXXMethodDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10226 | ClangASTContext::DeclContextGetAsCXXMethodDecl(const CompilerDeclContext &dc) { |
| 10227 | if (dc.IsClang()) |
| 10228 | return llvm::dyn_cast<clang::CXXMethodDecl>( |
| 10229 | (clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 10230 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10231 | } |
| 10232 | |
| 10233 | clang::FunctionDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10234 | ClangASTContext::DeclContextGetAsFunctionDecl(const CompilerDeclContext &dc) { |
| 10235 | if (dc.IsClang()) |
| 10236 | return llvm::dyn_cast<clang::FunctionDecl>( |
| 10237 | (clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 10238 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10239 | } |
| 10240 | |
| 10241 | clang::NamespaceDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10242 | ClangASTContext::DeclContextGetAsNamespaceDecl(const CompilerDeclContext &dc) { |
| 10243 | if (dc.IsClang()) |
| 10244 | return llvm::dyn_cast<clang::NamespaceDecl>( |
| 10245 | (clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 10246 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10247 | } |
| 10248 | |
| 10249 | ClangASTMetadata * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10250 | ClangASTContext::DeclContextGetMetaData(const CompilerDeclContext &dc, |
| 10251 | const void *object) { |
| 10252 | clang::ASTContext *ast = DeclContextGetClangASTContext(dc); |
| 10253 | if (ast) |
| 10254 | return ClangASTContext::GetMetadata(ast, object); |
| 10255 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10256 | } |
| 10257 | |
| 10258 | clang::ASTContext * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10259 | ClangASTContext::DeclContextGetClangASTContext(const CompilerDeclContext &dc) { |
| 10260 | ClangASTContext *ast = |
| 10261 | llvm::dyn_cast_or_null<ClangASTContext>(dc.GetTypeSystem()); |
| 10262 | if (ast) |
| 10263 | return ast->getASTContext(); |
| 10264 | return nullptr; |
| 10265 | } |
| 10266 | |
Raphael Isemann | 2eb963a | 2019-10-02 12:26:08 +0000 | [diff] [blame] | 10267 | ClangASTContextForExpressions::ClangASTContextForExpressions(Target &target, |
| 10268 | ArchSpec arch) |
| 10269 | : ClangASTContext(arch), m_target_wp(target.shared_from_this()), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10270 | m_persistent_variables(new ClangPersistentVariables) {} |
| 10271 | |
| 10272 | UserExpression *ClangASTContextForExpressions::GetUserExpression( |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 10273 | llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10274 | Expression::ResultType desired_type, |
Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 10275 | const EvaluateExpressionOptions &options, |
| 10276 | ValueObject *ctx_obj) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10277 | TargetSP target_sp = m_target_wp.lock(); |
| 10278 | if (!target_sp) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10279 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10280 | |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 10281 | return new ClangUserExpression(*target_sp.get(), expr, prefix, language, |
Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 10282 | desired_type, options, ctx_obj); |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 10283 | } |
| 10284 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10285 | FunctionCaller *ClangASTContextForExpressions::GetFunctionCaller( |
| 10286 | const CompilerType &return_type, const Address &function_address, |
| 10287 | const ValueList &arg_value_list, const char *name) { |
| 10288 | TargetSP target_sp = m_target_wp.lock(); |
| 10289 | if (!target_sp) |
| 10290 | return nullptr; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10291 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10292 | Process *process = target_sp->GetProcessSP().get(); |
| 10293 | if (!process) |
| 10294 | return nullptr; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10295 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10296 | return new ClangFunctionCaller(*process, return_type, function_address, |
| 10297 | arg_value_list, name); |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10298 | } |
| 10299 | |
| 10300 | UtilityFunction * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10301 | ClangASTContextForExpressions::GetUtilityFunction(const char *text, |
| 10302 | const char *name) { |
| 10303 | TargetSP target_sp = m_target_wp.lock(); |
| 10304 | if (!target_sp) |
| 10305 | return nullptr; |
| 10306 | |
| 10307 | return new ClangUtilityFunction(*target_sp.get(), text, name); |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10308 | } |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 10309 | |
| 10310 | PersistentExpressionState * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10311 | ClangASTContextForExpressions::GetPersistentExpressionState() { |
| 10312 | return m_persistent_variables.get(); |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 10313 | } |
Sean Callanan | 68e4423 | 2017-09-28 20:20:25 +0000 | [diff] [blame] | 10314 | |
| 10315 | clang::ExternalASTMerger & |
| 10316 | ClangASTContextForExpressions::GetMergerUnchecked() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 10317 | lldbassert(m_scratch_ast_source_up != nullptr); |
| 10318 | return m_scratch_ast_source_up->GetMergerUnchecked(); |
Sean Callanan | 68e4423 | 2017-09-28 20:20:25 +0000 | [diff] [blame] | 10319 | } |