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 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
Greg Clayton | ff48e4b | 2015-02-03 02:05:44 +0000 | [diff] [blame] | 14 | #include <mutex> // std::once |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | |
| 17 | // Other libraries and framework includes |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 18 | |
| 19 | // Clang headers like to use NDEBUG inside of them to enable/disable debug |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 20 | // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 21 | // or another. This is bad because it means that if clang was built in release |
| 22 | // mode, it assumes that you are building in release mode which is not always |
| 23 | // the case. You can end up with functions that are defined as empty in header |
| 24 | // files when NDEBUG is not defined, and this can cause link errors with the |
| 25 | // clang .a files that you have since you might be missing functions in the .a |
| 26 | // file. So we have to define NDEBUG when including clang headers to avoid any |
| 27 | // mismatches. This is covered by rdar://problem/8691220 |
| 28 | |
Sean Callanan | 3b1d4f6 | 2011-10-26 17:46:51 +0000 | [diff] [blame] | 29 | #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 30 | #define LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 31 | #define NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 32 | // Need to include assert.h so it is as clang would expect it to be (disabled) |
| 33 | #include <assert.h> |
| 34 | #endif |
| 35 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "clang/AST/ASTContext.h" |
| 37 | #include "clang/AST/ASTImporter.h" |
Greg Clayton | f74c403 | 2012-12-03 18:29:55 +0000 | [diff] [blame] | 38 | #include "clang/AST/Attr.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "clang/AST/CXXInheritance.h" |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 40 | #include "clang/AST/DeclObjC.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 41 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | #include "clang/AST/RecordLayout.h" |
| 43 | #include "clang/AST/Type.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 44 | #include "clang/AST/VTableBuilder.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | #include "clang/Basic/Builtins.h" |
Sean Callanan | 7e2863b | 2012-02-06 21:28:03 +0000 | [diff] [blame] | 46 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | #include "clang/Basic/FileManager.h" |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileSystemOptions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | #include "clang/Basic/SourceManager.h" |
| 50 | #include "clang/Basic/TargetInfo.h" |
| 51 | #include "clang/Basic/TargetOptions.h" |
| 52 | #include "clang/Frontend/FrontendOptions.h" |
| 53 | #include "clang/Frontend/LangStandard.h" |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 54 | |
| 55 | #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 56 | #undef NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 57 | #undef LLDB_DEFINED_NDEBUG_FOR_CLANG |
| 58 | // Need to re-include assert.h so it is as _we_ would expect it to be (enabled) |
| 59 | #include <assert.h> |
| 60 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 62 | #include "llvm/Support/Signals.h" |
| 63 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 64 | #include "lldb/Core/ArchSpec.h" |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 65 | #include "lldb/Core/Flags.h" |
Sean Callanan | fb8b709 | 2010-10-28 18:19:36 +0000 | [diff] [blame] | 66 | #include "lldb/Core/Log.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 67 | #include "lldb/Core/Module.h" |
| 68 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 69 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 70 | #include "lldb/Core/StreamFile.h" |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 71 | #include "lldb/Core/ThreadSafeDenseMap.h" |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 72 | #include "lldb/Core/UniqueCStringMap.h" |
Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 73 | #include "Plugins/ExpressionParser/Clang/ClangUserExpression.h" |
| 74 | #include "Plugins/ExpressionParser/Clang/ClangFunctionCaller.h" |
| 75 | #include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h" |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 76 | #include "lldb/Symbol/ClangASTContext.h" |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 77 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" |
Sean Callanan | 3b107b1 | 2011-12-03 03:15:28 +0000 | [diff] [blame] | 78 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 79 | #include "lldb/Symbol/ObjectFile.h" |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 80 | #include "lldb/Symbol/SymbolFile.h" |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 81 | #include "lldb/Symbol/VerifyDecl.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 82 | #include "lldb/Target/ExecutionContext.h" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 83 | #include "lldb/Target/Language.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 84 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 85 | #include "lldb/Target/Process.h" |
| 86 | #include "lldb/Target/Target.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 87 | |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 88 | #include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h" |
| 89 | |
Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 90 | #include <stdio.h> |
| 91 | |
Greg Clayton | 1341baf | 2013-07-11 23:36:31 +0000 | [diff] [blame] | 92 | #include <mutex> |
| 93 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 94 | using namespace lldb; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 95 | using namespace lldb_private; |
| 96 | using namespace llvm; |
| 97 | using namespace clang; |
| 98 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 99 | namespace |
| 100 | { |
| 101 | static inline bool ClangASTContextSupportsLanguage (lldb::LanguageType language) |
| 102 | { |
| 103 | return language == eLanguageTypeUnknown || // Clang is the default type system |
| 104 | Language::LanguageIsC (language) || |
| 105 | Language::LanguageIsCPlusPlus (language) || |
| 106 | Language::LanguageIsObjC (language); |
| 107 | } |
| 108 | } |
| 109 | |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 110 | typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, ClangASTContext*> ClangASTMap; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 111 | |
| 112 | static ClangASTMap & |
| 113 | GetASTMap() |
| 114 | { |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 115 | static ClangASTMap *g_map_ptr = nullptr; |
| 116 | static std::once_flag g_once_flag; |
| 117 | std::call_once(g_once_flag, []() { |
| 118 | g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins |
| 119 | }); |
| 120 | return *g_map_ptr; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 124 | clang::AccessSpecifier |
| 125 | ClangASTContext::ConvertAccessTypeToAccessSpecifier (AccessType access) |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 126 | { |
| 127 | switch (access) |
| 128 | { |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 129 | default: break; |
| 130 | case eAccessNone: return AS_none; |
| 131 | case eAccessPublic: return AS_public; |
| 132 | case eAccessPrivate: return AS_private; |
| 133 | case eAccessProtected: return AS_protected; |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 134 | } |
| 135 | return AS_none; |
| 136 | } |
| 137 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 138 | static void |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 139 | ParseLangArgs (LangOptions &Opts, InputKind IK, const char* triple) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | { |
| 141 | // FIXME: Cleanup per-file based stuff. |
| 142 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 143 | // Set some properties which depend solely on the input kind; it would be nice |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | // to move these to the language standard, and have the driver resolve the |
| 145 | // input kind + language standard. |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 146 | if (IK == IK_Asm) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 147 | Opts.AsmPreprocessor = 1; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 148 | } else if (IK == IK_ObjC || |
| 149 | IK == IK_ObjCXX || |
| 150 | IK == IK_PreprocessedObjC || |
| 151 | IK == IK_PreprocessedObjCXX) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | Opts.ObjC1 = Opts.ObjC2 = 1; |
| 153 | } |
| 154 | |
| 155 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 156 | |
| 157 | if (LangStd == LangStandard::lang_unspecified) { |
| 158 | // Based on the base language, pick one. |
| 159 | switch (IK) { |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 160 | case IK_None: |
| 161 | case IK_AST: |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 162 | case IK_LLVM_IR: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 163 | assert (!"Invalid input kind!"); |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 164 | case IK_OpenCL: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | LangStd = LangStandard::lang_opencl; |
| 166 | break; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 167 | case IK_CUDA: |
Artem Belevich | 52210ae | 2015-03-19 18:12:26 +0000 | [diff] [blame] | 168 | case IK_PreprocessedCuda: |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 169 | LangStd = LangStandard::lang_cuda; |
| 170 | break; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 171 | case IK_Asm: |
| 172 | case IK_C: |
| 173 | case IK_PreprocessedC: |
| 174 | case IK_ObjC: |
| 175 | case IK_PreprocessedObjC: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 176 | LangStd = LangStandard::lang_gnu99; |
| 177 | break; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 178 | case IK_CXX: |
| 179 | case IK_PreprocessedCXX: |
| 180 | case IK_ObjCXX: |
| 181 | case IK_PreprocessedObjCXX: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | LangStd = LangStandard::lang_gnucxx98; |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
Filipe Cabecinhas | e818ca2 | 2012-11-12 21:26:32 +0000 | [diff] [blame] | 188 | Opts.LineComment = Std.hasLineComments(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | Opts.C99 = Std.isC99(); |
| 190 | Opts.CPlusPlus = Std.isCPlusPlus(); |
Chandler Carruth | 38336a1 | 2013-01-02 12:55:00 +0000 | [diff] [blame] | 191 | Opts.CPlusPlus11 = Std.isCPlusPlus11(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | Opts.Digraphs = Std.hasDigraphs(); |
| 193 | Opts.GNUMode = Std.isGNUMode(); |
| 194 | Opts.GNUInline = !Std.isC99(); |
| 195 | Opts.HexFloats = Std.hasHexFloats(); |
| 196 | Opts.ImplicitInt = Std.hasImplicitInt(); |
Enrico Granata | c921e34 | 2013-01-10 02:37:22 +0000 | [diff] [blame] | 197 | |
| 198 | Opts.WChar = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | |
| 200 | // OpenCL has some additional defaults. |
| 201 | if (LangStd == LangStandard::lang_opencl) { |
| 202 | Opts.OpenCL = 1; |
| 203 | Opts.AltiVec = 1; |
| 204 | Opts.CXXOperatorNames = 1; |
| 205 | Opts.LaxVectorConversions = 1; |
| 206 | } |
| 207 | |
| 208 | // OpenCL and C++ both have bool, true, false keywords. |
| 209 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
| 210 | |
| 211 | // if (Opts.CPlusPlus) |
| 212 | // Opts.CXXOperatorNames = !Args.hasArg(OPT_fno_operator_names); |
| 213 | // |
| 214 | // if (Args.hasArg(OPT_fobjc_gc_only)) |
| 215 | // Opts.setGCMode(LangOptions::GCOnly); |
| 216 | // else if (Args.hasArg(OPT_fobjc_gc)) |
| 217 | // Opts.setGCMode(LangOptions::HybridGC); |
| 218 | // |
| 219 | // if (Args.hasArg(OPT_print_ivar_layout)) |
| 220 | // Opts.ObjCGCBitmapPrint = 1; |
| 221 | // |
| 222 | // if (Args.hasArg(OPT_faltivec)) |
| 223 | // Opts.AltiVec = 1; |
| 224 | // |
| 225 | // if (Args.hasArg(OPT_pthread)) |
| 226 | // Opts.POSIXThreads = 1; |
| 227 | // |
| 228 | // llvm::StringRef Vis = getLastArgValue(Args, OPT_fvisibility, |
| 229 | // "default"); |
| 230 | // if (Vis == "default") |
Sean Callanan | 37f76e5 | 2013-02-19 19:16:37 +0000 | [diff] [blame] | 231 | Opts.setValueVisibilityMode(DefaultVisibility); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 232 | // else if (Vis == "hidden") |
| 233 | // Opts.setVisibilityMode(LangOptions::Hidden); |
| 234 | // else if (Vis == "protected") |
| 235 | // Opts.setVisibilityMode(LangOptions::Protected); |
| 236 | // else |
| 237 | // Diags.Report(diag::err_drv_invalid_value) |
| 238 | // << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis; |
| 239 | |
| 240 | // Opts.OverflowChecking = Args.hasArg(OPT_ftrapv); |
| 241 | |
| 242 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 243 | // is specified, or -std is set to a conforming mode. |
| 244 | Opts.Trigraphs = !Opts.GNUMode; |
| 245 | // if (Args.hasArg(OPT_trigraphs)) |
| 246 | // Opts.Trigraphs = 1; |
| 247 | // |
| 248 | // Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, |
| 249 | // OPT_fno_dollars_in_identifiers, |
| 250 | // !Opts.AsmPreprocessor); |
| 251 | // Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); |
| 252 | // Opts.Microsoft = Args.hasArg(OPT_fms_extensions); |
| 253 | // Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); |
| 254 | // if (Args.hasArg(OPT_fno_lax_vector_conversions)) |
| 255 | // Opts.LaxVectorConversions = 0; |
| 256 | // Opts.Exceptions = Args.hasArg(OPT_fexceptions); |
| 257 | // Opts.RTTI = !Args.hasArg(OPT_fno_rtti); |
| 258 | // Opts.Blocks = Args.hasArg(OPT_fblocks); |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 259 | Opts.CharIsSigned = ArchSpec(triple).CharIsSignedByDefault(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 260 | // Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar); |
| 261 | // Opts.Freestanding = Args.hasArg(OPT_ffreestanding); |
| 262 | // Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; |
| 263 | // Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); |
| 264 | // Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); |
| 265 | // Opts.AccessControl = Args.hasArg(OPT_faccess_control); |
| 266 | // Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); |
| 267 | // Opts.MathErrno = !Args.hasArg(OPT_fno_math_errno); |
| 268 | // Opts.InstantiationDepth = getLastArgIntValue(Args, OPT_ftemplate_depth, 99, |
| 269 | // Diags); |
| 270 | // Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime); |
| 271 | // Opts.ObjCConstantStringClass = getLastArgValue(Args, |
| 272 | // OPT_fconstant_string_class); |
| 273 | // Opts.ObjCNonFragileABI = Args.hasArg(OPT_fobjc_nonfragile_abi); |
| 274 | // Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior); |
| 275 | // Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); |
| 276 | // Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); |
| 277 | // Opts.Static = Args.hasArg(OPT_static_define); |
| 278 | Opts.OptimizeSize = 0; |
| 279 | |
| 280 | // FIXME: Eliminate this dependency. |
| 281 | // unsigned Opt = |
| 282 | // Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags); |
| 283 | // Opts.Optimize = Opt != 0; |
| 284 | unsigned Opt = 0; |
| 285 | |
| 286 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 287 | // optimization level and -fno-inline, not actually whether the backend has |
| 288 | // inlining enabled. |
| 289 | // |
| 290 | // FIXME: This is affected by other options (-fno-inline). |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 291 | Opts.NoInlineDefine = !Opt; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | |
| 293 | // unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags); |
| 294 | // switch (SSP) { |
| 295 | // default: |
| 296 | // Diags.Report(diag::err_drv_invalid_value) |
| 297 | // << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; |
| 298 | // break; |
| 299 | // case 0: Opts.setStackProtectorMode(LangOptions::SSPOff); break; |
| 300 | // case 1: Opts.setStackProtectorMode(LangOptions::SSPOn); break; |
| 301 | // case 2: Opts.setStackProtectorMode(LangOptions::SSPReq); break; |
| 302 | // } |
| 303 | } |
| 304 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 305 | |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 306 | ClangASTContext::ClangASTContext (const char *target_triple) : |
| 307 | TypeSystem (TypeSystem::eKindClang), |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 308 | m_target_triple (), |
| 309 | m_ast_ap (), |
| 310 | m_language_options_ap (), |
| 311 | m_source_manager_ap (), |
| 312 | m_diagnostics_engine_ap (), |
| 313 | m_target_options_rp (), |
| 314 | m_target_info_ap (), |
| 315 | m_identifier_table_ap (), |
| 316 | m_selector_table_ap (), |
| 317 | m_builtins_ap (), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 318 | m_callback_tag_decl (nullptr), |
| 319 | m_callback_objc_decl (nullptr), |
| 320 | m_callback_baton (nullptr), |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 321 | m_pointer_byte_size (0), |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 322 | m_ast_owned (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 323 | { |
| 324 | if (target_triple && target_triple[0]) |
Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 325 | SetTargetTriple (target_triple); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | //---------------------------------------------------------------------- |
| 329 | // Destructor |
| 330 | //---------------------------------------------------------------------- |
| 331 | ClangASTContext::~ClangASTContext() |
| 332 | { |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 333 | if (m_ast_ap.get()) |
| 334 | { |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 335 | GetASTMap().Erase(m_ast_ap.get()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 336 | if (!m_ast_owned) |
| 337 | m_ast_ap.release(); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | m_builtins_ap.reset(); |
| 341 | m_selector_table_ap.reset(); |
| 342 | m_identifier_table_ap.reset(); |
| 343 | m_target_info_ap.reset(); |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 344 | m_target_options_rp.reset(); |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 345 | m_diagnostics_engine_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | m_source_manager_ap.reset(); |
| 347 | m_language_options_ap.reset(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 348 | m_ast_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 351 | ConstString |
| 352 | ClangASTContext::GetPluginNameStatic() |
| 353 | { |
| 354 | return ConstString("clang"); |
| 355 | } |
| 356 | |
| 357 | ConstString |
| 358 | ClangASTContext::GetPluginName() |
| 359 | { |
| 360 | return ClangASTContext::GetPluginNameStatic(); |
| 361 | } |
| 362 | |
| 363 | uint32_t |
| 364 | ClangASTContext::GetPluginVersion() |
| 365 | { |
| 366 | return 1; |
| 367 | } |
| 368 | |
| 369 | lldb::TypeSystemSP |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 370 | ClangASTContext::CreateInstance (lldb::LanguageType language, Module *module, Target *target) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 371 | { |
| 372 | if (ClangASTContextSupportsLanguage(language)) |
| 373 | { |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 374 | ArchSpec arch; |
| 375 | if (module) |
| 376 | arch = module->GetArchitecture(); |
| 377 | else if (target) |
| 378 | arch = target->GetArchitecture(); |
| 379 | |
| 380 | if (arch.IsValid()) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 381 | { |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 382 | ArchSpec fixed_arch = arch; |
| 383 | // LLVM wants this to be set to iOS or MacOSX; if we're working on |
| 384 | // a bare-boards type image, change the triple for llvm's benefit. |
| 385 | if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple && |
| 386 | fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 387 | { |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 388 | if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm || |
| 389 | fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 || |
| 390 | fixed_arch.GetTriple().getArch() == llvm::Triple::thumb) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 391 | { |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 392 | fixed_arch.GetTriple().setOS(llvm::Triple::IOS); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 393 | } |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 394 | else |
| 395 | { |
| 396 | fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (module) |
| 401 | { |
| 402 | std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext); |
| 403 | if (ast_sp) |
| 404 | { |
| 405 | ast_sp->SetArchitecture (fixed_arch); |
| 406 | } |
| 407 | return ast_sp; |
| 408 | } |
| 409 | else if (target) |
| 410 | { |
| 411 | std::shared_ptr<ClangASTContextForExpressions> ast_sp(new ClangASTContextForExpressions(*target)); |
| 412 | if (ast_sp) |
| 413 | { |
| 414 | ast_sp->SetArchitecture(fixed_arch); |
| 415 | ast_sp->m_scratch_ast_source_ap.reset (new ClangASTSource(target->shared_from_this())); |
| 416 | ast_sp->m_scratch_ast_source_ap->InstallASTContext(ast_sp->getASTContext()); |
| 417 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(ast_sp->m_scratch_ast_source_ap->CreateProxy()); |
| 418 | ast_sp->SetExternalSource(proxy_ast_source); |
| 419 | return ast_sp; |
| 420 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 421 | } |
| 422 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 423 | } |
| 424 | return lldb::TypeSystemSP(); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | void |
| 429 | ClangASTContext::Initialize() |
| 430 | { |
| 431 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 432 | "clang base AST context plug-in", |
| 433 | CreateInstance); |
| 434 | } |
| 435 | |
| 436 | void |
| 437 | ClangASTContext::Terminate() |
| 438 | { |
| 439 | PluginManager::UnregisterPlugin (CreateInstance); |
| 440 | } |
| 441 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 442 | |
| 443 | void |
| 444 | ClangASTContext::Clear() |
| 445 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 446 | m_ast_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | m_language_options_ap.reset(); |
| 448 | m_source_manager_ap.reset(); |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 449 | m_diagnostics_engine_ap.reset(); |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 450 | m_target_options_rp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 451 | m_target_info_ap.reset(); |
| 452 | m_identifier_table_ap.reset(); |
| 453 | m_selector_table_ap.reset(); |
| 454 | m_builtins_ap.reset(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 455 | m_pointer_byte_size = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | const char * |
| 459 | ClangASTContext::GetTargetTriple () |
| 460 | { |
| 461 | return m_target_triple.c_str(); |
| 462 | } |
| 463 | |
| 464 | void |
| 465 | ClangASTContext::SetTargetTriple (const char *target_triple) |
| 466 | { |
| 467 | Clear(); |
| 468 | m_target_triple.assign(target_triple); |
| 469 | } |
| 470 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 471 | void |
| 472 | ClangASTContext::SetArchitecture (const ArchSpec &arch) |
| 473 | { |
Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 474 | SetTargetTriple(arch.GetTriple().str().c_str()); |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 477 | bool |
| 478 | ClangASTContext::HasExternalSource () |
| 479 | { |
| 480 | ASTContext *ast = getASTContext(); |
| 481 | if (ast) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 482 | return ast->getExternalSource () != nullptr; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 483 | return false; |
| 484 | } |
| 485 | |
| 486 | void |
Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 487 | ClangASTContext::SetExternalSource (llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_ap) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 488 | { |
| 489 | ASTContext *ast = getASTContext(); |
| 490 | if (ast) |
| 491 | { |
| 492 | ast->setExternalSource (ast_source_ap); |
| 493 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true); |
| 494 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(true); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | void |
| 499 | ClangASTContext::RemoveExternalSource () |
| 500 | { |
| 501 | ASTContext *ast = getASTContext(); |
| 502 | |
| 503 | if (ast) |
| 504 | { |
Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 505 | llvm::IntrusiveRefCntPtr<ExternalASTSource> empty_ast_source_ap; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 506 | ast->setExternalSource (empty_ast_source_ap); |
| 507 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(false); |
| 508 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(false); |
| 509 | } |
| 510 | } |
| 511 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 512 | void |
| 513 | ClangASTContext::setASTContext(clang::ASTContext *ast_ctx) |
| 514 | { |
| 515 | if (!m_ast_owned) { |
| 516 | m_ast_ap.release(); |
| 517 | } |
| 518 | m_ast_owned = false; |
| 519 | m_ast_ap.reset(ast_ctx); |
| 520 | GetASTMap().Insert(ast_ctx, this); |
| 521 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 522 | |
| 523 | ASTContext * |
| 524 | ClangASTContext::getASTContext() |
| 525 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 526 | if (m_ast_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 527 | { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 528 | m_ast_owned = true; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 529 | m_ast_ap.reset(new ASTContext (*getLanguageOptions(), |
| 530 | *getSourceManager(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 531 | *getIdentifierTable(), |
| 532 | *getSelectorTable(), |
Alp Toker | cf55e88 | 2014-05-03 15:05:45 +0000 | [diff] [blame] | 533 | *getBuiltinContext())); |
Sean Callanan | 6d61b63 | 2015-04-09 17:42:48 +0000 | [diff] [blame] | 534 | |
| 535 | m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false); |
Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 536 | |
| 537 | // This can be NULL if we don't know anything about the architecture or if the |
| 538 | // target for an architecture isn't enabled in the llvm/clang that we built |
| 539 | TargetInfo *target_info = getTargetInfo(); |
| 540 | if (target_info) |
| 541 | m_ast_ap->InitBuiltinTypes(*target_info); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 542 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 543 | if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton) |
| 544 | { |
| 545 | m_ast_ap->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
| 546 | //m_ast_ap->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 547 | } |
| 548 | |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 549 | GetASTMap().Insert(m_ast_ap.get(), this); |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 550 | |
| 551 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (new ClangExternalASTSourceCallbacks (ClangASTContext::CompleteTagDecl, |
| 552 | ClangASTContext::CompleteObjCInterfaceDecl, |
| 553 | nullptr, |
| 554 | ClangASTContext::LayoutRecordType, |
| 555 | this)); |
| 556 | SetExternalSource (ast_source_ap); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 557 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 558 | return m_ast_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 561 | ClangASTContext* |
| 562 | ClangASTContext::GetASTContext (clang::ASTContext* ast) |
| 563 | { |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 564 | ClangASTContext *clang_ast = GetASTMap().Lookup(ast); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 565 | return clang_ast; |
| 566 | } |
| 567 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | Builtin::Context * |
| 569 | ClangASTContext::getBuiltinContext() |
| 570 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 571 | if (m_builtins_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 572 | m_builtins_ap.reset (new Builtin::Context()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 573 | return m_builtins_ap.get(); |
| 574 | } |
| 575 | |
| 576 | IdentifierTable * |
| 577 | ClangASTContext::getIdentifierTable() |
| 578 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 579 | if (m_identifier_table_ap.get() == nullptr) |
| 580 | m_identifier_table_ap.reset(new IdentifierTable (*ClangASTContext::getLanguageOptions(), nullptr)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 581 | return m_identifier_table_ap.get(); |
| 582 | } |
| 583 | |
| 584 | LangOptions * |
| 585 | ClangASTContext::getLanguageOptions() |
| 586 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 587 | if (m_language_options_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 588 | { |
| 589 | m_language_options_ap.reset(new LangOptions()); |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 590 | ParseLangArgs(*m_language_options_ap, IK_ObjCXX, GetTargetTriple()); |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 591 | // InitializeLangOptions(*m_language_options_ap, IK_ObjCXX); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 592 | } |
| 593 | return m_language_options_ap.get(); |
| 594 | } |
| 595 | |
| 596 | SelectorTable * |
| 597 | ClangASTContext::getSelectorTable() |
| 598 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 599 | if (m_selector_table_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 600 | m_selector_table_ap.reset (new SelectorTable()); |
| 601 | return m_selector_table_ap.get(); |
| 602 | } |
| 603 | |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 604 | clang::FileManager * |
| 605 | ClangASTContext::getFileManager() |
| 606 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 607 | if (m_file_manager_ap.get() == nullptr) |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 608 | { |
| 609 | clang::FileSystemOptions file_system_options; |
| 610 | m_file_manager_ap.reset(new clang::FileManager(file_system_options)); |
| 611 | } |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 612 | return m_file_manager_ap.get(); |
| 613 | } |
| 614 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 615 | clang::SourceManager * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 616 | ClangASTContext::getSourceManager() |
| 617 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 618 | if (m_source_manager_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 619 | m_source_manager_ap.reset(new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 | return m_source_manager_ap.get(); |
| 621 | } |
| 622 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 623 | clang::DiagnosticsEngine * |
| 624 | ClangASTContext::getDiagnosticsEngine() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 626 | if (m_diagnostics_engine_ap.get() == nullptr) |
Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 627 | { |
| 628 | llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs()); |
Sean Callanan | ec8f1ef | 2012-10-25 01:00:25 +0000 | [diff] [blame] | 629 | m_diagnostics_engine_ap.reset(new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions())); |
Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 630 | } |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 631 | return m_diagnostics_engine_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 634 | class NullDiagnosticConsumer : public DiagnosticConsumer |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 635 | { |
| 636 | public: |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 637 | NullDiagnosticConsumer () |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 638 | { |
| 639 | m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 640 | } |
| 641 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 642 | void HandleDiagnostic (DiagnosticsEngine::Level DiagLevel, const Diagnostic &info) |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 643 | { |
| 644 | if (m_log) |
| 645 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 646 | llvm::SmallVector<char, 32> diag_str(10); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 647 | info.FormatDiagnostic(diag_str); |
| 648 | diag_str.push_back('\0'); |
| 649 | m_log->Printf("Compiler diagnostic: %s\n", diag_str.data()); |
| 650 | } |
| 651 | } |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 652 | |
| 653 | DiagnosticConsumer *clone (DiagnosticsEngine &Diags) const |
| 654 | { |
| 655 | return new NullDiagnosticConsumer (); |
| 656 | } |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 657 | private: |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 658 | Log * m_log; |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 659 | }; |
| 660 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 661 | DiagnosticConsumer * |
| 662 | ClangASTContext::getDiagnosticConsumer() |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 663 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 664 | if (m_diagnostic_consumer_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 665 | m_diagnostic_consumer_ap.reset(new NullDiagnosticConsumer); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 666 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 667 | return m_diagnostic_consumer_ap.get(); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Jason Molenda | 45938b9 | 2014-07-08 23:46:39 +0000 | [diff] [blame] | 670 | std::shared_ptr<TargetOptions> & |
| 671 | ClangASTContext::getTargetOptions() { |
Alp Toker | edc902f | 2014-07-05 03:06:05 +0000 | [diff] [blame] | 672 | if (m_target_options_rp.get() == nullptr && !m_target_triple.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 673 | { |
Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 674 | m_target_options_rp = std::make_shared<TargetOptions>(); |
Alp Toker | edc902f | 2014-07-05 03:06:05 +0000 | [diff] [blame] | 675 | if (m_target_options_rp.get() != nullptr) |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 676 | m_target_options_rp->Triple = m_target_triple; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 677 | } |
Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 678 | return m_target_options_rp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | |
| 682 | TargetInfo * |
| 683 | ClangASTContext::getTargetInfo() |
| 684 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 685 | // target_triple should be something like "x86_64-apple-macosx" |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 686 | if (m_target_info_ap.get() == nullptr && !m_target_triple.empty()) |
Greg Clayton | 38d880a | 2012-11-16 21:35:22 +0000 | [diff] [blame] | 687 | m_target_info_ap.reset (TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(), getTargetOptions())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 688 | return m_target_info_ap.get(); |
| 689 | } |
| 690 | |
| 691 | #pragma mark Basic Types |
| 692 | |
| 693 | static inline bool |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 694 | QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext *ast, QualType qual_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 695 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 696 | uint64_t qual_type_bit_size = ast->getTypeSize(qual_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 697 | if (qual_type_bit_size == bit_size) |
| 698 | return true; |
| 699 | return false; |
| 700 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 701 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 702 | CompilerType |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 703 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (Encoding encoding, size_t bit_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 704 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 705 | return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (getASTContext(), encoding, bit_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 708 | CompilerType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 709 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (ASTContext *ast, Encoding encoding, uint32_t bit_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 711 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 712 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 713 | switch (encoding) |
| 714 | { |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 715 | case eEncodingInvalid: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 716 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 717 | return CompilerType (ast, ast->VoidPtrTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | break; |
| 719 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 720 | case eEncodingUint: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 721 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 722 | return CompilerType (ast, ast->UnsignedCharTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 723 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 724 | return CompilerType (ast, ast->UnsignedShortTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 725 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 726 | return CompilerType (ast, ast->UnsignedIntTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 727 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 728 | return CompilerType (ast, ast->UnsignedLongTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 729 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 730 | return CompilerType (ast, ast->UnsignedLongLongTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 731 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 732 | return CompilerType (ast, ast->UnsignedInt128Ty); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 733 | break; |
| 734 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 735 | case eEncodingSint: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 736 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 737 | return CompilerType (ast, ast->CharTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 738 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 739 | return CompilerType (ast, ast->ShortTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 740 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 741 | return CompilerType (ast, ast->IntTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 742 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 743 | return CompilerType (ast, ast->LongTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 744 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 745 | return CompilerType (ast, ast->LongLongTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 746 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 747 | return CompilerType (ast, ast->Int128Ty); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 748 | break; |
| 749 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 750 | case eEncodingIEEE754: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 751 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 752 | return CompilerType (ast, ast->FloatTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 753 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 754 | return CompilerType (ast, ast->DoubleTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 755 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 756 | return CompilerType (ast, ast->LongDoubleTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 757 | break; |
| 758 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 759 | case eEncodingVector: |
Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 760 | // Sanity check that bit_size is a multiple of 8's. |
| 761 | if (bit_size && !(bit_size & 0x7u)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 762 | return CompilerType (ast, ast->getExtVectorType (ast->UnsignedCharTy, bit_size/8)); |
Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 763 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 766 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 767 | } |
| 768 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 769 | |
| 770 | |
| 771 | lldb::BasicType |
| 772 | ClangASTContext::GetBasicTypeEnumeration (const ConstString &name) |
| 773 | { |
| 774 | if (name) |
| 775 | { |
| 776 | typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; |
| 777 | static TypeNameToBasicTypeMap g_type_map; |
| 778 | static std::once_flag g_once_flag; |
| 779 | std::call_once(g_once_flag, [](){ |
| 780 | // "void" |
| 781 | g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); |
| 782 | |
| 783 | // "char" |
| 784 | g_type_map.Append(ConstString("char").GetCString(), eBasicTypeChar); |
| 785 | g_type_map.Append(ConstString("signed char").GetCString(), eBasicTypeSignedChar); |
| 786 | g_type_map.Append(ConstString("unsigned char").GetCString(), eBasicTypeUnsignedChar); |
| 787 | g_type_map.Append(ConstString("wchar_t").GetCString(), eBasicTypeWChar); |
| 788 | g_type_map.Append(ConstString("signed wchar_t").GetCString(), eBasicTypeSignedWChar); |
| 789 | g_type_map.Append(ConstString("unsigned wchar_t").GetCString(), eBasicTypeUnsignedWChar); |
| 790 | // "short" |
| 791 | g_type_map.Append(ConstString("short").GetCString(), eBasicTypeShort); |
| 792 | g_type_map.Append(ConstString("short int").GetCString(), eBasicTypeShort); |
| 793 | g_type_map.Append(ConstString("unsigned short").GetCString(), eBasicTypeUnsignedShort); |
| 794 | g_type_map.Append(ConstString("unsigned short int").GetCString(), eBasicTypeUnsignedShort); |
| 795 | |
| 796 | // "int" |
| 797 | g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); |
| 798 | g_type_map.Append(ConstString("signed int").GetCString(), eBasicTypeInt); |
| 799 | g_type_map.Append(ConstString("unsigned int").GetCString(), eBasicTypeUnsignedInt); |
| 800 | g_type_map.Append(ConstString("unsigned").GetCString(), eBasicTypeUnsignedInt); |
| 801 | |
| 802 | // "long" |
| 803 | g_type_map.Append(ConstString("long").GetCString(), eBasicTypeLong); |
| 804 | g_type_map.Append(ConstString("long int").GetCString(), eBasicTypeLong); |
| 805 | g_type_map.Append(ConstString("unsigned long").GetCString(), eBasicTypeUnsignedLong); |
| 806 | g_type_map.Append(ConstString("unsigned long int").GetCString(), eBasicTypeUnsignedLong); |
| 807 | |
| 808 | // "long long" |
| 809 | g_type_map.Append(ConstString("long long").GetCString(), eBasicTypeLongLong); |
| 810 | g_type_map.Append(ConstString("long long int").GetCString(), eBasicTypeLongLong); |
| 811 | g_type_map.Append(ConstString("unsigned long long").GetCString(), eBasicTypeUnsignedLongLong); |
| 812 | g_type_map.Append(ConstString("unsigned long long int").GetCString(), eBasicTypeUnsignedLongLong); |
| 813 | |
| 814 | // "int128" |
| 815 | g_type_map.Append(ConstString("__int128_t").GetCString(), eBasicTypeInt128); |
| 816 | g_type_map.Append(ConstString("__uint128_t").GetCString(), eBasicTypeUnsignedInt128); |
| 817 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 818 | // Miscellaneous |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 819 | g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); |
| 820 | g_type_map.Append(ConstString("float").GetCString(), eBasicTypeFloat); |
| 821 | g_type_map.Append(ConstString("double").GetCString(), eBasicTypeDouble); |
| 822 | g_type_map.Append(ConstString("long double").GetCString(), eBasicTypeLongDouble); |
| 823 | g_type_map.Append(ConstString("id").GetCString(), eBasicTypeObjCID); |
| 824 | g_type_map.Append(ConstString("SEL").GetCString(), eBasicTypeObjCSel); |
| 825 | g_type_map.Append(ConstString("nullptr").GetCString(), eBasicTypeNullPtr); |
| 826 | g_type_map.Sort(); |
| 827 | }); |
| 828 | |
| 829 | return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); |
| 830 | } |
| 831 | return eBasicTypeInvalid; |
| 832 | } |
| 833 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 834 | CompilerType |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 835 | ClangASTContext::GetBasicType (ASTContext *ast, const ConstString &name) |
| 836 | { |
| 837 | if (ast) |
| 838 | { |
| 839 | lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration (name); |
| 840 | return ClangASTContext::GetBasicType (ast, basic_type); |
| 841 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 842 | return CompilerType(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | uint32_t |
| 846 | ClangASTContext::GetPointerByteSize () |
| 847 | { |
| 848 | if (m_pointer_byte_size == 0) |
Enrico Granata | 1cd5e92 | 2015-01-28 00:07:51 +0000 | [diff] [blame] | 849 | m_pointer_byte_size = GetBasicType(lldb::eBasicTypeVoid).GetPointerType().GetByteSize(nullptr); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 850 | return m_pointer_byte_size; |
| 851 | } |
| 852 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 853 | CompilerType |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 854 | ClangASTContext::GetBasicType (lldb::BasicType basic_type) |
| 855 | { |
| 856 | return GetBasicType (getASTContext(), basic_type); |
| 857 | } |
| 858 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 859 | CompilerType |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 860 | ClangASTContext::GetBasicType (ASTContext *ast, lldb::BasicType basic_type) |
| 861 | { |
| 862 | if (ast) |
| 863 | { |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 864 | lldb::opaque_compiler_type_t clang_type = nullptr; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 865 | |
| 866 | switch (basic_type) |
| 867 | { |
| 868 | case eBasicTypeInvalid: |
| 869 | case eBasicTypeOther: |
| 870 | break; |
| 871 | case eBasicTypeVoid: |
| 872 | clang_type = ast->VoidTy.getAsOpaquePtr(); |
| 873 | break; |
| 874 | case eBasicTypeChar: |
| 875 | clang_type = ast->CharTy.getAsOpaquePtr(); |
| 876 | break; |
| 877 | case eBasicTypeSignedChar: |
| 878 | clang_type = ast->SignedCharTy.getAsOpaquePtr(); |
| 879 | break; |
| 880 | case eBasicTypeUnsignedChar: |
| 881 | clang_type = ast->UnsignedCharTy.getAsOpaquePtr(); |
| 882 | break; |
| 883 | case eBasicTypeWChar: |
| 884 | clang_type = ast->getWCharType().getAsOpaquePtr(); |
| 885 | break; |
| 886 | case eBasicTypeSignedWChar: |
| 887 | clang_type = ast->getSignedWCharType().getAsOpaquePtr(); |
| 888 | break; |
| 889 | case eBasicTypeUnsignedWChar: |
| 890 | clang_type = ast->getUnsignedWCharType().getAsOpaquePtr(); |
| 891 | break; |
| 892 | case eBasicTypeChar16: |
| 893 | clang_type = ast->Char16Ty.getAsOpaquePtr(); |
| 894 | break; |
| 895 | case eBasicTypeChar32: |
| 896 | clang_type = ast->Char32Ty.getAsOpaquePtr(); |
| 897 | break; |
| 898 | case eBasicTypeShort: |
| 899 | clang_type = ast->ShortTy.getAsOpaquePtr(); |
| 900 | break; |
| 901 | case eBasicTypeUnsignedShort: |
| 902 | clang_type = ast->UnsignedShortTy.getAsOpaquePtr(); |
| 903 | break; |
| 904 | case eBasicTypeInt: |
| 905 | clang_type = ast->IntTy.getAsOpaquePtr(); |
| 906 | break; |
| 907 | case eBasicTypeUnsignedInt: |
| 908 | clang_type = ast->UnsignedIntTy.getAsOpaquePtr(); |
| 909 | break; |
| 910 | case eBasicTypeLong: |
| 911 | clang_type = ast->LongTy.getAsOpaquePtr(); |
| 912 | break; |
| 913 | case eBasicTypeUnsignedLong: |
| 914 | clang_type = ast->UnsignedLongTy.getAsOpaquePtr(); |
| 915 | break; |
| 916 | case eBasicTypeLongLong: |
| 917 | clang_type = ast->LongLongTy.getAsOpaquePtr(); |
| 918 | break; |
| 919 | case eBasicTypeUnsignedLongLong: |
| 920 | clang_type = ast->UnsignedLongLongTy.getAsOpaquePtr(); |
| 921 | break; |
| 922 | case eBasicTypeInt128: |
| 923 | clang_type = ast->Int128Ty.getAsOpaquePtr(); |
| 924 | break; |
| 925 | case eBasicTypeUnsignedInt128: |
| 926 | clang_type = ast->UnsignedInt128Ty.getAsOpaquePtr(); |
| 927 | break; |
| 928 | case eBasicTypeBool: |
| 929 | clang_type = ast->BoolTy.getAsOpaquePtr(); |
| 930 | break; |
| 931 | case eBasicTypeHalf: |
| 932 | clang_type = ast->HalfTy.getAsOpaquePtr(); |
| 933 | break; |
| 934 | case eBasicTypeFloat: |
| 935 | clang_type = ast->FloatTy.getAsOpaquePtr(); |
| 936 | break; |
| 937 | case eBasicTypeDouble: |
| 938 | clang_type = ast->DoubleTy.getAsOpaquePtr(); |
| 939 | break; |
| 940 | case eBasicTypeLongDouble: |
| 941 | clang_type = ast->LongDoubleTy.getAsOpaquePtr(); |
| 942 | break; |
| 943 | case eBasicTypeFloatComplex: |
| 944 | clang_type = ast->FloatComplexTy.getAsOpaquePtr(); |
| 945 | break; |
| 946 | case eBasicTypeDoubleComplex: |
| 947 | clang_type = ast->DoubleComplexTy.getAsOpaquePtr(); |
| 948 | break; |
| 949 | case eBasicTypeLongDoubleComplex: |
| 950 | clang_type = ast->LongDoubleComplexTy.getAsOpaquePtr(); |
| 951 | break; |
| 952 | case eBasicTypeObjCID: |
| 953 | clang_type = ast->getObjCIdType().getAsOpaquePtr(); |
| 954 | break; |
| 955 | case eBasicTypeObjCClass: |
| 956 | clang_type = ast->getObjCClassType().getAsOpaquePtr(); |
| 957 | break; |
| 958 | case eBasicTypeObjCSel: |
| 959 | clang_type = ast->getObjCSelType().getAsOpaquePtr(); |
| 960 | break; |
| 961 | case eBasicTypeNullPtr: |
| 962 | clang_type = ast->NullPtrTy.getAsOpaquePtr(); |
| 963 | break; |
| 964 | } |
| 965 | |
| 966 | if (clang_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 967 | return CompilerType (GetASTContext(ast), clang_type); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 968 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 969 | return CompilerType(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 973 | CompilerType |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 974 | ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name, uint32_t dw_ate, uint32_t bit_size) |
| 975 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 976 | ASTContext *ast = getASTContext(); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 977 | |
| 978 | #define streq(a,b) strcmp(a,b) == 0 |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 979 | assert (ast != nullptr); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 980 | if (ast) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 981 | { |
| 982 | switch (dw_ate) |
| 983 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 984 | default: |
| 985 | break; |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 986 | |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 987 | case DW_ATE_address: |
| 988 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 989 | return CompilerType (ast, ast->VoidPtrTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 990 | break; |
| 991 | |
| 992 | case DW_ATE_boolean: |
| 993 | if (QualTypeMatchesBitSize (bit_size, ast, ast->BoolTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 994 | return CompilerType (ast, ast->BoolTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 995 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 996 | return CompilerType (ast, ast->UnsignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 997 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 998 | return CompilerType (ast, ast->UnsignedShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 999 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1000 | return CompilerType (ast, ast->UnsignedIntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1001 | break; |
| 1002 | |
| 1003 | case DW_ATE_lo_user: |
| 1004 | // This has been seen to mean DW_AT_complex_integer |
| 1005 | if (type_name) |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1006 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1007 | if (::strstr(type_name, "complex")) |
| 1008 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1009 | CompilerType complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("int", DW_ATE_signed, bit_size/2); |
| 1010 | return CompilerType (ast, ast->getComplexType (GetQualType(complex_int_clang_type))); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1011 | } |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1012 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1013 | break; |
| 1014 | |
| 1015 | case DW_ATE_complex_float: |
| 1016 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatComplexTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1017 | return CompilerType (ast, ast->FloatComplexTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1018 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleComplexTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1019 | return CompilerType (ast, ast->DoubleComplexTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1020 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleComplexTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1021 | return CompilerType (ast, ast->LongDoubleComplexTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1022 | else |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1023 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1024 | CompilerType complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("float", DW_ATE_float, bit_size/2); |
| 1025 | return CompilerType (ast, ast->getComplexType (GetQualType(complex_float_clang_type))); |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1026 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1027 | break; |
| 1028 | |
| 1029 | case DW_ATE_float: |
Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1030 | if (streq(type_name, "float") && QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1031 | return CompilerType (ast, ast->FloatTy); |
Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1032 | if (streq(type_name, "double") && QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1033 | return CompilerType (ast, ast->DoubleTy); |
Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1034 | if (streq(type_name, "long double") && QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1035 | return CompilerType (ast, ast->LongDoubleTy); |
Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 1036 | // Fall back to not requiring a name match |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1037 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1038 | return CompilerType (ast, ast->FloatTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1039 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1040 | return CompilerType (ast, ast->DoubleTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1041 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1042 | return CompilerType (ast, ast->LongDoubleTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1043 | break; |
| 1044 | |
| 1045 | case DW_ATE_signed: |
| 1046 | if (type_name) |
| 1047 | { |
| 1048 | if (streq(type_name, "wchar_t") && |
Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1049 | QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy) && |
Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 1050 | (getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType()))) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1051 | return CompilerType (ast, ast->WCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1052 | if (streq(type_name, "void") && |
| 1053 | QualTypeMatchesBitSize (bit_size, ast, ast->VoidTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1054 | return CompilerType (ast, ast->VoidTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1055 | if (strstr(type_name, "long long") && |
| 1056 | QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1057 | return CompilerType (ast, ast->LongLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1058 | if (strstr(type_name, "long") && |
| 1059 | QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1060 | return CompilerType (ast, ast->LongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1061 | if (strstr(type_name, "short") && |
| 1062 | QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1063 | return CompilerType (ast, ast->ShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1064 | if (strstr(type_name, "char")) |
| 1065 | { |
| 1066 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1067 | return CompilerType (ast, ast->CharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1068 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1069 | return CompilerType (ast, ast->SignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1070 | } |
| 1071 | if (strstr(type_name, "int")) |
| 1072 | { |
| 1073 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1074 | return CompilerType (ast, ast->IntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1075 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1076 | return CompilerType (ast, ast->Int128Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | // We weren't able to match up a type name, just search by size |
| 1080 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1081 | return CompilerType (ast, ast->CharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1082 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1083 | return CompilerType (ast, ast->ShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1084 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1085 | return CompilerType (ast, ast->IntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1086 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1087 | return CompilerType (ast, ast->LongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1088 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1089 | return CompilerType (ast, ast->LongLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1090 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1091 | return CompilerType (ast, ast->Int128Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1092 | break; |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1093 | |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1094 | case DW_ATE_signed_char: |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1095 | if (ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char")) |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1096 | { |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1097 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1098 | return CompilerType (ast, ast->CharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1099 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1100 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1101 | return CompilerType (ast, ast->SignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1102 | break; |
| 1103 | |
| 1104 | case DW_ATE_unsigned: |
| 1105 | if (type_name) |
| 1106 | { |
Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1107 | if (streq(type_name, "wchar_t")) |
| 1108 | { |
| 1109 | if (QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy)) |
| 1110 | { |
Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 1111 | if (!(getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType()))) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1112 | return CompilerType (ast, ast->WCharTy); |
Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1113 | } |
| 1114 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1115 | if (strstr(type_name, "long long")) |
| 1116 | { |
| 1117 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1118 | return CompilerType (ast, ast->UnsignedLongLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1119 | } |
| 1120 | else if (strstr(type_name, "long")) |
| 1121 | { |
| 1122 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1123 | return CompilerType (ast, ast->UnsignedLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1124 | } |
| 1125 | else if (strstr(type_name, "short")) |
| 1126 | { |
| 1127 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1128 | return CompilerType (ast, ast->UnsignedShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1129 | } |
| 1130 | else if (strstr(type_name, "char")) |
| 1131 | { |
| 1132 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1133 | return CompilerType (ast, ast->UnsignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1134 | } |
| 1135 | else if (strstr(type_name, "int")) |
| 1136 | { |
| 1137 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1138 | return CompilerType (ast, ast->UnsignedIntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1139 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1140 | return CompilerType (ast, ast->UnsignedInt128Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | // We weren't able to match up a type name, just search by size |
| 1144 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1145 | return CompilerType (ast, ast->UnsignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1146 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1147 | return CompilerType (ast, ast->UnsignedShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1148 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1149 | return CompilerType (ast, ast->UnsignedIntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1150 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1151 | return CompilerType (ast, ast->UnsignedLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1152 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1153 | return CompilerType (ast, ast->UnsignedLongLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1154 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1155 | return CompilerType (ast, ast->UnsignedInt128Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1156 | break; |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1157 | |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1158 | case DW_ATE_unsigned_char: |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1159 | if (!ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char")) |
| 1160 | { |
| 1161 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1162 | return CompilerType (ast, ast->CharTy); |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1163 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1164 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1165 | return CompilerType (ast, ast->UnsignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1166 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1167 | return CompilerType (ast, ast->UnsignedShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1168 | break; |
| 1169 | |
| 1170 | case DW_ATE_imaginary_float: |
| 1171 | break; |
| 1172 | |
| 1173 | case DW_ATE_UTF: |
| 1174 | if (type_name) |
| 1175 | { |
| 1176 | if (streq(type_name, "char16_t")) |
| 1177 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1178 | return CompilerType (ast, ast->Char16Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1179 | } |
| 1180 | else if (streq(type_name, "char32_t")) |
| 1181 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1182 | return CompilerType (ast, ast->Char32Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | // This assert should fire for anything that we don't catch above so we know |
| 1189 | // to fix any issues we run into. |
Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 1190 | if (type_name) |
| 1191 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1192 | Host::SystemLog (Host::eSystemLogError, "error: need to add support for DW_TAG_base_type '%s' encoded with DW_ATE = 0x%x, bit_size = %u\n", type_name, dw_ate, bit_size); |
Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 1193 | } |
| 1194 | else |
| 1195 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1196 | Host::SystemLog (Host::eSystemLogError, "error: need to add support for DW_TAG_base_type encoded with DW_ATE = 0x%x, bit_size = %u\n", dw_ate, bit_size); |
Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 1197 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1198 | return CompilerType (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1201 | CompilerType |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1202 | ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast) |
| 1203 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1204 | if (ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1205 | return CompilerType (ast, ast->UnknownAnyTy); |
| 1206 | return CompilerType(); |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1209 | CompilerType |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1210 | ClangASTContext::GetCStringType (bool is_const) |
| 1211 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1212 | ASTContext *ast = getASTContext(); |
| 1213 | QualType char_type(ast->CharTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1214 | |
| 1215 | if (is_const) |
| 1216 | char_type.addConst(); |
| 1217 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1218 | return CompilerType (ast, ast->getPointerType(char_type)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 1221 | clang::DeclContext * |
| 1222 | ClangASTContext::GetTranslationUnitDecl (clang::ASTContext *ast) |
| 1223 | { |
| 1224 | return ast->getTranslationUnitDecl(); |
| 1225 | } |
| 1226 | |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1227 | clang::Decl * |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1228 | ClangASTContext::CopyDecl (ASTContext *dst_ast, |
| 1229 | ASTContext *src_ast, |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1230 | clang::Decl *source_decl) |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 1231 | { |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 1232 | FileSystemOptions file_system_options; |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1233 | FileManager file_manager (file_system_options); |
| 1234 | ASTImporter importer(*dst_ast, file_manager, |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1235 | *src_ast, file_manager, |
| 1236 | false); |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1237 | |
| 1238 | return importer.Import(source_decl); |
| 1239 | } |
| 1240 | |
Sean Callanan | 23a3027 | 2010-07-16 00:00:27 +0000 | [diff] [blame] | 1241 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1242 | ClangASTContext::AreTypesSame (CompilerType type1, |
| 1243 | CompilerType type2, |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1244 | bool ignore_qualifiers) |
Sean Callanan | 4dcca262 | 2010-07-15 22:30:52 +0000 | [diff] [blame] | 1245 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 1246 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type1.GetTypeSystem()); |
| 1247 | if (!ast || ast != type2.GetTypeSystem()) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1248 | return false; |
| 1249 | |
| 1250 | if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType()) |
Greg Clayton | 55995eb | 2012-04-06 17:38:55 +0000 | [diff] [blame] | 1251 | return true; |
| 1252 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1253 | QualType type1_qual = GetQualType(type1); |
| 1254 | QualType type2_qual = GetQualType(type2); |
Sean Callanan | 5056ab0 | 2012-02-18 02:01:03 +0000 | [diff] [blame] | 1255 | |
| 1256 | if (ignore_qualifiers) |
| 1257 | { |
| 1258 | type1_qual = type1_qual.getUnqualifiedType(); |
| 1259 | type2_qual = type2_qual.getUnqualifiedType(); |
| 1260 | } |
| 1261 | |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 1262 | return ast->getASTContext()->hasSameType (type1_qual, type2_qual); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1265 | CompilerType |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1266 | ClangASTContext::GetTypeForDecl (clang::NamedDecl *decl) |
| 1267 | { |
| 1268 | if (clang::ObjCInterfaceDecl *interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) |
| 1269 | return GetTypeForDecl(interface_decl); |
| 1270 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) |
| 1271 | return GetTypeForDecl(tag_decl); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1272 | return CompilerType(); |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1275 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1276 | CompilerType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1277 | ClangASTContext::GetTypeForDecl (TagDecl *decl) |
| 1278 | { |
| 1279 | // No need to call the getASTContext() accessor (which can create the AST |
| 1280 | // if it isn't created yet, because we can't have created a decl in this |
| 1281 | // AST if our AST didn't already exist... |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1282 | ASTContext *ast = &decl->getASTContext(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1283 | if (ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1284 | return CompilerType (ast, ast->getTagDeclType(decl)); |
| 1285 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1288 | CompilerType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1289 | ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl) |
| 1290 | { |
| 1291 | // No need to call the getASTContext() accessor (which can create the AST |
| 1292 | // if it isn't created yet, because we can't have created a decl in this |
| 1293 | // AST if our AST didn't already exist... |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1294 | ASTContext *ast = &decl->getASTContext(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1295 | if (ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1296 | return CompilerType (ast, ast->getObjCInterfaceType(decl)); |
| 1297 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1300 | #pragma mark Structure, Unions, Classes |
| 1301 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1302 | CompilerType |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1303 | ClangASTContext::CreateRecordType (DeclContext *decl_ctx, |
| 1304 | AccessType access_type, |
| 1305 | const char *name, |
| 1306 | int kind, |
| 1307 | LanguageType language, |
| 1308 | ClangASTMetadata *metadata) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1309 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1310 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1311 | assert (ast != nullptr); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1312 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1313 | if (decl_ctx == nullptr) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1314 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1315 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1316 | |
Greg Clayton | e1be996 | 2011-08-24 23:50:00 +0000 | [diff] [blame] | 1317 | if (language == eLanguageTypeObjC || language == eLanguageTypeObjC_plus_plus) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1318 | { |
Greg Clayton | aaf99e0 | 2010-10-11 02:25:34 +0000 | [diff] [blame] | 1319 | bool isForwardDecl = true; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1320 | bool isInternal = false; |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1321 | return CreateObjCClass (name, decl_ctx, isForwardDecl, isInternal, metadata); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1324 | // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and |
| 1325 | // we will need to update this code. I was told to currently always use |
| 1326 | // the CXXRecordDecl class since we often don't know from debug information |
| 1327 | // if something is struct or a class, so we default to always use the more |
| 1328 | // complete definition just in case. |
Sean Callanan | 11e32d3 | 2014-02-18 00:31:38 +0000 | [diff] [blame] | 1329 | |
| 1330 | bool is_anonymous = (!name) || (!name[0]); |
| 1331 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1332 | CXXRecordDecl *decl = CXXRecordDecl::Create (*ast, |
| 1333 | (TagDecl::TagKind)kind, |
| 1334 | decl_ctx, |
| 1335 | SourceLocation(), |
| 1336 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1337 | is_anonymous ? nullptr : &ast->Idents.get(name)); |
Sean Callanan | 11e32d3 | 2014-02-18 00:31:38 +0000 | [diff] [blame] | 1338 | |
| 1339 | if (is_anonymous) |
| 1340 | decl->setAnonymousStructOrUnion(true); |
Sean Callanan | 7282e2a | 2012-01-13 22:10:18 +0000 | [diff] [blame] | 1341 | |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1342 | if (decl) |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1343 | { |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1344 | if (metadata) |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1345 | SetMetadata(ast, decl, *metadata); |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1346 | |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1347 | if (access_type != eAccessNone) |
| 1348 | decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1349 | |
| 1350 | if (decl_ctx) |
| 1351 | decl_ctx->addDecl (decl); |
| 1352 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1353 | return CompilerType(ast, ast->getTagDeclType(decl)); |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1354 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1355 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1358 | static TemplateParameterList * |
| 1359 | CreateTemplateParameterList (ASTContext *ast, |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1360 | const ClangASTContext::TemplateParameterInfos &template_param_infos, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1361 | llvm::SmallVector<NamedDecl *, 8> &template_param_decls) |
| 1362 | { |
| 1363 | const bool parameter_pack = false; |
| 1364 | const bool is_typename = false; |
| 1365 | const unsigned depth = 0; |
| 1366 | const size_t num_template_params = template_param_infos.GetSize(); |
| 1367 | for (size_t i=0; i<num_template_params; ++i) |
| 1368 | { |
| 1369 | const char *name = template_param_infos.names[i]; |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1370 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1371 | IdentifierInfo *identifier_info = nullptr; |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1372 | if (name && name[0]) |
| 1373 | identifier_info = &ast->Idents.get(name); |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1374 | if (template_param_infos.args[i].getKind() == TemplateArgument::Integral) |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1375 | { |
| 1376 | template_param_decls.push_back (NonTypeTemplateParmDecl::Create (*ast, |
| 1377 | ast->getTranslationUnitDecl(), // Is this the right decl context?, SourceLocation StartLoc, |
| 1378 | SourceLocation(), |
| 1379 | SourceLocation(), |
| 1380 | depth, |
| 1381 | i, |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1382 | identifier_info, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1383 | template_param_infos.args[i].getIntegralType(), |
| 1384 | parameter_pack, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1385 | nullptr)); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1386 | |
| 1387 | } |
| 1388 | else |
| 1389 | { |
| 1390 | template_param_decls.push_back (TemplateTypeParmDecl::Create (*ast, |
| 1391 | ast->getTranslationUnitDecl(), // Is this the right decl context? |
| 1392 | SourceLocation(), |
| 1393 | SourceLocation(), |
| 1394 | depth, |
| 1395 | i, |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1396 | identifier_info, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1397 | is_typename, |
| 1398 | parameter_pack)); |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | TemplateParameterList *template_param_list = TemplateParameterList::Create (*ast, |
| 1403 | SourceLocation(), |
| 1404 | SourceLocation(), |
| 1405 | &template_param_decls.front(), |
| 1406 | template_param_decls.size(), |
| 1407 | SourceLocation()); |
| 1408 | return template_param_list; |
| 1409 | } |
| 1410 | |
| 1411 | clang::FunctionTemplateDecl * |
| 1412 | ClangASTContext::CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx, |
| 1413 | clang::FunctionDecl *func_decl, |
| 1414 | const char *name, |
| 1415 | const TemplateParameterInfos &template_param_infos) |
| 1416 | { |
| 1417 | // /// \brief Create a function template node. |
| 1418 | ASTContext *ast = getASTContext(); |
| 1419 | |
| 1420 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
| 1421 | |
| 1422 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, |
| 1423 | template_param_infos, |
| 1424 | template_param_decls); |
| 1425 | FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create (*ast, |
| 1426 | decl_ctx, |
| 1427 | func_decl->getLocation(), |
| 1428 | func_decl->getDeclName(), |
| 1429 | template_param_list, |
| 1430 | func_decl); |
| 1431 | |
| 1432 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); |
| 1433 | i < template_param_decl_count; |
| 1434 | ++i) |
| 1435 | { |
| 1436 | // TODO: verify which decl context we should put template_param_decls into.. |
| 1437 | template_param_decls[i]->setDeclContext (func_decl); |
| 1438 | } |
| 1439 | |
| 1440 | return func_tmpl_decl; |
| 1441 | } |
| 1442 | |
| 1443 | void |
| 1444 | ClangASTContext::CreateFunctionTemplateSpecializationInfo (FunctionDecl *func_decl, |
| 1445 | clang::FunctionTemplateDecl *func_tmpl_decl, |
| 1446 | const TemplateParameterInfos &infos) |
| 1447 | { |
| 1448 | TemplateArgumentList template_args (TemplateArgumentList::OnStack, |
| 1449 | infos.args.data(), |
| 1450 | infos.args.size()); |
| 1451 | |
| 1452 | func_decl->setFunctionTemplateSpecialization (func_tmpl_decl, |
| 1453 | &template_args, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1454 | nullptr); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1458 | ClassTemplateDecl * |
| 1459 | ClangASTContext::CreateClassTemplateDecl (DeclContext *decl_ctx, |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1460 | lldb::AccessType access_type, |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1461 | const char *class_name, |
| 1462 | int kind, |
| 1463 | const TemplateParameterInfos &template_param_infos) |
| 1464 | { |
| 1465 | ASTContext *ast = getASTContext(); |
| 1466 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1467 | ClassTemplateDecl *class_template_decl = nullptr; |
| 1468 | if (decl_ctx == nullptr) |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1469 | decl_ctx = ast->getTranslationUnitDecl(); |
| 1470 | |
| 1471 | IdentifierInfo &identifier_info = ast->Idents.get(class_name); |
| 1472 | DeclarationName decl_name (&identifier_info); |
| 1473 | |
| 1474 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1475 | |
| 1476 | for (NamedDecl *decl : result) |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1477 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1478 | class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1479 | if (class_template_decl) |
| 1480 | return class_template_decl; |
| 1481 | } |
| 1482 | |
| 1483 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1484 | |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1485 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, |
| 1486 | template_param_infos, |
| 1487 | template_param_decls); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1488 | |
| 1489 | CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create (*ast, |
| 1490 | (TagDecl::TagKind)kind, |
| 1491 | decl_ctx, // What decl context do we use here? TU? The actual decl context? |
| 1492 | SourceLocation(), |
| 1493 | SourceLocation(), |
| 1494 | &identifier_info); |
Greg Clayton | e04741d | 2011-12-02 02:09:28 +0000 | [diff] [blame] | 1495 | |
| 1496 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); |
| 1497 | i < template_param_decl_count; |
| 1498 | ++i) |
| 1499 | { |
| 1500 | template_param_decls[i]->setDeclContext (template_cxx_decl); |
| 1501 | } |
| 1502 | |
Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1503 | // With templated classes, we say that a class is templated with |
| 1504 | // specializations, but that the bare class has no functions. |
Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame] | 1505 | //template_cxx_decl->startDefinition(); |
| 1506 | //template_cxx_decl->completeDefinition(); |
Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1507 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1508 | class_template_decl = ClassTemplateDecl::Create (*ast, |
| 1509 | decl_ctx, // What decl context do we use here? TU? The actual decl context? |
| 1510 | SourceLocation(), |
| 1511 | decl_name, |
| 1512 | template_param_list, |
| 1513 | template_cxx_decl, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1514 | nullptr); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1515 | |
| 1516 | if (class_template_decl) |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1517 | { |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1518 | if (access_type != eAccessNone) |
| 1519 | class_template_decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1520 | |
| 1521 | //if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx)) |
| 1522 | // CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl)); |
| 1523 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1524 | decl_ctx->addDecl (class_template_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1525 | |
| 1526 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1527 | VerifyDecl(class_template_decl); |
| 1528 | #endif |
| 1529 | } |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1530 | |
| 1531 | return class_template_decl; |
| 1532 | } |
| 1533 | |
| 1534 | |
| 1535 | ClassTemplateSpecializationDecl * |
| 1536 | ClangASTContext::CreateClassTemplateSpecializationDecl (DeclContext *decl_ctx, |
| 1537 | ClassTemplateDecl *class_template_decl, |
| 1538 | int kind, |
| 1539 | const TemplateParameterInfos &template_param_infos) |
| 1540 | { |
| 1541 | ASTContext *ast = getASTContext(); |
| 1542 | ClassTemplateSpecializationDecl *class_template_specialization_decl = ClassTemplateSpecializationDecl::Create (*ast, |
| 1543 | (TagDecl::TagKind)kind, |
| 1544 | decl_ctx, |
| 1545 | SourceLocation(), |
| 1546 | SourceLocation(), |
| 1547 | class_template_decl, |
| 1548 | &template_param_infos.args.front(), |
| 1549 | template_param_infos.args.size(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1550 | nullptr); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1551 | |
Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame] | 1552 | class_template_specialization_decl->setSpecializationKind(TSK_ExplicitSpecialization); |
| 1553 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1554 | return class_template_specialization_decl; |
| 1555 | } |
| 1556 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1557 | CompilerType |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1558 | ClangASTContext::CreateClassTemplateSpecializationType (ClassTemplateSpecializationDecl *class_template_specialization_decl) |
| 1559 | { |
| 1560 | if (class_template_specialization_decl) |
| 1561 | { |
| 1562 | ASTContext *ast = getASTContext(); |
| 1563 | if (ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1564 | return CompilerType(ast, ast->getTagDeclType(class_template_specialization_decl)); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1565 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1566 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1569 | static inline bool |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1570 | check_op_param (uint32_t op_kind, bool unary, bool binary, uint32_t num_params) |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1571 | { |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1572 | // Special-case call since it can take any number of operands |
| 1573 | if(op_kind == OO_Call) |
| 1574 | return true; |
| 1575 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1576 | // The parameter count doesn't include "this" |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1577 | if (num_params == 0) |
| 1578 | return unary; |
| 1579 | if (num_params == 1) |
| 1580 | return binary; |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1581 | else |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1582 | return false; |
| 1583 | } |
Daniel Dunbar | dacdfb5 | 2011-10-31 22:50:57 +0000 | [diff] [blame] | 1584 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1585 | bool |
| 1586 | ClangASTContext::CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, uint32_t num_params) |
| 1587 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1588 | switch (op_kind) |
| 1589 | { |
| 1590 | default: |
| 1591 | break; |
| 1592 | // C++ standard allows any number of arguments to new/delete |
| 1593 | case OO_New: |
| 1594 | case OO_Array_New: |
| 1595 | case OO_Delete: |
| 1596 | case OO_Array_Delete: |
| 1597 | return true; |
| 1598 | } |
| 1599 | |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1600 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) case OO_##Name: return check_op_param (op_kind, Unary, Binary, num_params); |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1601 | switch (op_kind) |
| 1602 | { |
| 1603 | #include "clang/Basic/OperatorKinds.def" |
| 1604 | default: break; |
| 1605 | } |
| 1606 | return false; |
| 1607 | } |
| 1608 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1609 | clang::AccessSpecifier |
| 1610 | ClangASTContext::UnifyAccessSpecifiers (clang::AccessSpecifier lhs, clang::AccessSpecifier rhs) |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 1611 | { |
| 1612 | clang::AccessSpecifier ret = lhs; |
| 1613 | |
| 1614 | // Make the access equal to the stricter of the field and the nested field's access |
| 1615 | switch (ret) |
| 1616 | { |
| 1617 | case clang::AS_none: |
| 1618 | break; |
| 1619 | case clang::AS_private: |
| 1620 | break; |
| 1621 | case clang::AS_protected: |
| 1622 | if (rhs == AS_private) |
| 1623 | ret = AS_private; |
| 1624 | break; |
| 1625 | case clang::AS_public: |
| 1626 | ret = rhs; |
| 1627 | break; |
| 1628 | } |
| 1629 | |
| 1630 | return ret; |
| 1631 | } |
| 1632 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1633 | bool |
| 1634 | ClangASTContext::FieldIsBitfield (FieldDecl* field, uint32_t& bitfield_bit_size) |
| 1635 | { |
| 1636 | return FieldIsBitfield(getASTContext(), field, bitfield_bit_size); |
| 1637 | } |
| 1638 | |
| 1639 | bool |
| 1640 | ClangASTContext::FieldIsBitfield |
| 1641 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1642 | ASTContext *ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1643 | FieldDecl* field, |
| 1644 | uint32_t& bitfield_bit_size |
| 1645 | ) |
| 1646 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1647 | if (ast == nullptr || field == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1648 | return false; |
| 1649 | |
| 1650 | if (field->isBitField()) |
| 1651 | { |
| 1652 | Expr* bit_width_expr = field->getBitWidth(); |
| 1653 | if (bit_width_expr) |
| 1654 | { |
| 1655 | llvm::APSInt bit_width_apsint; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1656 | if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1657 | { |
| 1658 | bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX); |
| 1659 | return true; |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | return false; |
| 1664 | } |
| 1665 | |
| 1666 | bool |
| 1667 | ClangASTContext::RecordHasFields (const RecordDecl *record_decl) |
| 1668 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1669 | if (record_decl == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1670 | return false; |
| 1671 | |
| 1672 | if (!record_decl->field_empty()) |
| 1673 | return true; |
| 1674 | |
| 1675 | // No fields, lets check this is a CXX record and check the base classes |
| 1676 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 1677 | if (cxx_record_decl) |
| 1678 | { |
| 1679 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1680 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 1681 | base_class != base_class_end; |
| 1682 | ++base_class) |
| 1683 | { |
| 1684 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 1685 | if (RecordHasFields(base_class_decl)) |
| 1686 | return true; |
| 1687 | } |
| 1688 | } |
| 1689 | return false; |
| 1690 | } |
| 1691 | |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1692 | #pragma mark Objective C Classes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1693 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1694 | CompilerType |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1695 | ClangASTContext::CreateObjCClass |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1696 | ( |
| 1697 | const char *name, |
| 1698 | DeclContext *decl_ctx, |
| 1699 | bool isForwardDecl, |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1700 | bool isInternal, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1701 | ClangASTMetadata *metadata |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1702 | ) |
| 1703 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1704 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1705 | assert (ast != nullptr); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1706 | assert (name && name[0]); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1707 | if (decl_ctx == nullptr) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1708 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1709 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1710 | ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create (*ast, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1711 | decl_ctx, |
| 1712 | SourceLocation(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1713 | &ast->Idents.get(name), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1714 | nullptr, |
Pavel Labath | 67add94 | 2015-07-07 10:11:16 +0000 | [diff] [blame] | 1715 | nullptr, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1716 | SourceLocation(), |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1717 | /*isForwardDecl,*/ |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1718 | isInternal); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1719 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1720 | if (decl && metadata) |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1721 | SetMetadata(ast, decl, *metadata); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1722 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1723 | return CompilerType (ast, ast->getObjCInterfaceType(decl)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | static inline bool |
| 1727 | BaseSpecifierIsEmpty (const CXXBaseSpecifier *b) |
| 1728 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1729 | return ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()) == false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1732 | uint32_t |
| 1733 | ClangASTContext::GetNumBaseClasses (const CXXRecordDecl *cxx_record_decl, bool omit_empty_base_classes) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1734 | { |
| 1735 | uint32_t num_bases = 0; |
| 1736 | if (cxx_record_decl) |
| 1737 | { |
| 1738 | if (omit_empty_base_classes) |
| 1739 | { |
| 1740 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1741 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 1742 | base_class != base_class_end; |
| 1743 | ++base_class) |
| 1744 | { |
| 1745 | // Skip empty base classes |
| 1746 | if (omit_empty_base_classes) |
| 1747 | { |
| 1748 | if (BaseSpecifierIsEmpty (base_class)) |
| 1749 | continue; |
| 1750 | } |
| 1751 | ++num_bases; |
| 1752 | } |
| 1753 | } |
| 1754 | else |
| 1755 | num_bases = cxx_record_decl->getNumBases(); |
| 1756 | } |
| 1757 | return num_bases; |
| 1758 | } |
| 1759 | |
| 1760 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1761 | #pragma mark Namespace Declarations |
| 1762 | |
| 1763 | NamespaceDecl * |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1764 | ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *decl_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1765 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1766 | NamespaceDecl *namespace_decl = nullptr; |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1767 | ASTContext *ast = getASTContext(); |
| 1768 | TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl (); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1769 | if (decl_ctx == nullptr) |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1770 | decl_ctx = translation_unit_decl; |
| 1771 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1772 | if (name) |
| 1773 | { |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1774 | IdentifierInfo &identifier_info = ast->Idents.get(name); |
| 1775 | DeclarationName decl_name (&identifier_info); |
| 1776 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1777 | for (NamedDecl *decl : result) |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1778 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1779 | namespace_decl = dyn_cast<clang::NamespaceDecl>(decl); |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1780 | if (namespace_decl) |
| 1781 | return namespace_decl; |
| 1782 | } |
| 1783 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1784 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1785 | decl_ctx, |
| 1786 | false, |
| 1787 | SourceLocation(), |
| 1788 | SourceLocation(), |
| 1789 | &identifier_info, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1790 | nullptr); |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1791 | |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1792 | decl_ctx->addDecl (namespace_decl); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1793 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1794 | else |
| 1795 | { |
| 1796 | if (decl_ctx == translation_unit_decl) |
| 1797 | { |
| 1798 | namespace_decl = translation_unit_decl->getAnonymousNamespace(); |
| 1799 | if (namespace_decl) |
| 1800 | return namespace_decl; |
| 1801 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1802 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1803 | decl_ctx, |
| 1804 | false, |
| 1805 | SourceLocation(), |
| 1806 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1807 | nullptr, |
| 1808 | nullptr); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1809 | translation_unit_decl->setAnonymousNamespace (namespace_decl); |
| 1810 | translation_unit_decl->addDecl (namespace_decl); |
| 1811 | assert (namespace_decl == translation_unit_decl->getAnonymousNamespace()); |
| 1812 | } |
| 1813 | else |
| 1814 | { |
| 1815 | NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx); |
| 1816 | if (parent_namespace_decl) |
| 1817 | { |
| 1818 | namespace_decl = parent_namespace_decl->getAnonymousNamespace(); |
| 1819 | if (namespace_decl) |
| 1820 | return namespace_decl; |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1821 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1822 | decl_ctx, |
| 1823 | false, |
| 1824 | SourceLocation(), |
| 1825 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1826 | nullptr, |
| 1827 | nullptr); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1828 | parent_namespace_decl->setAnonymousNamespace (namespace_decl); |
| 1829 | parent_namespace_decl->addDecl (namespace_decl); |
| 1830 | assert (namespace_decl == parent_namespace_decl->getAnonymousNamespace()); |
| 1831 | } |
| 1832 | else |
| 1833 | { |
| 1834 | // BAD!!! |
| 1835 | } |
| 1836 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1837 | } |
| 1838 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1839 | VerifyDecl(namespace_decl); |
| 1840 | #endif |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1841 | return namespace_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1845 | clang::BlockDecl * |
| 1846 | ClangASTContext::CreateBlockDeclaration (clang::DeclContext *ctx) |
| 1847 | { |
| 1848 | if (ctx != nullptr) |
| 1849 | { |
| 1850 | clang::BlockDecl *decl = clang::BlockDecl::Create(*getASTContext(), ctx, clang::SourceLocation()); |
| 1851 | ctx->addDecl(decl); |
| 1852 | return decl; |
| 1853 | } |
| 1854 | return nullptr; |
| 1855 | } |
| 1856 | |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1857 | clang::DeclContext * |
| 1858 | FindLCABetweenDecls(clang::DeclContext *left, clang::DeclContext *right, clang::DeclContext *root) |
| 1859 | { |
| 1860 | if (root == nullptr) |
| 1861 | return nullptr; |
| 1862 | |
| 1863 | std::set<clang::DeclContext *> path_left; |
| 1864 | for (clang::DeclContext *d = left; d != nullptr; d = d->getParent()) |
| 1865 | path_left.insert(d); |
| 1866 | |
| 1867 | for (clang::DeclContext *d = right; d != nullptr; d = d->getParent()) |
| 1868 | if (path_left.find(d) != path_left.end()) |
| 1869 | return d; |
| 1870 | |
| 1871 | return nullptr; |
| 1872 | } |
| 1873 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1874 | clang::UsingDirectiveDecl * |
| 1875 | ClangASTContext::CreateUsingDirectiveDeclaration (clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl) |
| 1876 | { |
| 1877 | if (decl_ctx != nullptr && ns_decl != nullptr) |
| 1878 | { |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1879 | clang::TranslationUnitDecl *translation_unit = (clang::TranslationUnitDecl *)GetTranslationUnitDecl(getASTContext()); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1880 | clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(*getASTContext(), |
| 1881 | decl_ctx, |
| 1882 | clang::SourceLocation(), |
| 1883 | clang::SourceLocation(), |
| 1884 | clang::NestedNameSpecifierLoc(), |
| 1885 | clang::SourceLocation(), |
| 1886 | ns_decl, |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1887 | FindLCABetweenDecls(decl_ctx, ns_decl, translation_unit)); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1888 | decl_ctx->addDecl(using_decl); |
| 1889 | return using_decl; |
| 1890 | } |
| 1891 | return nullptr; |
| 1892 | } |
| 1893 | |
| 1894 | clang::UsingDecl * |
| 1895 | ClangASTContext::CreateUsingDeclaration (clang::DeclContext *current_decl_ctx, clang::NamedDecl *target) |
| 1896 | { |
| 1897 | if (current_decl_ctx != nullptr && target != nullptr) |
| 1898 | { |
| 1899 | clang::UsingDecl *using_decl = clang::UsingDecl::Create(*getASTContext(), |
| 1900 | current_decl_ctx, |
| 1901 | clang::SourceLocation(), |
| 1902 | clang::NestedNameSpecifierLoc(), |
| 1903 | clang::DeclarationNameInfo(), |
| 1904 | false); |
| 1905 | clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(*getASTContext(), |
| 1906 | current_decl_ctx, |
| 1907 | clang::SourceLocation(), |
| 1908 | using_decl, |
| 1909 | target); |
| 1910 | using_decl->addShadowDecl(shadow_decl); |
| 1911 | current_decl_ctx->addDecl(using_decl); |
| 1912 | return using_decl; |
| 1913 | } |
| 1914 | return nullptr; |
| 1915 | } |
| 1916 | |
| 1917 | clang::VarDecl * |
| 1918 | ClangASTContext::CreateVariableDeclaration (clang::DeclContext *decl_context, const char *name, clang::QualType type) |
| 1919 | { |
| 1920 | if (decl_context != nullptr) |
| 1921 | { |
| 1922 | clang::VarDecl *var_decl = clang::VarDecl::Create(*getASTContext(), |
| 1923 | decl_context, |
| 1924 | clang::SourceLocation(), |
| 1925 | clang::SourceLocation(), |
| 1926 | name && name[0] ? &getASTContext()->Idents.getOwn(name) : nullptr, |
| 1927 | type, |
| 1928 | nullptr, |
| 1929 | clang::SC_None); |
| 1930 | var_decl->setAccess(clang::AS_public); |
| 1931 | decl_context->addDecl(var_decl); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1932 | return var_decl; |
| 1933 | } |
| 1934 | return nullptr; |
| 1935 | } |
| 1936 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1937 | #pragma mark Function Types |
| 1938 | |
| 1939 | FunctionDecl * |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1940 | ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx, |
| 1941 | const char *name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1942 | const CompilerType &function_clang_type, |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1943 | int storage, |
| 1944 | bool is_inline) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1945 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1946 | FunctionDecl *func_decl = nullptr; |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1947 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1948 | if (decl_ctx == nullptr) |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1949 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1950 | |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1951 | |
| 1952 | const bool hasWrittenPrototype = true; |
| 1953 | const bool isConstexprSpecified = false; |
| 1954 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1955 | if (name && name[0]) |
| 1956 | { |
| 1957 | func_decl = FunctionDecl::Create (*ast, |
| 1958 | decl_ctx, |
| 1959 | SourceLocation(), |
| 1960 | SourceLocation(), |
| 1961 | DeclarationName (&ast->Idents.get(name)), |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1962 | GetQualType(function_clang_type), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1963 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 1964 | (clang::StorageClass)storage, |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1965 | is_inline, |
| 1966 | hasWrittenPrototype, |
| 1967 | isConstexprSpecified); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1968 | } |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1969 | else |
| 1970 | { |
| 1971 | func_decl = FunctionDecl::Create (*ast, |
| 1972 | decl_ctx, |
| 1973 | SourceLocation(), |
| 1974 | SourceLocation(), |
| 1975 | DeclarationName (), |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1976 | GetQualType(function_clang_type), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1977 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 1978 | (clang::StorageClass)storage, |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1979 | is_inline, |
| 1980 | hasWrittenPrototype, |
| 1981 | isConstexprSpecified); |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1982 | } |
| 1983 | if (func_decl) |
| 1984 | decl_ctx->addDecl (func_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1985 | |
| 1986 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1987 | VerifyDecl(func_decl); |
| 1988 | #endif |
| 1989 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1990 | return func_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1993 | CompilerType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1994 | ClangASTContext::CreateFunctionType (ASTContext *ast, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1995 | const CompilerType& result_type, |
| 1996 | const CompilerType *args, |
Sean Callanan | c81256a | 2010-09-16 20:40:25 +0000 | [diff] [blame] | 1997 | unsigned num_args, |
| 1998 | bool is_variadic, |
| 1999 | unsigned type_quals) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2000 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2001 | assert (ast != nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2002 | std::vector<QualType> qual_type_args; |
| 2003 | for (unsigned i=0; i<num_args; ++i) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2004 | qual_type_args.push_back (GetQualType(args[i])); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2005 | |
| 2006 | // TODO: Detect calling convention in DWARF? |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 2007 | FunctionProtoType::ExtProtoInfo proto_info; |
| 2008 | proto_info.Variadic = is_variadic; |
Sylvestre Ledru | 186ca7d | 2014-08-01 12:19:15 +0000 | [diff] [blame] | 2009 | proto_info.ExceptionSpec = EST_None; |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 2010 | proto_info.TypeQuals = type_quals; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 2011 | proto_info.RefQualifier = RQ_None; |
Sylvestre Ledru | 186ca7d | 2014-08-01 12:19:15 +0000 | [diff] [blame] | 2012 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2013 | return CompilerType (ast, ast->getFunctionType (GetQualType(result_type), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2014 | qual_type_args, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2015 | proto_info)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | ParmVarDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2019 | ClangASTContext::CreateParameterDeclaration (const char *name, const CompilerType ¶m_type, int storage) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2020 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2021 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2022 | assert (ast != nullptr); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2023 | return ParmVarDecl::Create(*ast, |
| 2024 | ast->getTranslationUnitDecl(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2025 | SourceLocation(), |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 2026 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2027 | name && name[0] ? &ast->Idents.get(name) : nullptr, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2028 | GetQualType(param_type), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2029 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 2030 | (clang::StorageClass)storage, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2031 | nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | void |
| 2035 | ClangASTContext::SetFunctionParameters (FunctionDecl *function_decl, ParmVarDecl **params, unsigned num_params) |
| 2036 | { |
| 2037 | if (function_decl) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 2038 | function_decl->setParams (ArrayRef<ParmVarDecl*>(params, num_params)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | |
| 2042 | #pragma mark Array Types |
| 2043 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2044 | CompilerType |
| 2045 | ClangASTContext::CreateArrayType (const CompilerType &element_type, |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2046 | size_t element_count, |
| 2047 | bool is_vector) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2048 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2049 | if (element_type.IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2050 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2051 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2052 | assert (ast != nullptr); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2053 | |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2054 | if (is_vector) |
| 2055 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2056 | return CompilerType (ast, ast->getExtVectorType(GetQualType(element_type), element_count)); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2057 | } |
| 2058 | else |
| 2059 | { |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2060 | |
| 2061 | llvm::APInt ap_element_count (64, element_count); |
| 2062 | if (element_count == 0) |
| 2063 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2064 | return CompilerType (ast, ast->getIncompleteArrayType (GetQualType(element_type), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2065 | ArrayType::Normal, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2066 | 0)); |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2067 | } |
| 2068 | else |
| 2069 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2070 | return CompilerType (ast, ast->getConstantArrayType (GetQualType(element_type), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2071 | ap_element_count, |
| 2072 | ArrayType::Normal, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2073 | 0)); |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2074 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2075 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2076 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2077 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2080 | CompilerType |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2081 | ClangASTContext::GetOrCreateStructForIdentifier (const ConstString &type_name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2082 | const std::initializer_list< std::pair < const char *, CompilerType > >& type_fields, |
Enrico Granata | a449e86 | 2014-10-30 00:53:28 +0000 | [diff] [blame] | 2083 | bool packed) |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2084 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2085 | CompilerType type; |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2086 | if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid()) |
| 2087 | return type; |
| 2088 | type = CreateRecordType(nullptr, lldb::eAccessPublic, type_name.GetCString(), clang::TTK_Struct, lldb::eLanguageTypeC); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2089 | StartTagDeclarationDefinition(type); |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2090 | for (const auto& field : type_fields) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2091 | AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic, 0); |
Enrico Granata | a449e86 | 2014-10-30 00:53:28 +0000 | [diff] [blame] | 2092 | if (packed) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2093 | SetIsPacked(type); |
| 2094 | CompleteTagDeclarationDefinition(type); |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2095 | return type; |
| 2096 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2097 | |
| 2098 | #pragma mark Enumeration Types |
| 2099 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2100 | CompilerType |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2101 | ClangASTContext::CreateEnumerationType |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2102 | ( |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2103 | const char *name, |
| 2104 | DeclContext *decl_ctx, |
| 2105 | const Declaration &decl, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2106 | const CompilerType &integer_clang_type |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2107 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2108 | { |
| 2109 | // TODO: Do something intelligent with the Declaration object passed in |
| 2110 | // like maybe filling in the SourceLocation with it... |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2111 | ASTContext *ast = getASTContext(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2112 | |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2113 | // TODO: ask about these... |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2114 | // const bool IsScoped = false; |
| 2115 | // const bool IsFixed = false; |
| 2116 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2117 | EnumDecl *enum_decl = EnumDecl::Create (*ast, |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2118 | decl_ctx, |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2119 | SourceLocation(), |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2120 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2121 | name && name[0] ? &ast->Idents.get(name) : nullptr, |
| 2122 | nullptr, |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 2123 | false, // IsScoped |
| 2124 | false, // IsScopedUsingClassTag |
| 2125 | false); // IsFixed |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 2126 | |
| 2127 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2128 | if (enum_decl) |
Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 2129 | { |
| 2130 | // TODO: check if we should be setting the promotion type too? |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2131 | enum_decl->setIntegerType(GetQualType(integer_clang_type)); |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 2132 | |
| 2133 | enum_decl->setAccess(AS_public); // TODO respect what's in the debug info |
| 2134 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2135 | return CompilerType (ast, ast->getTagDeclType(enum_decl)); |
Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 2136 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2137 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2138 | } |
| 2139 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2140 | // Disable this for now since I can't seem to get a nicely formatted float |
| 2141 | // out of the APFloat class without just getting the float, double or quad |
| 2142 | // and then using a formatted print on it which defeats the purpose. We ideally |
| 2143 | // would like to get perfect string values for any kind of float semantics |
| 2144 | // so we can support remote targets. The code below also requires a patch to |
| 2145 | // llvm::APInt. |
| 2146 | //bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2147 | //ClangASTContext::ConvertFloatValueToString (ASTContext *ast, lldb::opaque_compiler_type_t clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2148 | //{ |
| 2149 | // uint32_t count = 0; |
| 2150 | // bool is_complex = false; |
| 2151 | // if (ClangASTContext::IsFloatingPointType (clang_type, count, is_complex)) |
| 2152 | // { |
| 2153 | // unsigned num_bytes_per_float = byte_size / count; |
| 2154 | // unsigned num_bits_per_float = num_bytes_per_float * 8; |
| 2155 | // |
| 2156 | // float_str.clear(); |
| 2157 | // uint32_t i; |
| 2158 | // for (i=0; i<count; i++) |
| 2159 | // { |
| 2160 | // APInt ap_int(num_bits_per_float, bytes + i * num_bytes_per_float, (APInt::ByteOrder)apint_byte_order); |
| 2161 | // bool is_ieee = false; |
| 2162 | // APFloat ap_float(ap_int, is_ieee); |
| 2163 | // char s[1024]; |
| 2164 | // unsigned int hex_digits = 0; |
| 2165 | // bool upper_case = false; |
| 2166 | // |
| 2167 | // if (ap_float.convertToHexString(s, hex_digits, upper_case, APFloat::rmNearestTiesToEven) > 0) |
| 2168 | // { |
| 2169 | // if (i > 0) |
| 2170 | // float_str.append(", "); |
| 2171 | // float_str.append(s); |
| 2172 | // if (i == 1 && is_complex) |
| 2173 | // float_str.append(1, 'i'); |
| 2174 | // } |
| 2175 | // } |
| 2176 | // return !float_str.empty(); |
| 2177 | // } |
| 2178 | // return false; |
| 2179 | //} |
| 2180 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2181 | CompilerType |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2182 | ClangASTContext::GetIntTypeFromBitSize (clang::ASTContext *ast, |
| 2183 | size_t bit_size, bool is_signed) |
| 2184 | { |
| 2185 | if (ast) |
| 2186 | { |
| 2187 | if (is_signed) |
| 2188 | { |
| 2189 | if (bit_size == ast->getTypeSize(ast->SignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2190 | return CompilerType(ast, ast->SignedCharTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2191 | |
| 2192 | if (bit_size == ast->getTypeSize(ast->ShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2193 | return CompilerType(ast, ast->ShortTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2194 | |
| 2195 | if (bit_size == ast->getTypeSize(ast->IntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2196 | return CompilerType(ast, ast->IntTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2197 | |
| 2198 | if (bit_size == ast->getTypeSize(ast->LongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2199 | return CompilerType(ast, ast->LongTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2200 | |
| 2201 | if (bit_size == ast->getTypeSize(ast->LongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2202 | return CompilerType(ast, ast->LongLongTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2203 | |
| 2204 | if (bit_size == ast->getTypeSize(ast->Int128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2205 | return CompilerType(ast, ast->Int128Ty); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2206 | } |
| 2207 | else |
| 2208 | { |
| 2209 | if (bit_size == ast->getTypeSize(ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2210 | return CompilerType(ast, ast->UnsignedCharTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2211 | |
| 2212 | if (bit_size == ast->getTypeSize(ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2213 | return CompilerType(ast, ast->UnsignedShortTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2214 | |
| 2215 | if (bit_size == ast->getTypeSize(ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2216 | return CompilerType(ast, ast->UnsignedIntTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2217 | |
| 2218 | if (bit_size == ast->getTypeSize(ast->UnsignedLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2219 | return CompilerType(ast, ast->UnsignedLongTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2220 | |
| 2221 | if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2222 | return CompilerType(ast, ast->UnsignedLongLongTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2223 | |
| 2224 | if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2225 | return CompilerType(ast, ast->UnsignedInt128Ty); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2226 | } |
| 2227 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2228 | return CompilerType(); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2231 | CompilerType |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2232 | ClangASTContext::GetPointerSizedIntType (clang::ASTContext *ast, bool is_signed) |
| 2233 | { |
| 2234 | if (ast) |
| 2235 | return GetIntTypeFromBitSize(ast, ast->getTypeSize(ast->VoidPtrTy), is_signed); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2236 | return CompilerType(); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2237 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2238 | |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 2239 | bool |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2240 | ClangASTContext::GetCompleteDecl (clang::ASTContext *ast, |
| 2241 | clang::Decl *decl) |
| 2242 | { |
| 2243 | if (!decl) |
| 2244 | return false; |
| 2245 | |
| 2246 | ExternalASTSource *ast_source = ast->getExternalSource(); |
| 2247 | |
| 2248 | if (!ast_source) |
| 2249 | return false; |
| 2250 | |
| 2251 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) |
| 2252 | { |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2253 | if (tag_decl->isCompleteDefinition()) |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2254 | return true; |
| 2255 | |
| 2256 | if (!tag_decl->hasExternalLexicalStorage()) |
| 2257 | return false; |
| 2258 | |
| 2259 | ast_source->CompleteType(tag_decl); |
| 2260 | |
| 2261 | return !tag_decl->getTypeForDecl()->isIncompleteType(); |
| 2262 | } |
| 2263 | else if (clang::ObjCInterfaceDecl *objc_interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) |
| 2264 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2265 | if (objc_interface_decl->getDefinition()) |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2266 | return true; |
| 2267 | |
| 2268 | if (!objc_interface_decl->hasExternalLexicalStorage()) |
| 2269 | return false; |
| 2270 | |
| 2271 | ast_source->CompleteType(objc_interface_decl); |
| 2272 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2273 | return !objc_interface_decl->getTypeForDecl()->isIncompleteType(); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2274 | } |
| 2275 | else |
| 2276 | { |
| 2277 | return false; |
| 2278 | } |
| 2279 | } |
| 2280 | |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2281 | void |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2282 | ClangASTContext::SetMetadataAsUserID (const void *object, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2283 | user_id_t user_id) |
| 2284 | { |
| 2285 | ClangASTMetadata meta_data; |
| 2286 | meta_data.SetUserID (user_id); |
| 2287 | SetMetadata (object, meta_data); |
| 2288 | } |
| 2289 | |
| 2290 | void |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2291 | ClangASTContext::SetMetadata (clang::ASTContext *ast, |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2292 | const void *object, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2293 | ClangASTMetadata &metadata) |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2294 | { |
| 2295 | ClangExternalASTSourceCommon *external_source = |
Sean Callanan | ceeb74e | 2014-12-06 01:03:30 +0000 | [diff] [blame] | 2296 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2297 | |
| 2298 | if (external_source) |
| 2299 | external_source->SetMetadata(object, metadata); |
| 2300 | } |
| 2301 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2302 | ClangASTMetadata * |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2303 | ClangASTContext::GetMetadata (clang::ASTContext *ast, |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2304 | const void *object) |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2305 | { |
| 2306 | ClangExternalASTSourceCommon *external_source = |
Sean Callanan | ceeb74e | 2014-12-06 01:03:30 +0000 | [diff] [blame] | 2307 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2308 | |
| 2309 | if (external_source && external_source->HasMetadata(object)) |
| 2310 | return external_source->GetMetadata(object); |
| 2311 | else |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2312 | return nullptr; |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2315 | clang::DeclContext * |
| 2316 | ClangASTContext::GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl) |
| 2317 | { |
Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 2318 | return llvm::dyn_cast<clang::DeclContext>(cxx_method_decl); |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | clang::DeclContext * |
| 2322 | ClangASTContext::GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl) |
| 2323 | { |
Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 2324 | return llvm::dyn_cast<clang::DeclContext>(objc_method_decl); |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2327 | bool |
| 2328 | ClangASTContext::SetTagTypeKind (clang::QualType tag_qual_type, int kind) const |
| 2329 | { |
| 2330 | const clang::Type *clang_type = tag_qual_type.getTypePtr(); |
| 2331 | if (clang_type) |
| 2332 | { |
| 2333 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(clang_type); |
| 2334 | if (tag_type) |
| 2335 | { |
| 2336 | clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(tag_type->getDecl()); |
| 2337 | if (tag_decl) |
| 2338 | { |
| 2339 | tag_decl->setTagKind ((clang::TagDecl::TagKind)kind); |
| 2340 | return true; |
| 2341 | } |
| 2342 | } |
| 2343 | } |
| 2344 | return false; |
| 2345 | } |
| 2346 | |
| 2347 | |
| 2348 | bool |
| 2349 | ClangASTContext::SetDefaultAccessForRecordFields (clang::RecordDecl* record_decl, |
| 2350 | int default_accessibility, |
| 2351 | int *assigned_accessibilities, |
| 2352 | size_t num_assigned_accessibilities) |
| 2353 | { |
| 2354 | if (record_decl) |
| 2355 | { |
| 2356 | uint32_t field_idx; |
| 2357 | clang::RecordDecl::field_iterator field, field_end; |
| 2358 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(), field_idx = 0; |
| 2359 | field != field_end; |
| 2360 | ++field, ++field_idx) |
| 2361 | { |
| 2362 | // If no accessibility was assigned, assign the correct one |
| 2363 | if (field_idx < num_assigned_accessibilities && assigned_accessibilities[field_idx] == clang::AS_none) |
| 2364 | field->setAccess ((clang::AccessSpecifier)default_accessibility); |
| 2365 | } |
| 2366 | return true; |
| 2367 | } |
| 2368 | return false; |
| 2369 | } |
| 2370 | |
| 2371 | clang::DeclContext * |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2372 | ClangASTContext::GetDeclContextForType (const CompilerType& type) |
| 2373 | { |
| 2374 | return GetDeclContextForType(GetQualType(type)); |
| 2375 | } |
| 2376 | |
| 2377 | clang::DeclContext * |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2378 | ClangASTContext::GetDeclContextForType (clang::QualType type) |
| 2379 | { |
| 2380 | if (type.isNull()) |
| 2381 | return nullptr; |
| 2382 | |
| 2383 | clang::QualType qual_type = type.getCanonicalType(); |
| 2384 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2385 | switch (type_class) |
| 2386 | { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2387 | case clang::Type::ObjCInterface: return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())->getInterface(); |
| 2388 | case clang::Type::ObjCObjectPointer: return GetDeclContextForType (llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType()); |
| 2389 | case clang::Type::Record: return llvm::cast<clang::RecordType>(qual_type)->getDecl(); |
| 2390 | case clang::Type::Enum: return llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 2391 | case clang::Type::Typedef: return GetDeclContextForType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()); |
| 2392 | case clang::Type::Elaborated: return GetDeclContextForType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); |
| 2393 | case clang::Type::Paren: return GetDeclContextForType (llvm::cast<clang::ParenType>(qual_type)->desugar()); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2394 | default: |
| 2395 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2396 | } |
| 2397 | // No DeclContext in this type... |
| 2398 | return nullptr; |
| 2399 | } |
| 2400 | |
| 2401 | static bool |
| 2402 | GetCompleteQualType (clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion = true) |
| 2403 | { |
| 2404 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2405 | switch (type_class) |
| 2406 | { |
| 2407 | case clang::Type::ConstantArray: |
| 2408 | case clang::Type::IncompleteArray: |
| 2409 | case clang::Type::VariableArray: |
| 2410 | { |
| 2411 | const clang::ArrayType *array_type = llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr()); |
| 2412 | |
| 2413 | if (array_type) |
| 2414 | return GetCompleteQualType (ast, array_type->getElementType(), allow_completion); |
| 2415 | } |
| 2416 | break; |
| 2417 | |
| 2418 | case clang::Type::Record: |
| 2419 | case clang::Type::Enum: |
| 2420 | { |
| 2421 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 2422 | if (tag_type) |
| 2423 | { |
| 2424 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 2425 | if (tag_decl) |
| 2426 | { |
| 2427 | if (tag_decl->isCompleteDefinition()) |
| 2428 | return true; |
| 2429 | |
| 2430 | if (!allow_completion) |
| 2431 | return false; |
| 2432 | |
| 2433 | if (tag_decl->hasExternalLexicalStorage()) |
| 2434 | { |
| 2435 | if (ast) |
| 2436 | { |
| 2437 | clang::ExternalASTSource *external_ast_source = ast->getExternalSource(); |
| 2438 | if (external_ast_source) |
| 2439 | { |
| 2440 | external_ast_source->CompleteType(tag_decl); |
| 2441 | return !tag_type->isIncompleteType(); |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | return false; |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | } |
| 2450 | break; |
| 2451 | |
| 2452 | case clang::Type::ObjCObject: |
| 2453 | case clang::Type::ObjCInterface: |
| 2454 | { |
| 2455 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 2456 | if (objc_class_type) |
| 2457 | { |
| 2458 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 2459 | // We currently can't complete objective C types through the newly added ASTContext |
| 2460 | // because it only supports TagDecl objects right now... |
| 2461 | if (class_interface_decl) |
| 2462 | { |
| 2463 | if (class_interface_decl->getDefinition()) |
| 2464 | return true; |
| 2465 | |
| 2466 | if (!allow_completion) |
| 2467 | return false; |
| 2468 | |
| 2469 | if (class_interface_decl->hasExternalLexicalStorage()) |
| 2470 | { |
| 2471 | if (ast) |
| 2472 | { |
| 2473 | clang::ExternalASTSource *external_ast_source = ast->getExternalSource(); |
| 2474 | if (external_ast_source) |
| 2475 | { |
| 2476 | external_ast_source->CompleteType (class_interface_decl); |
| 2477 | return !objc_class_type->isIncompleteType(); |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | return false; |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | break; |
| 2486 | |
| 2487 | case clang::Type::Typedef: |
| 2488 | return GetCompleteQualType (ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(), allow_completion); |
| 2489 | |
| 2490 | case clang::Type::Elaborated: |
| 2491 | return GetCompleteQualType (ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(), allow_completion); |
| 2492 | |
| 2493 | case clang::Type::Paren: |
| 2494 | return GetCompleteQualType (ast, llvm::cast<clang::ParenType>(qual_type)->desugar(), allow_completion); |
| 2495 | |
| 2496 | default: |
| 2497 | break; |
| 2498 | } |
| 2499 | |
| 2500 | return true; |
| 2501 | } |
| 2502 | |
| 2503 | static clang::ObjCIvarDecl::AccessControl |
| 2504 | ConvertAccessTypeToObjCIvarAccessControl (AccessType access) |
| 2505 | { |
| 2506 | switch (access) |
| 2507 | { |
| 2508 | case eAccessNone: return clang::ObjCIvarDecl::None; |
| 2509 | case eAccessPublic: return clang::ObjCIvarDecl::Public; |
| 2510 | case eAccessPrivate: return clang::ObjCIvarDecl::Private; |
| 2511 | case eAccessProtected: return clang::ObjCIvarDecl::Protected; |
| 2512 | case eAccessPackage: return clang::ObjCIvarDecl::Package; |
| 2513 | } |
| 2514 | return clang::ObjCIvarDecl::None; |
| 2515 | } |
| 2516 | |
| 2517 | |
| 2518 | //---------------------------------------------------------------------- |
| 2519 | // Tests |
| 2520 | //---------------------------------------------------------------------- |
| 2521 | |
| 2522 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2523 | ClangASTContext::IsAggregateType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2524 | { |
| 2525 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2526 | |
| 2527 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2528 | switch (type_class) |
| 2529 | { |
| 2530 | case clang::Type::IncompleteArray: |
| 2531 | case clang::Type::VariableArray: |
| 2532 | case clang::Type::ConstantArray: |
| 2533 | case clang::Type::ExtVector: |
| 2534 | case clang::Type::Vector: |
| 2535 | case clang::Type::Record: |
| 2536 | case clang::Type::ObjCObject: |
| 2537 | case clang::Type::ObjCInterface: |
| 2538 | return true; |
| 2539 | case clang::Type::Elaborated: |
| 2540 | return IsAggregateType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 2541 | case clang::Type::Typedef: |
| 2542 | return IsAggregateType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 2543 | case clang::Type::Paren: |
| 2544 | return IsAggregateType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 2545 | default: |
| 2546 | break; |
| 2547 | } |
| 2548 | // The clang type does have a value |
| 2549 | return false; |
| 2550 | } |
| 2551 | |
| 2552 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2553 | ClangASTContext::IsArrayType (lldb::opaque_compiler_type_t type, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2554 | CompilerType *element_type_ptr, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2555 | uint64_t *size, |
| 2556 | bool *is_incomplete) |
| 2557 | { |
| 2558 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2559 | |
| 2560 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2561 | switch (type_class) |
| 2562 | { |
| 2563 | default: |
| 2564 | break; |
| 2565 | |
| 2566 | case clang::Type::ConstantArray: |
| 2567 | if (element_type_ptr) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2568 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2569 | if (size) |
| 2570 | *size = llvm::cast<clang::ConstantArrayType>(qual_type)->getSize().getLimitedValue(ULLONG_MAX); |
| 2571 | return true; |
| 2572 | |
| 2573 | case clang::Type::IncompleteArray: |
| 2574 | if (element_type_ptr) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2575 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2576 | if (size) |
| 2577 | *size = 0; |
| 2578 | if (is_incomplete) |
| 2579 | *is_incomplete = true; |
| 2580 | return true; |
| 2581 | |
| 2582 | case clang::Type::VariableArray: |
| 2583 | if (element_type_ptr) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2584 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::VariableArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2585 | if (size) |
| 2586 | *size = 0; |
| 2587 | return true; |
| 2588 | |
| 2589 | case clang::Type::DependentSizedArray: |
| 2590 | if (element_type_ptr) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2591 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::DependentSizedArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2592 | if (size) |
| 2593 | *size = 0; |
| 2594 | return true; |
| 2595 | |
| 2596 | case clang::Type::Typedef: |
| 2597 | return IsArrayType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 2598 | element_type_ptr, |
| 2599 | size, |
| 2600 | is_incomplete); |
| 2601 | case clang::Type::Elaborated: |
| 2602 | return IsArrayType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 2603 | element_type_ptr, |
| 2604 | size, |
| 2605 | is_incomplete); |
| 2606 | case clang::Type::Paren: |
| 2607 | return IsArrayType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 2608 | element_type_ptr, |
| 2609 | size, |
| 2610 | is_incomplete); |
| 2611 | } |
| 2612 | if (element_type_ptr) |
| 2613 | element_type_ptr->Clear(); |
| 2614 | if (size) |
| 2615 | *size = 0; |
| 2616 | if (is_incomplete) |
| 2617 | *is_incomplete = false; |
Bruce Mitchener | 778e7ab | 2015-09-16 00:00:16 +0000 | [diff] [blame] | 2618 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2622 | ClangASTContext::IsVectorType (lldb::opaque_compiler_type_t type, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2623 | CompilerType *element_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2624 | uint64_t *size) |
| 2625 | { |
| 2626 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2627 | |
| 2628 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2629 | switch (type_class) |
| 2630 | { |
| 2631 | case clang::Type::Vector: |
| 2632 | { |
| 2633 | const clang::VectorType *vector_type = qual_type->getAs<clang::VectorType>(); |
| 2634 | if (vector_type) |
| 2635 | { |
| 2636 | if (size) |
| 2637 | *size = vector_type->getNumElements(); |
| 2638 | if (element_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2639 | *element_type = CompilerType(getASTContext(), vector_type->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2640 | } |
| 2641 | return true; |
| 2642 | } |
| 2643 | break; |
| 2644 | case clang::Type::ExtVector: |
| 2645 | { |
| 2646 | const clang::ExtVectorType *ext_vector_type = qual_type->getAs<clang::ExtVectorType>(); |
| 2647 | if (ext_vector_type) |
| 2648 | { |
| 2649 | if (size) |
| 2650 | *size = ext_vector_type->getNumElements(); |
| 2651 | if (element_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2652 | *element_type = CompilerType(getASTContext(), ext_vector_type->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2653 | } |
| 2654 | return true; |
| 2655 | } |
| 2656 | default: |
| 2657 | break; |
| 2658 | } |
| 2659 | return false; |
| 2660 | } |
| 2661 | |
| 2662 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2663 | ClangASTContext::IsRuntimeGeneratedType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2664 | { |
| 2665 | clang::DeclContext* decl_ctx = ClangASTContext::GetASTContext(getASTContext())->GetDeclContextForType(GetQualType(type)); |
| 2666 | if (!decl_ctx) |
| 2667 | return false; |
| 2668 | |
| 2669 | if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx)) |
| 2670 | return false; |
| 2671 | |
| 2672 | clang::ObjCInterfaceDecl *result_iface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx); |
| 2673 | |
| 2674 | ClangASTMetadata* ast_metadata = ClangASTContext::GetMetadata(getASTContext(), result_iface_decl); |
| 2675 | if (!ast_metadata) |
| 2676 | return false; |
| 2677 | return (ast_metadata->GetISAPtr() != 0); |
| 2678 | } |
| 2679 | |
| 2680 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2681 | ClangASTContext::IsCharType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2682 | { |
| 2683 | return GetQualType(type).getUnqualifiedType()->isCharType(); |
| 2684 | } |
| 2685 | |
| 2686 | |
| 2687 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2688 | ClangASTContext::IsCompleteType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2689 | { |
| 2690 | const bool allow_completion = false; |
| 2691 | return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion); |
| 2692 | } |
| 2693 | |
| 2694 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2695 | ClangASTContext::IsConst(lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2696 | { |
| 2697 | return GetQualType(type).isConstQualified(); |
| 2698 | } |
| 2699 | |
| 2700 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2701 | ClangASTContext::IsCStringType (lldb::opaque_compiler_type_t type, uint32_t &length) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2702 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2703 | CompilerType pointee_or_element_clang_type; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2704 | length = 0; |
| 2705 | Flags type_flags (GetTypeInfo (type, &pointee_or_element_clang_type)); |
| 2706 | |
| 2707 | if (!pointee_or_element_clang_type.IsValid()) |
| 2708 | return false; |
| 2709 | |
| 2710 | if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer)) |
| 2711 | { |
| 2712 | if (pointee_or_element_clang_type.IsCharType()) |
| 2713 | { |
| 2714 | if (type_flags.Test (eTypeIsArray)) |
| 2715 | { |
| 2716 | // We know the size of the array and it could be a C string |
| 2717 | // since it is an array of characters |
| 2718 | length = llvm::cast<clang::ConstantArrayType>(GetCanonicalQualType(type).getTypePtr())->getSize().getLimitedValue(); |
| 2719 | } |
| 2720 | return true; |
| 2721 | |
| 2722 | } |
| 2723 | } |
| 2724 | return false; |
| 2725 | } |
| 2726 | |
| 2727 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2728 | ClangASTContext::IsFunctionType (lldb::opaque_compiler_type_t type, bool *is_variadic_ptr) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2729 | { |
| 2730 | if (type) |
| 2731 | { |
| 2732 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2733 | |
| 2734 | if (qual_type->isFunctionType()) |
| 2735 | { |
| 2736 | if (is_variadic_ptr) |
| 2737 | { |
| 2738 | const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 2739 | if (function_proto_type) |
| 2740 | *is_variadic_ptr = function_proto_type->isVariadic(); |
| 2741 | else |
| 2742 | *is_variadic_ptr = false; |
| 2743 | } |
| 2744 | return true; |
| 2745 | } |
| 2746 | |
| 2747 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2748 | switch (type_class) |
| 2749 | { |
| 2750 | default: |
| 2751 | break; |
| 2752 | case clang::Type::Typedef: |
| 2753 | return IsFunctionType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), nullptr); |
| 2754 | case clang::Type::Elaborated: |
| 2755 | return IsFunctionType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), nullptr); |
| 2756 | case clang::Type::Paren: |
| 2757 | return IsFunctionType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), nullptr); |
| 2758 | case clang::Type::LValueReference: |
| 2759 | case clang::Type::RValueReference: |
| 2760 | { |
| 2761 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 2762 | if (reference_type) |
| 2763 | return IsFunctionType(reference_type->getPointeeType().getAsOpaquePtr(), nullptr); |
| 2764 | } |
| 2765 | break; |
| 2766 | } |
| 2767 | } |
| 2768 | return false; |
| 2769 | } |
| 2770 | |
| 2771 | // Used to detect "Homogeneous Floating-point Aggregates" |
| 2772 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2773 | ClangASTContext::IsHomogeneousAggregate (lldb::opaque_compiler_type_t type, CompilerType* base_type_ptr) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2774 | { |
| 2775 | if (!type) |
| 2776 | return 0; |
| 2777 | |
| 2778 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2779 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2780 | switch (type_class) |
| 2781 | { |
| 2782 | case clang::Type::Record: |
| 2783 | if (GetCompleteType (type)) |
| 2784 | { |
| 2785 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 2786 | if (cxx_record_decl) |
| 2787 | { |
| 2788 | if (cxx_record_decl->getNumBases() || |
| 2789 | cxx_record_decl->isDynamicClass()) |
| 2790 | return 0; |
| 2791 | } |
| 2792 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 2793 | if (record_type) |
| 2794 | { |
| 2795 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 2796 | if (record_decl) |
| 2797 | { |
| 2798 | // We are looking for a structure that contains only floating point types |
| 2799 | clang::RecordDecl::field_iterator field_pos, field_end = record_decl->field_end(); |
| 2800 | uint32_t num_fields = 0; |
| 2801 | bool is_hva = false; |
| 2802 | bool is_hfa = false; |
| 2803 | clang::QualType base_qual_type; |
| 2804 | for (field_pos = record_decl->field_begin(); field_pos != field_end; ++field_pos) |
| 2805 | { |
| 2806 | clang::QualType field_qual_type = field_pos->getType(); |
| 2807 | if (field_qual_type->isFloatingType()) |
| 2808 | { |
| 2809 | if (field_qual_type->isComplexType()) |
| 2810 | return 0; |
| 2811 | else |
| 2812 | { |
| 2813 | if (num_fields == 0) |
| 2814 | base_qual_type = field_qual_type; |
| 2815 | else |
| 2816 | { |
| 2817 | if (is_hva) |
| 2818 | return 0; |
| 2819 | is_hfa = true; |
| 2820 | if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr()) |
| 2821 | return 0; |
| 2822 | } |
| 2823 | } |
| 2824 | } |
| 2825 | else if (field_qual_type->isVectorType() || field_qual_type->isExtVectorType()) |
| 2826 | { |
| 2827 | const clang::VectorType *array = field_qual_type.getTypePtr()->getAs<clang::VectorType>(); |
| 2828 | if (array && array->getNumElements() <= 4) |
| 2829 | { |
| 2830 | if (num_fields == 0) |
| 2831 | base_qual_type = array->getElementType(); |
| 2832 | else |
| 2833 | { |
| 2834 | if (is_hfa) |
| 2835 | return 0; |
| 2836 | is_hva = true; |
| 2837 | if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr()) |
| 2838 | return 0; |
| 2839 | } |
| 2840 | } |
| 2841 | else |
| 2842 | return 0; |
| 2843 | } |
| 2844 | else |
| 2845 | return 0; |
| 2846 | ++num_fields; |
| 2847 | } |
| 2848 | if (base_type_ptr) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2849 | *base_type_ptr = CompilerType (getASTContext(), base_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2850 | return num_fields; |
| 2851 | } |
| 2852 | } |
| 2853 | } |
| 2854 | break; |
| 2855 | |
| 2856 | case clang::Type::Typedef: |
| 2857 | return IsHomogeneousAggregate(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), base_type_ptr); |
| 2858 | |
| 2859 | case clang::Type::Elaborated: |
| 2860 | return IsHomogeneousAggregate(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), base_type_ptr); |
| 2861 | default: |
| 2862 | break; |
| 2863 | } |
| 2864 | return 0; |
| 2865 | } |
| 2866 | |
| 2867 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2868 | ClangASTContext::GetNumberOfFunctionArguments (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2869 | { |
| 2870 | if (type) |
| 2871 | { |
| 2872 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2873 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 2874 | if (func) |
| 2875 | return func->getNumParams(); |
| 2876 | } |
| 2877 | return 0; |
| 2878 | } |
| 2879 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2880 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2881 | ClangASTContext::GetFunctionArgumentAtIndex (lldb::opaque_compiler_type_t type, const size_t index) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2882 | { |
| 2883 | if (type) |
| 2884 | { |
| 2885 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2886 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 2887 | if (func) |
| 2888 | { |
| 2889 | if (index < func->getNumParams()) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2890 | return CompilerType(getASTContext(), func->getParamType(index)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2891 | } |
| 2892 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2893 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2897 | ClangASTContext::IsFunctionPointerType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2898 | { |
| 2899 | if (type) |
| 2900 | { |
| 2901 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2902 | |
| 2903 | if (qual_type->isFunctionPointerType()) |
| 2904 | return true; |
| 2905 | |
| 2906 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2907 | switch (type_class) |
| 2908 | { |
| 2909 | default: |
| 2910 | break; |
| 2911 | case clang::Type::Typedef: |
| 2912 | return IsFunctionPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 2913 | case clang::Type::Elaborated: |
| 2914 | return IsFunctionPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 2915 | case clang::Type::Paren: |
| 2916 | return IsFunctionPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 2917 | |
| 2918 | case clang::Type::LValueReference: |
| 2919 | case clang::Type::RValueReference: |
| 2920 | { |
| 2921 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 2922 | if (reference_type) |
| 2923 | return IsFunctionPointerType(reference_type->getPointeeType().getAsOpaquePtr()); |
| 2924 | } |
| 2925 | break; |
| 2926 | } |
| 2927 | } |
| 2928 | return false; |
| 2929 | |
| 2930 | } |
| 2931 | |
| 2932 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2933 | ClangASTContext::IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_signed) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2934 | { |
| 2935 | if (!type) |
| 2936 | return false; |
| 2937 | |
| 2938 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2939 | const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()); |
| 2940 | |
| 2941 | if (builtin_type) |
| 2942 | { |
| 2943 | if (builtin_type->isInteger()) |
| 2944 | { |
| 2945 | is_signed = builtin_type->isSignedInteger(); |
| 2946 | return true; |
| 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | return false; |
| 2951 | } |
| 2952 | |
| 2953 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2954 | ClangASTContext::IsPointerType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2955 | { |
| 2956 | if (type) |
| 2957 | { |
| 2958 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2959 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2960 | switch (type_class) |
| 2961 | { |
| 2962 | case clang::Type::Builtin: |
| 2963 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 2964 | { |
| 2965 | default: |
| 2966 | break; |
| 2967 | case clang::BuiltinType::ObjCId: |
| 2968 | case clang::BuiltinType::ObjCClass: |
| 2969 | return true; |
| 2970 | } |
| 2971 | return false; |
| 2972 | case clang::Type::ObjCObjectPointer: |
| 2973 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2974 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2975 | return true; |
| 2976 | case clang::Type::BlockPointer: |
| 2977 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2978 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2979 | return true; |
| 2980 | case clang::Type::Pointer: |
| 2981 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2982 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2983 | return true; |
| 2984 | case clang::Type::MemberPointer: |
| 2985 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2986 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2987 | return true; |
| 2988 | case clang::Type::Typedef: |
| 2989 | return IsPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type); |
| 2990 | case clang::Type::Elaborated: |
| 2991 | return IsPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type); |
| 2992 | case clang::Type::Paren: |
| 2993 | return IsPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type); |
| 2994 | default: |
| 2995 | break; |
| 2996 | } |
| 2997 | } |
| 2998 | if (pointee_type) |
| 2999 | pointee_type->Clear(); |
| 3000 | return false; |
| 3001 | } |
| 3002 | |
| 3003 | |
| 3004 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3005 | ClangASTContext::IsPointerOrReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3006 | { |
| 3007 | if (type) |
| 3008 | { |
| 3009 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3010 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3011 | switch (type_class) |
| 3012 | { |
| 3013 | case clang::Type::Builtin: |
| 3014 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 3015 | { |
| 3016 | default: |
| 3017 | break; |
| 3018 | case clang::BuiltinType::ObjCId: |
| 3019 | case clang::BuiltinType::ObjCClass: |
| 3020 | return true; |
| 3021 | } |
| 3022 | return false; |
| 3023 | case clang::Type::ObjCObjectPointer: |
| 3024 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3025 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3026 | return true; |
| 3027 | case clang::Type::BlockPointer: |
| 3028 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3029 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3030 | return true; |
| 3031 | case clang::Type::Pointer: |
| 3032 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3033 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3034 | return true; |
| 3035 | case clang::Type::MemberPointer: |
| 3036 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3037 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3038 | return true; |
| 3039 | case clang::Type::LValueReference: |
| 3040 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3041 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3042 | return true; |
| 3043 | case clang::Type::RValueReference: |
| 3044 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3045 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3046 | return true; |
| 3047 | case clang::Type::Typedef: |
| 3048 | return IsPointerOrReferenceType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type); |
| 3049 | case clang::Type::Elaborated: |
| 3050 | return IsPointerOrReferenceType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type); |
| 3051 | case clang::Type::Paren: |
| 3052 | return IsPointerOrReferenceType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type); |
| 3053 | default: |
| 3054 | break; |
| 3055 | } |
| 3056 | } |
| 3057 | if (pointee_type) |
| 3058 | pointee_type->Clear(); |
| 3059 | return false; |
| 3060 | } |
| 3061 | |
| 3062 | |
| 3063 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3064 | ClangASTContext::IsReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool* is_rvalue) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3065 | { |
| 3066 | if (type) |
| 3067 | { |
| 3068 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3069 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3070 | |
| 3071 | switch (type_class) |
| 3072 | { |
| 3073 | case clang::Type::LValueReference: |
| 3074 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3075 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3076 | if (is_rvalue) |
| 3077 | *is_rvalue = false; |
| 3078 | return true; |
| 3079 | case clang::Type::RValueReference: |
| 3080 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3081 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3082 | if (is_rvalue) |
| 3083 | *is_rvalue = true; |
| 3084 | return true; |
| 3085 | case clang::Type::Typedef: |
| 3086 | return IsReferenceType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type, is_rvalue); |
| 3087 | case clang::Type::Elaborated: |
| 3088 | return IsReferenceType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type, is_rvalue); |
| 3089 | case clang::Type::Paren: |
| 3090 | return IsReferenceType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type, is_rvalue); |
| 3091 | |
| 3092 | default: |
| 3093 | break; |
| 3094 | } |
| 3095 | } |
| 3096 | if (pointee_type) |
| 3097 | pointee_type->Clear(); |
| 3098 | return false; |
| 3099 | } |
| 3100 | |
| 3101 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3102 | ClangASTContext::IsFloatingPointType (lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3103 | { |
| 3104 | if (type) |
| 3105 | { |
| 3106 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3107 | |
| 3108 | if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal())) |
| 3109 | { |
| 3110 | clang::BuiltinType::Kind kind = BT->getKind(); |
| 3111 | if (kind >= clang::BuiltinType::Float && kind <= clang::BuiltinType::LongDouble) |
| 3112 | { |
| 3113 | count = 1; |
| 3114 | is_complex = false; |
| 3115 | return true; |
| 3116 | } |
| 3117 | } |
| 3118 | else if (const clang::ComplexType *CT = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal())) |
| 3119 | { |
| 3120 | if (IsFloatingPointType (CT->getElementType().getAsOpaquePtr(), count, is_complex)) |
| 3121 | { |
| 3122 | count = 2; |
| 3123 | is_complex = true; |
| 3124 | return true; |
| 3125 | } |
| 3126 | } |
| 3127 | else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal())) |
| 3128 | { |
| 3129 | if (IsFloatingPointType (VT->getElementType().getAsOpaquePtr(), count, is_complex)) |
| 3130 | { |
| 3131 | count = VT->getNumElements(); |
| 3132 | is_complex = false; |
| 3133 | return true; |
| 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | count = 0; |
| 3138 | is_complex = false; |
| 3139 | return false; |
| 3140 | } |
| 3141 | |
| 3142 | |
| 3143 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3144 | ClangASTContext::IsDefined(lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3145 | { |
| 3146 | if (!type) |
| 3147 | return false; |
| 3148 | |
| 3149 | clang::QualType qual_type(GetQualType(type)); |
| 3150 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 3151 | if (tag_type) |
| 3152 | { |
| 3153 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 3154 | if (tag_decl) |
| 3155 | return tag_decl->isCompleteDefinition(); |
| 3156 | return false; |
| 3157 | } |
| 3158 | else |
| 3159 | { |
| 3160 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 3161 | if (objc_class_type) |
| 3162 | { |
| 3163 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 3164 | if (class_interface_decl) |
| 3165 | return class_interface_decl->getDefinition() != nullptr; |
| 3166 | return false; |
| 3167 | } |
| 3168 | } |
| 3169 | return true; |
| 3170 | } |
| 3171 | |
| 3172 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3173 | ClangASTContext::IsObjCClassType (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3174 | { |
| 3175 | if (type) |
| 3176 | { |
| 3177 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3178 | |
| 3179 | const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); |
| 3180 | |
| 3181 | if (obj_pointer_type) |
| 3182 | return obj_pointer_type->isObjCClassType(); |
| 3183 | } |
| 3184 | return false; |
| 3185 | } |
| 3186 | |
| 3187 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3188 | ClangASTContext::IsObjCObjectOrInterfaceType (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3189 | { |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3190 | if (IsClangType(type)) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3191 | return GetCanonicalQualType(type)->isObjCObjectOrInterfaceType(); |
| 3192 | return false; |
| 3193 | } |
| 3194 | |
| 3195 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3196 | ClangASTContext::IsPolymorphicClass (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3197 | { |
| 3198 | if (type) |
| 3199 | { |
| 3200 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3201 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3202 | switch (type_class) |
| 3203 | { |
| 3204 | case clang::Type::Record: |
| 3205 | if (GetCompleteType(type)) |
| 3206 | { |
| 3207 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3208 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3209 | if (record_decl) |
| 3210 | { |
| 3211 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 3212 | if (cxx_record_decl) |
| 3213 | return cxx_record_decl->isPolymorphic(); |
| 3214 | } |
| 3215 | } |
| 3216 | break; |
| 3217 | |
| 3218 | default: |
| 3219 | break; |
| 3220 | } |
| 3221 | } |
| 3222 | return false; |
| 3223 | } |
| 3224 | |
| 3225 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3226 | ClangASTContext::IsPossibleDynamicType (lldb::opaque_compiler_type_t type, CompilerType *dynamic_pointee_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3227 | bool check_cplusplus, |
| 3228 | bool check_objc) |
| 3229 | { |
| 3230 | clang::QualType pointee_qual_type; |
| 3231 | if (type) |
| 3232 | { |
| 3233 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3234 | bool success = false; |
| 3235 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3236 | switch (type_class) |
| 3237 | { |
| 3238 | case clang::Type::Builtin: |
| 3239 | if (check_objc && llvm::cast<clang::BuiltinType>(qual_type)->getKind() == clang::BuiltinType::ObjCId) |
| 3240 | { |
| 3241 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3242 | dynamic_pointee_type->SetCompilerType(this, type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3243 | return true; |
| 3244 | } |
| 3245 | break; |
| 3246 | |
| 3247 | case clang::Type::ObjCObjectPointer: |
| 3248 | if (check_objc) |
| 3249 | { |
| 3250 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3251 | dynamic_pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3252 | return true; |
| 3253 | } |
| 3254 | break; |
| 3255 | |
| 3256 | case clang::Type::Pointer: |
| 3257 | pointee_qual_type = llvm::cast<clang::PointerType>(qual_type)->getPointeeType(); |
| 3258 | success = true; |
| 3259 | break; |
| 3260 | |
| 3261 | case clang::Type::LValueReference: |
| 3262 | case clang::Type::RValueReference: |
| 3263 | pointee_qual_type = llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType(); |
| 3264 | success = true; |
| 3265 | break; |
| 3266 | |
| 3267 | case clang::Type::Typedef: |
| 3268 | return IsPossibleDynamicType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 3269 | dynamic_pointee_type, |
| 3270 | check_cplusplus, |
| 3271 | check_objc); |
| 3272 | |
| 3273 | case clang::Type::Elaborated: |
| 3274 | return IsPossibleDynamicType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 3275 | dynamic_pointee_type, |
| 3276 | check_cplusplus, |
| 3277 | check_objc); |
| 3278 | |
| 3279 | case clang::Type::Paren: |
| 3280 | return IsPossibleDynamicType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3281 | dynamic_pointee_type, |
| 3282 | check_cplusplus, |
| 3283 | check_objc); |
| 3284 | default: |
| 3285 | break; |
| 3286 | } |
| 3287 | |
| 3288 | if (success) |
| 3289 | { |
| 3290 | // Check to make sure what we are pointing too is a possible dynamic C++ type |
| 3291 | // We currently accept any "void *" (in case we have a class that has been |
| 3292 | // watered down to an opaque pointer) and virtual C++ classes. |
| 3293 | const clang::Type::TypeClass pointee_type_class = pointee_qual_type.getCanonicalType()->getTypeClass(); |
| 3294 | switch (pointee_type_class) |
| 3295 | { |
| 3296 | case clang::Type::Builtin: |
| 3297 | switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) |
| 3298 | { |
| 3299 | case clang::BuiltinType::UnknownAny: |
| 3300 | case clang::BuiltinType::Void: |
| 3301 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3302 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3303 | return true; |
Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 3304 | default: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3305 | break; |
| 3306 | } |
| 3307 | break; |
| 3308 | |
| 3309 | case clang::Type::Record: |
| 3310 | if (check_cplusplus) |
| 3311 | { |
| 3312 | clang::CXXRecordDecl *cxx_record_decl = pointee_qual_type->getAsCXXRecordDecl(); |
| 3313 | if (cxx_record_decl) |
| 3314 | { |
| 3315 | bool is_complete = cxx_record_decl->isCompleteDefinition(); |
| 3316 | |
| 3317 | if (is_complete) |
| 3318 | success = cxx_record_decl->isDynamicClass(); |
| 3319 | else |
| 3320 | { |
| 3321 | ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), cxx_record_decl); |
| 3322 | if (metadata) |
| 3323 | success = metadata->GetIsDynamicCXXType(); |
| 3324 | else |
| 3325 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3326 | is_complete = CompilerType(getASTContext(), pointee_qual_type).GetCompleteType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3327 | if (is_complete) |
| 3328 | success = cxx_record_decl->isDynamicClass(); |
| 3329 | else |
| 3330 | success = false; |
| 3331 | } |
| 3332 | } |
| 3333 | |
| 3334 | if (success) |
| 3335 | { |
| 3336 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3337 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3338 | return true; |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | break; |
| 3343 | |
| 3344 | case clang::Type::ObjCObject: |
| 3345 | case clang::Type::ObjCInterface: |
| 3346 | if (check_objc) |
| 3347 | { |
| 3348 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3349 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3350 | return true; |
| 3351 | } |
| 3352 | break; |
| 3353 | |
| 3354 | default: |
| 3355 | break; |
| 3356 | } |
| 3357 | } |
| 3358 | } |
| 3359 | if (dynamic_pointee_type) |
| 3360 | dynamic_pointee_type->Clear(); |
| 3361 | return false; |
| 3362 | } |
| 3363 | |
| 3364 | |
| 3365 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3366 | ClangASTContext::IsScalarType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3367 | { |
| 3368 | if (!type) |
| 3369 | return false; |
| 3370 | |
| 3371 | return (GetTypeInfo (type, nullptr) & eTypeIsScalar) != 0; |
| 3372 | } |
| 3373 | |
| 3374 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3375 | ClangASTContext::IsTypedefType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3376 | { |
| 3377 | if (!type) |
| 3378 | return false; |
| 3379 | return GetQualType(type)->getTypeClass() == clang::Type::Typedef; |
| 3380 | } |
| 3381 | |
| 3382 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3383 | ClangASTContext::IsVoidType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3384 | { |
| 3385 | if (!type) |
| 3386 | return false; |
| 3387 | return GetCanonicalQualType(type)->isVoidType(); |
| 3388 | } |
| 3389 | |
| 3390 | bool |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 3391 | ClangASTContext::SupportsLanguage (lldb::LanguageType language) |
| 3392 | { |
| 3393 | return ClangASTContextSupportsLanguage(language); |
| 3394 | } |
| 3395 | |
| 3396 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3397 | ClangASTContext::GetCXXClassName (const CompilerType& type, std::string &class_name) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3398 | { |
| 3399 | if (type) |
| 3400 | { |
| 3401 | clang::QualType qual_type (GetCanonicalQualType(type)); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3402 | if (!qual_type.isNull()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3403 | { |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3404 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 3405 | if (cxx_record_decl) |
| 3406 | { |
| 3407 | class_name.assign(cxx_record_decl->getIdentifier()->getNameStart()); |
| 3408 | return true; |
| 3409 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3410 | } |
| 3411 | } |
| 3412 | class_name.clear(); |
| 3413 | return false; |
| 3414 | } |
| 3415 | |
| 3416 | |
| 3417 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3418 | ClangASTContext::IsCXXClassType (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3419 | { |
| 3420 | if (!type) |
| 3421 | return false; |
| 3422 | |
| 3423 | clang::QualType qual_type (GetCanonicalQualType(type)); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3424 | if (!qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3425 | return true; |
| 3426 | return false; |
| 3427 | } |
| 3428 | |
| 3429 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3430 | ClangASTContext::IsBeingDefined (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3431 | { |
| 3432 | if (!type) |
| 3433 | return false; |
| 3434 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3435 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type); |
| 3436 | if (tag_type) |
| 3437 | return tag_type->isBeingDefined(); |
| 3438 | return false; |
| 3439 | } |
| 3440 | |
| 3441 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3442 | ClangASTContext::IsObjCObjectPointerType (const CompilerType& type, CompilerType *class_type_ptr) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3443 | { |
| 3444 | if (!type) |
| 3445 | return false; |
| 3446 | |
| 3447 | clang::QualType qual_type (GetCanonicalQualType(type)); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3448 | |
| 3449 | if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3450 | { |
| 3451 | if (class_type_ptr) |
| 3452 | { |
| 3453 | if (!qual_type->isObjCClassType() && |
| 3454 | !qual_type->isObjCIdType()) |
| 3455 | { |
| 3456 | const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); |
| 3457 | if (obj_pointer_type == nullptr) |
| 3458 | class_type_ptr->Clear(); |
| 3459 | else |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3460 | class_type_ptr->SetCompilerType (type.GetTypeSystem(), clang::QualType(obj_pointer_type->getInterfaceType(), 0).getAsOpaquePtr()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3461 | } |
| 3462 | } |
| 3463 | return true; |
| 3464 | } |
| 3465 | if (class_type_ptr) |
| 3466 | class_type_ptr->Clear(); |
| 3467 | return false; |
| 3468 | } |
| 3469 | |
| 3470 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3471 | ClangASTContext::GetObjCClassName (const CompilerType& type, std::string &class_name) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3472 | { |
| 3473 | if (!type) |
| 3474 | return false; |
| 3475 | |
| 3476 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3477 | |
| 3478 | const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 3479 | if (object_type) |
| 3480 | { |
| 3481 | const clang::ObjCInterfaceDecl *interface = object_type->getInterface(); |
| 3482 | if (interface) |
| 3483 | { |
| 3484 | class_name = interface->getNameAsString(); |
| 3485 | return true; |
| 3486 | } |
| 3487 | } |
| 3488 | return false; |
| 3489 | } |
| 3490 | |
| 3491 | |
| 3492 | //---------------------------------------------------------------------- |
| 3493 | // Type Completion |
| 3494 | //---------------------------------------------------------------------- |
| 3495 | |
| 3496 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3497 | ClangASTContext::GetCompleteType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3498 | { |
| 3499 | if (!type) |
| 3500 | return false; |
| 3501 | const bool allow_completion = true; |
| 3502 | return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion); |
| 3503 | } |
| 3504 | |
| 3505 | ConstString |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3506 | ClangASTContext::GetTypeName (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3507 | { |
| 3508 | std::string type_name; |
| 3509 | if (type) |
| 3510 | { |
| 3511 | clang::PrintingPolicy printing_policy (getASTContext()->getPrintingPolicy()); |
| 3512 | clang::QualType qual_type(GetQualType(type)); |
| 3513 | printing_policy.SuppressTagKeyword = true; |
| 3514 | printing_policy.LangOpts.WChar = true; |
| 3515 | const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>(); |
| 3516 | if (typedef_type) |
| 3517 | { |
| 3518 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 3519 | type_name = typedef_decl->getQualifiedNameAsString(); |
| 3520 | } |
| 3521 | else |
| 3522 | { |
| 3523 | type_name = qual_type.getAsString(printing_policy); |
| 3524 | } |
| 3525 | } |
| 3526 | return ConstString(type_name); |
| 3527 | } |
| 3528 | |
| 3529 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3530 | ClangASTContext::GetTypeInfo (lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_clang_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3531 | { |
| 3532 | if (!type) |
| 3533 | return 0; |
| 3534 | |
| 3535 | if (pointee_or_element_clang_type) |
| 3536 | pointee_or_element_clang_type->Clear(); |
| 3537 | |
| 3538 | clang::QualType qual_type (GetQualType(type)); |
| 3539 | |
| 3540 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3541 | switch (type_class) |
| 3542 | { |
| 3543 | case clang::Type::Builtin: |
| 3544 | { |
| 3545 | const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()); |
| 3546 | |
| 3547 | uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue; |
| 3548 | switch (builtin_type->getKind()) |
| 3549 | { |
| 3550 | case clang::BuiltinType::ObjCId: |
| 3551 | case clang::BuiltinType::ObjCClass: |
| 3552 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3553 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->ObjCBuiltinClassTy); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3554 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; |
| 3555 | break; |
| 3556 | |
| 3557 | case clang::BuiltinType::ObjCSel: |
| 3558 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3559 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->CharTy); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3560 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; |
| 3561 | break; |
| 3562 | |
| 3563 | case clang::BuiltinType::Bool: |
| 3564 | case clang::BuiltinType::Char_U: |
| 3565 | case clang::BuiltinType::UChar: |
| 3566 | case clang::BuiltinType::WChar_U: |
| 3567 | case clang::BuiltinType::Char16: |
| 3568 | case clang::BuiltinType::Char32: |
| 3569 | case clang::BuiltinType::UShort: |
| 3570 | case clang::BuiltinType::UInt: |
| 3571 | case clang::BuiltinType::ULong: |
| 3572 | case clang::BuiltinType::ULongLong: |
| 3573 | case clang::BuiltinType::UInt128: |
| 3574 | case clang::BuiltinType::Char_S: |
| 3575 | case clang::BuiltinType::SChar: |
| 3576 | case clang::BuiltinType::WChar_S: |
| 3577 | case clang::BuiltinType::Short: |
| 3578 | case clang::BuiltinType::Int: |
| 3579 | case clang::BuiltinType::Long: |
| 3580 | case clang::BuiltinType::LongLong: |
| 3581 | case clang::BuiltinType::Int128: |
| 3582 | case clang::BuiltinType::Float: |
| 3583 | case clang::BuiltinType::Double: |
| 3584 | case clang::BuiltinType::LongDouble: |
| 3585 | builtin_type_flags |= eTypeIsScalar; |
| 3586 | if (builtin_type->isInteger()) |
| 3587 | { |
| 3588 | builtin_type_flags |= eTypeIsInteger; |
| 3589 | if (builtin_type->isSignedInteger()) |
| 3590 | builtin_type_flags |= eTypeIsSigned; |
| 3591 | } |
| 3592 | else if (builtin_type->isFloatingPoint()) |
| 3593 | builtin_type_flags |= eTypeIsFloat; |
| 3594 | break; |
| 3595 | default: |
| 3596 | break; |
| 3597 | } |
| 3598 | return builtin_type_flags; |
| 3599 | } |
| 3600 | |
| 3601 | case clang::Type::BlockPointer: |
| 3602 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3603 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3604 | return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock; |
| 3605 | |
| 3606 | case clang::Type::Complex: |
| 3607 | { |
| 3608 | uint32_t complex_type_flags = eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex; |
| 3609 | const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal()); |
| 3610 | if (complex_type) |
| 3611 | { |
| 3612 | clang::QualType complex_element_type (complex_type->getElementType()); |
| 3613 | if (complex_element_type->isIntegerType()) |
| 3614 | complex_type_flags |= eTypeIsFloat; |
| 3615 | else if (complex_element_type->isFloatingType()) |
| 3616 | complex_type_flags |= eTypeIsInteger; |
| 3617 | } |
| 3618 | return complex_type_flags; |
| 3619 | } |
| 3620 | break; |
| 3621 | |
| 3622 | case clang::Type::ConstantArray: |
| 3623 | case clang::Type::DependentSizedArray: |
| 3624 | case clang::Type::IncompleteArray: |
| 3625 | case clang::Type::VariableArray: |
| 3626 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3627 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3628 | return eTypeHasChildren | eTypeIsArray; |
| 3629 | |
| 3630 | case clang::Type::DependentName: return 0; |
| 3631 | case clang::Type::DependentSizedExtVector: return eTypeHasChildren | eTypeIsVector; |
| 3632 | case clang::Type::DependentTemplateSpecialization: return eTypeIsTemplate; |
| 3633 | case clang::Type::Decltype: return 0; |
| 3634 | |
| 3635 | case clang::Type::Enum: |
| 3636 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3637 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::EnumType>(qual_type)->getDecl()->getIntegerType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3638 | return eTypeIsEnumeration | eTypeHasValue; |
| 3639 | |
| 3640 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3641 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeInfo (pointee_or_element_clang_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3642 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3643 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeInfo (pointee_or_element_clang_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3644 | |
| 3645 | case clang::Type::FunctionProto: return eTypeIsFuncPrototype | eTypeHasValue; |
| 3646 | case clang::Type::FunctionNoProto: return eTypeIsFuncPrototype | eTypeHasValue; |
| 3647 | case clang::Type::InjectedClassName: return 0; |
| 3648 | |
| 3649 | case clang::Type::LValueReference: |
| 3650 | case clang::Type::RValueReference: |
| 3651 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3652 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3653 | return eTypeHasChildren | eTypeIsReference | eTypeHasValue; |
| 3654 | |
| 3655 | case clang::Type::MemberPointer: return eTypeIsPointer | eTypeIsMember | eTypeHasValue; |
| 3656 | |
| 3657 | case clang::Type::ObjCObjectPointer: |
| 3658 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3659 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3660 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | eTypeHasValue; |
| 3661 | |
| 3662 | case clang::Type::ObjCObject: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 3663 | case clang::Type::ObjCInterface: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 3664 | |
| 3665 | case clang::Type::Pointer: |
| 3666 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3667 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3668 | return eTypeHasChildren | eTypeIsPointer | eTypeHasValue; |
| 3669 | |
| 3670 | case clang::Type::Record: |
| 3671 | if (qual_type->getAsCXXRecordDecl()) |
| 3672 | return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus; |
| 3673 | else |
| 3674 | return eTypeHasChildren | eTypeIsStructUnion; |
| 3675 | break; |
| 3676 | case clang::Type::SubstTemplateTypeParm: return eTypeIsTemplate; |
| 3677 | case clang::Type::TemplateTypeParm: return eTypeIsTemplate; |
| 3678 | case clang::Type::TemplateSpecialization: return eTypeIsTemplate; |
| 3679 | |
| 3680 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3681 | return eTypeIsTypedef | CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetTypeInfo (pointee_or_element_clang_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3682 | case clang::Type::TypeOfExpr: return 0; |
| 3683 | case clang::Type::TypeOf: return 0; |
| 3684 | case clang::Type::UnresolvedUsing: return 0; |
| 3685 | |
| 3686 | case clang::Type::ExtVector: |
| 3687 | case clang::Type::Vector: |
| 3688 | { |
| 3689 | uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector; |
| 3690 | const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal()); |
| 3691 | if (vector_type) |
| 3692 | { |
| 3693 | if (vector_type->isIntegerType()) |
| 3694 | vector_type_flags |= eTypeIsFloat; |
| 3695 | else if (vector_type->isFloatingType()) |
| 3696 | vector_type_flags |= eTypeIsInteger; |
| 3697 | } |
| 3698 | return vector_type_flags; |
| 3699 | } |
| 3700 | default: return 0; |
| 3701 | } |
| 3702 | return 0; |
| 3703 | } |
| 3704 | |
| 3705 | |
| 3706 | |
| 3707 | lldb::LanguageType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3708 | ClangASTContext::GetMinimumLanguage (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3709 | { |
| 3710 | if (!type) |
| 3711 | return lldb::eLanguageTypeC; |
| 3712 | |
| 3713 | // If the type is a reference, then resolve it to what it refers to first: |
| 3714 | clang::QualType qual_type (GetCanonicalQualType(type).getNonReferenceType()); |
| 3715 | if (qual_type->isAnyPointerType()) |
| 3716 | { |
| 3717 | if (qual_type->isObjCObjectPointerType()) |
| 3718 | return lldb::eLanguageTypeObjC; |
| 3719 | |
| 3720 | clang::QualType pointee_type (qual_type->getPointeeType()); |
| 3721 | if (pointee_type->getPointeeCXXRecordDecl() != nullptr) |
| 3722 | return lldb::eLanguageTypeC_plus_plus; |
| 3723 | if (pointee_type->isObjCObjectOrInterfaceType()) |
| 3724 | return lldb::eLanguageTypeObjC; |
| 3725 | if (pointee_type->isObjCClassType()) |
| 3726 | return lldb::eLanguageTypeObjC; |
| 3727 | if (pointee_type.getTypePtr() == getASTContext()->ObjCBuiltinIdTy.getTypePtr()) |
| 3728 | return lldb::eLanguageTypeObjC; |
| 3729 | } |
| 3730 | else |
| 3731 | { |
| 3732 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 3733 | return lldb::eLanguageTypeObjC; |
| 3734 | if (qual_type->getAsCXXRecordDecl()) |
| 3735 | return lldb::eLanguageTypeC_plus_plus; |
| 3736 | switch (qual_type->getTypeClass()) |
| 3737 | { |
| 3738 | default: |
| 3739 | break; |
| 3740 | case clang::Type::Builtin: |
| 3741 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 3742 | { |
| 3743 | default: |
| 3744 | case clang::BuiltinType::Void: |
| 3745 | case clang::BuiltinType::Bool: |
| 3746 | case clang::BuiltinType::Char_U: |
| 3747 | case clang::BuiltinType::UChar: |
| 3748 | case clang::BuiltinType::WChar_U: |
| 3749 | case clang::BuiltinType::Char16: |
| 3750 | case clang::BuiltinType::Char32: |
| 3751 | case clang::BuiltinType::UShort: |
| 3752 | case clang::BuiltinType::UInt: |
| 3753 | case clang::BuiltinType::ULong: |
| 3754 | case clang::BuiltinType::ULongLong: |
| 3755 | case clang::BuiltinType::UInt128: |
| 3756 | case clang::BuiltinType::Char_S: |
| 3757 | case clang::BuiltinType::SChar: |
| 3758 | case clang::BuiltinType::WChar_S: |
| 3759 | case clang::BuiltinType::Short: |
| 3760 | case clang::BuiltinType::Int: |
| 3761 | case clang::BuiltinType::Long: |
| 3762 | case clang::BuiltinType::LongLong: |
| 3763 | case clang::BuiltinType::Int128: |
| 3764 | case clang::BuiltinType::Float: |
| 3765 | case clang::BuiltinType::Double: |
| 3766 | case clang::BuiltinType::LongDouble: |
| 3767 | break; |
| 3768 | |
| 3769 | case clang::BuiltinType::NullPtr: |
| 3770 | return eLanguageTypeC_plus_plus; |
| 3771 | |
| 3772 | case clang::BuiltinType::ObjCId: |
| 3773 | case clang::BuiltinType::ObjCClass: |
| 3774 | case clang::BuiltinType::ObjCSel: |
| 3775 | return eLanguageTypeObjC; |
| 3776 | |
| 3777 | case clang::BuiltinType::Dependent: |
| 3778 | case clang::BuiltinType::Overload: |
| 3779 | case clang::BuiltinType::BoundMember: |
| 3780 | case clang::BuiltinType::UnknownAny: |
| 3781 | break; |
| 3782 | } |
| 3783 | break; |
| 3784 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3785 | return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetMinimumLanguage(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3786 | } |
| 3787 | } |
| 3788 | return lldb::eLanguageTypeC; |
| 3789 | } |
| 3790 | |
| 3791 | lldb::TypeClass |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3792 | ClangASTContext::GetTypeClass (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3793 | { |
| 3794 | if (!type) |
| 3795 | return lldb::eTypeClassInvalid; |
| 3796 | |
| 3797 | clang::QualType qual_type(GetQualType(type)); |
| 3798 | |
| 3799 | switch (qual_type->getTypeClass()) |
| 3800 | { |
| 3801 | case clang::Type::UnaryTransform: break; |
| 3802 | case clang::Type::FunctionNoProto: return lldb::eTypeClassFunction; |
| 3803 | case clang::Type::FunctionProto: return lldb::eTypeClassFunction; |
| 3804 | case clang::Type::IncompleteArray: return lldb::eTypeClassArray; |
| 3805 | case clang::Type::VariableArray: return lldb::eTypeClassArray; |
| 3806 | case clang::Type::ConstantArray: return lldb::eTypeClassArray; |
| 3807 | case clang::Type::DependentSizedArray: return lldb::eTypeClassArray; |
| 3808 | case clang::Type::DependentSizedExtVector: return lldb::eTypeClassVector; |
| 3809 | case clang::Type::ExtVector: return lldb::eTypeClassVector; |
| 3810 | case clang::Type::Vector: return lldb::eTypeClassVector; |
| 3811 | case clang::Type::Builtin: return lldb::eTypeClassBuiltin; |
| 3812 | case clang::Type::ObjCObjectPointer: return lldb::eTypeClassObjCObjectPointer; |
| 3813 | case clang::Type::BlockPointer: return lldb::eTypeClassBlockPointer; |
| 3814 | case clang::Type::Pointer: return lldb::eTypeClassPointer; |
| 3815 | case clang::Type::LValueReference: return lldb::eTypeClassReference; |
| 3816 | case clang::Type::RValueReference: return lldb::eTypeClassReference; |
| 3817 | case clang::Type::MemberPointer: return lldb::eTypeClassMemberPointer; |
| 3818 | case clang::Type::Complex: |
| 3819 | if (qual_type->isComplexType()) |
| 3820 | return lldb::eTypeClassComplexFloat; |
| 3821 | else |
| 3822 | return lldb::eTypeClassComplexInteger; |
| 3823 | case clang::Type::ObjCObject: return lldb::eTypeClassObjCObject; |
| 3824 | case clang::Type::ObjCInterface: return lldb::eTypeClassObjCInterface; |
| 3825 | case clang::Type::Record: |
| 3826 | { |
| 3827 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3828 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3829 | if (record_decl->isUnion()) |
| 3830 | return lldb::eTypeClassUnion; |
| 3831 | else if (record_decl->isStruct()) |
| 3832 | return lldb::eTypeClassStruct; |
| 3833 | else |
| 3834 | return lldb::eTypeClassClass; |
| 3835 | } |
| 3836 | break; |
| 3837 | case clang::Type::Enum: return lldb::eTypeClassEnumeration; |
| 3838 | case clang::Type::Typedef: return lldb::eTypeClassTypedef; |
| 3839 | case clang::Type::UnresolvedUsing: break; |
| 3840 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3841 | return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeClass(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3842 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3843 | return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeClass(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3844 | |
| 3845 | case clang::Type::Attributed: break; |
| 3846 | case clang::Type::TemplateTypeParm: break; |
| 3847 | case clang::Type::SubstTemplateTypeParm: break; |
| 3848 | case clang::Type::SubstTemplateTypeParmPack:break; |
| 3849 | case clang::Type::Auto: break; |
| 3850 | case clang::Type::InjectedClassName: break; |
| 3851 | case clang::Type::DependentName: break; |
| 3852 | case clang::Type::DependentTemplateSpecialization: break; |
| 3853 | case clang::Type::PackExpansion: break; |
| 3854 | |
| 3855 | case clang::Type::TypeOfExpr: break; |
| 3856 | case clang::Type::TypeOf: break; |
| 3857 | case clang::Type::Decltype: break; |
| 3858 | case clang::Type::TemplateSpecialization: break; |
| 3859 | case clang::Type::Atomic: break; |
| 3860 | |
| 3861 | // pointer type decayed from an array or function type. |
| 3862 | case clang::Type::Decayed: break; |
| 3863 | case clang::Type::Adjusted: break; |
| 3864 | } |
| 3865 | // We don't know hot to display this type... |
| 3866 | return lldb::eTypeClassOther; |
| 3867 | |
| 3868 | } |
| 3869 | |
| 3870 | unsigned |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3871 | ClangASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3872 | { |
| 3873 | if (type) |
| 3874 | return GetQualType(type).getQualifiers().getCVRQualifiers(); |
| 3875 | return 0; |
| 3876 | } |
| 3877 | |
| 3878 | //---------------------------------------------------------------------- |
| 3879 | // Creating related types |
| 3880 | //---------------------------------------------------------------------- |
| 3881 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3882 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3883 | ClangASTContext::GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3884 | { |
| 3885 | if (type) |
| 3886 | { |
| 3887 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3888 | |
| 3889 | const clang::Type *array_eletype = qual_type.getTypePtr()->getArrayElementTypeNoTypeQual(); |
| 3890 | |
| 3891 | if (!array_eletype) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3892 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3893 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3894 | CompilerType element_type (getASTContext(), array_eletype->getCanonicalTypeUnqualified()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3895 | |
| 3896 | // TODO: the real stride will be >= this value.. find the real one! |
| 3897 | if (stride) |
| 3898 | *stride = element_type.GetByteSize(nullptr); |
| 3899 | |
| 3900 | return element_type; |
| 3901 | |
| 3902 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3903 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3904 | } |
| 3905 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3906 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3907 | ClangASTContext::GetCanonicalType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3908 | { |
| 3909 | if (type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3910 | return CompilerType (getASTContext(), GetCanonicalQualType(type)); |
| 3911 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | static clang::QualType |
| 3915 | GetFullyUnqualifiedType_Impl (clang::ASTContext *ast, clang::QualType qual_type) |
| 3916 | { |
| 3917 | if (qual_type->isPointerType()) |
| 3918 | qual_type = ast->getPointerType(GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType())); |
| 3919 | else |
| 3920 | qual_type = qual_type.getUnqualifiedType(); |
| 3921 | qual_type.removeLocalConst(); |
| 3922 | qual_type.removeLocalRestrict(); |
| 3923 | qual_type.removeLocalVolatile(); |
| 3924 | return qual_type; |
| 3925 | } |
| 3926 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3927 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3928 | ClangASTContext::GetFullyUnqualifiedType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3929 | { |
| 3930 | if (type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3931 | return CompilerType(getASTContext(), GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type))); |
| 3932 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3933 | } |
| 3934 | |
| 3935 | |
| 3936 | int |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3937 | ClangASTContext::GetFunctionArgumentCount (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3938 | { |
| 3939 | if (type) |
| 3940 | { |
| 3941 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type)); |
| 3942 | if (func) |
| 3943 | return func->getNumParams(); |
| 3944 | } |
| 3945 | return -1; |
| 3946 | } |
| 3947 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3948 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3949 | ClangASTContext::GetFunctionArgumentTypeAtIndex (lldb::opaque_compiler_type_t type, size_t idx) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3950 | { |
| 3951 | if (type) |
| 3952 | { |
| 3953 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type)); |
| 3954 | if (func) |
| 3955 | { |
| 3956 | const uint32_t num_args = func->getNumParams(); |
| 3957 | if (idx < num_args) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3958 | return CompilerType(getASTContext(), func->getParamType(idx)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3959 | } |
| 3960 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3961 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3962 | } |
| 3963 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3964 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3965 | ClangASTContext::GetFunctionReturnType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3966 | { |
| 3967 | if (type) |
| 3968 | { |
| 3969 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3970 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 3971 | if (func) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3972 | return CompilerType(getASTContext(), func->getReturnType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3973 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3974 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3978 | ClangASTContext::GetNumMemberFunctions (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3979 | { |
| 3980 | size_t num_functions = 0; |
| 3981 | if (type) |
| 3982 | { |
| 3983 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3984 | switch (qual_type->getTypeClass()) { |
| 3985 | case clang::Type::Record: |
| 3986 | if (GetCompleteQualType (getASTContext(), qual_type)) |
| 3987 | { |
| 3988 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3989 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3990 | assert(record_decl); |
| 3991 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 3992 | if (cxx_record_decl) |
| 3993 | num_functions = std::distance(cxx_record_decl->method_begin(), cxx_record_decl->method_end()); |
| 3994 | } |
| 3995 | break; |
| 3996 | |
| 3997 | case clang::Type::ObjCObjectPointer: |
| 3998 | if (GetCompleteType(type)) |
| 3999 | { |
| 4000 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); |
| 4001 | if (objc_class_type) |
| 4002 | { |
| 4003 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); |
| 4004 | if (class_interface_decl) |
| 4005 | num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end()); |
| 4006 | } |
| 4007 | } |
| 4008 | break; |
| 4009 | |
| 4010 | case clang::Type::ObjCObject: |
| 4011 | case clang::Type::ObjCInterface: |
| 4012 | if (GetCompleteType(type)) |
| 4013 | { |
| 4014 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4015 | if (objc_class_type) |
| 4016 | { |
| 4017 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 4018 | if (class_interface_decl) |
| 4019 | num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end()); |
| 4020 | } |
| 4021 | } |
| 4022 | break; |
| 4023 | |
| 4024 | |
| 4025 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4026 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumMemberFunctions(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4027 | |
| 4028 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4029 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumMemberFunctions(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4030 | |
| 4031 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4032 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumMemberFunctions(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4033 | |
| 4034 | default: |
| 4035 | break; |
| 4036 | } |
| 4037 | } |
| 4038 | return num_functions; |
| 4039 | } |
| 4040 | |
| 4041 | TypeMemberFunctionImpl |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4042 | ClangASTContext::GetMemberFunctionAtIndex (lldb::opaque_compiler_type_t type, size_t idx) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4043 | { |
| 4044 | std::string name(""); |
| 4045 | MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4046 | CompilerType clang_type{}; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4047 | clang::ObjCMethodDecl *method_decl(nullptr); |
| 4048 | if (type) |
| 4049 | { |
| 4050 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4051 | switch (qual_type->getTypeClass()) { |
| 4052 | case clang::Type::Record: |
| 4053 | if (GetCompleteQualType (getASTContext(), qual_type)) |
| 4054 | { |
| 4055 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4056 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4057 | assert(record_decl); |
| 4058 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 4059 | if (cxx_record_decl) |
| 4060 | { |
| 4061 | auto method_iter = cxx_record_decl->method_begin(); |
| 4062 | auto method_end = cxx_record_decl->method_end(); |
| 4063 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) |
| 4064 | { |
| 4065 | std::advance(method_iter, idx); |
| 4066 | auto method_decl = method_iter->getCanonicalDecl(); |
| 4067 | if (method_decl) |
| 4068 | { |
| 4069 | if (!method_decl->getName().empty()) |
| 4070 | name.assign(method_decl->getName().data()); |
| 4071 | else |
| 4072 | name.clear(); |
| 4073 | if (method_decl->isStatic()) |
| 4074 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4075 | else if (llvm::isa<clang::CXXConstructorDecl>(method_decl)) |
| 4076 | kind = lldb::eMemberFunctionKindConstructor; |
| 4077 | else if (llvm::isa<clang::CXXDestructorDecl>(method_decl)) |
| 4078 | kind = lldb::eMemberFunctionKindDestructor; |
| 4079 | else |
| 4080 | kind = lldb::eMemberFunctionKindInstanceMethod; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4081 | clang_type = CompilerType(getASTContext(),method_decl->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4082 | } |
| 4083 | } |
| 4084 | } |
| 4085 | } |
| 4086 | break; |
| 4087 | |
| 4088 | case clang::Type::ObjCObjectPointer: |
| 4089 | if (GetCompleteType(type)) |
| 4090 | { |
| 4091 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); |
| 4092 | if (objc_class_type) |
| 4093 | { |
| 4094 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); |
| 4095 | if (class_interface_decl) |
| 4096 | { |
| 4097 | auto method_iter = class_interface_decl->meth_begin(); |
| 4098 | auto method_end = class_interface_decl->meth_end(); |
| 4099 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) |
| 4100 | { |
| 4101 | std::advance(method_iter, idx); |
| 4102 | method_decl = method_iter->getCanonicalDecl(); |
| 4103 | if (method_decl) |
| 4104 | { |
| 4105 | name = method_decl->getSelector().getAsString(); |
| 4106 | if (method_decl->isClassMethod()) |
| 4107 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4108 | else |
| 4109 | kind = lldb::eMemberFunctionKindInstanceMethod; |
| 4110 | } |
| 4111 | } |
| 4112 | } |
| 4113 | } |
| 4114 | } |
| 4115 | break; |
| 4116 | |
| 4117 | case clang::Type::ObjCObject: |
| 4118 | case clang::Type::ObjCInterface: |
| 4119 | if (GetCompleteType(type)) |
| 4120 | { |
| 4121 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4122 | if (objc_class_type) |
| 4123 | { |
| 4124 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 4125 | if (class_interface_decl) |
| 4126 | { |
| 4127 | auto method_iter = class_interface_decl->meth_begin(); |
| 4128 | auto method_end = class_interface_decl->meth_end(); |
| 4129 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) |
| 4130 | { |
| 4131 | std::advance(method_iter, idx); |
| 4132 | method_decl = method_iter->getCanonicalDecl(); |
| 4133 | if (method_decl) |
| 4134 | { |
| 4135 | name = method_decl->getSelector().getAsString(); |
| 4136 | if (method_decl->isClassMethod()) |
| 4137 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4138 | else |
| 4139 | kind = lldb::eMemberFunctionKindInstanceMethod; |
| 4140 | } |
| 4141 | } |
| 4142 | } |
| 4143 | } |
| 4144 | } |
| 4145 | break; |
| 4146 | |
| 4147 | case clang::Type::Typedef: |
| 4148 | return GetMemberFunctionAtIndex(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx); |
| 4149 | |
| 4150 | case clang::Type::Elaborated: |
| 4151 | return GetMemberFunctionAtIndex(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx); |
| 4152 | |
| 4153 | case clang::Type::Paren: |
| 4154 | return GetMemberFunctionAtIndex(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx); |
| 4155 | |
| 4156 | default: |
| 4157 | break; |
| 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | if (kind == eMemberFunctionKindUnknown) |
| 4162 | return TypeMemberFunctionImpl(); |
| 4163 | if (method_decl) |
| 4164 | return TypeMemberFunctionImpl(method_decl, name, kind); |
| 4165 | if (type) |
| 4166 | return TypeMemberFunctionImpl(clang_type, name, kind); |
| 4167 | |
| 4168 | return TypeMemberFunctionImpl(); |
| 4169 | } |
| 4170 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4171 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4172 | ClangASTContext::GetNonReferenceType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4173 | { |
| 4174 | if (type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4175 | return CompilerType(getASTContext(), GetQualType(type).getNonReferenceType()); |
| 4176 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4177 | } |
| 4178 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4179 | CompilerType |
| 4180 | ClangASTContext::CreateTypedefType (const CompilerType& type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4181 | const char *typedef_name, |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4182 | const CompilerDeclContext &compiler_decl_ctx) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4183 | { |
| 4184 | if (type && typedef_name && typedef_name[0]) |
| 4185 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 4186 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4187 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4188 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4189 | clang::ASTContext* clang_ast = ast->getASTContext(); |
| 4190 | clang::QualType qual_type (GetQualType(type)); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4191 | |
| 4192 | clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4193 | if (decl_ctx == nullptr) |
| 4194 | decl_ctx = ast->getASTContext()->getTranslationUnitDecl(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4195 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4196 | clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast, |
| 4197 | decl_ctx, |
| 4198 | clang::SourceLocation(), |
| 4199 | clang::SourceLocation(), |
| 4200 | &clang_ast->Idents.get(typedef_name), |
| 4201 | clang_ast->getTrivialTypeSourceInfo(qual_type)); |
| 4202 | |
| 4203 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier |
| 4204 | |
| 4205 | // Get a uniqued clang::QualType for the typedef decl type |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4206 | return CompilerType (clang_ast, clang_ast->getTypedefType (decl)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4207 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4208 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4209 | |
| 4210 | } |
| 4211 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4212 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4213 | ClangASTContext::GetPointeeType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4214 | { |
| 4215 | if (type) |
| 4216 | { |
| 4217 | clang::QualType qual_type(GetQualType(type)); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4218 | return CompilerType (getASTContext(), qual_type.getTypePtr()->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4219 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4220 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4223 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4224 | ClangASTContext::GetPointerType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4225 | { |
| 4226 | if (type) |
| 4227 | { |
| 4228 | clang::QualType qual_type (GetQualType(type)); |
| 4229 | |
| 4230 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4231 | switch (type_class) |
| 4232 | { |
| 4233 | case clang::Type::ObjCObject: |
| 4234 | case clang::Type::ObjCInterface: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4235 | return CompilerType(getASTContext(), getASTContext()->getObjCObjectPointerType(qual_type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4236 | |
| 4237 | default: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4238 | return CompilerType(getASTContext(), getASTContext()->getPointerType(qual_type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4239 | } |
| 4240 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4241 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4242 | } |
| 4243 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4244 | |
| 4245 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4246 | ClangASTContext::GetLValueReferenceType (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4247 | { |
| 4248 | if (type) |
| 4249 | return CompilerType(this, getASTContext()->getLValueReferenceType(GetQualType(type)).getAsOpaquePtr()); |
| 4250 | else |
| 4251 | return CompilerType(); |
| 4252 | } |
| 4253 | |
| 4254 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4255 | ClangASTContext::GetRValueReferenceType (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4256 | { |
| 4257 | if (type) |
| 4258 | return CompilerType(this, getASTContext()->getRValueReferenceType(GetQualType(type)).getAsOpaquePtr()); |
| 4259 | else |
| 4260 | return CompilerType(); |
| 4261 | } |
| 4262 | |
| 4263 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4264 | ClangASTContext::AddConstModifier (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4265 | { |
| 4266 | if (type) |
| 4267 | { |
| 4268 | clang::QualType result(GetQualType(type)); |
| 4269 | result.addConst(); |
| 4270 | return CompilerType (this, result.getAsOpaquePtr()); |
| 4271 | } |
| 4272 | return CompilerType(); |
| 4273 | } |
| 4274 | |
| 4275 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4276 | ClangASTContext::AddVolatileModifier (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4277 | { |
| 4278 | if (type) |
| 4279 | { |
| 4280 | clang::QualType result(GetQualType(type)); |
| 4281 | result.addVolatile(); |
| 4282 | return CompilerType (this, result.getAsOpaquePtr()); |
| 4283 | } |
| 4284 | return CompilerType(); |
| 4285 | |
| 4286 | } |
| 4287 | |
| 4288 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4289 | ClangASTContext::AddRestrictModifier (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4290 | { |
| 4291 | if (type) |
| 4292 | { |
| 4293 | clang::QualType result(GetQualType(type)); |
| 4294 | result.addRestrict(); |
| 4295 | return CompilerType (this, result.getAsOpaquePtr()); |
| 4296 | } |
| 4297 | return CompilerType(); |
| 4298 | |
| 4299 | } |
| 4300 | |
| 4301 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4302 | ClangASTContext::CreateTypedef (lldb::opaque_compiler_type_t type, const char *typedef_name, const CompilerDeclContext &compiler_decl_ctx) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4303 | { |
| 4304 | if (type) |
| 4305 | { |
| 4306 | clang::ASTContext* clang_ast = getASTContext(); |
| 4307 | clang::QualType qual_type (GetQualType(type)); |
| 4308 | |
| 4309 | clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); |
| 4310 | if (decl_ctx == nullptr) |
| 4311 | decl_ctx = getASTContext()->getTranslationUnitDecl(); |
| 4312 | |
| 4313 | clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast, |
| 4314 | decl_ctx, |
| 4315 | clang::SourceLocation(), |
| 4316 | clang::SourceLocation(), |
| 4317 | &clang_ast->Idents.get(typedef_name), |
| 4318 | clang_ast->getTrivialTypeSourceInfo(qual_type)); |
| 4319 | |
| 4320 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier |
| 4321 | |
| 4322 | // Get a uniqued clang::QualType for the typedef decl type |
| 4323 | return CompilerType (this, clang_ast->getTypedefType (decl).getAsOpaquePtr()); |
| 4324 | |
| 4325 | } |
| 4326 | return CompilerType(); |
| 4327 | |
| 4328 | } |
| 4329 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4330 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4331 | ClangASTContext::GetTypedefedType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4332 | { |
| 4333 | if (type) |
| 4334 | { |
| 4335 | const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(GetQualType(type)); |
| 4336 | if (typedef_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4337 | return CompilerType (getASTContext(), typedef_type->getDecl()->getUnderlyingType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4338 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4339 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4340 | } |
| 4341 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4342 | CompilerType |
| 4343 | ClangASTContext::RemoveFastQualifiers (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4344 | { |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 4345 | if (IsClangType(type)) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4346 | { |
| 4347 | clang::QualType qual_type(GetQualType(type)); |
| 4348 | qual_type.getQualifiers().removeFastQualifiers(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4349 | return CompilerType (type.GetTypeSystem(), qual_type.getAsOpaquePtr()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4350 | } |
| 4351 | return type; |
| 4352 | } |
| 4353 | |
| 4354 | |
| 4355 | //---------------------------------------------------------------------- |
| 4356 | // Create related types using the current type's AST |
| 4357 | //---------------------------------------------------------------------- |
| 4358 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4359 | CompilerType |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4360 | ClangASTContext::GetBasicTypeFromAST (lldb::BasicType basic_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4361 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4362 | return ClangASTContext::GetBasicType(getASTContext(), basic_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4363 | } |
| 4364 | //---------------------------------------------------------------------- |
| 4365 | // Exploring the type |
| 4366 | //---------------------------------------------------------------------- |
| 4367 | |
| 4368 | uint64_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4369 | ClangASTContext::GetBitSize (lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4370 | { |
| 4371 | if (GetCompleteType (type)) |
| 4372 | { |
| 4373 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4374 | switch (qual_type->getTypeClass()) |
| 4375 | { |
| 4376 | case clang::Type::ObjCInterface: |
| 4377 | case clang::Type::ObjCObject: |
| 4378 | { |
| 4379 | ExecutionContext exe_ctx (exe_scope); |
| 4380 | Process *process = exe_ctx.GetProcessPtr(); |
| 4381 | if (process) |
| 4382 | { |
| 4383 | ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime(); |
| 4384 | if (objc_runtime) |
| 4385 | { |
| 4386 | uint64_t bit_size = 0; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4387 | if (objc_runtime->GetTypeBitSize(CompilerType(getASTContext(), qual_type), bit_size)) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4388 | return bit_size; |
| 4389 | } |
| 4390 | } |
| 4391 | else |
| 4392 | { |
| 4393 | static bool g_printed = false; |
| 4394 | if (!g_printed) |
| 4395 | { |
| 4396 | StreamString s; |
| 4397 | DumpTypeDescription(&s); |
| 4398 | |
| 4399 | llvm::outs() << "warning: trying to determine the size of type "; |
| 4400 | llvm::outs() << s.GetString() << "\n"; |
| 4401 | llvm::outs() << "without a valid ExecutionContext. this is not reliable. please file a bug against LLDB.\n"; |
| 4402 | llvm::outs() << "backtrace:\n"; |
| 4403 | llvm::sys::PrintStackTrace(llvm::outs()); |
| 4404 | llvm::outs() << "\n"; |
| 4405 | g_printed = true; |
| 4406 | } |
| 4407 | } |
| 4408 | } |
| 4409 | // fallthrough |
| 4410 | default: |
| 4411 | const uint32_t bit_size = getASTContext()->getTypeSize (qual_type); |
| 4412 | if (bit_size == 0) |
| 4413 | { |
| 4414 | if (qual_type->isIncompleteArrayType()) |
| 4415 | return getASTContext()->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified()); |
| 4416 | } |
| 4417 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 4418 | return bit_size + getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy); |
| 4419 | return bit_size; |
| 4420 | } |
| 4421 | } |
| 4422 | return 0; |
| 4423 | } |
| 4424 | |
| 4425 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4426 | ClangASTContext::GetTypeBitAlign (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4427 | { |
| 4428 | if (GetCompleteType(type)) |
| 4429 | return getASTContext()->getTypeAlign(GetQualType(type)); |
| 4430 | return 0; |
| 4431 | } |
| 4432 | |
| 4433 | |
| 4434 | lldb::Encoding |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4435 | ClangASTContext::GetEncoding (lldb::opaque_compiler_type_t type, uint64_t &count) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4436 | { |
| 4437 | if (!type) |
| 4438 | return lldb::eEncodingInvalid; |
| 4439 | |
| 4440 | count = 1; |
| 4441 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4442 | |
| 4443 | switch (qual_type->getTypeClass()) |
| 4444 | { |
| 4445 | case clang::Type::UnaryTransform: |
| 4446 | break; |
| 4447 | |
| 4448 | case clang::Type::FunctionNoProto: |
| 4449 | case clang::Type::FunctionProto: |
| 4450 | break; |
| 4451 | |
| 4452 | case clang::Type::IncompleteArray: |
| 4453 | case clang::Type::VariableArray: |
| 4454 | break; |
| 4455 | |
| 4456 | case clang::Type::ConstantArray: |
| 4457 | break; |
| 4458 | |
| 4459 | case clang::Type::ExtVector: |
| 4460 | case clang::Type::Vector: |
| 4461 | // TODO: Set this to more than one??? |
| 4462 | break; |
| 4463 | |
| 4464 | case clang::Type::Builtin: |
| 4465 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 4466 | { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4467 | case clang::BuiltinType::Void: |
| 4468 | break; |
| 4469 | |
| 4470 | case clang::BuiltinType::Bool: |
| 4471 | case clang::BuiltinType::Char_S: |
| 4472 | case clang::BuiltinType::SChar: |
| 4473 | case clang::BuiltinType::WChar_S: |
| 4474 | case clang::BuiltinType::Char16: |
| 4475 | case clang::BuiltinType::Char32: |
| 4476 | case clang::BuiltinType::Short: |
| 4477 | case clang::BuiltinType::Int: |
| 4478 | case clang::BuiltinType::Long: |
| 4479 | case clang::BuiltinType::LongLong: |
| 4480 | case clang::BuiltinType::Int128: return lldb::eEncodingSint; |
| 4481 | |
| 4482 | case clang::BuiltinType::Char_U: |
| 4483 | case clang::BuiltinType::UChar: |
| 4484 | case clang::BuiltinType::WChar_U: |
| 4485 | case clang::BuiltinType::UShort: |
| 4486 | case clang::BuiltinType::UInt: |
| 4487 | case clang::BuiltinType::ULong: |
| 4488 | case clang::BuiltinType::ULongLong: |
| 4489 | case clang::BuiltinType::UInt128: return lldb::eEncodingUint; |
| 4490 | |
| 4491 | case clang::BuiltinType::Float: |
| 4492 | case clang::BuiltinType::Double: |
| 4493 | case clang::BuiltinType::LongDouble: return lldb::eEncodingIEEE754; |
| 4494 | |
| 4495 | case clang::BuiltinType::ObjCClass: |
| 4496 | case clang::BuiltinType::ObjCId: |
| 4497 | case clang::BuiltinType::ObjCSel: return lldb::eEncodingUint; |
| 4498 | |
| 4499 | case clang::BuiltinType::NullPtr: return lldb::eEncodingUint; |
| 4500 | |
| 4501 | case clang::BuiltinType::Kind::ARCUnbridgedCast: |
| 4502 | case clang::BuiltinType::Kind::BoundMember: |
| 4503 | case clang::BuiltinType::Kind::BuiltinFn: |
| 4504 | case clang::BuiltinType::Kind::Dependent: |
| 4505 | case clang::BuiltinType::Kind::Half: |
Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4506 | case clang::BuiltinType::Kind::OCLClkEvent: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4507 | case clang::BuiltinType::Kind::OCLEvent: |
| 4508 | case clang::BuiltinType::Kind::OCLImage1d: |
| 4509 | case clang::BuiltinType::Kind::OCLImage1dArray: |
| 4510 | case clang::BuiltinType::Kind::OCLImage1dBuffer: |
| 4511 | case clang::BuiltinType::Kind::OCLImage2d: |
| 4512 | case clang::BuiltinType::Kind::OCLImage2dArray: |
Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4513 | case clang::BuiltinType::Kind::OCLImage2dArrayDepth: |
| 4514 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAA: |
| 4515 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepth: |
| 4516 | case clang::BuiltinType::Kind::OCLImage2dDepth: |
| 4517 | case clang::BuiltinType::Kind::OCLImage2dMSAA: |
| 4518 | case clang::BuiltinType::Kind::OCLImage2dMSAADepth: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4519 | case clang::BuiltinType::Kind::OCLImage3d: |
Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4520 | case clang::BuiltinType::Kind::OCLQueue: |
| 4521 | case clang::BuiltinType::Kind::OCLNDRange: |
| 4522 | case clang::BuiltinType::Kind::OCLReserveID: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4523 | case clang::BuiltinType::Kind::OCLSampler: |
Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4524 | case clang::BuiltinType::Kind::OMPArraySection: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4525 | case clang::BuiltinType::Kind::Overload: |
| 4526 | case clang::BuiltinType::Kind::PseudoObject: |
| 4527 | case clang::BuiltinType::Kind::UnknownAny: |
| 4528 | break; |
| 4529 | } |
| 4530 | break; |
| 4531 | // All pointer types are represented as unsigned integer encodings. |
| 4532 | // We may nee to add a eEncodingPointer if we ever need to know the |
| 4533 | // difference |
| 4534 | case clang::Type::ObjCObjectPointer: |
| 4535 | case clang::Type::BlockPointer: |
| 4536 | case clang::Type::Pointer: |
| 4537 | case clang::Type::LValueReference: |
| 4538 | case clang::Type::RValueReference: |
| 4539 | case clang::Type::MemberPointer: return lldb::eEncodingUint; |
| 4540 | case clang::Type::Complex: |
| 4541 | { |
| 4542 | lldb::Encoding encoding = lldb::eEncodingIEEE754; |
| 4543 | if (qual_type->isComplexType()) |
| 4544 | encoding = lldb::eEncodingIEEE754; |
| 4545 | else |
| 4546 | { |
| 4547 | const clang::ComplexType *complex_type = qual_type->getAsComplexIntegerType(); |
| 4548 | if (complex_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4549 | encoding = CompilerType(getASTContext(), complex_type->getElementType()).GetEncoding(count); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4550 | else |
| 4551 | encoding = lldb::eEncodingSint; |
| 4552 | } |
| 4553 | count = 2; |
| 4554 | return encoding; |
| 4555 | } |
| 4556 | |
| 4557 | case clang::Type::ObjCInterface: break; |
| 4558 | case clang::Type::Record: break; |
| 4559 | case clang::Type::Enum: return lldb::eEncodingSint; |
| 4560 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4561 | return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetEncoding(count); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4562 | |
| 4563 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4564 | return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetEncoding(count); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4565 | |
| 4566 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4567 | return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetEncoding(count); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4568 | |
| 4569 | case clang::Type::DependentSizedArray: |
| 4570 | case clang::Type::DependentSizedExtVector: |
| 4571 | case clang::Type::UnresolvedUsing: |
| 4572 | case clang::Type::Attributed: |
| 4573 | case clang::Type::TemplateTypeParm: |
| 4574 | case clang::Type::SubstTemplateTypeParm: |
| 4575 | case clang::Type::SubstTemplateTypeParmPack: |
| 4576 | case clang::Type::Auto: |
| 4577 | case clang::Type::InjectedClassName: |
| 4578 | case clang::Type::DependentName: |
| 4579 | case clang::Type::DependentTemplateSpecialization: |
| 4580 | case clang::Type::PackExpansion: |
| 4581 | case clang::Type::ObjCObject: |
| 4582 | |
| 4583 | case clang::Type::TypeOfExpr: |
| 4584 | case clang::Type::TypeOf: |
| 4585 | case clang::Type::Decltype: |
| 4586 | case clang::Type::TemplateSpecialization: |
| 4587 | case clang::Type::Atomic: |
| 4588 | case clang::Type::Adjusted: |
| 4589 | break; |
| 4590 | |
| 4591 | // pointer type decayed from an array or function type. |
| 4592 | case clang::Type::Decayed: |
| 4593 | break; |
| 4594 | } |
| 4595 | count = 0; |
| 4596 | return lldb::eEncodingInvalid; |
| 4597 | } |
| 4598 | |
| 4599 | lldb::Format |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4600 | ClangASTContext::GetFormat (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4601 | { |
| 4602 | if (!type) |
| 4603 | return lldb::eFormatDefault; |
| 4604 | |
| 4605 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4606 | |
| 4607 | switch (qual_type->getTypeClass()) |
| 4608 | { |
| 4609 | case clang::Type::UnaryTransform: |
| 4610 | break; |
| 4611 | |
| 4612 | case clang::Type::FunctionNoProto: |
| 4613 | case clang::Type::FunctionProto: |
| 4614 | break; |
| 4615 | |
| 4616 | case clang::Type::IncompleteArray: |
| 4617 | case clang::Type::VariableArray: |
| 4618 | break; |
| 4619 | |
| 4620 | case clang::Type::ConstantArray: |
| 4621 | return lldb::eFormatVoid; // no value |
| 4622 | |
| 4623 | case clang::Type::ExtVector: |
| 4624 | case clang::Type::Vector: |
| 4625 | break; |
| 4626 | |
| 4627 | case clang::Type::Builtin: |
| 4628 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 4629 | { |
| 4630 | //default: assert(0 && "Unknown builtin type!"); |
| 4631 | case clang::BuiltinType::UnknownAny: |
| 4632 | case clang::BuiltinType::Void: |
| 4633 | case clang::BuiltinType::BoundMember: |
| 4634 | break; |
| 4635 | |
| 4636 | case clang::BuiltinType::Bool: return lldb::eFormatBoolean; |
| 4637 | case clang::BuiltinType::Char_S: |
| 4638 | case clang::BuiltinType::SChar: |
| 4639 | case clang::BuiltinType::WChar_S: |
| 4640 | case clang::BuiltinType::Char_U: |
| 4641 | case clang::BuiltinType::UChar: |
| 4642 | case clang::BuiltinType::WChar_U: return lldb::eFormatChar; |
| 4643 | case clang::BuiltinType::Char16: return lldb::eFormatUnicode16; |
| 4644 | case clang::BuiltinType::Char32: return lldb::eFormatUnicode32; |
| 4645 | case clang::BuiltinType::UShort: return lldb::eFormatUnsigned; |
| 4646 | case clang::BuiltinType::Short: return lldb::eFormatDecimal; |
| 4647 | case clang::BuiltinType::UInt: return lldb::eFormatUnsigned; |
| 4648 | case clang::BuiltinType::Int: return lldb::eFormatDecimal; |
| 4649 | case clang::BuiltinType::ULong: return lldb::eFormatUnsigned; |
| 4650 | case clang::BuiltinType::Long: return lldb::eFormatDecimal; |
| 4651 | case clang::BuiltinType::ULongLong: return lldb::eFormatUnsigned; |
| 4652 | case clang::BuiltinType::LongLong: return lldb::eFormatDecimal; |
| 4653 | case clang::BuiltinType::UInt128: return lldb::eFormatUnsigned; |
| 4654 | case clang::BuiltinType::Int128: return lldb::eFormatDecimal; |
| 4655 | case clang::BuiltinType::Float: return lldb::eFormatFloat; |
| 4656 | case clang::BuiltinType::Double: return lldb::eFormatFloat; |
| 4657 | case clang::BuiltinType::LongDouble: return lldb::eFormatFloat; |
Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 4658 | default: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4659 | return lldb::eFormatHex; |
| 4660 | } |
| 4661 | break; |
| 4662 | case clang::Type::ObjCObjectPointer: return lldb::eFormatHex; |
| 4663 | case clang::Type::BlockPointer: return lldb::eFormatHex; |
| 4664 | case clang::Type::Pointer: return lldb::eFormatHex; |
| 4665 | case clang::Type::LValueReference: |
| 4666 | case clang::Type::RValueReference: return lldb::eFormatHex; |
| 4667 | case clang::Type::MemberPointer: break; |
| 4668 | case clang::Type::Complex: |
| 4669 | { |
| 4670 | if (qual_type->isComplexType()) |
| 4671 | return lldb::eFormatComplex; |
| 4672 | else |
| 4673 | return lldb::eFormatComplexInteger; |
| 4674 | } |
| 4675 | case clang::Type::ObjCInterface: break; |
| 4676 | case clang::Type::Record: break; |
| 4677 | case clang::Type::Enum: return lldb::eFormatEnum; |
| 4678 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4679 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetFormat(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4680 | case clang::Type::Auto: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4681 | return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->desugar()).GetFormat(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4682 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4683 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetFormat(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4684 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4685 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetFormat(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4686 | case clang::Type::DependentSizedArray: |
| 4687 | case clang::Type::DependentSizedExtVector: |
| 4688 | case clang::Type::UnresolvedUsing: |
| 4689 | case clang::Type::Attributed: |
| 4690 | case clang::Type::TemplateTypeParm: |
| 4691 | case clang::Type::SubstTemplateTypeParm: |
| 4692 | case clang::Type::SubstTemplateTypeParmPack: |
| 4693 | case clang::Type::InjectedClassName: |
| 4694 | case clang::Type::DependentName: |
| 4695 | case clang::Type::DependentTemplateSpecialization: |
| 4696 | case clang::Type::PackExpansion: |
| 4697 | case clang::Type::ObjCObject: |
| 4698 | |
| 4699 | case clang::Type::TypeOfExpr: |
| 4700 | case clang::Type::TypeOf: |
| 4701 | case clang::Type::Decltype: |
| 4702 | case clang::Type::TemplateSpecialization: |
| 4703 | case clang::Type::Atomic: |
| 4704 | case clang::Type::Adjusted: |
| 4705 | break; |
| 4706 | |
| 4707 | // pointer type decayed from an array or function type. |
| 4708 | case clang::Type::Decayed: |
| 4709 | break; |
| 4710 | } |
| 4711 | // We don't know hot to display this type... |
| 4712 | return lldb::eFormatBytes; |
| 4713 | } |
| 4714 | |
| 4715 | static bool |
| 4716 | ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl, bool check_superclass) |
| 4717 | { |
| 4718 | while (class_interface_decl) |
| 4719 | { |
| 4720 | if (class_interface_decl->ivar_size() > 0) |
| 4721 | return true; |
| 4722 | |
| 4723 | if (check_superclass) |
| 4724 | class_interface_decl = class_interface_decl->getSuperClass(); |
| 4725 | else |
| 4726 | break; |
| 4727 | } |
| 4728 | return false; |
| 4729 | } |
| 4730 | |
| 4731 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4732 | ClangASTContext::GetNumChildren (lldb::opaque_compiler_type_t type, bool omit_empty_base_classes) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4733 | { |
| 4734 | if (!type) |
| 4735 | return 0; |
| 4736 | |
| 4737 | uint32_t num_children = 0; |
| 4738 | clang::QualType qual_type(GetQualType(type)); |
| 4739 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4740 | switch (type_class) |
| 4741 | { |
| 4742 | case clang::Type::Builtin: |
| 4743 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 4744 | { |
| 4745 | case clang::BuiltinType::ObjCId: // child is Class |
| 4746 | case clang::BuiltinType::ObjCClass: // child is Class |
| 4747 | num_children = 1; |
| 4748 | break; |
| 4749 | |
| 4750 | default: |
| 4751 | break; |
| 4752 | } |
| 4753 | break; |
| 4754 | |
| 4755 | case clang::Type::Complex: return 0; |
| 4756 | |
| 4757 | case clang::Type::Record: |
| 4758 | if (GetCompleteQualType (getASTContext(), qual_type)) |
| 4759 | { |
| 4760 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4761 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4762 | assert(record_decl); |
| 4763 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 4764 | if (cxx_record_decl) |
| 4765 | { |
| 4766 | if (omit_empty_base_classes) |
| 4767 | { |
| 4768 | // Check each base classes to see if it or any of its |
| 4769 | // base classes contain any fields. This can help |
| 4770 | // limit the noise in variable views by not having to |
| 4771 | // show base classes that contain no members. |
| 4772 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 4773 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 4774 | base_class != base_class_end; |
| 4775 | ++base_class) |
| 4776 | { |
| 4777 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 4778 | |
| 4779 | // Skip empty base classes |
| 4780 | if (ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 4781 | continue; |
| 4782 | |
| 4783 | num_children++; |
| 4784 | } |
| 4785 | } |
| 4786 | else |
| 4787 | { |
| 4788 | // Include all base classes |
| 4789 | num_children += cxx_record_decl->getNumBases(); |
| 4790 | } |
| 4791 | |
| 4792 | } |
| 4793 | clang::RecordDecl::field_iterator field, field_end; |
| 4794 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field) |
| 4795 | ++num_children; |
| 4796 | } |
| 4797 | break; |
| 4798 | |
| 4799 | case clang::Type::ObjCObject: |
| 4800 | case clang::Type::ObjCInterface: |
| 4801 | if (GetCompleteQualType (getASTContext(), qual_type)) |
| 4802 | { |
| 4803 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4804 | assert (objc_class_type); |
| 4805 | if (objc_class_type) |
| 4806 | { |
| 4807 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 4808 | |
| 4809 | if (class_interface_decl) |
| 4810 | { |
| 4811 | |
| 4812 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 4813 | if (superclass_interface_decl) |
| 4814 | { |
| 4815 | if (omit_empty_base_classes) |
| 4816 | { |
| 4817 | if (ObjCDeclHasIVars (superclass_interface_decl, true)) |
| 4818 | ++num_children; |
| 4819 | } |
| 4820 | else |
| 4821 | ++num_children; |
| 4822 | } |
| 4823 | |
| 4824 | num_children += class_interface_decl->ivar_size(); |
| 4825 | } |
| 4826 | } |
| 4827 | } |
| 4828 | break; |
| 4829 | |
| 4830 | case clang::Type::ObjCObjectPointer: |
| 4831 | { |
| 4832 | const clang::ObjCObjectPointerType *pointer_type = llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()); |
| 4833 | clang::QualType pointee_type = pointer_type->getPointeeType(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4834 | uint32_t num_pointee_children = CompilerType (getASTContext(),pointee_type).GetNumChildren (omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4835 | // If this type points to a simple type, then it has 1 child |
| 4836 | if (num_pointee_children == 0) |
| 4837 | num_children = 1; |
| 4838 | else |
| 4839 | num_children = num_pointee_children; |
| 4840 | } |
| 4841 | break; |
| 4842 | |
| 4843 | case clang::Type::Vector: |
| 4844 | case clang::Type::ExtVector: |
| 4845 | num_children = llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements(); |
| 4846 | break; |
| 4847 | |
| 4848 | case clang::Type::ConstantArray: |
| 4849 | num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())->getSize().getLimitedValue(); |
| 4850 | break; |
| 4851 | |
| 4852 | case clang::Type::Pointer: |
| 4853 | { |
| 4854 | const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr()); |
| 4855 | clang::QualType pointee_type (pointer_type->getPointeeType()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4856 | uint32_t num_pointee_children = CompilerType (getASTContext(),pointee_type).GetNumChildren (omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4857 | if (num_pointee_children == 0) |
| 4858 | { |
| 4859 | // We have a pointer to a pointee type that claims it has no children. |
| 4860 | // We will want to look at |
| 4861 | num_children = GetNumPointeeChildren (pointee_type); |
| 4862 | } |
| 4863 | else |
| 4864 | num_children = num_pointee_children; |
| 4865 | } |
| 4866 | break; |
| 4867 | |
| 4868 | case clang::Type::LValueReference: |
| 4869 | case clang::Type::RValueReference: |
| 4870 | { |
| 4871 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 4872 | clang::QualType pointee_type = reference_type->getPointeeType(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4873 | uint32_t num_pointee_children = CompilerType (getASTContext(), pointee_type).GetNumChildren (omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4874 | // If this type points to a simple type, then it has 1 child |
| 4875 | if (num_pointee_children == 0) |
| 4876 | num_children = 1; |
| 4877 | else |
| 4878 | num_children = num_pointee_children; |
| 4879 | } |
| 4880 | break; |
| 4881 | |
| 4882 | |
| 4883 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4884 | num_children = CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumChildren (omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4885 | break; |
| 4886 | |
| 4887 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4888 | num_children = CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumChildren (omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4889 | break; |
| 4890 | |
| 4891 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4892 | num_children = CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumChildren (omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4893 | break; |
| 4894 | default: |
| 4895 | break; |
| 4896 | } |
| 4897 | return num_children; |
| 4898 | } |
| 4899 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4900 | CompilerType |
| 4901 | ClangASTContext::GetBuiltinTypeByName (const ConstString &name) |
| 4902 | { |
| 4903 | return GetBasicType (GetBasicTypeEnumeration (name)); |
| 4904 | } |
| 4905 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4906 | lldb::BasicType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4907 | ClangASTContext::GetBasicTypeEnumeration (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4908 | { |
| 4909 | if (type) |
| 4910 | { |
| 4911 | clang::QualType qual_type(GetQualType(type)); |
| 4912 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4913 | if (type_class == clang::Type::Builtin) |
| 4914 | { |
| 4915 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 4916 | { |
| 4917 | case clang::BuiltinType::Void: return eBasicTypeVoid; |
| 4918 | case clang::BuiltinType::Bool: return eBasicTypeBool; |
| 4919 | case clang::BuiltinType::Char_S: return eBasicTypeSignedChar; |
| 4920 | case clang::BuiltinType::Char_U: return eBasicTypeUnsignedChar; |
| 4921 | case clang::BuiltinType::Char16: return eBasicTypeChar16; |
| 4922 | case clang::BuiltinType::Char32: return eBasicTypeChar32; |
| 4923 | case clang::BuiltinType::UChar: return eBasicTypeUnsignedChar; |
| 4924 | case clang::BuiltinType::SChar: return eBasicTypeSignedChar; |
| 4925 | case clang::BuiltinType::WChar_S: return eBasicTypeSignedWChar; |
| 4926 | case clang::BuiltinType::WChar_U: return eBasicTypeUnsignedWChar; |
| 4927 | case clang::BuiltinType::Short: return eBasicTypeShort; |
| 4928 | case clang::BuiltinType::UShort: return eBasicTypeUnsignedShort; |
| 4929 | case clang::BuiltinType::Int: return eBasicTypeInt; |
| 4930 | case clang::BuiltinType::UInt: return eBasicTypeUnsignedInt; |
| 4931 | case clang::BuiltinType::Long: return eBasicTypeLong; |
| 4932 | case clang::BuiltinType::ULong: return eBasicTypeUnsignedLong; |
| 4933 | case clang::BuiltinType::LongLong: return eBasicTypeLongLong; |
| 4934 | case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong; |
| 4935 | case clang::BuiltinType::Int128: return eBasicTypeInt128; |
| 4936 | case clang::BuiltinType::UInt128: return eBasicTypeUnsignedInt128; |
| 4937 | |
| 4938 | case clang::BuiltinType::Half: return eBasicTypeHalf; |
| 4939 | case clang::BuiltinType::Float: return eBasicTypeFloat; |
| 4940 | case clang::BuiltinType::Double: return eBasicTypeDouble; |
| 4941 | case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble; |
| 4942 | |
| 4943 | case clang::BuiltinType::NullPtr: return eBasicTypeNullPtr; |
| 4944 | case clang::BuiltinType::ObjCId: return eBasicTypeObjCID; |
| 4945 | case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass; |
| 4946 | case clang::BuiltinType::ObjCSel: return eBasicTypeObjCSel; |
Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 4947 | default: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4948 | return eBasicTypeOther; |
| 4949 | } |
| 4950 | } |
| 4951 | } |
| 4952 | return eBasicTypeInvalid; |
| 4953 | } |
| 4954 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4955 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4956 | ClangASTContext::ForEachEnumerator (lldb::opaque_compiler_type_t type, std::function <bool (const CompilerType &integer_type, const ConstString &name, const llvm::APSInt &value)> const &callback) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4957 | { |
| 4958 | const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)); |
| 4959 | if (enum_type) |
| 4960 | { |
| 4961 | const clang::EnumDecl *enum_decl = enum_type->getDecl(); |
| 4962 | if (enum_decl) |
| 4963 | { |
| 4964 | CompilerType integer_type(this, enum_decl->getIntegerType().getAsOpaquePtr()); |
| 4965 | |
| 4966 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 4967 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) |
| 4968 | { |
| 4969 | ConstString name(enum_pos->getNameAsString().c_str()); |
| 4970 | if (!callback (integer_type, name, enum_pos->getInitVal())) |
| 4971 | break; |
| 4972 | } |
| 4973 | } |
| 4974 | } |
| 4975 | } |
| 4976 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4977 | |
| 4978 | #pragma mark Aggregate Types |
| 4979 | |
| 4980 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4981 | ClangASTContext::GetNumFields (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4982 | { |
| 4983 | if (!type) |
| 4984 | return 0; |
| 4985 | |
| 4986 | uint32_t count = 0; |
| 4987 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4988 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4989 | switch (type_class) |
| 4990 | { |
| 4991 | case clang::Type::Record: |
| 4992 | if (GetCompleteType(type)) |
| 4993 | { |
| 4994 | const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4995 | if (record_type) |
| 4996 | { |
| 4997 | clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4998 | if (record_decl) |
| 4999 | { |
| 5000 | uint32_t field_idx = 0; |
| 5001 | clang::RecordDecl::field_iterator field, field_end; |
| 5002 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field) |
| 5003 | ++field_idx; |
| 5004 | count = field_idx; |
| 5005 | } |
| 5006 | } |
| 5007 | } |
| 5008 | break; |
| 5009 | |
| 5010 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5011 | count = CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumFields(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5012 | break; |
| 5013 | |
| 5014 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5015 | count = CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumFields(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5016 | break; |
| 5017 | |
| 5018 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5019 | count = CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumFields(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5020 | break; |
| 5021 | |
| 5022 | case clang::Type::ObjCObjectPointer: |
| 5023 | if (GetCompleteType(type)) |
| 5024 | { |
| 5025 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); |
| 5026 | if (objc_class_type) |
| 5027 | { |
| 5028 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); |
| 5029 | |
| 5030 | if (class_interface_decl) |
| 5031 | count = class_interface_decl->ivar_size(); |
| 5032 | } |
| 5033 | } |
| 5034 | break; |
| 5035 | |
| 5036 | case clang::Type::ObjCObject: |
| 5037 | case clang::Type::ObjCInterface: |
| 5038 | if (GetCompleteType(type)) |
| 5039 | { |
| 5040 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5041 | if (objc_class_type) |
| 5042 | { |
| 5043 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 5044 | |
| 5045 | if (class_interface_decl) |
| 5046 | count = class_interface_decl->ivar_size(); |
| 5047 | } |
| 5048 | } |
| 5049 | break; |
| 5050 | |
| 5051 | default: |
| 5052 | break; |
| 5053 | } |
| 5054 | return count; |
| 5055 | } |
| 5056 | |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5057 | static lldb::opaque_compiler_type_t |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5058 | GetObjCFieldAtIndex (clang::ASTContext *ast, |
| 5059 | clang::ObjCInterfaceDecl *class_interface_decl, |
| 5060 | size_t idx, |
| 5061 | std::string& name, |
| 5062 | uint64_t *bit_offset_ptr, |
| 5063 | uint32_t *bitfield_bit_size_ptr, |
| 5064 | bool *is_bitfield_ptr) |
| 5065 | { |
| 5066 | if (class_interface_decl) |
| 5067 | { |
| 5068 | if (idx < (class_interface_decl->ivar_size())) |
| 5069 | { |
| 5070 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 5071 | uint32_t ivar_idx = 0; |
| 5072 | |
| 5073 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++ivar_idx) |
| 5074 | { |
| 5075 | if (ivar_idx == idx) |
| 5076 | { |
| 5077 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 5078 | |
| 5079 | clang::QualType ivar_qual_type(ivar_decl->getType()); |
| 5080 | |
| 5081 | name.assign(ivar_decl->getNameAsString()); |
| 5082 | |
| 5083 | if (bit_offset_ptr) |
| 5084 | { |
| 5085 | const clang::ASTRecordLayout &interface_layout = ast->getASTObjCInterfaceLayout(class_interface_decl); |
| 5086 | *bit_offset_ptr = interface_layout.getFieldOffset (ivar_idx); |
| 5087 | } |
| 5088 | |
| 5089 | const bool is_bitfield = ivar_pos->isBitField(); |
| 5090 | |
| 5091 | if (bitfield_bit_size_ptr) |
| 5092 | { |
| 5093 | *bitfield_bit_size_ptr = 0; |
| 5094 | |
| 5095 | if (is_bitfield && ast) |
| 5096 | { |
| 5097 | clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth(); |
| 5098 | llvm::APSInt bitfield_apsint; |
| 5099 | if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *ast)) |
| 5100 | { |
| 5101 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 5102 | } |
| 5103 | } |
| 5104 | } |
| 5105 | if (is_bitfield_ptr) |
| 5106 | *is_bitfield_ptr = is_bitfield; |
| 5107 | |
| 5108 | return ivar_qual_type.getAsOpaquePtr(); |
| 5109 | } |
| 5110 | } |
| 5111 | } |
| 5112 | } |
| 5113 | return nullptr; |
| 5114 | } |
| 5115 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5116 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5117 | ClangASTContext::GetFieldAtIndex (lldb::opaque_compiler_type_t type, size_t idx, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5118 | std::string& name, |
| 5119 | uint64_t *bit_offset_ptr, |
| 5120 | uint32_t *bitfield_bit_size_ptr, |
| 5121 | bool *is_bitfield_ptr) |
| 5122 | { |
| 5123 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5124 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5125 | |
| 5126 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5127 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5128 | switch (type_class) |
| 5129 | { |
| 5130 | case clang::Type::Record: |
| 5131 | if (GetCompleteType(type)) |
| 5132 | { |
| 5133 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 5134 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5135 | uint32_t field_idx = 0; |
| 5136 | clang::RecordDecl::field_iterator field, field_end; |
| 5137 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx) |
| 5138 | { |
| 5139 | if (idx == field_idx) |
| 5140 | { |
| 5141 | // Print the member type if requested |
| 5142 | // Print the member name and equal sign |
| 5143 | name.assign(field->getNameAsString()); |
| 5144 | |
| 5145 | // Figure out the type byte size (field_type_info.first) and |
| 5146 | // alignment (field_type_info.second) from the AST context. |
| 5147 | if (bit_offset_ptr) |
| 5148 | { |
| 5149 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); |
| 5150 | *bit_offset_ptr = record_layout.getFieldOffset (field_idx); |
| 5151 | } |
| 5152 | |
| 5153 | const bool is_bitfield = field->isBitField(); |
| 5154 | |
| 5155 | if (bitfield_bit_size_ptr) |
| 5156 | { |
| 5157 | *bitfield_bit_size_ptr = 0; |
| 5158 | |
| 5159 | if (is_bitfield) |
| 5160 | { |
| 5161 | clang::Expr *bitfield_bit_size_expr = field->getBitWidth(); |
| 5162 | llvm::APSInt bitfield_apsint; |
| 5163 | if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *getASTContext())) |
| 5164 | { |
| 5165 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 5166 | } |
| 5167 | } |
| 5168 | } |
| 5169 | if (is_bitfield_ptr) |
| 5170 | *is_bitfield_ptr = is_bitfield; |
| 5171 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5172 | return CompilerType (getASTContext(), field->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | } |
| 5176 | break; |
| 5177 | |
| 5178 | case clang::Type::ObjCObjectPointer: |
| 5179 | if (GetCompleteType(type)) |
| 5180 | { |
| 5181 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); |
| 5182 | if (objc_class_type) |
| 5183 | { |
| 5184 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5185 | return CompilerType (this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5186 | } |
| 5187 | } |
| 5188 | break; |
| 5189 | |
| 5190 | case clang::Type::ObjCObject: |
| 5191 | case clang::Type::ObjCInterface: |
| 5192 | if (GetCompleteType(type)) |
| 5193 | { |
| 5194 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5195 | assert (objc_class_type); |
| 5196 | if (objc_class_type) |
| 5197 | { |
| 5198 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5199 | return CompilerType (this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5200 | } |
| 5201 | } |
| 5202 | break; |
| 5203 | |
| 5204 | |
| 5205 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5206 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()). |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5207 | GetFieldAtIndex (idx, |
| 5208 | name, |
| 5209 | bit_offset_ptr, |
| 5210 | bitfield_bit_size_ptr, |
| 5211 | is_bitfield_ptr); |
| 5212 | |
| 5213 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5214 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()). |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5215 | GetFieldAtIndex (idx, |
| 5216 | name, |
| 5217 | bit_offset_ptr, |
| 5218 | bitfield_bit_size_ptr, |
| 5219 | is_bitfield_ptr); |
| 5220 | |
| 5221 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5222 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()). |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5223 | GetFieldAtIndex (idx, |
| 5224 | name, |
| 5225 | bit_offset_ptr, |
| 5226 | bitfield_bit_size_ptr, |
| 5227 | is_bitfield_ptr); |
| 5228 | |
| 5229 | default: |
| 5230 | break; |
| 5231 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5232 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5235 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5236 | ClangASTContext::GetNumDirectBaseClasses (lldb::opaque_compiler_type_t type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5237 | { |
| 5238 | uint32_t count = 0; |
| 5239 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5240 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5241 | switch (type_class) |
| 5242 | { |
| 5243 | case clang::Type::Record: |
| 5244 | if (GetCompleteType(type)) |
| 5245 | { |
| 5246 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5247 | if (cxx_record_decl) |
| 5248 | count = cxx_record_decl->getNumBases(); |
| 5249 | } |
| 5250 | break; |
| 5251 | |
| 5252 | case clang::Type::ObjCObjectPointer: |
| 5253 | count = GetPointeeType(type).GetNumDirectBaseClasses(); |
| 5254 | break; |
| 5255 | |
| 5256 | case clang::Type::ObjCObject: |
| 5257 | if (GetCompleteType(type)) |
| 5258 | { |
| 5259 | const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType(); |
| 5260 | if (objc_class_type) |
| 5261 | { |
| 5262 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 5263 | |
| 5264 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 5265 | count = 1; |
| 5266 | } |
| 5267 | } |
| 5268 | break; |
| 5269 | case clang::Type::ObjCInterface: |
| 5270 | if (GetCompleteType(type)) |
| 5271 | { |
| 5272 | const clang::ObjCInterfaceType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>(); |
| 5273 | if (objc_interface_type) |
| 5274 | { |
| 5275 | clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface(); |
| 5276 | |
| 5277 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 5278 | count = 1; |
| 5279 | } |
| 5280 | } |
| 5281 | break; |
| 5282 | |
| 5283 | |
| 5284 | case clang::Type::Typedef: |
| 5285 | count = GetNumDirectBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 5286 | break; |
| 5287 | |
| 5288 | case clang::Type::Elaborated: |
| 5289 | count = GetNumDirectBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 5290 | break; |
| 5291 | |
| 5292 | case clang::Type::Paren: |
| 5293 | return GetNumDirectBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 5294 | |
| 5295 | default: |
| 5296 | break; |
| 5297 | } |
| 5298 | return count; |
| 5299 | |
| 5300 | } |
| 5301 | |
| 5302 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5303 | ClangASTContext::GetNumVirtualBaseClasses (lldb::opaque_compiler_type_t type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5304 | { |
| 5305 | uint32_t count = 0; |
| 5306 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5307 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5308 | switch (type_class) |
| 5309 | { |
| 5310 | case clang::Type::Record: |
| 5311 | if (GetCompleteType(type)) |
| 5312 | { |
| 5313 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5314 | if (cxx_record_decl) |
| 5315 | count = cxx_record_decl->getNumVBases(); |
| 5316 | } |
| 5317 | break; |
| 5318 | |
| 5319 | case clang::Type::Typedef: |
| 5320 | count = GetNumVirtualBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 5321 | break; |
| 5322 | |
| 5323 | case clang::Type::Elaborated: |
| 5324 | count = GetNumVirtualBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 5325 | break; |
| 5326 | |
| 5327 | case clang::Type::Paren: |
| 5328 | count = GetNumVirtualBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 5329 | break; |
| 5330 | |
| 5331 | default: |
| 5332 | break; |
| 5333 | } |
| 5334 | return count; |
| 5335 | |
| 5336 | } |
| 5337 | |
| 5338 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5339 | ClangASTContext::GetDirectBaseClassAtIndex (lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5340 | { |
| 5341 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5342 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5343 | switch (type_class) |
| 5344 | { |
| 5345 | case clang::Type::Record: |
| 5346 | if (GetCompleteType(type)) |
| 5347 | { |
| 5348 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5349 | if (cxx_record_decl) |
| 5350 | { |
| 5351 | uint32_t curr_idx = 0; |
| 5352 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 5353 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 5354 | base_class != base_class_end; |
| 5355 | ++base_class, ++curr_idx) |
| 5356 | { |
| 5357 | if (curr_idx == idx) |
| 5358 | { |
| 5359 | if (bit_offset_ptr) |
| 5360 | { |
| 5361 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl); |
| 5362 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 5363 | if (base_class->isVirtual()) |
| 5364 | *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5365 | else |
| 5366 | *bit_offset_ptr = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5367 | } |
| 5368 | return CompilerType (this, base_class->getType().getAsOpaquePtr()); |
| 5369 | } |
| 5370 | } |
| 5371 | } |
| 5372 | } |
| 5373 | break; |
| 5374 | |
| 5375 | case clang::Type::ObjCObjectPointer: |
| 5376 | return GetPointeeType(type).GetDirectBaseClassAtIndex(idx, bit_offset_ptr); |
| 5377 | |
| 5378 | case clang::Type::ObjCObject: |
| 5379 | if (idx == 0 && GetCompleteType(type)) |
| 5380 | { |
| 5381 | const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType(); |
| 5382 | if (objc_class_type) |
| 5383 | { |
| 5384 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 5385 | |
| 5386 | if (class_interface_decl) |
| 5387 | { |
| 5388 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 5389 | if (superclass_interface_decl) |
| 5390 | { |
| 5391 | if (bit_offset_ptr) |
| 5392 | *bit_offset_ptr = 0; |
| 5393 | return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
| 5394 | } |
| 5395 | } |
| 5396 | } |
| 5397 | } |
| 5398 | break; |
| 5399 | case clang::Type::ObjCInterface: |
| 5400 | if (idx == 0 && GetCompleteType(type)) |
| 5401 | { |
| 5402 | const clang::ObjCObjectType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>(); |
| 5403 | if (objc_interface_type) |
| 5404 | { |
| 5405 | clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface(); |
| 5406 | |
| 5407 | if (class_interface_decl) |
| 5408 | { |
| 5409 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 5410 | if (superclass_interface_decl) |
| 5411 | { |
| 5412 | if (bit_offset_ptr) |
| 5413 | *bit_offset_ptr = 0; |
| 5414 | return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
| 5415 | } |
| 5416 | } |
| 5417 | } |
| 5418 | } |
| 5419 | break; |
| 5420 | |
| 5421 | |
| 5422 | case clang::Type::Typedef: |
| 5423 | return GetDirectBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5424 | |
| 5425 | case clang::Type::Elaborated: |
| 5426 | return GetDirectBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5427 | |
| 5428 | case clang::Type::Paren: |
| 5429 | return GetDirectBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5430 | |
| 5431 | default: |
| 5432 | break; |
| 5433 | } |
| 5434 | return CompilerType(); |
| 5435 | } |
| 5436 | |
| 5437 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5438 | ClangASTContext::GetVirtualBaseClassAtIndex (lldb::opaque_compiler_type_t type, |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5439 | size_t idx, |
| 5440 | uint32_t *bit_offset_ptr) |
| 5441 | { |
| 5442 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5443 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5444 | switch (type_class) |
| 5445 | { |
| 5446 | case clang::Type::Record: |
| 5447 | if (GetCompleteType(type)) |
| 5448 | { |
| 5449 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5450 | if (cxx_record_decl) |
| 5451 | { |
| 5452 | uint32_t curr_idx = 0; |
| 5453 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 5454 | for (base_class = cxx_record_decl->vbases_begin(), base_class_end = cxx_record_decl->vbases_end(); |
| 5455 | base_class != base_class_end; |
| 5456 | ++base_class, ++curr_idx) |
| 5457 | { |
| 5458 | if (curr_idx == idx) |
| 5459 | { |
| 5460 | if (bit_offset_ptr) |
| 5461 | { |
| 5462 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl); |
| 5463 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 5464 | *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5465 | |
| 5466 | } |
| 5467 | return CompilerType (this, base_class->getType().getAsOpaquePtr()); |
| 5468 | } |
| 5469 | } |
| 5470 | } |
| 5471 | } |
| 5472 | break; |
| 5473 | |
| 5474 | case clang::Type::Typedef: |
| 5475 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5476 | |
| 5477 | case clang::Type::Elaborated: |
| 5478 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5479 | |
| 5480 | case clang::Type::Paren: |
| 5481 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5482 | |
| 5483 | default: |
| 5484 | break; |
| 5485 | } |
| 5486 | return CompilerType(); |
| 5487 | |
| 5488 | } |
| 5489 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5490 | // If a pointer to a pointee type (the clang_type arg) says that it has no |
| 5491 | // children, then we either need to trust it, or override it and return a |
| 5492 | // different result. For example, an "int *" has one child that is an integer, |
| 5493 | // but a function pointer doesn't have any children. Likewise if a Record type |
| 5494 | // claims it has no children, then there really is nothing to show. |
| 5495 | uint32_t |
| 5496 | ClangASTContext::GetNumPointeeChildren (clang::QualType type) |
| 5497 | { |
| 5498 | if (type.isNull()) |
| 5499 | return 0; |
| 5500 | |
| 5501 | clang::QualType qual_type(type.getCanonicalType()); |
| 5502 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5503 | switch (type_class) |
| 5504 | { |
| 5505 | case clang::Type::Builtin: |
| 5506 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 5507 | { |
| 5508 | case clang::BuiltinType::UnknownAny: |
| 5509 | case clang::BuiltinType::Void: |
| 5510 | case clang::BuiltinType::NullPtr: |
| 5511 | case clang::BuiltinType::OCLEvent: |
| 5512 | case clang::BuiltinType::OCLImage1d: |
| 5513 | case clang::BuiltinType::OCLImage1dArray: |
| 5514 | case clang::BuiltinType::OCLImage1dBuffer: |
| 5515 | case clang::BuiltinType::OCLImage2d: |
| 5516 | case clang::BuiltinType::OCLImage2dArray: |
| 5517 | case clang::BuiltinType::OCLImage3d: |
| 5518 | case clang::BuiltinType::OCLSampler: |
| 5519 | return 0; |
| 5520 | case clang::BuiltinType::Bool: |
| 5521 | case clang::BuiltinType::Char_U: |
| 5522 | case clang::BuiltinType::UChar: |
| 5523 | case clang::BuiltinType::WChar_U: |
| 5524 | case clang::BuiltinType::Char16: |
| 5525 | case clang::BuiltinType::Char32: |
| 5526 | case clang::BuiltinType::UShort: |
| 5527 | case clang::BuiltinType::UInt: |
| 5528 | case clang::BuiltinType::ULong: |
| 5529 | case clang::BuiltinType::ULongLong: |
| 5530 | case clang::BuiltinType::UInt128: |
| 5531 | case clang::BuiltinType::Char_S: |
| 5532 | case clang::BuiltinType::SChar: |
| 5533 | case clang::BuiltinType::WChar_S: |
| 5534 | case clang::BuiltinType::Short: |
| 5535 | case clang::BuiltinType::Int: |
| 5536 | case clang::BuiltinType::Long: |
| 5537 | case clang::BuiltinType::LongLong: |
| 5538 | case clang::BuiltinType::Int128: |
| 5539 | case clang::BuiltinType::Float: |
| 5540 | case clang::BuiltinType::Double: |
| 5541 | case clang::BuiltinType::LongDouble: |
| 5542 | case clang::BuiltinType::Dependent: |
| 5543 | case clang::BuiltinType::Overload: |
| 5544 | case clang::BuiltinType::ObjCId: |
| 5545 | case clang::BuiltinType::ObjCClass: |
| 5546 | case clang::BuiltinType::ObjCSel: |
| 5547 | case clang::BuiltinType::BoundMember: |
| 5548 | case clang::BuiltinType::Half: |
| 5549 | case clang::BuiltinType::ARCUnbridgedCast: |
| 5550 | case clang::BuiltinType::PseudoObject: |
| 5551 | case clang::BuiltinType::BuiltinFn: |
Zachary Turner | 84f5b0d | 2015-09-09 17:25:43 +0000 | [diff] [blame] | 5552 | case clang::BuiltinType::OMPArraySection: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5553 | return 1; |
Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 5554 | default: |
| 5555 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5556 | } |
| 5557 | break; |
| 5558 | |
| 5559 | case clang::Type::Complex: return 1; |
| 5560 | case clang::Type::Pointer: return 1; |
| 5561 | case clang::Type::BlockPointer: return 0; // If block pointers don't have debug info, then no children for them |
| 5562 | case clang::Type::LValueReference: return 1; |
| 5563 | case clang::Type::RValueReference: return 1; |
| 5564 | case clang::Type::MemberPointer: return 0; |
| 5565 | case clang::Type::ConstantArray: return 0; |
| 5566 | case clang::Type::IncompleteArray: return 0; |
| 5567 | case clang::Type::VariableArray: return 0; |
| 5568 | case clang::Type::DependentSizedArray: return 0; |
| 5569 | case clang::Type::DependentSizedExtVector: return 0; |
| 5570 | case clang::Type::Vector: return 0; |
| 5571 | case clang::Type::ExtVector: return 0; |
| 5572 | case clang::Type::FunctionProto: return 0; // When we function pointers, they have no children... |
| 5573 | case clang::Type::FunctionNoProto: return 0; // When we function pointers, they have no children... |
| 5574 | case clang::Type::UnresolvedUsing: return 0; |
| 5575 | case clang::Type::Paren: return GetNumPointeeChildren (llvm::cast<clang::ParenType>(qual_type)->desugar()); |
| 5576 | case clang::Type::Typedef: return GetNumPointeeChildren (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()); |
| 5577 | case clang::Type::Elaborated: return GetNumPointeeChildren (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); |
| 5578 | case clang::Type::TypeOfExpr: return 0; |
| 5579 | case clang::Type::TypeOf: return 0; |
| 5580 | case clang::Type::Decltype: return 0; |
| 5581 | case clang::Type::Record: return 0; |
| 5582 | case clang::Type::Enum: return 1; |
| 5583 | case clang::Type::TemplateTypeParm: return 1; |
| 5584 | case clang::Type::SubstTemplateTypeParm: return 1; |
| 5585 | case clang::Type::TemplateSpecialization: return 1; |
| 5586 | case clang::Type::InjectedClassName: return 0; |
| 5587 | case clang::Type::DependentName: return 1; |
| 5588 | case clang::Type::DependentTemplateSpecialization: return 1; |
| 5589 | case clang::Type::ObjCObject: return 0; |
| 5590 | case clang::Type::ObjCInterface: return 0; |
| 5591 | case clang::Type::ObjCObjectPointer: return 1; |
| 5592 | default: |
| 5593 | break; |
| 5594 | } |
| 5595 | return 0; |
| 5596 | } |
| 5597 | |
| 5598 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5599 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5600 | ClangASTContext::GetChildCompilerTypeAtIndex (lldb::opaque_compiler_type_t type, |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 5601 | ExecutionContext *exe_ctx, |
| 5602 | size_t idx, |
| 5603 | bool transparent_pointers, |
| 5604 | bool omit_empty_base_classes, |
| 5605 | bool ignore_array_bounds, |
| 5606 | std::string& child_name, |
| 5607 | uint32_t &child_byte_size, |
| 5608 | int32_t &child_byte_offset, |
| 5609 | uint32_t &child_bitfield_bit_size, |
| 5610 | uint32_t &child_bitfield_bit_offset, |
| 5611 | bool &child_is_base_class, |
| 5612 | bool &child_is_deref_of_parent, |
| 5613 | ValueObject *valobj) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5614 | { |
| 5615 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5616 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5617 | |
| 5618 | clang::QualType parent_qual_type(GetCanonicalQualType(type)); |
| 5619 | const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass(); |
| 5620 | child_bitfield_bit_size = 0; |
| 5621 | child_bitfield_bit_offset = 0; |
| 5622 | child_is_base_class = false; |
| 5623 | |
| 5624 | const bool idx_is_valid = idx < GetNumChildren (type, omit_empty_base_classes); |
| 5625 | uint32_t bit_offset; |
| 5626 | switch (parent_type_class) |
| 5627 | { |
| 5628 | case clang::Type::Builtin: |
| 5629 | if (idx_is_valid) |
| 5630 | { |
| 5631 | switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) |
| 5632 | { |
| 5633 | case clang::BuiltinType::ObjCId: |
| 5634 | case clang::BuiltinType::ObjCClass: |
| 5635 | child_name = "isa"; |
| 5636 | child_byte_size = getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) / CHAR_BIT; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5637 | return CompilerType (getASTContext(), getASTContext()->ObjCBuiltinClassTy); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5638 | |
| 5639 | default: |
| 5640 | break; |
| 5641 | } |
| 5642 | } |
| 5643 | break; |
| 5644 | |
| 5645 | case clang::Type::Record: |
| 5646 | if (idx_is_valid && GetCompleteType(type)) |
| 5647 | { |
| 5648 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr()); |
| 5649 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5650 | assert(record_decl); |
| 5651 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); |
| 5652 | uint32_t child_idx = 0; |
| 5653 | |
| 5654 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 5655 | if (cxx_record_decl) |
| 5656 | { |
| 5657 | // We might have base classes to print out first |
| 5658 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 5659 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 5660 | base_class != base_class_end; |
| 5661 | ++base_class) |
| 5662 | { |
| 5663 | const clang::CXXRecordDecl *base_class_decl = nullptr; |
| 5664 | |
| 5665 | // Skip empty base classes |
| 5666 | if (omit_empty_base_classes) |
| 5667 | { |
| 5668 | base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 5669 | if (ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 5670 | continue; |
| 5671 | } |
| 5672 | |
| 5673 | if (idx == child_idx) |
| 5674 | { |
| 5675 | if (base_class_decl == nullptr) |
| 5676 | base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 5677 | |
| 5678 | |
| 5679 | if (base_class->isVirtual()) |
| 5680 | { |
| 5681 | bool handled = false; |
| 5682 | if (valobj) |
| 5683 | { |
| 5684 | Error err; |
| 5685 | AddressType addr_type = eAddressTypeInvalid; |
| 5686 | lldb::addr_t vtable_ptr_addr = valobj->GetCPPVTableAddress(addr_type); |
| 5687 | |
| 5688 | if (vtable_ptr_addr != LLDB_INVALID_ADDRESS && addr_type == eAddressTypeLoad) |
| 5689 | { |
| 5690 | |
| 5691 | ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); |
| 5692 | Process *process = exe_ctx.GetProcessPtr(); |
| 5693 | if (process) |
| 5694 | { |
| 5695 | clang::VTableContextBase *vtable_ctx = getASTContext()->getVTableContext(); |
| 5696 | if (vtable_ctx) |
| 5697 | { |
| 5698 | if (vtable_ctx->isMicrosoft()) |
| 5699 | { |
| 5700 | clang::MicrosoftVTableContext *msoft_vtable_ctx = static_cast<clang::MicrosoftVTableContext *>(vtable_ctx); |
| 5701 | |
| 5702 | if (vtable_ptr_addr) |
| 5703 | { |
| 5704 | const lldb::addr_t vbtable_ptr_addr = vtable_ptr_addr + record_layout.getVBPtrOffset().getQuantity(); |
| 5705 | |
| 5706 | const lldb::addr_t vbtable_ptr = process->ReadPointerFromMemory(vbtable_ptr_addr, err); |
| 5707 | if (vbtable_ptr != LLDB_INVALID_ADDRESS) |
| 5708 | { |
| 5709 | // Get the index into the virtual base table. The index is the index in uint32_t from vbtable_ptr |
| 5710 | const unsigned vbtable_index = msoft_vtable_ctx->getVBTableIndex(cxx_record_decl, base_class_decl); |
| 5711 | const lldb::addr_t base_offset_addr = vbtable_ptr + vbtable_index * 4; |
| 5712 | const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err); |
| 5713 | if (base_offset != UINT32_MAX) |
| 5714 | { |
| 5715 | handled = true; |
| 5716 | bit_offset = base_offset * 8; |
| 5717 | } |
| 5718 | } |
| 5719 | } |
| 5720 | } |
| 5721 | else |
| 5722 | { |
| 5723 | clang::ItaniumVTableContext *itanium_vtable_ctx = static_cast<clang::ItaniumVTableContext *>(vtable_ctx); |
| 5724 | if (vtable_ptr_addr) |
| 5725 | { |
| 5726 | const lldb::addr_t vtable_ptr = process->ReadPointerFromMemory(vtable_ptr_addr, err); |
| 5727 | if (vtable_ptr != LLDB_INVALID_ADDRESS) |
| 5728 | { |
| 5729 | clang::CharUnits base_offset_offset = itanium_vtable_ctx->getVirtualBaseOffsetOffset(cxx_record_decl, base_class_decl); |
| 5730 | const lldb::addr_t base_offset_addr = vtable_ptr + base_offset_offset.getQuantity(); |
| 5731 | const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err); |
| 5732 | if (base_offset != UINT32_MAX) |
| 5733 | { |
| 5734 | handled = true; |
| 5735 | bit_offset = base_offset * 8; |
| 5736 | } |
| 5737 | } |
| 5738 | } |
| 5739 | } |
| 5740 | } |
| 5741 | } |
| 5742 | } |
| 5743 | |
| 5744 | } |
| 5745 | if (!handled) |
| 5746 | bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5747 | } |
| 5748 | else |
| 5749 | bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5750 | |
| 5751 | // Base classes should be a multiple of 8 bits in size |
| 5752 | child_byte_offset = bit_offset/8; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5753 | CompilerType base_class_clang_type(getASTContext(), base_class->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5754 | child_name = base_class_clang_type.GetTypeName().AsCString(""); |
| 5755 | uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5756 | |
| 5757 | // Base classes bit sizes should be a multiple of 8 bits in size |
| 5758 | assert (base_class_clang_type_bit_size % 8 == 0); |
| 5759 | child_byte_size = base_class_clang_type_bit_size / 8; |
| 5760 | child_is_base_class = true; |
| 5761 | return base_class_clang_type; |
| 5762 | } |
| 5763 | // We don't increment the child index in the for loop since we might |
| 5764 | // be skipping empty base classes |
| 5765 | ++child_idx; |
| 5766 | } |
| 5767 | } |
| 5768 | // Make sure index is in range... |
| 5769 | uint32_t field_idx = 0; |
| 5770 | clang::RecordDecl::field_iterator field, field_end; |
| 5771 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx) |
| 5772 | { |
| 5773 | if (idx == child_idx) |
| 5774 | { |
| 5775 | // Print the member type if requested |
| 5776 | // Print the member name and equal sign |
| 5777 | child_name.assign(field->getNameAsString().c_str()); |
| 5778 | |
| 5779 | // Figure out the type byte size (field_type_info.first) and |
| 5780 | // alignment (field_type_info.second) from the AST context. |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5781 | CompilerType field_clang_type (getASTContext(), field->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5782 | assert(field_idx < record_layout.getFieldCount()); |
| 5783 | child_byte_size = field_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5784 | |
| 5785 | // Figure out the field offset within the current struct/union/class type |
| 5786 | bit_offset = record_layout.getFieldOffset (field_idx); |
| 5787 | child_byte_offset = bit_offset / 8; |
| 5788 | if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, child_bitfield_bit_size)) |
| 5789 | child_bitfield_bit_offset = bit_offset % 8; |
| 5790 | |
| 5791 | return field_clang_type; |
| 5792 | } |
| 5793 | } |
| 5794 | } |
| 5795 | break; |
| 5796 | |
| 5797 | case clang::Type::ObjCObject: |
| 5798 | case clang::Type::ObjCInterface: |
| 5799 | if (idx_is_valid && GetCompleteType(type)) |
| 5800 | { |
| 5801 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr()); |
| 5802 | assert (objc_class_type); |
| 5803 | if (objc_class_type) |
| 5804 | { |
| 5805 | uint32_t child_idx = 0; |
| 5806 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 5807 | |
| 5808 | if (class_interface_decl) |
| 5809 | { |
| 5810 | |
| 5811 | const clang::ASTRecordLayout &interface_layout = getASTContext()->getASTObjCInterfaceLayout(class_interface_decl); |
| 5812 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 5813 | if (superclass_interface_decl) |
| 5814 | { |
| 5815 | if (omit_empty_base_classes) |
| 5816 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5817 | CompilerType base_class_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5818 | if (base_class_clang_type.GetNumChildren(omit_empty_base_classes) > 0) |
| 5819 | { |
| 5820 | if (idx == 0) |
| 5821 | { |
| 5822 | clang::QualType ivar_qual_type(getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
| 5823 | |
| 5824 | |
| 5825 | child_name.assign(superclass_interface_decl->getNameAsString().c_str()); |
| 5826 | |
| 5827 | clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 5828 | |
| 5829 | child_byte_size = ivar_type_info.Width / 8; |
| 5830 | child_byte_offset = 0; |
| 5831 | child_is_base_class = true; |
| 5832 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5833 | return CompilerType (getASTContext(), ivar_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | ++child_idx; |
| 5837 | } |
| 5838 | } |
| 5839 | else |
| 5840 | ++child_idx; |
| 5841 | } |
| 5842 | |
| 5843 | const uint32_t superclass_idx = child_idx; |
| 5844 | |
| 5845 | if (idx < (child_idx + class_interface_decl->ivar_size())) |
| 5846 | { |
| 5847 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 5848 | |
| 5849 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos) |
| 5850 | { |
| 5851 | if (child_idx == idx) |
| 5852 | { |
| 5853 | clang::ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 5854 | |
| 5855 | clang::QualType ivar_qual_type(ivar_decl->getType()); |
| 5856 | |
| 5857 | child_name.assign(ivar_decl->getNameAsString().c_str()); |
| 5858 | |
| 5859 | clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 5860 | |
| 5861 | child_byte_size = ivar_type_info.Width / 8; |
| 5862 | |
| 5863 | // Figure out the field offset within the current struct/union/class type |
| 5864 | // For ObjC objects, we can't trust the bit offset we get from the Clang AST, since |
| 5865 | // that doesn't account for the space taken up by unbacked properties, or from |
| 5866 | // the changing size of base classes that are newer than this class. |
| 5867 | // So if we have a process around that we can ask about this object, do so. |
| 5868 | child_byte_offset = LLDB_INVALID_IVAR_OFFSET; |
| 5869 | Process *process = nullptr; |
| 5870 | if (exe_ctx) |
| 5871 | process = exe_ctx->GetProcessPtr(); |
| 5872 | if (process) |
| 5873 | { |
| 5874 | ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime(); |
| 5875 | if (objc_runtime != nullptr) |
| 5876 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5877 | CompilerType parent_ast_type (getASTContext(), parent_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5878 | child_byte_offset = objc_runtime->GetByteOffsetForIvar (parent_ast_type, ivar_decl->getNameAsString().c_str()); |
| 5879 | } |
| 5880 | } |
| 5881 | |
| 5882 | // Setting this to UINT32_MAX to make sure we don't compute it twice... |
| 5883 | bit_offset = UINT32_MAX; |
| 5884 | |
| 5885 | if (child_byte_offset == static_cast<int32_t>(LLDB_INVALID_IVAR_OFFSET)) |
| 5886 | { |
| 5887 | bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx); |
| 5888 | child_byte_offset = bit_offset / 8; |
| 5889 | } |
| 5890 | |
| 5891 | // Note, the ObjC Ivar Byte offset is just that, it doesn't account for the bit offset |
| 5892 | // of a bitfield within its containing object. So regardless of where we get the byte |
| 5893 | // offset from, we still need to get the bit offset for bitfields from the layout. |
| 5894 | |
| 5895 | if (ClangASTContext::FieldIsBitfield (getASTContext(), ivar_decl, child_bitfield_bit_size)) |
| 5896 | { |
| 5897 | if (bit_offset == UINT32_MAX) |
| 5898 | bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx); |
| 5899 | |
| 5900 | child_bitfield_bit_offset = bit_offset % 8; |
| 5901 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5902 | return CompilerType (getASTContext(), ivar_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5903 | } |
| 5904 | ++child_idx; |
| 5905 | } |
| 5906 | } |
| 5907 | } |
| 5908 | } |
| 5909 | } |
| 5910 | break; |
| 5911 | |
| 5912 | case clang::Type::ObjCObjectPointer: |
| 5913 | if (idx_is_valid) |
| 5914 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5915 | CompilerType pointee_clang_type (GetPointeeType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5916 | |
| 5917 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) |
| 5918 | { |
| 5919 | child_is_deref_of_parent = false; |
| 5920 | bool tmp_child_is_deref_of_parent = false; |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 5921 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 5922 | idx, |
| 5923 | transparent_pointers, |
| 5924 | omit_empty_base_classes, |
| 5925 | ignore_array_bounds, |
| 5926 | child_name, |
| 5927 | child_byte_size, |
| 5928 | child_byte_offset, |
| 5929 | child_bitfield_bit_size, |
| 5930 | child_bitfield_bit_offset, |
| 5931 | child_is_base_class, |
| 5932 | tmp_child_is_deref_of_parent, |
| 5933 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5934 | } |
| 5935 | else |
| 5936 | { |
| 5937 | child_is_deref_of_parent = true; |
| 5938 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; |
| 5939 | if (parent_name) |
| 5940 | { |
| 5941 | child_name.assign(1, '*'); |
| 5942 | child_name += parent_name; |
| 5943 | } |
| 5944 | |
| 5945 | // We have a pointer to an simple type |
| 5946 | if (idx == 0 && pointee_clang_type.GetCompleteType()) |
| 5947 | { |
| 5948 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5949 | child_byte_offset = 0; |
| 5950 | return pointee_clang_type; |
| 5951 | } |
| 5952 | } |
| 5953 | } |
| 5954 | break; |
| 5955 | |
| 5956 | case clang::Type::Vector: |
| 5957 | case clang::Type::ExtVector: |
| 5958 | if (idx_is_valid) |
| 5959 | { |
| 5960 | const clang::VectorType *array = llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr()); |
| 5961 | if (array) |
| 5962 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5963 | CompilerType element_type (getASTContext(), array->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5964 | if (element_type.GetCompleteType()) |
| 5965 | { |
| 5966 | char element_name[64]; |
| 5967 | ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx)); |
| 5968 | child_name.assign(element_name); |
| 5969 | child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5970 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 5971 | return element_type; |
| 5972 | } |
| 5973 | } |
| 5974 | } |
| 5975 | break; |
| 5976 | |
| 5977 | case clang::Type::ConstantArray: |
| 5978 | case clang::Type::IncompleteArray: |
| 5979 | if (ignore_array_bounds || idx_is_valid) |
| 5980 | { |
| 5981 | const clang::ArrayType *array = GetQualType(type)->getAsArrayTypeUnsafe(); |
| 5982 | if (array) |
| 5983 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5984 | CompilerType element_type (getASTContext(), array->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5985 | if (element_type.GetCompleteType()) |
| 5986 | { |
| 5987 | char element_name[64]; |
| 5988 | ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx)); |
| 5989 | child_name.assign(element_name); |
| 5990 | child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5991 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 5992 | return element_type; |
| 5993 | } |
| 5994 | } |
| 5995 | } |
| 5996 | break; |
| 5997 | |
| 5998 | |
| 5999 | case clang::Type::Pointer: |
| 6000 | if (idx_is_valid) |
| 6001 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6002 | CompilerType pointee_clang_type (GetPointeeType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6003 | |
| 6004 | // Don't dereference "void *" pointers |
| 6005 | if (pointee_clang_type.IsVoidType()) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6006 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6007 | |
| 6008 | if (transparent_pointers && pointee_clang_type.IsAggregateType ()) |
| 6009 | { |
| 6010 | child_is_deref_of_parent = false; |
| 6011 | bool tmp_child_is_deref_of_parent = false; |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6012 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6013 | idx, |
| 6014 | transparent_pointers, |
| 6015 | omit_empty_base_classes, |
| 6016 | ignore_array_bounds, |
| 6017 | child_name, |
| 6018 | child_byte_size, |
| 6019 | child_byte_offset, |
| 6020 | child_bitfield_bit_size, |
| 6021 | child_bitfield_bit_offset, |
| 6022 | child_is_base_class, |
| 6023 | tmp_child_is_deref_of_parent, |
| 6024 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6025 | } |
| 6026 | else |
| 6027 | { |
| 6028 | child_is_deref_of_parent = true; |
| 6029 | |
| 6030 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; |
| 6031 | if (parent_name) |
| 6032 | { |
| 6033 | child_name.assign(1, '*'); |
| 6034 | child_name += parent_name; |
| 6035 | } |
| 6036 | |
| 6037 | // We have a pointer to an simple type |
| 6038 | if (idx == 0) |
| 6039 | { |
| 6040 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6041 | child_byte_offset = 0; |
| 6042 | return pointee_clang_type; |
| 6043 | } |
| 6044 | } |
| 6045 | } |
| 6046 | break; |
| 6047 | |
| 6048 | case clang::Type::LValueReference: |
| 6049 | case clang::Type::RValueReference: |
| 6050 | if (idx_is_valid) |
| 6051 | { |
| 6052 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(parent_qual_type.getTypePtr()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6053 | CompilerType pointee_clang_type (getASTContext(), reference_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6054 | if (transparent_pointers && pointee_clang_type.IsAggregateType ()) |
| 6055 | { |
| 6056 | child_is_deref_of_parent = false; |
| 6057 | bool tmp_child_is_deref_of_parent = false; |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6058 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6059 | idx, |
| 6060 | transparent_pointers, |
| 6061 | omit_empty_base_classes, |
| 6062 | ignore_array_bounds, |
| 6063 | child_name, |
| 6064 | child_byte_size, |
| 6065 | child_byte_offset, |
| 6066 | child_bitfield_bit_size, |
| 6067 | child_bitfield_bit_offset, |
| 6068 | child_is_base_class, |
| 6069 | tmp_child_is_deref_of_parent, |
| 6070 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6071 | } |
| 6072 | else |
| 6073 | { |
| 6074 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; |
| 6075 | if (parent_name) |
| 6076 | { |
| 6077 | child_name.assign(1, '&'); |
| 6078 | child_name += parent_name; |
| 6079 | } |
| 6080 | |
| 6081 | // We have a pointer to an simple type |
| 6082 | if (idx == 0) |
| 6083 | { |
| 6084 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6085 | child_byte_offset = 0; |
| 6086 | return pointee_clang_type; |
| 6087 | } |
| 6088 | } |
| 6089 | } |
| 6090 | break; |
| 6091 | |
| 6092 | case clang::Type::Typedef: |
| 6093 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6094 | CompilerType typedefed_clang_type (getASTContext(), llvm::cast<clang::TypedefType>(parent_qual_type)->getDecl()->getUnderlyingType()); |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6095 | return typedefed_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6096 | idx, |
| 6097 | transparent_pointers, |
| 6098 | omit_empty_base_classes, |
| 6099 | ignore_array_bounds, |
| 6100 | child_name, |
| 6101 | child_byte_size, |
| 6102 | child_byte_offset, |
| 6103 | child_bitfield_bit_size, |
| 6104 | child_bitfield_bit_offset, |
| 6105 | child_is_base_class, |
| 6106 | child_is_deref_of_parent, |
| 6107 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6108 | } |
| 6109 | break; |
| 6110 | |
| 6111 | case clang::Type::Elaborated: |
| 6112 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6113 | CompilerType elaborated_clang_type (getASTContext(), llvm::cast<clang::ElaboratedType>(parent_qual_type)->getNamedType()); |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6114 | return elaborated_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6115 | idx, |
| 6116 | transparent_pointers, |
| 6117 | omit_empty_base_classes, |
| 6118 | ignore_array_bounds, |
| 6119 | child_name, |
| 6120 | child_byte_size, |
| 6121 | child_byte_offset, |
| 6122 | child_bitfield_bit_size, |
| 6123 | child_bitfield_bit_offset, |
| 6124 | child_is_base_class, |
| 6125 | child_is_deref_of_parent, |
| 6126 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | case clang::Type::Paren: |
| 6130 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6131 | CompilerType paren_clang_type (getASTContext(), llvm::cast<clang::ParenType>(parent_qual_type)->desugar()); |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6132 | return paren_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6133 | idx, |
| 6134 | transparent_pointers, |
| 6135 | omit_empty_base_classes, |
| 6136 | ignore_array_bounds, |
| 6137 | child_name, |
| 6138 | child_byte_size, |
| 6139 | child_byte_offset, |
| 6140 | child_bitfield_bit_size, |
| 6141 | child_bitfield_bit_offset, |
| 6142 | child_is_base_class, |
| 6143 | child_is_deref_of_parent, |
| 6144 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6145 | } |
| 6146 | |
| 6147 | |
| 6148 | default: |
| 6149 | break; |
| 6150 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6151 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | static uint32_t |
| 6155 | GetIndexForRecordBase |
| 6156 | ( |
| 6157 | const clang::RecordDecl *record_decl, |
| 6158 | const clang::CXXBaseSpecifier *base_spec, |
| 6159 | bool omit_empty_base_classes |
| 6160 | ) |
| 6161 | { |
| 6162 | uint32_t child_idx = 0; |
| 6163 | |
| 6164 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6165 | |
| 6166 | // const char *super_name = record_decl->getNameAsCString(); |
| 6167 | // const char *base_name = base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString(); |
| 6168 | // printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name); |
| 6169 | // |
| 6170 | if (cxx_record_decl) |
| 6171 | { |
| 6172 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 6173 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 6174 | base_class != base_class_end; |
| 6175 | ++base_class) |
| 6176 | { |
| 6177 | if (omit_empty_base_classes) |
| 6178 | { |
| 6179 | if (BaseSpecifierIsEmpty (base_class)) |
| 6180 | continue; |
| 6181 | } |
| 6182 | |
| 6183 | // printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", super_name, base_name, |
| 6184 | // child_idx, |
| 6185 | // base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString()); |
| 6186 | // |
| 6187 | // |
| 6188 | if (base_class == base_spec) |
| 6189 | return child_idx; |
| 6190 | ++child_idx; |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | return UINT32_MAX; |
| 6195 | } |
| 6196 | |
| 6197 | |
| 6198 | static uint32_t |
| 6199 | GetIndexForRecordChild (const clang::RecordDecl *record_decl, |
| 6200 | clang::NamedDecl *canonical_decl, |
| 6201 | bool omit_empty_base_classes) |
| 6202 | { |
| 6203 | uint32_t child_idx = ClangASTContext::GetNumBaseClasses (llvm::dyn_cast<clang::CXXRecordDecl>(record_decl), |
| 6204 | omit_empty_base_classes); |
| 6205 | |
| 6206 | clang::RecordDecl::field_iterator field, field_end; |
| 6207 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 6208 | field != field_end; |
| 6209 | ++field, ++child_idx) |
| 6210 | { |
| 6211 | if (field->getCanonicalDecl() == canonical_decl) |
| 6212 | return child_idx; |
| 6213 | } |
| 6214 | |
| 6215 | return UINT32_MAX; |
| 6216 | } |
| 6217 | |
| 6218 | // Look for a child member (doesn't include base classes, but it does include |
| 6219 | // their members) in the type hierarchy. Returns an index path into "clang_type" |
| 6220 | // on how to reach the appropriate member. |
| 6221 | // |
| 6222 | // class A |
| 6223 | // { |
| 6224 | // public: |
| 6225 | // int m_a; |
| 6226 | // int m_b; |
| 6227 | // }; |
| 6228 | // |
| 6229 | // class B |
| 6230 | // { |
| 6231 | // }; |
| 6232 | // |
| 6233 | // class C : |
| 6234 | // public B, |
| 6235 | // public A |
| 6236 | // { |
| 6237 | // }; |
| 6238 | // |
| 6239 | // If we have a clang type that describes "class C", and we wanted to looked |
| 6240 | // "m_b" in it: |
| 6241 | // |
| 6242 | // With omit_empty_base_classes == false we would get an integer array back with: |
| 6243 | // { 1, 1 } |
| 6244 | // The first index 1 is the child index for "class A" within class C |
| 6245 | // The second index 1 is the child index for "m_b" within class A |
| 6246 | // |
| 6247 | // With omit_empty_base_classes == true we would get an integer array back with: |
| 6248 | // { 0, 1 } |
| 6249 | // The first index 0 is the child index for "class A" within class C (since class B doesn't have any members it doesn't count) |
| 6250 | // The second index 1 is the child index for "m_b" within class A |
| 6251 | |
| 6252 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6253 | ClangASTContext::GetIndexOfChildMemberWithName (lldb::opaque_compiler_type_t type, const char *name, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6254 | bool omit_empty_base_classes, |
| 6255 | std::vector<uint32_t>& child_indexes) |
| 6256 | { |
| 6257 | if (type && name && name[0]) |
| 6258 | { |
| 6259 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6260 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6261 | switch (type_class) |
| 6262 | { |
| 6263 | case clang::Type::Record: |
| 6264 | if (GetCompleteType(type)) |
| 6265 | { |
| 6266 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 6267 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 6268 | |
| 6269 | assert(record_decl); |
| 6270 | uint32_t child_idx = 0; |
| 6271 | |
| 6272 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6273 | |
| 6274 | // Try and find a field that matches NAME |
| 6275 | clang::RecordDecl::field_iterator field, field_end; |
| 6276 | llvm::StringRef name_sref(name); |
| 6277 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 6278 | field != field_end; |
| 6279 | ++field, ++child_idx) |
| 6280 | { |
| 6281 | llvm::StringRef field_name = field->getName(); |
| 6282 | if (field_name.empty()) |
| 6283 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6284 | CompilerType field_type(getASTContext(),field->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6285 | child_indexes.push_back(child_idx); |
| 6286 | if (field_type.GetIndexOfChildMemberWithName(name, omit_empty_base_classes, child_indexes)) |
| 6287 | return child_indexes.size(); |
| 6288 | child_indexes.pop_back(); |
| 6289 | |
| 6290 | } |
| 6291 | else if (field_name.equals (name_sref)) |
| 6292 | { |
| 6293 | // We have to add on the number of base classes to this index! |
| 6294 | child_indexes.push_back (child_idx + ClangASTContext::GetNumBaseClasses (cxx_record_decl, omit_empty_base_classes)); |
| 6295 | return child_indexes.size(); |
| 6296 | } |
| 6297 | } |
| 6298 | |
| 6299 | if (cxx_record_decl) |
| 6300 | { |
| 6301 | const clang::RecordDecl *parent_record_decl = cxx_record_decl; |
| 6302 | |
| 6303 | //printf ("parent = %s\n", parent_record_decl->getNameAsCString()); |
| 6304 | |
| 6305 | //const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl(); |
| 6306 | // Didn't find things easily, lets let clang do its thang... |
| 6307 | clang::IdentifierInfo & ident_ref = getASTContext()->Idents.get(name_sref); |
| 6308 | clang::DeclarationName decl_name(&ident_ref); |
| 6309 | |
| 6310 | clang::CXXBasePaths paths; |
| 6311 | if (cxx_record_decl->lookupInBases([decl_name](const clang::CXXBaseSpecifier *specifier, clang::CXXBasePath &path) { |
| 6312 | return clang::CXXRecordDecl::FindOrdinaryMember(specifier, path, decl_name); |
| 6313 | }, |
| 6314 | paths)) |
| 6315 | { |
| 6316 | clang::CXXBasePaths::const_paths_iterator path, path_end = paths.end(); |
| 6317 | for (path = paths.begin(); path != path_end; ++path) |
| 6318 | { |
| 6319 | const size_t num_path_elements = path->size(); |
| 6320 | for (size_t e=0; e<num_path_elements; ++e) |
| 6321 | { |
| 6322 | clang::CXXBasePathElement elem = (*path)[e]; |
| 6323 | |
| 6324 | child_idx = GetIndexForRecordBase (parent_record_decl, elem.Base, omit_empty_base_classes); |
| 6325 | if (child_idx == UINT32_MAX) |
| 6326 | { |
| 6327 | child_indexes.clear(); |
| 6328 | return 0; |
| 6329 | } |
| 6330 | else |
| 6331 | { |
| 6332 | child_indexes.push_back (child_idx); |
| 6333 | parent_record_decl = llvm::cast<clang::RecordDecl>(elem.Base->getType()->getAs<clang::RecordType>()->getDecl()); |
| 6334 | } |
| 6335 | } |
| 6336 | for (clang::NamedDecl *path_decl : path->Decls) |
| 6337 | { |
| 6338 | child_idx = GetIndexForRecordChild (parent_record_decl, path_decl, omit_empty_base_classes); |
| 6339 | if (child_idx == UINT32_MAX) |
| 6340 | { |
| 6341 | child_indexes.clear(); |
| 6342 | return 0; |
| 6343 | } |
| 6344 | else |
| 6345 | { |
| 6346 | child_indexes.push_back (child_idx); |
| 6347 | } |
| 6348 | } |
| 6349 | } |
| 6350 | return child_indexes.size(); |
| 6351 | } |
| 6352 | } |
| 6353 | |
| 6354 | } |
| 6355 | break; |
| 6356 | |
| 6357 | case clang::Type::ObjCObject: |
| 6358 | case clang::Type::ObjCInterface: |
| 6359 | if (GetCompleteType(type)) |
| 6360 | { |
| 6361 | llvm::StringRef name_sref(name); |
| 6362 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 6363 | assert (objc_class_type); |
| 6364 | if (objc_class_type) |
| 6365 | { |
| 6366 | uint32_t child_idx = 0; |
| 6367 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 6368 | |
| 6369 | if (class_interface_decl) |
| 6370 | { |
| 6371 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 6372 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 6373 | |
| 6374 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx) |
| 6375 | { |
| 6376 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 6377 | |
| 6378 | if (ivar_decl->getName().equals (name_sref)) |
| 6379 | { |
| 6380 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 6381 | ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true))) |
| 6382 | ++child_idx; |
| 6383 | |
| 6384 | child_indexes.push_back (child_idx); |
| 6385 | return child_indexes.size(); |
| 6386 | } |
| 6387 | } |
| 6388 | |
| 6389 | if (superclass_interface_decl) |
| 6390 | { |
| 6391 | // The super class index is always zero for ObjC classes, |
| 6392 | // so we push it onto the child indexes in case we find |
| 6393 | // an ivar in our superclass... |
| 6394 | child_indexes.push_back (0); |
| 6395 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6396 | CompilerType superclass_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6397 | if (superclass_clang_type.GetIndexOfChildMemberWithName (name, |
| 6398 | omit_empty_base_classes, |
| 6399 | child_indexes)) |
| 6400 | { |
| 6401 | // We did find an ivar in a superclass so just |
| 6402 | // return the results! |
| 6403 | return child_indexes.size(); |
| 6404 | } |
| 6405 | |
| 6406 | // We didn't find an ivar matching "name" in our |
| 6407 | // superclass, pop the superclass zero index that |
| 6408 | // we pushed on above. |
| 6409 | child_indexes.pop_back(); |
| 6410 | } |
| 6411 | } |
| 6412 | } |
| 6413 | } |
| 6414 | break; |
| 6415 | |
| 6416 | case clang::Type::ObjCObjectPointer: |
| 6417 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6418 | CompilerType objc_object_clang_type (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6419 | return objc_object_clang_type.GetIndexOfChildMemberWithName (name, |
| 6420 | omit_empty_base_classes, |
| 6421 | child_indexes); |
| 6422 | } |
| 6423 | break; |
| 6424 | |
| 6425 | |
| 6426 | case clang::Type::ConstantArray: |
| 6427 | { |
| 6428 | // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 6429 | // const uint64_t element_count = array->getSize().getLimitedValue(); |
| 6430 | // |
| 6431 | // if (idx < element_count) |
| 6432 | // { |
| 6433 | // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); |
| 6434 | // |
| 6435 | // char element_name[32]; |
| 6436 | // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx); |
| 6437 | // |
| 6438 | // child_name.assign(element_name); |
| 6439 | // assert(field_type_info.first % 8 == 0); |
| 6440 | // child_byte_size = field_type_info.first / 8; |
| 6441 | // child_byte_offset = idx * child_byte_size; |
| 6442 | // return array->getElementType().getAsOpaquePtr(); |
| 6443 | // } |
| 6444 | } |
| 6445 | break; |
| 6446 | |
| 6447 | // case clang::Type::MemberPointerType: |
| 6448 | // { |
| 6449 | // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr()); |
| 6450 | // clang::QualType pointee_type = mem_ptr_type->getPointeeType(); |
| 6451 | // |
| 6452 | // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 6453 | // { |
| 6454 | // return GetIndexOfChildWithName (ast, |
| 6455 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 6456 | // name); |
| 6457 | // } |
| 6458 | // } |
| 6459 | // break; |
| 6460 | // |
| 6461 | case clang::Type::LValueReference: |
| 6462 | case clang::Type::RValueReference: |
| 6463 | { |
| 6464 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 6465 | clang::QualType pointee_type(reference_type->getPointeeType()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6466 | CompilerType pointee_clang_type (getASTContext(), pointee_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6467 | |
| 6468 | if (pointee_clang_type.IsAggregateType ()) |
| 6469 | { |
| 6470 | return pointee_clang_type.GetIndexOfChildMemberWithName (name, |
| 6471 | omit_empty_base_classes, |
| 6472 | child_indexes); |
| 6473 | } |
| 6474 | } |
| 6475 | break; |
| 6476 | |
| 6477 | case clang::Type::Pointer: |
| 6478 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6479 | CompilerType pointee_clang_type (GetPointeeType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6480 | |
| 6481 | if (pointee_clang_type.IsAggregateType ()) |
| 6482 | { |
| 6483 | return pointee_clang_type.GetIndexOfChildMemberWithName (name, |
| 6484 | omit_empty_base_classes, |
| 6485 | child_indexes); |
| 6486 | } |
| 6487 | } |
| 6488 | break; |
| 6489 | |
| 6490 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6491 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildMemberWithName (name, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6492 | omit_empty_base_classes, |
| 6493 | child_indexes); |
| 6494 | |
| 6495 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6496 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildMemberWithName (name, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6497 | omit_empty_base_classes, |
| 6498 | child_indexes); |
| 6499 | |
| 6500 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6501 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildMemberWithName (name, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6502 | omit_empty_base_classes, |
| 6503 | child_indexes); |
| 6504 | |
| 6505 | default: |
| 6506 | break; |
| 6507 | } |
| 6508 | } |
| 6509 | return 0; |
| 6510 | } |
| 6511 | |
| 6512 | |
| 6513 | // Get the index of the child of "clang_type" whose name matches. This function |
| 6514 | // doesn't descend into the children, but only looks one level deep and name |
| 6515 | // matches can include base class names. |
| 6516 | |
| 6517 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6518 | ClangASTContext::GetIndexOfChildWithName (lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6519 | { |
| 6520 | if (type && name && name[0]) |
| 6521 | { |
| 6522 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6523 | |
| 6524 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6525 | |
| 6526 | switch (type_class) |
| 6527 | { |
| 6528 | case clang::Type::Record: |
| 6529 | if (GetCompleteType(type)) |
| 6530 | { |
| 6531 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 6532 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 6533 | |
| 6534 | assert(record_decl); |
| 6535 | uint32_t child_idx = 0; |
| 6536 | |
| 6537 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6538 | |
| 6539 | if (cxx_record_decl) |
| 6540 | { |
| 6541 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 6542 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 6543 | base_class != base_class_end; |
| 6544 | ++base_class) |
| 6545 | { |
| 6546 | // Skip empty base classes |
| 6547 | clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 6548 | if (omit_empty_base_classes && ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 6549 | continue; |
| 6550 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6551 | CompilerType base_class_clang_type (getASTContext(), base_class->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6552 | std::string base_class_type_name (base_class_clang_type.GetTypeName().AsCString("")); |
| 6553 | if (base_class_type_name.compare (name) == 0) |
| 6554 | return child_idx; |
| 6555 | ++child_idx; |
| 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | // Try and find a field that matches NAME |
| 6560 | clang::RecordDecl::field_iterator field, field_end; |
| 6561 | llvm::StringRef name_sref(name); |
| 6562 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 6563 | field != field_end; |
| 6564 | ++field, ++child_idx) |
| 6565 | { |
| 6566 | if (field->getName().equals (name_sref)) |
| 6567 | return child_idx; |
| 6568 | } |
| 6569 | |
| 6570 | } |
| 6571 | break; |
| 6572 | |
| 6573 | case clang::Type::ObjCObject: |
| 6574 | case clang::Type::ObjCInterface: |
| 6575 | if (GetCompleteType(type)) |
| 6576 | { |
| 6577 | llvm::StringRef name_sref(name); |
| 6578 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 6579 | assert (objc_class_type); |
| 6580 | if (objc_class_type) |
| 6581 | { |
| 6582 | uint32_t child_idx = 0; |
| 6583 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 6584 | |
| 6585 | if (class_interface_decl) |
| 6586 | { |
| 6587 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 6588 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 6589 | |
| 6590 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx) |
| 6591 | { |
| 6592 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 6593 | |
| 6594 | if (ivar_decl->getName().equals (name_sref)) |
| 6595 | { |
| 6596 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 6597 | ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true))) |
| 6598 | ++child_idx; |
| 6599 | |
| 6600 | return child_idx; |
| 6601 | } |
| 6602 | } |
| 6603 | |
| 6604 | if (superclass_interface_decl) |
| 6605 | { |
| 6606 | if (superclass_interface_decl->getName().equals (name_sref)) |
| 6607 | return 0; |
| 6608 | } |
| 6609 | } |
| 6610 | } |
| 6611 | } |
| 6612 | break; |
| 6613 | |
| 6614 | case clang::Type::ObjCObjectPointer: |
| 6615 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6616 | CompilerType pointee_clang_type (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6617 | return pointee_clang_type.GetIndexOfChildWithName (name, omit_empty_base_classes); |
| 6618 | } |
| 6619 | break; |
| 6620 | |
| 6621 | case clang::Type::ConstantArray: |
| 6622 | { |
| 6623 | // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 6624 | // const uint64_t element_count = array->getSize().getLimitedValue(); |
| 6625 | // |
| 6626 | // if (idx < element_count) |
| 6627 | // { |
| 6628 | // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); |
| 6629 | // |
| 6630 | // char element_name[32]; |
| 6631 | // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx); |
| 6632 | // |
| 6633 | // child_name.assign(element_name); |
| 6634 | // assert(field_type_info.first % 8 == 0); |
| 6635 | // child_byte_size = field_type_info.first / 8; |
| 6636 | // child_byte_offset = idx * child_byte_size; |
| 6637 | // return array->getElementType().getAsOpaquePtr(); |
| 6638 | // } |
| 6639 | } |
| 6640 | break; |
| 6641 | |
| 6642 | // case clang::Type::MemberPointerType: |
| 6643 | // { |
| 6644 | // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr()); |
| 6645 | // clang::QualType pointee_type = mem_ptr_type->getPointeeType(); |
| 6646 | // |
| 6647 | // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 6648 | // { |
| 6649 | // return GetIndexOfChildWithName (ast, |
| 6650 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 6651 | // name); |
| 6652 | // } |
| 6653 | // } |
| 6654 | // break; |
| 6655 | // |
| 6656 | case clang::Type::LValueReference: |
| 6657 | case clang::Type::RValueReference: |
| 6658 | { |
| 6659 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6660 | CompilerType pointee_type (getASTContext(), reference_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6661 | |
| 6662 | if (pointee_type.IsAggregateType ()) |
| 6663 | { |
| 6664 | return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes); |
| 6665 | } |
| 6666 | } |
| 6667 | break; |
| 6668 | |
| 6669 | case clang::Type::Pointer: |
| 6670 | { |
| 6671 | const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6672 | CompilerType pointee_type (getASTContext(), pointer_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6673 | |
| 6674 | if (pointee_type.IsAggregateType ()) |
| 6675 | { |
| 6676 | return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes); |
| 6677 | } |
| 6678 | else |
| 6679 | { |
| 6680 | // if (parent_name) |
| 6681 | // { |
| 6682 | // child_name.assign(1, '*'); |
| 6683 | // child_name += parent_name; |
| 6684 | // } |
| 6685 | // |
| 6686 | // // We have a pointer to an simple type |
| 6687 | // if (idx == 0) |
| 6688 | // { |
| 6689 | // std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type); |
| 6690 | // assert(clang_type_info.first % 8 == 0); |
| 6691 | // child_byte_size = clang_type_info.first / 8; |
| 6692 | // child_byte_offset = 0; |
| 6693 | // return pointee_type.getAsOpaquePtr(); |
| 6694 | // } |
| 6695 | } |
| 6696 | } |
| 6697 | break; |
| 6698 | |
| 6699 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6700 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildWithName (name, omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6701 | |
| 6702 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6703 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildWithName (name, omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6704 | |
| 6705 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6706 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildWithName (name, omit_empty_base_classes); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6707 | |
| 6708 | default: |
| 6709 | break; |
| 6710 | } |
| 6711 | } |
| 6712 | return UINT32_MAX; |
| 6713 | } |
| 6714 | |
| 6715 | |
| 6716 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6717 | ClangASTContext::GetNumTemplateArguments (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6718 | { |
| 6719 | if (!type) |
| 6720 | return 0; |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6721 | |
| 6722 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 6723 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6724 | switch (type_class) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6725 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6726 | case clang::Type::Record: |
| 6727 | if (GetCompleteType(type)) |
| 6728 | { |
| 6729 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 6730 | if (cxx_record_decl) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6731 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6732 | const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl); |
| 6733 | if (template_decl) |
| 6734 | return template_decl->getTemplateArgs().size(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6735 | } |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6736 | } |
| 6737 | break; |
| 6738 | |
| 6739 | case clang::Type::Typedef: |
| 6740 | return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetNumTemplateArguments(); |
| 6741 | |
| 6742 | case clang::Type::Elaborated: |
| 6743 | return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetNumTemplateArguments(); |
| 6744 | |
| 6745 | case clang::Type::Paren: |
| 6746 | return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetNumTemplateArguments(); |
| 6747 | |
| 6748 | default: |
| 6749 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6750 | } |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6751 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6752 | return 0; |
| 6753 | } |
| 6754 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6755 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6756 | ClangASTContext::GetTemplateArgument (lldb::opaque_compiler_type_t type, size_t arg_idx, lldb::TemplateArgumentKind &kind) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6757 | { |
| 6758 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6759 | return CompilerType(); |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6760 | |
| 6761 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 6762 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6763 | switch (type_class) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6764 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6765 | case clang::Type::Record: |
| 6766 | if (GetCompleteType(type)) |
| 6767 | { |
| 6768 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 6769 | if (cxx_record_decl) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6770 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6771 | const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl); |
| 6772 | if (template_decl && arg_idx < template_decl->getTemplateArgs().size()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6773 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6774 | const clang::TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx]; |
| 6775 | switch (template_arg.getKind()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6776 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6777 | case clang::TemplateArgument::Null: |
| 6778 | kind = eTemplateArgumentKindNull; |
| 6779 | return CompilerType(); |
| 6780 | |
| 6781 | case clang::TemplateArgument::Type: |
| 6782 | kind = eTemplateArgumentKindType; |
| 6783 | return CompilerType(getASTContext(), template_arg.getAsType()); |
| 6784 | |
| 6785 | case clang::TemplateArgument::Declaration: |
| 6786 | kind = eTemplateArgumentKindDeclaration; |
| 6787 | return CompilerType(); |
| 6788 | |
| 6789 | case clang::TemplateArgument::Integral: |
| 6790 | kind = eTemplateArgumentKindIntegral; |
| 6791 | return CompilerType(getASTContext(), template_arg.getIntegralType()); |
| 6792 | |
| 6793 | case clang::TemplateArgument::Template: |
| 6794 | kind = eTemplateArgumentKindTemplate; |
| 6795 | return CompilerType(); |
| 6796 | |
| 6797 | case clang::TemplateArgument::TemplateExpansion: |
| 6798 | kind = eTemplateArgumentKindTemplateExpansion; |
| 6799 | return CompilerType(); |
| 6800 | |
| 6801 | case clang::TemplateArgument::Expression: |
| 6802 | kind = eTemplateArgumentKindExpression; |
| 6803 | return CompilerType(); |
| 6804 | |
| 6805 | case clang::TemplateArgument::Pack: |
| 6806 | kind = eTemplateArgumentKindPack; |
| 6807 | return CompilerType(); |
| 6808 | |
| 6809 | default: |
| 6810 | assert (!"Unhandled clang::TemplateArgument::ArgKind"); |
| 6811 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6812 | } |
| 6813 | } |
| 6814 | } |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6815 | } |
| 6816 | break; |
| 6817 | |
| 6818 | case clang::Type::Typedef: |
| 6819 | return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetTemplateArgument(arg_idx, kind); |
| 6820 | |
| 6821 | case clang::Type::Elaborated: |
| 6822 | return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetTemplateArgument(arg_idx, kind); |
| 6823 | |
| 6824 | case clang::Type::Paren: |
| 6825 | return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetTemplateArgument(arg_idx, kind); |
| 6826 | |
| 6827 | default: |
| 6828 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6829 | } |
| 6830 | kind = eTemplateArgumentKindNull; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6831 | return CompilerType (); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6832 | } |
| 6833 | |
Enrico Granata | c6bf2e2 | 2015-09-23 01:39:46 +0000 | [diff] [blame] | 6834 | CompilerType |
| 6835 | ClangASTContext::GetTypeForFormatters (void* type) |
| 6836 | { |
| 6837 | if (type) |
| 6838 | return RemoveFastQualifiers(CompilerType(this, type)); |
| 6839 | return CompilerType(); |
| 6840 | } |
| 6841 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6842 | static bool |
| 6843 | IsOperator (const char *name, clang::OverloadedOperatorKind &op_kind) |
| 6844 | { |
| 6845 | if (name == nullptr || name[0] == '\0') |
| 6846 | return false; |
| 6847 | |
| 6848 | #define OPERATOR_PREFIX "operator" |
| 6849 | #define OPERATOR_PREFIX_LENGTH (sizeof (OPERATOR_PREFIX) - 1) |
| 6850 | |
| 6851 | const char *post_op_name = nullptr; |
| 6852 | |
| 6853 | bool no_space = true; |
| 6854 | |
| 6855 | if (::strncmp(name, OPERATOR_PREFIX, OPERATOR_PREFIX_LENGTH)) |
| 6856 | return false; |
| 6857 | |
| 6858 | post_op_name = name + OPERATOR_PREFIX_LENGTH; |
| 6859 | |
| 6860 | if (post_op_name[0] == ' ') |
| 6861 | { |
| 6862 | post_op_name++; |
| 6863 | no_space = false; |
| 6864 | } |
| 6865 | |
| 6866 | #undef OPERATOR_PREFIX |
| 6867 | #undef OPERATOR_PREFIX_LENGTH |
| 6868 | |
| 6869 | // This is an operator, set the overloaded operator kind to invalid |
| 6870 | // in case this is a conversion operator... |
| 6871 | op_kind = clang::NUM_OVERLOADED_OPERATORS; |
| 6872 | |
| 6873 | switch (post_op_name[0]) |
| 6874 | { |
| 6875 | default: |
| 6876 | if (no_space) |
| 6877 | return false; |
| 6878 | break; |
| 6879 | case 'n': |
| 6880 | if (no_space) |
| 6881 | return false; |
| 6882 | if (strcmp (post_op_name, "new") == 0) |
| 6883 | op_kind = clang::OO_New; |
| 6884 | else if (strcmp (post_op_name, "new[]") == 0) |
| 6885 | op_kind = clang::OO_Array_New; |
| 6886 | break; |
| 6887 | |
| 6888 | case 'd': |
| 6889 | if (no_space) |
| 6890 | return false; |
| 6891 | if (strcmp (post_op_name, "delete") == 0) |
| 6892 | op_kind = clang::OO_Delete; |
| 6893 | else if (strcmp (post_op_name, "delete[]") == 0) |
| 6894 | op_kind = clang::OO_Array_Delete; |
| 6895 | break; |
| 6896 | |
| 6897 | case '+': |
| 6898 | if (post_op_name[1] == '\0') |
| 6899 | op_kind = clang::OO_Plus; |
| 6900 | else if (post_op_name[2] == '\0') |
| 6901 | { |
| 6902 | if (post_op_name[1] == '=') |
| 6903 | op_kind = clang::OO_PlusEqual; |
| 6904 | else if (post_op_name[1] == '+') |
| 6905 | op_kind = clang::OO_PlusPlus; |
| 6906 | } |
| 6907 | break; |
| 6908 | |
| 6909 | case '-': |
| 6910 | if (post_op_name[1] == '\0') |
| 6911 | op_kind = clang::OO_Minus; |
| 6912 | else if (post_op_name[2] == '\0') |
| 6913 | { |
| 6914 | switch (post_op_name[1]) |
| 6915 | { |
| 6916 | case '=': op_kind = clang::OO_MinusEqual; break; |
| 6917 | case '-': op_kind = clang::OO_MinusMinus; break; |
| 6918 | case '>': op_kind = clang::OO_Arrow; break; |
| 6919 | } |
| 6920 | } |
| 6921 | else if (post_op_name[3] == '\0') |
| 6922 | { |
| 6923 | if (post_op_name[2] == '*') |
| 6924 | op_kind = clang::OO_ArrowStar; break; |
| 6925 | } |
| 6926 | break; |
| 6927 | |
| 6928 | case '*': |
| 6929 | if (post_op_name[1] == '\0') |
| 6930 | op_kind = clang::OO_Star; |
| 6931 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6932 | op_kind = clang::OO_StarEqual; |
| 6933 | break; |
| 6934 | |
| 6935 | case '/': |
| 6936 | if (post_op_name[1] == '\0') |
| 6937 | op_kind = clang::OO_Slash; |
| 6938 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6939 | op_kind = clang::OO_SlashEqual; |
| 6940 | break; |
| 6941 | |
| 6942 | case '%': |
| 6943 | if (post_op_name[1] == '\0') |
| 6944 | op_kind = clang::OO_Percent; |
| 6945 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6946 | op_kind = clang::OO_PercentEqual; |
| 6947 | break; |
| 6948 | |
| 6949 | |
| 6950 | case '^': |
| 6951 | if (post_op_name[1] == '\0') |
| 6952 | op_kind = clang::OO_Caret; |
| 6953 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6954 | op_kind = clang::OO_CaretEqual; |
| 6955 | break; |
| 6956 | |
| 6957 | case '&': |
| 6958 | if (post_op_name[1] == '\0') |
| 6959 | op_kind = clang::OO_Amp; |
| 6960 | else if (post_op_name[2] == '\0') |
| 6961 | { |
| 6962 | switch (post_op_name[1]) |
| 6963 | { |
| 6964 | case '=': op_kind = clang::OO_AmpEqual; break; |
| 6965 | case '&': op_kind = clang::OO_AmpAmp; break; |
| 6966 | } |
| 6967 | } |
| 6968 | break; |
| 6969 | |
| 6970 | case '|': |
| 6971 | if (post_op_name[1] == '\0') |
| 6972 | op_kind = clang::OO_Pipe; |
| 6973 | else if (post_op_name[2] == '\0') |
| 6974 | { |
| 6975 | switch (post_op_name[1]) |
| 6976 | { |
| 6977 | case '=': op_kind = clang::OO_PipeEqual; break; |
| 6978 | case '|': op_kind = clang::OO_PipePipe; break; |
| 6979 | } |
| 6980 | } |
| 6981 | break; |
| 6982 | |
| 6983 | case '~': |
| 6984 | if (post_op_name[1] == '\0') |
| 6985 | op_kind = clang::OO_Tilde; |
| 6986 | break; |
| 6987 | |
| 6988 | case '!': |
| 6989 | if (post_op_name[1] == '\0') |
| 6990 | op_kind = clang::OO_Exclaim; |
| 6991 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6992 | op_kind = clang::OO_ExclaimEqual; |
| 6993 | break; |
| 6994 | |
| 6995 | case '=': |
| 6996 | if (post_op_name[1] == '\0') |
| 6997 | op_kind = clang::OO_Equal; |
| 6998 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6999 | op_kind = clang::OO_EqualEqual; |
| 7000 | break; |
| 7001 | |
| 7002 | case '<': |
| 7003 | if (post_op_name[1] == '\0') |
| 7004 | op_kind = clang::OO_Less; |
| 7005 | else if (post_op_name[2] == '\0') |
| 7006 | { |
| 7007 | switch (post_op_name[1]) |
| 7008 | { |
| 7009 | case '<': op_kind = clang::OO_LessLess; break; |
| 7010 | case '=': op_kind = clang::OO_LessEqual; break; |
| 7011 | } |
| 7012 | } |
| 7013 | else if (post_op_name[3] == '\0') |
| 7014 | { |
| 7015 | if (post_op_name[2] == '=') |
| 7016 | op_kind = clang::OO_LessLessEqual; |
| 7017 | } |
| 7018 | break; |
| 7019 | |
| 7020 | case '>': |
| 7021 | if (post_op_name[1] == '\0') |
| 7022 | op_kind = clang::OO_Greater; |
| 7023 | else if (post_op_name[2] == '\0') |
| 7024 | { |
| 7025 | switch (post_op_name[1]) |
| 7026 | { |
| 7027 | case '>': op_kind = clang::OO_GreaterGreater; break; |
| 7028 | case '=': op_kind = clang::OO_GreaterEqual; break; |
| 7029 | } |
| 7030 | } |
| 7031 | else if (post_op_name[1] == '>' && |
| 7032 | post_op_name[2] == '=' && |
| 7033 | post_op_name[3] == '\0') |
| 7034 | { |
| 7035 | op_kind = clang::OO_GreaterGreaterEqual; |
| 7036 | } |
| 7037 | break; |
| 7038 | |
| 7039 | case ',': |
| 7040 | if (post_op_name[1] == '\0') |
| 7041 | op_kind = clang::OO_Comma; |
| 7042 | break; |
| 7043 | |
| 7044 | case '(': |
| 7045 | if (post_op_name[1] == ')' && post_op_name[2] == '\0') |
| 7046 | op_kind = clang::OO_Call; |
| 7047 | break; |
| 7048 | |
| 7049 | case '[': |
| 7050 | if (post_op_name[1] == ']' && post_op_name[2] == '\0') |
| 7051 | op_kind = clang::OO_Subscript; |
| 7052 | break; |
| 7053 | } |
| 7054 | |
| 7055 | return true; |
| 7056 | } |
| 7057 | |
| 7058 | clang::EnumDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7059 | ClangASTContext::GetAsEnumDecl (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7060 | { |
| 7061 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)); |
| 7062 | if (enutype) |
| 7063 | return enutype->getDecl(); |
| 7064 | return NULL; |
| 7065 | } |
| 7066 | |
| 7067 | clang::RecordDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7068 | ClangASTContext::GetAsRecordDecl (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7069 | { |
| 7070 | const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(GetCanonicalQualType(type)); |
| 7071 | if (record_type) |
| 7072 | return record_type->getDecl(); |
| 7073 | return nullptr; |
| 7074 | } |
| 7075 | |
| 7076 | clang::CXXRecordDecl * |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7077 | ClangASTContext::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7078 | { |
| 7079 | return GetCanonicalQualType(type)->getAsCXXRecordDecl(); |
| 7080 | } |
| 7081 | |
| 7082 | clang::ObjCInterfaceDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7083 | ClangASTContext::GetAsObjCInterfaceDecl (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7084 | { |
| 7085 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(GetCanonicalQualType(type)); |
| 7086 | if (objc_class_type) |
| 7087 | return objc_class_type->getInterface(); |
| 7088 | return nullptr; |
| 7089 | } |
| 7090 | |
| 7091 | clang::FieldDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7092 | ClangASTContext::AddFieldToRecordType (const CompilerType& type, const char *name, |
| 7093 | const CompilerType &field_clang_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7094 | AccessType access, |
| 7095 | uint32_t bitfield_bit_size) |
| 7096 | { |
| 7097 | if (!type.IsValid() || !field_clang_type.IsValid()) |
| 7098 | return nullptr; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7099 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7100 | if (!ast) |
| 7101 | return nullptr; |
| 7102 | clang::ASTContext* clang_ast = ast->getASTContext(); |
| 7103 | |
| 7104 | clang::FieldDecl *field = nullptr; |
| 7105 | |
| 7106 | clang::Expr *bit_width = nullptr; |
| 7107 | if (bitfield_bit_size != 0) |
| 7108 | { |
| 7109 | llvm::APInt bitfield_bit_size_apint(clang_ast->getTypeSize(clang_ast->IntTy), bitfield_bit_size); |
| 7110 | bit_width = new (*clang_ast)clang::IntegerLiteral (*clang_ast, bitfield_bit_size_apint, clang_ast->IntTy, clang::SourceLocation()); |
| 7111 | } |
| 7112 | |
| 7113 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type); |
| 7114 | if (record_decl) |
| 7115 | { |
| 7116 | field = clang::FieldDecl::Create (*clang_ast, |
| 7117 | record_decl, |
| 7118 | clang::SourceLocation(), |
| 7119 | clang::SourceLocation(), |
| 7120 | name ? &clang_ast->Idents.get(name) : nullptr, // Identifier |
| 7121 | GetQualType(field_clang_type), // Field type |
| 7122 | nullptr, // TInfo * |
| 7123 | bit_width, // BitWidth |
| 7124 | false, // Mutable |
| 7125 | clang::ICIS_NoInit); // HasInit |
| 7126 | |
| 7127 | if (!name) |
| 7128 | { |
| 7129 | // Determine whether this field corresponds to an anonymous |
| 7130 | // struct or union. |
| 7131 | if (const clang::TagType *TagT = field->getType()->getAs<clang::TagType>()) { |
| 7132 | if (clang::RecordDecl *Rec = llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl())) |
| 7133 | if (!Rec->getDeclName()) { |
| 7134 | Rec->setAnonymousStructOrUnion(true); |
| 7135 | field->setImplicit(); |
| 7136 | |
| 7137 | } |
| 7138 | } |
| 7139 | } |
| 7140 | |
| 7141 | if (field) |
| 7142 | { |
| 7143 | field->setAccess (ClangASTContext::ConvertAccessTypeToAccessSpecifier (access)); |
| 7144 | |
| 7145 | record_decl->addDecl(field); |
| 7146 | |
| 7147 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7148 | VerifyDecl(field); |
| 7149 | #endif |
| 7150 | } |
| 7151 | } |
| 7152 | else |
| 7153 | { |
| 7154 | clang::ObjCInterfaceDecl *class_interface_decl = ast->GetAsObjCInterfaceDecl (type); |
| 7155 | |
| 7156 | if (class_interface_decl) |
| 7157 | { |
| 7158 | const bool is_synthesized = false; |
| 7159 | |
| 7160 | field_clang_type.GetCompleteType(); |
| 7161 | |
| 7162 | field = clang::ObjCIvarDecl::Create (*clang_ast, |
| 7163 | class_interface_decl, |
| 7164 | clang::SourceLocation(), |
| 7165 | clang::SourceLocation(), |
| 7166 | name ? &clang_ast->Idents.get(name) : nullptr, // Identifier |
| 7167 | GetQualType(field_clang_type), // Field type |
| 7168 | nullptr, // TypeSourceInfo * |
| 7169 | ConvertAccessTypeToObjCIvarAccessControl (access), |
| 7170 | bit_width, |
| 7171 | is_synthesized); |
| 7172 | |
| 7173 | if (field) |
| 7174 | { |
| 7175 | class_interface_decl->addDecl(field); |
| 7176 | |
| 7177 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7178 | VerifyDecl(field); |
| 7179 | #endif |
| 7180 | } |
| 7181 | } |
| 7182 | } |
| 7183 | return field; |
| 7184 | } |
| 7185 | |
| 7186 | void |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7187 | ClangASTContext::BuildIndirectFields (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7188 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7189 | if (!type) |
| 7190 | return; |
| 7191 | |
| 7192 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7193 | if (!ast) |
| 7194 | return; |
| 7195 | |
| 7196 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); |
| 7197 | |
| 7198 | if (!record_decl) |
| 7199 | return; |
| 7200 | |
| 7201 | typedef llvm::SmallVector <clang::IndirectFieldDecl *, 1> IndirectFieldVector; |
| 7202 | |
| 7203 | IndirectFieldVector indirect_fields; |
| 7204 | clang::RecordDecl::field_iterator field_pos; |
| 7205 | clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end(); |
| 7206 | clang::RecordDecl::field_iterator last_field_pos = field_end_pos; |
| 7207 | for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; last_field_pos = field_pos++) |
| 7208 | { |
| 7209 | if (field_pos->isAnonymousStructOrUnion()) |
| 7210 | { |
| 7211 | clang::QualType field_qual_type = field_pos->getType(); |
| 7212 | |
| 7213 | const clang::RecordType *field_record_type = field_qual_type->getAs<clang::RecordType>(); |
| 7214 | |
| 7215 | if (!field_record_type) |
| 7216 | continue; |
| 7217 | |
| 7218 | clang::RecordDecl *field_record_decl = field_record_type->getDecl(); |
| 7219 | |
| 7220 | if (!field_record_decl) |
| 7221 | continue; |
| 7222 | |
| 7223 | for (clang::RecordDecl::decl_iterator di = field_record_decl->decls_begin(), de = field_record_decl->decls_end(); |
| 7224 | di != de; |
| 7225 | ++di) |
| 7226 | { |
| 7227 | if (clang::FieldDecl *nested_field_decl = llvm::dyn_cast<clang::FieldDecl>(*di)) |
| 7228 | { |
| 7229 | clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[2]; |
| 7230 | chain[0] = *field_pos; |
| 7231 | chain[1] = nested_field_decl; |
| 7232 | clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(), |
| 7233 | record_decl, |
| 7234 | clang::SourceLocation(), |
| 7235 | nested_field_decl->getIdentifier(), |
| 7236 | nested_field_decl->getType(), |
| 7237 | chain, |
| 7238 | 2); |
| 7239 | |
| 7240 | indirect_field->setImplicit(); |
| 7241 | |
| 7242 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(), |
| 7243 | nested_field_decl->getAccess())); |
| 7244 | |
| 7245 | indirect_fields.push_back(indirect_field); |
| 7246 | } |
| 7247 | else if (clang::IndirectFieldDecl *nested_indirect_field_decl = llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) |
| 7248 | { |
| 7249 | int nested_chain_size = nested_indirect_field_decl->getChainingSize(); |
| 7250 | clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[nested_chain_size + 1]; |
| 7251 | chain[0] = *field_pos; |
| 7252 | |
| 7253 | int chain_index = 1; |
| 7254 | for (clang::IndirectFieldDecl::chain_iterator nci = nested_indirect_field_decl->chain_begin(), |
| 7255 | nce = nested_indirect_field_decl->chain_end(); |
| 7256 | nci < nce; |
| 7257 | ++nci) |
| 7258 | { |
| 7259 | chain[chain_index] = *nci; |
| 7260 | chain_index++; |
| 7261 | } |
| 7262 | |
| 7263 | clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(), |
| 7264 | record_decl, |
| 7265 | clang::SourceLocation(), |
| 7266 | nested_indirect_field_decl->getIdentifier(), |
| 7267 | nested_indirect_field_decl->getType(), |
| 7268 | chain, |
| 7269 | nested_chain_size + 1); |
| 7270 | |
| 7271 | indirect_field->setImplicit(); |
| 7272 | |
| 7273 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(), |
| 7274 | nested_indirect_field_decl->getAccess())); |
| 7275 | |
| 7276 | indirect_fields.push_back(indirect_field); |
| 7277 | } |
| 7278 | } |
| 7279 | } |
| 7280 | } |
| 7281 | |
| 7282 | // Check the last field to see if it has an incomplete array type as its |
| 7283 | // last member and if it does, the tell the record decl about it |
| 7284 | if (last_field_pos != field_end_pos) |
| 7285 | { |
| 7286 | if (last_field_pos->getType()->isIncompleteArrayType()) |
| 7287 | record_decl->hasFlexibleArrayMember(); |
| 7288 | } |
| 7289 | |
| 7290 | for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), ife = indirect_fields.end(); |
| 7291 | ifi < ife; |
| 7292 | ++ifi) |
| 7293 | { |
| 7294 | record_decl->addDecl(*ifi); |
| 7295 | } |
| 7296 | } |
| 7297 | |
| 7298 | void |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7299 | ClangASTContext::SetIsPacked (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7300 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7301 | if (type) |
| 7302 | { |
| 7303 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 7304 | if (ast) |
| 7305 | { |
| 7306 | clang::RecordDecl *record_decl = GetAsRecordDecl(type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7307 | |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7308 | if (!record_decl) |
| 7309 | return; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7310 | |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7311 | record_decl->addAttr(clang::PackedAttr::CreateImplicit(*ast->getASTContext())); |
| 7312 | } |
| 7313 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7314 | } |
| 7315 | |
| 7316 | clang::VarDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7317 | ClangASTContext::AddVariableToRecordType (const CompilerType& type, const char *name, |
| 7318 | const CompilerType &var_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7319 | AccessType access) |
| 7320 | { |
| 7321 | clang::VarDecl *var_decl = nullptr; |
| 7322 | |
| 7323 | if (!type.IsValid() || !var_type.IsValid()) |
| 7324 | return nullptr; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7325 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7326 | if (!ast) |
| 7327 | return nullptr; |
| 7328 | |
| 7329 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type); |
| 7330 | if (record_decl) |
| 7331 | { |
| 7332 | var_decl = clang::VarDecl::Create (*ast->getASTContext(), // ASTContext & |
| 7333 | record_decl, // DeclContext * |
| 7334 | clang::SourceLocation(), // clang::SourceLocation StartLoc |
| 7335 | clang::SourceLocation(), // clang::SourceLocation IdLoc |
| 7336 | name ? &ast->getASTContext()->Idents.get(name) : nullptr, // clang::IdentifierInfo * |
| 7337 | GetQualType(var_type), // Variable clang::QualType |
| 7338 | nullptr, // TypeSourceInfo * |
| 7339 | clang::SC_Static); // StorageClass |
| 7340 | if (var_decl) |
| 7341 | { |
| 7342 | var_decl->setAccess(ClangASTContext::ConvertAccessTypeToAccessSpecifier (access)); |
| 7343 | record_decl->addDecl(var_decl); |
| 7344 | |
| 7345 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7346 | VerifyDecl(var_decl); |
| 7347 | #endif |
| 7348 | } |
| 7349 | } |
| 7350 | return var_decl; |
| 7351 | } |
| 7352 | |
| 7353 | |
| 7354 | clang::CXXMethodDecl * |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7355 | ClangASTContext::AddMethodToCXXRecordType (lldb::opaque_compiler_type_t type, const char *name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7356 | const CompilerType &method_clang_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7357 | lldb::AccessType access, |
| 7358 | bool is_virtual, |
| 7359 | bool is_static, |
| 7360 | bool is_inline, |
| 7361 | bool is_explicit, |
| 7362 | bool is_attr_used, |
| 7363 | bool is_artificial) |
| 7364 | { |
| 7365 | if (!type || !method_clang_type.IsValid() || name == nullptr || name[0] == '\0') |
| 7366 | return nullptr; |
| 7367 | |
| 7368 | clang::QualType record_qual_type(GetCanonicalQualType(type)); |
| 7369 | |
| 7370 | clang::CXXRecordDecl *cxx_record_decl = record_qual_type->getAsCXXRecordDecl(); |
| 7371 | |
| 7372 | if (cxx_record_decl == nullptr) |
| 7373 | return nullptr; |
| 7374 | |
| 7375 | clang::QualType method_qual_type (GetQualType(method_clang_type)); |
| 7376 | |
| 7377 | clang::CXXMethodDecl *cxx_method_decl = nullptr; |
| 7378 | |
| 7379 | clang::DeclarationName decl_name (&getASTContext()->Idents.get(name)); |
| 7380 | |
| 7381 | const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr()); |
| 7382 | |
| 7383 | if (function_type == nullptr) |
| 7384 | return nullptr; |
| 7385 | |
| 7386 | const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(function_type)); |
| 7387 | |
| 7388 | if (!method_function_prototype) |
| 7389 | return nullptr; |
| 7390 | |
| 7391 | unsigned int num_params = method_function_prototype->getNumParams(); |
| 7392 | |
| 7393 | clang::CXXDestructorDecl *cxx_dtor_decl(nullptr); |
| 7394 | clang::CXXConstructorDecl *cxx_ctor_decl(nullptr); |
| 7395 | |
| 7396 | if (is_artificial) |
| 7397 | return nullptr; // skip everything artificial |
| 7398 | |
| 7399 | if (name[0] == '~') |
| 7400 | { |
| 7401 | cxx_dtor_decl = clang::CXXDestructorDecl::Create (*getASTContext(), |
| 7402 | cxx_record_decl, |
| 7403 | clang::SourceLocation(), |
| 7404 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXDestructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()), |
| 7405 | method_qual_type, |
| 7406 | nullptr, |
| 7407 | is_inline, |
| 7408 | is_artificial); |
| 7409 | cxx_method_decl = cxx_dtor_decl; |
| 7410 | } |
| 7411 | else if (decl_name == cxx_record_decl->getDeclName()) |
| 7412 | { |
| 7413 | cxx_ctor_decl = clang::CXXConstructorDecl::Create (*getASTContext(), |
| 7414 | cxx_record_decl, |
| 7415 | clang::SourceLocation(), |
| 7416 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConstructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()), |
| 7417 | method_qual_type, |
| 7418 | nullptr, // TypeSourceInfo * |
| 7419 | is_explicit, |
| 7420 | is_inline, |
| 7421 | is_artificial, |
| 7422 | false /*is_constexpr*/); |
| 7423 | cxx_method_decl = cxx_ctor_decl; |
| 7424 | } |
| 7425 | else |
| 7426 | { |
| 7427 | clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None; |
| 7428 | clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS; |
| 7429 | |
| 7430 | if (IsOperator (name, op_kind)) |
| 7431 | { |
| 7432 | if (op_kind != clang::NUM_OVERLOADED_OPERATORS) |
| 7433 | { |
| 7434 | // Check the number of operator parameters. Sometimes we have |
| 7435 | // seen bad DWARF that doesn't correctly describe operators and |
| 7436 | // if we try to create a method and add it to the class, clang |
| 7437 | // will assert and crash, so we need to make sure things are |
| 7438 | // acceptable. |
| 7439 | if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount (op_kind, num_params)) |
| 7440 | return nullptr; |
| 7441 | cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(), |
| 7442 | cxx_record_decl, |
| 7443 | clang::SourceLocation(), |
| 7444 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXOperatorName (op_kind), clang::SourceLocation()), |
| 7445 | method_qual_type, |
| 7446 | nullptr, // TypeSourceInfo * |
| 7447 | SC, |
| 7448 | is_inline, |
| 7449 | false /*is_constexpr*/, |
| 7450 | clang::SourceLocation()); |
| 7451 | } |
| 7452 | else if (num_params == 0) |
| 7453 | { |
| 7454 | // Conversion operators don't take params... |
| 7455 | cxx_method_decl = clang::CXXConversionDecl::Create (*getASTContext(), |
| 7456 | cxx_record_decl, |
| 7457 | clang::SourceLocation(), |
| 7458 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConversionFunctionName (getASTContext()->getCanonicalType (function_type->getReturnType())), clang::SourceLocation()), |
| 7459 | method_qual_type, |
| 7460 | nullptr, // TypeSourceInfo * |
| 7461 | is_inline, |
| 7462 | is_explicit, |
| 7463 | false /*is_constexpr*/, |
| 7464 | clang::SourceLocation()); |
| 7465 | } |
| 7466 | } |
| 7467 | |
| 7468 | if (cxx_method_decl == nullptr) |
| 7469 | { |
| 7470 | cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(), |
| 7471 | cxx_record_decl, |
| 7472 | clang::SourceLocation(), |
| 7473 | clang::DeclarationNameInfo (decl_name, clang::SourceLocation()), |
| 7474 | method_qual_type, |
| 7475 | nullptr, // TypeSourceInfo * |
| 7476 | SC, |
| 7477 | is_inline, |
| 7478 | false /*is_constexpr*/, |
| 7479 | clang::SourceLocation()); |
| 7480 | } |
| 7481 | } |
| 7482 | |
| 7483 | clang::AccessSpecifier access_specifier = ClangASTContext::ConvertAccessTypeToAccessSpecifier (access); |
| 7484 | |
| 7485 | cxx_method_decl->setAccess (access_specifier); |
| 7486 | cxx_method_decl->setVirtualAsWritten (is_virtual); |
| 7487 | |
| 7488 | if (is_attr_used) |
| 7489 | cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext())); |
| 7490 | |
| 7491 | // Populate the method decl with parameter decls |
| 7492 | |
| 7493 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; |
| 7494 | |
| 7495 | for (unsigned param_index = 0; |
| 7496 | param_index < num_params; |
| 7497 | ++param_index) |
| 7498 | { |
| 7499 | params.push_back (clang::ParmVarDecl::Create (*getASTContext(), |
| 7500 | cxx_method_decl, |
| 7501 | clang::SourceLocation(), |
| 7502 | clang::SourceLocation(), |
| 7503 | nullptr, // anonymous |
| 7504 | method_function_prototype->getParamType(param_index), |
| 7505 | nullptr, |
| 7506 | clang::SC_None, |
| 7507 | nullptr)); |
| 7508 | } |
| 7509 | |
| 7510 | cxx_method_decl->setParams (llvm::ArrayRef<clang::ParmVarDecl*>(params)); |
| 7511 | |
| 7512 | cxx_record_decl->addDecl (cxx_method_decl); |
| 7513 | |
| 7514 | // Sometimes the debug info will mention a constructor (default/copy/move), |
| 7515 | // destructor, or assignment operator (copy/move) but there won't be any |
| 7516 | // version of this in the code. So we check if the function was artificially |
| 7517 | // generated and if it is trivial and this lets the compiler/backend know |
| 7518 | // that it can inline the IR for these when it needs to and we can avoid a |
| 7519 | // "missing function" error when running expressions. |
| 7520 | |
| 7521 | if (is_artificial) |
| 7522 | { |
| 7523 | if (cxx_ctor_decl && |
| 7524 | ((cxx_ctor_decl->isDefaultConstructor() && cxx_record_decl->hasTrivialDefaultConstructor ()) || |
| 7525 | (cxx_ctor_decl->isCopyConstructor() && cxx_record_decl->hasTrivialCopyConstructor ()) || |
| 7526 | (cxx_ctor_decl->isMoveConstructor() && cxx_record_decl->hasTrivialMoveConstructor ()) )) |
| 7527 | { |
| 7528 | cxx_ctor_decl->setDefaulted(); |
| 7529 | cxx_ctor_decl->setTrivial(true); |
| 7530 | } |
| 7531 | else if (cxx_dtor_decl) |
| 7532 | { |
| 7533 | if (cxx_record_decl->hasTrivialDestructor()) |
| 7534 | { |
| 7535 | cxx_dtor_decl->setDefaulted(); |
| 7536 | cxx_dtor_decl->setTrivial(true); |
| 7537 | } |
| 7538 | } |
| 7539 | else if ((cxx_method_decl->isCopyAssignmentOperator() && cxx_record_decl->hasTrivialCopyAssignment()) || |
| 7540 | (cxx_method_decl->isMoveAssignmentOperator() && cxx_record_decl->hasTrivialMoveAssignment())) |
| 7541 | { |
| 7542 | cxx_method_decl->setDefaulted(); |
| 7543 | cxx_method_decl->setTrivial(true); |
| 7544 | } |
| 7545 | } |
| 7546 | |
| 7547 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7548 | VerifyDecl(cxx_method_decl); |
| 7549 | #endif |
| 7550 | |
| 7551 | // printf ("decl->isPolymorphic() = %i\n", cxx_record_decl->isPolymorphic()); |
| 7552 | // printf ("decl->isAggregate() = %i\n", cxx_record_decl->isAggregate()); |
| 7553 | // printf ("decl->isPOD() = %i\n", cxx_record_decl->isPOD()); |
| 7554 | // printf ("decl->isEmpty() = %i\n", cxx_record_decl->isEmpty()); |
| 7555 | // printf ("decl->isAbstract() = %i\n", cxx_record_decl->isAbstract()); |
| 7556 | // printf ("decl->hasTrivialConstructor() = %i\n", cxx_record_decl->hasTrivialConstructor()); |
| 7557 | // printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor()); |
| 7558 | // printf ("decl->hasTrivialCopyAssignment() = %i\n", cxx_record_decl->hasTrivialCopyAssignment()); |
| 7559 | // printf ("decl->hasTrivialDestructor() = %i\n", cxx_record_decl->hasTrivialDestructor()); |
| 7560 | return cxx_method_decl; |
| 7561 | } |
| 7562 | |
| 7563 | |
| 7564 | #pragma mark C++ Base Classes |
| 7565 | |
| 7566 | clang::CXXBaseSpecifier * |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7567 | ClangASTContext::CreateBaseClassSpecifier (lldb::opaque_compiler_type_t type, AccessType access, bool is_virtual, bool base_of_class) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7568 | { |
| 7569 | if (type) |
| 7570 | return new clang::CXXBaseSpecifier (clang::SourceRange(), |
| 7571 | is_virtual, |
| 7572 | base_of_class, |
| 7573 | ClangASTContext::ConvertAccessTypeToAccessSpecifier (access), |
| 7574 | getASTContext()->getTrivialTypeSourceInfo (GetQualType(type)), |
| 7575 | clang::SourceLocation()); |
| 7576 | return nullptr; |
| 7577 | } |
| 7578 | |
| 7579 | void |
| 7580 | ClangASTContext::DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, unsigned num_base_classes) |
| 7581 | { |
| 7582 | for (unsigned i=0; i<num_base_classes; ++i) |
| 7583 | { |
| 7584 | delete base_classes[i]; |
| 7585 | base_classes[i] = nullptr; |
| 7586 | } |
| 7587 | } |
| 7588 | |
| 7589 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7590 | ClangASTContext::SetBaseClassesForClassType (lldb::opaque_compiler_type_t type, clang::CXXBaseSpecifier const * const *base_classes, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7591 | unsigned num_base_classes) |
| 7592 | { |
| 7593 | if (type) |
| 7594 | { |
| 7595 | clang::CXXRecordDecl *cxx_record_decl = GetAsCXXRecordDecl(type); |
| 7596 | if (cxx_record_decl) |
| 7597 | { |
| 7598 | cxx_record_decl->setBases(base_classes, num_base_classes); |
| 7599 | return true; |
| 7600 | } |
| 7601 | } |
| 7602 | return false; |
| 7603 | } |
| 7604 | |
| 7605 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7606 | ClangASTContext::SetObjCSuperClass (const CompilerType& type, const CompilerType &superclass_clang_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7607 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7608 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7609 | if (!ast) |
| 7610 | return false; |
| 7611 | clang::ASTContext* clang_ast = ast->getASTContext(); |
| 7612 | |
| 7613 | if (type && superclass_clang_type.IsValid() && superclass_clang_type.GetTypeSystem() == type.GetTypeSystem()) |
| 7614 | { |
| 7615 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); |
| 7616 | clang::ObjCInterfaceDecl *super_interface_decl = GetAsObjCInterfaceDecl (superclass_clang_type); |
| 7617 | if (class_interface_decl && super_interface_decl) |
| 7618 | { |
| 7619 | class_interface_decl->setSuperClass(clang_ast->getTrivialTypeSourceInfo(clang_ast->getObjCInterfaceType(super_interface_decl))); |
| 7620 | return true; |
| 7621 | } |
| 7622 | } |
| 7623 | return false; |
| 7624 | } |
| 7625 | |
| 7626 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7627 | ClangASTContext::AddObjCClassProperty (const CompilerType& type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7628 | const char *property_name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7629 | const CompilerType &property_clang_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7630 | clang::ObjCIvarDecl *ivar_decl, |
| 7631 | const char *property_setter_name, |
| 7632 | const char *property_getter_name, |
| 7633 | uint32_t property_attributes, |
| 7634 | ClangASTMetadata *metadata) |
| 7635 | { |
| 7636 | if (!type || !property_clang_type.IsValid() || property_name == nullptr || property_name[0] == '\0') |
| 7637 | return false; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7638 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7639 | if (!ast) |
| 7640 | return false; |
| 7641 | clang::ASTContext* clang_ast = ast->getASTContext(); |
| 7642 | |
| 7643 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); |
| 7644 | |
| 7645 | if (class_interface_decl) |
| 7646 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7647 | CompilerType property_clang_type_to_access; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7648 | |
| 7649 | if (property_clang_type.IsValid()) |
| 7650 | property_clang_type_to_access = property_clang_type; |
| 7651 | else if (ivar_decl) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7652 | property_clang_type_to_access = CompilerType (clang_ast, ivar_decl->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7653 | |
| 7654 | if (class_interface_decl && property_clang_type_to_access.IsValid()) |
| 7655 | { |
| 7656 | clang::TypeSourceInfo *prop_type_source; |
| 7657 | if (ivar_decl) |
| 7658 | prop_type_source = clang_ast->getTrivialTypeSourceInfo (ivar_decl->getType()); |
| 7659 | else |
| 7660 | prop_type_source = clang_ast->getTrivialTypeSourceInfo (GetQualType(property_clang_type)); |
| 7661 | |
| 7662 | clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create (*clang_ast, |
| 7663 | class_interface_decl, |
| 7664 | clang::SourceLocation(), // Source Location |
| 7665 | &clang_ast->Idents.get(property_name), |
| 7666 | clang::SourceLocation(), //Source Location for AT |
| 7667 | clang::SourceLocation(), //Source location for ( |
| 7668 | ivar_decl ? ivar_decl->getType() : ClangASTContext::GetQualType(property_clang_type), |
| 7669 | prop_type_source); |
| 7670 | |
| 7671 | if (property_decl) |
| 7672 | { |
| 7673 | if (metadata) |
| 7674 | ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata); |
| 7675 | |
| 7676 | class_interface_decl->addDecl (property_decl); |
| 7677 | |
| 7678 | clang::Selector setter_sel, getter_sel; |
| 7679 | |
| 7680 | if (property_setter_name != nullptr) |
| 7681 | { |
| 7682 | std::string property_setter_no_colon(property_setter_name, strlen(property_setter_name) - 1); |
| 7683 | clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(property_setter_no_colon.c_str()); |
| 7684 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); |
| 7685 | } |
| 7686 | else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) |
| 7687 | { |
| 7688 | std::string setter_sel_string("set"); |
| 7689 | setter_sel_string.push_back(::toupper(property_name[0])); |
| 7690 | setter_sel_string.append(&property_name[1]); |
| 7691 | clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(setter_sel_string.c_str()); |
| 7692 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); |
| 7693 | } |
| 7694 | property_decl->setSetterName(setter_sel); |
| 7695 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter); |
| 7696 | |
| 7697 | if (property_getter_name != nullptr) |
| 7698 | { |
| 7699 | clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_getter_name); |
| 7700 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); |
| 7701 | } |
| 7702 | else |
| 7703 | { |
| 7704 | clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_name); |
| 7705 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); |
| 7706 | } |
| 7707 | property_decl->setGetterName(getter_sel); |
| 7708 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter); |
| 7709 | |
| 7710 | if (ivar_decl) |
| 7711 | property_decl->setPropertyIvarDecl (ivar_decl); |
| 7712 | |
| 7713 | if (property_attributes & DW_APPLE_PROPERTY_readonly) |
| 7714 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readonly); |
| 7715 | if (property_attributes & DW_APPLE_PROPERTY_readwrite) |
| 7716 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readwrite); |
| 7717 | if (property_attributes & DW_APPLE_PROPERTY_assign) |
| 7718 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_assign); |
| 7719 | if (property_attributes & DW_APPLE_PROPERTY_retain) |
| 7720 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_retain); |
| 7721 | if (property_attributes & DW_APPLE_PROPERTY_copy) |
| 7722 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_copy); |
| 7723 | if (property_attributes & DW_APPLE_PROPERTY_nonatomic) |
| 7724 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_nonatomic); |
| 7725 | |
| 7726 | if (!getter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(getter_sel)) |
| 7727 | { |
| 7728 | const bool isInstance = true; |
| 7729 | const bool isVariadic = false; |
| 7730 | const bool isSynthesized = false; |
| 7731 | const bool isImplicitlyDeclared = true; |
| 7732 | const bool isDefined = false; |
| 7733 | const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None; |
| 7734 | const bool HasRelatedResultType = false; |
| 7735 | |
| 7736 | clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create (*clang_ast, |
| 7737 | clang::SourceLocation(), |
| 7738 | clang::SourceLocation(), |
| 7739 | getter_sel, |
| 7740 | GetQualType(property_clang_type_to_access), |
| 7741 | nullptr, |
| 7742 | class_interface_decl, |
| 7743 | isInstance, |
| 7744 | isVariadic, |
| 7745 | isSynthesized, |
| 7746 | isImplicitlyDeclared, |
| 7747 | isDefined, |
| 7748 | impControl, |
| 7749 | HasRelatedResultType); |
| 7750 | |
| 7751 | if (getter && metadata) |
| 7752 | ClangASTContext::SetMetadata(clang_ast, getter, *metadata); |
| 7753 | |
| 7754 | if (getter) |
| 7755 | { |
| 7756 | getter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(), llvm::ArrayRef<clang::SourceLocation>()); |
| 7757 | |
| 7758 | class_interface_decl->addDecl(getter); |
| 7759 | } |
| 7760 | } |
| 7761 | |
| 7762 | if (!setter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(setter_sel)) |
| 7763 | { |
| 7764 | clang::QualType result_type = clang_ast->VoidTy; |
| 7765 | |
| 7766 | const bool isInstance = true; |
| 7767 | const bool isVariadic = false; |
| 7768 | const bool isSynthesized = false; |
| 7769 | const bool isImplicitlyDeclared = true; |
| 7770 | const bool isDefined = false; |
| 7771 | const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None; |
| 7772 | const bool HasRelatedResultType = false; |
| 7773 | |
| 7774 | clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create (*clang_ast, |
| 7775 | clang::SourceLocation(), |
| 7776 | clang::SourceLocation(), |
| 7777 | setter_sel, |
| 7778 | result_type, |
| 7779 | nullptr, |
| 7780 | class_interface_decl, |
| 7781 | isInstance, |
| 7782 | isVariadic, |
| 7783 | isSynthesized, |
| 7784 | isImplicitlyDeclared, |
| 7785 | isDefined, |
| 7786 | impControl, |
| 7787 | HasRelatedResultType); |
| 7788 | |
| 7789 | if (setter && metadata) |
| 7790 | ClangASTContext::SetMetadata(clang_ast, setter, *metadata); |
| 7791 | |
| 7792 | llvm::SmallVector<clang::ParmVarDecl *, 1> params; |
| 7793 | |
| 7794 | params.push_back (clang::ParmVarDecl::Create (*clang_ast, |
| 7795 | setter, |
| 7796 | clang::SourceLocation(), |
| 7797 | clang::SourceLocation(), |
| 7798 | nullptr, // anonymous |
| 7799 | GetQualType(property_clang_type_to_access), |
| 7800 | nullptr, |
| 7801 | clang::SC_Auto, |
| 7802 | nullptr)); |
| 7803 | |
| 7804 | if (setter) |
| 7805 | { |
| 7806 | setter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>()); |
| 7807 | |
| 7808 | class_interface_decl->addDecl(setter); |
| 7809 | } |
| 7810 | } |
| 7811 | |
| 7812 | return true; |
| 7813 | } |
| 7814 | } |
| 7815 | } |
| 7816 | return false; |
| 7817 | } |
| 7818 | |
| 7819 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7820 | ClangASTContext::IsObjCClassTypeAndHasIVars (const CompilerType& type, bool check_superclass) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7821 | { |
| 7822 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); |
| 7823 | if (class_interface_decl) |
| 7824 | return ObjCDeclHasIVars (class_interface_decl, check_superclass); |
| 7825 | return false; |
| 7826 | } |
| 7827 | |
| 7828 | |
| 7829 | clang::ObjCMethodDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7830 | ClangASTContext::AddMethodToObjCObjectType (const CompilerType& type, |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7831 | const char *name, // the full symbol name as seen in the symbol table (lldb::opaque_compiler_type_t type, "-[NString stringWithCString:]") |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7832 | const CompilerType &method_clang_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7833 | lldb::AccessType access, |
| 7834 | bool is_artificial) |
| 7835 | { |
| 7836 | if (!type || !method_clang_type.IsValid()) |
| 7837 | return nullptr; |
| 7838 | |
| 7839 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); |
| 7840 | |
| 7841 | if (class_interface_decl == nullptr) |
| 7842 | return nullptr; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7843 | ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 7844 | if (lldb_ast == nullptr) |
| 7845 | return nullptr; |
| 7846 | clang::ASTContext *ast = lldb_ast->getASTContext(); |
| 7847 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7848 | const char *selector_start = ::strchr (name, ' '); |
| 7849 | if (selector_start == nullptr) |
| 7850 | return nullptr; |
| 7851 | |
| 7852 | selector_start++; |
| 7853 | llvm::SmallVector<clang::IdentifierInfo *, 12> selector_idents; |
| 7854 | |
| 7855 | size_t len = 0; |
| 7856 | const char *start; |
| 7857 | //printf ("name = '%s'\n", name); |
| 7858 | |
| 7859 | unsigned num_selectors_with_args = 0; |
| 7860 | for (start = selector_start; |
| 7861 | start && *start != '\0' && *start != ']'; |
| 7862 | start += len) |
| 7863 | { |
| 7864 | len = ::strcspn(start, ":]"); |
| 7865 | bool has_arg = (start[len] == ':'); |
| 7866 | if (has_arg) |
| 7867 | ++num_selectors_with_args; |
| 7868 | selector_idents.push_back (&ast->Idents.get (llvm::StringRef (start, len))); |
| 7869 | if (has_arg) |
| 7870 | len += 1; |
| 7871 | } |
| 7872 | |
| 7873 | |
| 7874 | if (selector_idents.size() == 0) |
| 7875 | return nullptr; |
| 7876 | |
| 7877 | clang::Selector method_selector = ast->Selectors.getSelector (num_selectors_with_args ? selector_idents.size() : 0, |
| 7878 | selector_idents.data()); |
| 7879 | |
| 7880 | clang::QualType method_qual_type (GetQualType(method_clang_type)); |
| 7881 | |
| 7882 | // Populate the method decl with parameter decls |
| 7883 | const clang::Type *method_type(method_qual_type.getTypePtr()); |
| 7884 | |
| 7885 | if (method_type == nullptr) |
| 7886 | return nullptr; |
| 7887 | |
| 7888 | const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(method_type)); |
| 7889 | |
| 7890 | if (!method_function_prototype) |
| 7891 | return nullptr; |
| 7892 | |
| 7893 | |
| 7894 | bool is_variadic = false; |
| 7895 | bool is_synthesized = false; |
| 7896 | bool is_defined = false; |
| 7897 | clang::ObjCMethodDecl::ImplementationControl imp_control = clang::ObjCMethodDecl::None; |
| 7898 | |
| 7899 | const unsigned num_args = method_function_prototype->getNumParams(); |
| 7900 | |
| 7901 | if (num_args != num_selectors_with_args) |
| 7902 | return nullptr; // some debug information is corrupt. We are not going to deal with it. |
| 7903 | |
| 7904 | clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create (*ast, |
| 7905 | clang::SourceLocation(), // beginLoc, |
| 7906 | clang::SourceLocation(), // endLoc, |
| 7907 | method_selector, |
| 7908 | method_function_prototype->getReturnType(), |
| 7909 | nullptr, // TypeSourceInfo *ResultTInfo, |
| 7910 | ClangASTContext::GetASTContext(ast)->GetDeclContextForType(GetQualType(type)), |
| 7911 | name[0] == '-', |
| 7912 | is_variadic, |
| 7913 | is_synthesized, |
| 7914 | true, // is_implicitly_declared; we force this to true because we don't have source locations |
| 7915 | is_defined, |
| 7916 | imp_control, |
| 7917 | false /*has_related_result_type*/); |
| 7918 | |
| 7919 | |
| 7920 | if (objc_method_decl == nullptr) |
| 7921 | return nullptr; |
| 7922 | |
| 7923 | if (num_args > 0) |
| 7924 | { |
| 7925 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; |
| 7926 | |
| 7927 | for (unsigned param_index = 0; param_index < num_args; ++param_index) |
| 7928 | { |
| 7929 | params.push_back (clang::ParmVarDecl::Create (*ast, |
| 7930 | objc_method_decl, |
| 7931 | clang::SourceLocation(), |
| 7932 | clang::SourceLocation(), |
| 7933 | nullptr, // anonymous |
| 7934 | method_function_prototype->getParamType(param_index), |
| 7935 | nullptr, |
| 7936 | clang::SC_Auto, |
| 7937 | nullptr)); |
| 7938 | } |
| 7939 | |
| 7940 | objc_method_decl->setMethodParams(*ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>()); |
| 7941 | } |
| 7942 | |
| 7943 | class_interface_decl->addDecl (objc_method_decl); |
| 7944 | |
| 7945 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7946 | VerifyDecl(objc_method_decl); |
| 7947 | #endif |
| 7948 | |
| 7949 | return objc_method_decl; |
| 7950 | } |
| 7951 | |
| 7952 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7953 | ClangASTContext::SetHasExternalStorage (lldb::opaque_compiler_type_t type, bool has_extern) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7954 | { |
| 7955 | if (!type) |
| 7956 | return false; |
| 7957 | |
| 7958 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 7959 | |
| 7960 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7961 | switch (type_class) |
| 7962 | { |
| 7963 | case clang::Type::Record: |
| 7964 | { |
| 7965 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 7966 | if (cxx_record_decl) |
| 7967 | { |
| 7968 | cxx_record_decl->setHasExternalLexicalStorage (has_extern); |
| 7969 | cxx_record_decl->setHasExternalVisibleStorage (has_extern); |
| 7970 | return true; |
| 7971 | } |
| 7972 | } |
| 7973 | break; |
| 7974 | |
| 7975 | case clang::Type::Enum: |
| 7976 | { |
| 7977 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 7978 | if (enum_decl) |
| 7979 | { |
| 7980 | enum_decl->setHasExternalLexicalStorage (has_extern); |
| 7981 | enum_decl->setHasExternalVisibleStorage (has_extern); |
| 7982 | return true; |
| 7983 | } |
| 7984 | } |
| 7985 | break; |
| 7986 | |
| 7987 | case clang::Type::ObjCObject: |
| 7988 | case clang::Type::ObjCInterface: |
| 7989 | { |
| 7990 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 7991 | assert (objc_class_type); |
| 7992 | if (objc_class_type) |
| 7993 | { |
| 7994 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 7995 | |
| 7996 | if (class_interface_decl) |
| 7997 | { |
| 7998 | class_interface_decl->setHasExternalLexicalStorage (has_extern); |
| 7999 | class_interface_decl->setHasExternalVisibleStorage (has_extern); |
| 8000 | return true; |
| 8001 | } |
| 8002 | } |
| 8003 | } |
| 8004 | break; |
| 8005 | |
| 8006 | case clang::Type::Typedef: |
| 8007 | return SetHasExternalStorage(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), has_extern); |
| 8008 | |
| 8009 | case clang::Type::Elaborated: |
| 8010 | return SetHasExternalStorage (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), has_extern); |
| 8011 | |
| 8012 | case clang::Type::Paren: |
| 8013 | return SetHasExternalStorage (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), has_extern); |
| 8014 | |
| 8015 | default: |
| 8016 | break; |
| 8017 | } |
| 8018 | return false; |
| 8019 | } |
| 8020 | |
| 8021 | |
| 8022 | #pragma mark TagDecl |
| 8023 | |
| 8024 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8025 | ClangASTContext::StartTagDeclarationDefinition (const CompilerType &type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8026 | { |
| 8027 | if (type) |
| 8028 | { |
| 8029 | |
| 8030 | clang::QualType qual_type (GetQualType(type)); |
| 8031 | const clang::Type *t = qual_type.getTypePtr(); |
| 8032 | if (t) |
| 8033 | { |
| 8034 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(t); |
| 8035 | if (tag_type) |
| 8036 | { |
| 8037 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8038 | if (tag_decl) |
| 8039 | { |
| 8040 | tag_decl->startDefinition(); |
| 8041 | return true; |
| 8042 | } |
| 8043 | } |
| 8044 | |
| 8045 | const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(t); |
| 8046 | if (object_type) |
| 8047 | { |
| 8048 | clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface(); |
| 8049 | if (interface_decl) |
| 8050 | { |
| 8051 | interface_decl->startDefinition(); |
| 8052 | return true; |
| 8053 | } |
| 8054 | } |
| 8055 | } |
| 8056 | } |
| 8057 | return false; |
| 8058 | } |
| 8059 | |
| 8060 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8061 | ClangASTContext::CompleteTagDeclarationDefinition (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8062 | { |
| 8063 | if (type) |
| 8064 | { |
| 8065 | clang::QualType qual_type (GetQualType(type)); |
| 8066 | if (qual_type.isNull()) |
| 8067 | return false; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8068 | ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8069 | if (lldb_ast == nullptr) |
| 8070 | return false; |
| 8071 | clang::ASTContext *ast = lldb_ast->getASTContext(); |
| 8072 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8073 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 8074 | |
| 8075 | if (cxx_record_decl) |
| 8076 | { |
| 8077 | cxx_record_decl->completeDefinition(); |
| 8078 | |
| 8079 | return true; |
| 8080 | } |
| 8081 | |
| 8082 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(qual_type.getTypePtr()); |
| 8083 | |
| 8084 | if (enutype) |
| 8085 | { |
| 8086 | clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8087 | |
| 8088 | if (enum_decl) |
| 8089 | { |
| 8090 | /// TODO This really needs to be fixed. |
| 8091 | |
| 8092 | unsigned NumPositiveBits = 1; |
| 8093 | unsigned NumNegativeBits = 0; |
| 8094 | |
| 8095 | clang::QualType promotion_qual_type; |
| 8096 | // If the enum integer type is less than an integer in bit width, |
| 8097 | // then we must promote it to an integer size. |
| 8098 | if (ast->getTypeSize(enum_decl->getIntegerType()) < ast->getTypeSize(ast->IntTy)) |
| 8099 | { |
| 8100 | if (enum_decl->getIntegerType()->isSignedIntegerType()) |
| 8101 | promotion_qual_type = ast->IntTy; |
| 8102 | else |
| 8103 | promotion_qual_type = ast->UnsignedIntTy; |
| 8104 | } |
| 8105 | else |
| 8106 | promotion_qual_type = enum_decl->getIntegerType(); |
| 8107 | |
| 8108 | enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits); |
| 8109 | return true; |
| 8110 | } |
| 8111 | } |
| 8112 | } |
| 8113 | return false; |
| 8114 | } |
| 8115 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8116 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8117 | ClangASTContext::AddEnumerationValueToEnumerationType (lldb::opaque_compiler_type_t type, |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8118 | const CompilerType &enumerator_clang_type, |
| 8119 | const Declaration &decl, |
| 8120 | const char *name, |
| 8121 | int64_t enum_value, |
| 8122 | uint32_t enum_value_bit_size) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8123 | { |
| 8124 | if (type && enumerator_clang_type.IsValid() && name && name[0]) |
| 8125 | { |
| 8126 | clang::QualType enum_qual_type (GetCanonicalQualType(type)); |
| 8127 | |
| 8128 | bool is_signed = false; |
| 8129 | enumerator_clang_type.IsIntegerType (is_signed); |
| 8130 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
| 8131 | if (clang_type) |
| 8132 | { |
| 8133 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type); |
| 8134 | |
| 8135 | if (enutype) |
| 8136 | { |
| 8137 | llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed); |
| 8138 | enum_llvm_apsint = enum_value; |
| 8139 | clang::EnumConstantDecl *enumerator_decl = |
| 8140 | clang::EnumConstantDecl::Create (*getASTContext(), |
| 8141 | enutype->getDecl(), |
| 8142 | clang::SourceLocation(), |
| 8143 | name ? &getASTContext()->Idents.get(name) : nullptr, // Identifier |
| 8144 | GetQualType(enumerator_clang_type), |
| 8145 | nullptr, |
| 8146 | enum_llvm_apsint); |
| 8147 | |
| 8148 | if (enumerator_decl) |
| 8149 | { |
| 8150 | enutype->getDecl()->addDecl(enumerator_decl); |
| 8151 | |
| 8152 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 8153 | VerifyDecl(enumerator_decl); |
| 8154 | #endif |
| 8155 | |
| 8156 | return true; |
| 8157 | } |
| 8158 | } |
| 8159 | } |
| 8160 | } |
| 8161 | return false; |
| 8162 | } |
| 8163 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8164 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8165 | ClangASTContext::GetEnumerationIntegerType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8166 | { |
| 8167 | clang::QualType enum_qual_type (GetCanonicalQualType(type)); |
| 8168 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
| 8169 | if (clang_type) |
| 8170 | { |
| 8171 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type); |
| 8172 | if (enutype) |
| 8173 | { |
| 8174 | clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8175 | if (enum_decl) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8176 | return CompilerType (getASTContext(), enum_decl->getIntegerType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8177 | } |
| 8178 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8179 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8180 | } |
| 8181 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8182 | CompilerType |
| 8183 | ClangASTContext::CreateMemberPointerType (const CompilerType& type, const CompilerType &pointee_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8184 | { |
| 8185 | if (type && pointee_type.IsValid() && type.GetTypeSystem() == pointee_type.GetTypeSystem()) |
| 8186 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8187 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8188 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8189 | return CompilerType(); |
| 8190 | return CompilerType (ast->getASTContext(), |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8191 | ast->getASTContext()->getMemberPointerType (GetQualType(pointee_type), |
| 8192 | GetQualType(type).getTypePtr())); |
| 8193 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8194 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8195 | } |
| 8196 | |
| 8197 | |
| 8198 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8199 | ClangASTContext::ConvertStringToFloatValue (lldb::opaque_compiler_type_t type, const char *s, uint8_t *dst, size_t dst_size) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8200 | { |
| 8201 | if (type) |
| 8202 | { |
| 8203 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 8204 | uint32_t count = 0; |
| 8205 | bool is_complex = false; |
| 8206 | if (IsFloatingPointType (type, count, is_complex)) |
| 8207 | { |
| 8208 | // TODO: handle complex and vector types |
| 8209 | if (count != 1) |
| 8210 | return false; |
| 8211 | |
| 8212 | llvm::StringRef s_sref(s); |
| 8213 | llvm::APFloat ap_float(getASTContext()->getFloatTypeSemantics(qual_type), s_sref); |
| 8214 | |
| 8215 | const uint64_t bit_size = getASTContext()->getTypeSize (qual_type); |
| 8216 | const uint64_t byte_size = bit_size / 8; |
| 8217 | if (dst_size >= byte_size) |
| 8218 | { |
| 8219 | if (bit_size == sizeof(float)*8) |
| 8220 | { |
| 8221 | float float32 = ap_float.convertToFloat(); |
| 8222 | ::memcpy (dst, &float32, byte_size); |
| 8223 | return byte_size; |
| 8224 | } |
| 8225 | else if (bit_size >= 64) |
| 8226 | { |
| 8227 | llvm::APInt ap_int(ap_float.bitcastToAPInt()); |
| 8228 | ::memcpy (dst, ap_int.getRawData(), byte_size); |
| 8229 | return byte_size; |
| 8230 | } |
| 8231 | } |
| 8232 | } |
| 8233 | } |
| 8234 | return 0; |
| 8235 | } |
| 8236 | |
| 8237 | |
| 8238 | |
| 8239 | //---------------------------------------------------------------------- |
| 8240 | // Dumping types |
| 8241 | //---------------------------------------------------------------------- |
| 8242 | #define DEPTH_INCREMENT 2 |
| 8243 | |
| 8244 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8245 | ClangASTContext::DumpValue (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8246 | Stream *s, |
| 8247 | lldb::Format format, |
| 8248 | const lldb_private::DataExtractor &data, |
| 8249 | lldb::offset_t data_byte_offset, |
| 8250 | size_t data_byte_size, |
| 8251 | uint32_t bitfield_bit_size, |
| 8252 | uint32_t bitfield_bit_offset, |
| 8253 | bool show_types, |
| 8254 | bool show_summary, |
| 8255 | bool verbose, |
| 8256 | uint32_t depth) |
| 8257 | { |
| 8258 | if (!type) |
| 8259 | return; |
| 8260 | |
| 8261 | clang::QualType qual_type(GetQualType(type)); |
| 8262 | switch (qual_type->getTypeClass()) |
| 8263 | { |
| 8264 | case clang::Type::Record: |
| 8265 | if (GetCompleteType(type)) |
| 8266 | { |
| 8267 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 8268 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 8269 | assert(record_decl); |
| 8270 | uint32_t field_bit_offset = 0; |
| 8271 | uint32_t field_byte_offset = 0; |
| 8272 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); |
| 8273 | uint32_t child_idx = 0; |
| 8274 | |
| 8275 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 8276 | if (cxx_record_decl) |
| 8277 | { |
| 8278 | // We might have base classes to print out first |
| 8279 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 8280 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 8281 | base_class != base_class_end; |
| 8282 | ++base_class) |
| 8283 | { |
| 8284 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 8285 | |
| 8286 | // Skip empty base classes |
| 8287 | if (verbose == false && ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 8288 | continue; |
| 8289 | |
| 8290 | if (base_class->isVirtual()) |
| 8291 | field_bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 8292 | else |
| 8293 | field_bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 8294 | field_byte_offset = field_bit_offset / 8; |
| 8295 | assert (field_bit_offset % 8 == 0); |
| 8296 | if (child_idx == 0) |
| 8297 | s->PutChar('{'); |
| 8298 | else |
| 8299 | s->PutChar(','); |
| 8300 | |
| 8301 | clang::QualType base_class_qual_type = base_class->getType(); |
| 8302 | std::string base_class_type_name(base_class_qual_type.getAsString()); |
| 8303 | |
| 8304 | // Indent and print the base class type name |
| 8305 | s->Printf("\n%*s%s ", depth + DEPTH_INCREMENT, "", base_class_type_name.c_str()); |
| 8306 | |
| 8307 | clang::TypeInfo base_class_type_info = getASTContext()->getTypeInfo(base_class_qual_type); |
| 8308 | |
| 8309 | // Dump the value of the member |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8310 | CompilerType base_clang_type(getASTContext(), base_class_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8311 | base_clang_type.DumpValue (exe_ctx, |
| 8312 | s, // Stream to dump to |
| 8313 | base_clang_type.GetFormat(), // The format with which to display the member |
| 8314 | data, // Data buffer containing all bytes for this type |
| 8315 | data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from |
| 8316 | base_class_type_info.Width / 8, // Size of this type in bytes |
| 8317 | 0, // Bitfield bit size |
| 8318 | 0, // Bitfield bit offset |
| 8319 | show_types, // Boolean indicating if we should show the variable types |
| 8320 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8321 | verbose, // Verbose output? |
| 8322 | depth + DEPTH_INCREMENT); // Scope depth for any types that have children |
| 8323 | |
| 8324 | ++child_idx; |
| 8325 | } |
| 8326 | } |
| 8327 | uint32_t field_idx = 0; |
| 8328 | clang::RecordDecl::field_iterator field, field_end; |
| 8329 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx) |
| 8330 | { |
| 8331 | // Print the starting squiggly bracket (if this is the |
| 8332 | // first member) or comma (for member 2 and beyond) for |
| 8333 | // the struct/union/class member. |
| 8334 | if (child_idx == 0) |
| 8335 | s->PutChar('{'); |
| 8336 | else |
| 8337 | s->PutChar(','); |
| 8338 | |
| 8339 | // Indent |
| 8340 | s->Printf("\n%*s", depth + DEPTH_INCREMENT, ""); |
| 8341 | |
| 8342 | clang::QualType field_type = field->getType(); |
| 8343 | // Print the member type if requested |
| 8344 | // Figure out the type byte size (field_type_info.first) and |
| 8345 | // alignment (field_type_info.second) from the AST context. |
| 8346 | clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(field_type); |
| 8347 | assert(field_idx < record_layout.getFieldCount()); |
| 8348 | // Figure out the field offset within the current struct/union/class type |
| 8349 | field_bit_offset = record_layout.getFieldOffset (field_idx); |
| 8350 | field_byte_offset = field_bit_offset / 8; |
| 8351 | uint32_t field_bitfield_bit_size = 0; |
| 8352 | uint32_t field_bitfield_bit_offset = 0; |
| 8353 | if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, field_bitfield_bit_size)) |
| 8354 | field_bitfield_bit_offset = field_bit_offset % 8; |
| 8355 | |
| 8356 | if (show_types) |
| 8357 | { |
| 8358 | std::string field_type_name(field_type.getAsString()); |
| 8359 | if (field_bitfield_bit_size > 0) |
| 8360 | s->Printf("(%s:%u) ", field_type_name.c_str(), field_bitfield_bit_size); |
| 8361 | else |
| 8362 | s->Printf("(%s) ", field_type_name.c_str()); |
| 8363 | } |
| 8364 | // Print the member name and equal sign |
| 8365 | s->Printf("%s = ", field->getNameAsString().c_str()); |
| 8366 | |
| 8367 | |
| 8368 | // Dump the value of the member |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8369 | CompilerType field_clang_type (getASTContext(), field_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8370 | field_clang_type.DumpValue (exe_ctx, |
| 8371 | s, // Stream to dump to |
| 8372 | field_clang_type.GetFormat(), // The format with which to display the member |
| 8373 | data, // Data buffer containing all bytes for this type |
| 8374 | data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from |
| 8375 | field_type_info.Width / 8, // Size of this type in bytes |
| 8376 | field_bitfield_bit_size, // Bitfield bit size |
| 8377 | field_bitfield_bit_offset, // Bitfield bit offset |
| 8378 | show_types, // Boolean indicating if we should show the variable types |
| 8379 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8380 | verbose, // Verbose output? |
| 8381 | depth + DEPTH_INCREMENT); // Scope depth for any types that have children |
| 8382 | } |
| 8383 | |
| 8384 | // Indent the trailing squiggly bracket |
| 8385 | if (child_idx > 0) |
| 8386 | s->Printf("\n%*s}", depth, ""); |
| 8387 | } |
| 8388 | return; |
| 8389 | |
| 8390 | case clang::Type::Enum: |
| 8391 | if (GetCompleteType(type)) |
| 8392 | { |
| 8393 | const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr()); |
| 8394 | const clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8395 | assert(enum_decl); |
| 8396 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 8397 | lldb::offset_t offset = data_byte_offset; |
| 8398 | const int64_t enum_value = data.GetMaxU64Bitfield(&offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 8399 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) |
| 8400 | { |
| 8401 | if (enum_pos->getInitVal() == enum_value) |
| 8402 | { |
| 8403 | s->Printf("%s", enum_pos->getNameAsString().c_str()); |
| 8404 | return; |
| 8405 | } |
| 8406 | } |
| 8407 | // If we have gotten here we didn't get find the enumerator in the |
| 8408 | // enum decl, so just print the integer. |
| 8409 | s->Printf("%" PRIi64, enum_value); |
| 8410 | } |
| 8411 | return; |
| 8412 | |
| 8413 | case clang::Type::ConstantArray: |
| 8414 | { |
| 8415 | const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr()); |
| 8416 | bool is_array_of_characters = false; |
| 8417 | clang::QualType element_qual_type = array->getElementType(); |
| 8418 | |
| 8419 | const clang::Type *canonical_type = element_qual_type->getCanonicalTypeInternal().getTypePtr(); |
| 8420 | if (canonical_type) |
| 8421 | is_array_of_characters = canonical_type->isCharType(); |
| 8422 | |
| 8423 | const uint64_t element_count = array->getSize().getLimitedValue(); |
| 8424 | |
| 8425 | clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(element_qual_type); |
| 8426 | |
| 8427 | uint32_t element_idx = 0; |
| 8428 | uint32_t element_offset = 0; |
| 8429 | uint64_t element_byte_size = field_type_info.Width / 8; |
| 8430 | uint32_t element_stride = element_byte_size; |
| 8431 | |
| 8432 | if (is_array_of_characters) |
| 8433 | { |
| 8434 | s->PutChar('"'); |
| 8435 | data.Dump(s, data_byte_offset, lldb::eFormatChar, element_byte_size, element_count, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); |
| 8436 | s->PutChar('"'); |
| 8437 | return; |
| 8438 | } |
| 8439 | else |
| 8440 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8441 | CompilerType element_clang_type(getASTContext(), element_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8442 | lldb::Format element_format = element_clang_type.GetFormat(); |
| 8443 | |
| 8444 | for (element_idx = 0; element_idx < element_count; ++element_idx) |
| 8445 | { |
| 8446 | // Print the starting squiggly bracket (if this is the |
| 8447 | // first member) or comman (for member 2 and beyong) for |
| 8448 | // the struct/union/class member. |
| 8449 | if (element_idx == 0) |
| 8450 | s->PutChar('{'); |
| 8451 | else |
| 8452 | s->PutChar(','); |
| 8453 | |
| 8454 | // Indent and print the index |
| 8455 | s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx); |
| 8456 | |
| 8457 | // Figure out the field offset within the current struct/union/class type |
| 8458 | element_offset = element_idx * element_stride; |
| 8459 | |
| 8460 | // Dump the value of the member |
| 8461 | element_clang_type.DumpValue (exe_ctx, |
| 8462 | s, // Stream to dump to |
| 8463 | element_format, // The format with which to display the element |
| 8464 | data, // Data buffer containing all bytes for this type |
| 8465 | data_byte_offset + element_offset,// Offset into "data" where to grab value from |
| 8466 | element_byte_size, // Size of this type in bytes |
| 8467 | 0, // Bitfield bit size |
| 8468 | 0, // Bitfield bit offset |
| 8469 | show_types, // Boolean indicating if we should show the variable types |
| 8470 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8471 | verbose, // Verbose output? |
| 8472 | depth + DEPTH_INCREMENT); // Scope depth for any types that have children |
| 8473 | } |
| 8474 | |
| 8475 | // Indent the trailing squiggly bracket |
| 8476 | if (element_idx > 0) |
| 8477 | s->Printf("\n%*s}", depth, ""); |
| 8478 | } |
| 8479 | } |
| 8480 | return; |
| 8481 | |
| 8482 | case clang::Type::Typedef: |
| 8483 | { |
| 8484 | clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(); |
| 8485 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8486 | CompilerType typedef_clang_type (getASTContext(), typedef_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8487 | lldb::Format typedef_format = typedef_clang_type.GetFormat(); |
| 8488 | clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type); |
| 8489 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; |
| 8490 | |
| 8491 | return typedef_clang_type.DumpValue (exe_ctx, |
| 8492 | s, // Stream to dump to |
| 8493 | typedef_format, // The format with which to display the element |
| 8494 | data, // Data buffer containing all bytes for this type |
| 8495 | data_byte_offset, // Offset into "data" where to grab value from |
| 8496 | typedef_byte_size, // Size of this type in bytes |
| 8497 | bitfield_bit_size, // Bitfield bit size |
| 8498 | bitfield_bit_offset,// Bitfield bit offset |
| 8499 | show_types, // Boolean indicating if we should show the variable types |
| 8500 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8501 | verbose, // Verbose output? |
| 8502 | depth); // Scope depth for any types that have children |
| 8503 | } |
| 8504 | break; |
| 8505 | |
| 8506 | case clang::Type::Elaborated: |
| 8507 | { |
| 8508 | clang::QualType elaborated_qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8509 | CompilerType elaborated_clang_type (getASTContext(), elaborated_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8510 | lldb::Format elaborated_format = elaborated_clang_type.GetFormat(); |
| 8511 | clang::TypeInfo elaborated_type_info = getASTContext()->getTypeInfo(elaborated_qual_type); |
| 8512 | uint64_t elaborated_byte_size = elaborated_type_info.Width / 8; |
| 8513 | |
| 8514 | return elaborated_clang_type.DumpValue (exe_ctx, |
| 8515 | s, // Stream to dump to |
| 8516 | elaborated_format, // The format with which to display the element |
| 8517 | data, // Data buffer containing all bytes for this type |
| 8518 | data_byte_offset, // Offset into "data" where to grab value from |
| 8519 | elaborated_byte_size, // Size of this type in bytes |
| 8520 | bitfield_bit_size, // Bitfield bit size |
| 8521 | bitfield_bit_offset,// Bitfield bit offset |
| 8522 | show_types, // Boolean indicating if we should show the variable types |
| 8523 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8524 | verbose, // Verbose output? |
| 8525 | depth); // Scope depth for any types that have children |
| 8526 | } |
| 8527 | break; |
| 8528 | |
| 8529 | case clang::Type::Paren: |
| 8530 | { |
| 8531 | clang::QualType desugar_qual_type = llvm::cast<clang::ParenType>(qual_type)->desugar(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8532 | CompilerType desugar_clang_type (getASTContext(), desugar_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8533 | |
| 8534 | lldb::Format desugar_format = desugar_clang_type.GetFormat(); |
| 8535 | clang::TypeInfo desugar_type_info = getASTContext()->getTypeInfo(desugar_qual_type); |
| 8536 | uint64_t desugar_byte_size = desugar_type_info.Width / 8; |
| 8537 | |
| 8538 | return desugar_clang_type.DumpValue (exe_ctx, |
| 8539 | s, // Stream to dump to |
| 8540 | desugar_format, // The format with which to display the element |
| 8541 | data, // Data buffer containing all bytes for this type |
| 8542 | data_byte_offset, // Offset into "data" where to grab value from |
| 8543 | desugar_byte_size, // Size of this type in bytes |
| 8544 | bitfield_bit_size, // Bitfield bit size |
| 8545 | bitfield_bit_offset,// Bitfield bit offset |
| 8546 | show_types, // Boolean indicating if we should show the variable types |
| 8547 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8548 | verbose, // Verbose output? |
| 8549 | depth); // Scope depth for any types that have children |
| 8550 | } |
| 8551 | break; |
| 8552 | |
| 8553 | default: |
| 8554 | // We are down to a scalar type that we just need to display. |
| 8555 | data.Dump(s, |
| 8556 | data_byte_offset, |
| 8557 | format, |
| 8558 | data_byte_size, |
| 8559 | 1, |
| 8560 | UINT32_MAX, |
| 8561 | LLDB_INVALID_ADDRESS, |
| 8562 | bitfield_bit_size, |
| 8563 | bitfield_bit_offset); |
| 8564 | |
| 8565 | if (show_summary) |
| 8566 | DumpSummary (type, exe_ctx, s, data, data_byte_offset, data_byte_size); |
| 8567 | break; |
| 8568 | } |
| 8569 | } |
| 8570 | |
| 8571 | |
| 8572 | |
| 8573 | |
| 8574 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8575 | ClangASTContext::DumpTypeValue (lldb::opaque_compiler_type_t type, Stream *s, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8576 | lldb::Format format, |
| 8577 | const lldb_private::DataExtractor &data, |
| 8578 | lldb::offset_t byte_offset, |
| 8579 | size_t byte_size, |
| 8580 | uint32_t bitfield_bit_size, |
| 8581 | uint32_t bitfield_bit_offset, |
| 8582 | ExecutionContextScope *exe_scope) |
| 8583 | { |
| 8584 | if (!type) |
| 8585 | return false; |
| 8586 | if (IsAggregateType(type)) |
| 8587 | { |
| 8588 | return false; |
| 8589 | } |
| 8590 | else |
| 8591 | { |
| 8592 | clang::QualType qual_type(GetQualType(type)); |
| 8593 | |
| 8594 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 8595 | switch (type_class) |
| 8596 | { |
| 8597 | case clang::Type::Typedef: |
| 8598 | { |
| 8599 | clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8600 | CompilerType typedef_clang_type (getASTContext(), typedef_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8601 | if (format == eFormatDefault) |
| 8602 | format = typedef_clang_type.GetFormat(); |
| 8603 | clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type); |
| 8604 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; |
| 8605 | |
| 8606 | return typedef_clang_type.DumpTypeValue (s, |
| 8607 | format, // The format with which to display the element |
| 8608 | data, // Data buffer containing all bytes for this type |
| 8609 | byte_offset, // Offset into "data" where to grab value from |
| 8610 | typedef_byte_size, // Size of this type in bytes |
| 8611 | bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield |
| 8612 | bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0 |
| 8613 | exe_scope); |
| 8614 | } |
| 8615 | break; |
| 8616 | |
| 8617 | case clang::Type::Enum: |
| 8618 | // If our format is enum or default, show the enumeration value as |
| 8619 | // its enumeration string value, else just display it as requested. |
| 8620 | if ((format == eFormatEnum || format == eFormatDefault) && GetCompleteType(type)) |
| 8621 | { |
| 8622 | const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr()); |
| 8623 | const clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8624 | assert(enum_decl); |
| 8625 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 8626 | const bool is_signed = qual_type->isSignedIntegerOrEnumerationType(); |
| 8627 | lldb::offset_t offset = byte_offset; |
| 8628 | if (is_signed) |
| 8629 | { |
| 8630 | const int64_t enum_svalue = data.GetMaxS64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 8631 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) |
| 8632 | { |
| 8633 | if (enum_pos->getInitVal().getSExtValue() == enum_svalue) |
| 8634 | { |
| 8635 | s->PutCString (enum_pos->getNameAsString().c_str()); |
| 8636 | return true; |
| 8637 | } |
| 8638 | } |
| 8639 | // If we have gotten here we didn't get find the enumerator in the |
| 8640 | // enum decl, so just print the integer. |
| 8641 | s->Printf("%" PRIi64, enum_svalue); |
| 8642 | } |
| 8643 | else |
| 8644 | { |
| 8645 | const uint64_t enum_uvalue = data.GetMaxU64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 8646 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) |
| 8647 | { |
| 8648 | if (enum_pos->getInitVal().getZExtValue() == enum_uvalue) |
| 8649 | { |
| 8650 | s->PutCString (enum_pos->getNameAsString().c_str()); |
| 8651 | return true; |
| 8652 | } |
| 8653 | } |
| 8654 | // If we have gotten here we didn't get find the enumerator in the |
| 8655 | // enum decl, so just print the integer. |
| 8656 | s->Printf("%" PRIu64, enum_uvalue); |
| 8657 | } |
| 8658 | return true; |
| 8659 | } |
| 8660 | // format was not enum, just fall through and dump the value as requested.... |
| 8661 | |
| 8662 | default: |
| 8663 | // We are down to a scalar type that we just need to display. |
| 8664 | { |
| 8665 | uint32_t item_count = 1; |
| 8666 | // A few formats, we might need to modify our size and count for depending |
| 8667 | // on how we are trying to display the value... |
| 8668 | switch (format) |
| 8669 | { |
| 8670 | default: |
| 8671 | case eFormatBoolean: |
| 8672 | case eFormatBinary: |
| 8673 | case eFormatComplex: |
| 8674 | case eFormatCString: // NULL terminated C strings |
| 8675 | case eFormatDecimal: |
| 8676 | case eFormatEnum: |
| 8677 | case eFormatHex: |
| 8678 | case eFormatHexUppercase: |
| 8679 | case eFormatFloat: |
| 8680 | case eFormatOctal: |
| 8681 | case eFormatOSType: |
| 8682 | case eFormatUnsigned: |
| 8683 | case eFormatPointer: |
| 8684 | case eFormatVectorOfChar: |
| 8685 | case eFormatVectorOfSInt8: |
| 8686 | case eFormatVectorOfUInt8: |
| 8687 | case eFormatVectorOfSInt16: |
| 8688 | case eFormatVectorOfUInt16: |
| 8689 | case eFormatVectorOfSInt32: |
| 8690 | case eFormatVectorOfUInt32: |
| 8691 | case eFormatVectorOfSInt64: |
| 8692 | case eFormatVectorOfUInt64: |
| 8693 | case eFormatVectorOfFloat32: |
| 8694 | case eFormatVectorOfFloat64: |
| 8695 | case eFormatVectorOfUInt128: |
| 8696 | break; |
| 8697 | |
| 8698 | case eFormatChar: |
| 8699 | case eFormatCharPrintable: |
| 8700 | case eFormatCharArray: |
| 8701 | case eFormatBytes: |
| 8702 | case eFormatBytesWithASCII: |
| 8703 | item_count = byte_size; |
| 8704 | byte_size = 1; |
| 8705 | break; |
| 8706 | |
| 8707 | case eFormatUnicode16: |
| 8708 | item_count = byte_size / 2; |
| 8709 | byte_size = 2; |
| 8710 | break; |
| 8711 | |
| 8712 | case eFormatUnicode32: |
| 8713 | item_count = byte_size / 4; |
| 8714 | byte_size = 4; |
| 8715 | break; |
| 8716 | } |
| 8717 | return data.Dump (s, |
| 8718 | byte_offset, |
| 8719 | format, |
| 8720 | byte_size, |
| 8721 | item_count, |
| 8722 | UINT32_MAX, |
| 8723 | LLDB_INVALID_ADDRESS, |
| 8724 | bitfield_bit_size, |
| 8725 | bitfield_bit_offset, |
| 8726 | exe_scope); |
| 8727 | } |
| 8728 | break; |
| 8729 | } |
| 8730 | } |
| 8731 | return 0; |
| 8732 | } |
| 8733 | |
| 8734 | |
| 8735 | |
| 8736 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8737 | ClangASTContext::DumpSummary (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8738 | Stream *s, |
| 8739 | const lldb_private::DataExtractor &data, |
| 8740 | lldb::offset_t data_byte_offset, |
| 8741 | size_t data_byte_size) |
| 8742 | { |
| 8743 | uint32_t length = 0; |
| 8744 | if (IsCStringType (type, length)) |
| 8745 | { |
| 8746 | if (exe_ctx) |
| 8747 | { |
| 8748 | Process *process = exe_ctx->GetProcessPtr(); |
| 8749 | if (process) |
| 8750 | { |
| 8751 | lldb::offset_t offset = data_byte_offset; |
| 8752 | lldb::addr_t pointer_address = data.GetMaxU64(&offset, data_byte_size); |
| 8753 | std::vector<uint8_t> buf; |
| 8754 | if (length > 0) |
| 8755 | buf.resize (length); |
| 8756 | else |
| 8757 | buf.resize (256); |
| 8758 | |
| 8759 | lldb_private::DataExtractor cstr_data(&buf.front(), buf.size(), process->GetByteOrder(), 4); |
| 8760 | buf.back() = '\0'; |
| 8761 | size_t bytes_read; |
| 8762 | size_t total_cstr_len = 0; |
| 8763 | Error error; |
| 8764 | while ((bytes_read = process->ReadMemory (pointer_address, &buf.front(), buf.size(), error)) > 0) |
| 8765 | { |
| 8766 | const size_t len = strlen((const char *)&buf.front()); |
| 8767 | if (len == 0) |
| 8768 | break; |
| 8769 | if (total_cstr_len == 0) |
| 8770 | s->PutCString (" \""); |
| 8771 | cstr_data.Dump(s, 0, lldb::eFormatChar, 1, len, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); |
| 8772 | total_cstr_len += len; |
| 8773 | if (len < buf.size()) |
| 8774 | break; |
| 8775 | pointer_address += total_cstr_len; |
| 8776 | } |
| 8777 | if (total_cstr_len > 0) |
| 8778 | s->PutChar ('"'); |
| 8779 | } |
| 8780 | } |
| 8781 | } |
| 8782 | } |
| 8783 | |
| 8784 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8785 | ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8786 | { |
| 8787 | StreamFile s (stdout, false); |
| 8788 | DumpTypeDescription (&s); |
| 8789 | ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), type); |
| 8790 | if (metadata) |
| 8791 | { |
| 8792 | metadata->Dump (&s); |
| 8793 | } |
| 8794 | } |
| 8795 | |
| 8796 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8797 | ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type, Stream *s) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8798 | { |
| 8799 | if (type) |
| 8800 | { |
| 8801 | clang::QualType qual_type(GetQualType(type)); |
| 8802 | |
| 8803 | llvm::SmallVector<char, 1024> buf; |
| 8804 | llvm::raw_svector_ostream llvm_ostrm (buf); |
| 8805 | |
| 8806 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 8807 | switch (type_class) |
| 8808 | { |
| 8809 | case clang::Type::ObjCObject: |
| 8810 | case clang::Type::ObjCInterface: |
| 8811 | { |
| 8812 | GetCompleteType(type); |
| 8813 | |
| 8814 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 8815 | assert (objc_class_type); |
| 8816 | if (objc_class_type) |
| 8817 | { |
| 8818 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 8819 | if (class_interface_decl) |
| 8820 | { |
| 8821 | clang::PrintingPolicy policy = getASTContext()->getPrintingPolicy(); |
| 8822 | class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel()); |
| 8823 | } |
| 8824 | } |
| 8825 | } |
| 8826 | break; |
| 8827 | |
| 8828 | case clang::Type::Typedef: |
| 8829 | { |
| 8830 | const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>(); |
| 8831 | if (typedef_type) |
| 8832 | { |
| 8833 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 8834 | std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString()); |
| 8835 | if (!clang_typedef_name.empty()) |
| 8836 | { |
| 8837 | s->PutCString ("typedef "); |
| 8838 | s->PutCString (clang_typedef_name.c_str()); |
| 8839 | } |
| 8840 | } |
| 8841 | } |
| 8842 | break; |
| 8843 | |
| 8844 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8845 | CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).DumpTypeDescription(s); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8846 | return; |
| 8847 | |
| 8848 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8849 | CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).DumpTypeDescription(s); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8850 | return; |
| 8851 | |
| 8852 | case clang::Type::Record: |
| 8853 | { |
| 8854 | GetCompleteType(type); |
| 8855 | |
| 8856 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 8857 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 8858 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 8859 | |
| 8860 | if (cxx_record_decl) |
| 8861 | cxx_record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel()); |
| 8862 | else |
| 8863 | record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel()); |
| 8864 | } |
| 8865 | break; |
| 8866 | |
| 8867 | default: |
| 8868 | { |
| 8869 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 8870 | if (tag_type) |
| 8871 | { |
| 8872 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8873 | if (tag_decl) |
| 8874 | tag_decl->print(llvm_ostrm, 0); |
| 8875 | } |
| 8876 | else |
| 8877 | { |
| 8878 | std::string clang_type_name(qual_type.getAsString()); |
| 8879 | if (!clang_type_name.empty()) |
| 8880 | s->PutCString (clang_type_name.c_str()); |
| 8881 | } |
| 8882 | } |
| 8883 | } |
| 8884 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8885 | if (buf.size() > 0) |
| 8886 | { |
| 8887 | s->Write (buf.data(), buf.size()); |
| 8888 | } |
| 8889 | } |
| 8890 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8891 | |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8892 | clang::ClassTemplateDecl * |
Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 8893 | ClangASTContext::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8894 | lldb::AccessType access_type, |
| 8895 | const char *parent_name, |
| 8896 | int tag_decl_kind, |
| 8897 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 8898 | { |
| 8899 | if (template_param_infos.IsValid()) |
| 8900 | { |
| 8901 | std::string template_basename(parent_name); |
| 8902 | template_basename.erase (template_basename.find('<')); |
| 8903 | |
| 8904 | return CreateClassTemplateDecl (decl_ctx, |
| 8905 | access_type, |
| 8906 | template_basename.c_str(), |
| 8907 | tag_decl_kind, |
| 8908 | template_param_infos); |
| 8909 | } |
| 8910 | return NULL; |
| 8911 | } |
| 8912 | |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 8913 | void |
| 8914 | ClangASTContext::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 8915 | { |
| 8916 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 8917 | SymbolFile *sym_file = ast->GetSymbolFile(); |
| 8918 | if (sym_file) |
| 8919 | { |
| 8920 | CompilerType clang_type = GetTypeForDecl (decl); |
| 8921 | if (clang_type) |
| 8922 | sym_file->CompleteType (clang_type); |
| 8923 | } |
| 8924 | } |
| 8925 | |
| 8926 | void |
| 8927 | ClangASTContext::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 8928 | { |
| 8929 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 8930 | SymbolFile *sym_file = ast->GetSymbolFile(); |
| 8931 | if (sym_file) |
| 8932 | { |
| 8933 | CompilerType clang_type = GetTypeForDecl (decl); |
| 8934 | if (clang_type) |
| 8935 | sym_file->CompleteType (clang_type); |
| 8936 | } |
| 8937 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8938 | |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 8939 | |
| 8940 | DWARFASTParser * |
| 8941 | ClangASTContext::GetDWARFParser () |
| 8942 | { |
| 8943 | if (!m_dwarf_ast_parser_ap) |
| 8944 | m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this)); |
| 8945 | return m_dwarf_ast_parser_ap.get(); |
| 8946 | } |
| 8947 | |
| 8948 | |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8949 | bool |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 8950 | ClangASTContext::LayoutRecordType(void *baton, |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8951 | const clang::RecordDecl *record_decl, |
| 8952 | uint64_t &bit_size, |
| 8953 | uint64_t &alignment, |
| 8954 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
| 8955 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 8956 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 8957 | { |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 8958 | ClangASTContext *ast = (ClangASTContext *)baton; |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 8959 | DWARFASTParserClang *dwarf_ast_parser = (DWARFASTParserClang *)ast->GetDWARFParser(); |
| 8960 | return dwarf_ast_parser->LayoutRecordType(record_decl, bit_size, alignment, field_offsets, base_offsets, vbase_offsets); |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8961 | } |
| 8962 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 8963 | //---------------------------------------------------------------------- |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 8964 | // CompilerDecl override functions |
| 8965 | //---------------------------------------------------------------------- |
| 8966 | lldb::VariableSP |
| 8967 | ClangASTContext::DeclGetVariable (void *opaque_decl) |
| 8968 | { |
| 8969 | if (llvm::dyn_cast<clang::VarDecl>((clang::Decl *)opaque_decl)) |
| 8970 | { |
| 8971 | auto decl_search_it = m_decl_objects.find(opaque_decl); |
| 8972 | if (decl_search_it != m_decl_objects.end()) |
| 8973 | return std::static_pointer_cast<Variable>(decl_search_it->second); |
| 8974 | } |
| 8975 | return VariableSP(); |
| 8976 | } |
| 8977 | |
| 8978 | void |
| 8979 | ClangASTContext::DeclLinkToObject (void *opaque_decl, std::shared_ptr<void> object) |
| 8980 | { |
| 8981 | if (m_decl_objects.find(opaque_decl) == m_decl_objects.end()) |
| 8982 | m_decl_objects.insert(std::make_pair(opaque_decl, object)); |
| 8983 | } |
| 8984 | |
| 8985 | ConstString |
| 8986 | ClangASTContext::DeclGetName (void *opaque_decl) |
| 8987 | { |
| 8988 | if (opaque_decl) |
| 8989 | { |
| 8990 | clang::NamedDecl *nd = llvm::dyn_cast<NamedDecl>((clang::Decl*)opaque_decl); |
| 8991 | if (nd != nullptr) |
| 8992 | return ConstString(nd->getName()); |
| 8993 | } |
| 8994 | return ConstString(); |
| 8995 | } |
| 8996 | |
| 8997 | //---------------------------------------------------------------------- |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 8998 | // CompilerDeclContext functions |
| 8999 | //---------------------------------------------------------------------- |
| 9000 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9001 | std::vector<void *> |
| 9002 | ClangASTContext::DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name) |
| 9003 | { |
| 9004 | std::vector<void *> found_decls; |
| 9005 | if (opaque_decl_ctx) |
| 9006 | { |
| 9007 | DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx; |
| 9008 | std::set<DeclContext *> searched; |
| 9009 | std::multimap<DeclContext *, DeclContext *> search_queue; |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9010 | SymbolFile *symbol_file = GetSymbolFile(); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9011 | |
| 9012 | for (clang::DeclContext *decl_context = root_decl_ctx; decl_context != nullptr && found_decls.empty(); decl_context = decl_context->getParent()) |
| 9013 | { |
| 9014 | search_queue.insert(std::make_pair(decl_context, decl_context)); |
| 9015 | |
| 9016 | for (auto it = search_queue.find(decl_context); it != search_queue.end(); it++) |
| 9017 | { |
| 9018 | searched.insert(it->second); |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9019 | symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second)); |
| 9020 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9021 | for (clang::Decl *child : it->second->decls()) |
| 9022 | { |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9023 | if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9024 | { |
| 9025 | clang::DeclContext *from = ud->getCommonAncestor(); |
| 9026 | if (searched.find(ud->getNominatedNamespace()) == searched.end()) |
| 9027 | search_queue.insert(std::make_pair(from, ud->getNominatedNamespace())); |
| 9028 | } |
| 9029 | else if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child)) |
| 9030 | { |
| 9031 | for (clang::UsingShadowDecl *usd : ud->shadows()) |
| 9032 | { |
| 9033 | clang::Decl *target = usd->getTargetDecl(); |
| 9034 | if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target)) |
| 9035 | { |
| 9036 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9037 | if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) |
| 9038 | found_decls.push_back(nd); |
| 9039 | } |
| 9040 | } |
| 9041 | } |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9042 | else if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(child)) |
| 9043 | { |
| 9044 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9045 | if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) |
| 9046 | found_decls.push_back(nd); |
| 9047 | } |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9048 | } |
| 9049 | } |
| 9050 | } |
| 9051 | } |
| 9052 | return found_decls; |
| 9053 | } |
| 9054 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9055 | bool |
| 9056 | ClangASTContext::DeclContextIsStructUnionOrClass (void *opaque_decl_ctx) |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9057 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9058 | if (opaque_decl_ctx) |
| 9059 | return ((clang::DeclContext *)opaque_decl_ctx)->isRecord(); |
| 9060 | else |
| 9061 | return false; |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9062 | } |
| 9063 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9064 | ConstString |
| 9065 | ClangASTContext::DeclContextGetName (void *opaque_decl_ctx) |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9066 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9067 | if (opaque_decl_ctx) |
| 9068 | { |
| 9069 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); |
| 9070 | if (named_decl) |
| 9071 | return ConstString(named_decl->getName()); |
| 9072 | } |
| 9073 | return ConstString(); |
| 9074 | } |
| 9075 | |
| 9076 | bool |
| 9077 | ClangASTContext::DeclContextIsClassMethod (void *opaque_decl_ctx, |
| 9078 | lldb::LanguageType *language_ptr, |
| 9079 | bool *is_instance_method_ptr, |
| 9080 | ConstString *language_object_name_ptr) |
| 9081 | { |
| 9082 | if (opaque_decl_ctx) |
| 9083 | { |
| 9084 | clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx; |
| 9085 | if (ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx)) |
| 9086 | { |
| 9087 | if (is_instance_method_ptr) |
| 9088 | *is_instance_method_ptr = objc_method->isInstanceMethod(); |
| 9089 | if (language_ptr) |
| 9090 | *language_ptr = eLanguageTypeObjC; |
| 9091 | if (language_object_name_ptr) |
| 9092 | language_object_name_ptr->SetCString("self"); |
| 9093 | return true; |
| 9094 | } |
| 9095 | else if (CXXMethodDecl *cxx_method = llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx)) |
| 9096 | { |
| 9097 | if (is_instance_method_ptr) |
| 9098 | *is_instance_method_ptr = cxx_method->isInstance(); |
| 9099 | if (language_ptr) |
| 9100 | *language_ptr = eLanguageTypeC_plus_plus; |
| 9101 | if (language_object_name_ptr) |
| 9102 | language_object_name_ptr->SetCString("this"); |
| 9103 | return true; |
| 9104 | } |
| 9105 | else if (clang::FunctionDecl *function_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) |
| 9106 | { |
| 9107 | ClangASTMetadata *metadata = GetMetadata (&decl_ctx->getParentASTContext(), function_decl); |
| 9108 | if (metadata && metadata->HasObjectPtr()) |
| 9109 | { |
| 9110 | if (is_instance_method_ptr) |
| 9111 | *is_instance_method_ptr = true; |
| 9112 | if (language_ptr) |
| 9113 | *language_ptr = eLanguageTypeObjC; |
| 9114 | if (language_object_name_ptr) |
| 9115 | language_object_name_ptr->SetCString (metadata->GetObjectPtrName()); |
| 9116 | return true; |
| 9117 | } |
| 9118 | } |
| 9119 | } |
| 9120 | return false; |
| 9121 | } |
| 9122 | |
| 9123 | clang::DeclContext * |
| 9124 | ClangASTContext::DeclContextGetAsDeclContext (const CompilerDeclContext &dc) |
| 9125 | { |
| 9126 | if (dc.IsClang()) |
| 9127 | return (clang::DeclContext *)dc.GetOpaqueDeclContext(); |
| 9128 | return nullptr; |
| 9129 | } |
| 9130 | |
| 9131 | |
| 9132 | ObjCMethodDecl * |
| 9133 | ClangASTContext::DeclContextGetAsObjCMethodDecl (const CompilerDeclContext &dc) |
| 9134 | { |
| 9135 | if (dc.IsClang()) |
| 9136 | return llvm::dyn_cast<clang::ObjCMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 9137 | return nullptr; |
| 9138 | } |
| 9139 | |
| 9140 | CXXMethodDecl * |
| 9141 | ClangASTContext::DeclContextGetAsCXXMethodDecl (const CompilerDeclContext &dc) |
| 9142 | { |
| 9143 | if (dc.IsClang()) |
| 9144 | return llvm::dyn_cast<clang::CXXMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 9145 | return nullptr; |
| 9146 | } |
| 9147 | |
| 9148 | clang::FunctionDecl * |
| 9149 | ClangASTContext::DeclContextGetAsFunctionDecl (const CompilerDeclContext &dc) |
| 9150 | { |
| 9151 | if (dc.IsClang()) |
| 9152 | return llvm::dyn_cast<clang::FunctionDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 9153 | return nullptr; |
| 9154 | } |
| 9155 | |
| 9156 | clang::NamespaceDecl * |
| 9157 | ClangASTContext::DeclContextGetAsNamespaceDecl (const CompilerDeclContext &dc) |
| 9158 | { |
| 9159 | if (dc.IsClang()) |
| 9160 | return llvm::dyn_cast<clang::NamespaceDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 9161 | return nullptr; |
| 9162 | } |
| 9163 | |
| 9164 | ClangASTMetadata * |
| 9165 | ClangASTContext::DeclContextGetMetaData (const CompilerDeclContext &dc, const void *object) |
| 9166 | { |
| 9167 | clang::ASTContext *ast = DeclContextGetClangASTContext (dc); |
| 9168 | if (ast) |
| 9169 | return ClangASTContext::GetMetadata (ast, object); |
| 9170 | return nullptr; |
| 9171 | } |
| 9172 | |
| 9173 | clang::ASTContext * |
| 9174 | ClangASTContext::DeclContextGetClangASTContext (const CompilerDeclContext &dc) |
| 9175 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 9176 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(dc.GetTypeSystem()); |
| 9177 | if (ast) |
| 9178 | return ast->getASTContext(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9179 | return nullptr; |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9180 | } |
| 9181 | |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 9182 | ClangASTContextForExpressions::ClangASTContextForExpressions (Target &target) : |
| 9183 | ClangASTContext (target.GetArchitecture().GetTriple().getTriple().c_str()), |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 9184 | m_target_wp(target.shared_from_this()), |
| 9185 | m_persistent_variables (new ClangPersistentVariables) |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 9186 | { |
| 9187 | } |
| 9188 | |
| 9189 | UserExpression * |
| 9190 | ClangASTContextForExpressions::GetUserExpression (const char *expr, |
| 9191 | const char *expr_prefix, |
| 9192 | lldb::LanguageType language, |
| 9193 | Expression::ResultType desired_type) |
| 9194 | { |
| 9195 | TargetSP target_sp = m_target_wp.lock(); |
| 9196 | if (!target_sp) |
| 9197 | return nullptr; |
| 9198 | |
| 9199 | return new ClangUserExpression(*target_sp.get(), expr, expr_prefix, language, desired_type); |
| 9200 | } |
| 9201 | |
| 9202 | FunctionCaller * |
| 9203 | ClangASTContextForExpressions::GetFunctionCaller (const CompilerType &return_type, |
| 9204 | const Address& function_address, |
| 9205 | const ValueList &arg_value_list, |
| 9206 | const char *name) |
| 9207 | { |
| 9208 | TargetSP target_sp = m_target_wp.lock(); |
| 9209 | if (!target_sp) |
| 9210 | return nullptr; |
| 9211 | |
| 9212 | Process *process = target_sp->GetProcessSP().get(); |
| 9213 | if (!process) |
| 9214 | return nullptr; |
| 9215 | |
| 9216 | return new ClangFunctionCaller (*process, return_type, function_address, arg_value_list, name); |
| 9217 | } |
| 9218 | |
| 9219 | UtilityFunction * |
| 9220 | ClangASTContextForExpressions::GetUtilityFunction (const char *text, |
| 9221 | const char *name) |
| 9222 | { |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 9223 | TargetSP target_sp = m_target_wp.lock(); |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 9224 | if (!target_sp) |
| 9225 | return nullptr; |
| 9226 | |
| 9227 | return new ClangUtilityFunction(*target_sp.get(), text, name); |
| 9228 | } |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 9229 | |
| 9230 | PersistentExpressionState * |
| 9231 | ClangASTContextForExpressions::GetPersistentExpressionState () |
| 9232 | { |
| 9233 | return m_persistent_variables.get(); |
| 9234 | } |