Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ClangASTContext.cpp -------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 10 | #include "lldb/Symbol/ClangASTContext.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 12 | #include "llvm/Support/FormatAdapters.h" |
| 13 | #include "llvm/Support/FormatVariadic.h" |
| 14 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | // C Includes |
| 16 | // C++ Includes |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 17 | #include <mutex> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include <string> |
Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame] | 19 | #include <vector> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | // Other libraries and framework includes |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | // 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] | 24 | // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 25 | // or another. This is bad because it means that if clang was built in release |
| 26 | // mode, it assumes that you are building in release mode which is not always |
| 27 | // the case. You can end up with functions that are defined as empty in header |
| 28 | // files when NDEBUG is not defined, and this can cause link errors with the |
| 29 | // clang .a files that you have since you might be missing functions in the .a |
| 30 | // file. So we have to define NDEBUG when including clang headers to avoid any |
| 31 | // mismatches. This is covered by rdar://problem/8691220 |
| 32 | |
Sean Callanan | 3b1d4f6 | 2011-10-26 17:46:51 +0000 | [diff] [blame] | 33 | #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 34 | #define LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 35 | #define NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 36 | // Need to include assert.h so it is as clang would expect it to be (disabled) |
| 37 | #include <assert.h> |
| 38 | #endif |
| 39 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "clang/AST/ASTContext.h" |
| 41 | #include "clang/AST/ASTImporter.h" |
Greg Clayton | f74c403 | 2012-12-03 18:29:55 +0000 | [diff] [blame] | 42 | #include "clang/AST/Attr.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "clang/AST/CXXInheritance.h" |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 44 | #include "clang/AST/DeclObjC.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 45 | #include "clang/AST/DeclTemplate.h" |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 46 | #include "clang/AST/Mangle.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | #include "clang/AST/RecordLayout.h" |
| 48 | #include "clang/AST/Type.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 49 | #include "clang/AST/VTableBuilder.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | #include "clang/Basic/Builtins.h" |
Sean Callanan | 7e2863b | 2012-02-06 21:28:03 +0000 | [diff] [blame] | 51 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | #include "clang/Basic/FileManager.h" |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 53 | #include "clang/Basic/FileSystemOptions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | #include "clang/Basic/SourceManager.h" |
| 55 | #include "clang/Basic/TargetInfo.h" |
| 56 | #include "clang/Basic/TargetOptions.h" |
| 57 | #include "clang/Frontend/FrontendOptions.h" |
| 58 | #include "clang/Frontend/LangStandard.h" |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 59 | |
| 60 | #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 61 | #undef NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 62 | #undef LLDB_DEFINED_NDEBUG_FOR_CLANG |
| 63 | // Need to re-include assert.h so it is as _we_ would expect it to be (enabled) |
| 64 | #include <assert.h> |
| 65 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 67 | #include "llvm/Support/Signals.h" |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 68 | #include "llvm/Support/Threading.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 69 | |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 70 | #include "Plugins/ExpressionParser/Clang/ClangFunctionCaller.h" |
| 71 | #include "Plugins/ExpressionParser/Clang/ClangUserExpression.h" |
| 72 | #include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h" |
Pavel Labath | 5f19b90 | 2017-11-13 16:16:33 +0000 | [diff] [blame] | 73 | #include "lldb/Utility/ArchSpec.h" |
Zachary Turner | 01c3243 | 2017-02-14 19:06:07 +0000 | [diff] [blame] | 74 | #include "lldb/Utility/Flags.h" |
| 75 | |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 76 | #include "lldb/Core/DumpDataExtractor.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 77 | #include "lldb/Core/Module.h" |
| 78 | #include "lldb/Core/PluginManager.h" |
Ulrich Weigand | 9521ad2 | 2016-04-15 09:55:52 +0000 | [diff] [blame] | 79 | #include "lldb/Core/Scalar.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 80 | #include "lldb/Core/StreamFile.h" |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 81 | #include "lldb/Core/ThreadSafeDenseMap.h" |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 82 | #include "lldb/Core/UniqueCStringMap.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 83 | #include "lldb/Symbol/ClangASTContext.h" |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 84 | #include "lldb/Symbol/ClangASTImporter.h" |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 85 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" |
Sean Callanan | 3b107b1 | 2011-12-03 03:15:28 +0000 | [diff] [blame] | 86 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 87 | #include "lldb/Symbol/ClangUtil.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 88 | #include "lldb/Symbol/ObjectFile.h" |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 89 | #include "lldb/Symbol/SymbolFile.h" |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 90 | #include "lldb/Symbol/VerifyDecl.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 91 | #include "lldb/Target/ExecutionContext.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 92 | #include "lldb/Target/Language.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 93 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 94 | #include "lldb/Target/Process.h" |
| 95 | #include "lldb/Target/Target.h" |
Zachary Turner | 666cc0b | 2017-03-04 01:30:05 +0000 | [diff] [blame] | 96 | #include "lldb/Utility/DataExtractor.h" |
Sean Callanan | c530ba9 | 2016-05-02 21:15:31 +0000 | [diff] [blame] | 97 | #include "lldb/Utility/LLDBAssert.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 98 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 99 | #include "lldb/Utility/RegularExpression.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 100 | |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 101 | #include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h" |
Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 102 | #include "Plugins/SymbolFile/PDB/PDBASTParser.h" |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 103 | |
Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 104 | #include <stdio.h> |
| 105 | |
Greg Clayton | 1341baf | 2013-07-11 23:36:31 +0000 | [diff] [blame] | 106 | #include <mutex> |
| 107 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 108 | using namespace lldb; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | using namespace lldb_private; |
| 110 | using namespace llvm; |
| 111 | using namespace clang; |
| 112 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | namespace { |
| 114 | static inline bool |
| 115 | ClangASTContextSupportsLanguage(lldb::LanguageType language) { |
| 116 | return language == eLanguageTypeUnknown || // Clang is the default type system |
| 117 | Language::LanguageIsC(language) || |
| 118 | Language::LanguageIsCPlusPlus(language) || |
| 119 | Language::LanguageIsObjC(language) || |
| 120 | Language::LanguageIsPascal(language) || |
| 121 | // Use Clang for Rust until there is a proper language plugin for it |
| 122 | language == eLanguageTypeRust || |
Johan Engelen | 0479957 | 2016-11-25 11:01:12 +0000 | [diff] [blame] | 123 | language == eLanguageTypeExtRenderScript || |
| 124 | // Use Clang for D until there is a proper language plugin for it |
| 125 | language == eLanguageTypeD; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, ClangASTContext *> |
| 130 | ClangASTMap; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | static ClangASTMap &GetASTMap() { |
| 133 | static ClangASTMap *g_map_ptr = nullptr; |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 134 | static llvm::once_flag g_once_flag; |
| 135 | llvm::call_once(g_once_flag, []() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 136 | g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins |
| 137 | }); |
| 138 | return *g_map_ptr; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Davide Italiano | 7e3ef4d | 2018-03-20 19:46:32 +0000 | [diff] [blame] | 141 | bool ClangASTContext::IsOperator(const char *name, |
| 142 | clang::OverloadedOperatorKind &op_kind) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 143 | if (name == nullptr || name[0] == '\0') |
| 144 | return false; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 145 | |
| 146 | #define OPERATOR_PREFIX "operator" |
| 147 | #define OPERATOR_PREFIX_LENGTH (sizeof(OPERATOR_PREFIX) - 1) |
| 148 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 149 | const char *post_op_name = nullptr; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 150 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 151 | bool no_space = true; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 152 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | if (::strncmp(name, OPERATOR_PREFIX, OPERATOR_PREFIX_LENGTH)) |
| 154 | return false; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 155 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 156 | post_op_name = name + OPERATOR_PREFIX_LENGTH; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | if (post_op_name[0] == ' ') { |
| 159 | post_op_name++; |
| 160 | no_space = false; |
| 161 | } |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 162 | |
| 163 | #undef OPERATOR_PREFIX |
| 164 | #undef OPERATOR_PREFIX_LENGTH |
| 165 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | // This is an operator, set the overloaded operator kind to invalid |
| 167 | // in case this is a conversion operator... |
| 168 | op_kind = clang::NUM_OVERLOADED_OPERATORS; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 169 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 170 | switch (post_op_name[0]) { |
| 171 | default: |
| 172 | if (no_space) |
| 173 | return false; |
| 174 | break; |
| 175 | case 'n': |
| 176 | if (no_space) |
| 177 | return false; |
| 178 | if (strcmp(post_op_name, "new") == 0) |
| 179 | op_kind = clang::OO_New; |
| 180 | else if (strcmp(post_op_name, "new[]") == 0) |
| 181 | op_kind = clang::OO_Array_New; |
| 182 | break; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 183 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | case 'd': |
| 185 | if (no_space) |
| 186 | return false; |
| 187 | if (strcmp(post_op_name, "delete") == 0) |
| 188 | op_kind = clang::OO_Delete; |
| 189 | else if (strcmp(post_op_name, "delete[]") == 0) |
| 190 | op_kind = clang::OO_Array_Delete; |
| 191 | break; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 192 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 193 | case '+': |
| 194 | if (post_op_name[1] == '\0') |
| 195 | op_kind = clang::OO_Plus; |
| 196 | else if (post_op_name[2] == '\0') { |
| 197 | if (post_op_name[1] == '=') |
| 198 | op_kind = clang::OO_PlusEqual; |
| 199 | else if (post_op_name[1] == '+') |
| 200 | op_kind = clang::OO_PlusPlus; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 201 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 202 | break; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 203 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | case '-': |
| 205 | if (post_op_name[1] == '\0') |
| 206 | op_kind = clang::OO_Minus; |
| 207 | else if (post_op_name[2] == '\0') { |
| 208 | switch (post_op_name[1]) { |
| 209 | case '=': |
| 210 | op_kind = clang::OO_MinusEqual; |
| 211 | break; |
| 212 | case '-': |
| 213 | op_kind = clang::OO_MinusMinus; |
| 214 | break; |
| 215 | case '>': |
| 216 | op_kind = clang::OO_Arrow; |
| 217 | break; |
| 218 | } |
| 219 | } else if (post_op_name[3] == '\0') { |
| 220 | if (post_op_name[2] == '*') |
| 221 | op_kind = clang::OO_ArrowStar; |
| 222 | break; |
| 223 | } |
| 224 | break; |
| 225 | |
| 226 | case '*': |
| 227 | if (post_op_name[1] == '\0') |
| 228 | op_kind = clang::OO_Star; |
| 229 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 230 | op_kind = clang::OO_StarEqual; |
| 231 | break; |
| 232 | |
| 233 | case '/': |
| 234 | if (post_op_name[1] == '\0') |
| 235 | op_kind = clang::OO_Slash; |
| 236 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 237 | op_kind = clang::OO_SlashEqual; |
| 238 | break; |
| 239 | |
| 240 | case '%': |
| 241 | if (post_op_name[1] == '\0') |
| 242 | op_kind = clang::OO_Percent; |
| 243 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 244 | op_kind = clang::OO_PercentEqual; |
| 245 | break; |
| 246 | |
| 247 | case '^': |
| 248 | if (post_op_name[1] == '\0') |
| 249 | op_kind = clang::OO_Caret; |
| 250 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 251 | op_kind = clang::OO_CaretEqual; |
| 252 | break; |
| 253 | |
| 254 | case '&': |
| 255 | if (post_op_name[1] == '\0') |
| 256 | op_kind = clang::OO_Amp; |
| 257 | else if (post_op_name[2] == '\0') { |
| 258 | switch (post_op_name[1]) { |
| 259 | case '=': |
| 260 | op_kind = clang::OO_AmpEqual; |
| 261 | break; |
| 262 | case '&': |
| 263 | op_kind = clang::OO_AmpAmp; |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | break; |
| 268 | |
| 269 | case '|': |
| 270 | if (post_op_name[1] == '\0') |
| 271 | op_kind = clang::OO_Pipe; |
| 272 | else if (post_op_name[2] == '\0') { |
| 273 | switch (post_op_name[1]) { |
| 274 | case '=': |
| 275 | op_kind = clang::OO_PipeEqual; |
| 276 | break; |
| 277 | case '|': |
| 278 | op_kind = clang::OO_PipePipe; |
| 279 | break; |
| 280 | } |
| 281 | } |
| 282 | break; |
| 283 | |
| 284 | case '~': |
| 285 | if (post_op_name[1] == '\0') |
| 286 | op_kind = clang::OO_Tilde; |
| 287 | break; |
| 288 | |
| 289 | case '!': |
| 290 | if (post_op_name[1] == '\0') |
| 291 | op_kind = clang::OO_Exclaim; |
| 292 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 293 | op_kind = clang::OO_ExclaimEqual; |
| 294 | break; |
| 295 | |
| 296 | case '=': |
| 297 | if (post_op_name[1] == '\0') |
| 298 | op_kind = clang::OO_Equal; |
| 299 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 300 | op_kind = clang::OO_EqualEqual; |
| 301 | break; |
| 302 | |
| 303 | case '<': |
| 304 | if (post_op_name[1] == '\0') |
| 305 | op_kind = clang::OO_Less; |
| 306 | else if (post_op_name[2] == '\0') { |
| 307 | switch (post_op_name[1]) { |
| 308 | case '<': |
| 309 | op_kind = clang::OO_LessLess; |
| 310 | break; |
| 311 | case '=': |
| 312 | op_kind = clang::OO_LessEqual; |
| 313 | break; |
| 314 | } |
| 315 | } else if (post_op_name[3] == '\0') { |
| 316 | if (post_op_name[2] == '=') |
| 317 | op_kind = clang::OO_LessLessEqual; |
| 318 | } |
| 319 | break; |
| 320 | |
| 321 | case '>': |
| 322 | if (post_op_name[1] == '\0') |
| 323 | op_kind = clang::OO_Greater; |
| 324 | else if (post_op_name[2] == '\0') { |
| 325 | switch (post_op_name[1]) { |
| 326 | case '>': |
| 327 | op_kind = clang::OO_GreaterGreater; |
| 328 | break; |
| 329 | case '=': |
| 330 | op_kind = clang::OO_GreaterEqual; |
| 331 | break; |
| 332 | } |
| 333 | } else if (post_op_name[1] == '>' && post_op_name[2] == '=' && |
| 334 | post_op_name[3] == '\0') { |
| 335 | op_kind = clang::OO_GreaterGreaterEqual; |
| 336 | } |
| 337 | break; |
| 338 | |
| 339 | case ',': |
| 340 | if (post_op_name[1] == '\0') |
| 341 | op_kind = clang::OO_Comma; |
| 342 | break; |
| 343 | |
| 344 | case '(': |
| 345 | if (post_op_name[1] == ')' && post_op_name[2] == '\0') |
| 346 | op_kind = clang::OO_Call; |
| 347 | break; |
| 348 | |
| 349 | case '[': |
| 350 | if (post_op_name[1] == ']' && post_op_name[2] == '\0') |
| 351 | op_kind = clang::OO_Subscript; |
| 352 | break; |
| 353 | } |
| 354 | |
| 355 | return true; |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 356 | } |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 357 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 358 | clang::AccessSpecifier |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 359 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(AccessType access) { |
| 360 | switch (access) { |
| 361 | default: |
| 362 | break; |
| 363 | case eAccessNone: |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 364 | return AS_none; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 365 | case eAccessPublic: |
| 366 | return AS_public; |
| 367 | case eAccessPrivate: |
| 368 | return AS_private; |
| 369 | case eAccessProtected: |
| 370 | return AS_protected; |
| 371 | } |
| 372 | return AS_none; |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 375 | static void ParseLangArgs(LangOptions &Opts, InputKind IK, const char *triple) { |
| 376 | // FIXME: Cleanup per-file based stuff. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 377 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 378 | // Set some properties which depend solely on the input kind; it would be nice |
| 379 | // to move these to the language standard, and have the driver resolve the |
| 380 | // input kind + language standard. |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 381 | if (IK.getLanguage() == InputKind::Asm) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 382 | Opts.AsmPreprocessor = 1; |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 383 | } else if (IK.isObjectiveC()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 384 | Opts.ObjC1 = Opts.ObjC2 = 1; |
| 385 | } |
| 386 | |
| 387 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 388 | |
| 389 | if (LangStd == LangStandard::lang_unspecified) { |
| 390 | // Based on the base language, pick one. |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 391 | switch (IK.getLanguage()) { |
| 392 | case InputKind::Unknown: |
| 393 | case InputKind::LLVM_IR: |
| 394 | case InputKind::RenderScript: |
David Blaikie | a322f36 | 2017-01-06 00:38:06 +0000 | [diff] [blame] | 395 | llvm_unreachable("Invalid input kind!"); |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 396 | case InputKind::OpenCL: |
Pavel Labath | 4716854 | 2017-04-27 08:49:19 +0000 | [diff] [blame] | 397 | LangStd = LangStandard::lang_opencl10; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | break; |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 399 | case InputKind::CUDA: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 400 | LangStd = LangStandard::lang_cuda; |
| 401 | break; |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 402 | case InputKind::Asm: |
| 403 | case InputKind::C: |
| 404 | case InputKind::ObjC: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 405 | LangStd = LangStandard::lang_gnu99; |
| 406 | break; |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 407 | case InputKind::CXX: |
| 408 | case InputKind::ObjCXX: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 409 | LangStd = LangStandard::lang_gnucxx98; |
| 410 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 412 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 414 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
| 415 | Opts.LineComment = Std.hasLineComments(); |
| 416 | Opts.C99 = Std.isC99(); |
| 417 | Opts.CPlusPlus = Std.isCPlusPlus(); |
| 418 | Opts.CPlusPlus11 = Std.isCPlusPlus11(); |
| 419 | Opts.Digraphs = Std.hasDigraphs(); |
| 420 | Opts.GNUMode = Std.isGNUMode(); |
| 421 | Opts.GNUInline = !Std.isC99(); |
| 422 | Opts.HexFloats = Std.hasHexFloats(); |
| 423 | Opts.ImplicitInt = Std.hasImplicitInt(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 425 | Opts.WChar = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 427 | // OpenCL has some additional defaults. |
Pavel Labath | 4716854 | 2017-04-27 08:49:19 +0000 | [diff] [blame] | 428 | if (LangStd == LangStandard::lang_opencl10) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 429 | Opts.OpenCL = 1; |
| 430 | Opts.AltiVec = 1; |
| 431 | Opts.CXXOperatorNames = 1; |
| 432 | Opts.LaxVectorConversions = 1; |
| 433 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 435 | // OpenCL and C++ both have bool, true, false keywords. |
| 436 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 437 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 438 | Opts.setValueVisibilityMode(DefaultVisibility); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 440 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 441 | // is specified, or -std is set to a conforming mode. |
| 442 | Opts.Trigraphs = !Opts.GNUMode; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | Opts.CharIsSigned = ArchSpec(triple).CharIsSignedByDefault(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 444 | Opts.OptimizeSize = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 445 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 446 | // FIXME: Eliminate this dependency. |
| 447 | // unsigned Opt = |
| 448 | // Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags); |
| 449 | // Opts.Optimize = Opt != 0; |
| 450 | unsigned Opt = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 451 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 452 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 453 | // optimization level and -fno-inline, not actually whether the backend has |
| 454 | // inlining enabled. |
| 455 | // |
| 456 | // FIXME: This is affected by other options (-fno-inline). |
| 457 | Opts.NoInlineDefine = !Opt; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 460 | ClangASTContext::ClangASTContext(const char *target_triple) |
| 461 | : TypeSystem(TypeSystem::eKindClang), m_target_triple(), m_ast_ap(), |
| 462 | m_language_options_ap(), m_source_manager_ap(), m_diagnostics_engine_ap(), |
| 463 | m_target_options_rp(), m_target_info_ap(), m_identifier_table_ap(), |
| 464 | m_selector_table_ap(), m_builtins_ap(), m_callback_tag_decl(nullptr), |
| 465 | m_callback_objc_decl(nullptr), m_callback_baton(nullptr), |
| 466 | m_pointer_byte_size(0), m_ast_owned(false) { |
| 467 | if (target_triple && target_triple[0]) |
| 468 | SetTargetTriple(target_triple); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | //---------------------------------------------------------------------- |
| 472 | // Destructor |
| 473 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 474 | ClangASTContext::~ClangASTContext() { Finalize(); } |
| 475 | |
| 476 | ConstString ClangASTContext::GetPluginNameStatic() { |
| 477 | return ConstString("clang"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 480 | ConstString ClangASTContext::GetPluginName() { |
| 481 | return ClangASTContext::GetPluginNameStatic(); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 484 | uint32_t ClangASTContext::GetPluginVersion() { return 1; } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 485 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 486 | lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language, |
| 487 | lldb_private::Module *module, |
| 488 | Target *target) { |
| 489 | if (ClangASTContextSupportsLanguage(language)) { |
| 490 | ArchSpec arch; |
| 491 | if (module) |
| 492 | arch = module->GetArchitecture(); |
| 493 | else if (target) |
| 494 | arch = target->GetArchitecture(); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 495 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 496 | if (arch.IsValid()) { |
| 497 | ArchSpec fixed_arch = arch; |
| 498 | // LLVM wants this to be set to iOS or MacOSX; if we're working on |
| 499 | // a bare-boards type image, change the triple for llvm's benefit. |
| 500 | if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple && |
| 501 | fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) { |
| 502 | if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm || |
| 503 | fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 || |
| 504 | fixed_arch.GetTriple().getArch() == llvm::Triple::thumb) { |
| 505 | fixed_arch.GetTriple().setOS(llvm::Triple::IOS); |
| 506 | } else { |
| 507 | fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 508 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 509 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 510 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 511 | if (module) { |
| 512 | std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext); |
| 513 | if (ast_sp) { |
| 514 | ast_sp->SetArchitecture(fixed_arch); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 515 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 516 | return ast_sp; |
| 517 | } else if (target && target->IsValid()) { |
| 518 | std::shared_ptr<ClangASTContextForExpressions> ast_sp( |
| 519 | new ClangASTContextForExpressions(*target)); |
| 520 | if (ast_sp) { |
| 521 | ast_sp->SetArchitecture(fixed_arch); |
| 522 | ast_sp->m_scratch_ast_source_ap.reset( |
| 523 | new ClangASTSource(target->shared_from_this())); |
Sean Callanan | 68e4423 | 2017-09-28 20:20:25 +0000 | [diff] [blame] | 524 | lldbassert(ast_sp->getFileManager()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 525 | ast_sp->m_scratch_ast_source_ap->InstallASTContext( |
Sean Callanan | 68e4423 | 2017-09-28 20:20:25 +0000 | [diff] [blame] | 526 | *ast_sp->getASTContext(), *ast_sp->getFileManager(), true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 527 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source( |
| 528 | ast_sp->m_scratch_ast_source_ap->CreateProxy()); |
| 529 | ast_sp->SetExternalSource(proxy_ast_source); |
| 530 | return ast_sp; |
| 531 | } |
| 532 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 533 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 534 | } |
| 535 | return lldb::TypeSystemSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 538 | void ClangASTContext::EnumerateSupportedLanguages( |
| 539 | std::set<lldb::LanguageType> &languages_for_types, |
| 540 | std::set<lldb::LanguageType> &languages_for_expressions) { |
| 541 | static std::vector<lldb::LanguageType> s_supported_languages_for_types( |
| 542 | {lldb::eLanguageTypeC89, lldb::eLanguageTypeC, lldb::eLanguageTypeC11, |
| 543 | lldb::eLanguageTypeC_plus_plus, lldb::eLanguageTypeC99, |
| 544 | lldb::eLanguageTypeObjC, lldb::eLanguageTypeObjC_plus_plus, |
| 545 | lldb::eLanguageTypeC_plus_plus_03, lldb::eLanguageTypeC_plus_plus_11, |
| 546 | lldb::eLanguageTypeC11, lldb::eLanguageTypeC_plus_plus_14}); |
| 547 | |
| 548 | static std::vector<lldb::LanguageType> s_supported_languages_for_expressions( |
| 549 | {lldb::eLanguageTypeC_plus_plus, lldb::eLanguageTypeObjC_plus_plus, |
| 550 | lldb::eLanguageTypeC_plus_plus_03, lldb::eLanguageTypeC_plus_plus_11, |
| 551 | lldb::eLanguageTypeC_plus_plus_14}); |
| 552 | |
| 553 | languages_for_types.insert(s_supported_languages_for_types.begin(), |
| 554 | s_supported_languages_for_types.end()); |
| 555 | languages_for_expressions.insert( |
| 556 | s_supported_languages_for_expressions.begin(), |
| 557 | s_supported_languages_for_expressions.end()); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 560 | void ClangASTContext::Initialize() { |
| 561 | PluginManager::RegisterPlugin(GetPluginNameStatic(), |
| 562 | "clang base AST context plug-in", |
| 563 | CreateInstance, EnumerateSupportedLanguages); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 566 | void ClangASTContext::Terminate() { |
| 567 | PluginManager::UnregisterPlugin(CreateInstance); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 570 | void ClangASTContext::Finalize() { |
| 571 | if (m_ast_ap.get()) { |
| 572 | GetASTMap().Erase(m_ast_ap.get()); |
| 573 | if (!m_ast_owned) |
| 574 | m_ast_ap.release(); |
| 575 | } |
| 576 | |
| 577 | m_builtins_ap.reset(); |
| 578 | m_selector_table_ap.reset(); |
| 579 | m_identifier_table_ap.reset(); |
| 580 | m_target_info_ap.reset(); |
| 581 | m_target_options_rp.reset(); |
| 582 | m_diagnostics_engine_ap.reset(); |
| 583 | m_source_manager_ap.reset(); |
| 584 | m_language_options_ap.reset(); |
| 585 | m_ast_ap.reset(); |
| 586 | m_scratch_ast_source_ap.reset(); |
| 587 | } |
| 588 | |
| 589 | void ClangASTContext::Clear() { |
| 590 | m_ast_ap.reset(); |
| 591 | m_language_options_ap.reset(); |
| 592 | m_source_manager_ap.reset(); |
| 593 | m_diagnostics_engine_ap.reset(); |
| 594 | m_target_options_rp.reset(); |
| 595 | m_target_info_ap.reset(); |
| 596 | m_identifier_table_ap.reset(); |
| 597 | m_selector_table_ap.reset(); |
| 598 | m_builtins_ap.reset(); |
| 599 | m_pointer_byte_size = 0; |
| 600 | } |
| 601 | |
| 602 | const char *ClangASTContext::GetTargetTriple() { |
| 603 | return m_target_triple.c_str(); |
| 604 | } |
| 605 | |
| 606 | void ClangASTContext::SetTargetTriple(const char *target_triple) { |
| 607 | Clear(); |
| 608 | m_target_triple.assign(target_triple); |
| 609 | } |
| 610 | |
| 611 | void ClangASTContext::SetArchitecture(const ArchSpec &arch) { |
| 612 | SetTargetTriple(arch.GetTriple().str().c_str()); |
| 613 | } |
| 614 | |
| 615 | bool ClangASTContext::HasExternalSource() { |
| 616 | ASTContext *ast = getASTContext(); |
| 617 | if (ast) |
| 618 | return ast->getExternalSource() != nullptr; |
| 619 | return false; |
| 620 | } |
| 621 | |
| 622 | void ClangASTContext::SetExternalSource( |
| 623 | llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_ap) { |
| 624 | ASTContext *ast = getASTContext(); |
| 625 | if (ast) { |
| 626 | ast->setExternalSource(ast_source_ap); |
| 627 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true); |
| 628 | // ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(true); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | void ClangASTContext::RemoveExternalSource() { |
| 633 | ASTContext *ast = getASTContext(); |
| 634 | |
| 635 | if (ast) { |
| 636 | llvm::IntrusiveRefCntPtr<ExternalASTSource> empty_ast_source_ap; |
| 637 | ast->setExternalSource(empty_ast_source_ap); |
| 638 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(false); |
| 639 | // ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(false); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | void ClangASTContext::setASTContext(clang::ASTContext *ast_ctx) { |
| 644 | if (!m_ast_owned) { |
| 645 | m_ast_ap.release(); |
| 646 | } |
| 647 | m_ast_owned = false; |
| 648 | m_ast_ap.reset(ast_ctx); |
| 649 | GetASTMap().Insert(ast_ctx, this); |
| 650 | } |
| 651 | |
| 652 | ASTContext *ClangASTContext::getASTContext() { |
| 653 | if (m_ast_ap.get() == nullptr) { |
| 654 | m_ast_owned = true; |
| 655 | m_ast_ap.reset(new ASTContext(*getLanguageOptions(), *getSourceManager(), |
| 656 | *getIdentifierTable(), *getSelectorTable(), |
| 657 | *getBuiltinContext())); |
| 658 | |
| 659 | m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false); |
| 660 | |
| 661 | // This can be NULL if we don't know anything about the architecture or if |
| 662 | // the |
| 663 | // target for an architecture isn't enabled in the llvm/clang that we built |
| 664 | TargetInfo *target_info = getTargetInfo(); |
| 665 | if (target_info) |
| 666 | m_ast_ap->InitBuiltinTypes(*target_info); |
| 667 | |
| 668 | if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton) { |
| 669 | m_ast_ap->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
| 670 | // m_ast_ap->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 672 | |
| 673 | GetASTMap().Insert(m_ast_ap.get(), this); |
| 674 | |
| 675 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap( |
| 676 | new ClangExternalASTSourceCallbacks( |
| 677 | ClangASTContext::CompleteTagDecl, |
| 678 | ClangASTContext::CompleteObjCInterfaceDecl, nullptr, |
| 679 | ClangASTContext::LayoutRecordType, this)); |
| 680 | SetExternalSource(ast_source_ap); |
| 681 | } |
| 682 | return m_ast_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 685 | ClangASTContext *ClangASTContext::GetASTContext(clang::ASTContext *ast) { |
| 686 | ClangASTContext *clang_ast = GetASTMap().Lookup(ast); |
| 687 | return clang_ast; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 690 | Builtin::Context *ClangASTContext::getBuiltinContext() { |
| 691 | if (m_builtins_ap.get() == nullptr) |
| 692 | m_builtins_ap.reset(new Builtin::Context()); |
| 693 | return m_builtins_ap.get(); |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 696 | IdentifierTable *ClangASTContext::getIdentifierTable() { |
| 697 | if (m_identifier_table_ap.get() == nullptr) |
| 698 | m_identifier_table_ap.reset( |
| 699 | new IdentifierTable(*ClangASTContext::getLanguageOptions(), nullptr)); |
| 700 | return m_identifier_table_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 703 | LangOptions *ClangASTContext::getLanguageOptions() { |
| 704 | if (m_language_options_ap.get() == nullptr) { |
| 705 | m_language_options_ap.reset(new LangOptions()); |
Richard Smith | 8186cd4 | 2017-04-26 22:10:53 +0000 | [diff] [blame] | 706 | ParseLangArgs(*m_language_options_ap, InputKind::ObjCXX, GetTargetTriple()); |
| 707 | // InitializeLangOptions(*m_language_options_ap, InputKind::ObjCXX); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 708 | } |
| 709 | return m_language_options_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 712 | SelectorTable *ClangASTContext::getSelectorTable() { |
| 713 | if (m_selector_table_ap.get() == nullptr) |
| 714 | m_selector_table_ap.reset(new SelectorTable()); |
| 715 | return m_selector_table_ap.get(); |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 718 | clang::FileManager *ClangASTContext::getFileManager() { |
| 719 | if (m_file_manager_ap.get() == nullptr) { |
| 720 | clang::FileSystemOptions file_system_options; |
| 721 | m_file_manager_ap.reset(new clang::FileManager(file_system_options)); |
| 722 | } |
| 723 | return m_file_manager_ap.get(); |
| 724 | } |
| 725 | |
| 726 | clang::SourceManager *ClangASTContext::getSourceManager() { |
| 727 | if (m_source_manager_ap.get() == nullptr) |
| 728 | m_source_manager_ap.reset( |
| 729 | new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager())); |
| 730 | return m_source_manager_ap.get(); |
| 731 | } |
| 732 | |
| 733 | clang::DiagnosticsEngine *ClangASTContext::getDiagnosticsEngine() { |
| 734 | if (m_diagnostics_engine_ap.get() == nullptr) { |
| 735 | llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs()); |
| 736 | m_diagnostics_engine_ap.reset( |
| 737 | new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions())); |
| 738 | } |
| 739 | return m_diagnostics_engine_ap.get(); |
| 740 | } |
| 741 | |
| 742 | clang::MangleContext *ClangASTContext::getMangleContext() { |
| 743 | if (m_mangle_ctx_ap.get() == nullptr) |
| 744 | m_mangle_ctx_ap.reset(getASTContext()->createMangleContext()); |
| 745 | return m_mangle_ctx_ap.get(); |
| 746 | } |
| 747 | |
| 748 | class NullDiagnosticConsumer : public DiagnosticConsumer { |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 749 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 750 | NullDiagnosticConsumer() { |
| 751 | m_log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); |
| 752 | } |
Sean Callanan | 579e70c | 2016-03-19 00:03:59 +0000 | [diff] [blame] | 753 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 754 | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
| 755 | const clang::Diagnostic &info) { |
| 756 | if (m_log) { |
| 757 | llvm::SmallVector<char, 32> diag_str(10); |
| 758 | info.FormatDiagnostic(diag_str); |
| 759 | diag_str.push_back('\0'); |
| 760 | m_log->Printf("Compiler diagnostic: %s\n", diag_str.data()); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 761 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const { |
| 765 | return new NullDiagnosticConsumer(); |
| 766 | } |
| 767 | |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 768 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 769 | Log *m_log; |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 770 | }; |
| 771 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 772 | DiagnosticConsumer *ClangASTContext::getDiagnosticConsumer() { |
| 773 | if (m_diagnostic_consumer_ap.get() == nullptr) |
| 774 | m_diagnostic_consumer_ap.reset(new NullDiagnosticConsumer); |
| 775 | |
| 776 | return m_diagnostic_consumer_ap.get(); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 779 | std::shared_ptr<clang::TargetOptions> &ClangASTContext::getTargetOptions() { |
| 780 | if (m_target_options_rp.get() == nullptr && !m_target_triple.empty()) { |
| 781 | m_target_options_rp = std::make_shared<clang::TargetOptions>(); |
| 782 | if (m_target_options_rp.get() != nullptr) |
| 783 | m_target_options_rp->Triple = m_target_triple; |
| 784 | } |
| 785 | return m_target_options_rp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 788 | TargetInfo *ClangASTContext::getTargetInfo() { |
| 789 | // target_triple should be something like "x86_64-apple-macosx" |
| 790 | if (m_target_info_ap.get() == nullptr && !m_target_triple.empty()) |
| 791 | m_target_info_ap.reset(TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(), |
| 792 | getTargetOptions())); |
| 793 | return m_target_info_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | #pragma mark Basic Types |
| 797 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 798 | static inline bool QualTypeMatchesBitSize(const uint64_t bit_size, |
| 799 | ASTContext *ast, QualType qual_type) { |
| 800 | uint64_t qual_type_bit_size = ast->getTypeSize(qual_type); |
| 801 | if (qual_type_bit_size == bit_size) |
| 802 | return true; |
| 803 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 804 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 805 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 806 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 807 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding, |
| 808 | size_t bit_size) { |
| 809 | return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize( |
| 810 | getASTContext(), encoding, bit_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 813 | CompilerType ClangASTContext::GetBuiltinTypeForEncodingAndBitSize( |
| 814 | ASTContext *ast, Encoding encoding, uint32_t bit_size) { |
| 815 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 816 | return CompilerType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 817 | switch (encoding) { |
| 818 | case eEncodingInvalid: |
| 819 | if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy)) |
| 820 | return CompilerType(ast, ast->VoidPtrTy); |
| 821 | break; |
| 822 | |
| 823 | case eEncodingUint: |
| 824 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
| 825 | return CompilerType(ast, ast->UnsignedCharTy); |
| 826 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
| 827 | return CompilerType(ast, ast->UnsignedShortTy); |
| 828 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy)) |
| 829 | return CompilerType(ast, ast->UnsignedIntTy); |
| 830 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy)) |
| 831 | return CompilerType(ast, ast->UnsignedLongTy); |
| 832 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy)) |
| 833 | return CompilerType(ast, ast->UnsignedLongLongTy); |
| 834 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty)) |
| 835 | return CompilerType(ast, ast->UnsignedInt128Ty); |
| 836 | break; |
| 837 | |
| 838 | case eEncodingSint: |
| 839 | if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy)) |
| 840 | return CompilerType(ast, ast->SignedCharTy); |
| 841 | if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy)) |
| 842 | return CompilerType(ast, ast->ShortTy); |
| 843 | if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy)) |
| 844 | return CompilerType(ast, ast->IntTy); |
| 845 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy)) |
| 846 | return CompilerType(ast, ast->LongTy); |
| 847 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy)) |
| 848 | return CompilerType(ast, ast->LongLongTy); |
| 849 | if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty)) |
| 850 | return CompilerType(ast, ast->Int128Ty); |
| 851 | break; |
| 852 | |
| 853 | case eEncodingIEEE754: |
| 854 | if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy)) |
| 855 | return CompilerType(ast, ast->FloatTy); |
| 856 | if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy)) |
| 857 | return CompilerType(ast, ast->DoubleTy); |
| 858 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy)) |
| 859 | return CompilerType(ast, ast->LongDoubleTy); |
| 860 | if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy)) |
| 861 | return CompilerType(ast, ast->HalfTy); |
| 862 | break; |
| 863 | |
| 864 | case eEncodingVector: |
| 865 | // Sanity check that bit_size is a multiple of 8's. |
| 866 | if (bit_size && !(bit_size & 0x7u)) |
| 867 | return CompilerType( |
| 868 | ast, ast->getExtVectorType(ast->UnsignedCharTy, bit_size / 8)); |
| 869 | break; |
| 870 | } |
| 871 | |
| 872 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 875 | lldb::BasicType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 876 | ClangASTContext::GetBasicTypeEnumeration(const ConstString &name) { |
| 877 | if (name) { |
| 878 | typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; |
| 879 | static TypeNameToBasicTypeMap g_type_map; |
Kamil Rytarowski | c5f28e2 | 2017-02-06 17:55:02 +0000 | [diff] [blame] | 880 | static llvm::once_flag g_once_flag; |
| 881 | llvm::call_once(g_once_flag, []() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 882 | // "void" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 883 | g_type_map.Append(ConstString("void"), eBasicTypeVoid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 884 | |
| 885 | // "char" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 886 | g_type_map.Append(ConstString("char"), eBasicTypeChar); |
| 887 | g_type_map.Append(ConstString("signed char"), eBasicTypeSignedChar); |
| 888 | g_type_map.Append(ConstString("unsigned char"), eBasicTypeUnsignedChar); |
| 889 | g_type_map.Append(ConstString("wchar_t"), eBasicTypeWChar); |
| 890 | g_type_map.Append(ConstString("signed wchar_t"), eBasicTypeSignedWChar); |
| 891 | g_type_map.Append(ConstString("unsigned wchar_t"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 892 | eBasicTypeUnsignedWChar); |
| 893 | // "short" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 894 | g_type_map.Append(ConstString("short"), eBasicTypeShort); |
| 895 | g_type_map.Append(ConstString("short int"), eBasicTypeShort); |
| 896 | g_type_map.Append(ConstString("unsigned short"), eBasicTypeUnsignedShort); |
| 897 | g_type_map.Append(ConstString("unsigned short int"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 898 | eBasicTypeUnsignedShort); |
| 899 | |
| 900 | // "int" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 901 | g_type_map.Append(ConstString("int"), eBasicTypeInt); |
| 902 | g_type_map.Append(ConstString("signed int"), eBasicTypeInt); |
| 903 | g_type_map.Append(ConstString("unsigned int"), eBasicTypeUnsignedInt); |
| 904 | g_type_map.Append(ConstString("unsigned"), eBasicTypeUnsignedInt); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 905 | |
| 906 | // "long" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 907 | g_type_map.Append(ConstString("long"), eBasicTypeLong); |
| 908 | g_type_map.Append(ConstString("long int"), eBasicTypeLong); |
| 909 | g_type_map.Append(ConstString("unsigned long"), eBasicTypeUnsignedLong); |
| 910 | g_type_map.Append(ConstString("unsigned long int"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 911 | eBasicTypeUnsignedLong); |
| 912 | |
| 913 | // "long long" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 914 | g_type_map.Append(ConstString("long long"), eBasicTypeLongLong); |
| 915 | g_type_map.Append(ConstString("long long int"), eBasicTypeLongLong); |
| 916 | g_type_map.Append(ConstString("unsigned long long"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 917 | eBasicTypeUnsignedLongLong); |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 918 | g_type_map.Append(ConstString("unsigned long long int"), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 919 | eBasicTypeUnsignedLongLong); |
| 920 | |
| 921 | // "int128" |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 922 | g_type_map.Append(ConstString("__int128_t"), eBasicTypeInt128); |
| 923 | g_type_map.Append(ConstString("__uint128_t"), eBasicTypeUnsignedInt128); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 924 | |
| 925 | // Miscellaneous |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 926 | g_type_map.Append(ConstString("bool"), eBasicTypeBool); |
| 927 | g_type_map.Append(ConstString("float"), eBasicTypeFloat); |
| 928 | g_type_map.Append(ConstString("double"), eBasicTypeDouble); |
| 929 | g_type_map.Append(ConstString("long double"), eBasicTypeLongDouble); |
| 930 | g_type_map.Append(ConstString("id"), eBasicTypeObjCID); |
| 931 | g_type_map.Append(ConstString("SEL"), eBasicTypeObjCSel); |
| 932 | g_type_map.Append(ConstString("nullptr"), eBasicTypeNullPtr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 933 | g_type_map.Sort(); |
| 934 | }); |
| 935 | |
Pavel Labath | 4d35d6b | 2017-05-02 10:17:30 +0000 | [diff] [blame] | 936 | return g_type_map.Find(name, eBasicTypeInvalid); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 937 | } |
| 938 | return eBasicTypeInvalid; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 939 | } |
| 940 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 941 | CompilerType ClangASTContext::GetBasicType(ASTContext *ast, |
| 942 | const ConstString &name) { |
| 943 | if (ast) { |
| 944 | lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration(name); |
| 945 | return ClangASTContext::GetBasicType(ast, basic_type); |
| 946 | } |
| 947 | return CompilerType(); |
| 948 | } |
| 949 | |
| 950 | uint32_t ClangASTContext::GetPointerByteSize() { |
| 951 | if (m_pointer_byte_size == 0) |
| 952 | m_pointer_byte_size = GetBasicType(lldb::eBasicTypeVoid) |
| 953 | .GetPointerType() |
| 954 | .GetByteSize(nullptr); |
| 955 | return m_pointer_byte_size; |
| 956 | } |
| 957 | |
| 958 | CompilerType ClangASTContext::GetBasicType(lldb::BasicType basic_type) { |
| 959 | return GetBasicType(getASTContext(), basic_type); |
| 960 | } |
| 961 | |
| 962 | CompilerType ClangASTContext::GetBasicType(ASTContext *ast, |
| 963 | lldb::BasicType basic_type) { |
| 964 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 965 | return CompilerType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 966 | lldb::opaque_compiler_type_t clang_type = |
| 967 | GetOpaqueCompilerType(ast, basic_type); |
| 968 | |
| 969 | if (clang_type) |
| 970 | return CompilerType(GetASTContext(ast), clang_type); |
| 971 | return CompilerType(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 974 | CompilerType ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize( |
| 975 | const char *type_name, uint32_t dw_ate, uint32_t bit_size) { |
| 976 | ASTContext *ast = getASTContext(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 977 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 978 | #define streq(a, b) strcmp(a, b) == 0 |
| 979 | assert(ast != nullptr); |
| 980 | if (ast) { |
| 981 | switch (dw_ate) { |
| 982 | default: |
| 983 | break; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 984 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 985 | case DW_ATE_address: |
| 986 | if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy)) |
| 987 | return CompilerType(ast, ast->VoidPtrTy); |
| 988 | break; |
Zachary Turner | 9d8a97e | 2016-04-01 23:20:35 +0000 | [diff] [blame] | 989 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 990 | case DW_ATE_boolean: |
| 991 | if (QualTypeMatchesBitSize(bit_size, ast, ast->BoolTy)) |
| 992 | return CompilerType(ast, ast->BoolTy); |
| 993 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
| 994 | return CompilerType(ast, ast->UnsignedCharTy); |
| 995 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
| 996 | return CompilerType(ast, ast->UnsignedShortTy); |
| 997 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy)) |
| 998 | return CompilerType(ast, ast->UnsignedIntTy); |
| 999 | break; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1000 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1001 | case DW_ATE_lo_user: |
| 1002 | // This has been seen to mean DW_AT_complex_integer |
| 1003 | if (type_name) { |
| 1004 | if (::strstr(type_name, "complex")) { |
| 1005 | CompilerType complex_int_clang_type = |
| 1006 | GetBuiltinTypeForDWARFEncodingAndBitSize("int", DW_ATE_signed, |
| 1007 | bit_size / 2); |
| 1008 | return CompilerType(ast, ast->getComplexType(ClangUtil::GetQualType( |
| 1009 | complex_int_clang_type))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1010 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1011 | } |
| 1012 | break; |
| 1013 | |
| 1014 | case DW_ATE_complex_float: |
| 1015 | if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatComplexTy)) |
| 1016 | return CompilerType(ast, ast->FloatComplexTy); |
| 1017 | else if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleComplexTy)) |
| 1018 | return CompilerType(ast, ast->DoubleComplexTy); |
| 1019 | else if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleComplexTy)) |
| 1020 | return CompilerType(ast, ast->LongDoubleComplexTy); |
| 1021 | else { |
| 1022 | CompilerType complex_float_clang_type = |
| 1023 | GetBuiltinTypeForDWARFEncodingAndBitSize("float", DW_ATE_float, |
| 1024 | bit_size / 2); |
| 1025 | return CompilerType(ast, ast->getComplexType(ClangUtil::GetQualType( |
| 1026 | complex_float_clang_type))); |
| 1027 | } |
| 1028 | break; |
| 1029 | |
| 1030 | case DW_ATE_float: |
| 1031 | if (streq(type_name, "float") && |
| 1032 | QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy)) |
| 1033 | return CompilerType(ast, ast->FloatTy); |
| 1034 | if (streq(type_name, "double") && |
| 1035 | QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy)) |
| 1036 | return CompilerType(ast, ast->DoubleTy); |
| 1037 | if (streq(type_name, "long double") && |
| 1038 | QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy)) |
| 1039 | return CompilerType(ast, ast->LongDoubleTy); |
| 1040 | // Fall back to not requiring a name match |
| 1041 | if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy)) |
| 1042 | return CompilerType(ast, ast->FloatTy); |
| 1043 | if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy)) |
| 1044 | return CompilerType(ast, ast->DoubleTy); |
| 1045 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy)) |
| 1046 | return CompilerType(ast, ast->LongDoubleTy); |
| 1047 | if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy)) |
| 1048 | return CompilerType(ast, ast->HalfTy); |
| 1049 | break; |
| 1050 | |
| 1051 | case DW_ATE_signed: |
| 1052 | if (type_name) { |
| 1053 | if (streq(type_name, "wchar_t") && |
| 1054 | QualTypeMatchesBitSize(bit_size, ast, ast->WCharTy) && |
| 1055 | (getTargetInfo() && |
| 1056 | TargetInfo::isTypeSigned(getTargetInfo()->getWCharType()))) |
| 1057 | return CompilerType(ast, ast->WCharTy); |
| 1058 | if (streq(type_name, "void") && |
| 1059 | QualTypeMatchesBitSize(bit_size, ast, ast->VoidTy)) |
| 1060 | return CompilerType(ast, ast->VoidTy); |
| 1061 | if (strstr(type_name, "long long") && |
| 1062 | QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy)) |
| 1063 | return CompilerType(ast, ast->LongLongTy); |
| 1064 | if (strstr(type_name, "long") && |
| 1065 | QualTypeMatchesBitSize(bit_size, ast, ast->LongTy)) |
| 1066 | return CompilerType(ast, ast->LongTy); |
| 1067 | if (strstr(type_name, "short") && |
| 1068 | QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy)) |
| 1069 | return CompilerType(ast, ast->ShortTy); |
| 1070 | if (strstr(type_name, "char")) { |
| 1071 | if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy)) |
| 1072 | return CompilerType(ast, ast->CharTy); |
| 1073 | if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy)) |
| 1074 | return CompilerType(ast, ast->SignedCharTy); |
| 1075 | } |
| 1076 | if (strstr(type_name, "int")) { |
| 1077 | if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy)) |
| 1078 | return CompilerType(ast, ast->IntTy); |
| 1079 | if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty)) |
| 1080 | return CompilerType(ast, ast->Int128Ty); |
| 1081 | } |
| 1082 | } |
| 1083 | // We weren't able to match up a type name, just search by size |
| 1084 | if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy)) |
| 1085 | return CompilerType(ast, ast->CharTy); |
| 1086 | if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy)) |
| 1087 | return CompilerType(ast, ast->ShortTy); |
| 1088 | if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy)) |
| 1089 | return CompilerType(ast, ast->IntTy); |
| 1090 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy)) |
| 1091 | return CompilerType(ast, ast->LongTy); |
| 1092 | if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy)) |
| 1093 | return CompilerType(ast, ast->LongLongTy); |
| 1094 | if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty)) |
| 1095 | return CompilerType(ast, ast->Int128Ty); |
| 1096 | break; |
| 1097 | |
| 1098 | case DW_ATE_signed_char: |
| 1099 | if (ast->getLangOpts().CharIsSigned && type_name && |
| 1100 | streq(type_name, "char")) { |
| 1101 | if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy)) |
| 1102 | return CompilerType(ast, ast->CharTy); |
| 1103 | } |
| 1104 | if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy)) |
| 1105 | return CompilerType(ast, ast->SignedCharTy); |
| 1106 | break; |
| 1107 | |
| 1108 | case DW_ATE_unsigned: |
| 1109 | if (type_name) { |
| 1110 | if (streq(type_name, "wchar_t")) { |
| 1111 | if (QualTypeMatchesBitSize(bit_size, ast, ast->WCharTy)) { |
| 1112 | if (!(getTargetInfo() && |
| 1113 | TargetInfo::isTypeSigned(getTargetInfo()->getWCharType()))) |
| 1114 | return CompilerType(ast, ast->WCharTy); |
| 1115 | } |
| 1116 | } |
| 1117 | if (strstr(type_name, "long long")) { |
| 1118 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy)) |
| 1119 | return CompilerType(ast, ast->UnsignedLongLongTy); |
| 1120 | } else if (strstr(type_name, "long")) { |
| 1121 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy)) |
| 1122 | return CompilerType(ast, ast->UnsignedLongTy); |
| 1123 | } else if (strstr(type_name, "short")) { |
| 1124 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
| 1125 | return CompilerType(ast, ast->UnsignedShortTy); |
| 1126 | } else if (strstr(type_name, "char")) { |
| 1127 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
| 1128 | return CompilerType(ast, ast->UnsignedCharTy); |
| 1129 | } else if (strstr(type_name, "int")) { |
| 1130 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy)) |
| 1131 | return CompilerType(ast, ast->UnsignedIntTy); |
| 1132 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty)) |
| 1133 | return CompilerType(ast, ast->UnsignedInt128Ty); |
| 1134 | } |
| 1135 | } |
| 1136 | // We weren't able to match up a type name, just search by size |
| 1137 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
| 1138 | return CompilerType(ast, ast->UnsignedCharTy); |
| 1139 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
| 1140 | return CompilerType(ast, ast->UnsignedShortTy); |
| 1141 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy)) |
| 1142 | return CompilerType(ast, ast->UnsignedIntTy); |
| 1143 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy)) |
| 1144 | return CompilerType(ast, ast->UnsignedLongTy); |
| 1145 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy)) |
| 1146 | return CompilerType(ast, ast->UnsignedLongLongTy); |
| 1147 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty)) |
| 1148 | return CompilerType(ast, ast->UnsignedInt128Ty); |
| 1149 | break; |
| 1150 | |
| 1151 | case DW_ATE_unsigned_char: |
| 1152 | if (!ast->getLangOpts().CharIsSigned && type_name && |
| 1153 | streq(type_name, "char")) { |
| 1154 | if (QualTypeMatchesBitSize(bit_size, ast, ast->CharTy)) |
| 1155 | return CompilerType(ast, ast->CharTy); |
| 1156 | } |
| 1157 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy)) |
| 1158 | return CompilerType(ast, ast->UnsignedCharTy); |
| 1159 | if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy)) |
| 1160 | return CompilerType(ast, ast->UnsignedShortTy); |
| 1161 | break; |
| 1162 | |
| 1163 | case DW_ATE_imaginary_float: |
| 1164 | break; |
| 1165 | |
| 1166 | case DW_ATE_UTF: |
| 1167 | if (type_name) { |
| 1168 | if (streq(type_name, "char16_t")) { |
| 1169 | return CompilerType(ast, ast->Char16Ty); |
| 1170 | } else if (streq(type_name, "char32_t")) { |
| 1171 | return CompilerType(ast, ast->Char32Ty); |
| 1172 | } |
| 1173 | } |
| 1174 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1176 | } |
| 1177 | // This assert should fire for anything that we don't catch above so we know |
| 1178 | // to fix any issues we run into. |
| 1179 | if (type_name) { |
| 1180 | Host::SystemLog(Host::eSystemLogError, "error: need to add support for " |
| 1181 | "DW_TAG_base_type '%s' encoded with " |
| 1182 | "DW_ATE = 0x%x, bit_size = %u\n", |
| 1183 | type_name, dw_ate, bit_size); |
| 1184 | } else { |
| 1185 | Host::SystemLog(Host::eSystemLogError, "error: need to add support for " |
| 1186 | "DW_TAG_base_type encoded with " |
| 1187 | "DW_ATE = 0x%x, bit_size = %u\n", |
| 1188 | dw_ate, bit_size); |
| 1189 | } |
| 1190 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1193 | CompilerType ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast) { |
| 1194 | if (ast) |
| 1195 | return CompilerType(ast, ast->UnknownAnyTy); |
| 1196 | return CompilerType(); |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1199 | CompilerType ClangASTContext::GetCStringType(bool is_const) { |
| 1200 | ASTContext *ast = getASTContext(); |
| 1201 | QualType char_type(ast->CharTy); |
| 1202 | |
| 1203 | if (is_const) |
| 1204 | char_type.addConst(); |
| 1205 | |
| 1206 | return CompilerType(ast, ast->getPointerType(char_type)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 1209 | clang::DeclContext * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1210 | ClangASTContext::GetTranslationUnitDecl(clang::ASTContext *ast) { |
| 1211 | return ast->getTranslationUnitDecl(); |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1214 | clang::Decl *ClangASTContext::CopyDecl(ASTContext *dst_ast, ASTContext *src_ast, |
| 1215 | clang::Decl *source_decl) { |
| 1216 | FileSystemOptions file_system_options; |
| 1217 | FileManager file_manager(file_system_options); |
| 1218 | ASTImporter importer(*dst_ast, file_manager, *src_ast, file_manager, false); |
| 1219 | |
| 1220 | return importer.Import(source_decl); |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1223 | bool ClangASTContext::AreTypesSame(CompilerType type1, CompilerType type2, |
| 1224 | bool ignore_qualifiers) { |
| 1225 | ClangASTContext *ast = |
| 1226 | llvm::dyn_cast_or_null<ClangASTContext>(type1.GetTypeSystem()); |
| 1227 | if (!ast || ast != type2.GetTypeSystem()) |
| 1228 | return false; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1229 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1230 | if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType()) |
| 1231 | return true; |
Greg Clayton | 55995eb | 2012-04-06 17:38:55 +0000 | [diff] [blame] | 1232 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1233 | QualType type1_qual = ClangUtil::GetQualType(type1); |
| 1234 | QualType type2_qual = ClangUtil::GetQualType(type2); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 1235 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1236 | if (ignore_qualifiers) { |
| 1237 | type1_qual = type1_qual.getUnqualifiedType(); |
| 1238 | type2_qual = type2_qual.getUnqualifiedType(); |
| 1239 | } |
| 1240 | |
| 1241 | return ast->getASTContext()->hasSameType(type1_qual, type2_qual); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1244 | CompilerType ClangASTContext::GetTypeForDecl(clang::NamedDecl *decl) { |
| 1245 | if (clang::ObjCInterfaceDecl *interface_decl = |
| 1246 | llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) |
| 1247 | return GetTypeForDecl(interface_decl); |
| 1248 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) |
| 1249 | return GetTypeForDecl(tag_decl); |
| 1250 | return CompilerType(); |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1253 | CompilerType ClangASTContext::GetTypeForDecl(TagDecl *decl) { |
| 1254 | // No need to call the getASTContext() accessor (which can create the AST |
| 1255 | // if it isn't created yet, because we can't have created a decl in this |
| 1256 | // AST if our AST didn't already exist... |
| 1257 | ASTContext *ast = &decl->getASTContext(); |
| 1258 | if (ast) |
| 1259 | return CompilerType(ast, ast->getTagDeclType(decl)); |
| 1260 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1263 | CompilerType ClangASTContext::GetTypeForDecl(ObjCInterfaceDecl *decl) { |
| 1264 | // No need to call the getASTContext() accessor (which can create the AST |
| 1265 | // if it isn't created yet, because we can't have created a decl in this |
| 1266 | // AST if our AST didn't already exist... |
| 1267 | ASTContext *ast = &decl->getASTContext(); |
| 1268 | if (ast) |
| 1269 | return CompilerType(ast, ast->getObjCInterfaceType(decl)); |
| 1270 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1273 | #pragma mark Structure, Unions, Classes |
| 1274 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1275 | CompilerType ClangASTContext::CreateRecordType(DeclContext *decl_ctx, |
| 1276 | AccessType access_type, |
| 1277 | const char *name, int kind, |
| 1278 | LanguageType language, |
| 1279 | ClangASTMetadata *metadata) { |
| 1280 | ASTContext *ast = getASTContext(); |
| 1281 | assert(ast != nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1282 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1283 | if (decl_ctx == nullptr) |
| 1284 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1285 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1286 | if (language == eLanguageTypeObjC || |
| 1287 | language == eLanguageTypeObjC_plus_plus) { |
| 1288 | bool isForwardDecl = true; |
| 1289 | bool isInternal = false; |
| 1290 | return CreateObjCClass(name, decl_ctx, isForwardDecl, isInternal, metadata); |
| 1291 | } |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1292 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1293 | // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and |
| 1294 | // we will need to update this code. I was told to currently always use |
| 1295 | // the CXXRecordDecl class since we often don't know from debug information |
| 1296 | // if something is struct or a class, so we default to always use the more |
| 1297 | // complete definition just in case. |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1298 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1299 | bool is_anonymous = (!name) || (!name[0]); |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1300 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1301 | CXXRecordDecl *decl = CXXRecordDecl::Create( |
| 1302 | *ast, (TagDecl::TagKind)kind, decl_ctx, SourceLocation(), |
| 1303 | SourceLocation(), is_anonymous ? nullptr : &ast->Idents.get(name)); |
| 1304 | |
| 1305 | if (is_anonymous) |
| 1306 | decl->setAnonymousStructOrUnion(true); |
| 1307 | |
| 1308 | if (decl) { |
| 1309 | if (metadata) |
| 1310 | SetMetadata(ast, decl, *metadata); |
| 1311 | |
| 1312 | if (access_type != eAccessNone) |
| 1313 | decl->setAccess(ConvertAccessTypeToAccessSpecifier(access_type)); |
| 1314 | |
| 1315 | if (decl_ctx) |
| 1316 | decl_ctx->addDecl(decl); |
| 1317 | |
| 1318 | return CompilerType(ast, ast->getTagDeclType(decl)); |
| 1319 | } |
| 1320 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1323 | namespace { |
| 1324 | bool IsValueParam(const clang::TemplateArgument &argument) { |
| 1325 | return argument.getKind() == TemplateArgument::Integral; |
| 1326 | } |
| 1327 | } |
| 1328 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1329 | static TemplateParameterList *CreateTemplateParameterList( |
| 1330 | ASTContext *ast, |
| 1331 | const ClangASTContext::TemplateParameterInfos &template_param_infos, |
| 1332 | llvm::SmallVector<NamedDecl *, 8> &template_param_decls) { |
| 1333 | const bool parameter_pack = false; |
| 1334 | const bool is_typename = false; |
| 1335 | const unsigned depth = 0; |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1336 | const size_t num_template_params = template_param_infos.args.size(); |
| 1337 | DeclContext *const decl_context = |
| 1338 | ast->getTranslationUnitDecl(); // Is this the right decl context?, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1339 | for (size_t i = 0; i < num_template_params; ++i) { |
| 1340 | const char *name = template_param_infos.names[i]; |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1341 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1342 | IdentifierInfo *identifier_info = nullptr; |
| 1343 | if (name && name[0]) |
| 1344 | identifier_info = &ast->Idents.get(name); |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1345 | if (IsValueParam(template_param_infos.args[i])) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1346 | template_param_decls.push_back(NonTypeTemplateParmDecl::Create( |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1347 | *ast, decl_context, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1348 | SourceLocation(), SourceLocation(), depth, i, identifier_info, |
| 1349 | template_param_infos.args[i].getIntegralType(), parameter_pack, |
| 1350 | nullptr)); |
| 1351 | |
| 1352 | } else { |
| 1353 | template_param_decls.push_back(TemplateTypeParmDecl::Create( |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1354 | *ast, decl_context, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1355 | SourceLocation(), SourceLocation(), depth, i, identifier_info, |
| 1356 | is_typename, parameter_pack)); |
| 1357 | } |
| 1358 | } |
Eugene Zemtsov | a9d928c | 2017-09-29 03:15:08 +0000 | [diff] [blame] | 1359 | |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1360 | if (template_param_infos.packed_args && |
| 1361 | template_param_infos.packed_args->args.size()) { |
| 1362 | IdentifierInfo *identifier_info = nullptr; |
| 1363 | if (template_param_infos.pack_name && template_param_infos.pack_name[0]) |
| 1364 | identifier_info = &ast->Idents.get(template_param_infos.pack_name); |
| 1365 | const bool parameter_pack_true = true; |
| 1366 | if (IsValueParam(template_param_infos.packed_args->args[0])) { |
| 1367 | template_param_decls.push_back(NonTypeTemplateParmDecl::Create( |
| 1368 | *ast, decl_context, |
| 1369 | SourceLocation(), SourceLocation(), depth, num_template_params, |
| 1370 | identifier_info, |
| 1371 | template_param_infos.packed_args->args[0].getIntegralType(), |
| 1372 | parameter_pack_true, nullptr)); |
| 1373 | } else { |
| 1374 | template_param_decls.push_back(TemplateTypeParmDecl::Create( |
| 1375 | *ast, decl_context, |
| 1376 | SourceLocation(), SourceLocation(), depth, num_template_params, |
| 1377 | identifier_info, |
| 1378 | is_typename, parameter_pack_true)); |
| 1379 | } |
| 1380 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1381 | clang::Expr *const requires_clause = nullptr; // TODO: Concepts |
| 1382 | TemplateParameterList *template_param_list = TemplateParameterList::Create( |
| 1383 | *ast, SourceLocation(), SourceLocation(), template_param_decls, |
| 1384 | SourceLocation(), requires_clause); |
| 1385 | return template_param_list; |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1388 | clang::FunctionTemplateDecl *ClangASTContext::CreateFunctionTemplateDecl( |
| 1389 | clang::DeclContext *decl_ctx, clang::FunctionDecl *func_decl, |
| 1390 | const char *name, const TemplateParameterInfos &template_param_infos) { |
| 1391 | // /// \brief Create a function template node. |
| 1392 | ASTContext *ast = getASTContext(); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1393 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1394 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1395 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1396 | TemplateParameterList *template_param_list = CreateTemplateParameterList( |
| 1397 | ast, template_param_infos, template_param_decls); |
| 1398 | FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create( |
| 1399 | *ast, decl_ctx, func_decl->getLocation(), func_decl->getDeclName(), |
| 1400 | template_param_list, func_decl); |
| 1401 | |
| 1402 | for (size_t i = 0, template_param_decl_count = template_param_decls.size(); |
| 1403 | i < template_param_decl_count; ++i) { |
| 1404 | // TODO: verify which decl context we should put template_param_decls into.. |
| 1405 | template_param_decls[i]->setDeclContext(func_decl); |
| 1406 | } |
| 1407 | |
| 1408 | return func_tmpl_decl; |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1411 | void ClangASTContext::CreateFunctionTemplateSpecializationInfo( |
| 1412 | FunctionDecl *func_decl, clang::FunctionTemplateDecl *func_tmpl_decl, |
| 1413 | const TemplateParameterInfos &infos) { |
| 1414 | TemplateArgumentList template_args(TemplateArgumentList::OnStack, infos.args); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1415 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1416 | func_decl->setFunctionTemplateSpecialization(func_tmpl_decl, &template_args, |
| 1417 | nullptr); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1420 | ClassTemplateDecl *ClangASTContext::CreateClassTemplateDecl( |
| 1421 | DeclContext *decl_ctx, lldb::AccessType access_type, const char *class_name, |
| 1422 | int kind, const TemplateParameterInfos &template_param_infos) { |
| 1423 | ASTContext *ast = getASTContext(); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1424 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1425 | ClassTemplateDecl *class_template_decl = nullptr; |
| 1426 | if (decl_ctx == nullptr) |
| 1427 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1428 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1429 | IdentifierInfo &identifier_info = ast->Idents.get(class_name); |
| 1430 | DeclarationName decl_name(&identifier_info); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1431 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1432 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1433 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1434 | for (NamedDecl *decl : result) { |
| 1435 | class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1436 | if (class_template_decl) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1437 | return class_template_decl; |
| 1438 | } |
| 1439 | |
| 1440 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
| 1441 | |
| 1442 | TemplateParameterList *template_param_list = CreateTemplateParameterList( |
| 1443 | ast, template_param_infos, template_param_decls); |
| 1444 | |
| 1445 | CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create( |
| 1446 | *ast, (TagDecl::TagKind)kind, |
| 1447 | decl_ctx, // What decl context do we use here? TU? The actual decl |
| 1448 | // context? |
| 1449 | SourceLocation(), SourceLocation(), &identifier_info); |
| 1450 | |
| 1451 | for (size_t i = 0, template_param_decl_count = template_param_decls.size(); |
| 1452 | i < template_param_decl_count; ++i) { |
| 1453 | template_param_decls[i]->setDeclContext(template_cxx_decl); |
| 1454 | } |
| 1455 | |
| 1456 | // With templated classes, we say that a class is templated with |
| 1457 | // specializations, but that the bare class has no functions. |
| 1458 | // template_cxx_decl->startDefinition(); |
| 1459 | // template_cxx_decl->completeDefinition(); |
| 1460 | |
| 1461 | class_template_decl = ClassTemplateDecl::Create( |
| 1462 | *ast, |
| 1463 | decl_ctx, // What decl context do we use here? TU? The actual decl |
| 1464 | // context? |
Pavel Labath | 4294de3 | 2017-01-12 10:44:16 +0000 | [diff] [blame] | 1465 | SourceLocation(), decl_name, template_param_list, template_cxx_decl); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1466 | |
| 1467 | if (class_template_decl) { |
| 1468 | if (access_type != eAccessNone) |
| 1469 | class_template_decl->setAccess( |
| 1470 | ConvertAccessTypeToAccessSpecifier(access_type)); |
| 1471 | |
| 1472 | // if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx)) |
| 1473 | // CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl)); |
| 1474 | |
| 1475 | decl_ctx->addDecl(class_template_decl); |
| 1476 | |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1477 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1478 | VerifyDecl(class_template_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1479 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1480 | } |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1481 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1482 | return class_template_decl; |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1485 | ClassTemplateSpecializationDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1486 | ClangASTContext::CreateClassTemplateSpecializationDecl( |
| 1487 | DeclContext *decl_ctx, ClassTemplateDecl *class_template_decl, int kind, |
| 1488 | const TemplateParameterInfos &template_param_infos) { |
| 1489 | ASTContext *ast = getASTContext(); |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1490 | llvm::SmallVector<clang::TemplateArgument, 2> args( |
| 1491 | template_param_infos.args.size() + |
| 1492 | (template_param_infos.packed_args ? 1 : 0)); |
| 1493 | std::copy(template_param_infos.args.begin(), template_param_infos.args.end(), |
| 1494 | args.begin()); |
| 1495 | if (template_param_infos.packed_args) { |
| 1496 | args[args.size() - 1] = TemplateArgument::CreatePackCopy( |
| 1497 | *ast, template_param_infos.packed_args->args); |
| 1498 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1499 | ClassTemplateSpecializationDecl *class_template_specialization_decl = |
| 1500 | ClassTemplateSpecializationDecl::Create( |
| 1501 | *ast, (TagDecl::TagKind)kind, decl_ctx, SourceLocation(), |
Sean Callanan | 09e91ac | 2017-05-11 22:08:05 +0000 | [diff] [blame] | 1502 | SourceLocation(), class_template_decl, args, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1503 | nullptr); |
| 1504 | |
| 1505 | class_template_specialization_decl->setSpecializationKind( |
| 1506 | TSK_ExplicitSpecialization); |
| 1507 | |
| 1508 | return class_template_specialization_decl; |
| 1509 | } |
| 1510 | |
| 1511 | CompilerType ClangASTContext::CreateClassTemplateSpecializationType( |
| 1512 | ClassTemplateSpecializationDecl *class_template_specialization_decl) { |
| 1513 | if (class_template_specialization_decl) { |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1514 | ASTContext *ast = getASTContext(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1515 | if (ast) |
| 1516 | return CompilerType( |
| 1517 | ast, ast->getTagDeclType(class_template_specialization_decl)); |
| 1518 | } |
| 1519 | return CompilerType(); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1522 | static inline bool check_op_param(bool is_method, |
| 1523 | clang::OverloadedOperatorKind op_kind, |
| 1524 | bool unary, bool binary, |
| 1525 | uint32_t num_params) { |
| 1526 | // Special-case call since it can take any number of operands |
| 1527 | if (op_kind == OO_Call) |
| 1528 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1529 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1530 | // The parameter count doesn't include "this" |
| 1531 | if (is_method) |
| 1532 | ++num_params; |
| 1533 | if (num_params == 1) |
| 1534 | return unary; |
| 1535 | if (num_params == 2) |
| 1536 | return binary; |
| 1537 | else |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1538 | return false; |
| 1539 | } |
Daniel Dunbar | dacdfb5 | 2011-10-31 22:50:57 +0000 | [diff] [blame] | 1540 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1541 | bool ClangASTContext::CheckOverloadedOperatorKindParameterCount( |
| 1542 | bool is_method, clang::OverloadedOperatorKind op_kind, |
| 1543 | uint32_t num_params) { |
| 1544 | switch (op_kind) { |
| 1545 | default: |
| 1546 | break; |
| 1547 | // C++ standard allows any number of arguments to new/delete |
| 1548 | case OO_New: |
| 1549 | case OO_Array_New: |
| 1550 | case OO_Delete: |
| 1551 | case OO_Array_Delete: |
| 1552 | return true; |
| 1553 | } |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 1554 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1555 | #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \ |
| 1556 | case OO_##Name: \ |
| 1557 | return check_op_param(is_method, op_kind, Unary, Binary, num_params); |
| 1558 | switch (op_kind) { |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1559 | #include "clang/Basic/OperatorKinds.def" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1560 | default: |
| 1561 | break; |
| 1562 | } |
| 1563 | return false; |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1566 | clang::AccessSpecifier |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1567 | ClangASTContext::UnifyAccessSpecifiers(clang::AccessSpecifier lhs, |
| 1568 | clang::AccessSpecifier rhs) { |
| 1569 | // Make the access equal to the stricter of the field and the nested field's |
| 1570 | // access |
| 1571 | if (lhs == AS_none || rhs == AS_none) |
| 1572 | return AS_none; |
| 1573 | if (lhs == AS_private || rhs == AS_private) |
| 1574 | return AS_private; |
| 1575 | if (lhs == AS_protected || rhs == AS_protected) |
| 1576 | return AS_protected; |
| 1577 | return AS_public; |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1580 | bool ClangASTContext::FieldIsBitfield(FieldDecl *field, |
| 1581 | uint32_t &bitfield_bit_size) { |
| 1582 | return FieldIsBitfield(getASTContext(), field, bitfield_bit_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1585 | bool ClangASTContext::FieldIsBitfield(ASTContext *ast, FieldDecl *field, |
| 1586 | uint32_t &bitfield_bit_size) { |
| 1587 | if (ast == nullptr || field == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1588 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1589 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1590 | if (field->isBitField()) { |
| 1591 | Expr *bit_width_expr = field->getBitWidth(); |
| 1592 | if (bit_width_expr) { |
| 1593 | llvm::APSInt bit_width_apsint; |
| 1594 | if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast)) { |
| 1595 | bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1596 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1597 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1598 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1599 | } |
| 1600 | return false; |
| 1601 | } |
| 1602 | |
| 1603 | bool ClangASTContext::RecordHasFields(const RecordDecl *record_decl) { |
| 1604 | if (record_decl == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1605 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1606 | |
| 1607 | if (!record_decl->field_empty()) |
| 1608 | return true; |
| 1609 | |
| 1610 | // No fields, lets check this is a CXX record and check the base classes |
| 1611 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 1612 | if (cxx_record_decl) { |
| 1613 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1614 | for (base_class = cxx_record_decl->bases_begin(), |
| 1615 | base_class_end = cxx_record_decl->bases_end(); |
| 1616 | base_class != base_class_end; ++base_class) { |
| 1617 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>( |
| 1618 | base_class->getType()->getAs<RecordType>()->getDecl()); |
| 1619 | if (RecordHasFields(base_class_decl)) |
| 1620 | return true; |
| 1621 | } |
| 1622 | } |
| 1623 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1626 | #pragma mark Objective C Classes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1627 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1628 | CompilerType ClangASTContext::CreateObjCClass(const char *name, |
| 1629 | DeclContext *decl_ctx, |
| 1630 | bool isForwardDecl, |
| 1631 | bool isInternal, |
| 1632 | ClangASTMetadata *metadata) { |
| 1633 | ASTContext *ast = getASTContext(); |
| 1634 | assert(ast != nullptr); |
| 1635 | assert(name && name[0]); |
| 1636 | if (decl_ctx == nullptr) |
| 1637 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1638 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1639 | ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create( |
| 1640 | *ast, decl_ctx, SourceLocation(), &ast->Idents.get(name), nullptr, |
| 1641 | nullptr, SourceLocation(), |
| 1642 | /*isForwardDecl,*/ |
| 1643 | isInternal); |
| 1644 | |
| 1645 | if (decl && metadata) |
| 1646 | SetMetadata(ast, decl, *metadata); |
| 1647 | |
| 1648 | return CompilerType(ast, ast->getObjCInterfaceType(decl)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1651 | static inline bool BaseSpecifierIsEmpty(const CXXBaseSpecifier *b) { |
| 1652 | return ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()) == |
| 1653 | false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1656 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1657 | ClangASTContext::GetNumBaseClasses(const CXXRecordDecl *cxx_record_decl, |
| 1658 | bool omit_empty_base_classes) { |
| 1659 | uint32_t num_bases = 0; |
| 1660 | if (cxx_record_decl) { |
| 1661 | if (omit_empty_base_classes) { |
| 1662 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1663 | for (base_class = cxx_record_decl->bases_begin(), |
| 1664 | base_class_end = cxx_record_decl->bases_end(); |
| 1665 | base_class != base_class_end; ++base_class) { |
| 1666 | // Skip empty base classes |
| 1667 | if (omit_empty_base_classes) { |
| 1668 | if (BaseSpecifierIsEmpty(base_class)) |
| 1669 | continue; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1670 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1671 | ++num_bases; |
| 1672 | } |
| 1673 | } else |
| 1674 | num_bases = cxx_record_decl->getNumBases(); |
| 1675 | } |
| 1676 | return num_bases; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1679 | #pragma mark Namespace Declarations |
| 1680 | |
| 1681 | NamespaceDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1682 | ClangASTContext::GetUniqueNamespaceDeclaration(const char *name, |
| 1683 | DeclContext *decl_ctx) { |
| 1684 | NamespaceDecl *namespace_decl = nullptr; |
| 1685 | ASTContext *ast = getASTContext(); |
| 1686 | TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl(); |
| 1687 | if (decl_ctx == nullptr) |
| 1688 | decl_ctx = translation_unit_decl; |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1689 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1690 | if (name) { |
| 1691 | IdentifierInfo &identifier_info = ast->Idents.get(name); |
| 1692 | DeclarationName decl_name(&identifier_info); |
| 1693 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
| 1694 | for (NamedDecl *decl : result) { |
| 1695 | namespace_decl = dyn_cast<clang::NamespaceDecl>(decl); |
| 1696 | if (namespace_decl) |
| 1697 | return namespace_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1698 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1699 | |
| 1700 | namespace_decl = |
| 1701 | NamespaceDecl::Create(*ast, decl_ctx, false, SourceLocation(), |
| 1702 | SourceLocation(), &identifier_info, nullptr); |
| 1703 | |
| 1704 | decl_ctx->addDecl(namespace_decl); |
| 1705 | } else { |
| 1706 | if (decl_ctx == translation_unit_decl) { |
| 1707 | namespace_decl = translation_unit_decl->getAnonymousNamespace(); |
| 1708 | if (namespace_decl) |
| 1709 | return namespace_decl; |
| 1710 | |
| 1711 | namespace_decl = |
| 1712 | NamespaceDecl::Create(*ast, decl_ctx, false, SourceLocation(), |
| 1713 | SourceLocation(), nullptr, nullptr); |
| 1714 | translation_unit_decl->setAnonymousNamespace(namespace_decl); |
| 1715 | translation_unit_decl->addDecl(namespace_decl); |
| 1716 | assert(namespace_decl == translation_unit_decl->getAnonymousNamespace()); |
| 1717 | } else { |
| 1718 | NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx); |
| 1719 | if (parent_namespace_decl) { |
| 1720 | namespace_decl = parent_namespace_decl->getAnonymousNamespace(); |
| 1721 | if (namespace_decl) |
| 1722 | return namespace_decl; |
| 1723 | namespace_decl = |
| 1724 | NamespaceDecl::Create(*ast, decl_ctx, false, SourceLocation(), |
| 1725 | SourceLocation(), nullptr, nullptr); |
| 1726 | parent_namespace_decl->setAnonymousNamespace(namespace_decl); |
| 1727 | parent_namespace_decl->addDecl(namespace_decl); |
| 1728 | assert(namespace_decl == |
| 1729 | parent_namespace_decl->getAnonymousNamespace()); |
| 1730 | } else { |
| 1731 | // BAD!!! |
| 1732 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1733 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1734 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1735 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1736 | VerifyDecl(namespace_decl); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1737 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1738 | return namespace_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1741 | NamespaceDecl *ClangASTContext::GetUniqueNamespaceDeclaration( |
| 1742 | clang::ASTContext *ast, const char *name, clang::DeclContext *decl_ctx) { |
| 1743 | ClangASTContext *ast_ctx = ClangASTContext::GetASTContext(ast); |
| 1744 | if (ast_ctx == nullptr) |
| 1745 | return nullptr; |
Siva Chandra | 03ff5c8 | 2016-02-05 19:10:04 +0000 | [diff] [blame] | 1746 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1747 | return ast_ctx->GetUniqueNamespaceDeclaration(name, decl_ctx); |
Siva Chandra | 03ff5c8 | 2016-02-05 19:10:04 +0000 | [diff] [blame] | 1748 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1749 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1750 | clang::BlockDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1751 | ClangASTContext::CreateBlockDeclaration(clang::DeclContext *ctx) { |
| 1752 | if (ctx != nullptr) { |
| 1753 | clang::BlockDecl *decl = clang::BlockDecl::Create(*getASTContext(), ctx, |
| 1754 | clang::SourceLocation()); |
| 1755 | ctx->addDecl(decl); |
| 1756 | return decl; |
| 1757 | } |
| 1758 | return nullptr; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1761 | clang::DeclContext *FindLCABetweenDecls(clang::DeclContext *left, |
| 1762 | clang::DeclContext *right, |
| 1763 | clang::DeclContext *root) { |
| 1764 | if (root == nullptr) |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1765 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1766 | |
| 1767 | std::set<clang::DeclContext *> path_left; |
| 1768 | for (clang::DeclContext *d = left; d != nullptr; d = d->getParent()) |
| 1769 | path_left.insert(d); |
| 1770 | |
| 1771 | for (clang::DeclContext *d = right; d != nullptr; d = d->getParent()) |
| 1772 | if (path_left.find(d) != path_left.end()) |
| 1773 | return d; |
| 1774 | |
| 1775 | return nullptr; |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1778 | clang::UsingDirectiveDecl *ClangASTContext::CreateUsingDirectiveDeclaration( |
| 1779 | clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl) { |
| 1780 | if (decl_ctx != nullptr && ns_decl != nullptr) { |
| 1781 | clang::TranslationUnitDecl *translation_unit = |
| 1782 | (clang::TranslationUnitDecl *)GetTranslationUnitDecl(getASTContext()); |
| 1783 | clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create( |
| 1784 | *getASTContext(), decl_ctx, clang::SourceLocation(), |
| 1785 | clang::SourceLocation(), clang::NestedNameSpecifierLoc(), |
| 1786 | clang::SourceLocation(), ns_decl, |
| 1787 | FindLCABetweenDecls(decl_ctx, ns_decl, translation_unit)); |
| 1788 | decl_ctx->addDecl(using_decl); |
| 1789 | return using_decl; |
| 1790 | } |
| 1791 | return nullptr; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | clang::UsingDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1795 | ClangASTContext::CreateUsingDeclaration(clang::DeclContext *current_decl_ctx, |
| 1796 | clang::NamedDecl *target) { |
| 1797 | if (current_decl_ctx != nullptr && target != nullptr) { |
| 1798 | clang::UsingDecl *using_decl = clang::UsingDecl::Create( |
| 1799 | *getASTContext(), current_decl_ctx, clang::SourceLocation(), |
| 1800 | clang::NestedNameSpecifierLoc(), clang::DeclarationNameInfo(), false); |
| 1801 | clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create( |
| 1802 | *getASTContext(), current_decl_ctx, clang::SourceLocation(), using_decl, |
| 1803 | target); |
| 1804 | using_decl->addShadowDecl(shadow_decl); |
| 1805 | current_decl_ctx->addDecl(using_decl); |
| 1806 | return using_decl; |
| 1807 | } |
| 1808 | return nullptr; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1811 | clang::VarDecl *ClangASTContext::CreateVariableDeclaration( |
| 1812 | clang::DeclContext *decl_context, const char *name, clang::QualType type) { |
| 1813 | if (decl_context != nullptr) { |
| 1814 | clang::VarDecl *var_decl = clang::VarDecl::Create( |
| 1815 | *getASTContext(), decl_context, clang::SourceLocation(), |
| 1816 | clang::SourceLocation(), |
| 1817 | name && name[0] ? &getASTContext()->Idents.getOwn(name) : nullptr, type, |
| 1818 | nullptr, clang::SC_None); |
| 1819 | var_decl->setAccess(clang::AS_public); |
| 1820 | decl_context->addDecl(var_decl); |
| 1821 | return var_decl; |
| 1822 | } |
| 1823 | return nullptr; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Zachary Turner | 9d8a97e | 2016-04-01 23:20:35 +0000 | [diff] [blame] | 1826 | lldb::opaque_compiler_type_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1827 | ClangASTContext::GetOpaqueCompilerType(clang::ASTContext *ast, |
| 1828 | lldb::BasicType basic_type) { |
| 1829 | switch (basic_type) { |
| 1830 | case eBasicTypeVoid: |
| 1831 | return ast->VoidTy.getAsOpaquePtr(); |
| 1832 | case eBasicTypeChar: |
| 1833 | return ast->CharTy.getAsOpaquePtr(); |
| 1834 | case eBasicTypeSignedChar: |
| 1835 | return ast->SignedCharTy.getAsOpaquePtr(); |
| 1836 | case eBasicTypeUnsignedChar: |
| 1837 | return ast->UnsignedCharTy.getAsOpaquePtr(); |
| 1838 | case eBasicTypeWChar: |
| 1839 | return ast->getWCharType().getAsOpaquePtr(); |
| 1840 | case eBasicTypeSignedWChar: |
| 1841 | return ast->getSignedWCharType().getAsOpaquePtr(); |
| 1842 | case eBasicTypeUnsignedWChar: |
| 1843 | return ast->getUnsignedWCharType().getAsOpaquePtr(); |
| 1844 | case eBasicTypeChar16: |
| 1845 | return ast->Char16Ty.getAsOpaquePtr(); |
| 1846 | case eBasicTypeChar32: |
| 1847 | return ast->Char32Ty.getAsOpaquePtr(); |
| 1848 | case eBasicTypeShort: |
| 1849 | return ast->ShortTy.getAsOpaquePtr(); |
| 1850 | case eBasicTypeUnsignedShort: |
| 1851 | return ast->UnsignedShortTy.getAsOpaquePtr(); |
| 1852 | case eBasicTypeInt: |
| 1853 | return ast->IntTy.getAsOpaquePtr(); |
| 1854 | case eBasicTypeUnsignedInt: |
| 1855 | return ast->UnsignedIntTy.getAsOpaquePtr(); |
| 1856 | case eBasicTypeLong: |
| 1857 | return ast->LongTy.getAsOpaquePtr(); |
| 1858 | case eBasicTypeUnsignedLong: |
| 1859 | return ast->UnsignedLongTy.getAsOpaquePtr(); |
| 1860 | case eBasicTypeLongLong: |
| 1861 | return ast->LongLongTy.getAsOpaquePtr(); |
| 1862 | case eBasicTypeUnsignedLongLong: |
| 1863 | return ast->UnsignedLongLongTy.getAsOpaquePtr(); |
| 1864 | case eBasicTypeInt128: |
| 1865 | return ast->Int128Ty.getAsOpaquePtr(); |
| 1866 | case eBasicTypeUnsignedInt128: |
| 1867 | return ast->UnsignedInt128Ty.getAsOpaquePtr(); |
| 1868 | case eBasicTypeBool: |
| 1869 | return ast->BoolTy.getAsOpaquePtr(); |
| 1870 | case eBasicTypeHalf: |
| 1871 | return ast->HalfTy.getAsOpaquePtr(); |
| 1872 | case eBasicTypeFloat: |
| 1873 | return ast->FloatTy.getAsOpaquePtr(); |
| 1874 | case eBasicTypeDouble: |
| 1875 | return ast->DoubleTy.getAsOpaquePtr(); |
| 1876 | case eBasicTypeLongDouble: |
| 1877 | return ast->LongDoubleTy.getAsOpaquePtr(); |
| 1878 | case eBasicTypeFloatComplex: |
| 1879 | return ast->FloatComplexTy.getAsOpaquePtr(); |
| 1880 | case eBasicTypeDoubleComplex: |
| 1881 | return ast->DoubleComplexTy.getAsOpaquePtr(); |
| 1882 | case eBasicTypeLongDoubleComplex: |
| 1883 | return ast->LongDoubleComplexTy.getAsOpaquePtr(); |
| 1884 | case eBasicTypeObjCID: |
| 1885 | return ast->getObjCIdType().getAsOpaquePtr(); |
| 1886 | case eBasicTypeObjCClass: |
| 1887 | return ast->getObjCClassType().getAsOpaquePtr(); |
| 1888 | case eBasicTypeObjCSel: |
| 1889 | return ast->getObjCSelType().getAsOpaquePtr(); |
| 1890 | case eBasicTypeNullPtr: |
| 1891 | return ast->NullPtrTy.getAsOpaquePtr(); |
| 1892 | default: |
| 1893 | return nullptr; |
| 1894 | } |
Zachary Turner | 9d8a97e | 2016-04-01 23:20:35 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1897 | #pragma mark Function Types |
| 1898 | |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 1899 | clang::DeclarationName |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1900 | ClangASTContext::GetDeclarationName(const char *name, |
| 1901 | const CompilerType &function_clang_type) { |
| 1902 | if (!name || !name[0]) |
| 1903 | return clang::DeclarationName(); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 1904 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1905 | clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS; |
| 1906 | if (!IsOperator(name, op_kind) || op_kind == clang::NUM_OVERLOADED_OPERATORS) |
| 1907 | return DeclarationName(&getASTContext()->Idents.get( |
| 1908 | name)); // Not operator, but a regular function. |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 1909 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1910 | // Check the number of operator parameters. Sometimes we have |
| 1911 | // seen bad DWARF that doesn't correctly describe operators and |
| 1912 | // if we try to create a method and add it to the class, clang |
| 1913 | // will assert and crash, so we need to make sure things are |
| 1914 | // acceptable. |
| 1915 | clang::QualType method_qual_type(ClangUtil::GetQualType(function_clang_type)); |
| 1916 | const clang::FunctionProtoType *function_type = |
| 1917 | llvm::dyn_cast<clang::FunctionProtoType>(method_qual_type.getTypePtr()); |
| 1918 | if (function_type == nullptr) |
| 1919 | return clang::DeclarationName(); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 1920 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1921 | const bool is_method = false; |
| 1922 | const unsigned int num_params = function_type->getNumParams(); |
| 1923 | if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount( |
| 1924 | is_method, op_kind, num_params)) |
| 1925 | return clang::DeclarationName(); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 1926 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1927 | return getASTContext()->DeclarationNames.getCXXOperatorName(op_kind); |
Pavel Labath | 1ac2b20 | 2016-08-15 14:32:32 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1930 | FunctionDecl *ClangASTContext::CreateFunctionDeclaration( |
| 1931 | DeclContext *decl_ctx, const char *name, |
| 1932 | const CompilerType &function_clang_type, int storage, bool is_inline) { |
| 1933 | FunctionDecl *func_decl = nullptr; |
| 1934 | ASTContext *ast = getASTContext(); |
| 1935 | if (decl_ctx == nullptr) |
| 1936 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1937 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1938 | const bool hasWrittenPrototype = true; |
| 1939 | const bool isConstexprSpecified = false; |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1940 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1941 | clang::DeclarationName declarationName = |
| 1942 | GetDeclarationName(name, function_clang_type); |
| 1943 | func_decl = FunctionDecl::Create( |
| 1944 | *ast, decl_ctx, SourceLocation(), SourceLocation(), declarationName, |
| 1945 | ClangUtil::GetQualType(function_clang_type), nullptr, |
| 1946 | (clang::StorageClass)storage, is_inline, hasWrittenPrototype, |
| 1947 | isConstexprSpecified); |
| 1948 | if (func_decl) |
| 1949 | decl_ctx->addDecl(func_decl); |
| 1950 | |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1951 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1952 | VerifyDecl(func_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1953 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1954 | |
| 1955 | return func_decl; |
| 1956 | } |
| 1957 | |
| 1958 | CompilerType ClangASTContext::CreateFunctionType( |
| 1959 | ASTContext *ast, const CompilerType &result_type, const CompilerType *args, |
| 1960 | unsigned num_args, bool is_variadic, unsigned type_quals) { |
| 1961 | if (ast == nullptr) |
| 1962 | return CompilerType(); // invalid AST |
| 1963 | |
| 1964 | if (!result_type || !ClangUtil::IsClangType(result_type)) |
| 1965 | return CompilerType(); // invalid return type |
| 1966 | |
| 1967 | std::vector<QualType> qual_type_args; |
| 1968 | if (num_args > 0 && args == nullptr) |
| 1969 | return CompilerType(); // invalid argument array passed in |
| 1970 | |
| 1971 | // Verify that all arguments are valid and the right type |
| 1972 | for (unsigned i = 0; i < num_args; ++i) { |
| 1973 | if (args[i]) { |
| 1974 | // Make sure we have a clang type in args[i] and not a type from another |
| 1975 | // language whose name might match |
| 1976 | const bool is_clang_type = ClangUtil::IsClangType(args[i]); |
| 1977 | lldbassert(is_clang_type); |
| 1978 | if (is_clang_type) |
| 1979 | qual_type_args.push_back(ClangUtil::GetQualType(args[i])); |
| 1980 | else |
| 1981 | return CompilerType(); // invalid argument type (must be a clang type) |
| 1982 | } else |
| 1983 | return CompilerType(); // invalid argument type (empty) |
| 1984 | } |
| 1985 | |
| 1986 | // TODO: Detect calling convention in DWARF? |
| 1987 | FunctionProtoType::ExtProtoInfo proto_info; |
| 1988 | proto_info.Variadic = is_variadic; |
| 1989 | proto_info.ExceptionSpec = EST_None; |
| 1990 | proto_info.TypeQuals = type_quals; |
| 1991 | proto_info.RefQualifier = RQ_None; |
| 1992 | |
| 1993 | return CompilerType(ast, |
| 1994 | ast->getFunctionType(ClangUtil::GetQualType(result_type), |
| 1995 | qual_type_args, proto_info)); |
| 1996 | } |
| 1997 | |
| 1998 | ParmVarDecl *ClangASTContext::CreateParameterDeclaration( |
| 1999 | const char *name, const CompilerType ¶m_type, int storage) { |
| 2000 | ASTContext *ast = getASTContext(); |
| 2001 | assert(ast != nullptr); |
| 2002 | return ParmVarDecl::Create(*ast, ast->getTranslationUnitDecl(), |
| 2003 | SourceLocation(), SourceLocation(), |
| 2004 | name && name[0] ? &ast->Idents.get(name) : nullptr, |
| 2005 | ClangUtil::GetQualType(param_type), nullptr, |
| 2006 | (clang::StorageClass)storage, nullptr); |
| 2007 | } |
| 2008 | |
| 2009 | void ClangASTContext::SetFunctionParameters(FunctionDecl *function_decl, |
| 2010 | ParmVarDecl **params, |
| 2011 | unsigned num_params) { |
| 2012 | if (function_decl) |
| 2013 | function_decl->setParams(ArrayRef<ParmVarDecl *>(params, num_params)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2016 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2017 | ClangASTContext::CreateBlockPointerType(const CompilerType &function_type) { |
| 2018 | QualType block_type = m_ast_ap->getBlockPointerType( |
| 2019 | clang::QualType::getFromOpaquePtr(function_type.GetOpaqueQualType())); |
Greg Clayton | ceeb521 | 2016-05-26 22:33:25 +0000 | [diff] [blame] | 2020 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2021 | return CompilerType(this, block_type.getAsOpaquePtr()); |
Sean Callanan | c530ba9 | 2016-05-02 21:15:31 +0000 | [diff] [blame] | 2022 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2023 | |
| 2024 | #pragma mark Array Types |
| 2025 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2026 | CompilerType ClangASTContext::CreateArrayType(const CompilerType &element_type, |
| 2027 | size_t element_count, |
| 2028 | bool is_vector) { |
| 2029 | if (element_type.IsValid()) { |
| 2030 | ASTContext *ast = getASTContext(); |
| 2031 | assert(ast != nullptr); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2032 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2033 | if (is_vector) { |
| 2034 | return CompilerType( |
| 2035 | ast, ast->getExtVectorType(ClangUtil::GetQualType(element_type), |
| 2036 | element_count)); |
| 2037 | } else { |
| 2038 | |
| 2039 | llvm::APInt ap_element_count(64, element_count); |
| 2040 | if (element_count == 0) { |
| 2041 | return CompilerType(ast, ast->getIncompleteArrayType( |
| 2042 | ClangUtil::GetQualType(element_type), |
| 2043 | clang::ArrayType::Normal, 0)); |
| 2044 | } else { |
| 2045 | return CompilerType( |
| 2046 | ast, ast->getConstantArrayType(ClangUtil::GetQualType(element_type), |
| 2047 | ap_element_count, |
| 2048 | clang::ArrayType::Normal, 0)); |
| 2049 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2050 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2051 | } |
| 2052 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2055 | CompilerType ClangASTContext::CreateStructForIdentifier( |
| 2056 | const ConstString &type_name, |
| 2057 | const std::initializer_list<std::pair<const char *, CompilerType>> |
| 2058 | &type_fields, |
| 2059 | bool packed) { |
| 2060 | CompilerType type; |
| 2061 | if (!type_name.IsEmpty() && |
| 2062 | (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)) |
| 2063 | .IsValid()) { |
Pavel Labath | f31c9d2 | 2017-01-05 13:18:42 +0000 | [diff] [blame] | 2064 | lldbassert(0 && "Trying to create a type for an existing name"); |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2065 | return type; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | type = CreateRecordType(nullptr, lldb::eAccessPublic, type_name.GetCString(), |
| 2069 | clang::TTK_Struct, lldb::eLanguageTypeC); |
| 2070 | StartTagDeclarationDefinition(type); |
| 2071 | for (const auto &field : type_fields) |
| 2072 | AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic, |
| 2073 | 0); |
| 2074 | if (packed) |
| 2075 | SetIsPacked(type); |
| 2076 | CompleteTagDeclarationDefinition(type); |
| 2077 | return type; |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2078 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2079 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2080 | CompilerType ClangASTContext::GetOrCreateStructForIdentifier( |
| 2081 | const ConstString &type_name, |
| 2082 | const std::initializer_list<std::pair<const char *, CompilerType>> |
| 2083 | &type_fields, |
| 2084 | bool packed) { |
| 2085 | CompilerType type; |
| 2086 | if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid()) |
| 2087 | return type; |
Sean Callanan | c530ba9 | 2016-05-02 21:15:31 +0000 | [diff] [blame] | 2088 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2089 | return CreateStructForIdentifier(type_name, type_fields, packed); |
Sean Callanan | c530ba9 | 2016-05-02 21:15:31 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2092 | #pragma mark Enumeration Types |
| 2093 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2094 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2095 | ClangASTContext::CreateEnumerationType(const char *name, DeclContext *decl_ctx, |
| 2096 | const Declaration &decl, |
Tamas Berghammer | 5976583 | 2017-11-07 10:39:22 +0000 | [diff] [blame] | 2097 | const CompilerType &integer_clang_type, |
| 2098 | bool is_scoped) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2099 | // TODO: Do something intelligent with the Declaration object passed in |
| 2100 | // like maybe filling in the SourceLocation with it... |
| 2101 | ASTContext *ast = getASTContext(); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 2102 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2103 | // TODO: ask about these... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2104 | // const bool IsFixed = false; |
| 2105 | |
| 2106 | EnumDecl *enum_decl = EnumDecl::Create( |
| 2107 | *ast, decl_ctx, SourceLocation(), SourceLocation(), |
| 2108 | name && name[0] ? &ast->Idents.get(name) : nullptr, nullptr, |
Tamas Berghammer | cf6bf4c | 2017-11-07 13:43:55 +0000 | [diff] [blame] | 2109 | is_scoped, // IsScoped |
| 2110 | is_scoped, // IsScopedUsingClassTag |
| 2111 | false); // IsFixed |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2112 | |
| 2113 | if (enum_decl) { |
| 2114 | // TODO: check if we should be setting the promotion type too? |
| 2115 | enum_decl->setIntegerType(ClangUtil::GetQualType(integer_clang_type)); |
| 2116 | |
| 2117 | enum_decl->setAccess(AS_public); // TODO respect what's in the debug info |
| 2118 | |
| 2119 | return CompilerType(ast, ast->getTagDeclType(enum_decl)); |
| 2120 | } |
| 2121 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2124 | CompilerType ClangASTContext::GetIntTypeFromBitSize(clang::ASTContext *ast, |
| 2125 | size_t bit_size, |
| 2126 | bool is_signed) { |
| 2127 | if (ast) { |
| 2128 | if (is_signed) { |
| 2129 | if (bit_size == ast->getTypeSize(ast->SignedCharTy)) |
| 2130 | return CompilerType(ast, ast->SignedCharTy); |
| 2131 | |
| 2132 | if (bit_size == ast->getTypeSize(ast->ShortTy)) |
| 2133 | return CompilerType(ast, ast->ShortTy); |
| 2134 | |
| 2135 | if (bit_size == ast->getTypeSize(ast->IntTy)) |
| 2136 | return CompilerType(ast, ast->IntTy); |
| 2137 | |
| 2138 | if (bit_size == ast->getTypeSize(ast->LongTy)) |
| 2139 | return CompilerType(ast, ast->LongTy); |
| 2140 | |
| 2141 | if (bit_size == ast->getTypeSize(ast->LongLongTy)) |
| 2142 | return CompilerType(ast, ast->LongLongTy); |
| 2143 | |
| 2144 | if (bit_size == ast->getTypeSize(ast->Int128Ty)) |
| 2145 | return CompilerType(ast, ast->Int128Ty); |
| 2146 | } else { |
| 2147 | if (bit_size == ast->getTypeSize(ast->UnsignedCharTy)) |
| 2148 | return CompilerType(ast, ast->UnsignedCharTy); |
| 2149 | |
| 2150 | if (bit_size == ast->getTypeSize(ast->UnsignedShortTy)) |
| 2151 | return CompilerType(ast, ast->UnsignedShortTy); |
| 2152 | |
| 2153 | if (bit_size == ast->getTypeSize(ast->UnsignedIntTy)) |
| 2154 | return CompilerType(ast, ast->UnsignedIntTy); |
| 2155 | |
| 2156 | if (bit_size == ast->getTypeSize(ast->UnsignedLongTy)) |
| 2157 | return CompilerType(ast, ast->UnsignedLongTy); |
| 2158 | |
| 2159 | if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy)) |
| 2160 | return CompilerType(ast, ast->UnsignedLongLongTy); |
| 2161 | |
| 2162 | if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty)) |
| 2163 | return CompilerType(ast, ast->UnsignedInt128Ty); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2164 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2165 | } |
| 2166 | return CompilerType(); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2169 | CompilerType ClangASTContext::GetPointerSizedIntType(clang::ASTContext *ast, |
| 2170 | bool is_signed) { |
| 2171 | if (ast) |
| 2172 | return GetIntTypeFromBitSize(ast, ast->getTypeSize(ast->VoidPtrTy), |
| 2173 | is_signed); |
| 2174 | return CompilerType(); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2175 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2176 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2177 | void ClangASTContext::DumpDeclContextHiearchy(clang::DeclContext *decl_ctx) { |
| 2178 | if (decl_ctx) { |
| 2179 | DumpDeclContextHiearchy(decl_ctx->getParent()); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2180 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2181 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx); |
| 2182 | if (named_decl) { |
| 2183 | printf("%20s: %s\n", decl_ctx->getDeclKindName(), |
| 2184 | named_decl->getDeclName().getAsString().c_str()); |
| 2185 | } else { |
| 2186 | printf("%20s\n", decl_ctx->getDeclKindName()); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2187 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2188 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2191 | void ClangASTContext::DumpDeclHiearchy(clang::Decl *decl) { |
| 2192 | if (decl == nullptr) |
| 2193 | return; |
| 2194 | DumpDeclContextHiearchy(decl->getDeclContext()); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2195 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2196 | clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl); |
| 2197 | if (record_decl) { |
| 2198 | printf("%20s: %s%s\n", decl->getDeclKindName(), |
| 2199 | record_decl->getDeclName().getAsString().c_str(), |
| 2200 | record_decl->isInjectedClassName() ? " (injected class name)" : ""); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2201 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2202 | } else { |
| 2203 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl); |
| 2204 | if (named_decl) { |
| 2205 | printf("%20s: %s\n", decl->getDeclKindName(), |
| 2206 | named_decl->getDeclName().getAsString().c_str()); |
| 2207 | } else { |
| 2208 | printf("%20s\n", decl->getDeclKindName()); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2209 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2210 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2213 | bool ClangASTContext::DeclsAreEquivalent(clang::Decl *lhs_decl, |
| 2214 | clang::Decl *rhs_decl) { |
| 2215 | if (lhs_decl && rhs_decl) { |
| 2216 | //---------------------------------------------------------------------- |
| 2217 | // Make sure the decl kinds match first |
| 2218 | //---------------------------------------------------------------------- |
| 2219 | const clang::Decl::Kind lhs_decl_kind = lhs_decl->getKind(); |
| 2220 | const clang::Decl::Kind rhs_decl_kind = rhs_decl->getKind(); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2221 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2222 | if (lhs_decl_kind == rhs_decl_kind) { |
| 2223 | //------------------------------------------------------------------ |
| 2224 | // Now check that the decl contexts kinds are all equivalent |
| 2225 | // before we have to check any names of the decl contexts... |
| 2226 | //------------------------------------------------------------------ |
| 2227 | clang::DeclContext *lhs_decl_ctx = lhs_decl->getDeclContext(); |
| 2228 | clang::DeclContext *rhs_decl_ctx = rhs_decl->getDeclContext(); |
| 2229 | if (lhs_decl_ctx && rhs_decl_ctx) { |
| 2230 | while (1) { |
| 2231 | if (lhs_decl_ctx && rhs_decl_ctx) { |
| 2232 | const clang::Decl::Kind lhs_decl_ctx_kind = |
| 2233 | lhs_decl_ctx->getDeclKind(); |
| 2234 | const clang::Decl::Kind rhs_decl_ctx_kind = |
| 2235 | rhs_decl_ctx->getDeclKind(); |
| 2236 | if (lhs_decl_ctx_kind == rhs_decl_ctx_kind) { |
| 2237 | lhs_decl_ctx = lhs_decl_ctx->getParent(); |
| 2238 | rhs_decl_ctx = rhs_decl_ctx->getParent(); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2239 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2240 | if (lhs_decl_ctx == nullptr && rhs_decl_ctx == nullptr) |
| 2241 | break; |
| 2242 | } else |
| 2243 | return false; |
| 2244 | } else |
Tamas Berghammer | fcf334b | 2015-12-02 11:35:54 +0000 | [diff] [blame] | 2245 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | //-------------------------------------------------------------- |
| 2249 | // Now make sure the name of the decls match |
| 2250 | //-------------------------------------------------------------- |
| 2251 | clang::NamedDecl *lhs_named_decl = |
| 2252 | llvm::dyn_cast<clang::NamedDecl>(lhs_decl); |
| 2253 | clang::NamedDecl *rhs_named_decl = |
| 2254 | llvm::dyn_cast<clang::NamedDecl>(rhs_decl); |
| 2255 | if (lhs_named_decl && rhs_named_decl) { |
| 2256 | clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName(); |
| 2257 | clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName(); |
| 2258 | if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) { |
| 2259 | if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString()) |
| 2260 | return false; |
| 2261 | } else |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2262 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2263 | } else |
| 2264 | return false; |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2265 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2266 | //-------------------------------------------------------------- |
| 2267 | // We know that the decl context kinds all match, so now we need |
| 2268 | // to make sure the names match as well |
| 2269 | //-------------------------------------------------------------- |
| 2270 | lhs_decl_ctx = lhs_decl->getDeclContext(); |
| 2271 | rhs_decl_ctx = rhs_decl->getDeclContext(); |
| 2272 | while (1) { |
| 2273 | switch (lhs_decl_ctx->getDeclKind()) { |
| 2274 | case clang::Decl::TranslationUnit: |
| 2275 | // We don't care about the translation unit names |
| 2276 | return true; |
| 2277 | default: { |
| 2278 | clang::NamedDecl *lhs_named_decl = |
| 2279 | llvm::dyn_cast<clang::NamedDecl>(lhs_decl_ctx); |
| 2280 | clang::NamedDecl *rhs_named_decl = |
| 2281 | llvm::dyn_cast<clang::NamedDecl>(rhs_decl_ctx); |
| 2282 | if (lhs_named_decl && rhs_named_decl) { |
| 2283 | clang::DeclarationName lhs_decl_name = |
| 2284 | lhs_named_decl->getDeclName(); |
| 2285 | clang::DeclarationName rhs_decl_name = |
| 2286 | rhs_named_decl->getDeclName(); |
| 2287 | if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) { |
| 2288 | if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString()) |
| 2289 | return false; |
| 2290 | } else |
| 2291 | return false; |
| 2292 | } else |
| 2293 | return false; |
| 2294 | } break; |
| 2295 | } |
| 2296 | lhs_decl_ctx = lhs_decl_ctx->getParent(); |
| 2297 | rhs_decl_ctx = rhs_decl_ctx->getParent(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2298 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2299 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2300 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2301 | } |
| 2302 | return false; |
| 2303 | } |
| 2304 | bool ClangASTContext::GetCompleteDecl(clang::ASTContext *ast, |
| 2305 | clang::Decl *decl) { |
| 2306 | if (!decl) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2307 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2308 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2309 | ExternalASTSource *ast_source = ast->getExternalSource(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2310 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2311 | if (!ast_source) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2312 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2313 | |
| 2314 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) { |
| 2315 | if (tag_decl->isCompleteDefinition()) |
| 2316 | return true; |
| 2317 | |
| 2318 | if (!tag_decl->hasExternalLexicalStorage()) |
| 2319 | return false; |
| 2320 | |
| 2321 | ast_source->CompleteType(tag_decl); |
| 2322 | |
| 2323 | return !tag_decl->getTypeForDecl()->isIncompleteType(); |
| 2324 | } else if (clang::ObjCInterfaceDecl *objc_interface_decl = |
| 2325 | llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) { |
| 2326 | if (objc_interface_decl->getDefinition()) |
| 2327 | return true; |
| 2328 | |
| 2329 | if (!objc_interface_decl->hasExternalLexicalStorage()) |
| 2330 | return false; |
| 2331 | |
| 2332 | ast_source->CompleteType(objc_interface_decl); |
| 2333 | |
| 2334 | return !objc_interface_decl->getTypeForDecl()->isIncompleteType(); |
| 2335 | } else { |
| 2336 | return false; |
| 2337 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2340 | void ClangASTContext::SetMetadataAsUserID(const void *object, |
| 2341 | user_id_t user_id) { |
| 2342 | ClangASTMetadata meta_data; |
| 2343 | meta_data.SetUserID(user_id); |
| 2344 | SetMetadata(object, meta_data); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2347 | void ClangASTContext::SetMetadata(clang::ASTContext *ast, const void *object, |
| 2348 | ClangASTMetadata &metadata) { |
| 2349 | ClangExternalASTSourceCommon *external_source = |
| 2350 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); |
| 2351 | |
| 2352 | if (external_source) |
| 2353 | external_source->SetMetadata(object, metadata); |
| 2354 | } |
| 2355 | |
| 2356 | ClangASTMetadata *ClangASTContext::GetMetadata(clang::ASTContext *ast, |
| 2357 | const void *object) { |
| 2358 | ClangExternalASTSourceCommon *external_source = |
| 2359 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); |
| 2360 | |
| 2361 | if (external_source && external_source->HasMetadata(object)) |
| 2362 | return external_source->GetMetadata(object); |
| 2363 | else |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2364 | return nullptr; |
| 2365 | } |
| 2366 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2367 | clang::DeclContext * |
| 2368 | ClangASTContext::GetAsDeclContext(clang::CXXMethodDecl *cxx_method_decl) { |
| 2369 | return llvm::dyn_cast<clang::DeclContext>(cxx_method_decl); |
| 2370 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2371 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2372 | clang::DeclContext * |
| 2373 | ClangASTContext::GetAsDeclContext(clang::ObjCMethodDecl *objc_method_decl) { |
| 2374 | return llvm::dyn_cast<clang::DeclContext>(objc_method_decl); |
| 2375 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2376 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2377 | bool ClangASTContext::SetTagTypeKind(clang::QualType tag_qual_type, |
| 2378 | int kind) const { |
| 2379 | const clang::Type *clang_type = tag_qual_type.getTypePtr(); |
| 2380 | if (clang_type) { |
| 2381 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(clang_type); |
| 2382 | if (tag_type) { |
| 2383 | clang::TagDecl *tag_decl = |
| 2384 | llvm::dyn_cast<clang::TagDecl>(tag_type->getDecl()); |
| 2385 | if (tag_decl) { |
| 2386 | tag_decl->setTagKind((clang::TagDecl::TagKind)kind); |
| 2387 | return true; |
| 2388 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2389 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2390 | } |
| 2391 | return false; |
| 2392 | } |
| 2393 | |
| 2394 | bool ClangASTContext::SetDefaultAccessForRecordFields( |
| 2395 | clang::RecordDecl *record_decl, int default_accessibility, |
| 2396 | int *assigned_accessibilities, size_t num_assigned_accessibilities) { |
| 2397 | if (record_decl) { |
| 2398 | uint32_t field_idx; |
| 2399 | clang::RecordDecl::field_iterator field, field_end; |
| 2400 | for (field = record_decl->field_begin(), |
| 2401 | field_end = record_decl->field_end(), field_idx = 0; |
| 2402 | field != field_end; ++field, ++field_idx) { |
| 2403 | // If no accessibility was assigned, assign the correct one |
| 2404 | if (field_idx < num_assigned_accessibilities && |
| 2405 | assigned_accessibilities[field_idx] == clang::AS_none) |
| 2406 | field->setAccess((clang::AccessSpecifier)default_accessibility); |
| 2407 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2408 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2409 | } |
| 2410 | return false; |
| 2411 | } |
| 2412 | |
| 2413 | clang::DeclContext * |
| 2414 | ClangASTContext::GetDeclContextForType(const CompilerType &type) { |
| 2415 | return GetDeclContextForType(ClangUtil::GetQualType(type)); |
| 2416 | } |
| 2417 | |
| 2418 | clang::DeclContext * |
| 2419 | ClangASTContext::GetDeclContextForType(clang::QualType type) { |
| 2420 | if (type.isNull()) |
| 2421 | return nullptr; |
| 2422 | |
| 2423 | clang::QualType qual_type = type.getCanonicalType(); |
| 2424 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2425 | switch (type_class) { |
| 2426 | case clang::Type::ObjCInterface: |
| 2427 | return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr()) |
| 2428 | ->getInterface(); |
| 2429 | case clang::Type::ObjCObjectPointer: |
| 2430 | return GetDeclContextForType( |
| 2431 | llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()) |
| 2432 | ->getPointeeType()); |
| 2433 | case clang::Type::Record: |
| 2434 | return llvm::cast<clang::RecordType>(qual_type)->getDecl(); |
| 2435 | case clang::Type::Enum: |
| 2436 | return llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 2437 | case clang::Type::Typedef: |
| 2438 | return GetDeclContextForType(llvm::cast<clang::TypedefType>(qual_type) |
| 2439 | ->getDecl() |
| 2440 | ->getUnderlyingType()); |
| 2441 | case clang::Type::Auto: |
| 2442 | return GetDeclContextForType( |
| 2443 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()); |
| 2444 | case clang::Type::Elaborated: |
| 2445 | return GetDeclContextForType( |
| 2446 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); |
| 2447 | case clang::Type::Paren: |
| 2448 | return GetDeclContextForType( |
| 2449 | llvm::cast<clang::ParenType>(qual_type)->desugar()); |
| 2450 | default: |
| 2451 | break; |
| 2452 | } |
| 2453 | // No DeclContext in this type... |
| 2454 | return nullptr; |
| 2455 | } |
| 2456 | |
| 2457 | static bool GetCompleteQualType(clang::ASTContext *ast, |
| 2458 | clang::QualType qual_type, |
| 2459 | bool allow_completion = true) { |
| 2460 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2461 | switch (type_class) { |
| 2462 | case clang::Type::ConstantArray: |
| 2463 | case clang::Type::IncompleteArray: |
| 2464 | case clang::Type::VariableArray: { |
| 2465 | const clang::ArrayType *array_type = |
| 2466 | llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr()); |
| 2467 | |
| 2468 | if (array_type) |
| 2469 | return GetCompleteQualType(ast, array_type->getElementType(), |
| 2470 | allow_completion); |
| 2471 | } break; |
| 2472 | case clang::Type::Record: { |
| 2473 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 2474 | if (cxx_record_decl) { |
| 2475 | if (cxx_record_decl->hasExternalLexicalStorage()) { |
| 2476 | const bool is_complete = cxx_record_decl->isCompleteDefinition(); |
| 2477 | const bool fields_loaded = |
| 2478 | cxx_record_decl->hasLoadedFieldsFromExternalStorage(); |
| 2479 | if (is_complete && fields_loaded) |
| 2480 | return true; |
| 2481 | |
| 2482 | if (!allow_completion) |
| 2483 | return false; |
| 2484 | |
| 2485 | // Call the field_begin() accessor to for it to use the external source |
| 2486 | // to load the fields... |
| 2487 | clang::ExternalASTSource *external_ast_source = |
| 2488 | ast->getExternalSource(); |
| 2489 | if (external_ast_source) { |
| 2490 | external_ast_source->CompleteType(cxx_record_decl); |
| 2491 | if (cxx_record_decl->isCompleteDefinition()) { |
| 2492 | cxx_record_decl->field_begin(); |
| 2493 | cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true); |
| 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | const clang::TagType *tag_type = |
| 2499 | llvm::cast<clang::TagType>(qual_type.getTypePtr()); |
| 2500 | return !tag_type->isIncompleteType(); |
| 2501 | } break; |
| 2502 | |
| 2503 | case clang::Type::Enum: { |
| 2504 | const clang::TagType *tag_type = |
| 2505 | llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 2506 | if (tag_type) { |
| 2507 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 2508 | if (tag_decl) { |
| 2509 | if (tag_decl->getDefinition()) |
| 2510 | return true; |
| 2511 | |
| 2512 | if (!allow_completion) |
| 2513 | return false; |
| 2514 | |
| 2515 | if (tag_decl->hasExternalLexicalStorage()) { |
| 2516 | if (ast) { |
| 2517 | clang::ExternalASTSource *external_ast_source = |
| 2518 | ast->getExternalSource(); |
| 2519 | if (external_ast_source) { |
| 2520 | external_ast_source->CompleteType(tag_decl); |
| 2521 | return !tag_type->isIncompleteType(); |
| 2522 | } |
| 2523 | } |
| 2524 | } |
| 2525 | return false; |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | } break; |
| 2530 | case clang::Type::ObjCObject: |
| 2531 | case clang::Type::ObjCInterface: { |
| 2532 | const clang::ObjCObjectType *objc_class_type = |
| 2533 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 2534 | if (objc_class_type) { |
| 2535 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 2536 | objc_class_type->getInterface(); |
| 2537 | // We currently can't complete objective C types through the newly added |
| 2538 | // ASTContext |
| 2539 | // because it only supports TagDecl objects right now... |
| 2540 | if (class_interface_decl) { |
| 2541 | if (class_interface_decl->getDefinition()) |
| 2542 | return true; |
| 2543 | |
| 2544 | if (!allow_completion) |
| 2545 | return false; |
| 2546 | |
| 2547 | if (class_interface_decl->hasExternalLexicalStorage()) { |
| 2548 | if (ast) { |
| 2549 | clang::ExternalASTSource *external_ast_source = |
| 2550 | ast->getExternalSource(); |
| 2551 | if (external_ast_source) { |
| 2552 | external_ast_source->CompleteType(class_interface_decl); |
| 2553 | return !objc_class_type->isIncompleteType(); |
| 2554 | } |
| 2555 | } |
| 2556 | } |
| 2557 | return false; |
| 2558 | } |
| 2559 | } |
| 2560 | } break; |
| 2561 | |
| 2562 | case clang::Type::Typedef: |
| 2563 | return GetCompleteQualType(ast, llvm::cast<clang::TypedefType>(qual_type) |
| 2564 | ->getDecl() |
| 2565 | ->getUnderlyingType(), |
| 2566 | allow_completion); |
| 2567 | |
| 2568 | case clang::Type::Auto: |
| 2569 | return GetCompleteQualType( |
| 2570 | ast, llvm::cast<clang::AutoType>(qual_type)->getDeducedType(), |
| 2571 | allow_completion); |
| 2572 | |
| 2573 | case clang::Type::Elaborated: |
| 2574 | return GetCompleteQualType( |
| 2575 | ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(), |
| 2576 | allow_completion); |
| 2577 | |
| 2578 | case clang::Type::Paren: |
| 2579 | return GetCompleteQualType( |
| 2580 | ast, llvm::cast<clang::ParenType>(qual_type)->desugar(), |
| 2581 | allow_completion); |
| 2582 | |
| 2583 | case clang::Type::Attributed: |
| 2584 | return GetCompleteQualType( |
| 2585 | ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(), |
| 2586 | allow_completion); |
| 2587 | |
| 2588 | default: |
| 2589 | break; |
| 2590 | } |
| 2591 | |
| 2592 | return true; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | static clang::ObjCIvarDecl::AccessControl |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2596 | ConvertAccessTypeToObjCIvarAccessControl(AccessType access) { |
| 2597 | switch (access) { |
| 2598 | case eAccessNone: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2599 | return clang::ObjCIvarDecl::None; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2600 | case eAccessPublic: |
| 2601 | return clang::ObjCIvarDecl::Public; |
| 2602 | case eAccessPrivate: |
| 2603 | return clang::ObjCIvarDecl::Private; |
| 2604 | case eAccessProtected: |
| 2605 | return clang::ObjCIvarDecl::Protected; |
| 2606 | case eAccessPackage: |
| 2607 | return clang::ObjCIvarDecl::Package; |
| 2608 | } |
| 2609 | return clang::ObjCIvarDecl::None; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2610 | } |
| 2611 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2612 | //---------------------------------------------------------------------- |
| 2613 | // Tests |
| 2614 | //---------------------------------------------------------------------- |
| 2615 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2616 | bool ClangASTContext::IsAggregateType(lldb::opaque_compiler_type_t type) { |
| 2617 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2618 | |
| 2619 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2620 | switch (type_class) { |
| 2621 | case clang::Type::IncompleteArray: |
| 2622 | case clang::Type::VariableArray: |
| 2623 | case clang::Type::ConstantArray: |
| 2624 | case clang::Type::ExtVector: |
| 2625 | case clang::Type::Vector: |
| 2626 | case clang::Type::Record: |
| 2627 | case clang::Type::ObjCObject: |
| 2628 | case clang::Type::ObjCInterface: |
| 2629 | return true; |
| 2630 | case clang::Type::Auto: |
| 2631 | return IsAggregateType(llvm::cast<clang::AutoType>(qual_type) |
| 2632 | ->getDeducedType() |
| 2633 | .getAsOpaquePtr()); |
| 2634 | case clang::Type::Elaborated: |
| 2635 | return IsAggregateType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 2636 | ->getNamedType() |
| 2637 | .getAsOpaquePtr()); |
| 2638 | case clang::Type::Typedef: |
| 2639 | return IsAggregateType(llvm::cast<clang::TypedefType>(qual_type) |
| 2640 | ->getDecl() |
| 2641 | ->getUnderlyingType() |
| 2642 | .getAsOpaquePtr()); |
| 2643 | case clang::Type::Paren: |
| 2644 | return IsAggregateType( |
| 2645 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 2646 | default: |
| 2647 | break; |
| 2648 | } |
| 2649 | // The clang type does have a value |
| 2650 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2653 | bool ClangASTContext::IsAnonymousType(lldb::opaque_compiler_type_t type) { |
| 2654 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2655 | |
| 2656 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2657 | switch (type_class) { |
| 2658 | case clang::Type::Record: { |
| 2659 | if (const clang::RecordType *record_type = |
| 2660 | llvm::dyn_cast_or_null<clang::RecordType>( |
| 2661 | qual_type.getTypePtrOrNull())) { |
| 2662 | if (const clang::RecordDecl *record_decl = record_type->getDecl()) { |
| 2663 | return record_decl->isAnonymousStructOrUnion(); |
| 2664 | } |
Enrico Granata | 7123e2b | 2015-11-07 02:06:57 +0000 | [diff] [blame] | 2665 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2666 | break; |
| 2667 | } |
| 2668 | case clang::Type::Auto: |
| 2669 | return IsAnonymousType(llvm::cast<clang::AutoType>(qual_type) |
| 2670 | ->getDeducedType() |
| 2671 | .getAsOpaquePtr()); |
| 2672 | case clang::Type::Elaborated: |
| 2673 | return IsAnonymousType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 2674 | ->getNamedType() |
| 2675 | .getAsOpaquePtr()); |
| 2676 | case clang::Type::Typedef: |
| 2677 | return IsAnonymousType(llvm::cast<clang::TypedefType>(qual_type) |
| 2678 | ->getDecl() |
| 2679 | ->getUnderlyingType() |
| 2680 | .getAsOpaquePtr()); |
| 2681 | case clang::Type::Paren: |
| 2682 | return IsAnonymousType( |
| 2683 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 2684 | default: |
| 2685 | break; |
| 2686 | } |
| 2687 | // The clang type does have a value |
| 2688 | return false; |
Enrico Granata | 7123e2b | 2015-11-07 02:06:57 +0000 | [diff] [blame] | 2689 | } |
| 2690 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2691 | bool ClangASTContext::IsArrayType(lldb::opaque_compiler_type_t type, |
| 2692 | CompilerType *element_type_ptr, |
| 2693 | uint64_t *size, bool *is_incomplete) { |
| 2694 | clang::QualType qual_type(GetCanonicalQualType(type)); |
Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2695 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2696 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2697 | switch (type_class) { |
| 2698 | default: |
| 2699 | break; |
Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2700 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2701 | case clang::Type::ConstantArray: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2702 | if (element_type_ptr) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2703 | element_type_ptr->SetCompilerType( |
| 2704 | getASTContext(), |
| 2705 | llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2706 | if (size) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2707 | *size = llvm::cast<clang::ConstantArrayType>(qual_type) |
| 2708 | ->getSize() |
| 2709 | .getLimitedValue(ULLONG_MAX); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2710 | if (is_incomplete) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2711 | *is_incomplete = false; |
| 2712 | return true; |
| 2713 | |
| 2714 | case clang::Type::IncompleteArray: |
| 2715 | if (element_type_ptr) |
| 2716 | element_type_ptr->SetCompilerType( |
| 2717 | getASTContext(), |
| 2718 | llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType()); |
| 2719 | if (size) |
| 2720 | *size = 0; |
| 2721 | if (is_incomplete) |
| 2722 | *is_incomplete = true; |
| 2723 | return true; |
| 2724 | |
| 2725 | case clang::Type::VariableArray: |
| 2726 | if (element_type_ptr) |
| 2727 | element_type_ptr->SetCompilerType( |
| 2728 | getASTContext(), |
| 2729 | llvm::cast<clang::VariableArrayType>(qual_type)->getElementType()); |
| 2730 | if (size) |
| 2731 | *size = 0; |
| 2732 | if (is_incomplete) |
| 2733 | *is_incomplete = false; |
| 2734 | return true; |
| 2735 | |
| 2736 | case clang::Type::DependentSizedArray: |
| 2737 | if (element_type_ptr) |
| 2738 | element_type_ptr->SetCompilerType( |
| 2739 | getASTContext(), llvm::cast<clang::DependentSizedArrayType>(qual_type) |
| 2740 | ->getElementType()); |
| 2741 | if (size) |
| 2742 | *size = 0; |
| 2743 | if (is_incomplete) |
| 2744 | *is_incomplete = false; |
| 2745 | return true; |
| 2746 | |
| 2747 | case clang::Type::Typedef: |
| 2748 | return IsArrayType(llvm::cast<clang::TypedefType>(qual_type) |
| 2749 | ->getDecl() |
| 2750 | ->getUnderlyingType() |
| 2751 | .getAsOpaquePtr(), |
| 2752 | element_type_ptr, size, is_incomplete); |
| 2753 | case clang::Type::Auto: |
| 2754 | return IsArrayType(llvm::cast<clang::AutoType>(qual_type) |
| 2755 | ->getDeducedType() |
| 2756 | .getAsOpaquePtr(), |
| 2757 | element_type_ptr, size, is_incomplete); |
| 2758 | case clang::Type::Elaborated: |
| 2759 | return IsArrayType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 2760 | ->getNamedType() |
| 2761 | .getAsOpaquePtr(), |
| 2762 | element_type_ptr, size, is_incomplete); |
| 2763 | case clang::Type::Paren: |
| 2764 | return IsArrayType( |
| 2765 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 2766 | element_type_ptr, size, is_incomplete); |
| 2767 | } |
| 2768 | if (element_type_ptr) |
| 2769 | element_type_ptr->Clear(); |
| 2770 | if (size) |
| 2771 | *size = 0; |
| 2772 | if (is_incomplete) |
| 2773 | *is_incomplete = false; |
| 2774 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2777 | bool ClangASTContext::IsVectorType(lldb::opaque_compiler_type_t type, |
| 2778 | CompilerType *element_type, uint64_t *size) { |
| 2779 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2780 | |
| 2781 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2782 | switch (type_class) { |
| 2783 | case clang::Type::Vector: { |
| 2784 | const clang::VectorType *vector_type = |
| 2785 | qual_type->getAs<clang::VectorType>(); |
| 2786 | if (vector_type) { |
| 2787 | if (size) |
| 2788 | *size = vector_type->getNumElements(); |
| 2789 | if (element_type) |
| 2790 | *element_type = |
| 2791 | CompilerType(getASTContext(), vector_type->getElementType()); |
| 2792 | } |
| 2793 | return true; |
| 2794 | } break; |
| 2795 | case clang::Type::ExtVector: { |
| 2796 | const clang::ExtVectorType *ext_vector_type = |
| 2797 | qual_type->getAs<clang::ExtVectorType>(); |
| 2798 | if (ext_vector_type) { |
| 2799 | if (size) |
| 2800 | *size = ext_vector_type->getNumElements(); |
| 2801 | if (element_type) |
| 2802 | *element_type = |
| 2803 | CompilerType(getASTContext(), ext_vector_type->getElementType()); |
| 2804 | } |
| 2805 | return true; |
| 2806 | } |
| 2807 | default: |
| 2808 | break; |
| 2809 | } |
| 2810 | return false; |
| 2811 | } |
| 2812 | |
| 2813 | bool ClangASTContext::IsRuntimeGeneratedType( |
| 2814 | lldb::opaque_compiler_type_t type) { |
| 2815 | clang::DeclContext *decl_ctx = ClangASTContext::GetASTContext(getASTContext()) |
| 2816 | ->GetDeclContextForType(GetQualType(type)); |
| 2817 | if (!decl_ctx) |
| 2818 | return false; |
| 2819 | |
| 2820 | if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx)) |
| 2821 | return false; |
| 2822 | |
| 2823 | clang::ObjCInterfaceDecl *result_iface_decl = |
| 2824 | llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx); |
| 2825 | |
| 2826 | ClangASTMetadata *ast_metadata = |
| 2827 | ClangASTContext::GetMetadata(getASTContext(), result_iface_decl); |
| 2828 | if (!ast_metadata) |
| 2829 | return false; |
| 2830 | return (ast_metadata->GetISAPtr() != 0); |
| 2831 | } |
| 2832 | |
| 2833 | bool ClangASTContext::IsCharType(lldb::opaque_compiler_type_t type) { |
| 2834 | return GetQualType(type).getUnqualifiedType()->isCharType(); |
| 2835 | } |
| 2836 | |
| 2837 | bool ClangASTContext::IsCompleteType(lldb::opaque_compiler_type_t type) { |
| 2838 | const bool allow_completion = false; |
| 2839 | return GetCompleteQualType(getASTContext(), GetQualType(type), |
| 2840 | allow_completion); |
| 2841 | } |
| 2842 | |
| 2843 | bool ClangASTContext::IsConst(lldb::opaque_compiler_type_t type) { |
| 2844 | return GetQualType(type).isConstQualified(); |
| 2845 | } |
| 2846 | |
| 2847 | bool ClangASTContext::IsCStringType(lldb::opaque_compiler_type_t type, |
| 2848 | uint32_t &length) { |
| 2849 | CompilerType pointee_or_element_clang_type; |
| 2850 | length = 0; |
| 2851 | Flags type_flags(GetTypeInfo(type, &pointee_or_element_clang_type)); |
| 2852 | |
| 2853 | if (!pointee_or_element_clang_type.IsValid()) |
| 2854 | return false; |
| 2855 | |
| 2856 | if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer)) { |
| 2857 | if (pointee_or_element_clang_type.IsCharType()) { |
| 2858 | if (type_flags.Test(eTypeIsArray)) { |
| 2859 | // We know the size of the array and it could be a C string |
| 2860 | // since it is an array of characters |
| 2861 | length = llvm::cast<clang::ConstantArrayType>( |
| 2862 | GetCanonicalQualType(type).getTypePtr()) |
| 2863 | ->getSize() |
| 2864 | .getLimitedValue(); |
| 2865 | } |
| 2866 | return true; |
| 2867 | } |
| 2868 | } |
| 2869 | return false; |
| 2870 | } |
| 2871 | |
| 2872 | bool ClangASTContext::IsFunctionType(lldb::opaque_compiler_type_t type, |
| 2873 | bool *is_variadic_ptr) { |
| 2874 | if (type) { |
| 2875 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2876 | |
| 2877 | if (qual_type->isFunctionType()) { |
| 2878 | if (is_variadic_ptr) { |
| 2879 | const clang::FunctionProtoType *function_proto_type = |
| 2880 | llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 2881 | if (function_proto_type) |
| 2882 | *is_variadic_ptr = function_proto_type->isVariadic(); |
| 2883 | else |
| 2884 | *is_variadic_ptr = false; |
| 2885 | } |
| 2886 | return true; |
| 2887 | } |
| 2888 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2889 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2890 | switch (type_class) { |
| 2891 | default: |
| 2892 | break; |
| 2893 | case clang::Type::Typedef: |
| 2894 | return IsFunctionType(llvm::cast<clang::TypedefType>(qual_type) |
| 2895 | ->getDecl() |
| 2896 | ->getUnderlyingType() |
| 2897 | .getAsOpaquePtr(), |
| 2898 | nullptr); |
| 2899 | case clang::Type::Auto: |
| 2900 | return IsFunctionType(llvm::cast<clang::AutoType>(qual_type) |
| 2901 | ->getDeducedType() |
| 2902 | .getAsOpaquePtr(), |
| 2903 | nullptr); |
| 2904 | case clang::Type::Elaborated: |
| 2905 | return IsFunctionType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 2906 | ->getNamedType() |
| 2907 | .getAsOpaquePtr(), |
| 2908 | nullptr); |
| 2909 | case clang::Type::Paren: |
| 2910 | return IsFunctionType( |
| 2911 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 2912 | nullptr); |
| 2913 | case clang::Type::LValueReference: |
| 2914 | case clang::Type::RValueReference: { |
| 2915 | const clang::ReferenceType *reference_type = |
| 2916 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 2917 | if (reference_type) |
| 2918 | return IsFunctionType(reference_type->getPointeeType().getAsOpaquePtr(), |
| 2919 | nullptr); |
| 2920 | } break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2921 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2922 | } |
| 2923 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | // Used to detect "Homogeneous Floating-point Aggregates" |
| 2927 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2928 | ClangASTContext::IsHomogeneousAggregate(lldb::opaque_compiler_type_t type, |
| 2929 | CompilerType *base_type_ptr) { |
| 2930 | if (!type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2931 | return 0; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2932 | |
| 2933 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2934 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2935 | switch (type_class) { |
| 2936 | case clang::Type::Record: |
| 2937 | if (GetCompleteType(type)) { |
| 2938 | const clang::CXXRecordDecl *cxx_record_decl = |
| 2939 | qual_type->getAsCXXRecordDecl(); |
| 2940 | if (cxx_record_decl) { |
| 2941 | if (cxx_record_decl->getNumBases() || cxx_record_decl->isDynamicClass()) |
| 2942 | return 0; |
| 2943 | } |
| 2944 | const clang::RecordType *record_type = |
| 2945 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 2946 | if (record_type) { |
| 2947 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 2948 | if (record_decl) { |
| 2949 | // We are looking for a structure that contains only floating point |
| 2950 | // types |
| 2951 | clang::RecordDecl::field_iterator field_pos, |
| 2952 | field_end = record_decl->field_end(); |
| 2953 | uint32_t num_fields = 0; |
| 2954 | bool is_hva = false; |
| 2955 | bool is_hfa = false; |
| 2956 | clang::QualType base_qual_type; |
| 2957 | uint64_t base_bitwidth = 0; |
| 2958 | for (field_pos = record_decl->field_begin(); field_pos != field_end; |
| 2959 | ++field_pos) { |
| 2960 | clang::QualType field_qual_type = field_pos->getType(); |
| 2961 | uint64_t field_bitwidth = getASTContext()->getTypeSize(qual_type); |
| 2962 | if (field_qual_type->isFloatingType()) { |
| 2963 | if (field_qual_type->isComplexType()) |
| 2964 | return 0; |
| 2965 | else { |
| 2966 | if (num_fields == 0) |
| 2967 | base_qual_type = field_qual_type; |
| 2968 | else { |
| 2969 | if (is_hva) |
| 2970 | return 0; |
| 2971 | is_hfa = true; |
| 2972 | if (field_qual_type.getTypePtr() != |
| 2973 | base_qual_type.getTypePtr()) |
| 2974 | return 0; |
| 2975 | } |
| 2976 | } |
| 2977 | } else if (field_qual_type->isVectorType() || |
| 2978 | field_qual_type->isExtVectorType()) { |
| 2979 | if (num_fields == 0) { |
| 2980 | base_qual_type = field_qual_type; |
| 2981 | base_bitwidth = field_bitwidth; |
| 2982 | } else { |
| 2983 | if (is_hfa) |
| 2984 | return 0; |
| 2985 | is_hva = true; |
| 2986 | if (base_bitwidth != field_bitwidth) |
| 2987 | return 0; |
| 2988 | if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr()) |
| 2989 | return 0; |
| 2990 | } |
| 2991 | } else |
| 2992 | return 0; |
| 2993 | ++num_fields; |
| 2994 | } |
| 2995 | if (base_type_ptr) |
| 2996 | *base_type_ptr = CompilerType(getASTContext(), base_qual_type); |
| 2997 | return num_fields; |
| 2998 | } |
| 2999 | } |
| 3000 | } |
| 3001 | break; |
| 3002 | |
| 3003 | case clang::Type::Typedef: |
| 3004 | return IsHomogeneousAggregate(llvm::cast<clang::TypedefType>(qual_type) |
| 3005 | ->getDecl() |
| 3006 | ->getUnderlyingType() |
| 3007 | .getAsOpaquePtr(), |
| 3008 | base_type_ptr); |
| 3009 | |
| 3010 | case clang::Type::Auto: |
| 3011 | return IsHomogeneousAggregate(llvm::cast<clang::AutoType>(qual_type) |
| 3012 | ->getDeducedType() |
| 3013 | .getAsOpaquePtr(), |
| 3014 | base_type_ptr); |
| 3015 | |
| 3016 | case clang::Type::Elaborated: |
| 3017 | return IsHomogeneousAggregate(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3018 | ->getNamedType() |
| 3019 | .getAsOpaquePtr(), |
| 3020 | base_type_ptr); |
| 3021 | default: |
| 3022 | break; |
| 3023 | } |
| 3024 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3025 | } |
| 3026 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3027 | size_t ClangASTContext::GetNumberOfFunctionArguments( |
| 3028 | lldb::opaque_compiler_type_t type) { |
| 3029 | if (type) { |
| 3030 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3031 | const clang::FunctionProtoType *func = |
| 3032 | llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 3033 | if (func) |
| 3034 | return func->getNumParams(); |
| 3035 | } |
| 3036 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3039 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3040 | ClangASTContext::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type, |
| 3041 | const size_t index) { |
| 3042 | if (type) { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3043 | clang::QualType qual_type(GetQualType(type)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3044 | const clang::FunctionProtoType *func = |
| 3045 | llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 3046 | if (func) { |
| 3047 | if (index < func->getNumParams()) |
| 3048 | return CompilerType(getASTContext(), func->getParamType(index)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3049 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3050 | } |
| 3051 | return CompilerType(); |
| 3052 | } |
| 3053 | |
| 3054 | bool ClangASTContext::IsFunctionPointerType(lldb::opaque_compiler_type_t type) { |
| 3055 | if (type) { |
| 3056 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3057 | |
| 3058 | if (qual_type->isFunctionPointerType()) |
| 3059 | return true; |
| 3060 | |
| 3061 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3062 | switch (type_class) { |
| 3063 | default: |
| 3064 | break; |
| 3065 | case clang::Type::Typedef: |
| 3066 | return IsFunctionPointerType(llvm::cast<clang::TypedefType>(qual_type) |
| 3067 | ->getDecl() |
| 3068 | ->getUnderlyingType() |
| 3069 | .getAsOpaquePtr()); |
| 3070 | case clang::Type::Auto: |
| 3071 | return IsFunctionPointerType(llvm::cast<clang::AutoType>(qual_type) |
| 3072 | ->getDeducedType() |
| 3073 | .getAsOpaquePtr()); |
| 3074 | case clang::Type::Elaborated: |
| 3075 | return IsFunctionPointerType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3076 | ->getNamedType() |
| 3077 | .getAsOpaquePtr()); |
| 3078 | case clang::Type::Paren: |
| 3079 | return IsFunctionPointerType( |
| 3080 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 3081 | |
| 3082 | case clang::Type::LValueReference: |
| 3083 | case clang::Type::RValueReference: { |
| 3084 | const clang::ReferenceType *reference_type = |
| 3085 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 3086 | if (reference_type) |
| 3087 | return IsFunctionPointerType( |
| 3088 | reference_type->getPointeeType().getAsOpaquePtr()); |
| 3089 | } break; |
| 3090 | } |
| 3091 | } |
| 3092 | return false; |
| 3093 | } |
| 3094 | |
| 3095 | bool ClangASTContext::IsBlockPointerType( |
| 3096 | lldb::opaque_compiler_type_t type, |
| 3097 | CompilerType *function_pointer_type_ptr) { |
| 3098 | if (type) { |
| 3099 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3100 | |
| 3101 | if (qual_type->isBlockPointerType()) { |
| 3102 | if (function_pointer_type_ptr) { |
| 3103 | const clang::BlockPointerType *block_pointer_type = |
| 3104 | qual_type->getAs<clang::BlockPointerType>(); |
| 3105 | QualType pointee_type = block_pointer_type->getPointeeType(); |
| 3106 | QualType function_pointer_type = m_ast_ap->getPointerType(pointee_type); |
| 3107 | *function_pointer_type_ptr = |
| 3108 | CompilerType(getASTContext(), function_pointer_type); |
| 3109 | } |
| 3110 | return true; |
| 3111 | } |
| 3112 | |
| 3113 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3114 | switch (type_class) { |
| 3115 | default: |
| 3116 | break; |
| 3117 | case clang::Type::Typedef: |
| 3118 | return IsBlockPointerType(llvm::cast<clang::TypedefType>(qual_type) |
| 3119 | ->getDecl() |
| 3120 | ->getUnderlyingType() |
| 3121 | .getAsOpaquePtr(), |
| 3122 | function_pointer_type_ptr); |
| 3123 | case clang::Type::Auto: |
| 3124 | return IsBlockPointerType(llvm::cast<clang::AutoType>(qual_type) |
| 3125 | ->getDeducedType() |
| 3126 | .getAsOpaquePtr(), |
| 3127 | function_pointer_type_ptr); |
| 3128 | case clang::Type::Elaborated: |
| 3129 | return IsBlockPointerType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3130 | ->getNamedType() |
| 3131 | .getAsOpaquePtr(), |
| 3132 | function_pointer_type_ptr); |
| 3133 | case clang::Type::Paren: |
| 3134 | return IsBlockPointerType( |
| 3135 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3136 | function_pointer_type_ptr); |
| 3137 | |
| 3138 | case clang::Type::LValueReference: |
| 3139 | case clang::Type::RValueReference: { |
| 3140 | const clang::ReferenceType *reference_type = |
| 3141 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 3142 | if (reference_type) |
| 3143 | return IsBlockPointerType( |
| 3144 | reference_type->getPointeeType().getAsOpaquePtr(), |
| 3145 | function_pointer_type_ptr); |
| 3146 | } break; |
| 3147 | } |
| 3148 | } |
| 3149 | return false; |
| 3150 | } |
| 3151 | |
| 3152 | bool ClangASTContext::IsIntegerType(lldb::opaque_compiler_type_t type, |
| 3153 | bool &is_signed) { |
| 3154 | if (!type) |
| 3155 | return false; |
| 3156 | |
| 3157 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3158 | const clang::BuiltinType *builtin_type = |
| 3159 | llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()); |
| 3160 | |
| 3161 | if (builtin_type) { |
| 3162 | if (builtin_type->isInteger()) { |
| 3163 | is_signed = builtin_type->isSignedInteger(); |
| 3164 | return true; |
| 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | return false; |
| 3169 | } |
| 3170 | |
| 3171 | bool ClangASTContext::IsEnumerationType(lldb::opaque_compiler_type_t type, |
| 3172 | bool &is_signed) { |
| 3173 | if (type) { |
| 3174 | const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>( |
| 3175 | GetCanonicalQualType(type)->getCanonicalTypeInternal()); |
| 3176 | |
| 3177 | if (enum_type) { |
| 3178 | IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(), |
| 3179 | is_signed); |
| 3180 | return true; |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | return false; |
| 3185 | } |
| 3186 | |
| 3187 | bool ClangASTContext::IsPointerType(lldb::opaque_compiler_type_t type, |
| 3188 | CompilerType *pointee_type) { |
| 3189 | if (type) { |
| 3190 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3191 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3192 | switch (type_class) { |
| 3193 | case clang::Type::Builtin: |
| 3194 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 3195 | default: |
| 3196 | break; |
| 3197 | case clang::BuiltinType::ObjCId: |
| 3198 | case clang::BuiltinType::ObjCClass: |
| 3199 | return true; |
| 3200 | } |
| 3201 | return false; |
| 3202 | case clang::Type::ObjCObjectPointer: |
| 3203 | if (pointee_type) |
| 3204 | pointee_type->SetCompilerType( |
| 3205 | getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type) |
| 3206 | ->getPointeeType()); |
| 3207 | return true; |
| 3208 | case clang::Type::BlockPointer: |
| 3209 | if (pointee_type) |
| 3210 | pointee_type->SetCompilerType( |
| 3211 | getASTContext(), |
| 3212 | llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType()); |
| 3213 | return true; |
| 3214 | case clang::Type::Pointer: |
| 3215 | if (pointee_type) |
| 3216 | pointee_type->SetCompilerType( |
| 3217 | getASTContext(), |
| 3218 | llvm::cast<clang::PointerType>(qual_type)->getPointeeType()); |
| 3219 | return true; |
| 3220 | case clang::Type::MemberPointer: |
| 3221 | if (pointee_type) |
| 3222 | pointee_type->SetCompilerType( |
| 3223 | getASTContext(), |
| 3224 | llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType()); |
| 3225 | return true; |
| 3226 | case clang::Type::Typedef: |
| 3227 | return IsPointerType(llvm::cast<clang::TypedefType>(qual_type) |
| 3228 | ->getDecl() |
| 3229 | ->getUnderlyingType() |
| 3230 | .getAsOpaquePtr(), |
| 3231 | pointee_type); |
| 3232 | case clang::Type::Auto: |
| 3233 | return IsPointerType(llvm::cast<clang::AutoType>(qual_type) |
| 3234 | ->getDeducedType() |
| 3235 | .getAsOpaquePtr(), |
| 3236 | pointee_type); |
| 3237 | case clang::Type::Elaborated: |
| 3238 | return IsPointerType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3239 | ->getNamedType() |
| 3240 | .getAsOpaquePtr(), |
| 3241 | pointee_type); |
| 3242 | case clang::Type::Paren: |
| 3243 | return IsPointerType( |
| 3244 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3245 | pointee_type); |
| 3246 | default: |
| 3247 | break; |
| 3248 | } |
| 3249 | } |
| 3250 | if (pointee_type) |
| 3251 | pointee_type->Clear(); |
| 3252 | return false; |
| 3253 | } |
| 3254 | |
| 3255 | bool ClangASTContext::IsPointerOrReferenceType( |
| 3256 | lldb::opaque_compiler_type_t type, CompilerType *pointee_type) { |
| 3257 | if (type) { |
| 3258 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3259 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3260 | switch (type_class) { |
| 3261 | case clang::Type::Builtin: |
| 3262 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 3263 | default: |
| 3264 | break; |
| 3265 | case clang::BuiltinType::ObjCId: |
| 3266 | case clang::BuiltinType::ObjCClass: |
| 3267 | return true; |
| 3268 | } |
| 3269 | return false; |
| 3270 | case clang::Type::ObjCObjectPointer: |
| 3271 | if (pointee_type) |
| 3272 | pointee_type->SetCompilerType( |
| 3273 | getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type) |
| 3274 | ->getPointeeType()); |
| 3275 | return true; |
| 3276 | case clang::Type::BlockPointer: |
| 3277 | if (pointee_type) |
| 3278 | pointee_type->SetCompilerType( |
| 3279 | getASTContext(), |
| 3280 | llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType()); |
| 3281 | return true; |
| 3282 | case clang::Type::Pointer: |
| 3283 | if (pointee_type) |
| 3284 | pointee_type->SetCompilerType( |
| 3285 | getASTContext(), |
| 3286 | llvm::cast<clang::PointerType>(qual_type)->getPointeeType()); |
| 3287 | return true; |
| 3288 | case clang::Type::MemberPointer: |
| 3289 | if (pointee_type) |
| 3290 | pointee_type->SetCompilerType( |
| 3291 | getASTContext(), |
| 3292 | llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType()); |
| 3293 | return true; |
| 3294 | case clang::Type::LValueReference: |
| 3295 | if (pointee_type) |
| 3296 | pointee_type->SetCompilerType( |
| 3297 | getASTContext(), |
| 3298 | llvm::cast<clang::LValueReferenceType>(qual_type)->desugar()); |
| 3299 | return true; |
| 3300 | case clang::Type::RValueReference: |
| 3301 | if (pointee_type) |
| 3302 | pointee_type->SetCompilerType( |
| 3303 | getASTContext(), |
| 3304 | llvm::cast<clang::RValueReferenceType>(qual_type)->desugar()); |
| 3305 | return true; |
| 3306 | case clang::Type::Typedef: |
| 3307 | return IsPointerOrReferenceType(llvm::cast<clang::TypedefType>(qual_type) |
| 3308 | ->getDecl() |
| 3309 | ->getUnderlyingType() |
| 3310 | .getAsOpaquePtr(), |
| 3311 | pointee_type); |
| 3312 | case clang::Type::Auto: |
| 3313 | return IsPointerOrReferenceType(llvm::cast<clang::AutoType>(qual_type) |
| 3314 | ->getDeducedType() |
| 3315 | .getAsOpaquePtr(), |
| 3316 | pointee_type); |
| 3317 | case clang::Type::Elaborated: |
| 3318 | return IsPointerOrReferenceType( |
| 3319 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 3320 | ->getNamedType() |
| 3321 | .getAsOpaquePtr(), |
| 3322 | pointee_type); |
| 3323 | case clang::Type::Paren: |
| 3324 | return IsPointerOrReferenceType( |
| 3325 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3326 | pointee_type); |
| 3327 | default: |
| 3328 | break; |
| 3329 | } |
| 3330 | } |
| 3331 | if (pointee_type) |
| 3332 | pointee_type->Clear(); |
| 3333 | return false; |
| 3334 | } |
| 3335 | |
| 3336 | bool ClangASTContext::IsReferenceType(lldb::opaque_compiler_type_t type, |
| 3337 | CompilerType *pointee_type, |
| 3338 | bool *is_rvalue) { |
| 3339 | if (type) { |
| 3340 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3341 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3342 | |
| 3343 | switch (type_class) { |
| 3344 | case clang::Type::LValueReference: |
| 3345 | if (pointee_type) |
| 3346 | pointee_type->SetCompilerType( |
| 3347 | getASTContext(), |
| 3348 | llvm::cast<clang::LValueReferenceType>(qual_type)->desugar()); |
| 3349 | if (is_rvalue) |
| 3350 | *is_rvalue = false; |
| 3351 | return true; |
| 3352 | case clang::Type::RValueReference: |
| 3353 | if (pointee_type) |
| 3354 | pointee_type->SetCompilerType( |
| 3355 | getASTContext(), |
| 3356 | llvm::cast<clang::RValueReferenceType>(qual_type)->desugar()); |
| 3357 | if (is_rvalue) |
| 3358 | *is_rvalue = true; |
| 3359 | return true; |
| 3360 | case clang::Type::Typedef: |
| 3361 | return IsReferenceType(llvm::cast<clang::TypedefType>(qual_type) |
| 3362 | ->getDecl() |
| 3363 | ->getUnderlyingType() |
| 3364 | .getAsOpaquePtr(), |
| 3365 | pointee_type, is_rvalue); |
| 3366 | case clang::Type::Auto: |
| 3367 | return IsReferenceType(llvm::cast<clang::AutoType>(qual_type) |
| 3368 | ->getDeducedType() |
| 3369 | .getAsOpaquePtr(), |
| 3370 | pointee_type, is_rvalue); |
| 3371 | case clang::Type::Elaborated: |
| 3372 | return IsReferenceType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3373 | ->getNamedType() |
| 3374 | .getAsOpaquePtr(), |
| 3375 | pointee_type, is_rvalue); |
| 3376 | case clang::Type::Paren: |
| 3377 | return IsReferenceType( |
| 3378 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3379 | pointee_type, is_rvalue); |
| 3380 | |
| 3381 | default: |
| 3382 | break; |
| 3383 | } |
| 3384 | } |
| 3385 | if (pointee_type) |
| 3386 | pointee_type->Clear(); |
| 3387 | return false; |
| 3388 | } |
| 3389 | |
| 3390 | bool ClangASTContext::IsFloatingPointType(lldb::opaque_compiler_type_t type, |
| 3391 | uint32_t &count, bool &is_complex) { |
| 3392 | if (type) { |
| 3393 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3394 | |
| 3395 | if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>( |
| 3396 | qual_type->getCanonicalTypeInternal())) { |
| 3397 | clang::BuiltinType::Kind kind = BT->getKind(); |
| 3398 | if (kind >= clang::BuiltinType::Float && |
| 3399 | kind <= clang::BuiltinType::LongDouble) { |
| 3400 | count = 1; |
| 3401 | is_complex = false; |
| 3402 | return true; |
| 3403 | } |
| 3404 | } else if (const clang::ComplexType *CT = |
| 3405 | llvm::dyn_cast<clang::ComplexType>( |
| 3406 | qual_type->getCanonicalTypeInternal())) { |
| 3407 | if (IsFloatingPointType(CT->getElementType().getAsOpaquePtr(), count, |
| 3408 | is_complex)) { |
| 3409 | count = 2; |
| 3410 | is_complex = true; |
| 3411 | return true; |
| 3412 | } |
| 3413 | } else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>( |
| 3414 | qual_type->getCanonicalTypeInternal())) { |
| 3415 | if (IsFloatingPointType(VT->getElementType().getAsOpaquePtr(), count, |
| 3416 | is_complex)) { |
| 3417 | count = VT->getNumElements(); |
| 3418 | is_complex = false; |
| 3419 | return true; |
| 3420 | } |
| 3421 | } |
| 3422 | } |
| 3423 | count = 0; |
| 3424 | is_complex = false; |
| 3425 | return false; |
| 3426 | } |
| 3427 | |
| 3428 | bool ClangASTContext::IsDefined(lldb::opaque_compiler_type_t type) { |
| 3429 | if (!type) |
| 3430 | return false; |
| 3431 | |
| 3432 | clang::QualType qual_type(GetQualType(type)); |
| 3433 | const clang::TagType *tag_type = |
| 3434 | llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 3435 | if (tag_type) { |
| 3436 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 3437 | if (tag_decl) |
| 3438 | return tag_decl->isCompleteDefinition(); |
| 3439 | return false; |
| 3440 | } else { |
| 3441 | const clang::ObjCObjectType *objc_class_type = |
| 3442 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 3443 | if (objc_class_type) { |
| 3444 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 3445 | objc_class_type->getInterface(); |
| 3446 | if (class_interface_decl) |
| 3447 | return class_interface_decl->getDefinition() != nullptr; |
| 3448 | return false; |
| 3449 | } |
| 3450 | } |
| 3451 | return true; |
| 3452 | } |
| 3453 | |
| 3454 | bool ClangASTContext::IsObjCClassType(const CompilerType &type) { |
| 3455 | if (type) { |
| 3456 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
| 3457 | |
| 3458 | const clang::ObjCObjectPointerType *obj_pointer_type = |
| 3459 | llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); |
| 3460 | |
| 3461 | if (obj_pointer_type) |
| 3462 | return obj_pointer_type->isObjCClassType(); |
| 3463 | } |
| 3464 | return false; |
| 3465 | } |
| 3466 | |
| 3467 | bool ClangASTContext::IsObjCObjectOrInterfaceType(const CompilerType &type) { |
| 3468 | if (ClangUtil::IsClangType(type)) |
| 3469 | return ClangUtil::GetCanonicalQualType(type)->isObjCObjectOrInterfaceType(); |
| 3470 | return false; |
| 3471 | } |
| 3472 | |
| 3473 | bool ClangASTContext::IsClassType(lldb::opaque_compiler_type_t type) { |
| 3474 | if (!type) |
| 3475 | return false; |
| 3476 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3477 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3478 | return (type_class == clang::Type::Record); |
| 3479 | } |
| 3480 | |
| 3481 | bool ClangASTContext::IsEnumType(lldb::opaque_compiler_type_t type) { |
| 3482 | if (!type) |
| 3483 | return false; |
| 3484 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3485 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3486 | return (type_class == clang::Type::Enum); |
| 3487 | } |
| 3488 | |
| 3489 | bool ClangASTContext::IsPolymorphicClass(lldb::opaque_compiler_type_t type) { |
| 3490 | if (type) { |
| 3491 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3492 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3493 | switch (type_class) { |
| 3494 | case clang::Type::Record: |
| 3495 | if (GetCompleteType(type)) { |
| 3496 | const clang::RecordType *record_type = |
| 3497 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3498 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3499 | if (record_decl) { |
| 3500 | const clang::CXXRecordDecl *cxx_record_decl = |
| 3501 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 3502 | if (cxx_record_decl) |
| 3503 | return cxx_record_decl->isPolymorphic(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3504 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3505 | } |
| 3506 | break; |
| 3507 | |
| 3508 | default: |
| 3509 | break; |
| 3510 | } |
| 3511 | } |
| 3512 | return false; |
| 3513 | } |
| 3514 | |
| 3515 | bool ClangASTContext::IsPossibleDynamicType(lldb::opaque_compiler_type_t type, |
| 3516 | CompilerType *dynamic_pointee_type, |
| 3517 | bool check_cplusplus, |
| 3518 | bool check_objc) { |
| 3519 | clang::QualType pointee_qual_type; |
| 3520 | if (type) { |
| 3521 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3522 | bool success = false; |
| 3523 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3524 | switch (type_class) { |
| 3525 | case clang::Type::Builtin: |
| 3526 | if (check_objc && |
| 3527 | llvm::cast<clang::BuiltinType>(qual_type)->getKind() == |
| 3528 | clang::BuiltinType::ObjCId) { |
| 3529 | if (dynamic_pointee_type) |
| 3530 | dynamic_pointee_type->SetCompilerType(this, type); |
| 3531 | return true; |
| 3532 | } |
| 3533 | break; |
| 3534 | |
| 3535 | case clang::Type::ObjCObjectPointer: |
| 3536 | if (check_objc) { |
| 3537 | if (auto objc_pointee_type = |
| 3538 | qual_type->getPointeeType().getTypePtrOrNull()) { |
| 3539 | if (auto objc_object_type = |
| 3540 | llvm::dyn_cast_or_null<clang::ObjCObjectType>( |
| 3541 | objc_pointee_type)) { |
| 3542 | if (objc_object_type->isObjCClass()) |
| 3543 | return false; |
| 3544 | } |
| 3545 | } |
| 3546 | if (dynamic_pointee_type) |
| 3547 | dynamic_pointee_type->SetCompilerType( |
| 3548 | getASTContext(), |
| 3549 | llvm::cast<clang::ObjCObjectPointerType>(qual_type) |
| 3550 | ->getPointeeType()); |
| 3551 | return true; |
| 3552 | } |
| 3553 | break; |
| 3554 | |
| 3555 | case clang::Type::Pointer: |
| 3556 | pointee_qual_type = |
| 3557 | llvm::cast<clang::PointerType>(qual_type)->getPointeeType(); |
| 3558 | success = true; |
| 3559 | break; |
| 3560 | |
| 3561 | case clang::Type::LValueReference: |
| 3562 | case clang::Type::RValueReference: |
| 3563 | pointee_qual_type = |
| 3564 | llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType(); |
| 3565 | success = true; |
| 3566 | break; |
| 3567 | |
| 3568 | case clang::Type::Typedef: |
| 3569 | return IsPossibleDynamicType(llvm::cast<clang::TypedefType>(qual_type) |
| 3570 | ->getDecl() |
| 3571 | ->getUnderlyingType() |
| 3572 | .getAsOpaquePtr(), |
| 3573 | dynamic_pointee_type, check_cplusplus, |
| 3574 | check_objc); |
| 3575 | |
| 3576 | case clang::Type::Auto: |
| 3577 | return IsPossibleDynamicType(llvm::cast<clang::AutoType>(qual_type) |
| 3578 | ->getDeducedType() |
| 3579 | .getAsOpaquePtr(), |
| 3580 | dynamic_pointee_type, check_cplusplus, |
| 3581 | check_objc); |
| 3582 | |
| 3583 | case clang::Type::Elaborated: |
| 3584 | return IsPossibleDynamicType(llvm::cast<clang::ElaboratedType>(qual_type) |
| 3585 | ->getNamedType() |
| 3586 | .getAsOpaquePtr(), |
| 3587 | dynamic_pointee_type, check_cplusplus, |
| 3588 | check_objc); |
| 3589 | |
| 3590 | case clang::Type::Paren: |
| 3591 | return IsPossibleDynamicType( |
| 3592 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3593 | dynamic_pointee_type, check_cplusplus, check_objc); |
| 3594 | default: |
| 3595 | break; |
| 3596 | } |
| 3597 | |
| 3598 | if (success) { |
| 3599 | // Check to make sure what we are pointing too is a possible dynamic C++ |
| 3600 | // type |
| 3601 | // We currently accept any "void *" (in case we have a class that has been |
| 3602 | // watered down to an opaque pointer) and virtual C++ classes. |
| 3603 | const clang::Type::TypeClass pointee_type_class = |
| 3604 | pointee_qual_type.getCanonicalType()->getTypeClass(); |
| 3605 | switch (pointee_type_class) { |
| 3606 | case clang::Type::Builtin: |
| 3607 | switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) { |
| 3608 | case clang::BuiltinType::UnknownAny: |
| 3609 | case clang::BuiltinType::Void: |
| 3610 | if (dynamic_pointee_type) |
| 3611 | dynamic_pointee_type->SetCompilerType(getASTContext(), |
| 3612 | pointee_qual_type); |
| 3613 | return true; |
| 3614 | default: |
| 3615 | break; |
| 3616 | } |
| 3617 | break; |
| 3618 | |
| 3619 | case clang::Type::Record: |
| 3620 | if (check_cplusplus) { |
| 3621 | clang::CXXRecordDecl *cxx_record_decl = |
| 3622 | pointee_qual_type->getAsCXXRecordDecl(); |
| 3623 | if (cxx_record_decl) { |
| 3624 | bool is_complete = cxx_record_decl->isCompleteDefinition(); |
| 3625 | |
| 3626 | if (is_complete) |
| 3627 | success = cxx_record_decl->isDynamicClass(); |
| 3628 | else { |
| 3629 | ClangASTMetadata *metadata = ClangASTContext::GetMetadata( |
| 3630 | getASTContext(), cxx_record_decl); |
| 3631 | if (metadata) |
| 3632 | success = metadata->GetIsDynamicCXXType(); |
| 3633 | else { |
| 3634 | is_complete = CompilerType(getASTContext(), pointee_qual_type) |
| 3635 | .GetCompleteType(); |
| 3636 | if (is_complete) |
| 3637 | success = cxx_record_decl->isDynamicClass(); |
| 3638 | else |
| 3639 | success = false; |
| 3640 | } |
| 3641 | } |
| 3642 | |
| 3643 | if (success) { |
| 3644 | if (dynamic_pointee_type) |
| 3645 | dynamic_pointee_type->SetCompilerType(getASTContext(), |
| 3646 | pointee_qual_type); |
| 3647 | return true; |
| 3648 | } |
| 3649 | } |
| 3650 | } |
| 3651 | break; |
| 3652 | |
| 3653 | case clang::Type::ObjCObject: |
| 3654 | case clang::Type::ObjCInterface: |
| 3655 | if (check_objc) { |
| 3656 | if (dynamic_pointee_type) |
| 3657 | dynamic_pointee_type->SetCompilerType(getASTContext(), |
| 3658 | pointee_qual_type); |
| 3659 | return true; |
| 3660 | } |
| 3661 | break; |
| 3662 | |
| 3663 | default: |
| 3664 | break; |
| 3665 | } |
| 3666 | } |
| 3667 | } |
| 3668 | if (dynamic_pointee_type) |
| 3669 | dynamic_pointee_type->Clear(); |
| 3670 | return false; |
| 3671 | } |
| 3672 | |
| 3673 | bool ClangASTContext::IsScalarType(lldb::opaque_compiler_type_t type) { |
| 3674 | if (!type) |
| 3675 | return false; |
| 3676 | |
| 3677 | return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0; |
| 3678 | } |
| 3679 | |
| 3680 | bool ClangASTContext::IsTypedefType(lldb::opaque_compiler_type_t type) { |
| 3681 | if (!type) |
| 3682 | return false; |
| 3683 | return GetQualType(type)->getTypeClass() == clang::Type::Typedef; |
| 3684 | } |
| 3685 | |
| 3686 | bool ClangASTContext::IsVoidType(lldb::opaque_compiler_type_t type) { |
| 3687 | if (!type) |
| 3688 | return false; |
| 3689 | return GetCanonicalQualType(type)->isVoidType(); |
| 3690 | } |
| 3691 | |
| 3692 | bool ClangASTContext::SupportsLanguage(lldb::LanguageType language) { |
| 3693 | return ClangASTContextSupportsLanguage(language); |
| 3694 | } |
| 3695 | |
| 3696 | bool ClangASTContext::GetCXXClassName(const CompilerType &type, |
| 3697 | std::string &class_name) { |
| 3698 | if (type) { |
| 3699 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
| 3700 | if (!qual_type.isNull()) { |
| 3701 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 3702 | if (cxx_record_decl) { |
| 3703 | class_name.assign(cxx_record_decl->getIdentifier()->getNameStart()); |
| 3704 | return true; |
| 3705 | } |
| 3706 | } |
| 3707 | } |
| 3708 | class_name.clear(); |
| 3709 | return false; |
| 3710 | } |
| 3711 | |
| 3712 | bool ClangASTContext::IsCXXClassType(const CompilerType &type) { |
| 3713 | if (!type) |
| 3714 | return false; |
| 3715 | |
| 3716 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
| 3717 | if (!qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr) |
| 3718 | return true; |
| 3719 | return false; |
| 3720 | } |
| 3721 | |
| 3722 | bool ClangASTContext::IsBeingDefined(lldb::opaque_compiler_type_t type) { |
| 3723 | if (!type) |
| 3724 | return false; |
| 3725 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3726 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type); |
| 3727 | if (tag_type) |
| 3728 | return tag_type->isBeingDefined(); |
| 3729 | return false; |
| 3730 | } |
| 3731 | |
| 3732 | bool ClangASTContext::IsObjCObjectPointerType(const CompilerType &type, |
| 3733 | CompilerType *class_type_ptr) { |
| 3734 | if (!type) |
| 3735 | return false; |
| 3736 | |
| 3737 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
| 3738 | |
| 3739 | if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) { |
| 3740 | if (class_type_ptr) { |
| 3741 | if (!qual_type->isObjCClassType() && !qual_type->isObjCIdType()) { |
| 3742 | const clang::ObjCObjectPointerType *obj_pointer_type = |
| 3743 | llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); |
| 3744 | if (obj_pointer_type == nullptr) |
| 3745 | class_type_ptr->Clear(); |
| 3746 | else |
| 3747 | class_type_ptr->SetCompilerType( |
| 3748 | type.GetTypeSystem(), |
| 3749 | clang::QualType(obj_pointer_type->getInterfaceType(), 0) |
| 3750 | .getAsOpaquePtr()); |
| 3751 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3752 | } |
| 3753 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3754 | } |
| 3755 | if (class_type_ptr) |
| 3756 | class_type_ptr->Clear(); |
| 3757 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3760 | bool ClangASTContext::GetObjCClassName(const CompilerType &type, |
| 3761 | std::string &class_name) { |
| 3762 | if (!type) |
| 3763 | return false; |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 3764 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3765 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
| 3766 | |
| 3767 | const clang::ObjCObjectType *object_type = |
| 3768 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 3769 | if (object_type) { |
| 3770 | const clang::ObjCInterfaceDecl *interface = object_type->getInterface(); |
| 3771 | if (interface) { |
| 3772 | class_name = interface->getNameAsString(); |
| 3773 | return true; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3774 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3775 | } |
| 3776 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3777 | } |
| 3778 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3779 | //---------------------------------------------------------------------- |
| 3780 | // Type Completion |
| 3781 | //---------------------------------------------------------------------- |
| 3782 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3783 | bool ClangASTContext::GetCompleteType(lldb::opaque_compiler_type_t type) { |
| 3784 | if (!type) |
| 3785 | return false; |
| 3786 | const bool allow_completion = true; |
| 3787 | return GetCompleteQualType(getASTContext(), GetQualType(type), |
| 3788 | allow_completion); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3791 | ConstString ClangASTContext::GetTypeName(lldb::opaque_compiler_type_t type) { |
| 3792 | std::string type_name; |
| 3793 | if (type) { |
| 3794 | clang::PrintingPolicy printing_policy(getASTContext()->getPrintingPolicy()); |
| 3795 | clang::QualType qual_type(GetQualType(type)); |
| 3796 | printing_policy.SuppressTagKeyword = true; |
| 3797 | const clang::TypedefType *typedef_type = |
| 3798 | qual_type->getAs<clang::TypedefType>(); |
| 3799 | if (typedef_type) { |
| 3800 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 3801 | type_name = typedef_decl->getQualifiedNameAsString(); |
| 3802 | } else { |
| 3803 | type_name = qual_type.getAsString(printing_policy); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3804 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3805 | } |
| 3806 | return ConstString(type_name); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3810 | ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type, |
| 3811 | CompilerType *pointee_or_element_clang_type) { |
| 3812 | if (!type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3813 | return 0; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3814 | |
| 3815 | if (pointee_or_element_clang_type) |
| 3816 | pointee_or_element_clang_type->Clear(); |
| 3817 | |
| 3818 | clang::QualType qual_type(GetQualType(type)); |
| 3819 | |
| 3820 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3821 | switch (type_class) { |
Sean Callanan | ddf802a | 2017-06-02 01:24:18 +0000 | [diff] [blame] | 3822 | case clang::Type::Attributed: |
| 3823 | return GetTypeInfo( |
| 3824 | qual_type->getAs<clang::AttributedType>() |
| 3825 | ->getModifiedType().getAsOpaquePtr(), |
| 3826 | pointee_or_element_clang_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3827 | case clang::Type::Builtin: { |
| 3828 | const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>( |
| 3829 | qual_type->getCanonicalTypeInternal()); |
| 3830 | |
| 3831 | uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue; |
| 3832 | switch (builtin_type->getKind()) { |
| 3833 | case clang::BuiltinType::ObjCId: |
| 3834 | case clang::BuiltinType::ObjCClass: |
| 3835 | if (pointee_or_element_clang_type) |
| 3836 | pointee_or_element_clang_type->SetCompilerType( |
| 3837 | getASTContext(), getASTContext()->ObjCBuiltinClassTy); |
| 3838 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; |
| 3839 | break; |
| 3840 | |
| 3841 | case clang::BuiltinType::ObjCSel: |
| 3842 | if (pointee_or_element_clang_type) |
| 3843 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), |
| 3844 | getASTContext()->CharTy); |
| 3845 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; |
| 3846 | break; |
| 3847 | |
| 3848 | case clang::BuiltinType::Bool: |
| 3849 | case clang::BuiltinType::Char_U: |
| 3850 | case clang::BuiltinType::UChar: |
| 3851 | case clang::BuiltinType::WChar_U: |
| 3852 | case clang::BuiltinType::Char16: |
| 3853 | case clang::BuiltinType::Char32: |
| 3854 | case clang::BuiltinType::UShort: |
| 3855 | case clang::BuiltinType::UInt: |
| 3856 | case clang::BuiltinType::ULong: |
| 3857 | case clang::BuiltinType::ULongLong: |
| 3858 | case clang::BuiltinType::UInt128: |
| 3859 | case clang::BuiltinType::Char_S: |
| 3860 | case clang::BuiltinType::SChar: |
| 3861 | case clang::BuiltinType::WChar_S: |
| 3862 | case clang::BuiltinType::Short: |
| 3863 | case clang::BuiltinType::Int: |
| 3864 | case clang::BuiltinType::Long: |
| 3865 | case clang::BuiltinType::LongLong: |
| 3866 | case clang::BuiltinType::Int128: |
| 3867 | case clang::BuiltinType::Float: |
| 3868 | case clang::BuiltinType::Double: |
| 3869 | case clang::BuiltinType::LongDouble: |
| 3870 | builtin_type_flags |= eTypeIsScalar; |
| 3871 | if (builtin_type->isInteger()) { |
| 3872 | builtin_type_flags |= eTypeIsInteger; |
| 3873 | if (builtin_type->isSignedInteger()) |
| 3874 | builtin_type_flags |= eTypeIsSigned; |
| 3875 | } else if (builtin_type->isFloatingPoint()) |
| 3876 | builtin_type_flags |= eTypeIsFloat; |
| 3877 | break; |
| 3878 | default: |
| 3879 | break; |
| 3880 | } |
| 3881 | return builtin_type_flags; |
| 3882 | } |
| 3883 | |
| 3884 | case clang::Type::BlockPointer: |
| 3885 | if (pointee_or_element_clang_type) |
| 3886 | pointee_or_element_clang_type->SetCompilerType( |
| 3887 | getASTContext(), qual_type->getPointeeType()); |
| 3888 | return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock; |
| 3889 | |
| 3890 | case clang::Type::Complex: { |
| 3891 | uint32_t complex_type_flags = |
| 3892 | eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex; |
| 3893 | const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>( |
| 3894 | qual_type->getCanonicalTypeInternal()); |
| 3895 | if (complex_type) { |
| 3896 | clang::QualType complex_element_type(complex_type->getElementType()); |
| 3897 | if (complex_element_type->isIntegerType()) |
| 3898 | complex_type_flags |= eTypeIsFloat; |
| 3899 | else if (complex_element_type->isFloatingType()) |
| 3900 | complex_type_flags |= eTypeIsInteger; |
| 3901 | } |
| 3902 | return complex_type_flags; |
| 3903 | } break; |
| 3904 | |
| 3905 | case clang::Type::ConstantArray: |
| 3906 | case clang::Type::DependentSizedArray: |
| 3907 | case clang::Type::IncompleteArray: |
| 3908 | case clang::Type::VariableArray: |
| 3909 | if (pointee_or_element_clang_type) |
| 3910 | pointee_or_element_clang_type->SetCompilerType( |
| 3911 | getASTContext(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr()) |
| 3912 | ->getElementType()); |
| 3913 | return eTypeHasChildren | eTypeIsArray; |
| 3914 | |
| 3915 | case clang::Type::DependentName: |
| 3916 | return 0; |
| 3917 | case clang::Type::DependentSizedExtVector: |
| 3918 | return eTypeHasChildren | eTypeIsVector; |
| 3919 | case clang::Type::DependentTemplateSpecialization: |
| 3920 | return eTypeIsTemplate; |
| 3921 | case clang::Type::Decltype: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 3922 | return CompilerType( |
| 3923 | getASTContext(), |
| 3924 | llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType()) |
| 3925 | .GetTypeInfo(pointee_or_element_clang_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3926 | |
| 3927 | case clang::Type::Enum: |
| 3928 | if (pointee_or_element_clang_type) |
| 3929 | pointee_or_element_clang_type->SetCompilerType( |
| 3930 | getASTContext(), |
| 3931 | llvm::cast<clang::EnumType>(qual_type)->getDecl()->getIntegerType()); |
| 3932 | return eTypeIsEnumeration | eTypeHasValue; |
| 3933 | |
| 3934 | case clang::Type::Auto: |
| 3935 | return CompilerType( |
| 3936 | getASTContext(), |
| 3937 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 3938 | .GetTypeInfo(pointee_or_element_clang_type); |
| 3939 | case clang::Type::Elaborated: |
| 3940 | return CompilerType( |
| 3941 | getASTContext(), |
| 3942 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 3943 | .GetTypeInfo(pointee_or_element_clang_type); |
| 3944 | case clang::Type::Paren: |
| 3945 | return CompilerType(getASTContext(), |
| 3946 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 3947 | .GetTypeInfo(pointee_or_element_clang_type); |
| 3948 | |
| 3949 | case clang::Type::FunctionProto: |
| 3950 | return eTypeIsFuncPrototype | eTypeHasValue; |
| 3951 | case clang::Type::FunctionNoProto: |
| 3952 | return eTypeIsFuncPrototype | eTypeHasValue; |
| 3953 | case clang::Type::InjectedClassName: |
| 3954 | return 0; |
| 3955 | |
| 3956 | case clang::Type::LValueReference: |
| 3957 | case clang::Type::RValueReference: |
| 3958 | if (pointee_or_element_clang_type) |
| 3959 | pointee_or_element_clang_type->SetCompilerType( |
| 3960 | getASTContext(), |
| 3961 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()) |
| 3962 | ->getPointeeType()); |
| 3963 | return eTypeHasChildren | eTypeIsReference | eTypeHasValue; |
| 3964 | |
| 3965 | case clang::Type::MemberPointer: |
| 3966 | return eTypeIsPointer | eTypeIsMember | eTypeHasValue; |
| 3967 | |
| 3968 | case clang::Type::ObjCObjectPointer: |
| 3969 | if (pointee_or_element_clang_type) |
| 3970 | pointee_or_element_clang_type->SetCompilerType( |
| 3971 | getASTContext(), qual_type->getPointeeType()); |
| 3972 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | |
| 3973 | eTypeHasValue; |
| 3974 | |
| 3975 | case clang::Type::ObjCObject: |
| 3976 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 3977 | case clang::Type::ObjCInterface: |
| 3978 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 3979 | |
| 3980 | case clang::Type::Pointer: |
| 3981 | if (pointee_or_element_clang_type) |
| 3982 | pointee_or_element_clang_type->SetCompilerType( |
| 3983 | getASTContext(), qual_type->getPointeeType()); |
| 3984 | return eTypeHasChildren | eTypeIsPointer | eTypeHasValue; |
| 3985 | |
| 3986 | case clang::Type::Record: |
| 3987 | if (qual_type->getAsCXXRecordDecl()) |
| 3988 | return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus; |
| 3989 | else |
| 3990 | return eTypeHasChildren | eTypeIsStructUnion; |
| 3991 | break; |
| 3992 | case clang::Type::SubstTemplateTypeParm: |
| 3993 | return eTypeIsTemplate; |
| 3994 | case clang::Type::TemplateTypeParm: |
| 3995 | return eTypeIsTemplate; |
| 3996 | case clang::Type::TemplateSpecialization: |
| 3997 | return eTypeIsTemplate; |
| 3998 | |
| 3999 | case clang::Type::Typedef: |
| 4000 | return eTypeIsTypedef | |
| 4001 | CompilerType(getASTContext(), |
| 4002 | llvm::cast<clang::TypedefType>(qual_type) |
| 4003 | ->getDecl() |
| 4004 | ->getUnderlyingType()) |
| 4005 | .GetTypeInfo(pointee_or_element_clang_type); |
| 4006 | case clang::Type::TypeOfExpr: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4007 | return CompilerType(getASTContext(), |
| 4008 | llvm::cast<clang::TypeOfExprType>(qual_type) |
| 4009 | ->getUnderlyingExpr() |
| 4010 | ->getType()) |
| 4011 | .GetTypeInfo(pointee_or_element_clang_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4012 | case clang::Type::TypeOf: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4013 | return CompilerType( |
| 4014 | getASTContext(), |
| 4015 | llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType()) |
| 4016 | .GetTypeInfo(pointee_or_element_clang_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4017 | case clang::Type::UnresolvedUsing: |
| 4018 | return 0; |
| 4019 | |
| 4020 | case clang::Type::ExtVector: |
| 4021 | case clang::Type::Vector: { |
| 4022 | uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector; |
| 4023 | const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>( |
| 4024 | qual_type->getCanonicalTypeInternal()); |
| 4025 | if (vector_type) { |
| 4026 | if (vector_type->isIntegerType()) |
| 4027 | vector_type_flags |= eTypeIsFloat; |
| 4028 | else if (vector_type->isFloatingType()) |
| 4029 | vector_type_flags |= eTypeIsInteger; |
| 4030 | } |
| 4031 | return vector_type_flags; |
| 4032 | } |
| 4033 | default: |
| 4034 | return 0; |
| 4035 | } |
| 4036 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4037 | } |
| 4038 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4039 | lldb::LanguageType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4040 | ClangASTContext::GetMinimumLanguage(lldb::opaque_compiler_type_t type) { |
| 4041 | if (!type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4042 | return lldb::eLanguageTypeC; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4043 | |
| 4044 | // If the type is a reference, then resolve it to what it refers to first: |
| 4045 | clang::QualType qual_type(GetCanonicalQualType(type).getNonReferenceType()); |
| 4046 | if (qual_type->isAnyPointerType()) { |
| 4047 | if (qual_type->isObjCObjectPointerType()) |
| 4048 | return lldb::eLanguageTypeObjC; |
| 4049 | |
| 4050 | clang::QualType pointee_type(qual_type->getPointeeType()); |
| 4051 | if (pointee_type->getPointeeCXXRecordDecl() != nullptr) |
| 4052 | return lldb::eLanguageTypeC_plus_plus; |
| 4053 | if (pointee_type->isObjCObjectOrInterfaceType()) |
| 4054 | return lldb::eLanguageTypeObjC; |
| 4055 | if (pointee_type->isObjCClassType()) |
| 4056 | return lldb::eLanguageTypeObjC; |
| 4057 | if (pointee_type.getTypePtr() == |
| 4058 | getASTContext()->ObjCBuiltinIdTy.getTypePtr()) |
| 4059 | return lldb::eLanguageTypeObjC; |
| 4060 | } else { |
| 4061 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 4062 | return lldb::eLanguageTypeObjC; |
| 4063 | if (qual_type->getAsCXXRecordDecl()) |
| 4064 | return lldb::eLanguageTypeC_plus_plus; |
| 4065 | switch (qual_type->getTypeClass()) { |
| 4066 | default: |
| 4067 | break; |
| 4068 | case clang::Type::Builtin: |
| 4069 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 4070 | default: |
| 4071 | case clang::BuiltinType::Void: |
| 4072 | case clang::BuiltinType::Bool: |
| 4073 | case clang::BuiltinType::Char_U: |
| 4074 | case clang::BuiltinType::UChar: |
| 4075 | case clang::BuiltinType::WChar_U: |
| 4076 | case clang::BuiltinType::Char16: |
| 4077 | case clang::BuiltinType::Char32: |
| 4078 | case clang::BuiltinType::UShort: |
| 4079 | case clang::BuiltinType::UInt: |
| 4080 | case clang::BuiltinType::ULong: |
| 4081 | case clang::BuiltinType::ULongLong: |
| 4082 | case clang::BuiltinType::UInt128: |
| 4083 | case clang::BuiltinType::Char_S: |
| 4084 | case clang::BuiltinType::SChar: |
| 4085 | case clang::BuiltinType::WChar_S: |
| 4086 | case clang::BuiltinType::Short: |
| 4087 | case clang::BuiltinType::Int: |
| 4088 | case clang::BuiltinType::Long: |
| 4089 | case clang::BuiltinType::LongLong: |
| 4090 | case clang::BuiltinType::Int128: |
| 4091 | case clang::BuiltinType::Float: |
| 4092 | case clang::BuiltinType::Double: |
| 4093 | case clang::BuiltinType::LongDouble: |
| 4094 | break; |
| 4095 | |
| 4096 | case clang::BuiltinType::NullPtr: |
| 4097 | return eLanguageTypeC_plus_plus; |
| 4098 | |
| 4099 | case clang::BuiltinType::ObjCId: |
| 4100 | case clang::BuiltinType::ObjCClass: |
| 4101 | case clang::BuiltinType::ObjCSel: |
| 4102 | return eLanguageTypeObjC; |
| 4103 | |
| 4104 | case clang::BuiltinType::Dependent: |
| 4105 | case clang::BuiltinType::Overload: |
| 4106 | case clang::BuiltinType::BoundMember: |
| 4107 | case clang::BuiltinType::UnknownAny: |
| 4108 | break; |
| 4109 | } |
| 4110 | break; |
| 4111 | case clang::Type::Typedef: |
| 4112 | return CompilerType(getASTContext(), |
| 4113 | llvm::cast<clang::TypedefType>(qual_type) |
| 4114 | ->getDecl() |
| 4115 | ->getUnderlyingType()) |
| 4116 | .GetMinimumLanguage(); |
| 4117 | } |
| 4118 | } |
| 4119 | return lldb::eLanguageTypeC; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4120 | } |
| 4121 | |
| 4122 | lldb::TypeClass |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4123 | ClangASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) { |
| 4124 | if (!type) |
| 4125 | return lldb::eTypeClassInvalid; |
| 4126 | |
| 4127 | clang::QualType qual_type(GetQualType(type)); |
| 4128 | |
| 4129 | switch (qual_type->getTypeClass()) { |
| 4130 | case clang::Type::UnaryTransform: |
| 4131 | break; |
| 4132 | case clang::Type::FunctionNoProto: |
| 4133 | return lldb::eTypeClassFunction; |
| 4134 | case clang::Type::FunctionProto: |
| 4135 | return lldb::eTypeClassFunction; |
| 4136 | case clang::Type::IncompleteArray: |
| 4137 | return lldb::eTypeClassArray; |
| 4138 | case clang::Type::VariableArray: |
| 4139 | return lldb::eTypeClassArray; |
| 4140 | case clang::Type::ConstantArray: |
| 4141 | return lldb::eTypeClassArray; |
| 4142 | case clang::Type::DependentSizedArray: |
| 4143 | return lldb::eTypeClassArray; |
| 4144 | case clang::Type::DependentSizedExtVector: |
| 4145 | return lldb::eTypeClassVector; |
| 4146 | case clang::Type::ExtVector: |
| 4147 | return lldb::eTypeClassVector; |
| 4148 | case clang::Type::Vector: |
| 4149 | return lldb::eTypeClassVector; |
| 4150 | case clang::Type::Builtin: |
| 4151 | return lldb::eTypeClassBuiltin; |
| 4152 | case clang::Type::ObjCObjectPointer: |
| 4153 | return lldb::eTypeClassObjCObjectPointer; |
| 4154 | case clang::Type::BlockPointer: |
| 4155 | return lldb::eTypeClassBlockPointer; |
| 4156 | case clang::Type::Pointer: |
| 4157 | return lldb::eTypeClassPointer; |
| 4158 | case clang::Type::LValueReference: |
| 4159 | return lldb::eTypeClassReference; |
| 4160 | case clang::Type::RValueReference: |
| 4161 | return lldb::eTypeClassReference; |
| 4162 | case clang::Type::MemberPointer: |
| 4163 | return lldb::eTypeClassMemberPointer; |
| 4164 | case clang::Type::Complex: |
| 4165 | if (qual_type->isComplexType()) |
| 4166 | return lldb::eTypeClassComplexFloat; |
| 4167 | else |
| 4168 | return lldb::eTypeClassComplexInteger; |
| 4169 | case clang::Type::ObjCObject: |
| 4170 | return lldb::eTypeClassObjCObject; |
| 4171 | case clang::Type::ObjCInterface: |
| 4172 | return lldb::eTypeClassObjCInterface; |
| 4173 | case clang::Type::Record: { |
| 4174 | const clang::RecordType *record_type = |
| 4175 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4176 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4177 | if (record_decl->isUnion()) |
| 4178 | return lldb::eTypeClassUnion; |
| 4179 | else if (record_decl->isStruct()) |
| 4180 | return lldb::eTypeClassStruct; |
| 4181 | else |
| 4182 | return lldb::eTypeClassClass; |
| 4183 | } break; |
| 4184 | case clang::Type::Enum: |
| 4185 | return lldb::eTypeClassEnumeration; |
| 4186 | case clang::Type::Typedef: |
| 4187 | return lldb::eTypeClassTypedef; |
| 4188 | case clang::Type::UnresolvedUsing: |
| 4189 | break; |
| 4190 | case clang::Type::Paren: |
| 4191 | return CompilerType(getASTContext(), |
| 4192 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 4193 | .GetTypeClass(); |
| 4194 | case clang::Type::Auto: |
| 4195 | return CompilerType( |
| 4196 | getASTContext(), |
| 4197 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 4198 | .GetTypeClass(); |
| 4199 | case clang::Type::Elaborated: |
| 4200 | return CompilerType( |
| 4201 | getASTContext(), |
| 4202 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 4203 | .GetTypeClass(); |
| 4204 | |
| 4205 | case clang::Type::Attributed: |
| 4206 | break; |
| 4207 | case clang::Type::TemplateTypeParm: |
| 4208 | break; |
| 4209 | case clang::Type::SubstTemplateTypeParm: |
| 4210 | break; |
| 4211 | case clang::Type::SubstTemplateTypeParmPack: |
| 4212 | break; |
| 4213 | case clang::Type::InjectedClassName: |
| 4214 | break; |
| 4215 | case clang::Type::DependentName: |
| 4216 | break; |
| 4217 | case clang::Type::DependentTemplateSpecialization: |
| 4218 | break; |
| 4219 | case clang::Type::PackExpansion: |
| 4220 | break; |
| 4221 | |
| 4222 | case clang::Type::TypeOfExpr: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4223 | return CompilerType(getASTContext(), |
| 4224 | llvm::cast<clang::TypeOfExprType>(qual_type) |
| 4225 | ->getUnderlyingExpr() |
| 4226 | ->getType()) |
| 4227 | .GetTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4228 | case clang::Type::TypeOf: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4229 | return CompilerType( |
| 4230 | getASTContext(), |
| 4231 | llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType()) |
| 4232 | .GetTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4233 | case clang::Type::Decltype: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 4234 | return CompilerType( |
| 4235 | getASTContext(), |
| 4236 | llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType()) |
| 4237 | .GetTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4238 | case clang::Type::TemplateSpecialization: |
| 4239 | break; |
Pavel Labath | 4f19fce2 | 2017-02-17 13:39:50 +0000 | [diff] [blame] | 4240 | case clang::Type::DeducedTemplateSpecialization: |
| 4241 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4242 | case clang::Type::Atomic: |
| 4243 | break; |
| 4244 | case clang::Type::Pipe: |
| 4245 | break; |
| 4246 | |
| 4247 | // pointer type decayed from an array or function type. |
| 4248 | case clang::Type::Decayed: |
| 4249 | break; |
| 4250 | case clang::Type::Adjusted: |
| 4251 | break; |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 4252 | case clang::Type::ObjCTypeParam: |
| 4253 | break; |
Ted Woodward | 66060cf | 2017-10-11 22:42:21 +0000 | [diff] [blame] | 4254 | |
| 4255 | case clang::Type::DependentAddressSpace: |
| 4256 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4257 | } |
| 4258 | // We don't know hot to display this type... |
| 4259 | return lldb::eTypeClassOther; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4260 | } |
| 4261 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4262 | unsigned ClangASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) { |
| 4263 | if (type) |
| 4264 | return GetQualType(type).getQualifiers().getCVRQualifiers(); |
| 4265 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | //---------------------------------------------------------------------- |
| 4269 | // Creating related types |
| 4270 | //---------------------------------------------------------------------- |
| 4271 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4272 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4273 | ClangASTContext::GetArrayElementType(lldb::opaque_compiler_type_t type, |
| 4274 | uint64_t *stride) { |
| 4275 | if (type) { |
| 4276 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4277 | |
| 4278 | const clang::Type *array_eletype = |
| 4279 | qual_type.getTypePtr()->getArrayElementTypeNoTypeQual(); |
| 4280 | |
| 4281 | if (!array_eletype) |
| 4282 | return CompilerType(); |
| 4283 | |
| 4284 | CompilerType element_type(getASTContext(), |
| 4285 | array_eletype->getCanonicalTypeUnqualified()); |
| 4286 | |
| 4287 | // TODO: the real stride will be >= this value.. find the real one! |
| 4288 | if (stride) |
| 4289 | *stride = element_type.GetByteSize(nullptr); |
| 4290 | |
| 4291 | return element_type; |
| 4292 | } |
| 4293 | return CompilerType(); |
| 4294 | } |
| 4295 | |
| 4296 | CompilerType ClangASTContext::GetArrayType(lldb::opaque_compiler_type_t type, |
| 4297 | uint64_t size) { |
| 4298 | if (type) { |
| 4299 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4300 | if (clang::ASTContext *ast_ctx = getASTContext()) { |
| 4301 | if (size != 0) |
| 4302 | return CompilerType( |
| 4303 | ast_ctx, ast_ctx->getConstantArrayType( |
| 4304 | qual_type, llvm::APInt(64, size), |
| 4305 | clang::ArrayType::ArraySizeModifier::Normal, 0)); |
| 4306 | else |
| 4307 | return CompilerType( |
| 4308 | ast_ctx, |
| 4309 | ast_ctx->getIncompleteArrayType( |
| 4310 | qual_type, clang::ArrayType::ArraySizeModifier::Normal, 0)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4311 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4315 | } |
| 4316 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4317 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4318 | ClangASTContext::GetCanonicalType(lldb::opaque_compiler_type_t type) { |
| 4319 | if (type) |
| 4320 | return CompilerType(getASTContext(), GetCanonicalQualType(type)); |
| 4321 | return CompilerType(); |
| 4322 | } |
| 4323 | |
| 4324 | static clang::QualType GetFullyUnqualifiedType_Impl(clang::ASTContext *ast, |
| 4325 | clang::QualType qual_type) { |
| 4326 | if (qual_type->isPointerType()) |
| 4327 | qual_type = ast->getPointerType( |
| 4328 | GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType())); |
| 4329 | else |
| 4330 | qual_type = qual_type.getUnqualifiedType(); |
| 4331 | qual_type.removeLocalConst(); |
| 4332 | qual_type.removeLocalRestrict(); |
| 4333 | qual_type.removeLocalVolatile(); |
| 4334 | return qual_type; |
Enrico Granata | 639392f | 2016-08-30 20:39:58 +0000 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4338 | ClangASTContext::GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) { |
| 4339 | if (type) |
| 4340 | return CompilerType( |
| 4341 | getASTContext(), |
| 4342 | GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type))); |
| 4343 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4344 | } |
| 4345 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4346 | int ClangASTContext::GetFunctionArgumentCount( |
| 4347 | lldb::opaque_compiler_type_t type) { |
| 4348 | if (type) { |
| 4349 | const clang::FunctionProtoType *func = |
| 4350 | llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type)); |
| 4351 | if (func) |
| 4352 | return func->getNumParams(); |
| 4353 | } |
| 4354 | return -1; |
| 4355 | } |
| 4356 | |
| 4357 | CompilerType ClangASTContext::GetFunctionArgumentTypeAtIndex( |
| 4358 | lldb::opaque_compiler_type_t type, size_t idx) { |
| 4359 | if (type) { |
| 4360 | const clang::FunctionProtoType *func = |
| 4361 | llvm::dyn_cast<clang::FunctionProtoType>(GetQualType(type)); |
| 4362 | if (func) { |
| 4363 | const uint32_t num_args = func->getNumParams(); |
| 4364 | if (idx < num_args) |
| 4365 | return CompilerType(getASTContext(), func->getParamType(idx)); |
| 4366 | } |
| 4367 | } |
| 4368 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4371 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4372 | ClangASTContext::GetFunctionReturnType(lldb::opaque_compiler_type_t type) { |
| 4373 | if (type) { |
| 4374 | clang::QualType qual_type(GetQualType(type)); |
| 4375 | const clang::FunctionProtoType *func = |
| 4376 | llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 4377 | if (func) |
| 4378 | return CompilerType(getASTContext(), func->getReturnType()); |
| 4379 | } |
| 4380 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | size_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4384 | ClangASTContext::GetNumMemberFunctions(lldb::opaque_compiler_type_t type) { |
| 4385 | size_t num_functions = 0; |
| 4386 | if (type) { |
| 4387 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4388 | switch (qual_type->getTypeClass()) { |
| 4389 | case clang::Type::Record: |
| 4390 | if (GetCompleteQualType(getASTContext(), qual_type)) { |
| 4391 | const clang::RecordType *record_type = |
| 4392 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4393 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4394 | assert(record_decl); |
| 4395 | const clang::CXXRecordDecl *cxx_record_decl = |
| 4396 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 4397 | if (cxx_record_decl) |
| 4398 | num_functions = std::distance(cxx_record_decl->method_begin(), |
| 4399 | cxx_record_decl->method_end()); |
| 4400 | } |
| 4401 | break; |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 4402 | |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4403 | case clang::Type::ObjCObjectPointer: { |
| 4404 | const clang::ObjCObjectPointerType *objc_class_type = |
Sean Callanan | 732a6f4 | 2017-05-15 19:55:20 +0000 | [diff] [blame] | 4405 | qual_type->getAs<clang::ObjCObjectPointerType>(); |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4406 | const clang::ObjCInterfaceType *objc_interface_type = |
| 4407 | objc_class_type->getInterfaceType(); |
| 4408 | if (objc_interface_type && |
Davide Italiano | 52ffb53 | 2017-04-17 18:24:18 +0000 | [diff] [blame] | 4409 | GetCompleteType(static_cast<lldb::opaque_compiler_type_t>( |
| 4410 | const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) { |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4411 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 4412 | objc_interface_type->getDecl(); |
| 4413 | if (class_interface_decl) { |
| 4414 | num_functions = std::distance(class_interface_decl->meth_begin(), |
| 4415 | class_interface_decl->meth_end()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4416 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4417 | } |
| 4418 | break; |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4419 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4420 | |
| 4421 | case clang::Type::ObjCObject: |
| 4422 | case clang::Type::ObjCInterface: |
| 4423 | if (GetCompleteType(type)) { |
| 4424 | const clang::ObjCObjectType *objc_class_type = |
| 4425 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4426 | if (objc_class_type) { |
| 4427 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 4428 | objc_class_type->getInterface(); |
| 4429 | if (class_interface_decl) |
| 4430 | num_functions = std::distance(class_interface_decl->meth_begin(), |
| 4431 | class_interface_decl->meth_end()); |
| 4432 | } |
| 4433 | } |
| 4434 | break; |
| 4435 | |
| 4436 | case clang::Type::Typedef: |
| 4437 | return CompilerType(getASTContext(), |
| 4438 | llvm::cast<clang::TypedefType>(qual_type) |
| 4439 | ->getDecl() |
| 4440 | ->getUnderlyingType()) |
| 4441 | .GetNumMemberFunctions(); |
| 4442 | |
| 4443 | case clang::Type::Auto: |
| 4444 | return CompilerType( |
| 4445 | getASTContext(), |
| 4446 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 4447 | .GetNumMemberFunctions(); |
| 4448 | |
| 4449 | case clang::Type::Elaborated: |
| 4450 | return CompilerType( |
| 4451 | getASTContext(), |
| 4452 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 4453 | .GetNumMemberFunctions(); |
| 4454 | |
| 4455 | case clang::Type::Paren: |
| 4456 | return CompilerType(getASTContext(), |
| 4457 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 4458 | .GetNumMemberFunctions(); |
| 4459 | |
| 4460 | default: |
| 4461 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4462 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4463 | } |
| 4464 | return num_functions; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | TypeMemberFunctionImpl |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4468 | ClangASTContext::GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, |
| 4469 | size_t idx) { |
| 4470 | std::string name; |
| 4471 | MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown); |
| 4472 | CompilerType clang_type; |
| 4473 | CompilerDecl clang_decl; |
| 4474 | if (type) { |
| 4475 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4476 | switch (qual_type->getTypeClass()) { |
| 4477 | case clang::Type::Record: |
| 4478 | if (GetCompleteQualType(getASTContext(), qual_type)) { |
| 4479 | const clang::RecordType *record_type = |
| 4480 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4481 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4482 | assert(record_decl); |
| 4483 | const clang::CXXRecordDecl *cxx_record_decl = |
| 4484 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 4485 | if (cxx_record_decl) { |
| 4486 | auto method_iter = cxx_record_decl->method_begin(); |
| 4487 | auto method_end = cxx_record_decl->method_end(); |
| 4488 | if (idx < |
| 4489 | static_cast<size_t>(std::distance(method_iter, method_end))) { |
| 4490 | std::advance(method_iter, idx); |
| 4491 | clang::CXXMethodDecl *cxx_method_decl = |
| 4492 | method_iter->getCanonicalDecl(); |
| 4493 | if (cxx_method_decl) { |
| 4494 | name = cxx_method_decl->getDeclName().getAsString(); |
| 4495 | if (cxx_method_decl->isStatic()) |
| 4496 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4497 | else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl)) |
| 4498 | kind = lldb::eMemberFunctionKindConstructor; |
| 4499 | else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl)) |
| 4500 | kind = lldb::eMemberFunctionKindDestructor; |
| 4501 | else |
| 4502 | kind = lldb::eMemberFunctionKindInstanceMethod; |
| 4503 | clang_type = CompilerType( |
| 4504 | this, cxx_method_decl->getType().getAsOpaquePtr()); |
| 4505 | clang_decl = CompilerDecl(this, cxx_method_decl); |
| 4506 | } |
| 4507 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4508 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4509 | } |
| 4510 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4511 | |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4512 | case clang::Type::ObjCObjectPointer: { |
| 4513 | const clang::ObjCObjectPointerType *objc_class_type = |
Sean Callanan | 732a6f4 | 2017-05-15 19:55:20 +0000 | [diff] [blame] | 4514 | qual_type->getAs<clang::ObjCObjectPointerType>(); |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4515 | const clang::ObjCInterfaceType *objc_interface_type = |
| 4516 | objc_class_type->getInterfaceType(); |
| 4517 | if (objc_interface_type && |
Davide Italiano | 52ffb53 | 2017-04-17 18:24:18 +0000 | [diff] [blame] | 4518 | GetCompleteType(static_cast<lldb::opaque_compiler_type_t>( |
| 4519 | const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) { |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4520 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 4521 | objc_interface_type->getDecl(); |
| 4522 | if (class_interface_decl) { |
| 4523 | auto method_iter = class_interface_decl->meth_begin(); |
| 4524 | auto method_end = class_interface_decl->meth_end(); |
| 4525 | if (idx < |
| 4526 | static_cast<size_t>(std::distance(method_iter, method_end))) { |
| 4527 | std::advance(method_iter, idx); |
| 4528 | clang::ObjCMethodDecl *objc_method_decl = |
| 4529 | method_iter->getCanonicalDecl(); |
| 4530 | if (objc_method_decl) { |
| 4531 | clang_decl = CompilerDecl(this, objc_method_decl); |
| 4532 | name = objc_method_decl->getSelector().getAsString(); |
| 4533 | if (objc_method_decl->isClassMethod()) |
| 4534 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4535 | else |
| 4536 | kind = lldb::eMemberFunctionKindInstanceMethod; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4537 | } |
| 4538 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4539 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4540 | } |
| 4541 | break; |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 4542 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4543 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4544 | case clang::Type::ObjCObject: |
| 4545 | case clang::Type::ObjCInterface: |
| 4546 | if (GetCompleteType(type)) { |
| 4547 | const clang::ObjCObjectType *objc_class_type = |
| 4548 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4549 | if (objc_class_type) { |
| 4550 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 4551 | objc_class_type->getInterface(); |
| 4552 | if (class_interface_decl) { |
| 4553 | auto method_iter = class_interface_decl->meth_begin(); |
| 4554 | auto method_end = class_interface_decl->meth_end(); |
| 4555 | if (idx < |
| 4556 | static_cast<size_t>(std::distance(method_iter, method_end))) { |
| 4557 | std::advance(method_iter, idx); |
| 4558 | clang::ObjCMethodDecl *objc_method_decl = |
| 4559 | method_iter->getCanonicalDecl(); |
| 4560 | if (objc_method_decl) { |
| 4561 | clang_decl = CompilerDecl(this, objc_method_decl); |
| 4562 | name = objc_method_decl->getSelector().getAsString(); |
| 4563 | if (objc_method_decl->isClassMethod()) |
| 4564 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4565 | else |
| 4566 | kind = lldb::eMemberFunctionKindInstanceMethod; |
| 4567 | } |
| 4568 | } |
| 4569 | } |
Ewan Crawford | 27fc7a7 | 2016-03-15 09:50:16 +0000 | [diff] [blame] | 4570 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4571 | } |
| 4572 | break; |
Ewan Crawford | 27fc7a7 | 2016-03-15 09:50:16 +0000 | [diff] [blame] | 4573 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4574 | case clang::Type::Typedef: |
| 4575 | return GetMemberFunctionAtIndex(llvm::cast<clang::TypedefType>(qual_type) |
| 4576 | ->getDecl() |
| 4577 | ->getUnderlyingType() |
| 4578 | .getAsOpaquePtr(), |
| 4579 | idx); |
Ewan Crawford | 27fc7a7 | 2016-03-15 09:50:16 +0000 | [diff] [blame] | 4580 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4581 | case clang::Type::Auto: |
| 4582 | return GetMemberFunctionAtIndex(llvm::cast<clang::AutoType>(qual_type) |
| 4583 | ->getDeducedType() |
| 4584 | .getAsOpaquePtr(), |
| 4585 | idx); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4586 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4587 | case clang::Type::Elaborated: |
| 4588 | return GetMemberFunctionAtIndex( |
| 4589 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 4590 | ->getNamedType() |
| 4591 | .getAsOpaquePtr(), |
| 4592 | idx); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4593 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4594 | case clang::Type::Paren: |
| 4595 | return GetMemberFunctionAtIndex( |
| 4596 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 4597 | idx); |
| 4598 | |
| 4599 | default: |
| 4600 | break; |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4601 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4602 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4603 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4604 | if (kind == eMemberFunctionKindUnknown) |
| 4605 | return TypeMemberFunctionImpl(); |
| 4606 | else |
| 4607 | return TypeMemberFunctionImpl(clang_type, clang_decl, name, kind); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4608 | } |
| 4609 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4610 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4611 | ClangASTContext::GetNonReferenceType(lldb::opaque_compiler_type_t type) { |
| 4612 | if (type) |
| 4613 | return CompilerType(getASTContext(), |
| 4614 | GetQualType(type).getNonReferenceType()); |
| 4615 | return CompilerType(); |
| 4616 | } |
| 4617 | |
| 4618 | CompilerType ClangASTContext::CreateTypedefType( |
| 4619 | const CompilerType &type, const char *typedef_name, |
| 4620 | const CompilerDeclContext &compiler_decl_ctx) { |
| 4621 | if (type && typedef_name && typedef_name[0]) { |
| 4622 | ClangASTContext *ast = |
| 4623 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 4624 | if (!ast) |
| 4625 | return CompilerType(); |
| 4626 | clang::ASTContext *clang_ast = ast->getASTContext(); |
| 4627 | clang::QualType qual_type(ClangUtil::GetQualType(type)); |
| 4628 | |
| 4629 | clang::DeclContext *decl_ctx = |
| 4630 | ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); |
| 4631 | if (decl_ctx == nullptr) |
| 4632 | decl_ctx = ast->getASTContext()->getTranslationUnitDecl(); |
| 4633 | |
| 4634 | clang::TypedefDecl *decl = clang::TypedefDecl::Create( |
| 4635 | *clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(), |
| 4636 | &clang_ast->Idents.get(typedef_name), |
| 4637 | clang_ast->getTrivialTypeSourceInfo(qual_type)); |
| 4638 | |
| 4639 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier |
| 4640 | |
| 4641 | // Get a uniqued clang::QualType for the typedef decl type |
| 4642 | return CompilerType(clang_ast, clang_ast->getTypedefType(decl)); |
| 4643 | } |
| 4644 | return CompilerType(); |
| 4645 | } |
| 4646 | |
| 4647 | CompilerType |
| 4648 | ClangASTContext::GetPointeeType(lldb::opaque_compiler_type_t type) { |
| 4649 | if (type) { |
| 4650 | clang::QualType qual_type(GetQualType(type)); |
| 4651 | return CompilerType(getASTContext(), |
| 4652 | qual_type.getTypePtr()->getPointeeType()); |
| 4653 | } |
| 4654 | return CompilerType(); |
| 4655 | } |
| 4656 | |
| 4657 | CompilerType |
| 4658 | ClangASTContext::GetPointerType(lldb::opaque_compiler_type_t type) { |
| 4659 | if (type) { |
| 4660 | clang::QualType qual_type(GetQualType(type)); |
| 4661 | |
| 4662 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4663 | switch (type_class) { |
| 4664 | case clang::Type::ObjCObject: |
| 4665 | case clang::Type::ObjCInterface: |
| 4666 | return CompilerType(getASTContext(), |
| 4667 | getASTContext()->getObjCObjectPointerType(qual_type)); |
| 4668 | |
| 4669 | default: |
| 4670 | return CompilerType(getASTContext(), |
| 4671 | getASTContext()->getPointerType(qual_type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4672 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4673 | } |
| 4674 | return CompilerType(); |
| 4675 | } |
| 4676 | |
| 4677 | CompilerType |
| 4678 | ClangASTContext::GetLValueReferenceType(lldb::opaque_compiler_type_t type) { |
| 4679 | if (type) |
| 4680 | return CompilerType(this, getASTContext() |
| 4681 | ->getLValueReferenceType(GetQualType(type)) |
| 4682 | .getAsOpaquePtr()); |
| 4683 | else |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4684 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4685 | } |
| 4686 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4687 | CompilerType |
| 4688 | ClangASTContext::GetRValueReferenceType(lldb::opaque_compiler_type_t type) { |
| 4689 | if (type) |
| 4690 | return CompilerType(this, getASTContext() |
| 4691 | ->getRValueReferenceType(GetQualType(type)) |
| 4692 | .getAsOpaquePtr()); |
| 4693 | else |
| 4694 | return CompilerType(); |
| 4695 | } |
| 4696 | |
| 4697 | CompilerType |
| 4698 | ClangASTContext::AddConstModifier(lldb::opaque_compiler_type_t type) { |
| 4699 | if (type) { |
| 4700 | clang::QualType result(GetQualType(type)); |
| 4701 | result.addConst(); |
| 4702 | return CompilerType(this, result.getAsOpaquePtr()); |
| 4703 | } |
| 4704 | return CompilerType(); |
| 4705 | } |
| 4706 | |
| 4707 | CompilerType |
| 4708 | ClangASTContext::AddVolatileModifier(lldb::opaque_compiler_type_t type) { |
| 4709 | if (type) { |
| 4710 | clang::QualType result(GetQualType(type)); |
| 4711 | result.addVolatile(); |
| 4712 | return CompilerType(this, result.getAsOpaquePtr()); |
| 4713 | } |
| 4714 | return CompilerType(); |
| 4715 | } |
| 4716 | |
| 4717 | CompilerType |
| 4718 | ClangASTContext::AddRestrictModifier(lldb::opaque_compiler_type_t type) { |
| 4719 | if (type) { |
| 4720 | clang::QualType result(GetQualType(type)); |
| 4721 | result.addRestrict(); |
| 4722 | return CompilerType(this, result.getAsOpaquePtr()); |
| 4723 | } |
| 4724 | return CompilerType(); |
| 4725 | } |
| 4726 | |
| 4727 | CompilerType |
| 4728 | ClangASTContext::CreateTypedef(lldb::opaque_compiler_type_t type, |
| 4729 | const char *typedef_name, |
| 4730 | const CompilerDeclContext &compiler_decl_ctx) { |
| 4731 | if (type) { |
| 4732 | clang::ASTContext *clang_ast = getASTContext(); |
| 4733 | clang::QualType qual_type(GetQualType(type)); |
| 4734 | |
| 4735 | clang::DeclContext *decl_ctx = |
| 4736 | ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); |
| 4737 | if (decl_ctx == nullptr) |
| 4738 | decl_ctx = getASTContext()->getTranslationUnitDecl(); |
| 4739 | |
| 4740 | clang::TypedefDecl *decl = clang::TypedefDecl::Create( |
| 4741 | *clang_ast, decl_ctx, clang::SourceLocation(), clang::SourceLocation(), |
| 4742 | &clang_ast->Idents.get(typedef_name), |
| 4743 | clang_ast->getTrivialTypeSourceInfo(qual_type)); |
| 4744 | |
| 4745 | clang::TagDecl *tdecl = nullptr; |
| 4746 | if (!qual_type.isNull()) { |
| 4747 | if (const clang::RecordType *rt = qual_type->getAs<clang::RecordType>()) |
| 4748 | tdecl = rt->getDecl(); |
| 4749 | if (const clang::EnumType *et = qual_type->getAs<clang::EnumType>()) |
| 4750 | tdecl = et->getDecl(); |
| 4751 | } |
| 4752 | |
| 4753 | // Check whether this declaration is an anonymous struct, union, or enum, |
| 4754 | // hidden behind a typedef. If so, we |
| 4755 | // try to check whether we have a typedef tag to attach to the original |
| 4756 | // record declaration |
| 4757 | if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl()) |
| 4758 | tdecl->setTypedefNameForAnonDecl(decl); |
| 4759 | |
| 4760 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier |
| 4761 | |
| 4762 | // Get a uniqued clang::QualType for the typedef decl type |
| 4763 | return CompilerType(this, clang_ast->getTypedefType(decl).getAsOpaquePtr()); |
| 4764 | } |
| 4765 | return CompilerType(); |
| 4766 | } |
| 4767 | |
| 4768 | CompilerType |
| 4769 | ClangASTContext::GetTypedefedType(lldb::opaque_compiler_type_t type) { |
| 4770 | if (type) { |
| 4771 | const clang::TypedefType *typedef_type = |
| 4772 | llvm::dyn_cast<clang::TypedefType>(GetQualType(type)); |
| 4773 | if (typedef_type) |
| 4774 | return CompilerType(getASTContext(), |
| 4775 | typedef_type->getDecl()->getUnderlyingType()); |
| 4776 | } |
| 4777 | return CompilerType(); |
| 4778 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4779 | |
| 4780 | //---------------------------------------------------------------------- |
| 4781 | // Create related types using the current type's AST |
| 4782 | //---------------------------------------------------------------------- |
| 4783 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4784 | CompilerType ClangASTContext::GetBasicTypeFromAST(lldb::BasicType basic_type) { |
| 4785 | return ClangASTContext::GetBasicType(getASTContext(), basic_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4786 | } |
| 4787 | //---------------------------------------------------------------------- |
| 4788 | // Exploring the type |
| 4789 | //---------------------------------------------------------------------- |
| 4790 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4791 | uint64_t ClangASTContext::GetBitSize(lldb::opaque_compiler_type_t type, |
| 4792 | ExecutionContextScope *exe_scope) { |
| 4793 | if (GetCompleteType(type)) { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4794 | clang::QualType qual_type(GetCanonicalQualType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4795 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4796 | switch (type_class) { |
| 4797 | case clang::Type::Record: |
| 4798 | if (GetCompleteType(type)) |
| 4799 | return getASTContext()->getTypeSize(qual_type); |
| 4800 | else |
| 4801 | return 0; |
| 4802 | break; |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 4803 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4804 | case clang::Type::ObjCInterface: |
| 4805 | case clang::Type::ObjCObject: { |
| 4806 | ExecutionContext exe_ctx(exe_scope); |
| 4807 | Process *process = exe_ctx.GetProcessPtr(); |
| 4808 | if (process) { |
| 4809 | ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime(); |
| 4810 | if (objc_runtime) { |
| 4811 | uint64_t bit_size = 0; |
| 4812 | if (objc_runtime->GetTypeBitSize( |
| 4813 | CompilerType(getASTContext(), qual_type), bit_size)) |
| 4814 | return bit_size; |
| 4815 | } |
| 4816 | } else { |
| 4817 | static bool g_printed = false; |
| 4818 | if (!g_printed) { |
| 4819 | StreamString s; |
| 4820 | DumpTypeDescription(type, &s); |
| 4821 | |
| 4822 | llvm::outs() << "warning: trying to determine the size of type "; |
| 4823 | llvm::outs() << s.GetString() << "\n"; |
| 4824 | llvm::outs() << "without a valid ExecutionContext. this is not " |
| 4825 | "reliable. please file a bug against LLDB.\n"; |
| 4826 | llvm::outs() << "backtrace:\n"; |
| 4827 | llvm::sys::PrintStackTrace(llvm::outs()); |
| 4828 | llvm::outs() << "\n"; |
| 4829 | g_printed = true; |
| 4830 | } |
| 4831 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4832 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4833 | LLVM_FALLTHROUGH; |
| 4834 | default: |
| 4835 | const uint32_t bit_size = getASTContext()->getTypeSize(qual_type); |
| 4836 | if (bit_size == 0) { |
| 4837 | if (qual_type->isIncompleteArrayType()) |
| 4838 | return getASTContext()->getTypeSize( |
| 4839 | qual_type->getArrayElementTypeNoTypeQual() |
| 4840 | ->getCanonicalTypeUnqualified()); |
| 4841 | } |
| 4842 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 4843 | return bit_size + |
| 4844 | getASTContext()->getTypeSize( |
| 4845 | getASTContext()->ObjCBuiltinClassTy); |
| 4846 | return bit_size; |
| 4847 | } |
| 4848 | } |
| 4849 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4850 | } |
| 4851 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4852 | size_t ClangASTContext::GetTypeBitAlign(lldb::opaque_compiler_type_t type) { |
| 4853 | if (GetCompleteType(type)) |
| 4854 | return getASTContext()->getTypeAlign(GetQualType(type)); |
| 4855 | return 0; |
| 4856 | } |
| 4857 | |
| 4858 | lldb::Encoding ClangASTContext::GetEncoding(lldb::opaque_compiler_type_t type, |
| 4859 | uint64_t &count) { |
| 4860 | if (!type) |
| 4861 | return lldb::eEncodingInvalid; |
| 4862 | |
| 4863 | count = 1; |
| 4864 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4865 | |
| 4866 | switch (qual_type->getTypeClass()) { |
| 4867 | case clang::Type::UnaryTransform: |
| 4868 | break; |
| 4869 | |
| 4870 | case clang::Type::FunctionNoProto: |
| 4871 | case clang::Type::FunctionProto: |
| 4872 | break; |
| 4873 | |
| 4874 | case clang::Type::IncompleteArray: |
| 4875 | case clang::Type::VariableArray: |
| 4876 | break; |
| 4877 | |
| 4878 | case clang::Type::ConstantArray: |
| 4879 | break; |
| 4880 | |
| 4881 | case clang::Type::ExtVector: |
| 4882 | case clang::Type::Vector: |
| 4883 | // TODO: Set this to more than one??? |
| 4884 | break; |
| 4885 | |
| 4886 | case clang::Type::Builtin: |
| 4887 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 4888 | case clang::BuiltinType::Void: |
| 4889 | break; |
| 4890 | |
| 4891 | case clang::BuiltinType::Bool: |
| 4892 | case clang::BuiltinType::Char_S: |
| 4893 | case clang::BuiltinType::SChar: |
| 4894 | case clang::BuiltinType::WChar_S: |
| 4895 | case clang::BuiltinType::Char16: |
| 4896 | case clang::BuiltinType::Char32: |
| 4897 | case clang::BuiltinType::Short: |
| 4898 | case clang::BuiltinType::Int: |
| 4899 | case clang::BuiltinType::Long: |
| 4900 | case clang::BuiltinType::LongLong: |
| 4901 | case clang::BuiltinType::Int128: |
| 4902 | return lldb::eEncodingSint; |
| 4903 | |
| 4904 | case clang::BuiltinType::Char_U: |
| 4905 | case clang::BuiltinType::UChar: |
| 4906 | case clang::BuiltinType::WChar_U: |
| 4907 | case clang::BuiltinType::UShort: |
| 4908 | case clang::BuiltinType::UInt: |
| 4909 | case clang::BuiltinType::ULong: |
| 4910 | case clang::BuiltinType::ULongLong: |
| 4911 | case clang::BuiltinType::UInt128: |
| 4912 | return lldb::eEncodingUint; |
| 4913 | |
| 4914 | case clang::BuiltinType::Half: |
| 4915 | case clang::BuiltinType::Float: |
Ted Woodward | 4355c7c | 2017-09-20 19:16:53 +0000 | [diff] [blame] | 4916 | case clang::BuiltinType::Float16: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4917 | case clang::BuiltinType::Float128: |
| 4918 | case clang::BuiltinType::Double: |
| 4919 | case clang::BuiltinType::LongDouble: |
| 4920 | return lldb::eEncodingIEEE754; |
| 4921 | |
| 4922 | case clang::BuiltinType::ObjCClass: |
| 4923 | case clang::BuiltinType::ObjCId: |
| 4924 | case clang::BuiltinType::ObjCSel: |
| 4925 | return lldb::eEncodingUint; |
| 4926 | |
| 4927 | case clang::BuiltinType::NullPtr: |
| 4928 | return lldb::eEncodingUint; |
| 4929 | |
| 4930 | case clang::BuiltinType::Kind::ARCUnbridgedCast: |
| 4931 | case clang::BuiltinType::Kind::BoundMember: |
| 4932 | case clang::BuiltinType::Kind::BuiltinFn: |
| 4933 | case clang::BuiltinType::Kind::Dependent: |
| 4934 | case clang::BuiltinType::Kind::OCLClkEvent: |
| 4935 | case clang::BuiltinType::Kind::OCLEvent: |
| 4936 | case clang::BuiltinType::Kind::OCLImage1dRO: |
| 4937 | case clang::BuiltinType::Kind::OCLImage1dWO: |
| 4938 | case clang::BuiltinType::Kind::OCLImage1dRW: |
| 4939 | case clang::BuiltinType::Kind::OCLImage1dArrayRO: |
| 4940 | case clang::BuiltinType::Kind::OCLImage1dArrayWO: |
| 4941 | case clang::BuiltinType::Kind::OCLImage1dArrayRW: |
| 4942 | case clang::BuiltinType::Kind::OCLImage1dBufferRO: |
| 4943 | case clang::BuiltinType::Kind::OCLImage1dBufferWO: |
| 4944 | case clang::BuiltinType::Kind::OCLImage1dBufferRW: |
| 4945 | case clang::BuiltinType::Kind::OCLImage2dRO: |
| 4946 | case clang::BuiltinType::Kind::OCLImage2dWO: |
| 4947 | case clang::BuiltinType::Kind::OCLImage2dRW: |
| 4948 | case clang::BuiltinType::Kind::OCLImage2dArrayRO: |
| 4949 | case clang::BuiltinType::Kind::OCLImage2dArrayWO: |
| 4950 | case clang::BuiltinType::Kind::OCLImage2dArrayRW: |
| 4951 | case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO: |
| 4952 | case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO: |
| 4953 | case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW: |
| 4954 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO: |
| 4955 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO: |
| 4956 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW: |
| 4957 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO: |
| 4958 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO: |
| 4959 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW: |
| 4960 | case clang::BuiltinType::Kind::OCLImage2dDepthRO: |
| 4961 | case clang::BuiltinType::Kind::OCLImage2dDepthWO: |
| 4962 | case clang::BuiltinType::Kind::OCLImage2dDepthRW: |
| 4963 | case clang::BuiltinType::Kind::OCLImage2dMSAARO: |
| 4964 | case clang::BuiltinType::Kind::OCLImage2dMSAAWO: |
| 4965 | case clang::BuiltinType::Kind::OCLImage2dMSAARW: |
| 4966 | case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO: |
| 4967 | case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO: |
| 4968 | case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW: |
| 4969 | case clang::BuiltinType::Kind::OCLImage3dRO: |
| 4970 | case clang::BuiltinType::Kind::OCLImage3dWO: |
| 4971 | case clang::BuiltinType::Kind::OCLImage3dRW: |
| 4972 | case clang::BuiltinType::Kind::OCLQueue: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4973 | case clang::BuiltinType::Kind::OCLReserveID: |
| 4974 | case clang::BuiltinType::Kind::OCLSampler: |
| 4975 | case clang::BuiltinType::Kind::OMPArraySection: |
| 4976 | case clang::BuiltinType::Kind::Overload: |
| 4977 | case clang::BuiltinType::Kind::PseudoObject: |
| 4978 | case clang::BuiltinType::Kind::UnknownAny: |
| 4979 | break; |
| 4980 | } |
| 4981 | break; |
| 4982 | // All pointer types are represented as unsigned integer encodings. |
| 4983 | // We may nee to add a eEncodingPointer if we ever need to know the |
| 4984 | // difference |
| 4985 | case clang::Type::ObjCObjectPointer: |
| 4986 | case clang::Type::BlockPointer: |
| 4987 | case clang::Type::Pointer: |
| 4988 | case clang::Type::LValueReference: |
| 4989 | case clang::Type::RValueReference: |
| 4990 | case clang::Type::MemberPointer: |
| 4991 | return lldb::eEncodingUint; |
| 4992 | case clang::Type::Complex: { |
| 4993 | lldb::Encoding encoding = lldb::eEncodingIEEE754; |
| 4994 | if (qual_type->isComplexType()) |
| 4995 | encoding = lldb::eEncodingIEEE754; |
| 4996 | else { |
| 4997 | const clang::ComplexType *complex_type = |
| 4998 | qual_type->getAsComplexIntegerType(); |
| 4999 | if (complex_type) |
| 5000 | encoding = CompilerType(getASTContext(), complex_type->getElementType()) |
| 5001 | .GetEncoding(count); |
| 5002 | else |
| 5003 | encoding = lldb::eEncodingSint; |
| 5004 | } |
| 5005 | count = 2; |
| 5006 | return encoding; |
| 5007 | } |
| 5008 | |
| 5009 | case clang::Type::ObjCInterface: |
| 5010 | break; |
| 5011 | case clang::Type::Record: |
| 5012 | break; |
| 5013 | case clang::Type::Enum: |
| 5014 | return lldb::eEncodingSint; |
| 5015 | case clang::Type::Typedef: |
| 5016 | return CompilerType(getASTContext(), |
| 5017 | llvm::cast<clang::TypedefType>(qual_type) |
| 5018 | ->getDecl() |
| 5019 | ->getUnderlyingType()) |
| 5020 | .GetEncoding(count); |
| 5021 | |
| 5022 | case clang::Type::Auto: |
| 5023 | return CompilerType( |
| 5024 | getASTContext(), |
| 5025 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 5026 | .GetEncoding(count); |
| 5027 | |
| 5028 | case clang::Type::Elaborated: |
| 5029 | return CompilerType( |
| 5030 | getASTContext(), |
| 5031 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 5032 | .GetEncoding(count); |
| 5033 | |
| 5034 | case clang::Type::Paren: |
| 5035 | return CompilerType(getASTContext(), |
| 5036 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 5037 | .GetEncoding(count); |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5038 | case clang::Type::TypeOfExpr: |
| 5039 | return CompilerType(getASTContext(), |
| 5040 | llvm::cast<clang::TypeOfExprType>(qual_type) |
| 5041 | ->getUnderlyingExpr() |
| 5042 | ->getType()) |
| 5043 | .GetEncoding(count); |
| 5044 | case clang::Type::TypeOf: |
| 5045 | return CompilerType( |
| 5046 | getASTContext(), |
| 5047 | llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType()) |
| 5048 | .GetEncoding(count); |
| 5049 | case clang::Type::Decltype: |
| 5050 | return CompilerType( |
| 5051 | getASTContext(), |
| 5052 | llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType()) |
| 5053 | .GetEncoding(count); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5054 | case clang::Type::DependentSizedArray: |
| 5055 | case clang::Type::DependentSizedExtVector: |
| 5056 | case clang::Type::UnresolvedUsing: |
| 5057 | case clang::Type::Attributed: |
| 5058 | case clang::Type::TemplateTypeParm: |
| 5059 | case clang::Type::SubstTemplateTypeParm: |
| 5060 | case clang::Type::SubstTemplateTypeParmPack: |
| 5061 | case clang::Type::InjectedClassName: |
| 5062 | case clang::Type::DependentName: |
| 5063 | case clang::Type::DependentTemplateSpecialization: |
| 5064 | case clang::Type::PackExpansion: |
| 5065 | case clang::Type::ObjCObject: |
| 5066 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5067 | case clang::Type::TemplateSpecialization: |
Pavel Labath | 4f19fce2 | 2017-02-17 13:39:50 +0000 | [diff] [blame] | 5068 | case clang::Type::DeducedTemplateSpecialization: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5069 | case clang::Type::Atomic: |
| 5070 | case clang::Type::Adjusted: |
| 5071 | case clang::Type::Pipe: |
| 5072 | break; |
| 5073 | |
| 5074 | // pointer type decayed from an array or function type. |
| 5075 | case clang::Type::Decayed: |
| 5076 | break; |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 5077 | case clang::Type::ObjCTypeParam: |
| 5078 | break; |
Ted Woodward | 66060cf | 2017-10-11 22:42:21 +0000 | [diff] [blame] | 5079 | |
| 5080 | case clang::Type::DependentAddressSpace: |
| 5081 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5082 | } |
| 5083 | count = 0; |
| 5084 | return lldb::eEncodingInvalid; |
| 5085 | } |
| 5086 | |
| 5087 | lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) { |
| 5088 | if (!type) |
| 5089 | return lldb::eFormatDefault; |
| 5090 | |
| 5091 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5092 | |
| 5093 | switch (qual_type->getTypeClass()) { |
| 5094 | case clang::Type::UnaryTransform: |
| 5095 | break; |
| 5096 | |
| 5097 | case clang::Type::FunctionNoProto: |
| 5098 | case clang::Type::FunctionProto: |
| 5099 | break; |
| 5100 | |
| 5101 | case clang::Type::IncompleteArray: |
| 5102 | case clang::Type::VariableArray: |
| 5103 | break; |
| 5104 | |
| 5105 | case clang::Type::ConstantArray: |
| 5106 | return lldb::eFormatVoid; // no value |
| 5107 | |
| 5108 | case clang::Type::ExtVector: |
| 5109 | case clang::Type::Vector: |
| 5110 | break; |
| 5111 | |
| 5112 | case clang::Type::Builtin: |
| 5113 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 5114 | // default: assert(0 && "Unknown builtin type!"); |
| 5115 | case clang::BuiltinType::UnknownAny: |
| 5116 | case clang::BuiltinType::Void: |
| 5117 | case clang::BuiltinType::BoundMember: |
| 5118 | break; |
| 5119 | |
| 5120 | case clang::BuiltinType::Bool: |
| 5121 | return lldb::eFormatBoolean; |
| 5122 | case clang::BuiltinType::Char_S: |
| 5123 | case clang::BuiltinType::SChar: |
| 5124 | case clang::BuiltinType::WChar_S: |
| 5125 | case clang::BuiltinType::Char_U: |
| 5126 | case clang::BuiltinType::UChar: |
| 5127 | case clang::BuiltinType::WChar_U: |
| 5128 | return lldb::eFormatChar; |
| 5129 | case clang::BuiltinType::Char16: |
| 5130 | return lldb::eFormatUnicode16; |
| 5131 | case clang::BuiltinType::Char32: |
| 5132 | return lldb::eFormatUnicode32; |
| 5133 | case clang::BuiltinType::UShort: |
| 5134 | return lldb::eFormatUnsigned; |
| 5135 | case clang::BuiltinType::Short: |
| 5136 | return lldb::eFormatDecimal; |
| 5137 | case clang::BuiltinType::UInt: |
| 5138 | return lldb::eFormatUnsigned; |
| 5139 | case clang::BuiltinType::Int: |
| 5140 | return lldb::eFormatDecimal; |
| 5141 | case clang::BuiltinType::ULong: |
| 5142 | return lldb::eFormatUnsigned; |
| 5143 | case clang::BuiltinType::Long: |
| 5144 | return lldb::eFormatDecimal; |
| 5145 | case clang::BuiltinType::ULongLong: |
| 5146 | return lldb::eFormatUnsigned; |
| 5147 | case clang::BuiltinType::LongLong: |
| 5148 | return lldb::eFormatDecimal; |
| 5149 | case clang::BuiltinType::UInt128: |
| 5150 | return lldb::eFormatUnsigned; |
| 5151 | case clang::BuiltinType::Int128: |
| 5152 | return lldb::eFormatDecimal; |
| 5153 | case clang::BuiltinType::Half: |
| 5154 | case clang::BuiltinType::Float: |
| 5155 | case clang::BuiltinType::Double: |
| 5156 | case clang::BuiltinType::LongDouble: |
| 5157 | return lldb::eFormatFloat; |
| 5158 | default: |
| 5159 | return lldb::eFormatHex; |
| 5160 | } |
| 5161 | break; |
| 5162 | case clang::Type::ObjCObjectPointer: |
| 5163 | return lldb::eFormatHex; |
| 5164 | case clang::Type::BlockPointer: |
| 5165 | return lldb::eFormatHex; |
| 5166 | case clang::Type::Pointer: |
| 5167 | return lldb::eFormatHex; |
| 5168 | case clang::Type::LValueReference: |
| 5169 | case clang::Type::RValueReference: |
| 5170 | return lldb::eFormatHex; |
| 5171 | case clang::Type::MemberPointer: |
| 5172 | break; |
| 5173 | case clang::Type::Complex: { |
| 5174 | if (qual_type->isComplexType()) |
| 5175 | return lldb::eFormatComplex; |
| 5176 | else |
| 5177 | return lldb::eFormatComplexInteger; |
| 5178 | } |
| 5179 | case clang::Type::ObjCInterface: |
| 5180 | break; |
| 5181 | case clang::Type::Record: |
| 5182 | break; |
| 5183 | case clang::Type::Enum: |
| 5184 | return lldb::eFormatEnum; |
| 5185 | case clang::Type::Typedef: |
| 5186 | return CompilerType(getASTContext(), |
| 5187 | llvm::cast<clang::TypedefType>(qual_type) |
| 5188 | ->getDecl() |
| 5189 | ->getUnderlyingType()) |
| 5190 | .GetFormat(); |
| 5191 | case clang::Type::Auto: |
| 5192 | return CompilerType(getASTContext(), |
| 5193 | llvm::cast<clang::AutoType>(qual_type)->desugar()) |
| 5194 | .GetFormat(); |
| 5195 | case clang::Type::Paren: |
| 5196 | return CompilerType(getASTContext(), |
| 5197 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 5198 | .GetFormat(); |
| 5199 | case clang::Type::Elaborated: |
| 5200 | return CompilerType( |
| 5201 | getASTContext(), |
| 5202 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 5203 | .GetFormat(); |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 5204 | case clang::Type::TypeOfExpr: |
| 5205 | return CompilerType(getASTContext(), |
| 5206 | llvm::cast<clang::TypeOfExprType>(qual_type) |
| 5207 | ->getUnderlyingExpr() |
| 5208 | ->getType()) |
| 5209 | .GetFormat(); |
| 5210 | case clang::Type::TypeOf: |
| 5211 | return CompilerType( |
| 5212 | getASTContext(), |
| 5213 | llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType()) |
| 5214 | .GetFormat(); |
| 5215 | case clang::Type::Decltype: |
| 5216 | return CompilerType( |
| 5217 | getASTContext(), |
| 5218 | llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType()) |
| 5219 | .GetFormat(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5220 | case clang::Type::DependentSizedArray: |
| 5221 | case clang::Type::DependentSizedExtVector: |
| 5222 | case clang::Type::UnresolvedUsing: |
| 5223 | case clang::Type::Attributed: |
| 5224 | case clang::Type::TemplateTypeParm: |
| 5225 | case clang::Type::SubstTemplateTypeParm: |
| 5226 | case clang::Type::SubstTemplateTypeParmPack: |
| 5227 | case clang::Type::InjectedClassName: |
| 5228 | case clang::Type::DependentName: |
| 5229 | case clang::Type::DependentTemplateSpecialization: |
| 5230 | case clang::Type::PackExpansion: |
| 5231 | case clang::Type::ObjCObject: |
| 5232 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5233 | case clang::Type::TemplateSpecialization: |
Pavel Labath | 4f19fce2 | 2017-02-17 13:39:50 +0000 | [diff] [blame] | 5234 | case clang::Type::DeducedTemplateSpecialization: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5235 | case clang::Type::Atomic: |
| 5236 | case clang::Type::Adjusted: |
| 5237 | case clang::Type::Pipe: |
| 5238 | break; |
| 5239 | |
| 5240 | // pointer type decayed from an array or function type. |
| 5241 | case clang::Type::Decayed: |
| 5242 | break; |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 5243 | case clang::Type::ObjCTypeParam: |
| 5244 | break; |
Ted Woodward | 66060cf | 2017-10-11 22:42:21 +0000 | [diff] [blame] | 5245 | |
| 5246 | case clang::Type::DependentAddressSpace: |
| 5247 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5248 | } |
| 5249 | // We don't know hot to display this type... |
| 5250 | return lldb::eFormatBytes; |
| 5251 | } |
| 5252 | |
| 5253 | static bool ObjCDeclHasIVars(clang::ObjCInterfaceDecl *class_interface_decl, |
| 5254 | bool check_superclass) { |
| 5255 | while (class_interface_decl) { |
| 5256 | if (class_interface_decl->ivar_size() > 0) |
| 5257 | return true; |
| 5258 | |
| 5259 | if (check_superclass) |
| 5260 | class_interface_decl = class_interface_decl->getSuperClass(); |
| 5261 | else |
| 5262 | break; |
| 5263 | } |
| 5264 | return false; |
| 5265 | } |
| 5266 | |
| 5267 | uint32_t ClangASTContext::GetNumChildren(lldb::opaque_compiler_type_t type, |
| 5268 | bool omit_empty_base_classes) { |
| 5269 | if (!type) |
| 5270 | return 0; |
| 5271 | |
| 5272 | uint32_t num_children = 0; |
| 5273 | clang::QualType qual_type(GetQualType(type)); |
| 5274 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5275 | switch (type_class) { |
| 5276 | case clang::Type::Builtin: |
| 5277 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 5278 | case clang::BuiltinType::ObjCId: // child is Class |
| 5279 | case clang::BuiltinType::ObjCClass: // child is Class |
| 5280 | num_children = 1; |
| 5281 | break; |
| 5282 | |
| 5283 | default: |
| 5284 | break; |
| 5285 | } |
| 5286 | break; |
| 5287 | |
| 5288 | case clang::Type::Complex: |
| 5289 | return 0; |
| 5290 | |
| 5291 | case clang::Type::Record: |
| 5292 | if (GetCompleteQualType(getASTContext(), qual_type)) { |
| 5293 | const clang::RecordType *record_type = |
| 5294 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 5295 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5296 | assert(record_decl); |
| 5297 | const clang::CXXRecordDecl *cxx_record_decl = |
| 5298 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 5299 | if (cxx_record_decl) { |
| 5300 | if (omit_empty_base_classes) { |
| 5301 | // Check each base classes to see if it or any of its |
| 5302 | // base classes contain any fields. This can help |
| 5303 | // limit the noise in variable views by not having to |
| 5304 | // show base classes that contain no members. |
| 5305 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 5306 | base_class_end; |
| 5307 | for (base_class = cxx_record_decl->bases_begin(), |
| 5308 | base_class_end = cxx_record_decl->bases_end(); |
| 5309 | base_class != base_class_end; ++base_class) { |
| 5310 | const clang::CXXRecordDecl *base_class_decl = |
| 5311 | llvm::cast<clang::CXXRecordDecl>( |
| 5312 | base_class->getType() |
| 5313 | ->getAs<clang::RecordType>() |
| 5314 | ->getDecl()); |
| 5315 | |
| 5316 | // Skip empty base classes |
| 5317 | if (ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 5318 | continue; |
| 5319 | |
| 5320 | num_children++; |
| 5321 | } |
| 5322 | } else { |
| 5323 | // Include all base classes |
| 5324 | num_children += cxx_record_decl->getNumBases(); |
| 5325 | } |
| 5326 | } |
| 5327 | clang::RecordDecl::field_iterator field, field_end; |
| 5328 | for (field = record_decl->field_begin(), |
| 5329 | field_end = record_decl->field_end(); |
| 5330 | field != field_end; ++field) |
| 5331 | ++num_children; |
| 5332 | } |
| 5333 | break; |
| 5334 | |
| 5335 | case clang::Type::ObjCObject: |
| 5336 | case clang::Type::ObjCInterface: |
| 5337 | if (GetCompleteQualType(getASTContext(), qual_type)) { |
| 5338 | const clang::ObjCObjectType *objc_class_type = |
| 5339 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5340 | assert(objc_class_type); |
| 5341 | if (objc_class_type) { |
| 5342 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5343 | objc_class_type->getInterface(); |
| 5344 | |
| 5345 | if (class_interface_decl) { |
| 5346 | |
| 5347 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 5348 | class_interface_decl->getSuperClass(); |
| 5349 | if (superclass_interface_decl) { |
| 5350 | if (omit_empty_base_classes) { |
| 5351 | if (ObjCDeclHasIVars(superclass_interface_decl, true)) |
| 5352 | ++num_children; |
| 5353 | } else |
| 5354 | ++num_children; |
| 5355 | } |
| 5356 | |
| 5357 | num_children += class_interface_decl->ivar_size(); |
| 5358 | } |
| 5359 | } |
| 5360 | } |
| 5361 | break; |
| 5362 | |
| 5363 | case clang::Type::ObjCObjectPointer: { |
| 5364 | const clang::ObjCObjectPointerType *pointer_type = |
| 5365 | llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()); |
| 5366 | clang::QualType pointee_type = pointer_type->getPointeeType(); |
| 5367 | uint32_t num_pointee_children = |
| 5368 | CompilerType(getASTContext(), pointee_type) |
| 5369 | .GetNumChildren(omit_empty_base_classes); |
| 5370 | // If this type points to a simple type, then it has 1 child |
| 5371 | if (num_pointee_children == 0) |
| 5372 | num_children = 1; |
| 5373 | else |
| 5374 | num_children = num_pointee_children; |
| 5375 | } break; |
| 5376 | |
| 5377 | case clang::Type::Vector: |
| 5378 | case clang::Type::ExtVector: |
| 5379 | num_children = |
| 5380 | llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements(); |
| 5381 | break; |
| 5382 | |
| 5383 | case clang::Type::ConstantArray: |
| 5384 | num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr()) |
| 5385 | ->getSize() |
| 5386 | .getLimitedValue(); |
| 5387 | break; |
| 5388 | |
| 5389 | case clang::Type::Pointer: { |
| 5390 | const clang::PointerType *pointer_type = |
| 5391 | llvm::cast<clang::PointerType>(qual_type.getTypePtr()); |
| 5392 | clang::QualType pointee_type(pointer_type->getPointeeType()); |
| 5393 | uint32_t num_pointee_children = |
| 5394 | CompilerType(getASTContext(), pointee_type) |
| 5395 | .GetNumChildren(omit_empty_base_classes); |
| 5396 | if (num_pointee_children == 0) { |
| 5397 | // We have a pointer to a pointee type that claims it has no children. |
| 5398 | // We will want to look at |
| 5399 | num_children = GetNumPointeeChildren(pointee_type); |
| 5400 | } else |
| 5401 | num_children = num_pointee_children; |
| 5402 | } break; |
| 5403 | |
| 5404 | case clang::Type::LValueReference: |
| 5405 | case clang::Type::RValueReference: { |
| 5406 | const clang::ReferenceType *reference_type = |
| 5407 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 5408 | clang::QualType pointee_type = reference_type->getPointeeType(); |
| 5409 | uint32_t num_pointee_children = |
| 5410 | CompilerType(getASTContext(), pointee_type) |
| 5411 | .GetNumChildren(omit_empty_base_classes); |
| 5412 | // If this type points to a simple type, then it has 1 child |
| 5413 | if (num_pointee_children == 0) |
| 5414 | num_children = 1; |
| 5415 | else |
| 5416 | num_children = num_pointee_children; |
| 5417 | } break; |
| 5418 | |
| 5419 | case clang::Type::Typedef: |
| 5420 | num_children = |
| 5421 | CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type) |
| 5422 | ->getDecl() |
| 5423 | ->getUnderlyingType()) |
| 5424 | .GetNumChildren(omit_empty_base_classes); |
| 5425 | break; |
| 5426 | |
| 5427 | case clang::Type::Auto: |
| 5428 | num_children = |
| 5429 | CompilerType(getASTContext(), |
| 5430 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 5431 | .GetNumChildren(omit_empty_base_classes); |
| 5432 | break; |
| 5433 | |
| 5434 | case clang::Type::Elaborated: |
| 5435 | num_children = |
| 5436 | CompilerType( |
| 5437 | getASTContext(), |
| 5438 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 5439 | .GetNumChildren(omit_empty_base_classes); |
| 5440 | break; |
| 5441 | |
| 5442 | case clang::Type::Paren: |
| 5443 | num_children = |
| 5444 | CompilerType(getASTContext(), |
| 5445 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 5446 | .GetNumChildren(omit_empty_base_classes); |
| 5447 | break; |
| 5448 | default: |
| 5449 | break; |
| 5450 | } |
| 5451 | return num_children; |
| 5452 | } |
| 5453 | |
| 5454 | CompilerType ClangASTContext::GetBuiltinTypeByName(const ConstString &name) { |
| 5455 | return GetBasicType(GetBasicTypeEnumeration(name)); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 5456 | } |
| 5457 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5458 | lldb::BasicType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5459 | ClangASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) { |
| 5460 | if (type) { |
| 5461 | clang::QualType qual_type(GetQualType(type)); |
| 5462 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5463 | if (type_class == clang::Type::Builtin) { |
| 5464 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 5465 | case clang::BuiltinType::Void: |
| 5466 | return eBasicTypeVoid; |
| 5467 | case clang::BuiltinType::Bool: |
| 5468 | return eBasicTypeBool; |
| 5469 | case clang::BuiltinType::Char_S: |
| 5470 | return eBasicTypeSignedChar; |
| 5471 | case clang::BuiltinType::Char_U: |
| 5472 | return eBasicTypeUnsignedChar; |
| 5473 | case clang::BuiltinType::Char16: |
| 5474 | return eBasicTypeChar16; |
| 5475 | case clang::BuiltinType::Char32: |
| 5476 | return eBasicTypeChar32; |
| 5477 | case clang::BuiltinType::UChar: |
| 5478 | return eBasicTypeUnsignedChar; |
| 5479 | case clang::BuiltinType::SChar: |
| 5480 | return eBasicTypeSignedChar; |
| 5481 | case clang::BuiltinType::WChar_S: |
| 5482 | return eBasicTypeSignedWChar; |
| 5483 | case clang::BuiltinType::WChar_U: |
| 5484 | return eBasicTypeUnsignedWChar; |
| 5485 | case clang::BuiltinType::Short: |
| 5486 | return eBasicTypeShort; |
| 5487 | case clang::BuiltinType::UShort: |
| 5488 | return eBasicTypeUnsignedShort; |
| 5489 | case clang::BuiltinType::Int: |
| 5490 | return eBasicTypeInt; |
| 5491 | case clang::BuiltinType::UInt: |
| 5492 | return eBasicTypeUnsignedInt; |
| 5493 | case clang::BuiltinType::Long: |
| 5494 | return eBasicTypeLong; |
| 5495 | case clang::BuiltinType::ULong: |
| 5496 | return eBasicTypeUnsignedLong; |
| 5497 | case clang::BuiltinType::LongLong: |
| 5498 | return eBasicTypeLongLong; |
| 5499 | case clang::BuiltinType::ULongLong: |
| 5500 | return eBasicTypeUnsignedLongLong; |
| 5501 | case clang::BuiltinType::Int128: |
| 5502 | return eBasicTypeInt128; |
| 5503 | case clang::BuiltinType::UInt128: |
| 5504 | return eBasicTypeUnsignedInt128; |
| 5505 | |
| 5506 | case clang::BuiltinType::Half: |
| 5507 | return eBasicTypeHalf; |
| 5508 | case clang::BuiltinType::Float: |
| 5509 | return eBasicTypeFloat; |
| 5510 | case clang::BuiltinType::Double: |
| 5511 | return eBasicTypeDouble; |
| 5512 | case clang::BuiltinType::LongDouble: |
| 5513 | return eBasicTypeLongDouble; |
| 5514 | |
| 5515 | case clang::BuiltinType::NullPtr: |
| 5516 | return eBasicTypeNullPtr; |
| 5517 | case clang::BuiltinType::ObjCId: |
| 5518 | return eBasicTypeObjCID; |
| 5519 | case clang::BuiltinType::ObjCClass: |
| 5520 | return eBasicTypeObjCClass; |
| 5521 | case clang::BuiltinType::ObjCSel: |
| 5522 | return eBasicTypeObjCSel; |
| 5523 | default: |
| 5524 | return eBasicTypeOther; |
| 5525 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5526 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5527 | } |
| 5528 | return eBasicTypeInvalid; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5529 | } |
| 5530 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5531 | void ClangASTContext::ForEachEnumerator( |
| 5532 | lldb::opaque_compiler_type_t type, |
| 5533 | std::function<bool(const CompilerType &integer_type, |
| 5534 | const ConstString &name, |
| 5535 | const llvm::APSInt &value)> const &callback) { |
| 5536 | const clang::EnumType *enum_type = |
| 5537 | llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)); |
| 5538 | if (enum_type) { |
| 5539 | const clang::EnumDecl *enum_decl = enum_type->getDecl(); |
| 5540 | if (enum_decl) { |
| 5541 | CompilerType integer_type(this, |
| 5542 | enum_decl->getIntegerType().getAsOpaquePtr()); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5543 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5544 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 5545 | for (enum_pos = enum_decl->enumerator_begin(), |
| 5546 | enum_end_pos = enum_decl->enumerator_end(); |
| 5547 | enum_pos != enum_end_pos; ++enum_pos) { |
| 5548 | ConstString name(enum_pos->getNameAsString().c_str()); |
| 5549 | if (!callback(integer_type, name, enum_pos->getInitVal())) |
| 5550 | break; |
| 5551 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5552 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5553 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5554 | } |
| 5555 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5556 | #pragma mark Aggregate Types |
| 5557 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5558 | uint32_t ClangASTContext::GetNumFields(lldb::opaque_compiler_type_t type) { |
| 5559 | if (!type) |
| 5560 | return 0; |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5561 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5562 | uint32_t count = 0; |
| 5563 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5564 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5565 | switch (type_class) { |
| 5566 | case clang::Type::Record: |
| 5567 | if (GetCompleteType(type)) { |
| 5568 | const clang::RecordType *record_type = |
| 5569 | llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 5570 | if (record_type) { |
| 5571 | clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5572 | if (record_decl) { |
| 5573 | uint32_t field_idx = 0; |
| 5574 | clang::RecordDecl::field_iterator field, field_end; |
| 5575 | for (field = record_decl->field_begin(), |
| 5576 | field_end = record_decl->field_end(); |
| 5577 | field != field_end; ++field) |
| 5578 | ++field_idx; |
| 5579 | count = field_idx; |
| 5580 | } |
| 5581 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5582 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5583 | break; |
| 5584 | |
| 5585 | case clang::Type::Typedef: |
| 5586 | count = |
| 5587 | CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type) |
| 5588 | ->getDecl() |
| 5589 | ->getUnderlyingType()) |
| 5590 | .GetNumFields(); |
| 5591 | break; |
| 5592 | |
| 5593 | case clang::Type::Auto: |
| 5594 | count = |
| 5595 | CompilerType(getASTContext(), |
| 5596 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 5597 | .GetNumFields(); |
| 5598 | break; |
| 5599 | |
| 5600 | case clang::Type::Elaborated: |
| 5601 | count = CompilerType( |
| 5602 | getASTContext(), |
| 5603 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 5604 | .GetNumFields(); |
| 5605 | break; |
| 5606 | |
| 5607 | case clang::Type::Paren: |
| 5608 | count = CompilerType(getASTContext(), |
| 5609 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 5610 | .GetNumFields(); |
| 5611 | break; |
| 5612 | |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5613 | case clang::Type::ObjCObjectPointer: { |
| 5614 | const clang::ObjCObjectPointerType *objc_class_type = |
Sean Callanan | 732a6f4 | 2017-05-15 19:55:20 +0000 | [diff] [blame] | 5615 | qual_type->getAs<clang::ObjCObjectPointerType>(); |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5616 | const clang::ObjCInterfaceType *objc_interface_type = |
| 5617 | objc_class_type->getInterfaceType(); |
| 5618 | if (objc_interface_type && |
Davide Italiano | 52ffb53 | 2017-04-17 18:24:18 +0000 | [diff] [blame] | 5619 | GetCompleteType(static_cast<lldb::opaque_compiler_type_t>( |
| 5620 | const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) { |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5621 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5622 | objc_interface_type->getDecl(); |
| 5623 | if (class_interface_decl) { |
| 5624 | count = class_interface_decl->ivar_size(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5625 | } |
| 5626 | } |
| 5627 | break; |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5628 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5629 | |
| 5630 | case clang::Type::ObjCObject: |
| 5631 | case clang::Type::ObjCInterface: |
| 5632 | if (GetCompleteType(type)) { |
| 5633 | const clang::ObjCObjectType *objc_class_type = |
| 5634 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5635 | if (objc_class_type) { |
| 5636 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5637 | objc_class_type->getInterface(); |
| 5638 | |
| 5639 | if (class_interface_decl) |
| 5640 | count = class_interface_decl->ivar_size(); |
| 5641 | } |
| 5642 | } |
| 5643 | break; |
| 5644 | |
| 5645 | default: |
| 5646 | break; |
| 5647 | } |
| 5648 | return count; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5649 | } |
| 5650 | |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5651 | static lldb::opaque_compiler_type_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5652 | GetObjCFieldAtIndex(clang::ASTContext *ast, |
| 5653 | clang::ObjCInterfaceDecl *class_interface_decl, size_t idx, |
| 5654 | std::string &name, uint64_t *bit_offset_ptr, |
| 5655 | uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) { |
| 5656 | if (class_interface_decl) { |
| 5657 | if (idx < (class_interface_decl->ivar_size())) { |
| 5658 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, |
| 5659 | ivar_end = class_interface_decl->ivar_end(); |
| 5660 | uint32_t ivar_idx = 0; |
| 5661 | |
| 5662 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; |
| 5663 | ++ivar_pos, ++ivar_idx) { |
| 5664 | if (ivar_idx == idx) { |
| 5665 | const clang::ObjCIvarDecl *ivar_decl = *ivar_pos; |
| 5666 | |
| 5667 | clang::QualType ivar_qual_type(ivar_decl->getType()); |
| 5668 | |
| 5669 | name.assign(ivar_decl->getNameAsString()); |
| 5670 | |
| 5671 | if (bit_offset_ptr) { |
| 5672 | const clang::ASTRecordLayout &interface_layout = |
| 5673 | ast->getASTObjCInterfaceLayout(class_interface_decl); |
| 5674 | *bit_offset_ptr = interface_layout.getFieldOffset(ivar_idx); |
| 5675 | } |
| 5676 | |
| 5677 | const bool is_bitfield = ivar_pos->isBitField(); |
| 5678 | |
| 5679 | if (bitfield_bit_size_ptr) { |
| 5680 | *bitfield_bit_size_ptr = 0; |
| 5681 | |
| 5682 | if (is_bitfield && ast) { |
| 5683 | clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth(); |
| 5684 | llvm::APSInt bitfield_apsint; |
| 5685 | if (bitfield_bit_size_expr && |
| 5686 | bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, |
| 5687 | *ast)) { |
| 5688 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 5689 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5690 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5691 | } |
| 5692 | if (is_bitfield_ptr) |
| 5693 | *is_bitfield_ptr = is_bitfield; |
| 5694 | |
| 5695 | return ivar_qual_type.getAsOpaquePtr(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5696 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5697 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5698 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5699 | } |
| 5700 | return nullptr; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5701 | } |
| 5702 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5703 | CompilerType ClangASTContext::GetFieldAtIndex(lldb::opaque_compiler_type_t type, |
| 5704 | size_t idx, std::string &name, |
| 5705 | uint64_t *bit_offset_ptr, |
| 5706 | uint32_t *bitfield_bit_size_ptr, |
| 5707 | bool *is_bitfield_ptr) { |
| 5708 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5709 | return CompilerType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5710 | |
| 5711 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5712 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5713 | switch (type_class) { |
| 5714 | case clang::Type::Record: |
| 5715 | if (GetCompleteType(type)) { |
| 5716 | const clang::RecordType *record_type = |
| 5717 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 5718 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5719 | uint32_t field_idx = 0; |
| 5720 | clang::RecordDecl::field_iterator field, field_end; |
| 5721 | for (field = record_decl->field_begin(), |
| 5722 | field_end = record_decl->field_end(); |
| 5723 | field != field_end; ++field, ++field_idx) { |
| 5724 | if (idx == field_idx) { |
| 5725 | // Print the member type if requested |
| 5726 | // Print the member name and equal sign |
| 5727 | name.assign(field->getNameAsString()); |
| 5728 | |
| 5729 | // Figure out the type byte size (field_type_info.first) and |
| 5730 | // alignment (field_type_info.second) from the AST context. |
| 5731 | if (bit_offset_ptr) { |
| 5732 | const clang::ASTRecordLayout &record_layout = |
| 5733 | getASTContext()->getASTRecordLayout(record_decl); |
| 5734 | *bit_offset_ptr = record_layout.getFieldOffset(field_idx); |
| 5735 | } |
| 5736 | |
| 5737 | const bool is_bitfield = field->isBitField(); |
| 5738 | |
| 5739 | if (bitfield_bit_size_ptr) { |
| 5740 | *bitfield_bit_size_ptr = 0; |
| 5741 | |
| 5742 | if (is_bitfield) { |
| 5743 | clang::Expr *bitfield_bit_size_expr = field->getBitWidth(); |
| 5744 | llvm::APSInt bitfield_apsint; |
| 5745 | if (bitfield_bit_size_expr && |
| 5746 | bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, |
| 5747 | *getASTContext())) { |
| 5748 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 5749 | } |
| 5750 | } |
| 5751 | } |
| 5752 | if (is_bitfield_ptr) |
| 5753 | *is_bitfield_ptr = is_bitfield; |
| 5754 | |
| 5755 | return CompilerType(getASTContext(), field->getType()); |
| 5756 | } |
| 5757 | } |
| 5758 | } |
| 5759 | break; |
| 5760 | |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5761 | case clang::Type::ObjCObjectPointer: { |
| 5762 | const clang::ObjCObjectPointerType *objc_class_type = |
Sean Callanan | 732a6f4 | 2017-05-15 19:55:20 +0000 | [diff] [blame] | 5763 | qual_type->getAs<clang::ObjCObjectPointerType>(); |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5764 | const clang::ObjCInterfaceType *objc_interface_type = |
| 5765 | objc_class_type->getInterfaceType(); |
| 5766 | if (objc_interface_type && |
Davide Italiano | 52ffb53 | 2017-04-17 18:24:18 +0000 | [diff] [blame] | 5767 | GetCompleteType(static_cast<lldb::opaque_compiler_type_t>( |
| 5768 | const_cast<clang::ObjCInterfaceType *>(objc_interface_type)))) { |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5769 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5770 | objc_interface_type->getDecl(); |
| 5771 | if (class_interface_decl) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5772 | return CompilerType( |
| 5773 | this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, |
| 5774 | idx, name, bit_offset_ptr, |
| 5775 | bitfield_bit_size_ptr, is_bitfield_ptr)); |
| 5776 | } |
| 5777 | } |
| 5778 | break; |
Sean Callanan | f9c622a | 2016-09-30 18:44:43 +0000 | [diff] [blame] | 5779 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5780 | |
| 5781 | case clang::Type::ObjCObject: |
| 5782 | case clang::Type::ObjCInterface: |
| 5783 | if (GetCompleteType(type)) { |
| 5784 | const clang::ObjCObjectType *objc_class_type = |
| 5785 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5786 | assert(objc_class_type); |
| 5787 | if (objc_class_type) { |
| 5788 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5789 | objc_class_type->getInterface(); |
| 5790 | return CompilerType( |
| 5791 | this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, |
| 5792 | idx, name, bit_offset_ptr, |
| 5793 | bitfield_bit_size_ptr, is_bitfield_ptr)); |
| 5794 | } |
| 5795 | } |
| 5796 | break; |
| 5797 | |
| 5798 | case clang::Type::Typedef: |
| 5799 | return CompilerType(getASTContext(), |
| 5800 | llvm::cast<clang::TypedefType>(qual_type) |
| 5801 | ->getDecl() |
| 5802 | ->getUnderlyingType()) |
| 5803 | .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, |
| 5804 | is_bitfield_ptr); |
| 5805 | |
| 5806 | case clang::Type::Auto: |
| 5807 | return CompilerType( |
| 5808 | getASTContext(), |
| 5809 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 5810 | .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, |
| 5811 | is_bitfield_ptr); |
| 5812 | |
| 5813 | case clang::Type::Elaborated: |
| 5814 | return CompilerType( |
| 5815 | getASTContext(), |
| 5816 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 5817 | .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, |
| 5818 | is_bitfield_ptr); |
| 5819 | |
| 5820 | case clang::Type::Paren: |
| 5821 | return CompilerType(getASTContext(), |
| 5822 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 5823 | .GetFieldAtIndex(idx, name, bit_offset_ptr, bitfield_bit_size_ptr, |
| 5824 | is_bitfield_ptr); |
| 5825 | |
| 5826 | default: |
| 5827 | break; |
| 5828 | } |
| 5829 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5830 | } |
| 5831 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5832 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5833 | ClangASTContext::GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) { |
| 5834 | uint32_t count = 0; |
| 5835 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5836 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5837 | switch (type_class) { |
| 5838 | case clang::Type::Record: |
| 5839 | if (GetCompleteType(type)) { |
| 5840 | const clang::CXXRecordDecl *cxx_record_decl = |
| 5841 | qual_type->getAsCXXRecordDecl(); |
| 5842 | if (cxx_record_decl) |
| 5843 | count = cxx_record_decl->getNumBases(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5844 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5845 | break; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5846 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5847 | case clang::Type::ObjCObjectPointer: |
| 5848 | count = GetPointeeType(type).GetNumDirectBaseClasses(); |
| 5849 | break; |
| 5850 | |
| 5851 | case clang::Type::ObjCObject: |
| 5852 | if (GetCompleteType(type)) { |
| 5853 | const clang::ObjCObjectType *objc_class_type = |
| 5854 | qual_type->getAsObjCQualifiedInterfaceType(); |
| 5855 | if (objc_class_type) { |
| 5856 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5857 | objc_class_type->getInterface(); |
| 5858 | |
| 5859 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 5860 | count = 1; |
| 5861 | } |
| 5862 | } |
| 5863 | break; |
| 5864 | case clang::Type::ObjCInterface: |
| 5865 | if (GetCompleteType(type)) { |
| 5866 | const clang::ObjCInterfaceType *objc_interface_type = |
| 5867 | qual_type->getAs<clang::ObjCInterfaceType>(); |
| 5868 | if (objc_interface_type) { |
| 5869 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 5870 | objc_interface_type->getInterface(); |
| 5871 | |
| 5872 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 5873 | count = 1; |
| 5874 | } |
| 5875 | } |
| 5876 | break; |
| 5877 | |
| 5878 | case clang::Type::Typedef: |
| 5879 | count = GetNumDirectBaseClasses(llvm::cast<clang::TypedefType>(qual_type) |
| 5880 | ->getDecl() |
| 5881 | ->getUnderlyingType() |
| 5882 | .getAsOpaquePtr()); |
| 5883 | break; |
| 5884 | |
| 5885 | case clang::Type::Auto: |
| 5886 | count = GetNumDirectBaseClasses(llvm::cast<clang::AutoType>(qual_type) |
| 5887 | ->getDeducedType() |
| 5888 | .getAsOpaquePtr()); |
| 5889 | break; |
| 5890 | |
| 5891 | case clang::Type::Elaborated: |
| 5892 | count = GetNumDirectBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type) |
| 5893 | ->getNamedType() |
| 5894 | .getAsOpaquePtr()); |
| 5895 | break; |
| 5896 | |
| 5897 | case clang::Type::Paren: |
| 5898 | return GetNumDirectBaseClasses( |
| 5899 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 5900 | |
| 5901 | default: |
| 5902 | break; |
| 5903 | } |
| 5904 | return count; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5908 | ClangASTContext::GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) { |
| 5909 | uint32_t count = 0; |
| 5910 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5911 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5912 | switch (type_class) { |
| 5913 | case clang::Type::Record: |
| 5914 | if (GetCompleteType(type)) { |
| 5915 | const clang::CXXRecordDecl *cxx_record_decl = |
| 5916 | qual_type->getAsCXXRecordDecl(); |
| 5917 | if (cxx_record_decl) |
| 5918 | count = cxx_record_decl->getNumVBases(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5919 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5920 | break; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5921 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5922 | case clang::Type::Typedef: |
| 5923 | count = GetNumVirtualBaseClasses(llvm::cast<clang::TypedefType>(qual_type) |
| 5924 | ->getDecl() |
| 5925 | ->getUnderlyingType() |
| 5926 | .getAsOpaquePtr()); |
| 5927 | break; |
| 5928 | |
| 5929 | case clang::Type::Auto: |
| 5930 | count = GetNumVirtualBaseClasses(llvm::cast<clang::AutoType>(qual_type) |
| 5931 | ->getDeducedType() |
| 5932 | .getAsOpaquePtr()); |
| 5933 | break; |
| 5934 | |
| 5935 | case clang::Type::Elaborated: |
| 5936 | count = |
| 5937 | GetNumVirtualBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type) |
| 5938 | ->getNamedType() |
| 5939 | .getAsOpaquePtr()); |
| 5940 | break; |
| 5941 | |
| 5942 | case clang::Type::Paren: |
| 5943 | count = GetNumVirtualBaseClasses( |
| 5944 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 5945 | break; |
| 5946 | |
| 5947 | default: |
| 5948 | break; |
| 5949 | } |
| 5950 | return count; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5951 | } |
| 5952 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5953 | CompilerType ClangASTContext::GetDirectBaseClassAtIndex( |
| 5954 | lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) { |
| 5955 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5956 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5957 | switch (type_class) { |
| 5958 | case clang::Type::Record: |
| 5959 | if (GetCompleteType(type)) { |
| 5960 | const clang::CXXRecordDecl *cxx_record_decl = |
| 5961 | qual_type->getAsCXXRecordDecl(); |
| 5962 | if (cxx_record_decl) { |
| 5963 | uint32_t curr_idx = 0; |
| 5964 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 5965 | base_class_end; |
| 5966 | for (base_class = cxx_record_decl->bases_begin(), |
| 5967 | base_class_end = cxx_record_decl->bases_end(); |
| 5968 | base_class != base_class_end; ++base_class, ++curr_idx) { |
| 5969 | if (curr_idx == idx) { |
| 5970 | if (bit_offset_ptr) { |
| 5971 | const clang::ASTRecordLayout &record_layout = |
| 5972 | getASTContext()->getASTRecordLayout(cxx_record_decl); |
| 5973 | const clang::CXXRecordDecl *base_class_decl = |
| 5974 | llvm::cast<clang::CXXRecordDecl>( |
| 5975 | base_class->getType() |
| 5976 | ->getAs<clang::RecordType>() |
| 5977 | ->getDecl()); |
| 5978 | if (base_class->isVirtual()) |
| 5979 | *bit_offset_ptr = |
| 5980 | record_layout.getVBaseClassOffset(base_class_decl) |
| 5981 | .getQuantity() * |
| 5982 | 8; |
| 5983 | else |
| 5984 | *bit_offset_ptr = |
| 5985 | record_layout.getBaseClassOffset(base_class_decl) |
| 5986 | .getQuantity() * |
| 5987 | 8; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5988 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5989 | return CompilerType(this, base_class->getType().getAsOpaquePtr()); |
| 5990 | } |
| 5991 | } |
| 5992 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5993 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 5994 | break; |
| 5995 | |
| 5996 | case clang::Type::ObjCObjectPointer: |
| 5997 | return GetPointeeType(type).GetDirectBaseClassAtIndex(idx, bit_offset_ptr); |
| 5998 | |
| 5999 | case clang::Type::ObjCObject: |
| 6000 | if (idx == 0 && GetCompleteType(type)) { |
| 6001 | const clang::ObjCObjectType *objc_class_type = |
| 6002 | qual_type->getAsObjCQualifiedInterfaceType(); |
| 6003 | if (objc_class_type) { |
| 6004 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6005 | objc_class_type->getInterface(); |
| 6006 | |
| 6007 | if (class_interface_decl) { |
| 6008 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 6009 | class_interface_decl->getSuperClass(); |
| 6010 | if (superclass_interface_decl) { |
| 6011 | if (bit_offset_ptr) |
| 6012 | *bit_offset_ptr = 0; |
| 6013 | return CompilerType(getASTContext(), |
| 6014 | getASTContext()->getObjCInterfaceType( |
| 6015 | superclass_interface_decl)); |
| 6016 | } |
| 6017 | } |
| 6018 | } |
| 6019 | } |
| 6020 | break; |
| 6021 | case clang::Type::ObjCInterface: |
| 6022 | if (idx == 0 && GetCompleteType(type)) { |
| 6023 | const clang::ObjCObjectType *objc_interface_type = |
| 6024 | qual_type->getAs<clang::ObjCInterfaceType>(); |
| 6025 | if (objc_interface_type) { |
| 6026 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6027 | objc_interface_type->getInterface(); |
| 6028 | |
| 6029 | if (class_interface_decl) { |
| 6030 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 6031 | class_interface_decl->getSuperClass(); |
| 6032 | if (superclass_interface_decl) { |
| 6033 | if (bit_offset_ptr) |
| 6034 | *bit_offset_ptr = 0; |
| 6035 | return CompilerType(getASTContext(), |
| 6036 | getASTContext()->getObjCInterfaceType( |
| 6037 | superclass_interface_decl)); |
| 6038 | } |
| 6039 | } |
| 6040 | } |
| 6041 | } |
| 6042 | break; |
| 6043 | |
| 6044 | case clang::Type::Typedef: |
| 6045 | return GetDirectBaseClassAtIndex(llvm::cast<clang::TypedefType>(qual_type) |
| 6046 | ->getDecl() |
| 6047 | ->getUnderlyingType() |
| 6048 | .getAsOpaquePtr(), |
| 6049 | idx, bit_offset_ptr); |
| 6050 | |
| 6051 | case clang::Type::Auto: |
| 6052 | return GetDirectBaseClassAtIndex(llvm::cast<clang::AutoType>(qual_type) |
| 6053 | ->getDeducedType() |
| 6054 | .getAsOpaquePtr(), |
| 6055 | idx, bit_offset_ptr); |
| 6056 | |
| 6057 | case clang::Type::Elaborated: |
| 6058 | return GetDirectBaseClassAtIndex( |
| 6059 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 6060 | ->getNamedType() |
| 6061 | .getAsOpaquePtr(), |
| 6062 | idx, bit_offset_ptr); |
| 6063 | |
| 6064 | case clang::Type::Paren: |
| 6065 | return GetDirectBaseClassAtIndex( |
| 6066 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 6067 | idx, bit_offset_ptr); |
| 6068 | |
| 6069 | default: |
| 6070 | break; |
| 6071 | } |
| 6072 | return CompilerType(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6073 | } |
| 6074 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6075 | CompilerType ClangASTContext::GetVirtualBaseClassAtIndex( |
| 6076 | lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) { |
| 6077 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6078 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6079 | switch (type_class) { |
| 6080 | case clang::Type::Record: |
| 6081 | if (GetCompleteType(type)) { |
| 6082 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6083 | qual_type->getAsCXXRecordDecl(); |
| 6084 | if (cxx_record_decl) { |
| 6085 | uint32_t curr_idx = 0; |
| 6086 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 6087 | base_class_end; |
| 6088 | for (base_class = cxx_record_decl->vbases_begin(), |
| 6089 | base_class_end = cxx_record_decl->vbases_end(); |
| 6090 | base_class != base_class_end; ++base_class, ++curr_idx) { |
| 6091 | if (curr_idx == idx) { |
| 6092 | if (bit_offset_ptr) { |
| 6093 | const clang::ASTRecordLayout &record_layout = |
| 6094 | getASTContext()->getASTRecordLayout(cxx_record_decl); |
| 6095 | const clang::CXXRecordDecl *base_class_decl = |
| 6096 | llvm::cast<clang::CXXRecordDecl>( |
| 6097 | base_class->getType() |
| 6098 | ->getAs<clang::RecordType>() |
| 6099 | ->getDecl()); |
| 6100 | *bit_offset_ptr = |
| 6101 | record_layout.getVBaseClassOffset(base_class_decl) |
| 6102 | .getQuantity() * |
| 6103 | 8; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6104 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6105 | return CompilerType(this, base_class->getType().getAsOpaquePtr()); |
| 6106 | } |
| 6107 | } |
| 6108 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6109 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6110 | break; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6112 | case clang::Type::Typedef: |
| 6113 | return GetVirtualBaseClassAtIndex(llvm::cast<clang::TypedefType>(qual_type) |
| 6114 | ->getDecl() |
| 6115 | ->getUnderlyingType() |
| 6116 | .getAsOpaquePtr(), |
| 6117 | idx, bit_offset_ptr); |
| 6118 | |
| 6119 | case clang::Type::Auto: |
| 6120 | return GetVirtualBaseClassAtIndex(llvm::cast<clang::AutoType>(qual_type) |
| 6121 | ->getDeducedType() |
| 6122 | .getAsOpaquePtr(), |
| 6123 | idx, bit_offset_ptr); |
| 6124 | |
| 6125 | case clang::Type::Elaborated: |
| 6126 | return GetVirtualBaseClassAtIndex( |
| 6127 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 6128 | ->getNamedType() |
| 6129 | .getAsOpaquePtr(), |
| 6130 | idx, bit_offset_ptr); |
| 6131 | |
| 6132 | case clang::Type::Paren: |
| 6133 | return GetVirtualBaseClassAtIndex( |
| 6134 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 6135 | idx, bit_offset_ptr); |
| 6136 | |
| 6137 | default: |
| 6138 | break; |
| 6139 | } |
| 6140 | return CompilerType(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 6141 | } |
| 6142 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6143 | // If a pointer to a pointee type (the clang_type arg) says that it has no |
| 6144 | // children, then we either need to trust it, or override it and return a |
| 6145 | // different result. For example, an "int *" has one child that is an integer, |
| 6146 | // but a function pointer doesn't have any children. Likewise if a Record type |
| 6147 | // claims it has no children, then there really is nothing to show. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6148 | uint32_t ClangASTContext::GetNumPointeeChildren(clang::QualType type) { |
| 6149 | if (type.isNull()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6150 | return 0; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6151 | |
| 6152 | clang::QualType qual_type(type.getCanonicalType()); |
| 6153 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6154 | switch (type_class) { |
| 6155 | case clang::Type::Builtin: |
| 6156 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) { |
| 6157 | case clang::BuiltinType::UnknownAny: |
| 6158 | case clang::BuiltinType::Void: |
| 6159 | case clang::BuiltinType::NullPtr: |
| 6160 | case clang::BuiltinType::OCLEvent: |
| 6161 | case clang::BuiltinType::OCLImage1dRO: |
| 6162 | case clang::BuiltinType::OCLImage1dWO: |
| 6163 | case clang::BuiltinType::OCLImage1dRW: |
| 6164 | case clang::BuiltinType::OCLImage1dArrayRO: |
| 6165 | case clang::BuiltinType::OCLImage1dArrayWO: |
| 6166 | case clang::BuiltinType::OCLImage1dArrayRW: |
| 6167 | case clang::BuiltinType::OCLImage1dBufferRO: |
| 6168 | case clang::BuiltinType::OCLImage1dBufferWO: |
| 6169 | case clang::BuiltinType::OCLImage1dBufferRW: |
| 6170 | case clang::BuiltinType::OCLImage2dRO: |
| 6171 | case clang::BuiltinType::OCLImage2dWO: |
| 6172 | case clang::BuiltinType::OCLImage2dRW: |
| 6173 | case clang::BuiltinType::OCLImage2dArrayRO: |
| 6174 | case clang::BuiltinType::OCLImage2dArrayWO: |
| 6175 | case clang::BuiltinType::OCLImage2dArrayRW: |
| 6176 | case clang::BuiltinType::OCLImage3dRO: |
| 6177 | case clang::BuiltinType::OCLImage3dWO: |
| 6178 | case clang::BuiltinType::OCLImage3dRW: |
| 6179 | case clang::BuiltinType::OCLSampler: |
| 6180 | return 0; |
| 6181 | case clang::BuiltinType::Bool: |
| 6182 | case clang::BuiltinType::Char_U: |
| 6183 | case clang::BuiltinType::UChar: |
| 6184 | case clang::BuiltinType::WChar_U: |
| 6185 | case clang::BuiltinType::Char16: |
| 6186 | case clang::BuiltinType::Char32: |
| 6187 | case clang::BuiltinType::UShort: |
| 6188 | case clang::BuiltinType::UInt: |
| 6189 | case clang::BuiltinType::ULong: |
| 6190 | case clang::BuiltinType::ULongLong: |
| 6191 | case clang::BuiltinType::UInt128: |
| 6192 | case clang::BuiltinType::Char_S: |
| 6193 | case clang::BuiltinType::SChar: |
| 6194 | case clang::BuiltinType::WChar_S: |
| 6195 | case clang::BuiltinType::Short: |
| 6196 | case clang::BuiltinType::Int: |
| 6197 | case clang::BuiltinType::Long: |
| 6198 | case clang::BuiltinType::LongLong: |
| 6199 | case clang::BuiltinType::Int128: |
| 6200 | case clang::BuiltinType::Float: |
| 6201 | case clang::BuiltinType::Double: |
| 6202 | case clang::BuiltinType::LongDouble: |
| 6203 | case clang::BuiltinType::Dependent: |
| 6204 | case clang::BuiltinType::Overload: |
| 6205 | case clang::BuiltinType::ObjCId: |
| 6206 | case clang::BuiltinType::ObjCClass: |
| 6207 | case clang::BuiltinType::ObjCSel: |
| 6208 | case clang::BuiltinType::BoundMember: |
| 6209 | case clang::BuiltinType::Half: |
| 6210 | case clang::BuiltinType::ARCUnbridgedCast: |
| 6211 | case clang::BuiltinType::PseudoObject: |
| 6212 | case clang::BuiltinType::BuiltinFn: |
| 6213 | case clang::BuiltinType::OMPArraySection: |
| 6214 | return 1; |
| 6215 | default: |
| 6216 | return 0; |
| 6217 | } |
| 6218 | break; |
| 6219 | |
| 6220 | case clang::Type::Complex: |
| 6221 | return 1; |
| 6222 | case clang::Type::Pointer: |
| 6223 | return 1; |
| 6224 | case clang::Type::BlockPointer: |
| 6225 | return 0; // If block pointers don't have debug info, then no children for |
| 6226 | // them |
| 6227 | case clang::Type::LValueReference: |
| 6228 | return 1; |
| 6229 | case clang::Type::RValueReference: |
| 6230 | return 1; |
| 6231 | case clang::Type::MemberPointer: |
| 6232 | return 0; |
| 6233 | case clang::Type::ConstantArray: |
| 6234 | return 0; |
| 6235 | case clang::Type::IncompleteArray: |
| 6236 | return 0; |
| 6237 | case clang::Type::VariableArray: |
| 6238 | return 0; |
| 6239 | case clang::Type::DependentSizedArray: |
| 6240 | return 0; |
| 6241 | case clang::Type::DependentSizedExtVector: |
| 6242 | return 0; |
| 6243 | case clang::Type::Vector: |
| 6244 | return 0; |
| 6245 | case clang::Type::ExtVector: |
| 6246 | return 0; |
| 6247 | case clang::Type::FunctionProto: |
| 6248 | return 0; // When we function pointers, they have no children... |
| 6249 | case clang::Type::FunctionNoProto: |
| 6250 | return 0; // When we function pointers, they have no children... |
| 6251 | case clang::Type::UnresolvedUsing: |
| 6252 | return 0; |
| 6253 | case clang::Type::Paren: |
| 6254 | return GetNumPointeeChildren( |
| 6255 | llvm::cast<clang::ParenType>(qual_type)->desugar()); |
| 6256 | case clang::Type::Typedef: |
| 6257 | return GetNumPointeeChildren(llvm::cast<clang::TypedefType>(qual_type) |
| 6258 | ->getDecl() |
| 6259 | ->getUnderlyingType()); |
| 6260 | case clang::Type::Auto: |
| 6261 | return GetNumPointeeChildren( |
| 6262 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()); |
| 6263 | case clang::Type::Elaborated: |
| 6264 | return GetNumPointeeChildren( |
| 6265 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); |
| 6266 | case clang::Type::TypeOfExpr: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 6267 | return GetNumPointeeChildren(llvm::cast<clang::TypeOfExprType>(qual_type) |
| 6268 | ->getUnderlyingExpr() |
| 6269 | ->getType()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6270 | case clang::Type::TypeOf: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 6271 | return GetNumPointeeChildren( |
| 6272 | llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6273 | case clang::Type::Decltype: |
Jonas Devlieghere | 65d2d5b | 2018-02-20 10:15:08 +0000 | [diff] [blame] | 6274 | return GetNumPointeeChildren( |
| 6275 | llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6276 | case clang::Type::Record: |
| 6277 | return 0; |
| 6278 | case clang::Type::Enum: |
| 6279 | return 1; |
| 6280 | case clang::Type::TemplateTypeParm: |
| 6281 | return 1; |
| 6282 | case clang::Type::SubstTemplateTypeParm: |
| 6283 | return 1; |
| 6284 | case clang::Type::TemplateSpecialization: |
| 6285 | return 1; |
| 6286 | case clang::Type::InjectedClassName: |
| 6287 | return 0; |
| 6288 | case clang::Type::DependentName: |
| 6289 | return 1; |
| 6290 | case clang::Type::DependentTemplateSpecialization: |
| 6291 | return 1; |
| 6292 | case clang::Type::ObjCObject: |
| 6293 | return 0; |
| 6294 | case clang::Type::ObjCInterface: |
| 6295 | return 0; |
| 6296 | case clang::Type::ObjCObjectPointer: |
| 6297 | return 1; |
| 6298 | default: |
| 6299 | break; |
| 6300 | } |
| 6301 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6302 | } |
| 6303 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6304 | CompilerType ClangASTContext::GetChildCompilerTypeAtIndex( |
| 6305 | lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, |
| 6306 | bool transparent_pointers, bool omit_empty_base_classes, |
| 6307 | bool ignore_array_bounds, std::string &child_name, |
| 6308 | uint32_t &child_byte_size, int32_t &child_byte_offset, |
| 6309 | uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, |
| 6310 | bool &child_is_base_class, bool &child_is_deref_of_parent, |
| 6311 | ValueObject *valobj, uint64_t &language_flags) { |
| 6312 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6313 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6314 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6315 | clang::QualType parent_qual_type(GetCanonicalQualType(type)); |
| 6316 | const clang::Type::TypeClass parent_type_class = |
| 6317 | parent_qual_type->getTypeClass(); |
| 6318 | child_bitfield_bit_size = 0; |
| 6319 | child_bitfield_bit_offset = 0; |
| 6320 | child_is_base_class = false; |
| 6321 | language_flags = 0; |
| 6322 | |
| 6323 | const bool idx_is_valid = idx < GetNumChildren(type, omit_empty_base_classes); |
| 6324 | uint32_t bit_offset; |
| 6325 | switch (parent_type_class) { |
| 6326 | case clang::Type::Builtin: |
| 6327 | if (idx_is_valid) { |
| 6328 | switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) { |
| 6329 | case clang::BuiltinType::ObjCId: |
| 6330 | case clang::BuiltinType::ObjCClass: |
| 6331 | child_name = "isa"; |
| 6332 | child_byte_size = |
| 6333 | getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) / |
| 6334 | CHAR_BIT; |
| 6335 | return CompilerType(getASTContext(), |
| 6336 | getASTContext()->ObjCBuiltinClassTy); |
| 6337 | |
| 6338 | default: |
| 6339 | break; |
| 6340 | } |
| 6341 | } |
| 6342 | break; |
| 6343 | |
| 6344 | case clang::Type::Record: |
| 6345 | if (idx_is_valid && GetCompleteType(type)) { |
| 6346 | const clang::RecordType *record_type = |
| 6347 | llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr()); |
| 6348 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 6349 | assert(record_decl); |
| 6350 | const clang::ASTRecordLayout &record_layout = |
| 6351 | getASTContext()->getASTRecordLayout(record_decl); |
| 6352 | uint32_t child_idx = 0; |
| 6353 | |
| 6354 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6355 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6356 | if (cxx_record_decl) { |
| 6357 | // We might have base classes to print out first |
| 6358 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 6359 | base_class_end; |
| 6360 | for (base_class = cxx_record_decl->bases_begin(), |
| 6361 | base_class_end = cxx_record_decl->bases_end(); |
| 6362 | base_class != base_class_end; ++base_class) { |
| 6363 | const clang::CXXRecordDecl *base_class_decl = nullptr; |
| 6364 | |
| 6365 | // Skip empty base classes |
| 6366 | if (omit_empty_base_classes) { |
| 6367 | base_class_decl = llvm::cast<clang::CXXRecordDecl>( |
| 6368 | base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 6369 | if (ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 6370 | continue; |
| 6371 | } |
| 6372 | |
| 6373 | if (idx == child_idx) { |
| 6374 | if (base_class_decl == nullptr) |
| 6375 | base_class_decl = llvm::cast<clang::CXXRecordDecl>( |
| 6376 | base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 6377 | |
| 6378 | if (base_class->isVirtual()) { |
| 6379 | bool handled = false; |
| 6380 | if (valobj) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 6381 | Status err; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6382 | AddressType addr_type = eAddressTypeInvalid; |
| 6383 | lldb::addr_t vtable_ptr_addr = |
| 6384 | valobj->GetCPPVTableAddress(addr_type); |
| 6385 | |
| 6386 | if (vtable_ptr_addr != LLDB_INVALID_ADDRESS && |
| 6387 | addr_type == eAddressTypeLoad) { |
| 6388 | |
| 6389 | ExecutionContext exe_ctx(valobj->GetExecutionContextRef()); |
| 6390 | Process *process = exe_ctx.GetProcessPtr(); |
| 6391 | if (process) { |
| 6392 | clang::VTableContextBase *vtable_ctx = |
| 6393 | getASTContext()->getVTableContext(); |
| 6394 | if (vtable_ctx) { |
| 6395 | if (vtable_ctx->isMicrosoft()) { |
| 6396 | clang::MicrosoftVTableContext *msoft_vtable_ctx = |
| 6397 | static_cast<clang::MicrosoftVTableContext *>( |
| 6398 | vtable_ctx); |
| 6399 | |
| 6400 | if (vtable_ptr_addr) { |
| 6401 | const lldb::addr_t vbtable_ptr_addr = |
| 6402 | vtable_ptr_addr + |
| 6403 | record_layout.getVBPtrOffset().getQuantity(); |
| 6404 | |
| 6405 | const lldb::addr_t vbtable_ptr = |
| 6406 | process->ReadPointerFromMemory(vbtable_ptr_addr, |
| 6407 | err); |
| 6408 | if (vbtable_ptr != LLDB_INVALID_ADDRESS) { |
| 6409 | // Get the index into the virtual base table. The |
| 6410 | // index is the index in uint32_t from vbtable_ptr |
| 6411 | const unsigned vbtable_index = |
| 6412 | msoft_vtable_ctx->getVBTableIndex( |
| 6413 | cxx_record_decl, base_class_decl); |
| 6414 | const lldb::addr_t base_offset_addr = |
| 6415 | vbtable_ptr + vbtable_index * 4; |
| 6416 | const uint32_t base_offset = |
| 6417 | process->ReadUnsignedIntegerFromMemory( |
| 6418 | base_offset_addr, 4, UINT32_MAX, err); |
| 6419 | if (base_offset != UINT32_MAX) { |
| 6420 | handled = true; |
| 6421 | bit_offset = base_offset * 8; |
| 6422 | } |
| 6423 | } |
| 6424 | } |
| 6425 | } else { |
| 6426 | clang::ItaniumVTableContext *itanium_vtable_ctx = |
| 6427 | static_cast<clang::ItaniumVTableContext *>( |
| 6428 | vtable_ctx); |
| 6429 | if (vtable_ptr_addr) { |
| 6430 | const lldb::addr_t vtable_ptr = |
| 6431 | process->ReadPointerFromMemory(vtable_ptr_addr, |
| 6432 | err); |
| 6433 | if (vtable_ptr != LLDB_INVALID_ADDRESS) { |
| 6434 | clang::CharUnits base_offset_offset = |
| 6435 | itanium_vtable_ctx->getVirtualBaseOffsetOffset( |
| 6436 | cxx_record_decl, base_class_decl); |
| 6437 | const lldb::addr_t base_offset_addr = |
| 6438 | vtable_ptr + base_offset_offset.getQuantity(); |
| 6439 | const uint32_t base_offset_size = |
| 6440 | process->GetAddressByteSize(); |
| 6441 | const uint64_t base_offset = |
| 6442 | process->ReadUnsignedIntegerFromMemory( |
| 6443 | base_offset_addr, base_offset_size, |
| 6444 | UINT32_MAX, err); |
| 6445 | if (base_offset < UINT32_MAX) { |
| 6446 | handled = true; |
| 6447 | bit_offset = base_offset * 8; |
| 6448 | } |
| 6449 | } |
| 6450 | } |
| 6451 | } |
| 6452 | } |
| 6453 | } |
| 6454 | } |
| 6455 | } |
| 6456 | if (!handled) |
| 6457 | bit_offset = record_layout.getVBaseClassOffset(base_class_decl) |
| 6458 | .getQuantity() * |
| 6459 | 8; |
| 6460 | } else |
| 6461 | bit_offset = record_layout.getBaseClassOffset(base_class_decl) |
| 6462 | .getQuantity() * |
| 6463 | 8; |
| 6464 | |
| 6465 | // Base classes should be a multiple of 8 bits in size |
| 6466 | child_byte_offset = bit_offset / 8; |
| 6467 | CompilerType base_class_clang_type(getASTContext(), |
| 6468 | base_class->getType()); |
| 6469 | child_name = base_class_clang_type.GetTypeName().AsCString(""); |
| 6470 | uint64_t base_class_clang_type_bit_size = |
| 6471 | base_class_clang_type.GetBitSize( |
| 6472 | exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6473 | |
| 6474 | // Base classes bit sizes should be a multiple of 8 bits in size |
| 6475 | assert(base_class_clang_type_bit_size % 8 == 0); |
| 6476 | child_byte_size = base_class_clang_type_bit_size / 8; |
| 6477 | child_is_base_class = true; |
| 6478 | return base_class_clang_type; |
| 6479 | } |
| 6480 | // We don't increment the child index in the for loop since we might |
| 6481 | // be skipping empty base classes |
| 6482 | ++child_idx; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6483 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6484 | } |
| 6485 | // Make sure index is in range... |
| 6486 | uint32_t field_idx = 0; |
| 6487 | clang::RecordDecl::field_iterator field, field_end; |
| 6488 | for (field = record_decl->field_begin(), |
| 6489 | field_end = record_decl->field_end(); |
| 6490 | field != field_end; ++field, ++field_idx, ++child_idx) { |
| 6491 | if (idx == child_idx) { |
| 6492 | // Print the member type if requested |
| 6493 | // Print the member name and equal sign |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 6494 | child_name.assign(field->getNameAsString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6495 | |
| 6496 | // Figure out the type byte size (field_type_info.first) and |
| 6497 | // alignment (field_type_info.second) from the AST context. |
| 6498 | CompilerType field_clang_type(getASTContext(), field->getType()); |
| 6499 | assert(field_idx < record_layout.getFieldCount()); |
| 6500 | child_byte_size = field_clang_type.GetByteSize( |
| 6501 | exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6502 | const uint32_t child_bit_size = child_byte_size * 8; |
| 6503 | |
| 6504 | // Figure out the field offset within the current struct/union/class |
| 6505 | // type |
| 6506 | bit_offset = record_layout.getFieldOffset(field_idx); |
| 6507 | if (ClangASTContext::FieldIsBitfield(getASTContext(), *field, |
| 6508 | child_bitfield_bit_size)) { |
| 6509 | child_bitfield_bit_offset = bit_offset % child_bit_size; |
| 6510 | const uint32_t child_bit_offset = |
| 6511 | bit_offset - child_bitfield_bit_offset; |
| 6512 | child_byte_offset = child_bit_offset / 8; |
| 6513 | } else { |
| 6514 | child_byte_offset = bit_offset / 8; |
| 6515 | } |
| 6516 | |
| 6517 | return field_clang_type; |
| 6518 | } |
| 6519 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6520 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6521 | break; |
| 6522 | |
| 6523 | case clang::Type::ObjCObject: |
| 6524 | case clang::Type::ObjCInterface: |
| 6525 | if (idx_is_valid && GetCompleteType(type)) { |
| 6526 | const clang::ObjCObjectType *objc_class_type = |
| 6527 | llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr()); |
| 6528 | assert(objc_class_type); |
| 6529 | if (objc_class_type) { |
| 6530 | uint32_t child_idx = 0; |
| 6531 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 6532 | objc_class_type->getInterface(); |
| 6533 | |
| 6534 | if (class_interface_decl) { |
| 6535 | |
| 6536 | const clang::ASTRecordLayout &interface_layout = |
| 6537 | getASTContext()->getASTObjCInterfaceLayout(class_interface_decl); |
| 6538 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 6539 | class_interface_decl->getSuperClass(); |
| 6540 | if (superclass_interface_decl) { |
| 6541 | if (omit_empty_base_classes) { |
| 6542 | CompilerType base_class_clang_type( |
| 6543 | getASTContext(), getASTContext()->getObjCInterfaceType( |
| 6544 | superclass_interface_decl)); |
| 6545 | if (base_class_clang_type.GetNumChildren( |
| 6546 | omit_empty_base_classes) > 0) { |
| 6547 | if (idx == 0) { |
| 6548 | clang::QualType ivar_qual_type( |
| 6549 | getASTContext()->getObjCInterfaceType( |
| 6550 | superclass_interface_decl)); |
| 6551 | |
| 6552 | child_name.assign( |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 6553 | superclass_interface_decl->getNameAsString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6554 | |
| 6555 | clang::TypeInfo ivar_type_info = |
| 6556 | getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 6557 | |
| 6558 | child_byte_size = ivar_type_info.Width / 8; |
| 6559 | child_byte_offset = 0; |
| 6560 | child_is_base_class = true; |
| 6561 | |
| 6562 | return CompilerType(getASTContext(), ivar_qual_type); |
| 6563 | } |
| 6564 | |
| 6565 | ++child_idx; |
| 6566 | } |
| 6567 | } else |
| 6568 | ++child_idx; |
| 6569 | } |
| 6570 | |
| 6571 | const uint32_t superclass_idx = child_idx; |
| 6572 | |
| 6573 | if (idx < (child_idx + class_interface_decl->ivar_size())) { |
| 6574 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, |
| 6575 | ivar_end = class_interface_decl->ivar_end(); |
| 6576 | |
| 6577 | for (ivar_pos = class_interface_decl->ivar_begin(); |
| 6578 | ivar_pos != ivar_end; ++ivar_pos) { |
| 6579 | if (child_idx == idx) { |
| 6580 | clang::ObjCIvarDecl *ivar_decl = *ivar_pos; |
| 6581 | |
| 6582 | clang::QualType ivar_qual_type(ivar_decl->getType()); |
| 6583 | |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 6584 | child_name.assign(ivar_decl->getNameAsString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6585 | |
| 6586 | clang::TypeInfo ivar_type_info = |
| 6587 | getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 6588 | |
| 6589 | child_byte_size = ivar_type_info.Width / 8; |
| 6590 | |
| 6591 | // Figure out the field offset within the current |
| 6592 | // struct/union/class type |
| 6593 | // For ObjC objects, we can't trust the bit offset we get from |
| 6594 | // the Clang AST, since |
| 6595 | // that doesn't account for the space taken up by unbacked |
| 6596 | // properties, or from |
| 6597 | // the changing size of base classes that are newer than this |
| 6598 | // class. |
| 6599 | // So if we have a process around that we can ask about this |
| 6600 | // object, do so. |
| 6601 | child_byte_offset = LLDB_INVALID_IVAR_OFFSET; |
| 6602 | Process *process = nullptr; |
| 6603 | if (exe_ctx) |
| 6604 | process = exe_ctx->GetProcessPtr(); |
| 6605 | if (process) { |
| 6606 | ObjCLanguageRuntime *objc_runtime = |
| 6607 | process->GetObjCLanguageRuntime(); |
| 6608 | if (objc_runtime != nullptr) { |
| 6609 | CompilerType parent_ast_type(getASTContext(), |
| 6610 | parent_qual_type); |
| 6611 | child_byte_offset = objc_runtime->GetByteOffsetForIvar( |
| 6612 | parent_ast_type, ivar_decl->getNameAsString().c_str()); |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | // Setting this to UINT32_MAX to make sure we don't compute it |
| 6617 | // twice... |
| 6618 | bit_offset = UINT32_MAX; |
| 6619 | |
| 6620 | if (child_byte_offset == |
| 6621 | static_cast<int32_t>(LLDB_INVALID_IVAR_OFFSET)) { |
| 6622 | bit_offset = interface_layout.getFieldOffset(child_idx - |
| 6623 | superclass_idx); |
| 6624 | child_byte_offset = bit_offset / 8; |
| 6625 | } |
| 6626 | |
| 6627 | // Note, the ObjC Ivar Byte offset is just that, it doesn't |
| 6628 | // account for the bit offset |
| 6629 | // of a bitfield within its containing object. So regardless of |
| 6630 | // where we get the byte |
| 6631 | // offset from, we still need to get the bit offset for |
| 6632 | // bitfields from the layout. |
| 6633 | |
| 6634 | if (ClangASTContext::FieldIsBitfield(getASTContext(), ivar_decl, |
| 6635 | child_bitfield_bit_size)) { |
| 6636 | if (bit_offset == UINT32_MAX) |
| 6637 | bit_offset = interface_layout.getFieldOffset( |
| 6638 | child_idx - superclass_idx); |
| 6639 | |
| 6640 | child_bitfield_bit_offset = bit_offset % 8; |
| 6641 | } |
| 6642 | return CompilerType(getASTContext(), ivar_qual_type); |
| 6643 | } |
| 6644 | ++child_idx; |
| 6645 | } |
| 6646 | } |
| 6647 | } |
| 6648 | } |
| 6649 | } |
| 6650 | break; |
| 6651 | |
| 6652 | case clang::Type::ObjCObjectPointer: |
| 6653 | if (idx_is_valid) { |
| 6654 | CompilerType pointee_clang_type(GetPointeeType(type)); |
| 6655 | |
| 6656 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) { |
| 6657 | child_is_deref_of_parent = false; |
| 6658 | bool tmp_child_is_deref_of_parent = false; |
| 6659 | return pointee_clang_type.GetChildCompilerTypeAtIndex( |
| 6660 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6661 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6662 | child_bitfield_bit_size, child_bitfield_bit_offset, |
| 6663 | child_is_base_class, tmp_child_is_deref_of_parent, valobj, |
| 6664 | language_flags); |
| 6665 | } else { |
| 6666 | child_is_deref_of_parent = true; |
| 6667 | const char *parent_name = |
| 6668 | valobj ? valobj->GetName().GetCString() : NULL; |
| 6669 | if (parent_name) { |
| 6670 | child_name.assign(1, '*'); |
| 6671 | child_name += parent_name; |
| 6672 | } |
| 6673 | |
| 6674 | // We have a pointer to an simple type |
| 6675 | if (idx == 0 && pointee_clang_type.GetCompleteType()) { |
| 6676 | child_byte_size = pointee_clang_type.GetByteSize( |
| 6677 | exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6678 | child_byte_offset = 0; |
| 6679 | return pointee_clang_type; |
| 6680 | } |
| 6681 | } |
| 6682 | } |
| 6683 | break; |
| 6684 | |
| 6685 | case clang::Type::Vector: |
| 6686 | case clang::Type::ExtVector: |
| 6687 | if (idx_is_valid) { |
| 6688 | const clang::VectorType *array = |
| 6689 | llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr()); |
| 6690 | if (array) { |
| 6691 | CompilerType element_type(getASTContext(), array->getElementType()); |
| 6692 | if (element_type.GetCompleteType()) { |
| 6693 | char element_name[64]; |
| 6694 | ::snprintf(element_name, sizeof(element_name), "[%" PRIu64 "]", |
| 6695 | static_cast<uint64_t>(idx)); |
| 6696 | child_name.assign(element_name); |
| 6697 | child_byte_size = element_type.GetByteSize( |
| 6698 | exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6699 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 6700 | return element_type; |
| 6701 | } |
| 6702 | } |
| 6703 | } |
| 6704 | break; |
| 6705 | |
| 6706 | case clang::Type::ConstantArray: |
| 6707 | case clang::Type::IncompleteArray: |
| 6708 | if (ignore_array_bounds || idx_is_valid) { |
| 6709 | const clang::ArrayType *array = GetQualType(type)->getAsArrayTypeUnsafe(); |
| 6710 | if (array) { |
| 6711 | CompilerType element_type(getASTContext(), array->getElementType()); |
| 6712 | if (element_type.GetCompleteType()) { |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 6713 | child_name = llvm::formatv("[{0}]", idx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6714 | child_byte_size = element_type.GetByteSize( |
| 6715 | exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6716 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 6717 | return element_type; |
| 6718 | } |
| 6719 | } |
| 6720 | } |
| 6721 | break; |
| 6722 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6723 | case clang::Type::Pointer: { |
| 6724 | CompilerType pointee_clang_type(GetPointeeType(type)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6725 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6726 | // Don't dereference "void *" pointers |
| 6727 | if (pointee_clang_type.IsVoidType()) |
| 6728 | return CompilerType(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6729 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6730 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) { |
| 6731 | child_is_deref_of_parent = false; |
| 6732 | bool tmp_child_is_deref_of_parent = false; |
| 6733 | return pointee_clang_type.GetChildCompilerTypeAtIndex( |
| 6734 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6735 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6736 | child_bitfield_bit_size, child_bitfield_bit_offset, |
| 6737 | child_is_base_class, tmp_child_is_deref_of_parent, valobj, |
| 6738 | language_flags); |
| 6739 | } else { |
| 6740 | child_is_deref_of_parent = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6741 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6742 | const char *parent_name = |
| 6743 | valobj ? valobj->GetName().GetCString() : NULL; |
| 6744 | if (parent_name) { |
| 6745 | child_name.assign(1, '*'); |
| 6746 | child_name += parent_name; |
| 6747 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6748 | |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6749 | // We have a pointer to an simple type |
| 6750 | if (idx == 0) { |
| 6751 | child_byte_size = pointee_clang_type.GetByteSize( |
| 6752 | exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6753 | child_byte_offset = 0; |
| 6754 | return pointee_clang_type; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6755 | } |
| 6756 | } |
| 6757 | break; |
Tamas Berghammer | 1c62e03 | 2017-01-07 16:39:07 +0000 | [diff] [blame] | 6758 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6759 | |
| 6760 | case clang::Type::LValueReference: |
| 6761 | case clang::Type::RValueReference: |
| 6762 | if (idx_is_valid) { |
| 6763 | const clang::ReferenceType *reference_type = |
| 6764 | llvm::cast<clang::ReferenceType>(parent_qual_type.getTypePtr()); |
| 6765 | CompilerType pointee_clang_type(getASTContext(), |
| 6766 | reference_type->getPointeeType()); |
| 6767 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) { |
| 6768 | child_is_deref_of_parent = false; |
| 6769 | bool tmp_child_is_deref_of_parent = false; |
| 6770 | return pointee_clang_type.GetChildCompilerTypeAtIndex( |
| 6771 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6772 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6773 | child_bitfield_bit_size, child_bitfield_bit_offset, |
| 6774 | child_is_base_class, tmp_child_is_deref_of_parent, valobj, |
| 6775 | language_flags); |
| 6776 | } else { |
| 6777 | const char *parent_name = |
| 6778 | valobj ? valobj->GetName().GetCString() : NULL; |
| 6779 | if (parent_name) { |
| 6780 | child_name.assign(1, '&'); |
| 6781 | child_name += parent_name; |
| 6782 | } |
| 6783 | |
| 6784 | // We have a pointer to an simple type |
| 6785 | if (idx == 0) { |
| 6786 | child_byte_size = pointee_clang_type.GetByteSize( |
| 6787 | exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6788 | child_byte_offset = 0; |
| 6789 | return pointee_clang_type; |
| 6790 | } |
| 6791 | } |
| 6792 | } |
| 6793 | break; |
| 6794 | |
| 6795 | case clang::Type::Typedef: { |
| 6796 | CompilerType typedefed_clang_type( |
| 6797 | getASTContext(), llvm::cast<clang::TypedefType>(parent_qual_type) |
| 6798 | ->getDecl() |
| 6799 | ->getUnderlyingType()); |
| 6800 | return typedefed_clang_type.GetChildCompilerTypeAtIndex( |
| 6801 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6802 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6803 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 6804 | child_is_deref_of_parent, valobj, language_flags); |
| 6805 | } break; |
| 6806 | |
| 6807 | case clang::Type::Auto: { |
| 6808 | CompilerType elaborated_clang_type( |
| 6809 | getASTContext(), |
| 6810 | llvm::cast<clang::AutoType>(parent_qual_type)->getDeducedType()); |
| 6811 | return elaborated_clang_type.GetChildCompilerTypeAtIndex( |
| 6812 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6813 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6814 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 6815 | child_is_deref_of_parent, valobj, language_flags); |
| 6816 | } |
| 6817 | |
| 6818 | case clang::Type::Elaborated: { |
| 6819 | CompilerType elaborated_clang_type( |
| 6820 | getASTContext(), |
| 6821 | llvm::cast<clang::ElaboratedType>(parent_qual_type)->getNamedType()); |
| 6822 | return elaborated_clang_type.GetChildCompilerTypeAtIndex( |
| 6823 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6824 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6825 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 6826 | child_is_deref_of_parent, valobj, language_flags); |
| 6827 | } |
| 6828 | |
| 6829 | case clang::Type::Paren: { |
| 6830 | CompilerType paren_clang_type( |
| 6831 | getASTContext(), |
| 6832 | llvm::cast<clang::ParenType>(parent_qual_type)->desugar()); |
| 6833 | return paren_clang_type.GetChildCompilerTypeAtIndex( |
| 6834 | exe_ctx, idx, transparent_pointers, omit_empty_base_classes, |
| 6835 | ignore_array_bounds, child_name, child_byte_size, child_byte_offset, |
| 6836 | child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, |
| 6837 | child_is_deref_of_parent, valobj, language_flags); |
| 6838 | } |
| 6839 | |
| 6840 | default: |
| 6841 | break; |
| 6842 | } |
| 6843 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6844 | } |
| 6845 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6846 | static uint32_t GetIndexForRecordBase(const clang::RecordDecl *record_decl, |
| 6847 | const clang::CXXBaseSpecifier *base_spec, |
| 6848 | bool omit_empty_base_classes) { |
| 6849 | uint32_t child_idx = 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6850 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6851 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6852 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6853 | |
| 6854 | // const char *super_name = record_decl->getNameAsCString(); |
| 6855 | // const char *base_name = |
| 6856 | // base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString(); |
| 6857 | // printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name); |
| 6858 | // |
| 6859 | if (cxx_record_decl) { |
| 6860 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 6861 | for (base_class = cxx_record_decl->bases_begin(), |
| 6862 | base_class_end = cxx_record_decl->bases_end(); |
| 6863 | base_class != base_class_end; ++base_class) { |
| 6864 | if (omit_empty_base_classes) { |
| 6865 | if (BaseSpecifierIsEmpty(base_class)) |
| 6866 | continue; |
| 6867 | } |
| 6868 | |
| 6869 | // printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", |
| 6870 | // super_name, base_name, |
| 6871 | // child_idx, |
| 6872 | // base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString()); |
| 6873 | // |
| 6874 | // |
| 6875 | if (base_class == base_spec) |
| 6876 | return child_idx; |
| 6877 | ++child_idx; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6878 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6879 | } |
| 6880 | |
| 6881 | return UINT32_MAX; |
| 6882 | } |
| 6883 | |
| 6884 | static uint32_t GetIndexForRecordChild(const clang::RecordDecl *record_decl, |
| 6885 | clang::NamedDecl *canonical_decl, |
| 6886 | bool omit_empty_base_classes) { |
| 6887 | uint32_t child_idx = ClangASTContext::GetNumBaseClasses( |
| 6888 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl), |
| 6889 | omit_empty_base_classes); |
| 6890 | |
| 6891 | clang::RecordDecl::field_iterator field, field_end; |
| 6892 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 6893 | field != field_end; ++field, ++child_idx) { |
| 6894 | if (field->getCanonicalDecl() == canonical_decl) |
| 6895 | return child_idx; |
| 6896 | } |
| 6897 | |
| 6898 | return UINT32_MAX; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | // Look for a child member (doesn't include base classes, but it does include |
| 6902 | // their members) in the type hierarchy. Returns an index path into "clang_type" |
| 6903 | // on how to reach the appropriate member. |
| 6904 | // |
| 6905 | // class A |
| 6906 | // { |
| 6907 | // public: |
| 6908 | // int m_a; |
| 6909 | // int m_b; |
| 6910 | // }; |
| 6911 | // |
| 6912 | // class B |
| 6913 | // { |
| 6914 | // }; |
| 6915 | // |
| 6916 | // class C : |
| 6917 | // public B, |
| 6918 | // public A |
| 6919 | // { |
| 6920 | // }; |
| 6921 | // |
| 6922 | // If we have a clang type that describes "class C", and we wanted to looked |
| 6923 | // "m_b" in it: |
| 6924 | // |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6925 | // With omit_empty_base_classes == false we would get an integer array back |
| 6926 | // with: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6927 | // { 1, 1 } |
| 6928 | // The first index 1 is the child index for "class A" within class C |
| 6929 | // The second index 1 is the child index for "m_b" within class A |
| 6930 | // |
| 6931 | // With omit_empty_base_classes == true we would get an integer array back with: |
| 6932 | // { 0, 1 } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6933 | // The first index 0 is the child index for "class A" within class C (since |
| 6934 | // class B doesn't have any members it doesn't count) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6935 | // The second index 1 is the child index for "m_b" within class A |
| 6936 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6937 | size_t ClangASTContext::GetIndexOfChildMemberWithName( |
| 6938 | lldb::opaque_compiler_type_t type, const char *name, |
| 6939 | bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) { |
| 6940 | if (type && name && name[0]) { |
| 6941 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6942 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6943 | switch (type_class) { |
| 6944 | case clang::Type::Record: |
| 6945 | if (GetCompleteType(type)) { |
| 6946 | const clang::RecordType *record_type = |
| 6947 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 6948 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 6949 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6950 | assert(record_decl); |
| 6951 | uint32_t child_idx = 0; |
| 6952 | |
| 6953 | const clang::CXXRecordDecl *cxx_record_decl = |
| 6954 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6955 | |
| 6956 | // Try and find a field that matches NAME |
| 6957 | clang::RecordDecl::field_iterator field, field_end; |
| 6958 | llvm::StringRef name_sref(name); |
| 6959 | for (field = record_decl->field_begin(), |
| 6960 | field_end = record_decl->field_end(); |
| 6961 | field != field_end; ++field, ++child_idx) { |
| 6962 | llvm::StringRef field_name = field->getName(); |
| 6963 | if (field_name.empty()) { |
| 6964 | CompilerType field_type(getASTContext(), field->getType()); |
| 6965 | child_indexes.push_back(child_idx); |
| 6966 | if (field_type.GetIndexOfChildMemberWithName( |
| 6967 | name, omit_empty_base_classes, child_indexes)) |
| 6968 | return child_indexes.size(); |
| 6969 | child_indexes.pop_back(); |
| 6970 | |
| 6971 | } else if (field_name.equals(name_sref)) { |
| 6972 | // We have to add on the number of base classes to this index! |
| 6973 | child_indexes.push_back( |
| 6974 | child_idx + ClangASTContext::GetNumBaseClasses( |
| 6975 | cxx_record_decl, omit_empty_base_classes)); |
| 6976 | return child_indexes.size(); |
| 6977 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6978 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6979 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 6980 | if (cxx_record_decl) { |
| 6981 | const clang::RecordDecl *parent_record_decl = cxx_record_decl; |
| 6982 | |
| 6983 | // printf ("parent = %s\n", parent_record_decl->getNameAsCString()); |
| 6984 | |
| 6985 | // const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl(); |
| 6986 | // Didn't find things easily, lets let clang do its thang... |
| 6987 | clang::IdentifierInfo &ident_ref = |
| 6988 | getASTContext()->Idents.get(name_sref); |
| 6989 | clang::DeclarationName decl_name(&ident_ref); |
| 6990 | |
| 6991 | clang::CXXBasePaths paths; |
| 6992 | if (cxx_record_decl->lookupInBases( |
| 6993 | [decl_name](const clang::CXXBaseSpecifier *specifier, |
| 6994 | clang::CXXBasePath &path) { |
| 6995 | return clang::CXXRecordDecl::FindOrdinaryMember( |
| 6996 | specifier, path, decl_name); |
| 6997 | }, |
| 6998 | paths)) { |
| 6999 | clang::CXXBasePaths::const_paths_iterator path, |
| 7000 | path_end = paths.end(); |
| 7001 | for (path = paths.begin(); path != path_end; ++path) { |
| 7002 | const size_t num_path_elements = path->size(); |
| 7003 | for (size_t e = 0; e < num_path_elements; ++e) { |
| 7004 | clang::CXXBasePathElement elem = (*path)[e]; |
| 7005 | |
| 7006 | child_idx = GetIndexForRecordBase(parent_record_decl, elem.Base, |
| 7007 | omit_empty_base_classes); |
| 7008 | if (child_idx == UINT32_MAX) { |
| 7009 | child_indexes.clear(); |
| 7010 | return 0; |
| 7011 | } else { |
| 7012 | child_indexes.push_back(child_idx); |
| 7013 | parent_record_decl = llvm::cast<clang::RecordDecl>( |
| 7014 | elem.Base->getType() |
| 7015 | ->getAs<clang::RecordType>() |
| 7016 | ->getDecl()); |
| 7017 | } |
| 7018 | } |
| 7019 | for (clang::NamedDecl *path_decl : path->Decls) { |
| 7020 | child_idx = GetIndexForRecordChild( |
| 7021 | parent_record_decl, path_decl, omit_empty_base_classes); |
| 7022 | if (child_idx == UINT32_MAX) { |
| 7023 | child_indexes.clear(); |
| 7024 | return 0; |
| 7025 | } else { |
| 7026 | child_indexes.push_back(child_idx); |
| 7027 | } |
| 7028 | } |
| 7029 | } |
| 7030 | return child_indexes.size(); |
| 7031 | } |
| 7032 | } |
| 7033 | } |
| 7034 | break; |
| 7035 | |
| 7036 | case clang::Type::ObjCObject: |
| 7037 | case clang::Type::ObjCInterface: |
| 7038 | if (GetCompleteType(type)) { |
| 7039 | llvm::StringRef name_sref(name); |
| 7040 | const clang::ObjCObjectType *objc_class_type = |
| 7041 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 7042 | assert(objc_class_type); |
| 7043 | if (objc_class_type) { |
| 7044 | uint32_t child_idx = 0; |
| 7045 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 7046 | objc_class_type->getInterface(); |
| 7047 | |
| 7048 | if (class_interface_decl) { |
| 7049 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, |
| 7050 | ivar_end = class_interface_decl->ivar_end(); |
| 7051 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 7052 | class_interface_decl->getSuperClass(); |
| 7053 | |
| 7054 | for (ivar_pos = class_interface_decl->ivar_begin(); |
| 7055 | ivar_pos != ivar_end; ++ivar_pos, ++child_idx) { |
| 7056 | const clang::ObjCIvarDecl *ivar_decl = *ivar_pos; |
| 7057 | |
| 7058 | if (ivar_decl->getName().equals(name_sref)) { |
| 7059 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 7060 | (omit_empty_base_classes && |
| 7061 | ObjCDeclHasIVars(superclass_interface_decl, true))) |
| 7062 | ++child_idx; |
| 7063 | |
| 7064 | child_indexes.push_back(child_idx); |
| 7065 | return child_indexes.size(); |
| 7066 | } |
| 7067 | } |
| 7068 | |
| 7069 | if (superclass_interface_decl) { |
| 7070 | // The super class index is always zero for ObjC classes, |
| 7071 | // so we push it onto the child indexes in case we find |
| 7072 | // an ivar in our superclass... |
| 7073 | child_indexes.push_back(0); |
| 7074 | |
| 7075 | CompilerType superclass_clang_type( |
| 7076 | getASTContext(), getASTContext()->getObjCInterfaceType( |
| 7077 | superclass_interface_decl)); |
| 7078 | if (superclass_clang_type.GetIndexOfChildMemberWithName( |
| 7079 | name, omit_empty_base_classes, child_indexes)) { |
| 7080 | // We did find an ivar in a superclass so just |
| 7081 | // return the results! |
| 7082 | return child_indexes.size(); |
| 7083 | } |
| 7084 | |
| 7085 | // We didn't find an ivar matching "name" in our |
| 7086 | // superclass, pop the superclass zero index that |
| 7087 | // we pushed on above. |
| 7088 | child_indexes.pop_back(); |
| 7089 | } |
| 7090 | } |
| 7091 | } |
| 7092 | } |
| 7093 | break; |
| 7094 | |
| 7095 | case clang::Type::ObjCObjectPointer: { |
| 7096 | CompilerType objc_object_clang_type( |
| 7097 | getASTContext(), |
| 7098 | llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()) |
| 7099 | ->getPointeeType()); |
| 7100 | return objc_object_clang_type.GetIndexOfChildMemberWithName( |
| 7101 | name, omit_empty_base_classes, child_indexes); |
| 7102 | } break; |
| 7103 | |
| 7104 | case clang::Type::ConstantArray: { |
| 7105 | // const clang::ConstantArrayType *array = |
| 7106 | // llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 7107 | // const uint64_t element_count = |
| 7108 | // array->getSize().getLimitedValue(); |
| 7109 | // |
| 7110 | // if (idx < element_count) |
| 7111 | // { |
| 7112 | // std::pair<uint64_t, unsigned> field_type_info = |
| 7113 | // ast->getTypeInfo(array->getElementType()); |
| 7114 | // |
| 7115 | // char element_name[32]; |
| 7116 | // ::snprintf (element_name, sizeof (element_name), |
| 7117 | // "%s[%u]", parent_name ? parent_name : "", idx); |
| 7118 | // |
| 7119 | // child_name.assign(element_name); |
| 7120 | // assert(field_type_info.first % 8 == 0); |
| 7121 | // child_byte_size = field_type_info.first / 8; |
| 7122 | // child_byte_offset = idx * child_byte_size; |
| 7123 | // return array->getElementType().getAsOpaquePtr(); |
| 7124 | // } |
| 7125 | } break; |
| 7126 | |
| 7127 | // case clang::Type::MemberPointerType: |
| 7128 | // { |
| 7129 | // MemberPointerType *mem_ptr_type = |
| 7130 | // llvm::cast<MemberPointerType>(qual_type.getTypePtr()); |
| 7131 | // clang::QualType pointee_type = |
| 7132 | // mem_ptr_type->getPointeeType(); |
| 7133 | // |
| 7134 | // if (ClangASTContext::IsAggregateType |
| 7135 | // (pointee_type.getAsOpaquePtr())) |
| 7136 | // { |
| 7137 | // return GetIndexOfChildWithName (ast, |
| 7138 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 7139 | // name); |
| 7140 | // } |
| 7141 | // } |
| 7142 | // break; |
| 7143 | // |
| 7144 | case clang::Type::LValueReference: |
| 7145 | case clang::Type::RValueReference: { |
| 7146 | const clang::ReferenceType *reference_type = |
| 7147 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 7148 | clang::QualType pointee_type(reference_type->getPointeeType()); |
| 7149 | CompilerType pointee_clang_type(getASTContext(), pointee_type); |
| 7150 | |
| 7151 | if (pointee_clang_type.IsAggregateType()) { |
| 7152 | return pointee_clang_type.GetIndexOfChildMemberWithName( |
| 7153 | name, omit_empty_base_classes, child_indexes); |
| 7154 | } |
| 7155 | } break; |
| 7156 | |
| 7157 | case clang::Type::Pointer: { |
| 7158 | CompilerType pointee_clang_type(GetPointeeType(type)); |
| 7159 | |
| 7160 | if (pointee_clang_type.IsAggregateType()) { |
| 7161 | return pointee_clang_type.GetIndexOfChildMemberWithName( |
| 7162 | name, omit_empty_base_classes, child_indexes); |
| 7163 | } |
| 7164 | } break; |
| 7165 | |
| 7166 | case clang::Type::Typedef: |
| 7167 | return CompilerType(getASTContext(), |
| 7168 | llvm::cast<clang::TypedefType>(qual_type) |
| 7169 | ->getDecl() |
| 7170 | ->getUnderlyingType()) |
| 7171 | .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, |
| 7172 | child_indexes); |
| 7173 | |
| 7174 | case clang::Type::Auto: |
| 7175 | return CompilerType( |
| 7176 | getASTContext(), |
| 7177 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 7178 | .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, |
| 7179 | child_indexes); |
| 7180 | |
| 7181 | case clang::Type::Elaborated: |
| 7182 | return CompilerType( |
| 7183 | getASTContext(), |
| 7184 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 7185 | .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, |
| 7186 | child_indexes); |
| 7187 | |
| 7188 | case clang::Type::Paren: |
| 7189 | return CompilerType(getASTContext(), |
| 7190 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 7191 | .GetIndexOfChildMemberWithName(name, omit_empty_base_classes, |
| 7192 | child_indexes); |
| 7193 | |
| 7194 | default: |
| 7195 | break; |
| 7196 | } |
| 7197 | } |
| 7198 | return 0; |
| 7199 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7200 | |
| 7201 | // Get the index of the child of "clang_type" whose name matches. This function |
| 7202 | // doesn't descend into the children, but only looks one level deep and name |
| 7203 | // matches can include base class names. |
| 7204 | |
| 7205 | uint32_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7206 | ClangASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type, |
| 7207 | const char *name, |
| 7208 | bool omit_empty_base_classes) { |
| 7209 | if (type && name && name[0]) { |
| 7210 | clang::QualType qual_type(GetCanonicalQualType(type)); |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 7211 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7212 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7213 | |
| 7214 | switch (type_class) { |
| 7215 | case clang::Type::Record: |
| 7216 | if (GetCompleteType(type)) { |
| 7217 | const clang::RecordType *record_type = |
| 7218 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 7219 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 7220 | |
| 7221 | assert(record_decl); |
| 7222 | uint32_t child_idx = 0; |
| 7223 | |
| 7224 | const clang::CXXRecordDecl *cxx_record_decl = |
| 7225 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 7226 | |
| 7227 | if (cxx_record_decl) { |
| 7228 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 7229 | base_class_end; |
| 7230 | for (base_class = cxx_record_decl->bases_begin(), |
| 7231 | base_class_end = cxx_record_decl->bases_end(); |
| 7232 | base_class != base_class_end; ++base_class) { |
| 7233 | // Skip empty base classes |
| 7234 | clang::CXXRecordDecl *base_class_decl = |
| 7235 | llvm::cast<clang::CXXRecordDecl>( |
| 7236 | base_class->getType() |
| 7237 | ->getAs<clang::RecordType>() |
| 7238 | ->getDecl()); |
| 7239 | if (omit_empty_base_classes && |
| 7240 | ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 7241 | continue; |
| 7242 | |
| 7243 | CompilerType base_class_clang_type(getASTContext(), |
| 7244 | base_class->getType()); |
| 7245 | std::string base_class_type_name( |
| 7246 | base_class_clang_type.GetTypeName().AsCString("")); |
| 7247 | if (base_class_type_name.compare(name) == 0) |
| 7248 | return child_idx; |
| 7249 | ++child_idx; |
| 7250 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7251 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7252 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7253 | // Try and find a field that matches NAME |
| 7254 | clang::RecordDecl::field_iterator field, field_end; |
| 7255 | llvm::StringRef name_sref(name); |
| 7256 | for (field = record_decl->field_begin(), |
| 7257 | field_end = record_decl->field_end(); |
| 7258 | field != field_end; ++field, ++child_idx) { |
| 7259 | if (field->getName().equals(name_sref)) |
| 7260 | return child_idx; |
| 7261 | } |
| 7262 | } |
| 7263 | break; |
| 7264 | |
| 7265 | case clang::Type::ObjCObject: |
| 7266 | case clang::Type::ObjCInterface: |
| 7267 | if (GetCompleteType(type)) { |
| 7268 | llvm::StringRef name_sref(name); |
| 7269 | const clang::ObjCObjectType *objc_class_type = |
| 7270 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 7271 | assert(objc_class_type); |
| 7272 | if (objc_class_type) { |
| 7273 | uint32_t child_idx = 0; |
| 7274 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 7275 | objc_class_type->getInterface(); |
| 7276 | |
| 7277 | if (class_interface_decl) { |
| 7278 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, |
| 7279 | ivar_end = class_interface_decl->ivar_end(); |
| 7280 | clang::ObjCInterfaceDecl *superclass_interface_decl = |
| 7281 | class_interface_decl->getSuperClass(); |
| 7282 | |
| 7283 | for (ivar_pos = class_interface_decl->ivar_begin(); |
| 7284 | ivar_pos != ivar_end; ++ivar_pos, ++child_idx) { |
| 7285 | const clang::ObjCIvarDecl *ivar_decl = *ivar_pos; |
| 7286 | |
| 7287 | if (ivar_decl->getName().equals(name_sref)) { |
| 7288 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 7289 | (omit_empty_base_classes && |
| 7290 | ObjCDeclHasIVars(superclass_interface_decl, true))) |
| 7291 | ++child_idx; |
| 7292 | |
| 7293 | return child_idx; |
| 7294 | } |
| 7295 | } |
| 7296 | |
| 7297 | if (superclass_interface_decl) { |
| 7298 | if (superclass_interface_decl->getName().equals(name_sref)) |
| 7299 | return 0; |
| 7300 | } |
| 7301 | } |
| 7302 | } |
| 7303 | } |
| 7304 | break; |
| 7305 | |
| 7306 | case clang::Type::ObjCObjectPointer: { |
| 7307 | CompilerType pointee_clang_type( |
| 7308 | getASTContext(), |
| 7309 | llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()) |
| 7310 | ->getPointeeType()); |
| 7311 | return pointee_clang_type.GetIndexOfChildWithName( |
| 7312 | name, omit_empty_base_classes); |
| 7313 | } break; |
| 7314 | |
| 7315 | case clang::Type::ConstantArray: { |
| 7316 | // const clang::ConstantArrayType *array = |
| 7317 | // llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 7318 | // const uint64_t element_count = |
| 7319 | // array->getSize().getLimitedValue(); |
| 7320 | // |
| 7321 | // if (idx < element_count) |
| 7322 | // { |
| 7323 | // std::pair<uint64_t, unsigned> field_type_info = |
| 7324 | // ast->getTypeInfo(array->getElementType()); |
| 7325 | // |
| 7326 | // char element_name[32]; |
| 7327 | // ::snprintf (element_name, sizeof (element_name), |
| 7328 | // "%s[%u]", parent_name ? parent_name : "", idx); |
| 7329 | // |
| 7330 | // child_name.assign(element_name); |
| 7331 | // assert(field_type_info.first % 8 == 0); |
| 7332 | // child_byte_size = field_type_info.first / 8; |
| 7333 | // child_byte_offset = idx * child_byte_size; |
| 7334 | // return array->getElementType().getAsOpaquePtr(); |
| 7335 | // } |
| 7336 | } break; |
| 7337 | |
| 7338 | // case clang::Type::MemberPointerType: |
| 7339 | // { |
| 7340 | // MemberPointerType *mem_ptr_type = |
| 7341 | // llvm::cast<MemberPointerType>(qual_type.getTypePtr()); |
| 7342 | // clang::QualType pointee_type = |
| 7343 | // mem_ptr_type->getPointeeType(); |
| 7344 | // |
| 7345 | // if (ClangASTContext::IsAggregateType |
| 7346 | // (pointee_type.getAsOpaquePtr())) |
| 7347 | // { |
| 7348 | // return GetIndexOfChildWithName (ast, |
| 7349 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 7350 | // name); |
| 7351 | // } |
| 7352 | // } |
| 7353 | // break; |
| 7354 | // |
| 7355 | case clang::Type::LValueReference: |
| 7356 | case clang::Type::RValueReference: { |
| 7357 | const clang::ReferenceType *reference_type = |
| 7358 | llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 7359 | CompilerType pointee_type(getASTContext(), |
| 7360 | reference_type->getPointeeType()); |
| 7361 | |
| 7362 | if (pointee_type.IsAggregateType()) { |
| 7363 | return pointee_type.GetIndexOfChildWithName(name, |
| 7364 | omit_empty_base_classes); |
| 7365 | } |
| 7366 | } break; |
| 7367 | |
| 7368 | case clang::Type::Pointer: { |
| 7369 | const clang::PointerType *pointer_type = |
| 7370 | llvm::cast<clang::PointerType>(qual_type.getTypePtr()); |
| 7371 | CompilerType pointee_type(getASTContext(), |
| 7372 | pointer_type->getPointeeType()); |
| 7373 | |
| 7374 | if (pointee_type.IsAggregateType()) { |
| 7375 | return pointee_type.GetIndexOfChildWithName(name, |
| 7376 | omit_empty_base_classes); |
| 7377 | } else { |
| 7378 | // if (parent_name) |
| 7379 | // { |
| 7380 | // child_name.assign(1, '*'); |
| 7381 | // child_name += parent_name; |
| 7382 | // } |
| 7383 | // |
| 7384 | // // We have a pointer to an simple type |
| 7385 | // if (idx == 0) |
| 7386 | // { |
| 7387 | // std::pair<uint64_t, unsigned> clang_type_info |
| 7388 | // = ast->getTypeInfo(pointee_type); |
| 7389 | // assert(clang_type_info.first % 8 == 0); |
| 7390 | // child_byte_size = clang_type_info.first / 8; |
| 7391 | // child_byte_offset = 0; |
| 7392 | // return pointee_type.getAsOpaquePtr(); |
| 7393 | // } |
| 7394 | } |
| 7395 | } break; |
| 7396 | |
| 7397 | case clang::Type::Auto: |
| 7398 | return CompilerType( |
| 7399 | getASTContext(), |
| 7400 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 7401 | .GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 7402 | |
| 7403 | case clang::Type::Elaborated: |
| 7404 | return CompilerType( |
| 7405 | getASTContext(), |
| 7406 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 7407 | .GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 7408 | |
| 7409 | case clang::Type::Paren: |
| 7410 | return CompilerType(getASTContext(), |
| 7411 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 7412 | .GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 7413 | |
| 7414 | case clang::Type::Typedef: |
| 7415 | return CompilerType(getASTContext(), |
| 7416 | llvm::cast<clang::TypedefType>(qual_type) |
| 7417 | ->getDecl() |
| 7418 | ->getUnderlyingType()) |
| 7419 | .GetIndexOfChildWithName(name, omit_empty_base_classes); |
| 7420 | |
| 7421 | default: |
| 7422 | break; |
| 7423 | } |
| 7424 | } |
| 7425 | return UINT32_MAX; |
| 7426 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7427 | |
| 7428 | size_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7429 | ClangASTContext::GetNumTemplateArguments(lldb::opaque_compiler_type_t type) { |
| 7430 | if (!type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7431 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7432 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7433 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 7434 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7435 | switch (type_class) { |
| 7436 | case clang::Type::Record: |
| 7437 | if (GetCompleteType(type)) { |
| 7438 | const clang::CXXRecordDecl *cxx_record_decl = |
| 7439 | qual_type->getAsCXXRecordDecl(); |
| 7440 | if (cxx_record_decl) { |
| 7441 | const clang::ClassTemplateSpecializationDecl *template_decl = |
| 7442 | llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>( |
| 7443 | cxx_record_decl); |
| 7444 | if (template_decl) |
| 7445 | return template_decl->getTemplateArgs().size(); |
| 7446 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7447 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7448 | break; |
| 7449 | |
| 7450 | case clang::Type::Typedef: |
| 7451 | return (CompilerType(getASTContext(), |
| 7452 | llvm::cast<clang::TypedefType>(qual_type) |
| 7453 | ->getDecl() |
| 7454 | ->getUnderlyingType())) |
| 7455 | .GetNumTemplateArguments(); |
| 7456 | |
| 7457 | case clang::Type::Auto: |
| 7458 | return (CompilerType( |
| 7459 | getASTContext(), |
| 7460 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType())) |
| 7461 | .GetNumTemplateArguments(); |
| 7462 | |
| 7463 | case clang::Type::Elaborated: |
| 7464 | return (CompilerType( |
| 7465 | getASTContext(), |
| 7466 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())) |
| 7467 | .GetNumTemplateArguments(); |
| 7468 | |
| 7469 | case clang::Type::Paren: |
| 7470 | return (CompilerType(getASTContext(), |
| 7471 | llvm::cast<clang::ParenType>(qual_type)->desugar())) |
| 7472 | .GetNumTemplateArguments(); |
| 7473 | |
| 7474 | default: |
| 7475 | break; |
| 7476 | } |
| 7477 | |
| 7478 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7479 | } |
| 7480 | |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7481 | const clang::ClassTemplateSpecializationDecl * |
| 7482 | ClangASTContext::GetAsTemplateSpecialization( |
| 7483 | lldb::opaque_compiler_type_t type) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7484 | if (!type) |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7485 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7486 | |
| 7487 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 7488 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7489 | switch (type_class) { |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7490 | case clang::Type::Record: { |
| 7491 | if (! GetCompleteType(type)) |
| 7492 | return nullptr; |
| 7493 | const clang::CXXRecordDecl *cxx_record_decl = |
| 7494 | qual_type->getAsCXXRecordDecl(); |
| 7495 | if (!cxx_record_decl) |
| 7496 | return nullptr; |
| 7497 | return llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>( |
| 7498 | cxx_record_decl); |
| 7499 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7500 | |
| 7501 | case clang::Type::Typedef: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7502 | return GetAsTemplateSpecialization(llvm::cast<clang::TypedefType>(qual_type) |
| 7503 | ->getDecl() |
| 7504 | ->getUnderlyingType() |
| 7505 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7506 | |
| 7507 | case clang::Type::Auto: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7508 | return GetAsTemplateSpecialization(llvm::cast<clang::AutoType>(qual_type) |
| 7509 | ->getDeducedType() |
| 7510 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7511 | |
| 7512 | case clang::Type::Elaborated: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7513 | return GetAsTemplateSpecialization( |
| 7514 | llvm::cast<clang::ElaboratedType>(qual_type) |
| 7515 | ->getNamedType() |
| 7516 | .getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7517 | |
| 7518 | case clang::Type::Paren: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7519 | return GetAsTemplateSpecialization( |
| 7520 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7521 | |
| 7522 | default: |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7523 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7524 | } |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | lldb::TemplateArgumentKind |
| 7528 | ClangASTContext::GetTemplateArgumentKind(lldb::opaque_compiler_type_t type, |
| 7529 | size_t arg_idx) { |
| 7530 | const clang::ClassTemplateSpecializationDecl *template_decl = |
| 7531 | GetAsTemplateSpecialization(type); |
| 7532 | if (! template_decl || arg_idx >= template_decl->getTemplateArgs().size()) |
| 7533 | return eTemplateArgumentKindNull; |
| 7534 | |
| 7535 | switch (template_decl->getTemplateArgs()[arg_idx].getKind()) { |
| 7536 | case clang::TemplateArgument::Null: |
| 7537 | return eTemplateArgumentKindNull; |
| 7538 | |
| 7539 | case clang::TemplateArgument::NullPtr: |
| 7540 | return eTemplateArgumentKindNullPtr; |
| 7541 | |
| 7542 | case clang::TemplateArgument::Type: |
| 7543 | return eTemplateArgumentKindType; |
| 7544 | |
| 7545 | case clang::TemplateArgument::Declaration: |
| 7546 | return eTemplateArgumentKindDeclaration; |
| 7547 | |
| 7548 | case clang::TemplateArgument::Integral: |
| 7549 | return eTemplateArgumentKindIntegral; |
| 7550 | |
| 7551 | case clang::TemplateArgument::Template: |
| 7552 | return eTemplateArgumentKindTemplate; |
| 7553 | |
| 7554 | case clang::TemplateArgument::TemplateExpansion: |
| 7555 | return eTemplateArgumentKindTemplateExpansion; |
| 7556 | |
| 7557 | case clang::TemplateArgument::Expression: |
| 7558 | return eTemplateArgumentKindExpression; |
| 7559 | |
| 7560 | case clang::TemplateArgument::Pack: |
| 7561 | return eTemplateArgumentKindPack; |
| 7562 | } |
| 7563 | llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind"); |
| 7564 | } |
| 7565 | |
| 7566 | CompilerType |
| 7567 | ClangASTContext::GetTypeTemplateArgument(lldb::opaque_compiler_type_t type, |
| 7568 | size_t idx) { |
| 7569 | const clang::ClassTemplateSpecializationDecl *template_decl = |
| 7570 | GetAsTemplateSpecialization(type); |
| 7571 | if (!template_decl || idx >= template_decl->getTemplateArgs().size()) |
| 7572 | return CompilerType(); |
| 7573 | |
| 7574 | const clang::TemplateArgument &template_arg = |
| 7575 | template_decl->getTemplateArgs()[idx]; |
| 7576 | if (template_arg.getKind() != clang::TemplateArgument::Type) |
| 7577 | return CompilerType(); |
| 7578 | |
| 7579 | return CompilerType(getASTContext(), template_arg.getAsType()); |
| 7580 | } |
| 7581 | |
Pavel Labath | f59056f | 2017-11-30 10:16:54 +0000 | [diff] [blame] | 7582 | llvm::Optional<CompilerType::IntegralTemplateArgument> |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7583 | ClangASTContext::GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type, |
| 7584 | size_t idx) { |
| 7585 | const clang::ClassTemplateSpecializationDecl *template_decl = |
| 7586 | GetAsTemplateSpecialization(type); |
| 7587 | if (! template_decl || idx >= template_decl->getTemplateArgs().size()) |
Pavel Labath | f59056f | 2017-11-30 10:16:54 +0000 | [diff] [blame] | 7588 | return llvm::None; |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7589 | |
| 7590 | const clang::TemplateArgument &template_arg = |
| 7591 | template_decl->getTemplateArgs()[idx]; |
| 7592 | if (template_arg.getKind() != clang::TemplateArgument::Integral) |
Pavel Labath | f59056f | 2017-11-30 10:16:54 +0000 | [diff] [blame] | 7593 | return llvm::None; |
Pavel Labath | 769b21e | 2017-11-13 14:26:21 +0000 | [diff] [blame] | 7594 | |
Pavel Labath | f59056f | 2017-11-30 10:16:54 +0000 | [diff] [blame] | 7595 | return {{template_arg.getAsIntegral(), |
| 7596 | CompilerType(getASTContext(), template_arg.getIntegralType())}}; |
Enrico Granata | c6bf2e2 | 2015-09-23 01:39:46 +0000 | [diff] [blame] | 7597 | } |
| 7598 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7599 | CompilerType ClangASTContext::GetTypeForFormatters(void *type) { |
| 7600 | if (type) |
| 7601 | return ClangUtil::RemoveFastQualifiers(CompilerType(this, type)); |
| 7602 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7603 | } |
| 7604 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7605 | clang::EnumDecl *ClangASTContext::GetAsEnumDecl(const CompilerType &type) { |
| 7606 | const clang::EnumType *enutype = |
| 7607 | llvm::dyn_cast<clang::EnumType>(ClangUtil::GetCanonicalQualType(type)); |
| 7608 | if (enutype) |
| 7609 | return enutype->getDecl(); |
| 7610 | return NULL; |
| 7611 | } |
| 7612 | |
| 7613 | clang::RecordDecl *ClangASTContext::GetAsRecordDecl(const CompilerType &type) { |
| 7614 | const clang::RecordType *record_type = |
| 7615 | llvm::dyn_cast<clang::RecordType>(ClangUtil::GetCanonicalQualType(type)); |
| 7616 | if (record_type) |
| 7617 | return record_type->getDecl(); |
| 7618 | return nullptr; |
| 7619 | } |
| 7620 | |
| 7621 | clang::TagDecl *ClangASTContext::GetAsTagDecl(const CompilerType &type) { |
| 7622 | clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type); |
| 7623 | if (qual_type.isNull()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7624 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7625 | else |
| 7626 | return qual_type->getAsTagDecl(); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 7627 | } |
| 7628 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7629 | clang::CXXRecordDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7630 | ClangASTContext::GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type) { |
| 7631 | return GetCanonicalQualType(type)->getAsCXXRecordDecl(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7632 | } |
| 7633 | |
| 7634 | clang::ObjCInterfaceDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7635 | ClangASTContext::GetAsObjCInterfaceDecl(const CompilerType &type) { |
| 7636 | const clang::ObjCObjectType *objc_class_type = |
| 7637 | llvm::dyn_cast<clang::ObjCObjectType>( |
| 7638 | ClangUtil::GetCanonicalQualType(type)); |
| 7639 | if (objc_class_type) |
| 7640 | return objc_class_type->getInterface(); |
| 7641 | return nullptr; |
| 7642 | } |
| 7643 | |
| 7644 | clang::FieldDecl *ClangASTContext::AddFieldToRecordType( |
| 7645 | const CompilerType &type, const char *name, |
| 7646 | const CompilerType &field_clang_type, AccessType access, |
| 7647 | uint32_t bitfield_bit_size) { |
| 7648 | if (!type.IsValid() || !field_clang_type.IsValid()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7649 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7650 | ClangASTContext *ast = |
| 7651 | llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); |
| 7652 | if (!ast) |
| 7653 | return nullptr; |
| 7654 | clang::ASTContext *clang_ast = ast->getASTContext(); |
| 7655 | |
| 7656 | clang::FieldDecl *field = nullptr; |
| 7657 | |
| 7658 | clang::Expr *bit_width = nullptr; |
| 7659 | if (bitfield_bit_size != 0) { |
| 7660 | llvm::APInt bitfield_bit_size_apint( |
| 7661 | clang_ast->getTypeSize(clang_ast->IntTy), bitfield_bit_size); |
| 7662 | bit_width = new (*clang_ast) |
| 7663 | clang::IntegerLiteral(*clang_ast, bitfield_bit_size_apint, |
| 7664 | clang_ast->IntTy, clang::SourceLocation()); |
| 7665 | } |
| 7666 | |
| 7667 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); |
| 7668 | if (record_decl) { |
| 7669 | field = clang::FieldDecl::Create( |
| 7670 | *clang_ast, record_decl, clang::SourceLocation(), |
| 7671 | clang::SourceLocation(), |
| 7672 | name ? &clang_ast->Idents.get(name) : nullptr, // Identifier |
| 7673 | ClangUtil::GetQualType(field_clang_type), // Field type |
| 7674 | nullptr, // TInfo * |
| 7675 | bit_width, // BitWidth |
| 7676 | false, // Mutable |
| 7677 | clang::ICIS_NoInit); // HasInit |
| 7678 | |
| 7679 | if (!name) { |
| 7680 | // Determine whether this field corresponds to an anonymous |
| 7681 | // struct or union. |
| 7682 | if (const clang::TagType *TagT = |
| 7683 | field->getType()->getAs<clang::TagType>()) { |
| 7684 | if (clang::RecordDecl *Rec = |
| 7685 | llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl())) |
| 7686 | if (!Rec->getDeclName()) { |
| 7687 | Rec->setAnonymousStructOrUnion(true); |
| 7688 | field->setImplicit(); |
| 7689 | } |
| 7690 | } |
| 7691 | } |
| 7692 | |
| 7693 | if (field) { |
| 7694 | field->setAccess( |
| 7695 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(access)); |
| 7696 | |
| 7697 | record_decl->addDecl(field); |
| 7698 | |
| 7699 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7700 | VerifyDecl(field); |
| 7701 | #endif |
| 7702 | } |
| 7703 | } else { |
| 7704 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 7705 | ast->GetAsObjCInterfaceDecl(type); |
| 7706 | |
| 7707 | if (class_interface_decl) { |
| 7708 | const bool is_synthesized = false; |
| 7709 | |
| 7710 | field_clang_type.GetCompleteType(); |
| 7711 | |
| 7712 | field = clang::ObjCIvarDecl::Create( |
| 7713 | *clang_ast, class_interface_decl, clang::SourceLocation(), |
| 7714 | clang::SourceLocation(), |
| 7715 | name ? &clang_ast->Idents.get(name) : nullptr, // Identifier |
| 7716 | ClangUtil::GetQualType(field_clang_type), // Field type |
| 7717 | nullptr, // TypeSourceInfo * |
| 7718 | ConvertAccessTypeToObjCIvarAccessControl(access), bit_width, |
| 7719 | is_synthesized); |
| 7720 | |
| 7721 | if (field) { |
| 7722 | class_interface_decl->addDecl(field); |
| 7723 | |
| 7724 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7725 | VerifyDecl(field); |
| 7726 | #endif |
| 7727 | } |
| 7728 | } |
| 7729 | } |
| 7730 | return field; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7731 | } |
| 7732 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7733 | void ClangASTContext::BuildIndirectFields(const CompilerType &type) { |
| 7734 | if (!type) |
| 7735 | return; |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 7736 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7737 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 7738 | if (!ast) |
| 7739 | return; |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 7740 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7741 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 7742 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7743 | if (!record_decl) |
| 7744 | return; |
| 7745 | |
| 7746 | typedef llvm::SmallVector<clang::IndirectFieldDecl *, 1> IndirectFieldVector; |
| 7747 | |
| 7748 | IndirectFieldVector indirect_fields; |
| 7749 | clang::RecordDecl::field_iterator field_pos; |
| 7750 | clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end(); |
| 7751 | clang::RecordDecl::field_iterator last_field_pos = field_end_pos; |
| 7752 | for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; |
| 7753 | last_field_pos = field_pos++) { |
| 7754 | if (field_pos->isAnonymousStructOrUnion()) { |
| 7755 | clang::QualType field_qual_type = field_pos->getType(); |
| 7756 | |
| 7757 | const clang::RecordType *field_record_type = |
| 7758 | field_qual_type->getAs<clang::RecordType>(); |
| 7759 | |
| 7760 | if (!field_record_type) |
| 7761 | continue; |
| 7762 | |
| 7763 | clang::RecordDecl *field_record_decl = field_record_type->getDecl(); |
| 7764 | |
| 7765 | if (!field_record_decl) |
| 7766 | continue; |
| 7767 | |
| 7768 | for (clang::RecordDecl::decl_iterator |
| 7769 | di = field_record_decl->decls_begin(), |
| 7770 | de = field_record_decl->decls_end(); |
| 7771 | di != de; ++di) { |
| 7772 | if (clang::FieldDecl *nested_field_decl = |
| 7773 | llvm::dyn_cast<clang::FieldDecl>(*di)) { |
| 7774 | clang::NamedDecl **chain = |
| 7775 | new (*ast->getASTContext()) clang::NamedDecl *[2]; |
| 7776 | chain[0] = *field_pos; |
| 7777 | chain[1] = nested_field_decl; |
| 7778 | clang::IndirectFieldDecl *indirect_field = |
| 7779 | clang::IndirectFieldDecl::Create( |
| 7780 | *ast->getASTContext(), record_decl, clang::SourceLocation(), |
| 7781 | nested_field_decl->getIdentifier(), |
| 7782 | nested_field_decl->getType(), {chain, 2}); |
| 7783 | |
| 7784 | indirect_field->setImplicit(); |
| 7785 | |
| 7786 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers( |
| 7787 | field_pos->getAccess(), nested_field_decl->getAccess())); |
| 7788 | |
| 7789 | indirect_fields.push_back(indirect_field); |
| 7790 | } else if (clang::IndirectFieldDecl *nested_indirect_field_decl = |
| 7791 | llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) { |
| 7792 | size_t nested_chain_size = |
| 7793 | nested_indirect_field_decl->getChainingSize(); |
| 7794 | clang::NamedDecl **chain = new (*ast->getASTContext()) |
| 7795 | clang::NamedDecl *[nested_chain_size + 1]; |
| 7796 | chain[0] = *field_pos; |
| 7797 | |
| 7798 | int chain_index = 1; |
| 7799 | for (clang::IndirectFieldDecl::chain_iterator |
| 7800 | nci = nested_indirect_field_decl->chain_begin(), |
| 7801 | nce = nested_indirect_field_decl->chain_end(); |
| 7802 | nci < nce; ++nci) { |
| 7803 | chain[chain_index] = *nci; |
| 7804 | chain_index++; |
| 7805 | } |
| 7806 | |
| 7807 | clang::IndirectFieldDecl *indirect_field = |
| 7808 | clang::IndirectFieldDecl::Create( |
| 7809 | *ast->getASTContext(), record_decl, clang::SourceLocation(), |
| 7810 | nested_indirect_field_decl->getIdentifier(), |
| 7811 | nested_indirect_field_decl->getType(), |
| 7812 | {chain, nested_chain_size + 1}); |
| 7813 | |
| 7814 | indirect_field->setImplicit(); |
| 7815 | |
| 7816 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers( |
| 7817 | field_pos->getAccess(), nested_indirect_field_decl->getAccess())); |
| 7818 | |
| 7819 | indirect_fields.push_back(indirect_field); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7820 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7821 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7822 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7823 | } |
| 7824 | |
| 7825 | // Check the last field to see if it has an incomplete array type as its |
| 7826 | // last member and if it does, the tell the record decl about it |
| 7827 | if (last_field_pos != field_end_pos) { |
| 7828 | if (last_field_pos->getType()->isIncompleteArrayType()) |
| 7829 | record_decl->hasFlexibleArrayMember(); |
| 7830 | } |
| 7831 | |
| 7832 | for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), |
| 7833 | ife = indirect_fields.end(); |
| 7834 | ifi < ife; ++ifi) { |
| 7835 | record_decl->addDecl(*ifi); |
| 7836 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7837 | } |
| 7838 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7839 | void ClangASTContext::SetIsPacked(const CompilerType &type) { |
| 7840 | if (type) { |
| 7841 | ClangASTContext *ast = |
| 7842 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 7843 | if (ast) { |
| 7844 | clang::RecordDecl *record_decl = GetAsRecordDecl(type); |
| 7845 | |
| 7846 | if (!record_decl) |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7847 | return; |
| 7848 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7849 | record_decl->addAttr( |
| 7850 | clang::PackedAttr::CreateImplicit(*ast->getASTContext())); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7851 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7852 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7853 | } |
| 7854 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7855 | clang::VarDecl *ClangASTContext::AddVariableToRecordType( |
| 7856 | const CompilerType &type, const char *name, const CompilerType &var_type, |
| 7857 | AccessType access) { |
| 7858 | clang::VarDecl *var_decl = nullptr; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7859 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7860 | if (!type.IsValid() || !var_type.IsValid()) |
| 7861 | return nullptr; |
| 7862 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 7863 | if (!ast) |
| 7864 | return nullptr; |
| 7865 | |
| 7866 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); |
| 7867 | if (record_decl) { |
| 7868 | var_decl = clang::VarDecl::Create( |
| 7869 | *ast->getASTContext(), // ASTContext & |
| 7870 | record_decl, // DeclContext * |
| 7871 | clang::SourceLocation(), // clang::SourceLocation StartLoc |
| 7872 | clang::SourceLocation(), // clang::SourceLocation IdLoc |
| 7873 | name ? &ast->getASTContext()->Idents.get(name) |
| 7874 | : nullptr, // clang::IdentifierInfo * |
| 7875 | ClangUtil::GetQualType(var_type), // Variable clang::QualType |
| 7876 | nullptr, // TypeSourceInfo * |
| 7877 | clang::SC_Static); // StorageClass |
| 7878 | if (var_decl) { |
| 7879 | var_decl->setAccess( |
| 7880 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(access)); |
| 7881 | record_decl->addDecl(var_decl); |
| 7882 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7883 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7884 | VerifyDecl(var_decl); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7885 | #endif |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7886 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7887 | } |
| 7888 | return var_decl; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7889 | } |
| 7890 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7891 | clang::CXXMethodDecl *ClangASTContext::AddMethodToCXXRecordType( |
Davide Italiano | 675767a | 2018-03-27 19:40:50 +0000 | [diff] [blame^] | 7892 | 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] | 7893 | const CompilerType &method_clang_type, lldb::AccessType access, |
| 7894 | bool is_virtual, bool is_static, bool is_inline, bool is_explicit, |
| 7895 | bool is_attr_used, bool is_artificial) { |
| 7896 | if (!type || !method_clang_type.IsValid() || name == nullptr || |
| 7897 | name[0] == '\0') |
| 7898 | return nullptr; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7899 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7900 | clang::QualType record_qual_type(GetCanonicalQualType(type)); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 7901 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7902 | clang::CXXRecordDecl *cxx_record_decl = |
| 7903 | record_qual_type->getAsCXXRecordDecl(); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 7904 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7905 | if (cxx_record_decl == nullptr) |
| 7906 | return nullptr; |
| 7907 | |
| 7908 | clang::QualType method_qual_type(ClangUtil::GetQualType(method_clang_type)); |
| 7909 | |
| 7910 | clang::CXXMethodDecl *cxx_method_decl = nullptr; |
| 7911 | |
| 7912 | clang::DeclarationName decl_name(&getASTContext()->Idents.get(name)); |
| 7913 | |
| 7914 | const clang::FunctionType *function_type = |
| 7915 | llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr()); |
| 7916 | |
| 7917 | if (function_type == nullptr) |
| 7918 | return nullptr; |
| 7919 | |
| 7920 | const clang::FunctionProtoType *method_function_prototype( |
| 7921 | llvm::dyn_cast<clang::FunctionProtoType>(function_type)); |
| 7922 | |
| 7923 | if (!method_function_prototype) |
| 7924 | return nullptr; |
| 7925 | |
| 7926 | unsigned int num_params = method_function_prototype->getNumParams(); |
| 7927 | |
| 7928 | clang::CXXDestructorDecl *cxx_dtor_decl(nullptr); |
| 7929 | clang::CXXConstructorDecl *cxx_ctor_decl(nullptr); |
| 7930 | |
| 7931 | if (is_artificial) |
| 7932 | return nullptr; // skip everything artificial |
| 7933 | |
| 7934 | if (name[0] == '~') { |
| 7935 | cxx_dtor_decl = clang::CXXDestructorDecl::Create( |
| 7936 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 7937 | clang::DeclarationNameInfo( |
| 7938 | getASTContext()->DeclarationNames.getCXXDestructorName( |
| 7939 | getASTContext()->getCanonicalType(record_qual_type)), |
| 7940 | clang::SourceLocation()), |
| 7941 | method_qual_type, nullptr, is_inline, is_artificial); |
| 7942 | cxx_method_decl = cxx_dtor_decl; |
| 7943 | } else if (decl_name == cxx_record_decl->getDeclName()) { |
| 7944 | cxx_ctor_decl = clang::CXXConstructorDecl::Create( |
| 7945 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 7946 | clang::DeclarationNameInfo( |
| 7947 | getASTContext()->DeclarationNames.getCXXConstructorName( |
| 7948 | getASTContext()->getCanonicalType(record_qual_type)), |
| 7949 | clang::SourceLocation()), |
| 7950 | method_qual_type, |
| 7951 | nullptr, // TypeSourceInfo * |
| 7952 | is_explicit, is_inline, is_artificial, false /*is_constexpr*/); |
| 7953 | cxx_method_decl = cxx_ctor_decl; |
| 7954 | } else { |
| 7955 | clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None; |
| 7956 | clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS; |
| 7957 | |
| 7958 | if (IsOperator(name, op_kind)) { |
| 7959 | if (op_kind != clang::NUM_OVERLOADED_OPERATORS) { |
| 7960 | // Check the number of operator parameters. Sometimes we have |
| 7961 | // seen bad DWARF that doesn't correctly describe operators and |
| 7962 | // if we try to create a method and add it to the class, clang |
| 7963 | // will assert and crash, so we need to make sure things are |
| 7964 | // acceptable. |
| 7965 | const bool is_method = true; |
| 7966 | if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount( |
| 7967 | is_method, op_kind, num_params)) |
| 7968 | return nullptr; |
| 7969 | cxx_method_decl = clang::CXXMethodDecl::Create( |
| 7970 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 7971 | clang::DeclarationNameInfo( |
| 7972 | getASTContext()->DeclarationNames.getCXXOperatorName(op_kind), |
| 7973 | clang::SourceLocation()), |
| 7974 | method_qual_type, |
| 7975 | nullptr, // TypeSourceInfo * |
| 7976 | SC, is_inline, false /*is_constexpr*/, clang::SourceLocation()); |
| 7977 | } else if (num_params == 0) { |
| 7978 | // Conversion operators don't take params... |
| 7979 | cxx_method_decl = clang::CXXConversionDecl::Create( |
| 7980 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 7981 | clang::DeclarationNameInfo( |
| 7982 | getASTContext()->DeclarationNames.getCXXConversionFunctionName( |
| 7983 | getASTContext()->getCanonicalType( |
| 7984 | function_type->getReturnType())), |
| 7985 | clang::SourceLocation()), |
| 7986 | method_qual_type, |
| 7987 | nullptr, // TypeSourceInfo * |
| 7988 | is_inline, is_explicit, false /*is_constexpr*/, |
| 7989 | clang::SourceLocation()); |
| 7990 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7991 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 7992 | |
| 7993 | if (cxx_method_decl == nullptr) { |
| 7994 | cxx_method_decl = clang::CXXMethodDecl::Create( |
| 7995 | *getASTContext(), cxx_record_decl, clang::SourceLocation(), |
| 7996 | clang::DeclarationNameInfo(decl_name, clang::SourceLocation()), |
| 7997 | method_qual_type, |
| 7998 | nullptr, // TypeSourceInfo * |
| 7999 | SC, is_inline, false /*is_constexpr*/, clang::SourceLocation()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8000 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8001 | } |
| 8002 | |
| 8003 | clang::AccessSpecifier access_specifier = |
| 8004 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(access); |
| 8005 | |
| 8006 | cxx_method_decl->setAccess(access_specifier); |
| 8007 | cxx_method_decl->setVirtualAsWritten(is_virtual); |
| 8008 | |
| 8009 | if (is_attr_used) |
| 8010 | cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext())); |
| 8011 | |
Davide Italiano | 675767a | 2018-03-27 19:40:50 +0000 | [diff] [blame^] | 8012 | if (mangled_name != NULL) { |
| 8013 | cxx_method_decl->addAttr( |
| 8014 | clang::AsmLabelAttr::CreateImplicit(*getASTContext(), mangled_name)); |
| 8015 | } |
| 8016 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8017 | // Populate the method decl with parameter decls |
| 8018 | |
| 8019 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; |
| 8020 | |
| 8021 | for (unsigned param_index = 0; param_index < num_params; ++param_index) { |
| 8022 | params.push_back(clang::ParmVarDecl::Create( |
| 8023 | *getASTContext(), cxx_method_decl, clang::SourceLocation(), |
| 8024 | clang::SourceLocation(), |
| 8025 | nullptr, // anonymous |
| 8026 | method_function_prototype->getParamType(param_index), nullptr, |
| 8027 | clang::SC_None, nullptr)); |
| 8028 | } |
| 8029 | |
| 8030 | cxx_method_decl->setParams(llvm::ArrayRef<clang::ParmVarDecl *>(params)); |
| 8031 | |
| 8032 | cxx_record_decl->addDecl(cxx_method_decl); |
| 8033 | |
| 8034 | // Sometimes the debug info will mention a constructor (default/copy/move), |
| 8035 | // destructor, or assignment operator (copy/move) but there won't be any |
| 8036 | // version of this in the code. So we check if the function was artificially |
| 8037 | // generated and if it is trivial and this lets the compiler/backend know |
| 8038 | // that it can inline the IR for these when it needs to and we can avoid a |
| 8039 | // "missing function" error when running expressions. |
| 8040 | |
| 8041 | if (is_artificial) { |
| 8042 | if (cxx_ctor_decl && ((cxx_ctor_decl->isDefaultConstructor() && |
| 8043 | cxx_record_decl->hasTrivialDefaultConstructor()) || |
| 8044 | (cxx_ctor_decl->isCopyConstructor() && |
| 8045 | cxx_record_decl->hasTrivialCopyConstructor()) || |
| 8046 | (cxx_ctor_decl->isMoveConstructor() && |
| 8047 | cxx_record_decl->hasTrivialMoveConstructor()))) { |
| 8048 | cxx_ctor_decl->setDefaulted(); |
| 8049 | cxx_ctor_decl->setTrivial(true); |
| 8050 | } else if (cxx_dtor_decl) { |
| 8051 | if (cxx_record_decl->hasTrivialDestructor()) { |
| 8052 | cxx_dtor_decl->setDefaulted(); |
| 8053 | cxx_dtor_decl->setTrivial(true); |
| 8054 | } |
| 8055 | } else if ((cxx_method_decl->isCopyAssignmentOperator() && |
| 8056 | cxx_record_decl->hasTrivialCopyAssignment()) || |
| 8057 | (cxx_method_decl->isMoveAssignmentOperator() && |
| 8058 | cxx_record_decl->hasTrivialMoveAssignment())) { |
| 8059 | cxx_method_decl->setDefaulted(); |
| 8060 | cxx_method_decl->setTrivial(true); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8061 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8062 | } |
| 8063 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8064 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8065 | VerifyDecl(cxx_method_decl); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8066 | #endif |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8067 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8068 | // printf ("decl->isPolymorphic() = %i\n", |
| 8069 | // cxx_record_decl->isPolymorphic()); |
| 8070 | // printf ("decl->isAggregate() = %i\n", |
| 8071 | // cxx_record_decl->isAggregate()); |
| 8072 | // printf ("decl->isPOD() = %i\n", |
| 8073 | // cxx_record_decl->isPOD()); |
| 8074 | // printf ("decl->isEmpty() = %i\n", |
| 8075 | // cxx_record_decl->isEmpty()); |
| 8076 | // printf ("decl->isAbstract() = %i\n", |
| 8077 | // cxx_record_decl->isAbstract()); |
| 8078 | // printf ("decl->hasTrivialConstructor() = %i\n", |
| 8079 | // cxx_record_decl->hasTrivialConstructor()); |
| 8080 | // printf ("decl->hasTrivialCopyConstructor() = %i\n", |
| 8081 | // cxx_record_decl->hasTrivialCopyConstructor()); |
| 8082 | // printf ("decl->hasTrivialCopyAssignment() = %i\n", |
| 8083 | // cxx_record_decl->hasTrivialCopyAssignment()); |
| 8084 | // printf ("decl->hasTrivialDestructor() = %i\n", |
| 8085 | // cxx_record_decl->hasTrivialDestructor()); |
| 8086 | return cxx_method_decl; |
| 8087 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8088 | |
| 8089 | #pragma mark C++ Base Classes |
| 8090 | |
| 8091 | clang::CXXBaseSpecifier * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8092 | ClangASTContext::CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type, |
| 8093 | AccessType access, bool is_virtual, |
| 8094 | bool base_of_class) { |
| 8095 | if (type) |
| 8096 | return new clang::CXXBaseSpecifier( |
| 8097 | clang::SourceRange(), is_virtual, base_of_class, |
| 8098 | ClangASTContext::ConvertAccessTypeToAccessSpecifier(access), |
| 8099 | getASTContext()->getTrivialTypeSourceInfo(GetQualType(type)), |
| 8100 | clang::SourceLocation()); |
| 8101 | return nullptr; |
| 8102 | } |
| 8103 | |
| 8104 | void ClangASTContext::DeleteBaseClassSpecifiers( |
| 8105 | clang::CXXBaseSpecifier **base_classes, unsigned num_base_classes) { |
| 8106 | for (unsigned i = 0; i < num_base_classes; ++i) { |
| 8107 | delete base_classes[i]; |
| 8108 | base_classes[i] = nullptr; |
| 8109 | } |
| 8110 | } |
| 8111 | |
| 8112 | bool ClangASTContext::SetBaseClassesForClassType( |
| 8113 | lldb::opaque_compiler_type_t type, |
| 8114 | clang::CXXBaseSpecifier const *const *base_classes, |
| 8115 | unsigned num_base_classes) { |
| 8116 | if (type) { |
| 8117 | clang::CXXRecordDecl *cxx_record_decl = GetAsCXXRecordDecl(type); |
| 8118 | if (cxx_record_decl) { |
| 8119 | cxx_record_decl->setBases(base_classes, num_base_classes); |
| 8120 | return true; |
| 8121 | } |
| 8122 | } |
| 8123 | return false; |
| 8124 | } |
| 8125 | |
| 8126 | bool ClangASTContext::SetObjCSuperClass( |
| 8127 | const CompilerType &type, const CompilerType &superclass_clang_type) { |
| 8128 | ClangASTContext *ast = |
| 8129 | llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); |
| 8130 | if (!ast) |
| 8131 | return false; |
| 8132 | clang::ASTContext *clang_ast = ast->getASTContext(); |
| 8133 | |
| 8134 | if (type && superclass_clang_type.IsValid() && |
| 8135 | superclass_clang_type.GetTypeSystem() == type.GetTypeSystem()) { |
| 8136 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 8137 | GetAsObjCInterfaceDecl(type); |
| 8138 | clang::ObjCInterfaceDecl *super_interface_decl = |
| 8139 | GetAsObjCInterfaceDecl(superclass_clang_type); |
| 8140 | if (class_interface_decl && super_interface_decl) { |
| 8141 | class_interface_decl->setSuperClass(clang_ast->getTrivialTypeSourceInfo( |
| 8142 | clang_ast->getObjCInterfaceType(super_interface_decl))); |
| 8143 | return true; |
| 8144 | } |
| 8145 | } |
| 8146 | return false; |
| 8147 | } |
| 8148 | |
| 8149 | bool ClangASTContext::AddObjCClassProperty( |
| 8150 | const CompilerType &type, const char *property_name, |
| 8151 | const CompilerType &property_clang_type, clang::ObjCIvarDecl *ivar_decl, |
| 8152 | const char *property_setter_name, const char *property_getter_name, |
| 8153 | uint32_t property_attributes, ClangASTMetadata *metadata) { |
| 8154 | if (!type || !property_clang_type.IsValid() || property_name == nullptr || |
| 8155 | property_name[0] == '\0') |
| 8156 | return false; |
| 8157 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8158 | if (!ast) |
| 8159 | return false; |
| 8160 | clang::ASTContext *clang_ast = ast->getASTContext(); |
| 8161 | |
| 8162 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); |
| 8163 | |
| 8164 | if (class_interface_decl) { |
| 8165 | CompilerType property_clang_type_to_access; |
| 8166 | |
| 8167 | if (property_clang_type.IsValid()) |
| 8168 | property_clang_type_to_access = property_clang_type; |
| 8169 | else if (ivar_decl) |
| 8170 | property_clang_type_to_access = |
| 8171 | CompilerType(clang_ast, ivar_decl->getType()); |
| 8172 | |
| 8173 | if (class_interface_decl && property_clang_type_to_access.IsValid()) { |
| 8174 | clang::TypeSourceInfo *prop_type_source; |
| 8175 | if (ivar_decl) |
| 8176 | prop_type_source = |
| 8177 | clang_ast->getTrivialTypeSourceInfo(ivar_decl->getType()); |
| 8178 | else |
| 8179 | prop_type_source = clang_ast->getTrivialTypeSourceInfo( |
| 8180 | ClangUtil::GetQualType(property_clang_type)); |
| 8181 | |
| 8182 | clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create( |
| 8183 | *clang_ast, class_interface_decl, |
| 8184 | clang::SourceLocation(), // Source Location |
| 8185 | &clang_ast->Idents.get(property_name), |
| 8186 | clang::SourceLocation(), // Source Location for AT |
| 8187 | clang::SourceLocation(), // Source location for ( |
| 8188 | ivar_decl ? ivar_decl->getType() |
| 8189 | : ClangUtil::GetQualType(property_clang_type), |
| 8190 | prop_type_source); |
| 8191 | |
| 8192 | if (property_decl) { |
| 8193 | if (metadata) |
| 8194 | ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata); |
| 8195 | |
| 8196 | class_interface_decl->addDecl(property_decl); |
| 8197 | |
| 8198 | clang::Selector setter_sel, getter_sel; |
| 8199 | |
| 8200 | if (property_setter_name != nullptr) { |
| 8201 | std::string property_setter_no_colon( |
| 8202 | property_setter_name, strlen(property_setter_name) - 1); |
| 8203 | clang::IdentifierInfo *setter_ident = |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 8204 | &clang_ast->Idents.get(property_setter_no_colon); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8205 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); |
| 8206 | } else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) { |
| 8207 | std::string setter_sel_string("set"); |
| 8208 | setter_sel_string.push_back(::toupper(property_name[0])); |
| 8209 | setter_sel_string.append(&property_name[1]); |
| 8210 | clang::IdentifierInfo *setter_ident = |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 8211 | &clang_ast->Idents.get(setter_sel_string); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8212 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); |
| 8213 | } |
| 8214 | property_decl->setSetterName(setter_sel); |
| 8215 | property_decl->setPropertyAttributes( |
| 8216 | clang::ObjCPropertyDecl::OBJC_PR_setter); |
| 8217 | |
| 8218 | if (property_getter_name != nullptr) { |
| 8219 | clang::IdentifierInfo *getter_ident = |
| 8220 | &clang_ast->Idents.get(property_getter_name); |
| 8221 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); |
| 8222 | } else { |
| 8223 | clang::IdentifierInfo *getter_ident = |
| 8224 | &clang_ast->Idents.get(property_name); |
| 8225 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); |
| 8226 | } |
| 8227 | property_decl->setGetterName(getter_sel); |
| 8228 | property_decl->setPropertyAttributes( |
| 8229 | clang::ObjCPropertyDecl::OBJC_PR_getter); |
| 8230 | |
| 8231 | if (ivar_decl) |
| 8232 | property_decl->setPropertyIvarDecl(ivar_decl); |
| 8233 | |
| 8234 | if (property_attributes & DW_APPLE_PROPERTY_readonly) |
| 8235 | property_decl->setPropertyAttributes( |
| 8236 | clang::ObjCPropertyDecl::OBJC_PR_readonly); |
| 8237 | if (property_attributes & DW_APPLE_PROPERTY_readwrite) |
| 8238 | property_decl->setPropertyAttributes( |
| 8239 | clang::ObjCPropertyDecl::OBJC_PR_readwrite); |
| 8240 | if (property_attributes & DW_APPLE_PROPERTY_assign) |
| 8241 | property_decl->setPropertyAttributes( |
| 8242 | clang::ObjCPropertyDecl::OBJC_PR_assign); |
| 8243 | if (property_attributes & DW_APPLE_PROPERTY_retain) |
| 8244 | property_decl->setPropertyAttributes( |
| 8245 | clang::ObjCPropertyDecl::OBJC_PR_retain); |
| 8246 | if (property_attributes & DW_APPLE_PROPERTY_copy) |
| 8247 | property_decl->setPropertyAttributes( |
| 8248 | clang::ObjCPropertyDecl::OBJC_PR_copy); |
| 8249 | if (property_attributes & DW_APPLE_PROPERTY_nonatomic) |
| 8250 | property_decl->setPropertyAttributes( |
| 8251 | clang::ObjCPropertyDecl::OBJC_PR_nonatomic); |
| 8252 | if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_nullability) |
| 8253 | property_decl->setPropertyAttributes( |
| 8254 | clang::ObjCPropertyDecl::OBJC_PR_nullability); |
| 8255 | if (property_attributes & |
| 8256 | clang::ObjCPropertyDecl::OBJC_PR_null_resettable) |
| 8257 | property_decl->setPropertyAttributes( |
| 8258 | clang::ObjCPropertyDecl::OBJC_PR_null_resettable); |
| 8259 | if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class) |
| 8260 | property_decl->setPropertyAttributes( |
| 8261 | clang::ObjCPropertyDecl::OBJC_PR_class); |
| 8262 | |
| 8263 | const bool isInstance = |
| 8264 | (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class) == 0; |
| 8265 | |
| 8266 | if (!getter_sel.isNull() && |
| 8267 | !(isInstance |
| 8268 | ? class_interface_decl->lookupInstanceMethod(getter_sel) |
| 8269 | : class_interface_decl->lookupClassMethod(getter_sel))) { |
| 8270 | const bool isVariadic = false; |
| 8271 | const bool isSynthesized = false; |
| 8272 | const bool isImplicitlyDeclared = true; |
| 8273 | const bool isDefined = false; |
| 8274 | const clang::ObjCMethodDecl::ImplementationControl impControl = |
| 8275 | clang::ObjCMethodDecl::None; |
| 8276 | const bool HasRelatedResultType = false; |
| 8277 | |
| 8278 | clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create( |
| 8279 | *clang_ast, clang::SourceLocation(), clang::SourceLocation(), |
| 8280 | getter_sel, ClangUtil::GetQualType(property_clang_type_to_access), |
| 8281 | nullptr, class_interface_decl, isInstance, isVariadic, |
| 8282 | isSynthesized, isImplicitlyDeclared, isDefined, impControl, |
| 8283 | HasRelatedResultType); |
| 8284 | |
| 8285 | if (getter && metadata) |
| 8286 | ClangASTContext::SetMetadata(clang_ast, getter, *metadata); |
| 8287 | |
| 8288 | if (getter) { |
| 8289 | getter->setMethodParams(*clang_ast, |
| 8290 | llvm::ArrayRef<clang::ParmVarDecl *>(), |
| 8291 | llvm::ArrayRef<clang::SourceLocation>()); |
| 8292 | |
| 8293 | class_interface_decl->addDecl(getter); |
| 8294 | } |
| 8295 | } |
| 8296 | |
| 8297 | if (!setter_sel.isNull() && |
| 8298 | !(isInstance |
| 8299 | ? class_interface_decl->lookupInstanceMethod(setter_sel) |
| 8300 | : class_interface_decl->lookupClassMethod(setter_sel))) { |
| 8301 | clang::QualType result_type = clang_ast->VoidTy; |
| 8302 | const bool isVariadic = false; |
| 8303 | const bool isSynthesized = false; |
| 8304 | const bool isImplicitlyDeclared = true; |
| 8305 | const bool isDefined = false; |
| 8306 | const clang::ObjCMethodDecl::ImplementationControl impControl = |
| 8307 | clang::ObjCMethodDecl::None; |
| 8308 | const bool HasRelatedResultType = false; |
| 8309 | |
| 8310 | clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create( |
| 8311 | *clang_ast, clang::SourceLocation(), clang::SourceLocation(), |
| 8312 | setter_sel, result_type, nullptr, class_interface_decl, |
| 8313 | isInstance, isVariadic, isSynthesized, isImplicitlyDeclared, |
| 8314 | isDefined, impControl, HasRelatedResultType); |
| 8315 | |
| 8316 | if (setter && metadata) |
| 8317 | ClangASTContext::SetMetadata(clang_ast, setter, *metadata); |
| 8318 | |
| 8319 | llvm::SmallVector<clang::ParmVarDecl *, 1> params; |
| 8320 | |
| 8321 | params.push_back(clang::ParmVarDecl::Create( |
| 8322 | *clang_ast, setter, clang::SourceLocation(), |
| 8323 | clang::SourceLocation(), |
| 8324 | nullptr, // anonymous |
| 8325 | ClangUtil::GetQualType(property_clang_type_to_access), nullptr, |
| 8326 | clang::SC_Auto, nullptr)); |
| 8327 | |
| 8328 | if (setter) { |
| 8329 | setter->setMethodParams( |
| 8330 | *clang_ast, llvm::ArrayRef<clang::ParmVarDecl *>(params), |
| 8331 | llvm::ArrayRef<clang::SourceLocation>()); |
| 8332 | |
| 8333 | class_interface_decl->addDecl(setter); |
| 8334 | } |
| 8335 | } |
| 8336 | |
| 8337 | return true; |
| 8338 | } |
| 8339 | } |
| 8340 | } |
| 8341 | return false; |
| 8342 | } |
| 8343 | |
| 8344 | bool ClangASTContext::IsObjCClassTypeAndHasIVars(const CompilerType &type, |
| 8345 | bool check_superclass) { |
| 8346 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); |
| 8347 | if (class_interface_decl) |
| 8348 | return ObjCDeclHasIVars(class_interface_decl, check_superclass); |
| 8349 | return false; |
| 8350 | } |
| 8351 | |
| 8352 | clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType( |
| 8353 | const CompilerType &type, |
| 8354 | const char *name, // the full symbol name as seen in the symbol table |
| 8355 | // (lldb::opaque_compiler_type_t type, "-[NString |
| 8356 | // stringWithCString:]") |
| 8357 | const CompilerType &method_clang_type, lldb::AccessType access, |
| 8358 | bool is_artificial, bool is_variadic) { |
| 8359 | if (!type || !method_clang_type.IsValid()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8360 | return nullptr; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8361 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8362 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); |
| 8363 | |
| 8364 | if (class_interface_decl == nullptr) |
| 8365 | return nullptr; |
| 8366 | ClangASTContext *lldb_ast = |
| 8367 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8368 | if (lldb_ast == nullptr) |
| 8369 | return nullptr; |
| 8370 | clang::ASTContext *ast = lldb_ast->getASTContext(); |
| 8371 | |
| 8372 | const char *selector_start = ::strchr(name, ' '); |
| 8373 | if (selector_start == nullptr) |
| 8374 | return nullptr; |
| 8375 | |
| 8376 | selector_start++; |
| 8377 | llvm::SmallVector<clang::IdentifierInfo *, 12> selector_idents; |
| 8378 | |
| 8379 | size_t len = 0; |
| 8380 | const char *start; |
| 8381 | // printf ("name = '%s'\n", name); |
| 8382 | |
| 8383 | unsigned num_selectors_with_args = 0; |
| 8384 | for (start = selector_start; start && *start != '\0' && *start != ']'; |
| 8385 | start += len) { |
| 8386 | len = ::strcspn(start, ":]"); |
| 8387 | bool has_arg = (start[len] == ':'); |
| 8388 | if (has_arg) |
| 8389 | ++num_selectors_with_args; |
| 8390 | selector_idents.push_back(&ast->Idents.get(llvm::StringRef(start, len))); |
| 8391 | if (has_arg) |
| 8392 | len += 1; |
| 8393 | } |
| 8394 | |
| 8395 | if (selector_idents.size() == 0) |
| 8396 | return nullptr; |
| 8397 | |
| 8398 | clang::Selector method_selector = ast->Selectors.getSelector( |
| 8399 | num_selectors_with_args ? selector_idents.size() : 0, |
| 8400 | selector_idents.data()); |
| 8401 | |
| 8402 | clang::QualType method_qual_type(ClangUtil::GetQualType(method_clang_type)); |
| 8403 | |
| 8404 | // Populate the method decl with parameter decls |
| 8405 | const clang::Type *method_type(method_qual_type.getTypePtr()); |
| 8406 | |
| 8407 | if (method_type == nullptr) |
| 8408 | return nullptr; |
| 8409 | |
| 8410 | const clang::FunctionProtoType *method_function_prototype( |
| 8411 | llvm::dyn_cast<clang::FunctionProtoType>(method_type)); |
| 8412 | |
| 8413 | if (!method_function_prototype) |
| 8414 | return nullptr; |
| 8415 | |
| 8416 | bool is_synthesized = false; |
| 8417 | bool is_defined = false; |
| 8418 | clang::ObjCMethodDecl::ImplementationControl imp_control = |
| 8419 | clang::ObjCMethodDecl::None; |
| 8420 | |
| 8421 | const unsigned num_args = method_function_prototype->getNumParams(); |
| 8422 | |
| 8423 | if (num_args != num_selectors_with_args) |
| 8424 | return nullptr; // some debug information is corrupt. We are not going to |
| 8425 | // deal with it. |
| 8426 | |
| 8427 | clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create( |
| 8428 | *ast, |
| 8429 | clang::SourceLocation(), // beginLoc, |
| 8430 | clang::SourceLocation(), // endLoc, |
| 8431 | method_selector, method_function_prototype->getReturnType(), |
| 8432 | nullptr, // TypeSourceInfo *ResultTInfo, |
| 8433 | ClangASTContext::GetASTContext(ast)->GetDeclContextForType( |
| 8434 | ClangUtil::GetQualType(type)), |
| 8435 | name[0] == '-', is_variadic, is_synthesized, |
| 8436 | true, // is_implicitly_declared; we force this to true because we don't |
| 8437 | // have source locations |
| 8438 | is_defined, imp_control, false /*has_related_result_type*/); |
| 8439 | |
| 8440 | if (objc_method_decl == nullptr) |
| 8441 | return nullptr; |
| 8442 | |
| 8443 | if (num_args > 0) { |
| 8444 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; |
| 8445 | |
| 8446 | for (unsigned param_index = 0; param_index < num_args; ++param_index) { |
| 8447 | params.push_back(clang::ParmVarDecl::Create( |
| 8448 | *ast, objc_method_decl, clang::SourceLocation(), |
| 8449 | clang::SourceLocation(), |
| 8450 | nullptr, // anonymous |
| 8451 | method_function_prototype->getParamType(param_index), nullptr, |
| 8452 | clang::SC_Auto, nullptr)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8453 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8454 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8455 | objc_method_decl->setMethodParams( |
| 8456 | *ast, llvm::ArrayRef<clang::ParmVarDecl *>(params), |
| 8457 | llvm::ArrayRef<clang::SourceLocation>()); |
| 8458 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8459 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8460 | class_interface_decl->addDecl(objc_method_decl); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8461 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8462 | #ifdef LLDB_CONFIGURATION_DEBUG |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8463 | VerifyDecl(objc_method_decl); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8464 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8465 | |
| 8466 | return objc_method_decl; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8467 | } |
| 8468 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8469 | bool ClangASTContext::GetHasExternalStorage(const CompilerType &type) { |
| 8470 | if (ClangUtil::IsClangType(type)) |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8471 | return false; |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8472 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8473 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type)); |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8474 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8475 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 8476 | switch (type_class) { |
| 8477 | case clang::Type::Record: { |
| 8478 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 8479 | if (cxx_record_decl) |
| 8480 | return cxx_record_decl->hasExternalLexicalStorage() || |
| 8481 | cxx_record_decl->hasExternalVisibleStorage(); |
| 8482 | } break; |
Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 8483 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8484 | case clang::Type::Enum: { |
| 8485 | clang::EnumDecl *enum_decl = |
| 8486 | llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 8487 | if (enum_decl) |
| 8488 | return enum_decl->hasExternalLexicalStorage() || |
| 8489 | enum_decl->hasExternalVisibleStorage(); |
| 8490 | } break; |
| 8491 | |
| 8492 | case clang::Type::ObjCObject: |
| 8493 | case clang::Type::ObjCInterface: { |
| 8494 | const clang::ObjCObjectType *objc_class_type = |
| 8495 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 8496 | assert(objc_class_type); |
| 8497 | if (objc_class_type) { |
| 8498 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 8499 | objc_class_type->getInterface(); |
| 8500 | |
| 8501 | if (class_interface_decl) |
| 8502 | return class_interface_decl->hasExternalLexicalStorage() || |
| 8503 | class_interface_decl->hasExternalVisibleStorage(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8504 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8505 | } break; |
| 8506 | |
| 8507 | case clang::Type::Typedef: |
| 8508 | return GetHasExternalStorage(CompilerType( |
| 8509 | type.GetTypeSystem(), llvm::cast<clang::TypedefType>(qual_type) |
| 8510 | ->getDecl() |
| 8511 | ->getUnderlyingType() |
| 8512 | .getAsOpaquePtr())); |
| 8513 | |
| 8514 | case clang::Type::Auto: |
| 8515 | return GetHasExternalStorage(CompilerType( |
| 8516 | type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type) |
| 8517 | ->getDeducedType() |
| 8518 | .getAsOpaquePtr())); |
| 8519 | |
| 8520 | case clang::Type::Elaborated: |
| 8521 | return GetHasExternalStorage(CompilerType( |
| 8522 | type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type) |
| 8523 | ->getNamedType() |
| 8524 | .getAsOpaquePtr())); |
| 8525 | |
| 8526 | case clang::Type::Paren: |
| 8527 | return GetHasExternalStorage(CompilerType( |
| 8528 | type.GetTypeSystem(), |
| 8529 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())); |
| 8530 | |
| 8531 | default: |
| 8532 | break; |
| 8533 | } |
| 8534 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8535 | } |
| 8536 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8537 | bool ClangASTContext::SetHasExternalStorage(lldb::opaque_compiler_type_t type, |
| 8538 | bool has_extern) { |
| 8539 | if (!type) |
| 8540 | return false; |
| 8541 | |
| 8542 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 8543 | |
| 8544 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 8545 | switch (type_class) { |
| 8546 | case clang::Type::Record: { |
| 8547 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 8548 | if (cxx_record_decl) { |
| 8549 | cxx_record_decl->setHasExternalLexicalStorage(has_extern); |
| 8550 | cxx_record_decl->setHasExternalVisibleStorage(has_extern); |
| 8551 | return true; |
| 8552 | } |
| 8553 | } break; |
| 8554 | |
| 8555 | case clang::Type::Enum: { |
| 8556 | clang::EnumDecl *enum_decl = |
| 8557 | llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 8558 | if (enum_decl) { |
| 8559 | enum_decl->setHasExternalLexicalStorage(has_extern); |
| 8560 | enum_decl->setHasExternalVisibleStorage(has_extern); |
| 8561 | return true; |
| 8562 | } |
| 8563 | } break; |
| 8564 | |
| 8565 | case clang::Type::ObjCObject: |
| 8566 | case clang::Type::ObjCInterface: { |
| 8567 | const clang::ObjCObjectType *objc_class_type = |
| 8568 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 8569 | assert(objc_class_type); |
| 8570 | if (objc_class_type) { |
| 8571 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 8572 | objc_class_type->getInterface(); |
| 8573 | |
| 8574 | if (class_interface_decl) { |
| 8575 | class_interface_decl->setHasExternalLexicalStorage(has_extern); |
| 8576 | class_interface_decl->setHasExternalVisibleStorage(has_extern); |
| 8577 | return true; |
| 8578 | } |
| 8579 | } |
| 8580 | } break; |
| 8581 | |
| 8582 | case clang::Type::Typedef: |
| 8583 | return SetHasExternalStorage(llvm::cast<clang::TypedefType>(qual_type) |
| 8584 | ->getDecl() |
| 8585 | ->getUnderlyingType() |
| 8586 | .getAsOpaquePtr(), |
| 8587 | has_extern); |
| 8588 | |
| 8589 | case clang::Type::Auto: |
| 8590 | return SetHasExternalStorage(llvm::cast<clang::AutoType>(qual_type) |
| 8591 | ->getDeducedType() |
| 8592 | .getAsOpaquePtr(), |
| 8593 | has_extern); |
| 8594 | |
| 8595 | case clang::Type::Elaborated: |
| 8596 | return SetHasExternalStorage(llvm::cast<clang::ElaboratedType>(qual_type) |
| 8597 | ->getNamedType() |
| 8598 | .getAsOpaquePtr(), |
| 8599 | has_extern); |
| 8600 | |
| 8601 | case clang::Type::Paren: |
| 8602 | return SetHasExternalStorage( |
| 8603 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 8604 | has_extern); |
| 8605 | |
| 8606 | default: |
| 8607 | break; |
| 8608 | } |
| 8609 | return false; |
| 8610 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8611 | |
| 8612 | #pragma mark TagDecl |
| 8613 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8614 | bool ClangASTContext::StartTagDeclarationDefinition(const CompilerType &type) { |
| 8615 | clang::QualType qual_type(ClangUtil::GetQualType(type)); |
| 8616 | if (!qual_type.isNull()) { |
| 8617 | const clang::TagType *tag_type = qual_type->getAs<clang::TagType>(); |
| 8618 | if (tag_type) { |
| 8619 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8620 | if (tag_decl) { |
| 8621 | tag_decl->startDefinition(); |
| 8622 | return true; |
| 8623 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8624 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8625 | |
| 8626 | const clang::ObjCObjectType *object_type = |
| 8627 | qual_type->getAs<clang::ObjCObjectType>(); |
| 8628 | if (object_type) { |
| 8629 | clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface(); |
| 8630 | if (interface_decl) { |
| 8631 | interface_decl->startDefinition(); |
| 8632 | return true; |
| 8633 | } |
| 8634 | } |
| 8635 | } |
| 8636 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8637 | } |
| 8638 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8639 | bool ClangASTContext::CompleteTagDeclarationDefinition( |
| 8640 | const CompilerType &type) { |
| 8641 | clang::QualType qual_type(ClangUtil::GetQualType(type)); |
| 8642 | if (!qual_type.isNull()) { |
| 8643 | // Make sure we use the same methodology as |
| 8644 | // ClangASTContext::StartTagDeclarationDefinition() |
| 8645 | // as to how we start/end the definition. Previously we were calling |
| 8646 | const clang::TagType *tag_type = qual_type->getAs<clang::TagType>(); |
| 8647 | if (tag_type) { |
| 8648 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8649 | if (tag_decl) { |
| 8650 | clang::CXXRecordDecl *cxx_record_decl = |
| 8651 | llvm::dyn_cast_or_null<clang::CXXRecordDecl>(tag_decl); |
| 8652 | |
| 8653 | if (cxx_record_decl) { |
| 8654 | if (!cxx_record_decl->isCompleteDefinition()) |
| 8655 | cxx_record_decl->completeDefinition(); |
| 8656 | cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true); |
| 8657 | cxx_record_decl->setHasExternalLexicalStorage(false); |
| 8658 | cxx_record_decl->setHasExternalVisibleStorage(false); |
| 8659 | return true; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8660 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8661 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8662 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8663 | |
| 8664 | const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>(); |
| 8665 | |
| 8666 | if (enutype) { |
| 8667 | clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8668 | |
| 8669 | if (enum_decl) { |
| 8670 | if (!enum_decl->isCompleteDefinition()) { |
| 8671 | ClangASTContext *lldb_ast = |
| 8672 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8673 | if (lldb_ast == nullptr) |
| 8674 | return false; |
| 8675 | clang::ASTContext *ast = lldb_ast->getASTContext(); |
| 8676 | |
| 8677 | /// TODO This really needs to be fixed. |
| 8678 | |
| 8679 | QualType integer_type(enum_decl->getIntegerType()); |
| 8680 | if (!integer_type.isNull()) { |
| 8681 | unsigned NumPositiveBits = 1; |
| 8682 | unsigned NumNegativeBits = 0; |
| 8683 | |
| 8684 | clang::QualType promotion_qual_type; |
| 8685 | // If the enum integer type is less than an integer in bit width, |
| 8686 | // then we must promote it to an integer size. |
| 8687 | if (ast->getTypeSize(enum_decl->getIntegerType()) < |
| 8688 | ast->getTypeSize(ast->IntTy)) { |
| 8689 | if (enum_decl->getIntegerType()->isSignedIntegerType()) |
| 8690 | promotion_qual_type = ast->IntTy; |
| 8691 | else |
| 8692 | promotion_qual_type = ast->UnsignedIntTy; |
| 8693 | } else |
| 8694 | promotion_qual_type = enum_decl->getIntegerType(); |
| 8695 | |
| 8696 | enum_decl->completeDefinition(enum_decl->getIntegerType(), |
| 8697 | promotion_qual_type, NumPositiveBits, |
| 8698 | NumNegativeBits); |
| 8699 | } |
| 8700 | } |
| 8701 | return true; |
| 8702 | } |
| 8703 | } |
| 8704 | } |
| 8705 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8706 | } |
| 8707 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8708 | bool ClangASTContext::AddEnumerationValueToEnumerationType( |
| 8709 | lldb::opaque_compiler_type_t type, |
| 8710 | const CompilerType &enumerator_clang_type, const Declaration &decl, |
| 8711 | const char *name, int64_t enum_value, uint32_t enum_value_bit_size) { |
| 8712 | if (type && enumerator_clang_type.IsValid() && name && name[0]) { |
| 8713 | clang::QualType enum_qual_type(GetCanonicalQualType(type)); |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 8714 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8715 | bool is_signed = false; |
| 8716 | enumerator_clang_type.IsIntegerType(is_signed); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8717 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8718 | if (clang_type) { |
| 8719 | const clang::EnumType *enutype = |
| 8720 | llvm::dyn_cast<clang::EnumType>(clang_type); |
| 8721 | |
| 8722 | if (enutype) { |
| 8723 | llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed); |
| 8724 | enum_llvm_apsint = enum_value; |
| 8725 | clang::EnumConstantDecl *enumerator_decl = |
| 8726 | clang::EnumConstantDecl::Create( |
| 8727 | *getASTContext(), enutype->getDecl(), clang::SourceLocation(), |
| 8728 | name ? &getASTContext()->Idents.get(name) |
| 8729 | : nullptr, // Identifier |
| 8730 | ClangUtil::GetQualType(enumerator_clang_type), |
| 8731 | nullptr, enum_llvm_apsint); |
| 8732 | |
| 8733 | if (enumerator_decl) { |
| 8734 | enutype->getDecl()->addDecl(enumerator_decl); |
| 8735 | |
| 8736 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 8737 | VerifyDecl(enumerator_decl); |
| 8738 | #endif |
| 8739 | |
| 8740 | return true; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8741 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8742 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8743 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8744 | } |
| 8745 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8746 | } |
| 8747 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8748 | CompilerType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8749 | ClangASTContext::GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) { |
| 8750 | clang::QualType enum_qual_type(GetCanonicalQualType(type)); |
| 8751 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
| 8752 | if (clang_type) { |
| 8753 | const clang::EnumType *enutype = |
| 8754 | llvm::dyn_cast<clang::EnumType>(clang_type); |
| 8755 | if (enutype) { |
| 8756 | clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8757 | if (enum_decl) |
| 8758 | return CompilerType(getASTContext(), enum_decl->getIntegerType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8759 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8760 | } |
| 8761 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8762 | } |
| 8763 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8764 | CompilerType |
| 8765 | ClangASTContext::CreateMemberPointerType(const CompilerType &type, |
| 8766 | const CompilerType &pointee_type) { |
| 8767 | if (type && pointee_type.IsValid() && |
| 8768 | type.GetTypeSystem() == pointee_type.GetTypeSystem()) { |
| 8769 | ClangASTContext *ast = |
| 8770 | llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8771 | if (!ast) |
| 8772 | return CompilerType(); |
| 8773 | return CompilerType(ast->getASTContext(), |
| 8774 | ast->getASTContext()->getMemberPointerType( |
| 8775 | ClangUtil::GetQualType(pointee_type), |
| 8776 | ClangUtil::GetQualType(type).getTypePtr())); |
| 8777 | } |
| 8778 | return CompilerType(); |
| 8779 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8780 | |
| 8781 | size_t |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8782 | ClangASTContext::ConvertStringToFloatValue(lldb::opaque_compiler_type_t type, |
| 8783 | const char *s, uint8_t *dst, |
| 8784 | size_t dst_size) { |
| 8785 | if (type) { |
| 8786 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 8787 | uint32_t count = 0; |
| 8788 | bool is_complex = false; |
| 8789 | if (IsFloatingPointType(type, count, is_complex)) { |
| 8790 | // TODO: handle complex and vector types |
| 8791 | if (count != 1) |
| 8792 | return false; |
| 8793 | |
| 8794 | llvm::StringRef s_sref(s); |
| 8795 | llvm::APFloat ap_float(getASTContext()->getFloatTypeSemantics(qual_type), |
| 8796 | s_sref); |
| 8797 | |
| 8798 | const uint64_t bit_size = getASTContext()->getTypeSize(qual_type); |
| 8799 | const uint64_t byte_size = bit_size / 8; |
| 8800 | if (dst_size >= byte_size) { |
| 8801 | Scalar scalar = ap_float.bitcastToAPInt().zextOrTrunc( |
| 8802 | llvm::NextPowerOf2(byte_size) * 8); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 8803 | lldb_private::Status get_data_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8804 | if (scalar.GetAsMemoryData(dst, byte_size, |
| 8805 | lldb_private::endian::InlHostByteOrder(), |
| 8806 | get_data_error)) |
| 8807 | return byte_size; |
| 8808 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8809 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8810 | } |
| 8811 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8812 | } |
| 8813 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8814 | //---------------------------------------------------------------------- |
| 8815 | // Dumping types |
| 8816 | //---------------------------------------------------------------------- |
| 8817 | #define DEPTH_INCREMENT 2 |
| 8818 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8819 | void ClangASTContext::DumpValue( |
| 8820 | lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream *s, |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 8821 | lldb::Format format, const DataExtractor &data, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8822 | lldb::offset_t data_byte_offset, size_t data_byte_size, |
| 8823 | uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, bool show_types, |
| 8824 | bool show_summary, bool verbose, uint32_t depth) { |
| 8825 | if (!type) |
| 8826 | return; |
| 8827 | |
| 8828 | clang::QualType qual_type(GetQualType(type)); |
| 8829 | switch (qual_type->getTypeClass()) { |
| 8830 | case clang::Type::Record: |
| 8831 | if (GetCompleteType(type)) { |
| 8832 | const clang::RecordType *record_type = |
| 8833 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 8834 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 8835 | assert(record_decl); |
| 8836 | uint32_t field_bit_offset = 0; |
| 8837 | uint32_t field_byte_offset = 0; |
| 8838 | const clang::ASTRecordLayout &record_layout = |
| 8839 | getASTContext()->getASTRecordLayout(record_decl); |
| 8840 | uint32_t child_idx = 0; |
| 8841 | |
| 8842 | const clang::CXXRecordDecl *cxx_record_decl = |
| 8843 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 8844 | if (cxx_record_decl) { |
| 8845 | // We might have base classes to print out first |
| 8846 | clang::CXXRecordDecl::base_class_const_iterator base_class, |
| 8847 | base_class_end; |
| 8848 | for (base_class = cxx_record_decl->bases_begin(), |
| 8849 | base_class_end = cxx_record_decl->bases_end(); |
| 8850 | base_class != base_class_end; ++base_class) { |
| 8851 | const clang::CXXRecordDecl *base_class_decl = |
| 8852 | llvm::cast<clang::CXXRecordDecl>( |
| 8853 | base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 8854 | |
| 8855 | // Skip empty base classes |
| 8856 | if (verbose == false && |
| 8857 | ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 8858 | continue; |
| 8859 | |
| 8860 | if (base_class->isVirtual()) |
| 8861 | field_bit_offset = |
| 8862 | record_layout.getVBaseClassOffset(base_class_decl) |
| 8863 | .getQuantity() * |
| 8864 | 8; |
| 8865 | else |
| 8866 | field_bit_offset = record_layout.getBaseClassOffset(base_class_decl) |
| 8867 | .getQuantity() * |
| 8868 | 8; |
| 8869 | field_byte_offset = field_bit_offset / 8; |
| 8870 | assert(field_bit_offset % 8 == 0); |
| 8871 | if (child_idx == 0) |
| 8872 | s->PutChar('{'); |
| 8873 | else |
| 8874 | s->PutChar(','); |
| 8875 | |
| 8876 | clang::QualType base_class_qual_type = base_class->getType(); |
| 8877 | std::string base_class_type_name(base_class_qual_type.getAsString()); |
| 8878 | |
| 8879 | // Indent and print the base class type name |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 8880 | s->Format("\n{0}{1}", llvm::fmt_repeat(" ", depth + DEPTH_INCREMENT), |
| 8881 | base_class_type_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 8882 | |
| 8883 | clang::TypeInfo base_class_type_info = |
| 8884 | getASTContext()->getTypeInfo(base_class_qual_type); |
| 8885 | |
| 8886 | // Dump the value of the member |
| 8887 | CompilerType base_clang_type(getASTContext(), base_class_qual_type); |
| 8888 | base_clang_type.DumpValue( |
| 8889 | exe_ctx, |
| 8890 | s, // Stream to dump to |
| 8891 | base_clang_type |
| 8892 | .GetFormat(), // The format with which to display the member |
| 8893 | data, // Data buffer containing all bytes for this type |
| 8894 | data_byte_offset + field_byte_offset, // Offset into "data" where |
| 8895 | // to grab value from |
| 8896 | base_class_type_info.Width / 8, // Size of this type in bytes |
| 8897 | 0, // Bitfield bit size |
| 8898 | 0, // Bitfield bit offset |
| 8899 | show_types, // Boolean indicating if we should show the variable |
| 8900 | // types |
| 8901 | show_summary, // Boolean indicating if we should show a summary |
| 8902 | // for the current type |
| 8903 | verbose, // Verbose output? |
| 8904 | depth + DEPTH_INCREMENT); // Scope depth for any types that have |
| 8905 | // children |
| 8906 | |
| 8907 | ++child_idx; |
| 8908 | } |
| 8909 | } |
| 8910 | uint32_t field_idx = 0; |
| 8911 | clang::RecordDecl::field_iterator field, field_end; |
| 8912 | for (field = record_decl->field_begin(), |
| 8913 | field_end = record_decl->field_end(); |
| 8914 | field != field_end; ++field, ++field_idx, ++child_idx) { |
| 8915 | // Print the starting squiggly bracket (if this is the |
| 8916 | // first member) or comma (for member 2 and beyond) for |
| 8917 | // the struct/union/class member. |
| 8918 | if (child_idx == 0) |
| 8919 | s->PutChar('{'); |
| 8920 | else |
| 8921 | s->PutChar(','); |
| 8922 | |
| 8923 | // Indent |
| 8924 | s->Printf("\n%*s", depth + DEPTH_INCREMENT, ""); |
| 8925 | |
| 8926 | clang::QualType field_type = field->getType(); |
| 8927 | // Print the member type if requested |
| 8928 | // Figure out the type byte size (field_type_info.first) and |
| 8929 | // alignment (field_type_info.second) from the AST context. |
| 8930 | clang::TypeInfo field_type_info = |
| 8931 | getASTContext()->getTypeInfo(field_type); |
| 8932 | assert(field_idx < record_layout.getFieldCount()); |
| 8933 | // Figure out the field offset within the current struct/union/class |
| 8934 | // type |
| 8935 | field_bit_offset = record_layout.getFieldOffset(field_idx); |
| 8936 | field_byte_offset = field_bit_offset / 8; |
| 8937 | uint32_t field_bitfield_bit_size = 0; |
| 8938 | uint32_t field_bitfield_bit_offset = 0; |
| 8939 | if (ClangASTContext::FieldIsBitfield(getASTContext(), *field, |
| 8940 | field_bitfield_bit_size)) |
| 8941 | field_bitfield_bit_offset = field_bit_offset % 8; |
| 8942 | |
| 8943 | if (show_types) { |
| 8944 | std::string field_type_name(field_type.getAsString()); |
| 8945 | if (field_bitfield_bit_size > 0) |
| 8946 | s->Printf("(%s:%u) ", field_type_name.c_str(), |
| 8947 | field_bitfield_bit_size); |
| 8948 | else |
| 8949 | s->Printf("(%s) ", field_type_name.c_str()); |
| 8950 | } |
| 8951 | // Print the member name and equal sign |
| 8952 | s->Printf("%s = ", field->getNameAsString().c_str()); |
| 8953 | |
| 8954 | // Dump the value of the member |
| 8955 | CompilerType field_clang_type(getASTContext(), field_type); |
| 8956 | field_clang_type.DumpValue( |
| 8957 | exe_ctx, |
| 8958 | s, // Stream to dump to |
| 8959 | field_clang_type |
| 8960 | .GetFormat(), // The format with which to display the member |
| 8961 | data, // Data buffer containing all bytes for this type |
| 8962 | data_byte_offset + field_byte_offset, // Offset into "data" where to |
| 8963 | // grab value from |
| 8964 | field_type_info.Width / 8, // Size of this type in bytes |
| 8965 | field_bitfield_bit_size, // Bitfield bit size |
| 8966 | field_bitfield_bit_offset, // Bitfield bit offset |
| 8967 | show_types, // Boolean indicating if we should show the variable |
| 8968 | // types |
| 8969 | show_summary, // Boolean indicating if we should show a summary for |
| 8970 | // the current type |
| 8971 | verbose, // Verbose output? |
| 8972 | depth + DEPTH_INCREMENT); // Scope depth for any types that have |
| 8973 | // children |
| 8974 | } |
| 8975 | |
| 8976 | // Indent the trailing squiggly bracket |
| 8977 | if (child_idx > 0) |
| 8978 | s->Printf("\n%*s}", depth, ""); |
| 8979 | } |
| 8980 | return; |
| 8981 | |
| 8982 | case clang::Type::Enum: |
| 8983 | if (GetCompleteType(type)) { |
| 8984 | const clang::EnumType *enutype = |
| 8985 | llvm::cast<clang::EnumType>(qual_type.getTypePtr()); |
| 8986 | const clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8987 | assert(enum_decl); |
| 8988 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 8989 | lldb::offset_t offset = data_byte_offset; |
| 8990 | const int64_t enum_value = data.GetMaxU64Bitfield( |
| 8991 | &offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 8992 | for (enum_pos = enum_decl->enumerator_begin(), |
| 8993 | enum_end_pos = enum_decl->enumerator_end(); |
| 8994 | enum_pos != enum_end_pos; ++enum_pos) { |
| 8995 | if (enum_pos->getInitVal() == enum_value) { |
| 8996 | s->Printf("%s", enum_pos->getNameAsString().c_str()); |
| 8997 | return; |
| 8998 | } |
| 8999 | } |
| 9000 | // If we have gotten here we didn't get find the enumerator in the |
| 9001 | // enum decl, so just print the integer. |
| 9002 | s->Printf("%" PRIi64, enum_value); |
| 9003 | } |
| 9004 | return; |
| 9005 | |
| 9006 | case clang::Type::ConstantArray: { |
| 9007 | const clang::ConstantArrayType *array = |
| 9008 | llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr()); |
| 9009 | bool is_array_of_characters = false; |
| 9010 | clang::QualType element_qual_type = array->getElementType(); |
| 9011 | |
| 9012 | const clang::Type *canonical_type = |
| 9013 | element_qual_type->getCanonicalTypeInternal().getTypePtr(); |
| 9014 | if (canonical_type) |
| 9015 | is_array_of_characters = canonical_type->isCharType(); |
| 9016 | |
| 9017 | const uint64_t element_count = array->getSize().getLimitedValue(); |
| 9018 | |
| 9019 | clang::TypeInfo field_type_info = |
| 9020 | getASTContext()->getTypeInfo(element_qual_type); |
| 9021 | |
| 9022 | uint32_t element_idx = 0; |
| 9023 | uint32_t element_offset = 0; |
| 9024 | uint64_t element_byte_size = field_type_info.Width / 8; |
| 9025 | uint32_t element_stride = element_byte_size; |
| 9026 | |
| 9027 | if (is_array_of_characters) { |
| 9028 | s->PutChar('"'); |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9029 | DumpDataExtractor(data, s, data_byte_offset, lldb::eFormatChar, |
| 9030 | element_byte_size, element_count, UINT32_MAX, |
| 9031 | LLDB_INVALID_ADDRESS, 0, 0); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9032 | s->PutChar('"'); |
| 9033 | return; |
| 9034 | } else { |
| 9035 | CompilerType element_clang_type(getASTContext(), element_qual_type); |
| 9036 | lldb::Format element_format = element_clang_type.GetFormat(); |
| 9037 | |
| 9038 | for (element_idx = 0; element_idx < element_count; ++element_idx) { |
| 9039 | // Print the starting squiggly bracket (if this is the |
| 9040 | // first member) or comman (for member 2 and beyong) for |
| 9041 | // the struct/union/class member. |
| 9042 | if (element_idx == 0) |
| 9043 | s->PutChar('{'); |
| 9044 | else |
| 9045 | s->PutChar(','); |
| 9046 | |
| 9047 | // Indent and print the index |
| 9048 | s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx); |
| 9049 | |
| 9050 | // Figure out the field offset within the current struct/union/class |
| 9051 | // type |
| 9052 | element_offset = element_idx * element_stride; |
| 9053 | |
| 9054 | // Dump the value of the member |
| 9055 | element_clang_type.DumpValue( |
| 9056 | exe_ctx, |
| 9057 | s, // Stream to dump to |
| 9058 | element_format, // The format with which to display the element |
| 9059 | data, // Data buffer containing all bytes for this type |
| 9060 | data_byte_offset + |
| 9061 | element_offset, // Offset into "data" where to grab value from |
| 9062 | element_byte_size, // Size of this type in bytes |
| 9063 | 0, // Bitfield bit size |
| 9064 | 0, // Bitfield bit offset |
| 9065 | show_types, // Boolean indicating if we should show the variable |
| 9066 | // types |
| 9067 | show_summary, // Boolean indicating if we should show a summary for |
| 9068 | // the current type |
| 9069 | verbose, // Verbose output? |
| 9070 | depth + DEPTH_INCREMENT); // Scope depth for any types that have |
| 9071 | // children |
| 9072 | } |
| 9073 | |
| 9074 | // Indent the trailing squiggly bracket |
| 9075 | if (element_idx > 0) |
| 9076 | s->Printf("\n%*s}", depth, ""); |
| 9077 | } |
| 9078 | } |
| 9079 | return; |
| 9080 | |
| 9081 | case clang::Type::Typedef: { |
| 9082 | clang::QualType typedef_qual_type = |
| 9083 | llvm::cast<clang::TypedefType>(qual_type) |
| 9084 | ->getDecl() |
| 9085 | ->getUnderlyingType(); |
| 9086 | |
| 9087 | CompilerType typedef_clang_type(getASTContext(), typedef_qual_type); |
| 9088 | lldb::Format typedef_format = typedef_clang_type.GetFormat(); |
| 9089 | clang::TypeInfo typedef_type_info = |
| 9090 | getASTContext()->getTypeInfo(typedef_qual_type); |
| 9091 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; |
| 9092 | |
| 9093 | return typedef_clang_type.DumpValue( |
| 9094 | exe_ctx, |
| 9095 | s, // Stream to dump to |
| 9096 | typedef_format, // The format with which to display the element |
| 9097 | data, // Data buffer containing all bytes for this type |
| 9098 | data_byte_offset, // Offset into "data" where to grab value from |
| 9099 | typedef_byte_size, // Size of this type in bytes |
| 9100 | bitfield_bit_size, // Bitfield bit size |
| 9101 | bitfield_bit_offset, // Bitfield bit offset |
| 9102 | show_types, // Boolean indicating if we should show the variable types |
| 9103 | show_summary, // Boolean indicating if we should show a summary for the |
| 9104 | // current type |
| 9105 | verbose, // Verbose output? |
| 9106 | depth); // Scope depth for any types that have children |
| 9107 | } break; |
| 9108 | |
| 9109 | case clang::Type::Auto: { |
| 9110 | clang::QualType elaborated_qual_type = |
| 9111 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType(); |
| 9112 | CompilerType elaborated_clang_type(getASTContext(), elaborated_qual_type); |
| 9113 | lldb::Format elaborated_format = elaborated_clang_type.GetFormat(); |
| 9114 | clang::TypeInfo elaborated_type_info = |
| 9115 | getASTContext()->getTypeInfo(elaborated_qual_type); |
| 9116 | uint64_t elaborated_byte_size = elaborated_type_info.Width / 8; |
| 9117 | |
| 9118 | return elaborated_clang_type.DumpValue( |
| 9119 | exe_ctx, |
| 9120 | s, // Stream to dump to |
| 9121 | elaborated_format, // The format with which to display the element |
| 9122 | data, // Data buffer containing all bytes for this type |
| 9123 | data_byte_offset, // Offset into "data" where to grab value from |
| 9124 | elaborated_byte_size, // Size of this type in bytes |
| 9125 | bitfield_bit_size, // Bitfield bit size |
| 9126 | bitfield_bit_offset, // Bitfield bit offset |
| 9127 | show_types, // Boolean indicating if we should show the variable types |
| 9128 | show_summary, // Boolean indicating if we should show a summary for the |
| 9129 | // current type |
| 9130 | verbose, // Verbose output? |
| 9131 | depth); // Scope depth for any types that have children |
| 9132 | } break; |
| 9133 | |
| 9134 | case clang::Type::Elaborated: { |
| 9135 | clang::QualType elaborated_qual_type = |
| 9136 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(); |
| 9137 | CompilerType elaborated_clang_type(getASTContext(), elaborated_qual_type); |
| 9138 | lldb::Format elaborated_format = elaborated_clang_type.GetFormat(); |
| 9139 | clang::TypeInfo elaborated_type_info = |
| 9140 | getASTContext()->getTypeInfo(elaborated_qual_type); |
| 9141 | uint64_t elaborated_byte_size = elaborated_type_info.Width / 8; |
| 9142 | |
| 9143 | return elaborated_clang_type.DumpValue( |
| 9144 | exe_ctx, |
| 9145 | s, // Stream to dump to |
| 9146 | elaborated_format, // The format with which to display the element |
| 9147 | data, // Data buffer containing all bytes for this type |
| 9148 | data_byte_offset, // Offset into "data" where to grab value from |
| 9149 | elaborated_byte_size, // Size of this type in bytes |
| 9150 | bitfield_bit_size, // Bitfield bit size |
| 9151 | bitfield_bit_offset, // Bitfield bit offset |
| 9152 | show_types, // Boolean indicating if we should show the variable types |
| 9153 | show_summary, // Boolean indicating if we should show a summary for the |
| 9154 | // current type |
| 9155 | verbose, // Verbose output? |
| 9156 | depth); // Scope depth for any types that have children |
| 9157 | } break; |
| 9158 | |
| 9159 | case clang::Type::Paren: { |
| 9160 | clang::QualType desugar_qual_type = |
| 9161 | llvm::cast<clang::ParenType>(qual_type)->desugar(); |
| 9162 | CompilerType desugar_clang_type(getASTContext(), desugar_qual_type); |
| 9163 | |
| 9164 | lldb::Format desugar_format = desugar_clang_type.GetFormat(); |
| 9165 | clang::TypeInfo desugar_type_info = |
| 9166 | getASTContext()->getTypeInfo(desugar_qual_type); |
| 9167 | uint64_t desugar_byte_size = desugar_type_info.Width / 8; |
| 9168 | |
| 9169 | return desugar_clang_type.DumpValue( |
| 9170 | exe_ctx, |
| 9171 | s, // Stream to dump to |
| 9172 | desugar_format, // The format with which to display the element |
| 9173 | data, // Data buffer containing all bytes for this type |
| 9174 | data_byte_offset, // Offset into "data" where to grab value from |
| 9175 | desugar_byte_size, // Size of this type in bytes |
| 9176 | bitfield_bit_size, // Bitfield bit size |
| 9177 | bitfield_bit_offset, // Bitfield bit offset |
| 9178 | show_types, // Boolean indicating if we should show the variable types |
| 9179 | show_summary, // Boolean indicating if we should show a summary for the |
| 9180 | // current type |
| 9181 | verbose, // Verbose output? |
| 9182 | depth); // Scope depth for any types that have children |
| 9183 | } break; |
| 9184 | |
| 9185 | default: |
| 9186 | // 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] | 9187 | DumpDataExtractor(data, s, data_byte_offset, format, data_byte_size, 1, |
| 9188 | UINT32_MAX, LLDB_INVALID_ADDRESS, bitfield_bit_size, |
| 9189 | bitfield_bit_offset); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9190 | |
| 9191 | if (show_summary) |
| 9192 | DumpSummary(type, exe_ctx, s, data, data_byte_offset, data_byte_size); |
| 9193 | break; |
| 9194 | } |
| 9195 | } |
| 9196 | |
| 9197 | bool ClangASTContext::DumpTypeValue( |
| 9198 | lldb::opaque_compiler_type_t type, Stream *s, lldb::Format format, |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9199 | const DataExtractor &data, lldb::offset_t byte_offset, size_t byte_size, |
| 9200 | uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9201 | ExecutionContextScope *exe_scope) { |
| 9202 | if (!type) |
| 9203 | return false; |
| 9204 | if (IsAggregateType(type)) { |
| 9205 | return false; |
| 9206 | } else { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9207 | clang::QualType qual_type(GetQualType(type)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9208 | |
| 9209 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 9210 | switch (type_class) { |
| 9211 | case clang::Type::Typedef: { |
| 9212 | clang::QualType typedef_qual_type = |
| 9213 | llvm::cast<clang::TypedefType>(qual_type) |
| 9214 | ->getDecl() |
| 9215 | ->getUnderlyingType(); |
| 9216 | CompilerType typedef_clang_type(getASTContext(), typedef_qual_type); |
| 9217 | if (format == eFormatDefault) |
| 9218 | format = typedef_clang_type.GetFormat(); |
| 9219 | clang::TypeInfo typedef_type_info = |
| 9220 | getASTContext()->getTypeInfo(typedef_qual_type); |
| 9221 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; |
| 9222 | |
| 9223 | return typedef_clang_type.DumpTypeValue( |
| 9224 | s, |
| 9225 | format, // The format with which to display the element |
| 9226 | data, // Data buffer containing all bytes for this type |
| 9227 | byte_offset, // Offset into "data" where to grab value from |
| 9228 | typedef_byte_size, // Size of this type in bytes |
| 9229 | bitfield_bit_size, // Size in bits of a bitfield value, if zero don't |
| 9230 | // treat as a bitfield |
| 9231 | bitfield_bit_offset, // Offset in bits of a bitfield value if |
| 9232 | // bitfield_bit_size != 0 |
| 9233 | exe_scope); |
| 9234 | } break; |
| 9235 | |
| 9236 | case clang::Type::Enum: |
| 9237 | // If our format is enum or default, show the enumeration value as |
| 9238 | // its enumeration string value, else just display it as requested. |
| 9239 | if ((format == eFormatEnum || format == eFormatDefault) && |
| 9240 | GetCompleteType(type)) { |
| 9241 | const clang::EnumType *enutype = |
| 9242 | llvm::cast<clang::EnumType>(qual_type.getTypePtr()); |
| 9243 | const clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 9244 | assert(enum_decl); |
| 9245 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 9246 | const bool is_signed = qual_type->isSignedIntegerOrEnumerationType(); |
| 9247 | lldb::offset_t offset = byte_offset; |
| 9248 | if (is_signed) { |
| 9249 | const int64_t enum_svalue = data.GetMaxS64Bitfield( |
| 9250 | &offset, byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 9251 | for (enum_pos = enum_decl->enumerator_begin(), |
| 9252 | enum_end_pos = enum_decl->enumerator_end(); |
| 9253 | enum_pos != enum_end_pos; ++enum_pos) { |
| 9254 | if (enum_pos->getInitVal().getSExtValue() == enum_svalue) { |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 9255 | s->PutCString(enum_pos->getNameAsString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9256 | return true; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9257 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9258 | } |
| 9259 | // If we have gotten here we didn't get find the enumerator in the |
| 9260 | // enum decl, so just print the integer. |
| 9261 | s->Printf("%" PRIi64, enum_svalue); |
| 9262 | } else { |
| 9263 | const uint64_t enum_uvalue = data.GetMaxU64Bitfield( |
| 9264 | &offset, byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 9265 | for (enum_pos = enum_decl->enumerator_begin(), |
| 9266 | enum_end_pos = enum_decl->enumerator_end(); |
| 9267 | enum_pos != enum_end_pos; ++enum_pos) { |
| 9268 | if (enum_pos->getInitVal().getZExtValue() == enum_uvalue) { |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 9269 | s->PutCString(enum_pos->getNameAsString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9270 | return true; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9271 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9272 | } |
| 9273 | // If we have gotten here we didn't get find the enumerator in the |
| 9274 | // enum decl, so just print the integer. |
| 9275 | s->Printf("%" PRIu64, enum_uvalue); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9276 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9277 | return true; |
| 9278 | } |
| 9279 | // format was not enum, just fall through and dump the value as |
| 9280 | // requested.... |
| 9281 | LLVM_FALLTHROUGH; |
| 9282 | |
| 9283 | default: |
| 9284 | // We are down to a scalar type that we just need to display. |
| 9285 | { |
| 9286 | uint32_t item_count = 1; |
| 9287 | // A few formats, we might need to modify our size and count for |
| 9288 | // depending |
| 9289 | // on how we are trying to display the value... |
| 9290 | switch (format) { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9291 | default: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9292 | case eFormatBoolean: |
| 9293 | case eFormatBinary: |
| 9294 | case eFormatComplex: |
| 9295 | case eFormatCString: // NULL terminated C strings |
| 9296 | case eFormatDecimal: |
| 9297 | case eFormatEnum: |
| 9298 | case eFormatHex: |
| 9299 | case eFormatHexUppercase: |
| 9300 | case eFormatFloat: |
| 9301 | case eFormatOctal: |
| 9302 | case eFormatOSType: |
| 9303 | case eFormatUnsigned: |
| 9304 | case eFormatPointer: |
| 9305 | case eFormatVectorOfChar: |
| 9306 | case eFormatVectorOfSInt8: |
| 9307 | case eFormatVectorOfUInt8: |
| 9308 | case eFormatVectorOfSInt16: |
| 9309 | case eFormatVectorOfUInt16: |
| 9310 | case eFormatVectorOfSInt32: |
| 9311 | case eFormatVectorOfUInt32: |
| 9312 | case eFormatVectorOfSInt64: |
| 9313 | case eFormatVectorOfUInt64: |
| 9314 | case eFormatVectorOfFloat32: |
| 9315 | case eFormatVectorOfFloat64: |
| 9316 | case eFormatVectorOfUInt128: |
| 9317 | break; |
| 9318 | |
| 9319 | case eFormatChar: |
| 9320 | case eFormatCharPrintable: |
| 9321 | case eFormatCharArray: |
| 9322 | case eFormatBytes: |
| 9323 | case eFormatBytesWithASCII: |
| 9324 | item_count = byte_size; |
| 9325 | byte_size = 1; |
| 9326 | break; |
| 9327 | |
| 9328 | case eFormatUnicode16: |
| 9329 | item_count = byte_size / 2; |
| 9330 | byte_size = 2; |
| 9331 | break; |
| 9332 | |
| 9333 | case eFormatUnicode32: |
| 9334 | item_count = byte_size / 4; |
| 9335 | byte_size = 4; |
| 9336 | break; |
| 9337 | } |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9338 | return DumpDataExtractor(data, s, byte_offset, format, byte_size, |
| 9339 | item_count, UINT32_MAX, LLDB_INVALID_ADDRESS, |
| 9340 | bitfield_bit_size, bitfield_bit_offset, |
| 9341 | exe_scope); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9342 | } |
| 9343 | break; |
| 9344 | } |
| 9345 | } |
| 9346 | return 0; |
| 9347 | } |
| 9348 | |
| 9349 | void ClangASTContext::DumpSummary(lldb::opaque_compiler_type_t type, |
| 9350 | ExecutionContext *exe_ctx, Stream *s, |
| 9351 | const lldb_private::DataExtractor &data, |
| 9352 | lldb::offset_t data_byte_offset, |
| 9353 | size_t data_byte_size) { |
| 9354 | uint32_t length = 0; |
| 9355 | if (IsCStringType(type, length)) { |
| 9356 | if (exe_ctx) { |
| 9357 | Process *process = exe_ctx->GetProcessPtr(); |
| 9358 | if (process) { |
| 9359 | lldb::offset_t offset = data_byte_offset; |
| 9360 | lldb::addr_t pointer_address = data.GetMaxU64(&offset, data_byte_size); |
| 9361 | std::vector<uint8_t> buf; |
| 9362 | if (length > 0) |
| 9363 | buf.resize(length); |
| 9364 | else |
| 9365 | buf.resize(256); |
| 9366 | |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9367 | DataExtractor cstr_data(&buf.front(), buf.size(), |
| 9368 | process->GetByteOrder(), 4); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9369 | buf.back() = '\0'; |
| 9370 | size_t bytes_read; |
| 9371 | size_t total_cstr_len = 0; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 9372 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9373 | while ((bytes_read = process->ReadMemory(pointer_address, &buf.front(), |
| 9374 | buf.size(), error)) > 0) { |
| 9375 | const size_t len = strlen((const char *)&buf.front()); |
| 9376 | if (len == 0) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9377 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9378 | if (total_cstr_len == 0) |
| 9379 | s->PutCString(" \""); |
Zachary Turner | 29cb868 | 2017-03-03 20:57:05 +0000 | [diff] [blame] | 9380 | DumpDataExtractor(cstr_data, s, 0, lldb::eFormatChar, 1, len, |
| 9381 | UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9382 | total_cstr_len += len; |
| 9383 | if (len < buf.size()) |
| 9384 | break; |
| 9385 | pointer_address += total_cstr_len; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9386 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9387 | if (total_cstr_len > 0) |
| 9388 | s->PutChar('"'); |
| 9389 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9390 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9391 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9392 | } |
| 9393 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9394 | void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type) { |
| 9395 | StreamFile s(stdout, false); |
| 9396 | DumpTypeDescription(type, &s); |
| 9397 | ClangASTMetadata *metadata = |
| 9398 | ClangASTContext::GetMetadata(getASTContext(), type); |
| 9399 | if (metadata) { |
| 9400 | metadata->Dump(&s); |
| 9401 | } |
| 9402 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9403 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9404 | void ClangASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, |
| 9405 | Stream *s) { |
| 9406 | if (type) { |
| 9407 | clang::QualType qual_type(GetQualType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9408 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9409 | llvm::SmallVector<char, 1024> buf; |
| 9410 | llvm::raw_svector_ostream llvm_ostrm(buf); |
| 9411 | |
| 9412 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 9413 | switch (type_class) { |
| 9414 | case clang::Type::ObjCObject: |
| 9415 | case clang::Type::ObjCInterface: { |
| 9416 | GetCompleteType(type); |
| 9417 | |
| 9418 | const clang::ObjCObjectType *objc_class_type = |
| 9419 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 9420 | assert(objc_class_type); |
| 9421 | if (objc_class_type) { |
| 9422 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 9423 | objc_class_type->getInterface(); |
| 9424 | if (class_interface_decl) { |
| 9425 | clang::PrintingPolicy policy = getASTContext()->getPrintingPolicy(); |
| 9426 | class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9427 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9428 | } |
| 9429 | } break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9430 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9431 | case clang::Type::Typedef: { |
| 9432 | const clang::TypedefType *typedef_type = |
| 9433 | qual_type->getAs<clang::TypedefType>(); |
| 9434 | if (typedef_type) { |
| 9435 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 9436 | std::string clang_typedef_name( |
| 9437 | typedef_decl->getQualifiedNameAsString()); |
| 9438 | if (!clang_typedef_name.empty()) { |
| 9439 | s->PutCString("typedef "); |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 9440 | s->PutCString(clang_typedef_name); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9441 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9442 | } |
| 9443 | } break; |
| 9444 | |
| 9445 | case clang::Type::Auto: |
| 9446 | CompilerType(getASTContext(), |
| 9447 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType()) |
| 9448 | .DumpTypeDescription(s); |
| 9449 | return; |
| 9450 | |
| 9451 | case clang::Type::Elaborated: |
| 9452 | CompilerType(getASTContext(), |
| 9453 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()) |
| 9454 | .DumpTypeDescription(s); |
| 9455 | return; |
| 9456 | |
| 9457 | case clang::Type::Paren: |
| 9458 | CompilerType(getASTContext(), |
| 9459 | llvm::cast<clang::ParenType>(qual_type)->desugar()) |
| 9460 | .DumpTypeDescription(s); |
| 9461 | return; |
| 9462 | |
| 9463 | case clang::Type::Record: { |
| 9464 | GetCompleteType(type); |
| 9465 | |
| 9466 | const clang::RecordType *record_type = |
| 9467 | llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 9468 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 9469 | const clang::CXXRecordDecl *cxx_record_decl = |
| 9470 | llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 9471 | |
| 9472 | if (cxx_record_decl) |
| 9473 | cxx_record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), |
| 9474 | s->GetIndentLevel()); |
| 9475 | else |
| 9476 | record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), |
| 9477 | s->GetIndentLevel()); |
| 9478 | } break; |
| 9479 | |
| 9480 | default: { |
| 9481 | const clang::TagType *tag_type = |
| 9482 | llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 9483 | if (tag_type) { |
| 9484 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 9485 | if (tag_decl) |
| 9486 | tag_decl->print(llvm_ostrm, 0); |
| 9487 | } else { |
| 9488 | std::string clang_type_name(qual_type.getAsString()); |
| 9489 | if (!clang_type_name.empty()) |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 9490 | s->PutCString(clang_type_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9491 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9492 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 9493 | } |
| 9494 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9495 | if (buf.size() > 0) { |
| 9496 | s->Write(buf.data(), buf.size()); |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9497 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9498 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9499 | } |
| 9500 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9501 | void ClangASTContext::DumpTypeName(const CompilerType &type) { |
| 9502 | if (ClangUtil::IsClangType(type)) { |
| 9503 | clang::QualType qual_type( |
| 9504 | ClangUtil::GetCanonicalQualType(ClangUtil::RemoveFastQualifiers(type))); |
| 9505 | |
| 9506 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 9507 | switch (type_class) { |
| 9508 | case clang::Type::Record: { |
| 9509 | const clang::CXXRecordDecl *cxx_record_decl = |
| 9510 | qual_type->getAsCXXRecordDecl(); |
| 9511 | if (cxx_record_decl) |
| 9512 | printf("class %s", cxx_record_decl->getName().str().c_str()); |
| 9513 | } break; |
| 9514 | |
| 9515 | case clang::Type::Enum: { |
| 9516 | clang::EnumDecl *enum_decl = |
| 9517 | llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 9518 | if (enum_decl) { |
| 9519 | printf("enum %s", enum_decl->getName().str().c_str()); |
| 9520 | } |
| 9521 | } break; |
| 9522 | |
| 9523 | case clang::Type::ObjCObject: |
| 9524 | case clang::Type::ObjCInterface: { |
| 9525 | const clang::ObjCObjectType *objc_class_type = |
| 9526 | llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 9527 | if (objc_class_type) { |
| 9528 | clang::ObjCInterfaceDecl *class_interface_decl = |
| 9529 | objc_class_type->getInterface(); |
| 9530 | // We currently can't complete objective C types through the newly added |
| 9531 | // ASTContext |
| 9532 | // because it only supports TagDecl objects right now... |
| 9533 | if (class_interface_decl) |
| 9534 | printf("@class %s", class_interface_decl->getName().str().c_str()); |
| 9535 | } |
| 9536 | } break; |
| 9537 | |
| 9538 | case clang::Type::Typedef: |
| 9539 | printf("typedef %s", llvm::cast<clang::TypedefType>(qual_type) |
| 9540 | ->getDecl() |
| 9541 | ->getName() |
| 9542 | .str() |
| 9543 | .c_str()); |
| 9544 | break; |
| 9545 | |
| 9546 | case clang::Type::Auto: |
| 9547 | printf("auto "); |
| 9548 | return DumpTypeName(CompilerType(type.GetTypeSystem(), |
| 9549 | llvm::cast<clang::AutoType>(qual_type) |
| 9550 | ->getDeducedType() |
| 9551 | .getAsOpaquePtr())); |
| 9552 | |
| 9553 | case clang::Type::Elaborated: |
| 9554 | printf("elaborated "); |
| 9555 | return DumpTypeName(CompilerType( |
| 9556 | type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type) |
| 9557 | ->getNamedType() |
| 9558 | .getAsOpaquePtr())); |
| 9559 | |
| 9560 | case clang::Type::Paren: |
| 9561 | printf("paren "); |
| 9562 | return DumpTypeName(CompilerType( |
| 9563 | type.GetTypeSystem(), |
| 9564 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())); |
| 9565 | |
| 9566 | default: |
| 9567 | printf("ClangASTContext::DumpTypeName() type_class = %u", type_class); |
| 9568 | break; |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9569 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9570 | } |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9571 | } |
| 9572 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9573 | clang::ClassTemplateDecl *ClangASTContext::ParseClassTemplateDecl( |
| 9574 | clang::DeclContext *decl_ctx, lldb::AccessType access_type, |
| 9575 | const char *parent_name, int tag_decl_kind, |
| 9576 | const ClangASTContext::TemplateParameterInfos &template_param_infos) { |
| 9577 | if (template_param_infos.IsValid()) { |
| 9578 | std::string template_basename(parent_name); |
| 9579 | template_basename.erase(template_basename.find('<')); |
| 9580 | |
| 9581 | return CreateClassTemplateDecl(decl_ctx, access_type, |
| 9582 | template_basename.c_str(), tag_decl_kind, |
| 9583 | template_param_infos); |
| 9584 | } |
| 9585 | return NULL; |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9586 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9587 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9588 | void ClangASTContext::CompleteTagDecl(void *baton, clang::TagDecl *decl) { |
| 9589 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 9590 | SymbolFile *sym_file = ast->GetSymbolFile(); |
| 9591 | if (sym_file) { |
| 9592 | CompilerType clang_type = GetTypeForDecl(decl); |
| 9593 | if (clang_type) |
| 9594 | sym_file->CompleteType(clang_type); |
| 9595 | } |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 9596 | } |
| 9597 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9598 | void ClangASTContext::CompleteObjCInterfaceDecl( |
| 9599 | void *baton, clang::ObjCInterfaceDecl *decl) { |
| 9600 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 9601 | SymbolFile *sym_file = ast->GetSymbolFile(); |
| 9602 | if (sym_file) { |
| 9603 | CompilerType clang_type = GetTypeForDecl(decl); |
| 9604 | if (clang_type) |
| 9605 | sym_file->CompleteType(clang_type); |
| 9606 | } |
Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 9607 | } |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 9608 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9609 | DWARFASTParser *ClangASTContext::GetDWARFParser() { |
| 9610 | if (!m_dwarf_ast_parser_ap) |
| 9611 | m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this)); |
| 9612 | return m_dwarf_ast_parser_ap.get(); |
| 9613 | } |
| 9614 | |
| 9615 | PDBASTParser *ClangASTContext::GetPDBParser() { |
| 9616 | if (!m_pdb_ast_parser_ap) |
| 9617 | m_pdb_ast_parser_ap.reset(new PDBASTParser(*this)); |
| 9618 | return m_pdb_ast_parser_ap.get(); |
| 9619 | } |
| 9620 | |
| 9621 | bool ClangASTContext::LayoutRecordType( |
| 9622 | void *baton, const clang::RecordDecl *record_decl, uint64_t &bit_size, |
| 9623 | uint64_t &alignment, |
| 9624 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
| 9625 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
| 9626 | &base_offsets, |
| 9627 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
| 9628 | &vbase_offsets) { |
| 9629 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 9630 | DWARFASTParserClang *dwarf_ast_parser = |
| 9631 | (DWARFASTParserClang *)ast->GetDWARFParser(); |
| 9632 | return dwarf_ast_parser->GetClangASTImporter().LayoutRecordType( |
| 9633 | record_decl, bit_size, alignment, field_offsets, base_offsets, |
| 9634 | vbase_offsets); |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9635 | } |
| 9636 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9637 | //---------------------------------------------------------------------- |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9638 | // CompilerDecl override functions |
| 9639 | //---------------------------------------------------------------------- |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9640 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9641 | ConstString ClangASTContext::DeclGetName(void *opaque_decl) { |
| 9642 | if (opaque_decl) { |
| 9643 | clang::NamedDecl *nd = |
| 9644 | llvm::dyn_cast<NamedDecl>((clang::Decl *)opaque_decl); |
| 9645 | if (nd != nullptr) |
| 9646 | return ConstString(nd->getDeclName().getAsString()); |
| 9647 | } |
| 9648 | return ConstString(); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9649 | } |
| 9650 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9651 | ConstString ClangASTContext::DeclGetMangledName(void *opaque_decl) { |
| 9652 | if (opaque_decl) { |
| 9653 | clang::NamedDecl *nd = |
| 9654 | llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)opaque_decl); |
| 9655 | if (nd != nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd)) { |
| 9656 | clang::MangleContext *mc = getMangleContext(); |
| 9657 | if (mc && mc->shouldMangleCXXName(nd)) { |
| 9658 | llvm::SmallVector<char, 1024> buf; |
| 9659 | llvm::raw_svector_ostream llvm_ostrm(buf); |
| 9660 | if (llvm::isa<clang::CXXConstructorDecl>(nd)) { |
| 9661 | mc->mangleCXXCtor(llvm::dyn_cast<clang::CXXConstructorDecl>(nd), |
| 9662 | Ctor_Complete, llvm_ostrm); |
| 9663 | } else if (llvm::isa<clang::CXXDestructorDecl>(nd)) { |
| 9664 | mc->mangleCXXDtor(llvm::dyn_cast<clang::CXXDestructorDecl>(nd), |
| 9665 | Dtor_Complete, llvm_ostrm); |
| 9666 | } else { |
| 9667 | mc->mangleName(nd, llvm_ostrm); |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9668 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9669 | if (buf.size() > 0) |
| 9670 | return ConstString(buf.data(), buf.size()); |
| 9671 | } |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9672 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9673 | } |
| 9674 | return ConstString(); |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9675 | } |
| 9676 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9677 | CompilerDeclContext ClangASTContext::DeclGetDeclContext(void *opaque_decl) { |
| 9678 | if (opaque_decl) |
| 9679 | return CompilerDeclContext(this, |
| 9680 | ((clang::Decl *)opaque_decl)->getDeclContext()); |
| 9681 | else |
| 9682 | return CompilerDeclContext(); |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9683 | } |
| 9684 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9685 | CompilerType ClangASTContext::DeclGetFunctionReturnType(void *opaque_decl) { |
| 9686 | if (clang::FunctionDecl *func_decl = |
| 9687 | llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) |
| 9688 | return CompilerType(this, func_decl->getReturnType().getAsOpaquePtr()); |
| 9689 | if (clang::ObjCMethodDecl *objc_method = |
| 9690 | llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl)) |
| 9691 | return CompilerType(this, objc_method->getReturnType().getAsOpaquePtr()); |
| 9692 | else |
Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9693 | return CompilerType(); |
| 9694 | } |
| 9695 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9696 | size_t ClangASTContext::DeclGetFunctionNumArguments(void *opaque_decl) { |
| 9697 | if (clang::FunctionDecl *func_decl = |
| 9698 | llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) |
| 9699 | return func_decl->param_size(); |
| 9700 | if (clang::ObjCMethodDecl *objc_method = |
| 9701 | llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl *)opaque_decl)) |
| 9702 | return objc_method->param_size(); |
| 9703 | else |
| 9704 | return 0; |
| 9705 | } |
| 9706 | |
| 9707 | CompilerType ClangASTContext::DeclGetFunctionArgumentType(void *opaque_decl, |
| 9708 | size_t idx) { |
| 9709 | if (clang::FunctionDecl *func_decl = |
| 9710 | llvm::dyn_cast<clang::FunctionDecl>((clang::Decl *)opaque_decl)) { |
| 9711 | if (idx < func_decl->param_size()) { |
| 9712 | ParmVarDecl *var_decl = func_decl->getParamDecl(idx); |
| 9713 | if (var_decl) |
| 9714 | return CompilerType(this, var_decl->getOriginalType().getAsOpaquePtr()); |
| 9715 | } |
| 9716 | } else if (clang::ObjCMethodDecl *objc_method = |
| 9717 | llvm::dyn_cast<clang::ObjCMethodDecl>( |
| 9718 | (clang::Decl *)opaque_decl)) { |
| 9719 | if (idx < objc_method->param_size()) |
| 9720 | return CompilerType( |
| 9721 | this, |
| 9722 | objc_method->parameters()[idx]->getOriginalType().getAsOpaquePtr()); |
| 9723 | } |
| 9724 | return CompilerType(); |
| 9725 | } |
| 9726 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9727 | //---------------------------------------------------------------------- |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9728 | // CompilerDeclContext functions |
| 9729 | //---------------------------------------------------------------------- |
| 9730 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9731 | std::vector<CompilerDecl> ClangASTContext::DeclContextFindDeclByName( |
| 9732 | void *opaque_decl_ctx, ConstString name, const bool ignore_using_decls) { |
| 9733 | std::vector<CompilerDecl> found_decls; |
| 9734 | if (opaque_decl_ctx) { |
| 9735 | DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx; |
| 9736 | std::set<DeclContext *> searched; |
| 9737 | std::multimap<DeclContext *, DeclContext *> search_queue; |
| 9738 | SymbolFile *symbol_file = GetSymbolFile(); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9739 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9740 | for (clang::DeclContext *decl_context = root_decl_ctx; |
| 9741 | decl_context != nullptr && found_decls.empty(); |
| 9742 | decl_context = decl_context->getParent()) { |
| 9743 | search_queue.insert(std::make_pair(decl_context, decl_context)); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9744 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9745 | for (auto it = search_queue.find(decl_context); it != search_queue.end(); |
| 9746 | it++) { |
| 9747 | if (!searched.insert(it->second).second) |
| 9748 | continue; |
| 9749 | symbol_file->ParseDeclsForContext( |
| 9750 | CompilerDeclContext(this, it->second)); |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9751 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9752 | for (clang::Decl *child : it->second->decls()) { |
| 9753 | if (clang::UsingDirectiveDecl *ud = |
| 9754 | llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) { |
| 9755 | if (ignore_using_decls) |
| 9756 | continue; |
| 9757 | clang::DeclContext *from = ud->getCommonAncestor(); |
| 9758 | if (searched.find(ud->getNominatedNamespace()) == searched.end()) |
| 9759 | search_queue.insert( |
| 9760 | std::make_pair(from, ud->getNominatedNamespace())); |
| 9761 | } else if (clang::UsingDecl *ud = |
| 9762 | llvm::dyn_cast<clang::UsingDecl>(child)) { |
| 9763 | if (ignore_using_decls) |
| 9764 | continue; |
| 9765 | for (clang::UsingShadowDecl *usd : ud->shadows()) { |
| 9766 | clang::Decl *target = usd->getTargetDecl(); |
| 9767 | if (clang::NamedDecl *nd = |
| 9768 | llvm::dyn_cast<clang::NamedDecl>(target)) { |
| 9769 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9770 | if (ii != nullptr && |
| 9771 | ii->getName().equals(name.AsCString(nullptr))) |
| 9772 | found_decls.push_back(CompilerDecl(this, nd)); |
| 9773 | } |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9774 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9775 | } else if (clang::NamedDecl *nd = |
| 9776 | llvm::dyn_cast<clang::NamedDecl>(child)) { |
| 9777 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9778 | if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) |
| 9779 | found_decls.push_back(CompilerDecl(this, nd)); |
| 9780 | } |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9781 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9782 | } |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9783 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9784 | } |
| 9785 | return found_decls; |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9786 | } |
| 9787 | |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9788 | // 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] | 9789 | // and return the number of levels it took to find it, or |
| 9790 | // LLDB_INVALID_DECL_LEVEL |
| 9791 | // if not found. If the decl was imported via a using declaration, its name |
| 9792 | // and/or |
| 9793 | // type, if set, will be used to check that the decl found in the scope is a |
| 9794 | // match. |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9795 | // |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9796 | // The optional name is required by languages (like C++) to handle using |
| 9797 | // declarations |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9798 | // like: |
| 9799 | // |
| 9800 | // void poo(); |
| 9801 | // namespace ns { |
| 9802 | // void foo(); |
| 9803 | // void goo(); |
| 9804 | // } |
| 9805 | // void bar() { |
| 9806 | // using ns::foo; |
| 9807 | // // CountDeclLevels returns 0 for 'foo', 1 for 'poo', and |
| 9808 | // // LLDB_INVALID_DECL_LEVEL for 'goo'. |
| 9809 | // } |
| 9810 | // |
| 9811 | // The optional type is useful in the case that there's a specific overload |
| 9812 | // that we're looking for that might otherwise be shadowed, like: |
| 9813 | // |
| 9814 | // void foo(int); |
| 9815 | // namespace ns { |
| 9816 | // void foo(); |
| 9817 | // } |
| 9818 | // void bar() { |
| 9819 | // using ns::foo; |
| 9820 | // // CountDeclLevels returns 0 for { 'foo', void() }, |
| 9821 | // // 1 for { 'foo', void(int) }, and |
| 9822 | // // LLDB_INVALID_DECL_LEVEL for { 'foo', void(int, int) }. |
| 9823 | // } |
| 9824 | // |
| 9825 | // NOTE: Because file statics are at the TranslationUnit along with globals, a |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9826 | // function at file scope will return the same level as a function at global |
| 9827 | // scope. |
| 9828 | // Ideally we'd like to treat the file scope as an additional scope just below |
| 9829 | // the |
| 9830 | // global scope. More work needs to be done to recognise that, if the decl |
| 9831 | // we're |
| 9832 | // trying to look up is static, we should compare its source file with that of |
| 9833 | // the |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9834 | // current scope and return a lower number for it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9835 | uint32_t ClangASTContext::CountDeclLevels(clang::DeclContext *frame_decl_ctx, |
| 9836 | clang::DeclContext *child_decl_ctx, |
| 9837 | ConstString *child_name, |
| 9838 | CompilerType *child_type) { |
| 9839 | if (frame_decl_ctx) { |
| 9840 | std::set<DeclContext *> searched; |
| 9841 | std::multimap<DeclContext *, DeclContext *> search_queue; |
| 9842 | SymbolFile *symbol_file = GetSymbolFile(); |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9843 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9844 | // Get the lookup scope for the decl we're trying to find. |
| 9845 | clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent(); |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9846 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9847 | // Look for it in our scope's decl context and its parents. |
| 9848 | uint32_t level = 0; |
| 9849 | for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx != nullptr; |
| 9850 | decl_ctx = decl_ctx->getParent()) { |
| 9851 | if (!decl_ctx->isLookupContext()) |
| 9852 | continue; |
| 9853 | if (decl_ctx == parent_decl_ctx) |
| 9854 | // Found it! |
| 9855 | return level; |
| 9856 | search_queue.insert(std::make_pair(decl_ctx, decl_ctx)); |
| 9857 | for (auto it = search_queue.find(decl_ctx); it != search_queue.end(); |
| 9858 | it++) { |
| 9859 | if (searched.find(it->second) != searched.end()) |
| 9860 | continue; |
| 9861 | |
| 9862 | // Currently DWARF has one shared translation unit for all Decls at top |
| 9863 | // level, so this |
| 9864 | // would erroneously find using statements anywhere. So don't look at |
| 9865 | // the top-level |
| 9866 | // translation unit. |
| 9867 | // TODO fix this and add a testcase that depends on it. |
| 9868 | |
| 9869 | if (llvm::isa<clang::TranslationUnitDecl>(it->second)) |
| 9870 | continue; |
| 9871 | |
| 9872 | searched.insert(it->second); |
| 9873 | symbol_file->ParseDeclsForContext( |
| 9874 | CompilerDeclContext(this, it->second)); |
| 9875 | |
| 9876 | for (clang::Decl *child : it->second->decls()) { |
| 9877 | if (clang::UsingDirectiveDecl *ud = |
| 9878 | llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) { |
| 9879 | clang::DeclContext *ns = ud->getNominatedNamespace(); |
| 9880 | if (ns == parent_decl_ctx) |
| 9881 | // Found it! |
| 9882 | return level; |
| 9883 | clang::DeclContext *from = ud->getCommonAncestor(); |
| 9884 | if (searched.find(ns) == searched.end()) |
| 9885 | search_queue.insert(std::make_pair(from, ns)); |
| 9886 | } else if (child_name) { |
| 9887 | if (clang::UsingDecl *ud = |
| 9888 | llvm::dyn_cast<clang::UsingDecl>(child)) { |
| 9889 | for (clang::UsingShadowDecl *usd : ud->shadows()) { |
| 9890 | clang::Decl *target = usd->getTargetDecl(); |
| 9891 | clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target); |
| 9892 | if (!nd) |
| 9893 | continue; |
| 9894 | // Check names. |
| 9895 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9896 | if (ii == nullptr || |
| 9897 | !ii->getName().equals(child_name->AsCString(nullptr))) |
| 9898 | continue; |
| 9899 | // Check types, if one was provided. |
| 9900 | if (child_type) { |
| 9901 | CompilerType clang_type = ClangASTContext::GetTypeForDecl(nd); |
| 9902 | if (!AreTypesSame(clang_type, *child_type, |
| 9903 | /*ignore_qualifiers=*/true)) |
| 9904 | continue; |
| 9905 | } |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9906 | // Found it! |
| 9907 | return level; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9908 | } |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9909 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9910 | } |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9911 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9912 | } |
| 9913 | ++level; |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9914 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9915 | } |
| 9916 | return LLDB_INVALID_DECL_LEVEL; |
Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9917 | } |
| 9918 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9919 | bool ClangASTContext::DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) { |
| 9920 | if (opaque_decl_ctx) |
| 9921 | return ((clang::DeclContext *)opaque_decl_ctx)->isRecord(); |
| 9922 | else |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9923 | return false; |
| 9924 | } |
| 9925 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9926 | ConstString ClangASTContext::DeclContextGetName(void *opaque_decl_ctx) { |
| 9927 | if (opaque_decl_ctx) { |
| 9928 | clang::NamedDecl *named_decl = |
| 9929 | llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); |
| 9930 | if (named_decl) |
| 9931 | return ConstString(named_decl->getName()); |
| 9932 | } |
| 9933 | return ConstString(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9934 | } |
| 9935 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9936 | ConstString |
| 9937 | ClangASTContext::DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) { |
| 9938 | if (opaque_decl_ctx) { |
| 9939 | clang::NamedDecl *named_decl = |
| 9940 | llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); |
| 9941 | if (named_decl) |
| 9942 | return ConstString( |
| 9943 | llvm::StringRef(named_decl->getQualifiedNameAsString())); |
| 9944 | } |
| 9945 | return ConstString(); |
| 9946 | } |
| 9947 | |
| 9948 | bool ClangASTContext::DeclContextIsClassMethod( |
| 9949 | void *opaque_decl_ctx, lldb::LanguageType *language_ptr, |
| 9950 | bool *is_instance_method_ptr, ConstString *language_object_name_ptr) { |
| 9951 | if (opaque_decl_ctx) { |
| 9952 | clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx; |
| 9953 | if (ObjCMethodDecl *objc_method = |
| 9954 | llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx)) { |
| 9955 | if (is_instance_method_ptr) |
| 9956 | *is_instance_method_ptr = objc_method->isInstanceMethod(); |
| 9957 | if (language_ptr) |
| 9958 | *language_ptr = eLanguageTypeObjC; |
| 9959 | if (language_object_name_ptr) |
| 9960 | language_object_name_ptr->SetCString("self"); |
| 9961 | return true; |
| 9962 | } else if (CXXMethodDecl *cxx_method = |
| 9963 | llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx)) { |
| 9964 | if (is_instance_method_ptr) |
| 9965 | *is_instance_method_ptr = cxx_method->isInstance(); |
| 9966 | if (language_ptr) |
| 9967 | *language_ptr = eLanguageTypeC_plus_plus; |
| 9968 | if (language_object_name_ptr) |
| 9969 | language_object_name_ptr->SetCString("this"); |
| 9970 | return true; |
| 9971 | } else if (clang::FunctionDecl *function_decl = |
| 9972 | llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) { |
| 9973 | ClangASTMetadata *metadata = |
| 9974 | GetMetadata(&decl_ctx->getParentASTContext(), function_decl); |
| 9975 | if (metadata && metadata->HasObjectPtr()) { |
| 9976 | if (is_instance_method_ptr) |
| 9977 | *is_instance_method_ptr = true; |
| 9978 | if (language_ptr) |
| 9979 | *language_ptr = eLanguageTypeObjC; |
| 9980 | if (language_object_name_ptr) |
| 9981 | language_object_name_ptr->SetCString(metadata->GetObjectPtrName()); |
| 9982 | return true; |
| 9983 | } |
| 9984 | } |
| 9985 | } |
| 9986 | return false; |
| 9987 | } |
| 9988 | |
| 9989 | clang::DeclContext * |
| 9990 | ClangASTContext::DeclContextGetAsDeclContext(const CompilerDeclContext &dc) { |
| 9991 | if (dc.IsClang()) |
| 9992 | return (clang::DeclContext *)dc.GetOpaqueDeclContext(); |
| 9993 | return nullptr; |
| 9994 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9995 | |
| 9996 | ObjCMethodDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 9997 | ClangASTContext::DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc) { |
| 9998 | if (dc.IsClang()) |
| 9999 | return llvm::dyn_cast<clang::ObjCMethodDecl>( |
| 10000 | (clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 10001 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10002 | } |
| 10003 | |
| 10004 | CXXMethodDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10005 | ClangASTContext::DeclContextGetAsCXXMethodDecl(const CompilerDeclContext &dc) { |
| 10006 | if (dc.IsClang()) |
| 10007 | return llvm::dyn_cast<clang::CXXMethodDecl>( |
| 10008 | (clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 10009 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10010 | } |
| 10011 | |
| 10012 | clang::FunctionDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10013 | ClangASTContext::DeclContextGetAsFunctionDecl(const CompilerDeclContext &dc) { |
| 10014 | if (dc.IsClang()) |
| 10015 | return llvm::dyn_cast<clang::FunctionDecl>( |
| 10016 | (clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 10017 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10018 | } |
| 10019 | |
| 10020 | clang::NamespaceDecl * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10021 | ClangASTContext::DeclContextGetAsNamespaceDecl(const CompilerDeclContext &dc) { |
| 10022 | if (dc.IsClang()) |
| 10023 | return llvm::dyn_cast<clang::NamespaceDecl>( |
| 10024 | (clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 10025 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10026 | } |
| 10027 | |
| 10028 | ClangASTMetadata * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10029 | ClangASTContext::DeclContextGetMetaData(const CompilerDeclContext &dc, |
| 10030 | const void *object) { |
| 10031 | clang::ASTContext *ast = DeclContextGetClangASTContext(dc); |
| 10032 | if (ast) |
| 10033 | return ClangASTContext::GetMetadata(ast, object); |
| 10034 | return nullptr; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10035 | } |
| 10036 | |
| 10037 | clang::ASTContext * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10038 | ClangASTContext::DeclContextGetClangASTContext(const CompilerDeclContext &dc) { |
| 10039 | ClangASTContext *ast = |
| 10040 | llvm::dyn_cast_or_null<ClangASTContext>(dc.GetTypeSystem()); |
| 10041 | if (ast) |
| 10042 | return ast->getASTContext(); |
| 10043 | return nullptr; |
| 10044 | } |
| 10045 | |
| 10046 | ClangASTContextForExpressions::ClangASTContextForExpressions(Target &target) |
| 10047 | : ClangASTContext(target.GetArchitecture().GetTriple().getTriple().c_str()), |
| 10048 | m_target_wp(target.shared_from_this()), |
| 10049 | m_persistent_variables(new ClangPersistentVariables) {} |
| 10050 | |
| 10051 | UserExpression *ClangASTContextForExpressions::GetUserExpression( |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 10052 | llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10053 | Expression::ResultType desired_type, |
| 10054 | const EvaluateExpressionOptions &options) { |
| 10055 | TargetSP target_sp = m_target_wp.lock(); |
| 10056 | if (!target_sp) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10057 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10058 | |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 10059 | return new ClangUserExpression(*target_sp.get(), expr, prefix, language, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10060 | desired_type, options); |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 10061 | } |
| 10062 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10063 | FunctionCaller *ClangASTContextForExpressions::GetFunctionCaller( |
| 10064 | const CompilerType &return_type, const Address &function_address, |
| 10065 | const ValueList &arg_value_list, const char *name) { |
| 10066 | TargetSP target_sp = m_target_wp.lock(); |
| 10067 | if (!target_sp) |
| 10068 | return nullptr; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10069 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10070 | Process *process = target_sp->GetProcessSP().get(); |
| 10071 | if (!process) |
| 10072 | return nullptr; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10073 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10074 | return new ClangFunctionCaller(*process, return_type, function_address, |
| 10075 | arg_value_list, name); |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10076 | } |
| 10077 | |
| 10078 | UtilityFunction * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10079 | ClangASTContextForExpressions::GetUtilityFunction(const char *text, |
| 10080 | const char *name) { |
| 10081 | TargetSP target_sp = m_target_wp.lock(); |
| 10082 | if (!target_sp) |
| 10083 | return nullptr; |
| 10084 | |
| 10085 | return new ClangUtilityFunction(*target_sp.get(), text, name); |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10086 | } |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 10087 | |
| 10088 | PersistentExpressionState * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10089 | ClangASTContextForExpressions::GetPersistentExpressionState() { |
| 10090 | return m_persistent_variables.get(); |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 10091 | } |
Sean Callanan | 68e4423 | 2017-09-28 20:20:25 +0000 | [diff] [blame] | 10092 | |
| 10093 | clang::ExternalASTMerger & |
| 10094 | ClangASTContextForExpressions::GetMergerUnchecked() { |
Eugene Zemtsov | a9d928c | 2017-09-29 03:15:08 +0000 | [diff] [blame] | 10095 | lldbassert(m_scratch_ast_source_ap != nullptr); |
Sean Callanan | 68e4423 | 2017-09-28 20:20:25 +0000 | [diff] [blame] | 10096 | return m_scratch_ast_source_ap->GetMergerUnchecked(); |
| 10097 | } |