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 |
| 370 | ClangASTContext::CreateInstance (lldb::LanguageType language, const lldb_private::ArchSpec &arch) |
| 371 | { |
| 372 | if (ClangASTContextSupportsLanguage(language)) |
| 373 | { |
| 374 | std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext); |
| 375 | if (ast_sp) |
| 376 | { |
| 377 | if (arch.IsValid()) |
| 378 | { |
| 379 | ArchSpec fixed_arch = arch; |
| 380 | // LLVM wants this to be set to iOS or MacOSX; if we're working on |
| 381 | // a bare-boards type image, change the triple for llvm's benefit. |
| 382 | if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple && |
| 383 | fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) |
| 384 | { |
| 385 | if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm || |
| 386 | fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 || |
| 387 | fixed_arch.GetTriple().getArch() == llvm::Triple::thumb) |
| 388 | { |
| 389 | fixed_arch.GetTriple().setOS(llvm::Triple::IOS); |
| 390 | } |
| 391 | else |
| 392 | { |
| 393 | fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX); |
| 394 | } |
| 395 | } |
| 396 | ast_sp->SetArchitecture (fixed_arch); |
| 397 | } |
| 398 | } |
| 399 | return ast_sp; |
| 400 | } |
| 401 | return lldb::TypeSystemSP(); |
| 402 | } |
| 403 | |
| 404 | |
| 405 | void |
| 406 | ClangASTContext::Initialize() |
| 407 | { |
| 408 | PluginManager::RegisterPlugin (GetPluginNameStatic(), |
| 409 | "clang base AST context plug-in", |
| 410 | CreateInstance); |
| 411 | } |
| 412 | |
| 413 | void |
| 414 | ClangASTContext::Terminate() |
| 415 | { |
| 416 | PluginManager::UnregisterPlugin (CreateInstance); |
| 417 | } |
| 418 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 419 | |
| 420 | void |
| 421 | ClangASTContext::Clear() |
| 422 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 423 | m_ast_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | m_language_options_ap.reset(); |
| 425 | m_source_manager_ap.reset(); |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 426 | m_diagnostics_engine_ap.reset(); |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 427 | m_target_options_rp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | m_target_info_ap.reset(); |
| 429 | m_identifier_table_ap.reset(); |
| 430 | m_selector_table_ap.reset(); |
| 431 | m_builtins_ap.reset(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 432 | m_pointer_byte_size = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | const char * |
| 436 | ClangASTContext::GetTargetTriple () |
| 437 | { |
| 438 | return m_target_triple.c_str(); |
| 439 | } |
| 440 | |
| 441 | void |
| 442 | ClangASTContext::SetTargetTriple (const char *target_triple) |
| 443 | { |
| 444 | Clear(); |
| 445 | m_target_triple.assign(target_triple); |
| 446 | } |
| 447 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 448 | void |
| 449 | ClangASTContext::SetArchitecture (const ArchSpec &arch) |
| 450 | { |
Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 451 | SetTargetTriple(arch.GetTriple().str().c_str()); |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 454 | bool |
| 455 | ClangASTContext::HasExternalSource () |
| 456 | { |
| 457 | ASTContext *ast = getASTContext(); |
| 458 | if (ast) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 459 | return ast->getExternalSource () != nullptr; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 460 | return false; |
| 461 | } |
| 462 | |
| 463 | void |
Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 464 | ClangASTContext::SetExternalSource (llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_ap) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 465 | { |
| 466 | ASTContext *ast = getASTContext(); |
| 467 | if (ast) |
| 468 | { |
| 469 | ast->setExternalSource (ast_source_ap); |
| 470 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true); |
| 471 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(true); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | void |
| 476 | ClangASTContext::RemoveExternalSource () |
| 477 | { |
| 478 | ASTContext *ast = getASTContext(); |
| 479 | |
| 480 | if (ast) |
| 481 | { |
Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 482 | llvm::IntrusiveRefCntPtr<ExternalASTSource> empty_ast_source_ap; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 483 | ast->setExternalSource (empty_ast_source_ap); |
| 484 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(false); |
| 485 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(false); |
| 486 | } |
| 487 | } |
| 488 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 489 | void |
| 490 | ClangASTContext::setASTContext(clang::ASTContext *ast_ctx) |
| 491 | { |
| 492 | if (!m_ast_owned) { |
| 493 | m_ast_ap.release(); |
| 494 | } |
| 495 | m_ast_owned = false; |
| 496 | m_ast_ap.reset(ast_ctx); |
| 497 | GetASTMap().Insert(ast_ctx, this); |
| 498 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 499 | |
| 500 | ASTContext * |
| 501 | ClangASTContext::getASTContext() |
| 502 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 503 | if (m_ast_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 504 | { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 505 | m_ast_owned = true; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 506 | m_ast_ap.reset(new ASTContext (*getLanguageOptions(), |
| 507 | *getSourceManager(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 508 | *getIdentifierTable(), |
| 509 | *getSelectorTable(), |
Alp Toker | cf55e88 | 2014-05-03 15:05:45 +0000 | [diff] [blame] | 510 | *getBuiltinContext())); |
Sean Callanan | 6d61b63 | 2015-04-09 17:42:48 +0000 | [diff] [blame] | 511 | |
| 512 | m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false); |
Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 513 | |
| 514 | // This can be NULL if we don't know anything about the architecture or if the |
| 515 | // target for an architecture isn't enabled in the llvm/clang that we built |
| 516 | TargetInfo *target_info = getTargetInfo(); |
| 517 | if (target_info) |
| 518 | m_ast_ap->InitBuiltinTypes(*target_info); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 519 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 520 | if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton) |
| 521 | { |
| 522 | m_ast_ap->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
| 523 | //m_ast_ap->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 524 | } |
| 525 | |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 526 | GetASTMap().Insert(m_ast_ap.get(), this); |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 527 | |
| 528 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (new ClangExternalASTSourceCallbacks (ClangASTContext::CompleteTagDecl, |
| 529 | ClangASTContext::CompleteObjCInterfaceDecl, |
| 530 | nullptr, |
| 531 | ClangASTContext::LayoutRecordType, |
| 532 | this)); |
| 533 | SetExternalSource (ast_source_ap); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 535 | return m_ast_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 538 | ClangASTContext* |
| 539 | ClangASTContext::GetASTContext (clang::ASTContext* ast) |
| 540 | { |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 541 | ClangASTContext *clang_ast = GetASTMap().Lookup(ast); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 542 | return clang_ast; |
| 543 | } |
| 544 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 545 | Builtin::Context * |
| 546 | ClangASTContext::getBuiltinContext() |
| 547 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 548 | if (m_builtins_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 549 | m_builtins_ap.reset (new Builtin::Context()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | return m_builtins_ap.get(); |
| 551 | } |
| 552 | |
| 553 | IdentifierTable * |
| 554 | ClangASTContext::getIdentifierTable() |
| 555 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 556 | if (m_identifier_table_ap.get() == nullptr) |
| 557 | m_identifier_table_ap.reset(new IdentifierTable (*ClangASTContext::getLanguageOptions(), nullptr)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 558 | return m_identifier_table_ap.get(); |
| 559 | } |
| 560 | |
| 561 | LangOptions * |
| 562 | ClangASTContext::getLanguageOptions() |
| 563 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 564 | if (m_language_options_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 565 | { |
| 566 | m_language_options_ap.reset(new LangOptions()); |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 567 | ParseLangArgs(*m_language_options_ap, IK_ObjCXX, GetTargetTriple()); |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 568 | // InitializeLangOptions(*m_language_options_ap, IK_ObjCXX); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 569 | } |
| 570 | return m_language_options_ap.get(); |
| 571 | } |
| 572 | |
| 573 | SelectorTable * |
| 574 | ClangASTContext::getSelectorTable() |
| 575 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 576 | if (m_selector_table_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 577 | m_selector_table_ap.reset (new SelectorTable()); |
| 578 | return m_selector_table_ap.get(); |
| 579 | } |
| 580 | |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 581 | clang::FileManager * |
| 582 | ClangASTContext::getFileManager() |
| 583 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 584 | if (m_file_manager_ap.get() == nullptr) |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 585 | { |
| 586 | clang::FileSystemOptions file_system_options; |
| 587 | m_file_manager_ap.reset(new clang::FileManager(file_system_options)); |
| 588 | } |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 589 | return m_file_manager_ap.get(); |
| 590 | } |
| 591 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 592 | clang::SourceManager * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 593 | ClangASTContext::getSourceManager() |
| 594 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 595 | if (m_source_manager_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 596 | m_source_manager_ap.reset(new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 597 | return m_source_manager_ap.get(); |
| 598 | } |
| 599 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 600 | clang::DiagnosticsEngine * |
| 601 | ClangASTContext::getDiagnosticsEngine() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 602 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 603 | if (m_diagnostics_engine_ap.get() == nullptr) |
Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 604 | { |
| 605 | llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs()); |
Sean Callanan | ec8f1ef | 2012-10-25 01:00:25 +0000 | [diff] [blame] | 606 | m_diagnostics_engine_ap.reset(new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions())); |
Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 607 | } |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 608 | return m_diagnostics_engine_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 611 | class NullDiagnosticConsumer : public DiagnosticConsumer |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 612 | { |
| 613 | public: |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 614 | NullDiagnosticConsumer () |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 615 | { |
| 616 | m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 617 | } |
| 618 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 619 | void HandleDiagnostic (DiagnosticsEngine::Level DiagLevel, const Diagnostic &info) |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 620 | { |
| 621 | if (m_log) |
| 622 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 623 | llvm::SmallVector<char, 32> diag_str(10); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 624 | info.FormatDiagnostic(diag_str); |
| 625 | diag_str.push_back('\0'); |
| 626 | m_log->Printf("Compiler diagnostic: %s\n", diag_str.data()); |
| 627 | } |
| 628 | } |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 629 | |
| 630 | DiagnosticConsumer *clone (DiagnosticsEngine &Diags) const |
| 631 | { |
| 632 | return new NullDiagnosticConsumer (); |
| 633 | } |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 634 | private: |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 635 | Log * m_log; |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 636 | }; |
| 637 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 638 | DiagnosticConsumer * |
| 639 | ClangASTContext::getDiagnosticConsumer() |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 640 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 641 | if (m_diagnostic_consumer_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 642 | m_diagnostic_consumer_ap.reset(new NullDiagnosticConsumer); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 643 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 644 | return m_diagnostic_consumer_ap.get(); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Jason Molenda | 45938b9 | 2014-07-08 23:46:39 +0000 | [diff] [blame] | 647 | std::shared_ptr<TargetOptions> & |
| 648 | ClangASTContext::getTargetOptions() { |
Alp Toker | edc902f | 2014-07-05 03:06:05 +0000 | [diff] [blame] | 649 | if (m_target_options_rp.get() == nullptr && !m_target_triple.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | { |
Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 651 | m_target_options_rp = std::make_shared<TargetOptions>(); |
Alp Toker | edc902f | 2014-07-05 03:06:05 +0000 | [diff] [blame] | 652 | if (m_target_options_rp.get() != nullptr) |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 653 | m_target_options_rp->Triple = m_target_triple; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 654 | } |
Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 655 | return m_target_options_rp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | |
| 659 | TargetInfo * |
| 660 | ClangASTContext::getTargetInfo() |
| 661 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 662 | // target_triple should be something like "x86_64-apple-macosx" |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 663 | if (m_target_info_ap.get() == nullptr && !m_target_triple.empty()) |
Greg Clayton | 38d880a | 2012-11-16 21:35:22 +0000 | [diff] [blame] | 664 | m_target_info_ap.reset (TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(), getTargetOptions())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 665 | return m_target_info_ap.get(); |
| 666 | } |
| 667 | |
| 668 | #pragma mark Basic Types |
| 669 | |
| 670 | static inline bool |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 671 | QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext *ast, QualType qual_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 672 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 673 | uint64_t qual_type_bit_size = ast->getTypeSize(qual_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 674 | if (qual_type_bit_size == bit_size) |
| 675 | return true; |
| 676 | return false; |
| 677 | } |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 678 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 679 | CompilerType |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 680 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (Encoding encoding, size_t bit_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 681 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 682 | return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (getASTContext(), encoding, bit_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 685 | CompilerType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 686 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (ASTContext *ast, Encoding encoding, uint32_t bit_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 688 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 689 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 690 | switch (encoding) |
| 691 | { |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 692 | case eEncodingInvalid: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 693 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 694 | return CompilerType (ast, ast->VoidPtrTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 695 | break; |
| 696 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 697 | case eEncodingUint: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 698 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 699 | return CompilerType (ast, ast->UnsignedCharTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 700 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 701 | return CompilerType (ast, ast->UnsignedShortTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 702 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 703 | return CompilerType (ast, ast->UnsignedIntTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 704 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 705 | return CompilerType (ast, ast->UnsignedLongTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 706 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 707 | return CompilerType (ast, ast->UnsignedLongLongTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 708 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 709 | return CompilerType (ast, ast->UnsignedInt128Ty); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | break; |
| 711 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 712 | case eEncodingSint: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 713 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 714 | return CompilerType (ast, ast->CharTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 715 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 716 | return CompilerType (ast, ast->ShortTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 717 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 718 | return CompilerType (ast, ast->IntTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 719 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 720 | return CompilerType (ast, ast->LongTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 721 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 722 | return CompilerType (ast, ast->LongLongTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 723 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 724 | return CompilerType (ast, ast->Int128Ty); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | break; |
| 726 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 727 | case eEncodingIEEE754: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 728 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 729 | return CompilerType (ast, ast->FloatTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 730 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 731 | return CompilerType (ast, ast->DoubleTy); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 732 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 733 | return CompilerType (ast, ast->LongDoubleTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 734 | break; |
| 735 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 736 | case eEncodingVector: |
Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 737 | // Sanity check that bit_size is a multiple of 8's. |
| 738 | if (bit_size && !(bit_size & 0x7u)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 739 | return CompilerType (ast, ast->getExtVectorType (ast->UnsignedCharTy, bit_size/8)); |
Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 740 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 743 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 746 | |
| 747 | |
| 748 | lldb::BasicType |
| 749 | ClangASTContext::GetBasicTypeEnumeration (const ConstString &name) |
| 750 | { |
| 751 | if (name) |
| 752 | { |
| 753 | typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; |
| 754 | static TypeNameToBasicTypeMap g_type_map; |
| 755 | static std::once_flag g_once_flag; |
| 756 | std::call_once(g_once_flag, [](){ |
| 757 | // "void" |
| 758 | g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); |
| 759 | |
| 760 | // "char" |
| 761 | g_type_map.Append(ConstString("char").GetCString(), eBasicTypeChar); |
| 762 | g_type_map.Append(ConstString("signed char").GetCString(), eBasicTypeSignedChar); |
| 763 | g_type_map.Append(ConstString("unsigned char").GetCString(), eBasicTypeUnsignedChar); |
| 764 | g_type_map.Append(ConstString("wchar_t").GetCString(), eBasicTypeWChar); |
| 765 | g_type_map.Append(ConstString("signed wchar_t").GetCString(), eBasicTypeSignedWChar); |
| 766 | g_type_map.Append(ConstString("unsigned wchar_t").GetCString(), eBasicTypeUnsignedWChar); |
| 767 | // "short" |
| 768 | g_type_map.Append(ConstString("short").GetCString(), eBasicTypeShort); |
| 769 | g_type_map.Append(ConstString("short int").GetCString(), eBasicTypeShort); |
| 770 | g_type_map.Append(ConstString("unsigned short").GetCString(), eBasicTypeUnsignedShort); |
| 771 | g_type_map.Append(ConstString("unsigned short int").GetCString(), eBasicTypeUnsignedShort); |
| 772 | |
| 773 | // "int" |
| 774 | g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); |
| 775 | g_type_map.Append(ConstString("signed int").GetCString(), eBasicTypeInt); |
| 776 | g_type_map.Append(ConstString("unsigned int").GetCString(), eBasicTypeUnsignedInt); |
| 777 | g_type_map.Append(ConstString("unsigned").GetCString(), eBasicTypeUnsignedInt); |
| 778 | |
| 779 | // "long" |
| 780 | g_type_map.Append(ConstString("long").GetCString(), eBasicTypeLong); |
| 781 | g_type_map.Append(ConstString("long int").GetCString(), eBasicTypeLong); |
| 782 | g_type_map.Append(ConstString("unsigned long").GetCString(), eBasicTypeUnsignedLong); |
| 783 | g_type_map.Append(ConstString("unsigned long int").GetCString(), eBasicTypeUnsignedLong); |
| 784 | |
| 785 | // "long long" |
| 786 | g_type_map.Append(ConstString("long long").GetCString(), eBasicTypeLongLong); |
| 787 | g_type_map.Append(ConstString("long long int").GetCString(), eBasicTypeLongLong); |
| 788 | g_type_map.Append(ConstString("unsigned long long").GetCString(), eBasicTypeUnsignedLongLong); |
| 789 | g_type_map.Append(ConstString("unsigned long long int").GetCString(), eBasicTypeUnsignedLongLong); |
| 790 | |
| 791 | // "int128" |
| 792 | g_type_map.Append(ConstString("__int128_t").GetCString(), eBasicTypeInt128); |
| 793 | g_type_map.Append(ConstString("__uint128_t").GetCString(), eBasicTypeUnsignedInt128); |
| 794 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 795 | // Miscellaneous |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 796 | g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); |
| 797 | g_type_map.Append(ConstString("float").GetCString(), eBasicTypeFloat); |
| 798 | g_type_map.Append(ConstString("double").GetCString(), eBasicTypeDouble); |
| 799 | g_type_map.Append(ConstString("long double").GetCString(), eBasicTypeLongDouble); |
| 800 | g_type_map.Append(ConstString("id").GetCString(), eBasicTypeObjCID); |
| 801 | g_type_map.Append(ConstString("SEL").GetCString(), eBasicTypeObjCSel); |
| 802 | g_type_map.Append(ConstString("nullptr").GetCString(), eBasicTypeNullPtr); |
| 803 | g_type_map.Sort(); |
| 804 | }); |
| 805 | |
| 806 | return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); |
| 807 | } |
| 808 | return eBasicTypeInvalid; |
| 809 | } |
| 810 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 811 | CompilerType |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 812 | ClangASTContext::GetBasicType (ASTContext *ast, const ConstString &name) |
| 813 | { |
| 814 | if (ast) |
| 815 | { |
| 816 | lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration (name); |
| 817 | return ClangASTContext::GetBasicType (ast, basic_type); |
| 818 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 819 | return CompilerType(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | uint32_t |
| 823 | ClangASTContext::GetPointerByteSize () |
| 824 | { |
| 825 | if (m_pointer_byte_size == 0) |
Enrico Granata | 1cd5e92 | 2015-01-28 00:07:51 +0000 | [diff] [blame] | 826 | m_pointer_byte_size = GetBasicType(lldb::eBasicTypeVoid).GetPointerType().GetByteSize(nullptr); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 827 | return m_pointer_byte_size; |
| 828 | } |
| 829 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 830 | CompilerType |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 831 | ClangASTContext::GetBasicType (lldb::BasicType basic_type) |
| 832 | { |
| 833 | return GetBasicType (getASTContext(), basic_type); |
| 834 | } |
| 835 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 836 | CompilerType |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 837 | ClangASTContext::GetBasicType (ASTContext *ast, lldb::BasicType basic_type) |
| 838 | { |
| 839 | if (ast) |
| 840 | { |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 841 | lldb::opaque_compiler_type_t clang_type = nullptr; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 842 | |
| 843 | switch (basic_type) |
| 844 | { |
| 845 | case eBasicTypeInvalid: |
| 846 | case eBasicTypeOther: |
| 847 | break; |
| 848 | case eBasicTypeVoid: |
| 849 | clang_type = ast->VoidTy.getAsOpaquePtr(); |
| 850 | break; |
| 851 | case eBasicTypeChar: |
| 852 | clang_type = ast->CharTy.getAsOpaquePtr(); |
| 853 | break; |
| 854 | case eBasicTypeSignedChar: |
| 855 | clang_type = ast->SignedCharTy.getAsOpaquePtr(); |
| 856 | break; |
| 857 | case eBasicTypeUnsignedChar: |
| 858 | clang_type = ast->UnsignedCharTy.getAsOpaquePtr(); |
| 859 | break; |
| 860 | case eBasicTypeWChar: |
| 861 | clang_type = ast->getWCharType().getAsOpaquePtr(); |
| 862 | break; |
| 863 | case eBasicTypeSignedWChar: |
| 864 | clang_type = ast->getSignedWCharType().getAsOpaquePtr(); |
| 865 | break; |
| 866 | case eBasicTypeUnsignedWChar: |
| 867 | clang_type = ast->getUnsignedWCharType().getAsOpaquePtr(); |
| 868 | break; |
| 869 | case eBasicTypeChar16: |
| 870 | clang_type = ast->Char16Ty.getAsOpaquePtr(); |
| 871 | break; |
| 872 | case eBasicTypeChar32: |
| 873 | clang_type = ast->Char32Ty.getAsOpaquePtr(); |
| 874 | break; |
| 875 | case eBasicTypeShort: |
| 876 | clang_type = ast->ShortTy.getAsOpaquePtr(); |
| 877 | break; |
| 878 | case eBasicTypeUnsignedShort: |
| 879 | clang_type = ast->UnsignedShortTy.getAsOpaquePtr(); |
| 880 | break; |
| 881 | case eBasicTypeInt: |
| 882 | clang_type = ast->IntTy.getAsOpaquePtr(); |
| 883 | break; |
| 884 | case eBasicTypeUnsignedInt: |
| 885 | clang_type = ast->UnsignedIntTy.getAsOpaquePtr(); |
| 886 | break; |
| 887 | case eBasicTypeLong: |
| 888 | clang_type = ast->LongTy.getAsOpaquePtr(); |
| 889 | break; |
| 890 | case eBasicTypeUnsignedLong: |
| 891 | clang_type = ast->UnsignedLongTy.getAsOpaquePtr(); |
| 892 | break; |
| 893 | case eBasicTypeLongLong: |
| 894 | clang_type = ast->LongLongTy.getAsOpaquePtr(); |
| 895 | break; |
| 896 | case eBasicTypeUnsignedLongLong: |
| 897 | clang_type = ast->UnsignedLongLongTy.getAsOpaquePtr(); |
| 898 | break; |
| 899 | case eBasicTypeInt128: |
| 900 | clang_type = ast->Int128Ty.getAsOpaquePtr(); |
| 901 | break; |
| 902 | case eBasicTypeUnsignedInt128: |
| 903 | clang_type = ast->UnsignedInt128Ty.getAsOpaquePtr(); |
| 904 | break; |
| 905 | case eBasicTypeBool: |
| 906 | clang_type = ast->BoolTy.getAsOpaquePtr(); |
| 907 | break; |
| 908 | case eBasicTypeHalf: |
| 909 | clang_type = ast->HalfTy.getAsOpaquePtr(); |
| 910 | break; |
| 911 | case eBasicTypeFloat: |
| 912 | clang_type = ast->FloatTy.getAsOpaquePtr(); |
| 913 | break; |
| 914 | case eBasicTypeDouble: |
| 915 | clang_type = ast->DoubleTy.getAsOpaquePtr(); |
| 916 | break; |
| 917 | case eBasicTypeLongDouble: |
| 918 | clang_type = ast->LongDoubleTy.getAsOpaquePtr(); |
| 919 | break; |
| 920 | case eBasicTypeFloatComplex: |
| 921 | clang_type = ast->FloatComplexTy.getAsOpaquePtr(); |
| 922 | break; |
| 923 | case eBasicTypeDoubleComplex: |
| 924 | clang_type = ast->DoubleComplexTy.getAsOpaquePtr(); |
| 925 | break; |
| 926 | case eBasicTypeLongDoubleComplex: |
| 927 | clang_type = ast->LongDoubleComplexTy.getAsOpaquePtr(); |
| 928 | break; |
| 929 | case eBasicTypeObjCID: |
| 930 | clang_type = ast->getObjCIdType().getAsOpaquePtr(); |
| 931 | break; |
| 932 | case eBasicTypeObjCClass: |
| 933 | clang_type = ast->getObjCClassType().getAsOpaquePtr(); |
| 934 | break; |
| 935 | case eBasicTypeObjCSel: |
| 936 | clang_type = ast->getObjCSelType().getAsOpaquePtr(); |
| 937 | break; |
| 938 | case eBasicTypeNullPtr: |
| 939 | clang_type = ast->NullPtrTy.getAsOpaquePtr(); |
| 940 | break; |
| 941 | } |
| 942 | |
| 943 | if (clang_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 944 | return CompilerType (GetASTContext(ast), clang_type); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 945 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 946 | return CompilerType(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 950 | CompilerType |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 951 | ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name, uint32_t dw_ate, uint32_t bit_size) |
| 952 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 953 | ASTContext *ast = getASTContext(); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 954 | |
| 955 | #define streq(a,b) strcmp(a,b) == 0 |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 956 | assert (ast != nullptr); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 957 | if (ast) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 958 | { |
| 959 | switch (dw_ate) |
| 960 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 961 | default: |
| 962 | break; |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 963 | |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 964 | case DW_ATE_address: |
| 965 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 966 | return CompilerType (ast, ast->VoidPtrTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 967 | break; |
| 968 | |
| 969 | case DW_ATE_boolean: |
| 970 | if (QualTypeMatchesBitSize (bit_size, ast, ast->BoolTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 971 | return CompilerType (ast, ast->BoolTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 972 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 973 | return CompilerType (ast, ast->UnsignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 974 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 975 | return CompilerType (ast, ast->UnsignedShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 976 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 977 | return CompilerType (ast, ast->UnsignedIntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 978 | break; |
| 979 | |
| 980 | case DW_ATE_lo_user: |
| 981 | // This has been seen to mean DW_AT_complex_integer |
| 982 | if (type_name) |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 983 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 984 | if (::strstr(type_name, "complex")) |
| 985 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 986 | CompilerType complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("int", DW_ATE_signed, bit_size/2); |
| 987 | return CompilerType (ast, ast->getComplexType (GetQualType(complex_int_clang_type))); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 988 | } |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 989 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 990 | break; |
| 991 | |
| 992 | case DW_ATE_complex_float: |
| 993 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatComplexTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 994 | return CompilerType (ast, ast->FloatComplexTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 995 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleComplexTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 996 | return CompilerType (ast, ast->DoubleComplexTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 997 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleComplexTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 998 | return CompilerType (ast, ast->LongDoubleComplexTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 999 | else |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1000 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1001 | CompilerType complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("float", DW_ATE_float, bit_size/2); |
| 1002 | return CompilerType (ast, ast->getComplexType (GetQualType(complex_float_clang_type))); |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1003 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1004 | break; |
| 1005 | |
| 1006 | case DW_ATE_float: |
Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1007 | if (streq(type_name, "float") && QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1008 | return CompilerType (ast, ast->FloatTy); |
Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1009 | if (streq(type_name, "double") && QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1010 | return CompilerType (ast, ast->DoubleTy); |
Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1011 | if (streq(type_name, "long double") && QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1012 | return CompilerType (ast, ast->LongDoubleTy); |
Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 1013 | // Fall back to not requiring a name match |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1014 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1015 | return CompilerType (ast, ast->FloatTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1016 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1017 | return CompilerType (ast, ast->DoubleTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1018 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1019 | return CompilerType (ast, ast->LongDoubleTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | |
| 1022 | case DW_ATE_signed: |
| 1023 | if (type_name) |
| 1024 | { |
| 1025 | if (streq(type_name, "wchar_t") && |
Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1026 | QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy) && |
Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 1027 | (getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType()))) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1028 | return CompilerType (ast, ast->WCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1029 | if (streq(type_name, "void") && |
| 1030 | QualTypeMatchesBitSize (bit_size, ast, ast->VoidTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1031 | return CompilerType (ast, ast->VoidTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1032 | if (strstr(type_name, "long long") && |
| 1033 | QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1034 | return CompilerType (ast, ast->LongLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1035 | if (strstr(type_name, "long") && |
| 1036 | QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1037 | return CompilerType (ast, ast->LongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1038 | if (strstr(type_name, "short") && |
| 1039 | QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1040 | return CompilerType (ast, ast->ShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1041 | if (strstr(type_name, "char")) |
| 1042 | { |
| 1043 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1044 | return CompilerType (ast, ast->CharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1045 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1046 | return CompilerType (ast, ast->SignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1047 | } |
| 1048 | if (strstr(type_name, "int")) |
| 1049 | { |
| 1050 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1051 | return CompilerType (ast, ast->IntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1052 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1053 | return CompilerType (ast, ast->Int128Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | // We weren't able to match up a type name, just search by size |
| 1057 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1058 | return CompilerType (ast, ast->CharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1059 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1060 | return CompilerType (ast, ast->ShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1061 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1062 | return CompilerType (ast, ast->IntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1063 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1064 | return CompilerType (ast, ast->LongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1065 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1066 | return CompilerType (ast, ast->LongLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1067 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1068 | return CompilerType (ast, ast->Int128Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1069 | break; |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1070 | |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1071 | case DW_ATE_signed_char: |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1072 | if (ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char")) |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1073 | { |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1074 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1075 | return CompilerType (ast, ast->CharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1076 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1077 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1078 | return CompilerType (ast, ast->SignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1079 | break; |
| 1080 | |
| 1081 | case DW_ATE_unsigned: |
| 1082 | if (type_name) |
| 1083 | { |
Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1084 | if (streq(type_name, "wchar_t")) |
| 1085 | { |
| 1086 | if (QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy)) |
| 1087 | { |
Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 1088 | if (!(getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType()))) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1089 | return CompilerType (ast, ast->WCharTy); |
Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1090 | } |
| 1091 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1092 | if (strstr(type_name, "long long")) |
| 1093 | { |
| 1094 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1095 | return CompilerType (ast, ast->UnsignedLongLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1096 | } |
| 1097 | else if (strstr(type_name, "long")) |
| 1098 | { |
| 1099 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1100 | return CompilerType (ast, ast->UnsignedLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1101 | } |
| 1102 | else if (strstr(type_name, "short")) |
| 1103 | { |
| 1104 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1105 | return CompilerType (ast, ast->UnsignedShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1106 | } |
| 1107 | else if (strstr(type_name, "char")) |
| 1108 | { |
| 1109 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1110 | return CompilerType (ast, ast->UnsignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1111 | } |
| 1112 | else if (strstr(type_name, "int")) |
| 1113 | { |
| 1114 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1115 | return CompilerType (ast, ast->UnsignedIntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1116 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1117 | return CompilerType (ast, ast->UnsignedInt128Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | // We weren't able to match up a type name, just search by size |
| 1121 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1122 | return CompilerType (ast, ast->UnsignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1123 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1124 | return CompilerType (ast, ast->UnsignedShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1125 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1126 | return CompilerType (ast, ast->UnsignedIntTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1127 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1128 | return CompilerType (ast, ast->UnsignedLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1129 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1130 | return CompilerType (ast, ast->UnsignedLongLongTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1131 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1132 | return CompilerType (ast, ast->UnsignedInt128Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1133 | break; |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1134 | |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1135 | case DW_ATE_unsigned_char: |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1136 | if (!ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char")) |
| 1137 | { |
| 1138 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1139 | return CompilerType (ast, ast->CharTy); |
Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1140 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1141 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1142 | return CompilerType (ast, ast->UnsignedCharTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1143 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1144 | return CompilerType (ast, ast->UnsignedShortTy); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1145 | break; |
| 1146 | |
| 1147 | case DW_ATE_imaginary_float: |
| 1148 | break; |
| 1149 | |
| 1150 | case DW_ATE_UTF: |
| 1151 | if (type_name) |
| 1152 | { |
| 1153 | if (streq(type_name, "char16_t")) |
| 1154 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1155 | return CompilerType (ast, ast->Char16Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1156 | } |
| 1157 | else if (streq(type_name, "char32_t")) |
| 1158 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1159 | return CompilerType (ast, ast->Char32Ty); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | // This assert should fire for anything that we don't catch above so we know |
| 1166 | // to fix any issues we run into. |
Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 1167 | if (type_name) |
| 1168 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1169 | 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] | 1170 | } |
| 1171 | else |
| 1172 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1173 | 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] | 1174 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1175 | return CompilerType (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1178 | CompilerType |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1179 | ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast) |
| 1180 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1181 | if (ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1182 | return CompilerType (ast, ast->UnknownAnyTy); |
| 1183 | return CompilerType(); |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1186 | CompilerType |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1187 | ClangASTContext::GetCStringType (bool is_const) |
| 1188 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1189 | ASTContext *ast = getASTContext(); |
| 1190 | QualType char_type(ast->CharTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | |
| 1192 | if (is_const) |
| 1193 | char_type.addConst(); |
| 1194 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1195 | return CompilerType (ast, ast->getPointerType(char_type)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 1198 | clang::DeclContext * |
| 1199 | ClangASTContext::GetTranslationUnitDecl (clang::ASTContext *ast) |
| 1200 | { |
| 1201 | return ast->getTranslationUnitDecl(); |
| 1202 | } |
| 1203 | |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1204 | clang::Decl * |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1205 | ClangASTContext::CopyDecl (ASTContext *dst_ast, |
| 1206 | ASTContext *src_ast, |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1207 | clang::Decl *source_decl) |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 1208 | { |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 1209 | FileSystemOptions file_system_options; |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1210 | FileManager file_manager (file_system_options); |
| 1211 | ASTImporter importer(*dst_ast, file_manager, |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1212 | *src_ast, file_manager, |
| 1213 | false); |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1214 | |
| 1215 | return importer.Import(source_decl); |
| 1216 | } |
| 1217 | |
Sean Callanan | 23a3027 | 2010-07-16 00:00:27 +0000 | [diff] [blame] | 1218 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1219 | ClangASTContext::AreTypesSame (CompilerType type1, |
| 1220 | CompilerType type2, |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1221 | bool ignore_qualifiers) |
Sean Callanan | 4dcca262 | 2010-07-15 22:30:52 +0000 | [diff] [blame] | 1222 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 1223 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type1.GetTypeSystem()); |
| 1224 | if (!ast || ast != type2.GetTypeSystem()) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1225 | return false; |
| 1226 | |
| 1227 | if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType()) |
Greg Clayton | 55995eb | 2012-04-06 17:38:55 +0000 | [diff] [blame] | 1228 | return true; |
| 1229 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1230 | QualType type1_qual = GetQualType(type1); |
| 1231 | QualType type2_qual = GetQualType(type2); |
Sean Callanan | 5056ab0 | 2012-02-18 02:01:03 +0000 | [diff] [blame] | 1232 | |
| 1233 | if (ignore_qualifiers) |
| 1234 | { |
| 1235 | type1_qual = type1_qual.getUnqualifiedType(); |
| 1236 | type2_qual = type2_qual.getUnqualifiedType(); |
| 1237 | } |
| 1238 | |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 1239 | return ast->getASTContext()->hasSameType (type1_qual, type2_qual); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1242 | CompilerType |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1243 | ClangASTContext::GetTypeForDecl (clang::NamedDecl *decl) |
| 1244 | { |
| 1245 | if (clang::ObjCInterfaceDecl *interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) |
| 1246 | return GetTypeForDecl(interface_decl); |
| 1247 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) |
| 1248 | return GetTypeForDecl(tag_decl); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1249 | return CompilerType(); |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1252 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1253 | CompilerType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1254 | ClangASTContext::GetTypeForDecl (TagDecl *decl) |
| 1255 | { |
| 1256 | // No need to call the getASTContext() accessor (which can create the AST |
| 1257 | // if it isn't created yet, because we can't have created a decl in this |
| 1258 | // AST if our AST didn't already exist... |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1259 | ASTContext *ast = &decl->getASTContext(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1260 | if (ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1261 | return CompilerType (ast, ast->getTagDeclType(decl)); |
| 1262 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1265 | CompilerType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1266 | ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl) |
| 1267 | { |
| 1268 | // No need to call the getASTContext() accessor (which can create the AST |
| 1269 | // if it isn't created yet, because we can't have created a decl in this |
| 1270 | // AST if our AST didn't already exist... |
Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1271 | ASTContext *ast = &decl->getASTContext(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1272 | if (ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1273 | return CompilerType (ast, ast->getObjCInterfaceType(decl)); |
| 1274 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1277 | #pragma mark Structure, Unions, Classes |
| 1278 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1279 | CompilerType |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1280 | ClangASTContext::CreateRecordType (DeclContext *decl_ctx, |
| 1281 | AccessType access_type, |
| 1282 | const char *name, |
| 1283 | int kind, |
| 1284 | LanguageType language, |
| 1285 | ClangASTMetadata *metadata) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1286 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1287 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1288 | assert (ast != nullptr); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1289 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1290 | if (decl_ctx == nullptr) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1291 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1292 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1293 | |
Greg Clayton | e1be996 | 2011-08-24 23:50:00 +0000 | [diff] [blame] | 1294 | if (language == eLanguageTypeObjC || language == eLanguageTypeObjC_plus_plus) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1295 | { |
Greg Clayton | aaf99e0 | 2010-10-11 02:25:34 +0000 | [diff] [blame] | 1296 | bool isForwardDecl = true; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1297 | bool isInternal = false; |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1298 | return CreateObjCClass (name, decl_ctx, isForwardDecl, isInternal, metadata); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1301 | // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and |
| 1302 | // we will need to update this code. I was told to currently always use |
| 1303 | // the CXXRecordDecl class since we often don't know from debug information |
| 1304 | // if something is struct or a class, so we default to always use the more |
| 1305 | // complete definition just in case. |
Sean Callanan | 11e32d3 | 2014-02-18 00:31:38 +0000 | [diff] [blame] | 1306 | |
| 1307 | bool is_anonymous = (!name) || (!name[0]); |
| 1308 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1309 | CXXRecordDecl *decl = CXXRecordDecl::Create (*ast, |
| 1310 | (TagDecl::TagKind)kind, |
| 1311 | decl_ctx, |
| 1312 | SourceLocation(), |
| 1313 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1314 | is_anonymous ? nullptr : &ast->Idents.get(name)); |
Sean Callanan | 11e32d3 | 2014-02-18 00:31:38 +0000 | [diff] [blame] | 1315 | |
| 1316 | if (is_anonymous) |
| 1317 | decl->setAnonymousStructOrUnion(true); |
Sean Callanan | 7282e2a | 2012-01-13 22:10:18 +0000 | [diff] [blame] | 1318 | |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1319 | if (decl) |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1320 | { |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1321 | if (metadata) |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1322 | SetMetadata(ast, decl, *metadata); |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1323 | |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1324 | if (access_type != eAccessNone) |
| 1325 | decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1326 | |
| 1327 | if (decl_ctx) |
| 1328 | decl_ctx->addDecl (decl); |
| 1329 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1330 | return CompilerType(ast, ast->getTagDeclType(decl)); |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1331 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1332 | return CompilerType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1335 | static TemplateParameterList * |
| 1336 | CreateTemplateParameterList (ASTContext *ast, |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1337 | const ClangASTContext::TemplateParameterInfos &template_param_infos, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1338 | llvm::SmallVector<NamedDecl *, 8> &template_param_decls) |
| 1339 | { |
| 1340 | const bool parameter_pack = false; |
| 1341 | const bool is_typename = false; |
| 1342 | const unsigned depth = 0; |
| 1343 | const size_t num_template_params = template_param_infos.GetSize(); |
| 1344 | for (size_t i=0; i<num_template_params; ++i) |
| 1345 | { |
| 1346 | const char *name = template_param_infos.names[i]; |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1347 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1348 | IdentifierInfo *identifier_info = nullptr; |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1349 | if (name && name[0]) |
| 1350 | identifier_info = &ast->Idents.get(name); |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1351 | if (template_param_infos.args[i].getKind() == TemplateArgument::Integral) |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1352 | { |
| 1353 | template_param_decls.push_back (NonTypeTemplateParmDecl::Create (*ast, |
| 1354 | ast->getTranslationUnitDecl(), // Is this the right decl context?, SourceLocation StartLoc, |
| 1355 | SourceLocation(), |
| 1356 | SourceLocation(), |
| 1357 | depth, |
| 1358 | i, |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1359 | identifier_info, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1360 | template_param_infos.args[i].getIntegralType(), |
| 1361 | parameter_pack, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1362 | nullptr)); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1363 | |
| 1364 | } |
| 1365 | else |
| 1366 | { |
| 1367 | template_param_decls.push_back (TemplateTypeParmDecl::Create (*ast, |
| 1368 | ast->getTranslationUnitDecl(), // Is this the right decl context? |
| 1369 | SourceLocation(), |
| 1370 | SourceLocation(), |
| 1371 | depth, |
| 1372 | i, |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1373 | identifier_info, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1374 | is_typename, |
| 1375 | parameter_pack)); |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | TemplateParameterList *template_param_list = TemplateParameterList::Create (*ast, |
| 1380 | SourceLocation(), |
| 1381 | SourceLocation(), |
| 1382 | &template_param_decls.front(), |
| 1383 | template_param_decls.size(), |
| 1384 | SourceLocation()); |
| 1385 | return template_param_list; |
| 1386 | } |
| 1387 | |
| 1388 | clang::FunctionTemplateDecl * |
| 1389 | ClangASTContext::CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx, |
| 1390 | clang::FunctionDecl *func_decl, |
| 1391 | const char *name, |
| 1392 | const TemplateParameterInfos &template_param_infos) |
| 1393 | { |
| 1394 | // /// \brief Create a function template node. |
| 1395 | ASTContext *ast = getASTContext(); |
| 1396 | |
| 1397 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
| 1398 | |
| 1399 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, |
| 1400 | template_param_infos, |
| 1401 | template_param_decls); |
| 1402 | FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create (*ast, |
| 1403 | decl_ctx, |
| 1404 | func_decl->getLocation(), |
| 1405 | func_decl->getDeclName(), |
| 1406 | template_param_list, |
| 1407 | func_decl); |
| 1408 | |
| 1409 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); |
| 1410 | i < template_param_decl_count; |
| 1411 | ++i) |
| 1412 | { |
| 1413 | // TODO: verify which decl context we should put template_param_decls into.. |
| 1414 | template_param_decls[i]->setDeclContext (func_decl); |
| 1415 | } |
| 1416 | |
| 1417 | return func_tmpl_decl; |
| 1418 | } |
| 1419 | |
| 1420 | void |
| 1421 | ClangASTContext::CreateFunctionTemplateSpecializationInfo (FunctionDecl *func_decl, |
| 1422 | clang::FunctionTemplateDecl *func_tmpl_decl, |
| 1423 | const TemplateParameterInfos &infos) |
| 1424 | { |
| 1425 | TemplateArgumentList template_args (TemplateArgumentList::OnStack, |
| 1426 | infos.args.data(), |
| 1427 | infos.args.size()); |
| 1428 | |
| 1429 | func_decl->setFunctionTemplateSpecialization (func_tmpl_decl, |
| 1430 | &template_args, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1431 | nullptr); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1435 | ClassTemplateDecl * |
| 1436 | ClangASTContext::CreateClassTemplateDecl (DeclContext *decl_ctx, |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1437 | lldb::AccessType access_type, |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1438 | const char *class_name, |
| 1439 | int kind, |
| 1440 | const TemplateParameterInfos &template_param_infos) |
| 1441 | { |
| 1442 | ASTContext *ast = getASTContext(); |
| 1443 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1444 | ClassTemplateDecl *class_template_decl = nullptr; |
| 1445 | if (decl_ctx == nullptr) |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1446 | decl_ctx = ast->getTranslationUnitDecl(); |
| 1447 | |
| 1448 | IdentifierInfo &identifier_info = ast->Idents.get(class_name); |
| 1449 | DeclarationName decl_name (&identifier_info); |
| 1450 | |
| 1451 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1452 | |
| 1453 | for (NamedDecl *decl : result) |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1454 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1455 | class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1456 | if (class_template_decl) |
| 1457 | return class_template_decl; |
| 1458 | } |
| 1459 | |
| 1460 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1461 | |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1462 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, |
| 1463 | template_param_infos, |
| 1464 | template_param_decls); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1465 | |
| 1466 | CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create (*ast, |
| 1467 | (TagDecl::TagKind)kind, |
| 1468 | decl_ctx, // What decl context do we use here? TU? The actual decl context? |
| 1469 | SourceLocation(), |
| 1470 | SourceLocation(), |
| 1471 | &identifier_info); |
Greg Clayton | e04741d | 2011-12-02 02:09:28 +0000 | [diff] [blame] | 1472 | |
| 1473 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); |
| 1474 | i < template_param_decl_count; |
| 1475 | ++i) |
| 1476 | { |
| 1477 | template_param_decls[i]->setDeclContext (template_cxx_decl); |
| 1478 | } |
| 1479 | |
Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1480 | // With templated classes, we say that a class is templated with |
| 1481 | // specializations, but that the bare class has no functions. |
Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame] | 1482 | //template_cxx_decl->startDefinition(); |
| 1483 | //template_cxx_decl->completeDefinition(); |
Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1484 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1485 | class_template_decl = ClassTemplateDecl::Create (*ast, |
| 1486 | decl_ctx, // What decl context do we use here? TU? The actual decl context? |
| 1487 | SourceLocation(), |
| 1488 | decl_name, |
| 1489 | template_param_list, |
| 1490 | template_cxx_decl, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1491 | nullptr); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1492 | |
| 1493 | if (class_template_decl) |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1494 | { |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1495 | if (access_type != eAccessNone) |
| 1496 | class_template_decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1497 | |
| 1498 | //if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx)) |
| 1499 | // CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl)); |
| 1500 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1501 | decl_ctx->addDecl (class_template_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1502 | |
| 1503 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1504 | VerifyDecl(class_template_decl); |
| 1505 | #endif |
| 1506 | } |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1507 | |
| 1508 | return class_template_decl; |
| 1509 | } |
| 1510 | |
| 1511 | |
| 1512 | ClassTemplateSpecializationDecl * |
| 1513 | ClangASTContext::CreateClassTemplateSpecializationDecl (DeclContext *decl_ctx, |
| 1514 | ClassTemplateDecl *class_template_decl, |
| 1515 | int kind, |
| 1516 | const TemplateParameterInfos &template_param_infos) |
| 1517 | { |
| 1518 | ASTContext *ast = getASTContext(); |
| 1519 | ClassTemplateSpecializationDecl *class_template_specialization_decl = ClassTemplateSpecializationDecl::Create (*ast, |
| 1520 | (TagDecl::TagKind)kind, |
| 1521 | decl_ctx, |
| 1522 | SourceLocation(), |
| 1523 | SourceLocation(), |
| 1524 | class_template_decl, |
| 1525 | &template_param_infos.args.front(), |
| 1526 | template_param_infos.args.size(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1527 | nullptr); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1528 | |
Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame] | 1529 | class_template_specialization_decl->setSpecializationKind(TSK_ExplicitSpecialization); |
| 1530 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1531 | return class_template_specialization_decl; |
| 1532 | } |
| 1533 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1534 | CompilerType |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1535 | ClangASTContext::CreateClassTemplateSpecializationType (ClassTemplateSpecializationDecl *class_template_specialization_decl) |
| 1536 | { |
| 1537 | if (class_template_specialization_decl) |
| 1538 | { |
| 1539 | ASTContext *ast = getASTContext(); |
| 1540 | if (ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1541 | return CompilerType(ast, ast->getTagDeclType(class_template_specialization_decl)); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1542 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1543 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1546 | static inline bool |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1547 | 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] | 1548 | { |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1549 | // Special-case call since it can take any number of operands |
| 1550 | if(op_kind == OO_Call) |
| 1551 | return true; |
| 1552 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1553 | // The parameter count doesn't include "this" |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1554 | if (num_params == 0) |
| 1555 | return unary; |
| 1556 | if (num_params == 1) |
| 1557 | return binary; |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1558 | else |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1559 | return false; |
| 1560 | } |
Daniel Dunbar | dacdfb5 | 2011-10-31 22:50:57 +0000 | [diff] [blame] | 1561 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1562 | bool |
| 1563 | ClangASTContext::CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, uint32_t num_params) |
| 1564 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1565 | switch (op_kind) |
| 1566 | { |
| 1567 | default: |
| 1568 | break; |
| 1569 | // C++ standard allows any number of arguments to new/delete |
| 1570 | case OO_New: |
| 1571 | case OO_Array_New: |
| 1572 | case OO_Delete: |
| 1573 | case OO_Array_Delete: |
| 1574 | return true; |
| 1575 | } |
| 1576 | |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1577 | #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] | 1578 | switch (op_kind) |
| 1579 | { |
| 1580 | #include "clang/Basic/OperatorKinds.def" |
| 1581 | default: break; |
| 1582 | } |
| 1583 | return false; |
| 1584 | } |
| 1585 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1586 | clang::AccessSpecifier |
| 1587 | ClangASTContext::UnifyAccessSpecifiers (clang::AccessSpecifier lhs, clang::AccessSpecifier rhs) |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 1588 | { |
| 1589 | clang::AccessSpecifier ret = lhs; |
| 1590 | |
| 1591 | // Make the access equal to the stricter of the field and the nested field's access |
| 1592 | switch (ret) |
| 1593 | { |
| 1594 | case clang::AS_none: |
| 1595 | break; |
| 1596 | case clang::AS_private: |
| 1597 | break; |
| 1598 | case clang::AS_protected: |
| 1599 | if (rhs == AS_private) |
| 1600 | ret = AS_private; |
| 1601 | break; |
| 1602 | case clang::AS_public: |
| 1603 | ret = rhs; |
| 1604 | break; |
| 1605 | } |
| 1606 | |
| 1607 | return ret; |
| 1608 | } |
| 1609 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1610 | bool |
| 1611 | ClangASTContext::FieldIsBitfield (FieldDecl* field, uint32_t& bitfield_bit_size) |
| 1612 | { |
| 1613 | return FieldIsBitfield(getASTContext(), field, bitfield_bit_size); |
| 1614 | } |
| 1615 | |
| 1616 | bool |
| 1617 | ClangASTContext::FieldIsBitfield |
| 1618 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1619 | ASTContext *ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1620 | FieldDecl* field, |
| 1621 | uint32_t& bitfield_bit_size |
| 1622 | ) |
| 1623 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1624 | if (ast == nullptr || field == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1625 | return false; |
| 1626 | |
| 1627 | if (field->isBitField()) |
| 1628 | { |
| 1629 | Expr* bit_width_expr = field->getBitWidth(); |
| 1630 | if (bit_width_expr) |
| 1631 | { |
| 1632 | llvm::APSInt bit_width_apsint; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1633 | if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1634 | { |
| 1635 | bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX); |
| 1636 | return true; |
| 1637 | } |
| 1638 | } |
| 1639 | } |
| 1640 | return false; |
| 1641 | } |
| 1642 | |
| 1643 | bool |
| 1644 | ClangASTContext::RecordHasFields (const RecordDecl *record_decl) |
| 1645 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1646 | if (record_decl == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1647 | return false; |
| 1648 | |
| 1649 | if (!record_decl->field_empty()) |
| 1650 | return true; |
| 1651 | |
| 1652 | // No fields, lets check this is a CXX record and check the base classes |
| 1653 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 1654 | if (cxx_record_decl) |
| 1655 | { |
| 1656 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1657 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 1658 | base_class != base_class_end; |
| 1659 | ++base_class) |
| 1660 | { |
| 1661 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 1662 | if (RecordHasFields(base_class_decl)) |
| 1663 | return true; |
| 1664 | } |
| 1665 | } |
| 1666 | return false; |
| 1667 | } |
| 1668 | |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1669 | #pragma mark Objective C Classes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1670 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1671 | CompilerType |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1672 | ClangASTContext::CreateObjCClass |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1673 | ( |
| 1674 | const char *name, |
| 1675 | DeclContext *decl_ctx, |
| 1676 | bool isForwardDecl, |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1677 | bool isInternal, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1678 | ClangASTMetadata *metadata |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1679 | ) |
| 1680 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1681 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1682 | assert (ast != nullptr); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1683 | assert (name && name[0]); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1684 | if (decl_ctx == nullptr) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1685 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1686 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1687 | ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create (*ast, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1688 | decl_ctx, |
| 1689 | SourceLocation(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1690 | &ast->Idents.get(name), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1691 | nullptr, |
Pavel Labath | 67add94 | 2015-07-07 10:11:16 +0000 | [diff] [blame] | 1692 | nullptr, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1693 | SourceLocation(), |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1694 | /*isForwardDecl,*/ |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1695 | isInternal); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1696 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1697 | if (decl && metadata) |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1698 | SetMetadata(ast, decl, *metadata); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1699 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1700 | return CompilerType (ast, ast->getObjCInterfaceType(decl)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | static inline bool |
| 1704 | BaseSpecifierIsEmpty (const CXXBaseSpecifier *b) |
| 1705 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1706 | return ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()) == false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1709 | uint32_t |
| 1710 | ClangASTContext::GetNumBaseClasses (const CXXRecordDecl *cxx_record_decl, bool omit_empty_base_classes) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1711 | { |
| 1712 | uint32_t num_bases = 0; |
| 1713 | if (cxx_record_decl) |
| 1714 | { |
| 1715 | if (omit_empty_base_classes) |
| 1716 | { |
| 1717 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1718 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 1719 | base_class != base_class_end; |
| 1720 | ++base_class) |
| 1721 | { |
| 1722 | // Skip empty base classes |
| 1723 | if (omit_empty_base_classes) |
| 1724 | { |
| 1725 | if (BaseSpecifierIsEmpty (base_class)) |
| 1726 | continue; |
| 1727 | } |
| 1728 | ++num_bases; |
| 1729 | } |
| 1730 | } |
| 1731 | else |
| 1732 | num_bases = cxx_record_decl->getNumBases(); |
| 1733 | } |
| 1734 | return num_bases; |
| 1735 | } |
| 1736 | |
| 1737 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1738 | #pragma mark Namespace Declarations |
| 1739 | |
| 1740 | NamespaceDecl * |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1741 | ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *decl_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1742 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1743 | NamespaceDecl *namespace_decl = nullptr; |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1744 | ASTContext *ast = getASTContext(); |
| 1745 | TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl (); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1746 | if (decl_ctx == nullptr) |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1747 | decl_ctx = translation_unit_decl; |
| 1748 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1749 | if (name) |
| 1750 | { |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1751 | IdentifierInfo &identifier_info = ast->Idents.get(name); |
| 1752 | DeclarationName decl_name (&identifier_info); |
| 1753 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1754 | for (NamedDecl *decl : result) |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1755 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1756 | namespace_decl = dyn_cast<clang::NamespaceDecl>(decl); |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1757 | if (namespace_decl) |
| 1758 | return namespace_decl; |
| 1759 | } |
| 1760 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1761 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1762 | decl_ctx, |
| 1763 | false, |
| 1764 | SourceLocation(), |
| 1765 | SourceLocation(), |
| 1766 | &identifier_info, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1767 | nullptr); |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1768 | |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1769 | decl_ctx->addDecl (namespace_decl); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1770 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1771 | else |
| 1772 | { |
| 1773 | if (decl_ctx == translation_unit_decl) |
| 1774 | { |
| 1775 | namespace_decl = translation_unit_decl->getAnonymousNamespace(); |
| 1776 | if (namespace_decl) |
| 1777 | return namespace_decl; |
| 1778 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1779 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1780 | decl_ctx, |
| 1781 | false, |
| 1782 | SourceLocation(), |
| 1783 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1784 | nullptr, |
| 1785 | nullptr); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1786 | translation_unit_decl->setAnonymousNamespace (namespace_decl); |
| 1787 | translation_unit_decl->addDecl (namespace_decl); |
| 1788 | assert (namespace_decl == translation_unit_decl->getAnonymousNamespace()); |
| 1789 | } |
| 1790 | else |
| 1791 | { |
| 1792 | NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx); |
| 1793 | if (parent_namespace_decl) |
| 1794 | { |
| 1795 | namespace_decl = parent_namespace_decl->getAnonymousNamespace(); |
| 1796 | if (namespace_decl) |
| 1797 | return namespace_decl; |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1798 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1799 | decl_ctx, |
| 1800 | false, |
| 1801 | SourceLocation(), |
| 1802 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1803 | nullptr, |
| 1804 | nullptr); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1805 | parent_namespace_decl->setAnonymousNamespace (namespace_decl); |
| 1806 | parent_namespace_decl->addDecl (namespace_decl); |
| 1807 | assert (namespace_decl == parent_namespace_decl->getAnonymousNamespace()); |
| 1808 | } |
| 1809 | else |
| 1810 | { |
| 1811 | // BAD!!! |
| 1812 | } |
| 1813 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1814 | } |
| 1815 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1816 | VerifyDecl(namespace_decl); |
| 1817 | #endif |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1818 | return namespace_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1822 | clang::BlockDecl * |
| 1823 | ClangASTContext::CreateBlockDeclaration (clang::DeclContext *ctx) |
| 1824 | { |
| 1825 | if (ctx != nullptr) |
| 1826 | { |
| 1827 | clang::BlockDecl *decl = clang::BlockDecl::Create(*getASTContext(), ctx, clang::SourceLocation()); |
| 1828 | ctx->addDecl(decl); |
| 1829 | return decl; |
| 1830 | } |
| 1831 | return nullptr; |
| 1832 | } |
| 1833 | |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1834 | clang::DeclContext * |
| 1835 | FindLCABetweenDecls(clang::DeclContext *left, clang::DeclContext *right, clang::DeclContext *root) |
| 1836 | { |
| 1837 | if (root == nullptr) |
| 1838 | return nullptr; |
| 1839 | |
| 1840 | std::set<clang::DeclContext *> path_left; |
| 1841 | for (clang::DeclContext *d = left; d != nullptr; d = d->getParent()) |
| 1842 | path_left.insert(d); |
| 1843 | |
| 1844 | for (clang::DeclContext *d = right; d != nullptr; d = d->getParent()) |
| 1845 | if (path_left.find(d) != path_left.end()) |
| 1846 | return d; |
| 1847 | |
| 1848 | return nullptr; |
| 1849 | } |
| 1850 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1851 | clang::UsingDirectiveDecl * |
| 1852 | ClangASTContext::CreateUsingDirectiveDeclaration (clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl) |
| 1853 | { |
| 1854 | if (decl_ctx != nullptr && ns_decl != nullptr) |
| 1855 | { |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1856 | clang::TranslationUnitDecl *translation_unit = (clang::TranslationUnitDecl *)GetTranslationUnitDecl(getASTContext()); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1857 | clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(*getASTContext(), |
| 1858 | decl_ctx, |
| 1859 | clang::SourceLocation(), |
| 1860 | clang::SourceLocation(), |
| 1861 | clang::NestedNameSpecifierLoc(), |
| 1862 | clang::SourceLocation(), |
| 1863 | ns_decl, |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1864 | FindLCABetweenDecls(decl_ctx, ns_decl, translation_unit)); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1865 | decl_ctx->addDecl(using_decl); |
| 1866 | return using_decl; |
| 1867 | } |
| 1868 | return nullptr; |
| 1869 | } |
| 1870 | |
| 1871 | clang::UsingDecl * |
| 1872 | ClangASTContext::CreateUsingDeclaration (clang::DeclContext *current_decl_ctx, clang::NamedDecl *target) |
| 1873 | { |
| 1874 | if (current_decl_ctx != nullptr && target != nullptr) |
| 1875 | { |
| 1876 | clang::UsingDecl *using_decl = clang::UsingDecl::Create(*getASTContext(), |
| 1877 | current_decl_ctx, |
| 1878 | clang::SourceLocation(), |
| 1879 | clang::NestedNameSpecifierLoc(), |
| 1880 | clang::DeclarationNameInfo(), |
| 1881 | false); |
| 1882 | clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(*getASTContext(), |
| 1883 | current_decl_ctx, |
| 1884 | clang::SourceLocation(), |
| 1885 | using_decl, |
| 1886 | target); |
| 1887 | using_decl->addShadowDecl(shadow_decl); |
| 1888 | current_decl_ctx->addDecl(using_decl); |
| 1889 | return using_decl; |
| 1890 | } |
| 1891 | return nullptr; |
| 1892 | } |
| 1893 | |
| 1894 | clang::VarDecl * |
| 1895 | ClangASTContext::CreateVariableDeclaration (clang::DeclContext *decl_context, const char *name, clang::QualType type) |
| 1896 | { |
| 1897 | if (decl_context != nullptr) |
| 1898 | { |
| 1899 | clang::VarDecl *var_decl = clang::VarDecl::Create(*getASTContext(), |
| 1900 | decl_context, |
| 1901 | clang::SourceLocation(), |
| 1902 | clang::SourceLocation(), |
| 1903 | name && name[0] ? &getASTContext()->Idents.getOwn(name) : nullptr, |
| 1904 | type, |
| 1905 | nullptr, |
| 1906 | clang::SC_None); |
| 1907 | var_decl->setAccess(clang::AS_public); |
| 1908 | decl_context->addDecl(var_decl); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1909 | return var_decl; |
| 1910 | } |
| 1911 | return nullptr; |
| 1912 | } |
| 1913 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1914 | #pragma mark Function Types |
| 1915 | |
| 1916 | FunctionDecl * |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1917 | ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx, |
| 1918 | const char *name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1919 | const CompilerType &function_clang_type, |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1920 | int storage, |
| 1921 | bool is_inline) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1922 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1923 | FunctionDecl *func_decl = nullptr; |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1924 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1925 | if (decl_ctx == nullptr) |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1926 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1927 | |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1928 | |
| 1929 | const bool hasWrittenPrototype = true; |
| 1930 | const bool isConstexprSpecified = false; |
| 1931 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1932 | if (name && name[0]) |
| 1933 | { |
| 1934 | func_decl = FunctionDecl::Create (*ast, |
| 1935 | decl_ctx, |
| 1936 | SourceLocation(), |
| 1937 | SourceLocation(), |
| 1938 | DeclarationName (&ast->Idents.get(name)), |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1939 | GetQualType(function_clang_type), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1940 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 1941 | (clang::StorageClass)storage, |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1942 | is_inline, |
| 1943 | hasWrittenPrototype, |
| 1944 | isConstexprSpecified); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1945 | } |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1946 | else |
| 1947 | { |
| 1948 | func_decl = FunctionDecl::Create (*ast, |
| 1949 | decl_ctx, |
| 1950 | SourceLocation(), |
| 1951 | SourceLocation(), |
| 1952 | DeclarationName (), |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1953 | GetQualType(function_clang_type), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1954 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 1955 | (clang::StorageClass)storage, |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1956 | is_inline, |
| 1957 | hasWrittenPrototype, |
| 1958 | isConstexprSpecified); |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1959 | } |
| 1960 | if (func_decl) |
| 1961 | decl_ctx->addDecl (func_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1962 | |
| 1963 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1964 | VerifyDecl(func_decl); |
| 1965 | #endif |
| 1966 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1967 | return func_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1970 | CompilerType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1971 | ClangASTContext::CreateFunctionType (ASTContext *ast, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1972 | const CompilerType& result_type, |
| 1973 | const CompilerType *args, |
Sean Callanan | c81256a | 2010-09-16 20:40:25 +0000 | [diff] [blame] | 1974 | unsigned num_args, |
| 1975 | bool is_variadic, |
| 1976 | unsigned type_quals) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1977 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1978 | assert (ast != nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1979 | std::vector<QualType> qual_type_args; |
| 1980 | for (unsigned i=0; i<num_args; ++i) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1981 | qual_type_args.push_back (GetQualType(args[i])); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1982 | |
| 1983 | // TODO: Detect calling convention in DWARF? |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1984 | FunctionProtoType::ExtProtoInfo proto_info; |
| 1985 | proto_info.Variadic = is_variadic; |
Sylvestre Ledru | 186ca7d | 2014-08-01 12:19:15 +0000 | [diff] [blame] | 1986 | proto_info.ExceptionSpec = EST_None; |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1987 | proto_info.TypeQuals = type_quals; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1988 | proto_info.RefQualifier = RQ_None; |
Sylvestre Ledru | 186ca7d | 2014-08-01 12:19:15 +0000 | [diff] [blame] | 1989 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1990 | return CompilerType (ast, ast->getFunctionType (GetQualType(result_type), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1991 | qual_type_args, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1992 | proto_info)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | ParmVarDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1996 | ClangASTContext::CreateParameterDeclaration (const char *name, const CompilerType ¶m_type, int storage) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1997 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1998 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1999 | assert (ast != nullptr); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2000 | return ParmVarDecl::Create(*ast, |
| 2001 | ast->getTranslationUnitDecl(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2002 | SourceLocation(), |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 2003 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2004 | name && name[0] ? &ast->Idents.get(name) : nullptr, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2005 | GetQualType(param_type), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2006 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 2007 | (clang::StorageClass)storage, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2008 | nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | void |
| 2012 | ClangASTContext::SetFunctionParameters (FunctionDecl *function_decl, ParmVarDecl **params, unsigned num_params) |
| 2013 | { |
| 2014 | if (function_decl) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 2015 | function_decl->setParams (ArrayRef<ParmVarDecl*>(params, num_params)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | |
| 2019 | #pragma mark Array Types |
| 2020 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2021 | CompilerType |
| 2022 | ClangASTContext::CreateArrayType (const CompilerType &element_type, |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2023 | size_t element_count, |
| 2024 | bool is_vector) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2025 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2026 | if (element_type.IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2027 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2028 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2029 | assert (ast != nullptr); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2030 | |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2031 | if (is_vector) |
| 2032 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2033 | return CompilerType (ast, ast->getExtVectorType(GetQualType(element_type), element_count)); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2034 | } |
| 2035 | else |
| 2036 | { |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2037 | |
| 2038 | llvm::APInt ap_element_count (64, element_count); |
| 2039 | if (element_count == 0) |
| 2040 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2041 | return CompilerType (ast, ast->getIncompleteArrayType (GetQualType(element_type), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2042 | ArrayType::Normal, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2043 | 0)); |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2044 | } |
| 2045 | else |
| 2046 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2047 | return CompilerType (ast, ast->getConstantArrayType (GetQualType(element_type), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2048 | ap_element_count, |
| 2049 | ArrayType::Normal, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2050 | 0)); |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2051 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2052 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2053 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2054 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2057 | CompilerType |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2058 | ClangASTContext::GetOrCreateStructForIdentifier (const ConstString &type_name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2059 | const std::initializer_list< std::pair < const char *, CompilerType > >& type_fields, |
Enrico Granata | a449e86 | 2014-10-30 00:53:28 +0000 | [diff] [blame] | 2060 | bool packed) |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2061 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2062 | CompilerType type; |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2063 | if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid()) |
| 2064 | return type; |
| 2065 | 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] | 2066 | StartTagDeclarationDefinition(type); |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2067 | for (const auto& field : type_fields) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2068 | AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic, 0); |
Enrico Granata | a449e86 | 2014-10-30 00:53:28 +0000 | [diff] [blame] | 2069 | if (packed) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2070 | SetIsPacked(type); |
| 2071 | CompleteTagDeclarationDefinition(type); |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2072 | return type; |
| 2073 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2074 | |
| 2075 | #pragma mark Enumeration Types |
| 2076 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2077 | CompilerType |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2078 | ClangASTContext::CreateEnumerationType |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2079 | ( |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2080 | const char *name, |
| 2081 | DeclContext *decl_ctx, |
| 2082 | const Declaration &decl, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2083 | const CompilerType &integer_clang_type |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2084 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2085 | { |
| 2086 | // TODO: Do something intelligent with the Declaration object passed in |
| 2087 | // like maybe filling in the SourceLocation with it... |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2088 | ASTContext *ast = getASTContext(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2089 | |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2090 | // TODO: ask about these... |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2091 | // const bool IsScoped = false; |
| 2092 | // const bool IsFixed = false; |
| 2093 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2094 | EnumDecl *enum_decl = EnumDecl::Create (*ast, |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2095 | decl_ctx, |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2096 | SourceLocation(), |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2097 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2098 | name && name[0] ? &ast->Idents.get(name) : nullptr, |
| 2099 | nullptr, |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 2100 | false, // IsScoped |
| 2101 | false, // IsScopedUsingClassTag |
| 2102 | false); // IsFixed |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 2103 | |
| 2104 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2105 | if (enum_decl) |
Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 2106 | { |
| 2107 | // TODO: check if we should be setting the promotion type too? |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2108 | enum_decl->setIntegerType(GetQualType(integer_clang_type)); |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 2109 | |
| 2110 | enum_decl->setAccess(AS_public); // TODO respect what's in the debug info |
| 2111 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2112 | return CompilerType (ast, ast->getTagDeclType(enum_decl)); |
Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 2113 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2114 | return CompilerType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2117 | // Disable this for now since I can't seem to get a nicely formatted float |
| 2118 | // out of the APFloat class without just getting the float, double or quad |
| 2119 | // and then using a formatted print on it which defeats the purpose. We ideally |
| 2120 | // would like to get perfect string values for any kind of float semantics |
| 2121 | // so we can support remote targets. The code below also requires a patch to |
| 2122 | // llvm::APInt. |
| 2123 | //bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2124 | //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] | 2125 | //{ |
| 2126 | // uint32_t count = 0; |
| 2127 | // bool is_complex = false; |
| 2128 | // if (ClangASTContext::IsFloatingPointType (clang_type, count, is_complex)) |
| 2129 | // { |
| 2130 | // unsigned num_bytes_per_float = byte_size / count; |
| 2131 | // unsigned num_bits_per_float = num_bytes_per_float * 8; |
| 2132 | // |
| 2133 | // float_str.clear(); |
| 2134 | // uint32_t i; |
| 2135 | // for (i=0; i<count; i++) |
| 2136 | // { |
| 2137 | // APInt ap_int(num_bits_per_float, bytes + i * num_bytes_per_float, (APInt::ByteOrder)apint_byte_order); |
| 2138 | // bool is_ieee = false; |
| 2139 | // APFloat ap_float(ap_int, is_ieee); |
| 2140 | // char s[1024]; |
| 2141 | // unsigned int hex_digits = 0; |
| 2142 | // bool upper_case = false; |
| 2143 | // |
| 2144 | // if (ap_float.convertToHexString(s, hex_digits, upper_case, APFloat::rmNearestTiesToEven) > 0) |
| 2145 | // { |
| 2146 | // if (i > 0) |
| 2147 | // float_str.append(", "); |
| 2148 | // float_str.append(s); |
| 2149 | // if (i == 1 && is_complex) |
| 2150 | // float_str.append(1, 'i'); |
| 2151 | // } |
| 2152 | // } |
| 2153 | // return !float_str.empty(); |
| 2154 | // } |
| 2155 | // return false; |
| 2156 | //} |
| 2157 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2158 | CompilerType |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2159 | ClangASTContext::GetIntTypeFromBitSize (clang::ASTContext *ast, |
| 2160 | size_t bit_size, bool is_signed) |
| 2161 | { |
| 2162 | if (ast) |
| 2163 | { |
| 2164 | if (is_signed) |
| 2165 | { |
| 2166 | if (bit_size == ast->getTypeSize(ast->SignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2167 | return CompilerType(ast, ast->SignedCharTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2168 | |
| 2169 | if (bit_size == ast->getTypeSize(ast->ShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2170 | return CompilerType(ast, ast->ShortTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2171 | |
| 2172 | if (bit_size == ast->getTypeSize(ast->IntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2173 | return CompilerType(ast, ast->IntTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2174 | |
| 2175 | if (bit_size == ast->getTypeSize(ast->LongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2176 | return CompilerType(ast, ast->LongTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2177 | |
| 2178 | if (bit_size == ast->getTypeSize(ast->LongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2179 | return CompilerType(ast, ast->LongLongTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2180 | |
| 2181 | if (bit_size == ast->getTypeSize(ast->Int128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2182 | return CompilerType(ast, ast->Int128Ty); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2183 | } |
| 2184 | else |
| 2185 | { |
| 2186 | if (bit_size == ast->getTypeSize(ast->UnsignedCharTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2187 | return CompilerType(ast, ast->UnsignedCharTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2188 | |
| 2189 | if (bit_size == ast->getTypeSize(ast->UnsignedShortTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2190 | return CompilerType(ast, ast->UnsignedShortTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2191 | |
| 2192 | if (bit_size == ast->getTypeSize(ast->UnsignedIntTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2193 | return CompilerType(ast, ast->UnsignedIntTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2194 | |
| 2195 | if (bit_size == ast->getTypeSize(ast->UnsignedLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2196 | return CompilerType(ast, ast->UnsignedLongTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2197 | |
| 2198 | if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2199 | return CompilerType(ast, ast->UnsignedLongLongTy); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2200 | |
| 2201 | if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty)) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2202 | return CompilerType(ast, ast->UnsignedInt128Ty); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2203 | } |
| 2204 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2205 | return CompilerType(); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2208 | CompilerType |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2209 | ClangASTContext::GetPointerSizedIntType (clang::ASTContext *ast, bool is_signed) |
| 2210 | { |
| 2211 | if (ast) |
| 2212 | return GetIntTypeFromBitSize(ast, ast->getTypeSize(ast->VoidPtrTy), is_signed); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2213 | return CompilerType(); |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2214 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2215 | |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 2216 | bool |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2217 | ClangASTContext::GetCompleteDecl (clang::ASTContext *ast, |
| 2218 | clang::Decl *decl) |
| 2219 | { |
| 2220 | if (!decl) |
| 2221 | return false; |
| 2222 | |
| 2223 | ExternalASTSource *ast_source = ast->getExternalSource(); |
| 2224 | |
| 2225 | if (!ast_source) |
| 2226 | return false; |
| 2227 | |
| 2228 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) |
| 2229 | { |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2230 | if (tag_decl->isCompleteDefinition()) |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2231 | return true; |
| 2232 | |
| 2233 | if (!tag_decl->hasExternalLexicalStorage()) |
| 2234 | return false; |
| 2235 | |
| 2236 | ast_source->CompleteType(tag_decl); |
| 2237 | |
| 2238 | return !tag_decl->getTypeForDecl()->isIncompleteType(); |
| 2239 | } |
| 2240 | else if (clang::ObjCInterfaceDecl *objc_interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) |
| 2241 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2242 | if (objc_interface_decl->getDefinition()) |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2243 | return true; |
| 2244 | |
| 2245 | if (!objc_interface_decl->hasExternalLexicalStorage()) |
| 2246 | return false; |
| 2247 | |
| 2248 | ast_source->CompleteType(objc_interface_decl); |
| 2249 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2250 | return !objc_interface_decl->getTypeForDecl()->isIncompleteType(); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2251 | } |
| 2252 | else |
| 2253 | { |
| 2254 | return false; |
| 2255 | } |
| 2256 | } |
| 2257 | |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2258 | void |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2259 | ClangASTContext::SetMetadataAsUserID (const void *object, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2260 | user_id_t user_id) |
| 2261 | { |
| 2262 | ClangASTMetadata meta_data; |
| 2263 | meta_data.SetUserID (user_id); |
| 2264 | SetMetadata (object, meta_data); |
| 2265 | } |
| 2266 | |
| 2267 | void |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2268 | ClangASTContext::SetMetadata (clang::ASTContext *ast, |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2269 | const void *object, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2270 | ClangASTMetadata &metadata) |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2271 | { |
| 2272 | ClangExternalASTSourceCommon *external_source = |
Sean Callanan | ceeb74e | 2014-12-06 01:03:30 +0000 | [diff] [blame] | 2273 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2274 | |
| 2275 | if (external_source) |
| 2276 | external_source->SetMetadata(object, metadata); |
| 2277 | } |
| 2278 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2279 | ClangASTMetadata * |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2280 | ClangASTContext::GetMetadata (clang::ASTContext *ast, |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2281 | const void *object) |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2282 | { |
| 2283 | ClangExternalASTSourceCommon *external_source = |
Sean Callanan | ceeb74e | 2014-12-06 01:03:30 +0000 | [diff] [blame] | 2284 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2285 | |
| 2286 | if (external_source && external_source->HasMetadata(object)) |
| 2287 | return external_source->GetMetadata(object); |
| 2288 | else |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2289 | return nullptr; |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2292 | clang::DeclContext * |
| 2293 | ClangASTContext::GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl) |
| 2294 | { |
Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 2295 | return llvm::dyn_cast<clang::DeclContext>(cxx_method_decl); |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | clang::DeclContext * |
| 2299 | ClangASTContext::GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl) |
| 2300 | { |
Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 2301 | return llvm::dyn_cast<clang::DeclContext>(objc_method_decl); |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2304 | bool |
| 2305 | ClangASTContext::SetTagTypeKind (clang::QualType tag_qual_type, int kind) const |
| 2306 | { |
| 2307 | const clang::Type *clang_type = tag_qual_type.getTypePtr(); |
| 2308 | if (clang_type) |
| 2309 | { |
| 2310 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(clang_type); |
| 2311 | if (tag_type) |
| 2312 | { |
| 2313 | clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(tag_type->getDecl()); |
| 2314 | if (tag_decl) |
| 2315 | { |
| 2316 | tag_decl->setTagKind ((clang::TagDecl::TagKind)kind); |
| 2317 | return true; |
| 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | return false; |
| 2322 | } |
| 2323 | |
| 2324 | |
| 2325 | bool |
| 2326 | ClangASTContext::SetDefaultAccessForRecordFields (clang::RecordDecl* record_decl, |
| 2327 | int default_accessibility, |
| 2328 | int *assigned_accessibilities, |
| 2329 | size_t num_assigned_accessibilities) |
| 2330 | { |
| 2331 | if (record_decl) |
| 2332 | { |
| 2333 | uint32_t field_idx; |
| 2334 | clang::RecordDecl::field_iterator field, field_end; |
| 2335 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(), field_idx = 0; |
| 2336 | field != field_end; |
| 2337 | ++field, ++field_idx) |
| 2338 | { |
| 2339 | // If no accessibility was assigned, assign the correct one |
| 2340 | if (field_idx < num_assigned_accessibilities && assigned_accessibilities[field_idx] == clang::AS_none) |
| 2341 | field->setAccess ((clang::AccessSpecifier)default_accessibility); |
| 2342 | } |
| 2343 | return true; |
| 2344 | } |
| 2345 | return false; |
| 2346 | } |
| 2347 | |
| 2348 | clang::DeclContext * |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2349 | ClangASTContext::GetDeclContextForType (const CompilerType& type) |
| 2350 | { |
| 2351 | return GetDeclContextForType(GetQualType(type)); |
| 2352 | } |
| 2353 | |
| 2354 | clang::DeclContext * |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2355 | ClangASTContext::GetDeclContextForType (clang::QualType type) |
| 2356 | { |
| 2357 | if (type.isNull()) |
| 2358 | return nullptr; |
| 2359 | |
| 2360 | clang::QualType qual_type = type.getCanonicalType(); |
| 2361 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2362 | switch (type_class) |
| 2363 | { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2364 | case clang::Type::ObjCInterface: return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())->getInterface(); |
| 2365 | case clang::Type::ObjCObjectPointer: return GetDeclContextForType (llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType()); |
| 2366 | case clang::Type::Record: return llvm::cast<clang::RecordType>(qual_type)->getDecl(); |
| 2367 | case clang::Type::Enum: return llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 2368 | case clang::Type::Typedef: return GetDeclContextForType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()); |
| 2369 | case clang::Type::Elaborated: return GetDeclContextForType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); |
| 2370 | 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] | 2371 | default: |
| 2372 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2373 | } |
| 2374 | // No DeclContext in this type... |
| 2375 | return nullptr; |
| 2376 | } |
| 2377 | |
| 2378 | static bool |
| 2379 | GetCompleteQualType (clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion = true) |
| 2380 | { |
| 2381 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2382 | switch (type_class) |
| 2383 | { |
| 2384 | case clang::Type::ConstantArray: |
| 2385 | case clang::Type::IncompleteArray: |
| 2386 | case clang::Type::VariableArray: |
| 2387 | { |
| 2388 | const clang::ArrayType *array_type = llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr()); |
| 2389 | |
| 2390 | if (array_type) |
| 2391 | return GetCompleteQualType (ast, array_type->getElementType(), allow_completion); |
| 2392 | } |
| 2393 | break; |
| 2394 | |
| 2395 | case clang::Type::Record: |
| 2396 | case clang::Type::Enum: |
| 2397 | { |
| 2398 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 2399 | if (tag_type) |
| 2400 | { |
| 2401 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 2402 | if (tag_decl) |
| 2403 | { |
| 2404 | if (tag_decl->isCompleteDefinition()) |
| 2405 | return true; |
| 2406 | |
| 2407 | if (!allow_completion) |
| 2408 | return false; |
| 2409 | |
| 2410 | if (tag_decl->hasExternalLexicalStorage()) |
| 2411 | { |
| 2412 | if (ast) |
| 2413 | { |
| 2414 | clang::ExternalASTSource *external_ast_source = ast->getExternalSource(); |
| 2415 | if (external_ast_source) |
| 2416 | { |
| 2417 | external_ast_source->CompleteType(tag_decl); |
| 2418 | return !tag_type->isIncompleteType(); |
| 2419 | } |
| 2420 | } |
| 2421 | } |
| 2422 | return false; |
| 2423 | } |
| 2424 | } |
| 2425 | |
| 2426 | } |
| 2427 | break; |
| 2428 | |
| 2429 | case clang::Type::ObjCObject: |
| 2430 | case clang::Type::ObjCInterface: |
| 2431 | { |
| 2432 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 2433 | if (objc_class_type) |
| 2434 | { |
| 2435 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 2436 | // We currently can't complete objective C types through the newly added ASTContext |
| 2437 | // because it only supports TagDecl objects right now... |
| 2438 | if (class_interface_decl) |
| 2439 | { |
| 2440 | if (class_interface_decl->getDefinition()) |
| 2441 | return true; |
| 2442 | |
| 2443 | if (!allow_completion) |
| 2444 | return false; |
| 2445 | |
| 2446 | if (class_interface_decl->hasExternalLexicalStorage()) |
| 2447 | { |
| 2448 | if (ast) |
| 2449 | { |
| 2450 | clang::ExternalASTSource *external_ast_source = ast->getExternalSource(); |
| 2451 | if (external_ast_source) |
| 2452 | { |
| 2453 | external_ast_source->CompleteType (class_interface_decl); |
| 2454 | return !objc_class_type->isIncompleteType(); |
| 2455 | } |
| 2456 | } |
| 2457 | } |
| 2458 | return false; |
| 2459 | } |
| 2460 | } |
| 2461 | } |
| 2462 | break; |
| 2463 | |
| 2464 | case clang::Type::Typedef: |
| 2465 | return GetCompleteQualType (ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(), allow_completion); |
| 2466 | |
| 2467 | case clang::Type::Elaborated: |
| 2468 | return GetCompleteQualType (ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(), allow_completion); |
| 2469 | |
| 2470 | case clang::Type::Paren: |
| 2471 | return GetCompleteQualType (ast, llvm::cast<clang::ParenType>(qual_type)->desugar(), allow_completion); |
| 2472 | |
| 2473 | default: |
| 2474 | break; |
| 2475 | } |
| 2476 | |
| 2477 | return true; |
| 2478 | } |
| 2479 | |
| 2480 | static clang::ObjCIvarDecl::AccessControl |
| 2481 | ConvertAccessTypeToObjCIvarAccessControl (AccessType access) |
| 2482 | { |
| 2483 | switch (access) |
| 2484 | { |
| 2485 | case eAccessNone: return clang::ObjCIvarDecl::None; |
| 2486 | case eAccessPublic: return clang::ObjCIvarDecl::Public; |
| 2487 | case eAccessPrivate: return clang::ObjCIvarDecl::Private; |
| 2488 | case eAccessProtected: return clang::ObjCIvarDecl::Protected; |
| 2489 | case eAccessPackage: return clang::ObjCIvarDecl::Package; |
| 2490 | } |
| 2491 | return clang::ObjCIvarDecl::None; |
| 2492 | } |
| 2493 | |
| 2494 | |
| 2495 | //---------------------------------------------------------------------- |
| 2496 | // Tests |
| 2497 | //---------------------------------------------------------------------- |
| 2498 | |
| 2499 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2500 | ClangASTContext::IsAggregateType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2501 | { |
| 2502 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2503 | |
| 2504 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2505 | switch (type_class) |
| 2506 | { |
| 2507 | case clang::Type::IncompleteArray: |
| 2508 | case clang::Type::VariableArray: |
| 2509 | case clang::Type::ConstantArray: |
| 2510 | case clang::Type::ExtVector: |
| 2511 | case clang::Type::Vector: |
| 2512 | case clang::Type::Record: |
| 2513 | case clang::Type::ObjCObject: |
| 2514 | case clang::Type::ObjCInterface: |
| 2515 | return true; |
| 2516 | case clang::Type::Elaborated: |
| 2517 | return IsAggregateType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 2518 | case clang::Type::Typedef: |
| 2519 | return IsAggregateType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 2520 | case clang::Type::Paren: |
| 2521 | return IsAggregateType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 2522 | default: |
| 2523 | break; |
| 2524 | } |
| 2525 | // The clang type does have a value |
| 2526 | return false; |
| 2527 | } |
| 2528 | |
| 2529 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2530 | ClangASTContext::IsArrayType (lldb::opaque_compiler_type_t type, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2531 | CompilerType *element_type_ptr, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2532 | uint64_t *size, |
| 2533 | bool *is_incomplete) |
| 2534 | { |
| 2535 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2536 | |
| 2537 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2538 | switch (type_class) |
| 2539 | { |
| 2540 | default: |
| 2541 | break; |
| 2542 | |
| 2543 | case clang::Type::ConstantArray: |
| 2544 | if (element_type_ptr) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2545 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2546 | if (size) |
| 2547 | *size = llvm::cast<clang::ConstantArrayType>(qual_type)->getSize().getLimitedValue(ULLONG_MAX); |
| 2548 | return true; |
| 2549 | |
| 2550 | case clang::Type::IncompleteArray: |
| 2551 | if (element_type_ptr) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2552 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2553 | if (size) |
| 2554 | *size = 0; |
| 2555 | if (is_incomplete) |
| 2556 | *is_incomplete = true; |
| 2557 | return true; |
| 2558 | |
| 2559 | case clang::Type::VariableArray: |
| 2560 | if (element_type_ptr) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2561 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::VariableArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2562 | if (size) |
| 2563 | *size = 0; |
| 2564 | return true; |
| 2565 | |
| 2566 | case clang::Type::DependentSizedArray: |
| 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::DependentSizedArrayType>(qual_type)->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2569 | if (size) |
| 2570 | *size = 0; |
| 2571 | return true; |
| 2572 | |
| 2573 | case clang::Type::Typedef: |
| 2574 | return IsArrayType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 2575 | element_type_ptr, |
| 2576 | size, |
| 2577 | is_incomplete); |
| 2578 | case clang::Type::Elaborated: |
| 2579 | return IsArrayType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 2580 | element_type_ptr, |
| 2581 | size, |
| 2582 | is_incomplete); |
| 2583 | case clang::Type::Paren: |
| 2584 | return IsArrayType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 2585 | element_type_ptr, |
| 2586 | size, |
| 2587 | is_incomplete); |
| 2588 | } |
| 2589 | if (element_type_ptr) |
| 2590 | element_type_ptr->Clear(); |
| 2591 | if (size) |
| 2592 | *size = 0; |
| 2593 | if (is_incomplete) |
| 2594 | *is_incomplete = false; |
Bruce Mitchener | 778e7ab | 2015-09-16 00:00:16 +0000 | [diff] [blame] | 2595 | return false; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2599 | ClangASTContext::IsVectorType (lldb::opaque_compiler_type_t type, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2600 | CompilerType *element_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2601 | uint64_t *size) |
| 2602 | { |
| 2603 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2604 | |
| 2605 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2606 | switch (type_class) |
| 2607 | { |
| 2608 | case clang::Type::Vector: |
| 2609 | { |
| 2610 | const clang::VectorType *vector_type = qual_type->getAs<clang::VectorType>(); |
| 2611 | if (vector_type) |
| 2612 | { |
| 2613 | if (size) |
| 2614 | *size = vector_type->getNumElements(); |
| 2615 | if (element_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2616 | *element_type = CompilerType(getASTContext(), vector_type->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2617 | } |
| 2618 | return true; |
| 2619 | } |
| 2620 | break; |
| 2621 | case clang::Type::ExtVector: |
| 2622 | { |
| 2623 | const clang::ExtVectorType *ext_vector_type = qual_type->getAs<clang::ExtVectorType>(); |
| 2624 | if (ext_vector_type) |
| 2625 | { |
| 2626 | if (size) |
| 2627 | *size = ext_vector_type->getNumElements(); |
| 2628 | if (element_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2629 | *element_type = CompilerType(getASTContext(), ext_vector_type->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2630 | } |
| 2631 | return true; |
| 2632 | } |
| 2633 | default: |
| 2634 | break; |
| 2635 | } |
| 2636 | return false; |
| 2637 | } |
| 2638 | |
| 2639 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2640 | ClangASTContext::IsRuntimeGeneratedType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2641 | { |
| 2642 | clang::DeclContext* decl_ctx = ClangASTContext::GetASTContext(getASTContext())->GetDeclContextForType(GetQualType(type)); |
| 2643 | if (!decl_ctx) |
| 2644 | return false; |
| 2645 | |
| 2646 | if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx)) |
| 2647 | return false; |
| 2648 | |
| 2649 | clang::ObjCInterfaceDecl *result_iface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx); |
| 2650 | |
| 2651 | ClangASTMetadata* ast_metadata = ClangASTContext::GetMetadata(getASTContext(), result_iface_decl); |
| 2652 | if (!ast_metadata) |
| 2653 | return false; |
| 2654 | return (ast_metadata->GetISAPtr() != 0); |
| 2655 | } |
| 2656 | |
| 2657 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2658 | ClangASTContext::IsCharType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2659 | { |
| 2660 | return GetQualType(type).getUnqualifiedType()->isCharType(); |
| 2661 | } |
| 2662 | |
| 2663 | |
| 2664 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2665 | ClangASTContext::IsCompleteType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2666 | { |
| 2667 | const bool allow_completion = false; |
| 2668 | return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion); |
| 2669 | } |
| 2670 | |
| 2671 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2672 | ClangASTContext::IsConst(lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2673 | { |
| 2674 | return GetQualType(type).isConstQualified(); |
| 2675 | } |
| 2676 | |
| 2677 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2678 | ClangASTContext::IsCStringType (lldb::opaque_compiler_type_t type, uint32_t &length) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2679 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2680 | CompilerType pointee_or_element_clang_type; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2681 | length = 0; |
| 2682 | Flags type_flags (GetTypeInfo (type, &pointee_or_element_clang_type)); |
| 2683 | |
| 2684 | if (!pointee_or_element_clang_type.IsValid()) |
| 2685 | return false; |
| 2686 | |
| 2687 | if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer)) |
| 2688 | { |
| 2689 | if (pointee_or_element_clang_type.IsCharType()) |
| 2690 | { |
| 2691 | if (type_flags.Test (eTypeIsArray)) |
| 2692 | { |
| 2693 | // We know the size of the array and it could be a C string |
| 2694 | // since it is an array of characters |
| 2695 | length = llvm::cast<clang::ConstantArrayType>(GetCanonicalQualType(type).getTypePtr())->getSize().getLimitedValue(); |
| 2696 | } |
| 2697 | return true; |
| 2698 | |
| 2699 | } |
| 2700 | } |
| 2701 | return false; |
| 2702 | } |
| 2703 | |
| 2704 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2705 | ClangASTContext::IsFunctionType (lldb::opaque_compiler_type_t type, bool *is_variadic_ptr) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2706 | { |
| 2707 | if (type) |
| 2708 | { |
| 2709 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2710 | |
| 2711 | if (qual_type->isFunctionType()) |
| 2712 | { |
| 2713 | if (is_variadic_ptr) |
| 2714 | { |
| 2715 | const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 2716 | if (function_proto_type) |
| 2717 | *is_variadic_ptr = function_proto_type->isVariadic(); |
| 2718 | else |
| 2719 | *is_variadic_ptr = false; |
| 2720 | } |
| 2721 | return true; |
| 2722 | } |
| 2723 | |
| 2724 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2725 | switch (type_class) |
| 2726 | { |
| 2727 | default: |
| 2728 | break; |
| 2729 | case clang::Type::Typedef: |
| 2730 | return IsFunctionType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), nullptr); |
| 2731 | case clang::Type::Elaborated: |
| 2732 | return IsFunctionType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), nullptr); |
| 2733 | case clang::Type::Paren: |
| 2734 | return IsFunctionType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), nullptr); |
| 2735 | case clang::Type::LValueReference: |
| 2736 | case clang::Type::RValueReference: |
| 2737 | { |
| 2738 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 2739 | if (reference_type) |
| 2740 | return IsFunctionType(reference_type->getPointeeType().getAsOpaquePtr(), nullptr); |
| 2741 | } |
| 2742 | break; |
| 2743 | } |
| 2744 | } |
| 2745 | return false; |
| 2746 | } |
| 2747 | |
| 2748 | // Used to detect "Homogeneous Floating-point Aggregates" |
| 2749 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2750 | ClangASTContext::IsHomogeneousAggregate (lldb::opaque_compiler_type_t type, CompilerType* base_type_ptr) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2751 | { |
| 2752 | if (!type) |
| 2753 | return 0; |
| 2754 | |
| 2755 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 2756 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2757 | switch (type_class) |
| 2758 | { |
| 2759 | case clang::Type::Record: |
| 2760 | if (GetCompleteType (type)) |
| 2761 | { |
| 2762 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 2763 | if (cxx_record_decl) |
| 2764 | { |
| 2765 | if (cxx_record_decl->getNumBases() || |
| 2766 | cxx_record_decl->isDynamicClass()) |
| 2767 | return 0; |
| 2768 | } |
| 2769 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 2770 | if (record_type) |
| 2771 | { |
| 2772 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 2773 | if (record_decl) |
| 2774 | { |
| 2775 | // We are looking for a structure that contains only floating point types |
| 2776 | clang::RecordDecl::field_iterator field_pos, field_end = record_decl->field_end(); |
| 2777 | uint32_t num_fields = 0; |
| 2778 | bool is_hva = false; |
| 2779 | bool is_hfa = false; |
| 2780 | clang::QualType base_qual_type; |
| 2781 | for (field_pos = record_decl->field_begin(); field_pos != field_end; ++field_pos) |
| 2782 | { |
| 2783 | clang::QualType field_qual_type = field_pos->getType(); |
| 2784 | if (field_qual_type->isFloatingType()) |
| 2785 | { |
| 2786 | if (field_qual_type->isComplexType()) |
| 2787 | return 0; |
| 2788 | else |
| 2789 | { |
| 2790 | if (num_fields == 0) |
| 2791 | base_qual_type = field_qual_type; |
| 2792 | else |
| 2793 | { |
| 2794 | if (is_hva) |
| 2795 | return 0; |
| 2796 | is_hfa = true; |
| 2797 | if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr()) |
| 2798 | return 0; |
| 2799 | } |
| 2800 | } |
| 2801 | } |
| 2802 | else if (field_qual_type->isVectorType() || field_qual_type->isExtVectorType()) |
| 2803 | { |
| 2804 | const clang::VectorType *array = field_qual_type.getTypePtr()->getAs<clang::VectorType>(); |
| 2805 | if (array && array->getNumElements() <= 4) |
| 2806 | { |
| 2807 | if (num_fields == 0) |
| 2808 | base_qual_type = array->getElementType(); |
| 2809 | else |
| 2810 | { |
| 2811 | if (is_hfa) |
| 2812 | return 0; |
| 2813 | is_hva = true; |
| 2814 | if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr()) |
| 2815 | return 0; |
| 2816 | } |
| 2817 | } |
| 2818 | else |
| 2819 | return 0; |
| 2820 | } |
| 2821 | else |
| 2822 | return 0; |
| 2823 | ++num_fields; |
| 2824 | } |
| 2825 | if (base_type_ptr) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2826 | *base_type_ptr = CompilerType (getASTContext(), base_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2827 | return num_fields; |
| 2828 | } |
| 2829 | } |
| 2830 | } |
| 2831 | break; |
| 2832 | |
| 2833 | case clang::Type::Typedef: |
| 2834 | return IsHomogeneousAggregate(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), base_type_ptr); |
| 2835 | |
| 2836 | case clang::Type::Elaborated: |
| 2837 | return IsHomogeneousAggregate(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), base_type_ptr); |
| 2838 | default: |
| 2839 | break; |
| 2840 | } |
| 2841 | return 0; |
| 2842 | } |
| 2843 | |
| 2844 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2845 | ClangASTContext::GetNumberOfFunctionArguments (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2846 | { |
| 2847 | if (type) |
| 2848 | { |
| 2849 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2850 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 2851 | if (func) |
| 2852 | return func->getNumParams(); |
| 2853 | } |
| 2854 | return 0; |
| 2855 | } |
| 2856 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2857 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2858 | ClangASTContext::GetFunctionArgumentAtIndex (lldb::opaque_compiler_type_t type, const size_t index) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2859 | { |
| 2860 | if (type) |
| 2861 | { |
| 2862 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2863 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 2864 | if (func) |
| 2865 | { |
| 2866 | if (index < func->getNumParams()) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2867 | return CompilerType(getASTContext(), func->getParamType(index)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2868 | } |
| 2869 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2870 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2874 | ClangASTContext::IsFunctionPointerType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2875 | { |
| 2876 | if (type) |
| 2877 | { |
| 2878 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2879 | |
| 2880 | if (qual_type->isFunctionPointerType()) |
| 2881 | return true; |
| 2882 | |
| 2883 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2884 | switch (type_class) |
| 2885 | { |
| 2886 | default: |
| 2887 | break; |
| 2888 | case clang::Type::Typedef: |
| 2889 | return IsFunctionPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 2890 | case clang::Type::Elaborated: |
| 2891 | return IsFunctionPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 2892 | case clang::Type::Paren: |
| 2893 | return IsFunctionPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 2894 | |
| 2895 | case clang::Type::LValueReference: |
| 2896 | case clang::Type::RValueReference: |
| 2897 | { |
| 2898 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 2899 | if (reference_type) |
| 2900 | return IsFunctionPointerType(reference_type->getPointeeType().getAsOpaquePtr()); |
| 2901 | } |
| 2902 | break; |
| 2903 | } |
| 2904 | } |
| 2905 | return false; |
| 2906 | |
| 2907 | } |
| 2908 | |
| 2909 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2910 | ClangASTContext::IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_signed) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2911 | { |
| 2912 | if (!type) |
| 2913 | return false; |
| 2914 | |
| 2915 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2916 | const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()); |
| 2917 | |
| 2918 | if (builtin_type) |
| 2919 | { |
| 2920 | if (builtin_type->isInteger()) |
| 2921 | { |
| 2922 | is_signed = builtin_type->isSignedInteger(); |
| 2923 | return true; |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | return false; |
| 2928 | } |
| 2929 | |
| 2930 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2931 | ClangASTContext::IsPointerType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2932 | { |
| 2933 | if (type) |
| 2934 | { |
| 2935 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2936 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2937 | switch (type_class) |
| 2938 | { |
| 2939 | case clang::Type::Builtin: |
| 2940 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 2941 | { |
| 2942 | default: |
| 2943 | break; |
| 2944 | case clang::BuiltinType::ObjCId: |
| 2945 | case clang::BuiltinType::ObjCClass: |
| 2946 | return true; |
| 2947 | } |
| 2948 | return false; |
| 2949 | case clang::Type::ObjCObjectPointer: |
| 2950 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2951 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2952 | return true; |
| 2953 | case clang::Type::BlockPointer: |
| 2954 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2955 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2956 | return true; |
| 2957 | case clang::Type::Pointer: |
| 2958 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2959 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2960 | return true; |
| 2961 | case clang::Type::MemberPointer: |
| 2962 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2963 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2964 | return true; |
| 2965 | case clang::Type::Typedef: |
| 2966 | return IsPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type); |
| 2967 | case clang::Type::Elaborated: |
| 2968 | return IsPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type); |
| 2969 | case clang::Type::Paren: |
| 2970 | return IsPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type); |
| 2971 | default: |
| 2972 | break; |
| 2973 | } |
| 2974 | } |
| 2975 | if (pointee_type) |
| 2976 | pointee_type->Clear(); |
| 2977 | return false; |
| 2978 | } |
| 2979 | |
| 2980 | |
| 2981 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2982 | ClangASTContext::IsPointerOrReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2983 | { |
| 2984 | if (type) |
| 2985 | { |
| 2986 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 2987 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2988 | switch (type_class) |
| 2989 | { |
| 2990 | case clang::Type::Builtin: |
| 2991 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 2992 | { |
| 2993 | default: |
| 2994 | break; |
| 2995 | case clang::BuiltinType::ObjCId: |
| 2996 | case clang::BuiltinType::ObjCClass: |
| 2997 | return true; |
| 2998 | } |
| 2999 | return false; |
| 3000 | case clang::Type::ObjCObjectPointer: |
| 3001 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3002 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3003 | return true; |
| 3004 | case clang::Type::BlockPointer: |
| 3005 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3006 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3007 | return true; |
| 3008 | case clang::Type::Pointer: |
| 3009 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3010 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3011 | return true; |
| 3012 | case clang::Type::MemberPointer: |
| 3013 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3014 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3015 | return true; |
| 3016 | case clang::Type::LValueReference: |
| 3017 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3018 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3019 | return true; |
| 3020 | case clang::Type::RValueReference: |
| 3021 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3022 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3023 | return true; |
| 3024 | case clang::Type::Typedef: |
| 3025 | return IsPointerOrReferenceType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type); |
| 3026 | case clang::Type::Elaborated: |
| 3027 | return IsPointerOrReferenceType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type); |
| 3028 | case clang::Type::Paren: |
| 3029 | return IsPointerOrReferenceType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type); |
| 3030 | default: |
| 3031 | break; |
| 3032 | } |
| 3033 | } |
| 3034 | if (pointee_type) |
| 3035 | pointee_type->Clear(); |
| 3036 | return false; |
| 3037 | } |
| 3038 | |
| 3039 | |
| 3040 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3041 | 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] | 3042 | { |
| 3043 | if (type) |
| 3044 | { |
| 3045 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3046 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3047 | |
| 3048 | switch (type_class) |
| 3049 | { |
| 3050 | case clang::Type::LValueReference: |
| 3051 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3052 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3053 | if (is_rvalue) |
| 3054 | *is_rvalue = false; |
| 3055 | return true; |
| 3056 | case clang::Type::RValueReference: |
| 3057 | if (pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3058 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3059 | if (is_rvalue) |
| 3060 | *is_rvalue = true; |
| 3061 | return true; |
| 3062 | case clang::Type::Typedef: |
| 3063 | return IsReferenceType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type, is_rvalue); |
| 3064 | case clang::Type::Elaborated: |
| 3065 | return IsReferenceType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type, is_rvalue); |
| 3066 | case clang::Type::Paren: |
| 3067 | return IsReferenceType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type, is_rvalue); |
| 3068 | |
| 3069 | default: |
| 3070 | break; |
| 3071 | } |
| 3072 | } |
| 3073 | if (pointee_type) |
| 3074 | pointee_type->Clear(); |
| 3075 | return false; |
| 3076 | } |
| 3077 | |
| 3078 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3079 | 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] | 3080 | { |
| 3081 | if (type) |
| 3082 | { |
| 3083 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3084 | |
| 3085 | if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal())) |
| 3086 | { |
| 3087 | clang::BuiltinType::Kind kind = BT->getKind(); |
| 3088 | if (kind >= clang::BuiltinType::Float && kind <= clang::BuiltinType::LongDouble) |
| 3089 | { |
| 3090 | count = 1; |
| 3091 | is_complex = false; |
| 3092 | return true; |
| 3093 | } |
| 3094 | } |
| 3095 | else if (const clang::ComplexType *CT = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal())) |
| 3096 | { |
| 3097 | if (IsFloatingPointType (CT->getElementType().getAsOpaquePtr(), count, is_complex)) |
| 3098 | { |
| 3099 | count = 2; |
| 3100 | is_complex = true; |
| 3101 | return true; |
| 3102 | } |
| 3103 | } |
| 3104 | else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal())) |
| 3105 | { |
| 3106 | if (IsFloatingPointType (VT->getElementType().getAsOpaquePtr(), count, is_complex)) |
| 3107 | { |
| 3108 | count = VT->getNumElements(); |
| 3109 | is_complex = false; |
| 3110 | return true; |
| 3111 | } |
| 3112 | } |
| 3113 | } |
| 3114 | count = 0; |
| 3115 | is_complex = false; |
| 3116 | return false; |
| 3117 | } |
| 3118 | |
| 3119 | |
| 3120 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3121 | ClangASTContext::IsDefined(lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3122 | { |
| 3123 | if (!type) |
| 3124 | return false; |
| 3125 | |
| 3126 | clang::QualType qual_type(GetQualType(type)); |
| 3127 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 3128 | if (tag_type) |
| 3129 | { |
| 3130 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 3131 | if (tag_decl) |
| 3132 | return tag_decl->isCompleteDefinition(); |
| 3133 | return false; |
| 3134 | } |
| 3135 | else |
| 3136 | { |
| 3137 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 3138 | if (objc_class_type) |
| 3139 | { |
| 3140 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 3141 | if (class_interface_decl) |
| 3142 | return class_interface_decl->getDefinition() != nullptr; |
| 3143 | return false; |
| 3144 | } |
| 3145 | } |
| 3146 | return true; |
| 3147 | } |
| 3148 | |
| 3149 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3150 | ClangASTContext::IsObjCClassType (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3151 | { |
| 3152 | if (type) |
| 3153 | { |
| 3154 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3155 | |
| 3156 | const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); |
| 3157 | |
| 3158 | if (obj_pointer_type) |
| 3159 | return obj_pointer_type->isObjCClassType(); |
| 3160 | } |
| 3161 | return false; |
| 3162 | } |
| 3163 | |
| 3164 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3165 | ClangASTContext::IsObjCObjectOrInterfaceType (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3166 | { |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3167 | if (IsClangType(type)) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3168 | return GetCanonicalQualType(type)->isObjCObjectOrInterfaceType(); |
| 3169 | return false; |
| 3170 | } |
| 3171 | |
| 3172 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3173 | ClangASTContext::IsPolymorphicClass (lldb::opaque_compiler_type_t 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 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3179 | switch (type_class) |
| 3180 | { |
| 3181 | case clang::Type::Record: |
| 3182 | if (GetCompleteType(type)) |
| 3183 | { |
| 3184 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3185 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3186 | if (record_decl) |
| 3187 | { |
| 3188 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 3189 | if (cxx_record_decl) |
| 3190 | return cxx_record_decl->isPolymorphic(); |
| 3191 | } |
| 3192 | } |
| 3193 | break; |
| 3194 | |
| 3195 | default: |
| 3196 | break; |
| 3197 | } |
| 3198 | } |
| 3199 | return false; |
| 3200 | } |
| 3201 | |
| 3202 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3203 | ClangASTContext::IsPossibleDynamicType (lldb::opaque_compiler_type_t type, CompilerType *dynamic_pointee_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3204 | bool check_cplusplus, |
| 3205 | bool check_objc) |
| 3206 | { |
| 3207 | clang::QualType pointee_qual_type; |
| 3208 | if (type) |
| 3209 | { |
| 3210 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3211 | bool success = false; |
| 3212 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3213 | switch (type_class) |
| 3214 | { |
| 3215 | case clang::Type::Builtin: |
| 3216 | if (check_objc && llvm::cast<clang::BuiltinType>(qual_type)->getKind() == clang::BuiltinType::ObjCId) |
| 3217 | { |
| 3218 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3219 | dynamic_pointee_type->SetCompilerType(this, type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3220 | return true; |
| 3221 | } |
| 3222 | break; |
| 3223 | |
| 3224 | case clang::Type::ObjCObjectPointer: |
| 3225 | if (check_objc) |
| 3226 | { |
| 3227 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3228 | dynamic_pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3229 | return true; |
| 3230 | } |
| 3231 | break; |
| 3232 | |
| 3233 | case clang::Type::Pointer: |
| 3234 | pointee_qual_type = llvm::cast<clang::PointerType>(qual_type)->getPointeeType(); |
| 3235 | success = true; |
| 3236 | break; |
| 3237 | |
| 3238 | case clang::Type::LValueReference: |
| 3239 | case clang::Type::RValueReference: |
| 3240 | pointee_qual_type = llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType(); |
| 3241 | success = true; |
| 3242 | break; |
| 3243 | |
| 3244 | case clang::Type::Typedef: |
| 3245 | return IsPossibleDynamicType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 3246 | dynamic_pointee_type, |
| 3247 | check_cplusplus, |
| 3248 | check_objc); |
| 3249 | |
| 3250 | case clang::Type::Elaborated: |
| 3251 | return IsPossibleDynamicType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 3252 | dynamic_pointee_type, |
| 3253 | check_cplusplus, |
| 3254 | check_objc); |
| 3255 | |
| 3256 | case clang::Type::Paren: |
| 3257 | return IsPossibleDynamicType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), |
| 3258 | dynamic_pointee_type, |
| 3259 | check_cplusplus, |
| 3260 | check_objc); |
| 3261 | default: |
| 3262 | break; |
| 3263 | } |
| 3264 | |
| 3265 | if (success) |
| 3266 | { |
| 3267 | // Check to make sure what we are pointing too is a possible dynamic C++ type |
| 3268 | // We currently accept any "void *" (in case we have a class that has been |
| 3269 | // watered down to an opaque pointer) and virtual C++ classes. |
| 3270 | const clang::Type::TypeClass pointee_type_class = pointee_qual_type.getCanonicalType()->getTypeClass(); |
| 3271 | switch (pointee_type_class) |
| 3272 | { |
| 3273 | case clang::Type::Builtin: |
| 3274 | switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) |
| 3275 | { |
| 3276 | case clang::BuiltinType::UnknownAny: |
| 3277 | case clang::BuiltinType::Void: |
| 3278 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3279 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3280 | return true; |
Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 3281 | default: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3282 | break; |
| 3283 | } |
| 3284 | break; |
| 3285 | |
| 3286 | case clang::Type::Record: |
| 3287 | if (check_cplusplus) |
| 3288 | { |
| 3289 | clang::CXXRecordDecl *cxx_record_decl = pointee_qual_type->getAsCXXRecordDecl(); |
| 3290 | if (cxx_record_decl) |
| 3291 | { |
| 3292 | bool is_complete = cxx_record_decl->isCompleteDefinition(); |
| 3293 | |
| 3294 | if (is_complete) |
| 3295 | success = cxx_record_decl->isDynamicClass(); |
| 3296 | else |
| 3297 | { |
| 3298 | ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), cxx_record_decl); |
| 3299 | if (metadata) |
| 3300 | success = metadata->GetIsDynamicCXXType(); |
| 3301 | else |
| 3302 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3303 | is_complete = CompilerType(getASTContext(), pointee_qual_type).GetCompleteType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3304 | if (is_complete) |
| 3305 | success = cxx_record_decl->isDynamicClass(); |
| 3306 | else |
| 3307 | success = false; |
| 3308 | } |
| 3309 | } |
| 3310 | |
| 3311 | if (success) |
| 3312 | { |
| 3313 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3314 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3315 | return true; |
| 3316 | } |
| 3317 | } |
| 3318 | } |
| 3319 | break; |
| 3320 | |
| 3321 | case clang::Type::ObjCObject: |
| 3322 | case clang::Type::ObjCInterface: |
| 3323 | if (check_objc) |
| 3324 | { |
| 3325 | if (dynamic_pointee_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3326 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3327 | return true; |
| 3328 | } |
| 3329 | break; |
| 3330 | |
| 3331 | default: |
| 3332 | break; |
| 3333 | } |
| 3334 | } |
| 3335 | } |
| 3336 | if (dynamic_pointee_type) |
| 3337 | dynamic_pointee_type->Clear(); |
| 3338 | return false; |
| 3339 | } |
| 3340 | |
| 3341 | |
| 3342 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3343 | ClangASTContext::IsScalarType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3344 | { |
| 3345 | if (!type) |
| 3346 | return false; |
| 3347 | |
| 3348 | return (GetTypeInfo (type, nullptr) & eTypeIsScalar) != 0; |
| 3349 | } |
| 3350 | |
| 3351 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3352 | ClangASTContext::IsTypedefType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3353 | { |
| 3354 | if (!type) |
| 3355 | return false; |
| 3356 | return GetQualType(type)->getTypeClass() == clang::Type::Typedef; |
| 3357 | } |
| 3358 | |
| 3359 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3360 | ClangASTContext::IsVoidType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3361 | { |
| 3362 | if (!type) |
| 3363 | return false; |
| 3364 | return GetCanonicalQualType(type)->isVoidType(); |
| 3365 | } |
| 3366 | |
| 3367 | bool |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 3368 | ClangASTContext::SupportsLanguage (lldb::LanguageType language) |
| 3369 | { |
| 3370 | return ClangASTContextSupportsLanguage(language); |
| 3371 | } |
| 3372 | |
| 3373 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3374 | ClangASTContext::GetCXXClassName (const CompilerType& type, std::string &class_name) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3375 | { |
| 3376 | if (type) |
| 3377 | { |
| 3378 | clang::QualType qual_type (GetCanonicalQualType(type)); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3379 | if (!qual_type.isNull()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3380 | { |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3381 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 3382 | if (cxx_record_decl) |
| 3383 | { |
| 3384 | class_name.assign(cxx_record_decl->getIdentifier()->getNameStart()); |
| 3385 | return true; |
| 3386 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3387 | } |
| 3388 | } |
| 3389 | class_name.clear(); |
| 3390 | return false; |
| 3391 | } |
| 3392 | |
| 3393 | |
| 3394 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3395 | ClangASTContext::IsCXXClassType (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3396 | { |
| 3397 | if (!type) |
| 3398 | return false; |
| 3399 | |
| 3400 | clang::QualType qual_type (GetCanonicalQualType(type)); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3401 | if (!qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3402 | return true; |
| 3403 | return false; |
| 3404 | } |
| 3405 | |
| 3406 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3407 | ClangASTContext::IsBeingDefined (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3408 | { |
| 3409 | if (!type) |
| 3410 | return false; |
| 3411 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3412 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type); |
| 3413 | if (tag_type) |
| 3414 | return tag_type->isBeingDefined(); |
| 3415 | return false; |
| 3416 | } |
| 3417 | |
| 3418 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3419 | ClangASTContext::IsObjCObjectPointerType (const CompilerType& type, CompilerType *class_type_ptr) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3420 | { |
| 3421 | if (!type) |
| 3422 | return false; |
| 3423 | |
| 3424 | clang::QualType qual_type (GetCanonicalQualType(type)); |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3425 | |
| 3426 | if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3427 | { |
| 3428 | if (class_type_ptr) |
| 3429 | { |
| 3430 | if (!qual_type->isObjCClassType() && |
| 3431 | !qual_type->isObjCIdType()) |
| 3432 | { |
| 3433 | const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); |
| 3434 | if (obj_pointer_type == nullptr) |
| 3435 | class_type_ptr->Clear(); |
| 3436 | else |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3437 | 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] | 3438 | } |
| 3439 | } |
| 3440 | return true; |
| 3441 | } |
| 3442 | if (class_type_ptr) |
| 3443 | class_type_ptr->Clear(); |
| 3444 | return false; |
| 3445 | } |
| 3446 | |
| 3447 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3448 | ClangASTContext::GetObjCClassName (const CompilerType& type, std::string &class_name) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3449 | { |
| 3450 | if (!type) |
| 3451 | return false; |
| 3452 | |
| 3453 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 3454 | |
| 3455 | const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 3456 | if (object_type) |
| 3457 | { |
| 3458 | const clang::ObjCInterfaceDecl *interface = object_type->getInterface(); |
| 3459 | if (interface) |
| 3460 | { |
| 3461 | class_name = interface->getNameAsString(); |
| 3462 | return true; |
| 3463 | } |
| 3464 | } |
| 3465 | return false; |
| 3466 | } |
| 3467 | |
| 3468 | |
| 3469 | //---------------------------------------------------------------------- |
| 3470 | // Type Completion |
| 3471 | //---------------------------------------------------------------------- |
| 3472 | |
| 3473 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3474 | ClangASTContext::GetCompleteType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3475 | { |
| 3476 | if (!type) |
| 3477 | return false; |
| 3478 | const bool allow_completion = true; |
| 3479 | return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion); |
| 3480 | } |
| 3481 | |
| 3482 | ConstString |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3483 | ClangASTContext::GetTypeName (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3484 | { |
| 3485 | std::string type_name; |
| 3486 | if (type) |
| 3487 | { |
| 3488 | clang::PrintingPolicy printing_policy (getASTContext()->getPrintingPolicy()); |
| 3489 | clang::QualType qual_type(GetQualType(type)); |
| 3490 | printing_policy.SuppressTagKeyword = true; |
| 3491 | printing_policy.LangOpts.WChar = true; |
| 3492 | const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>(); |
| 3493 | if (typedef_type) |
| 3494 | { |
| 3495 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 3496 | type_name = typedef_decl->getQualifiedNameAsString(); |
| 3497 | } |
| 3498 | else |
| 3499 | { |
| 3500 | type_name = qual_type.getAsString(printing_policy); |
| 3501 | } |
| 3502 | } |
| 3503 | return ConstString(type_name); |
| 3504 | } |
| 3505 | |
| 3506 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3507 | 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] | 3508 | { |
| 3509 | if (!type) |
| 3510 | return 0; |
| 3511 | |
| 3512 | if (pointee_or_element_clang_type) |
| 3513 | pointee_or_element_clang_type->Clear(); |
| 3514 | |
| 3515 | clang::QualType qual_type (GetQualType(type)); |
| 3516 | |
| 3517 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3518 | switch (type_class) |
| 3519 | { |
| 3520 | case clang::Type::Builtin: |
| 3521 | { |
| 3522 | const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()); |
| 3523 | |
| 3524 | uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue; |
| 3525 | switch (builtin_type->getKind()) |
| 3526 | { |
| 3527 | case clang::BuiltinType::ObjCId: |
| 3528 | case clang::BuiltinType::ObjCClass: |
| 3529 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3530 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->ObjCBuiltinClassTy); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3531 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; |
| 3532 | break; |
| 3533 | |
| 3534 | case clang::BuiltinType::ObjCSel: |
| 3535 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3536 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->CharTy); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3537 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; |
| 3538 | break; |
| 3539 | |
| 3540 | case clang::BuiltinType::Bool: |
| 3541 | case clang::BuiltinType::Char_U: |
| 3542 | case clang::BuiltinType::UChar: |
| 3543 | case clang::BuiltinType::WChar_U: |
| 3544 | case clang::BuiltinType::Char16: |
| 3545 | case clang::BuiltinType::Char32: |
| 3546 | case clang::BuiltinType::UShort: |
| 3547 | case clang::BuiltinType::UInt: |
| 3548 | case clang::BuiltinType::ULong: |
| 3549 | case clang::BuiltinType::ULongLong: |
| 3550 | case clang::BuiltinType::UInt128: |
| 3551 | case clang::BuiltinType::Char_S: |
| 3552 | case clang::BuiltinType::SChar: |
| 3553 | case clang::BuiltinType::WChar_S: |
| 3554 | case clang::BuiltinType::Short: |
| 3555 | case clang::BuiltinType::Int: |
| 3556 | case clang::BuiltinType::Long: |
| 3557 | case clang::BuiltinType::LongLong: |
| 3558 | case clang::BuiltinType::Int128: |
| 3559 | case clang::BuiltinType::Float: |
| 3560 | case clang::BuiltinType::Double: |
| 3561 | case clang::BuiltinType::LongDouble: |
| 3562 | builtin_type_flags |= eTypeIsScalar; |
| 3563 | if (builtin_type->isInteger()) |
| 3564 | { |
| 3565 | builtin_type_flags |= eTypeIsInteger; |
| 3566 | if (builtin_type->isSignedInteger()) |
| 3567 | builtin_type_flags |= eTypeIsSigned; |
| 3568 | } |
| 3569 | else if (builtin_type->isFloatingPoint()) |
| 3570 | builtin_type_flags |= eTypeIsFloat; |
| 3571 | break; |
| 3572 | default: |
| 3573 | break; |
| 3574 | } |
| 3575 | return builtin_type_flags; |
| 3576 | } |
| 3577 | |
| 3578 | case clang::Type::BlockPointer: |
| 3579 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3580 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3581 | return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock; |
| 3582 | |
| 3583 | case clang::Type::Complex: |
| 3584 | { |
| 3585 | uint32_t complex_type_flags = eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex; |
| 3586 | const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal()); |
| 3587 | if (complex_type) |
| 3588 | { |
| 3589 | clang::QualType complex_element_type (complex_type->getElementType()); |
| 3590 | if (complex_element_type->isIntegerType()) |
| 3591 | complex_type_flags |= eTypeIsFloat; |
| 3592 | else if (complex_element_type->isFloatingType()) |
| 3593 | complex_type_flags |= eTypeIsInteger; |
| 3594 | } |
| 3595 | return complex_type_flags; |
| 3596 | } |
| 3597 | break; |
| 3598 | |
| 3599 | case clang::Type::ConstantArray: |
| 3600 | case clang::Type::DependentSizedArray: |
| 3601 | case clang::Type::IncompleteArray: |
| 3602 | case clang::Type::VariableArray: |
| 3603 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3604 | 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] | 3605 | return eTypeHasChildren | eTypeIsArray; |
| 3606 | |
| 3607 | case clang::Type::DependentName: return 0; |
| 3608 | case clang::Type::DependentSizedExtVector: return eTypeHasChildren | eTypeIsVector; |
| 3609 | case clang::Type::DependentTemplateSpecialization: return eTypeIsTemplate; |
| 3610 | case clang::Type::Decltype: return 0; |
| 3611 | |
| 3612 | case clang::Type::Enum: |
| 3613 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3614 | 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] | 3615 | return eTypeIsEnumeration | eTypeHasValue; |
| 3616 | |
| 3617 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3618 | 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] | 3619 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3620 | 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] | 3621 | |
| 3622 | case clang::Type::FunctionProto: return eTypeIsFuncPrototype | eTypeHasValue; |
| 3623 | case clang::Type::FunctionNoProto: return eTypeIsFuncPrototype | eTypeHasValue; |
| 3624 | case clang::Type::InjectedClassName: return 0; |
| 3625 | |
| 3626 | case clang::Type::LValueReference: |
| 3627 | case clang::Type::RValueReference: |
| 3628 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3629 | 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] | 3630 | return eTypeHasChildren | eTypeIsReference | eTypeHasValue; |
| 3631 | |
| 3632 | case clang::Type::MemberPointer: return eTypeIsPointer | eTypeIsMember | eTypeHasValue; |
| 3633 | |
| 3634 | case clang::Type::ObjCObjectPointer: |
| 3635 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3636 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3637 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | eTypeHasValue; |
| 3638 | |
| 3639 | case clang::Type::ObjCObject: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 3640 | case clang::Type::ObjCInterface: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 3641 | |
| 3642 | case clang::Type::Pointer: |
| 3643 | if (pointee_or_element_clang_type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3644 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3645 | return eTypeHasChildren | eTypeIsPointer | eTypeHasValue; |
| 3646 | |
| 3647 | case clang::Type::Record: |
| 3648 | if (qual_type->getAsCXXRecordDecl()) |
| 3649 | return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus; |
| 3650 | else |
| 3651 | return eTypeHasChildren | eTypeIsStructUnion; |
| 3652 | break; |
| 3653 | case clang::Type::SubstTemplateTypeParm: return eTypeIsTemplate; |
| 3654 | case clang::Type::TemplateTypeParm: return eTypeIsTemplate; |
| 3655 | case clang::Type::TemplateSpecialization: return eTypeIsTemplate; |
| 3656 | |
| 3657 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3658 | 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] | 3659 | case clang::Type::TypeOfExpr: return 0; |
| 3660 | case clang::Type::TypeOf: return 0; |
| 3661 | case clang::Type::UnresolvedUsing: return 0; |
| 3662 | |
| 3663 | case clang::Type::ExtVector: |
| 3664 | case clang::Type::Vector: |
| 3665 | { |
| 3666 | uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector; |
| 3667 | const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal()); |
| 3668 | if (vector_type) |
| 3669 | { |
| 3670 | if (vector_type->isIntegerType()) |
| 3671 | vector_type_flags |= eTypeIsFloat; |
| 3672 | else if (vector_type->isFloatingType()) |
| 3673 | vector_type_flags |= eTypeIsInteger; |
| 3674 | } |
| 3675 | return vector_type_flags; |
| 3676 | } |
| 3677 | default: return 0; |
| 3678 | } |
| 3679 | return 0; |
| 3680 | } |
| 3681 | |
| 3682 | |
| 3683 | |
| 3684 | lldb::LanguageType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3685 | ClangASTContext::GetMinimumLanguage (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3686 | { |
| 3687 | if (!type) |
| 3688 | return lldb::eLanguageTypeC; |
| 3689 | |
| 3690 | // If the type is a reference, then resolve it to what it refers to first: |
| 3691 | clang::QualType qual_type (GetCanonicalQualType(type).getNonReferenceType()); |
| 3692 | if (qual_type->isAnyPointerType()) |
| 3693 | { |
| 3694 | if (qual_type->isObjCObjectPointerType()) |
| 3695 | return lldb::eLanguageTypeObjC; |
| 3696 | |
| 3697 | clang::QualType pointee_type (qual_type->getPointeeType()); |
| 3698 | if (pointee_type->getPointeeCXXRecordDecl() != nullptr) |
| 3699 | return lldb::eLanguageTypeC_plus_plus; |
| 3700 | if (pointee_type->isObjCObjectOrInterfaceType()) |
| 3701 | return lldb::eLanguageTypeObjC; |
| 3702 | if (pointee_type->isObjCClassType()) |
| 3703 | return lldb::eLanguageTypeObjC; |
| 3704 | if (pointee_type.getTypePtr() == getASTContext()->ObjCBuiltinIdTy.getTypePtr()) |
| 3705 | return lldb::eLanguageTypeObjC; |
| 3706 | } |
| 3707 | else |
| 3708 | { |
| 3709 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 3710 | return lldb::eLanguageTypeObjC; |
| 3711 | if (qual_type->getAsCXXRecordDecl()) |
| 3712 | return lldb::eLanguageTypeC_plus_plus; |
| 3713 | switch (qual_type->getTypeClass()) |
| 3714 | { |
| 3715 | default: |
| 3716 | break; |
| 3717 | case clang::Type::Builtin: |
| 3718 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 3719 | { |
| 3720 | default: |
| 3721 | case clang::BuiltinType::Void: |
| 3722 | case clang::BuiltinType::Bool: |
| 3723 | case clang::BuiltinType::Char_U: |
| 3724 | case clang::BuiltinType::UChar: |
| 3725 | case clang::BuiltinType::WChar_U: |
| 3726 | case clang::BuiltinType::Char16: |
| 3727 | case clang::BuiltinType::Char32: |
| 3728 | case clang::BuiltinType::UShort: |
| 3729 | case clang::BuiltinType::UInt: |
| 3730 | case clang::BuiltinType::ULong: |
| 3731 | case clang::BuiltinType::ULongLong: |
| 3732 | case clang::BuiltinType::UInt128: |
| 3733 | case clang::BuiltinType::Char_S: |
| 3734 | case clang::BuiltinType::SChar: |
| 3735 | case clang::BuiltinType::WChar_S: |
| 3736 | case clang::BuiltinType::Short: |
| 3737 | case clang::BuiltinType::Int: |
| 3738 | case clang::BuiltinType::Long: |
| 3739 | case clang::BuiltinType::LongLong: |
| 3740 | case clang::BuiltinType::Int128: |
| 3741 | case clang::BuiltinType::Float: |
| 3742 | case clang::BuiltinType::Double: |
| 3743 | case clang::BuiltinType::LongDouble: |
| 3744 | break; |
| 3745 | |
| 3746 | case clang::BuiltinType::NullPtr: |
| 3747 | return eLanguageTypeC_plus_plus; |
| 3748 | |
| 3749 | case clang::BuiltinType::ObjCId: |
| 3750 | case clang::BuiltinType::ObjCClass: |
| 3751 | case clang::BuiltinType::ObjCSel: |
| 3752 | return eLanguageTypeObjC; |
| 3753 | |
| 3754 | case clang::BuiltinType::Dependent: |
| 3755 | case clang::BuiltinType::Overload: |
| 3756 | case clang::BuiltinType::BoundMember: |
| 3757 | case clang::BuiltinType::UnknownAny: |
| 3758 | break; |
| 3759 | } |
| 3760 | break; |
| 3761 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3762 | return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetMinimumLanguage(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3763 | } |
| 3764 | } |
| 3765 | return lldb::eLanguageTypeC; |
| 3766 | } |
| 3767 | |
| 3768 | lldb::TypeClass |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3769 | ClangASTContext::GetTypeClass (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3770 | { |
| 3771 | if (!type) |
| 3772 | return lldb::eTypeClassInvalid; |
| 3773 | |
| 3774 | clang::QualType qual_type(GetQualType(type)); |
| 3775 | |
| 3776 | switch (qual_type->getTypeClass()) |
| 3777 | { |
| 3778 | case clang::Type::UnaryTransform: break; |
| 3779 | case clang::Type::FunctionNoProto: return lldb::eTypeClassFunction; |
| 3780 | case clang::Type::FunctionProto: return lldb::eTypeClassFunction; |
| 3781 | case clang::Type::IncompleteArray: return lldb::eTypeClassArray; |
| 3782 | case clang::Type::VariableArray: return lldb::eTypeClassArray; |
| 3783 | case clang::Type::ConstantArray: return lldb::eTypeClassArray; |
| 3784 | case clang::Type::DependentSizedArray: return lldb::eTypeClassArray; |
| 3785 | case clang::Type::DependentSizedExtVector: return lldb::eTypeClassVector; |
| 3786 | case clang::Type::ExtVector: return lldb::eTypeClassVector; |
| 3787 | case clang::Type::Vector: return lldb::eTypeClassVector; |
| 3788 | case clang::Type::Builtin: return lldb::eTypeClassBuiltin; |
| 3789 | case clang::Type::ObjCObjectPointer: return lldb::eTypeClassObjCObjectPointer; |
| 3790 | case clang::Type::BlockPointer: return lldb::eTypeClassBlockPointer; |
| 3791 | case clang::Type::Pointer: return lldb::eTypeClassPointer; |
| 3792 | case clang::Type::LValueReference: return lldb::eTypeClassReference; |
| 3793 | case clang::Type::RValueReference: return lldb::eTypeClassReference; |
| 3794 | case clang::Type::MemberPointer: return lldb::eTypeClassMemberPointer; |
| 3795 | case clang::Type::Complex: |
| 3796 | if (qual_type->isComplexType()) |
| 3797 | return lldb::eTypeClassComplexFloat; |
| 3798 | else |
| 3799 | return lldb::eTypeClassComplexInteger; |
| 3800 | case clang::Type::ObjCObject: return lldb::eTypeClassObjCObject; |
| 3801 | case clang::Type::ObjCInterface: return lldb::eTypeClassObjCInterface; |
| 3802 | case clang::Type::Record: |
| 3803 | { |
| 3804 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3805 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3806 | if (record_decl->isUnion()) |
| 3807 | return lldb::eTypeClassUnion; |
| 3808 | else if (record_decl->isStruct()) |
| 3809 | return lldb::eTypeClassStruct; |
| 3810 | else |
| 3811 | return lldb::eTypeClassClass; |
| 3812 | } |
| 3813 | break; |
| 3814 | case clang::Type::Enum: return lldb::eTypeClassEnumeration; |
| 3815 | case clang::Type::Typedef: return lldb::eTypeClassTypedef; |
| 3816 | case clang::Type::UnresolvedUsing: break; |
| 3817 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3818 | return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeClass(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3819 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3820 | return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeClass(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3821 | |
| 3822 | case clang::Type::Attributed: break; |
| 3823 | case clang::Type::TemplateTypeParm: break; |
| 3824 | case clang::Type::SubstTemplateTypeParm: break; |
| 3825 | case clang::Type::SubstTemplateTypeParmPack:break; |
| 3826 | case clang::Type::Auto: break; |
| 3827 | case clang::Type::InjectedClassName: break; |
| 3828 | case clang::Type::DependentName: break; |
| 3829 | case clang::Type::DependentTemplateSpecialization: break; |
| 3830 | case clang::Type::PackExpansion: break; |
| 3831 | |
| 3832 | case clang::Type::TypeOfExpr: break; |
| 3833 | case clang::Type::TypeOf: break; |
| 3834 | case clang::Type::Decltype: break; |
| 3835 | case clang::Type::TemplateSpecialization: break; |
| 3836 | case clang::Type::Atomic: break; |
| 3837 | |
| 3838 | // pointer type decayed from an array or function type. |
| 3839 | case clang::Type::Decayed: break; |
| 3840 | case clang::Type::Adjusted: break; |
| 3841 | } |
| 3842 | // We don't know hot to display this type... |
| 3843 | return lldb::eTypeClassOther; |
| 3844 | |
| 3845 | } |
| 3846 | |
| 3847 | unsigned |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3848 | ClangASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3849 | { |
| 3850 | if (type) |
| 3851 | return GetQualType(type).getQualifiers().getCVRQualifiers(); |
| 3852 | return 0; |
| 3853 | } |
| 3854 | |
| 3855 | //---------------------------------------------------------------------- |
| 3856 | // Creating related types |
| 3857 | //---------------------------------------------------------------------- |
| 3858 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3859 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3860 | ClangASTContext::GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3861 | { |
| 3862 | if (type) |
| 3863 | { |
| 3864 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3865 | |
| 3866 | const clang::Type *array_eletype = qual_type.getTypePtr()->getArrayElementTypeNoTypeQual(); |
| 3867 | |
| 3868 | if (!array_eletype) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3869 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3870 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3871 | CompilerType element_type (getASTContext(), array_eletype->getCanonicalTypeUnqualified()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3872 | |
| 3873 | // TODO: the real stride will be >= this value.. find the real one! |
| 3874 | if (stride) |
| 3875 | *stride = element_type.GetByteSize(nullptr); |
| 3876 | |
| 3877 | return element_type; |
| 3878 | |
| 3879 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3880 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3881 | } |
| 3882 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3883 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3884 | ClangASTContext::GetCanonicalType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3885 | { |
| 3886 | if (type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3887 | return CompilerType (getASTContext(), GetCanonicalQualType(type)); |
| 3888 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | static clang::QualType |
| 3892 | GetFullyUnqualifiedType_Impl (clang::ASTContext *ast, clang::QualType qual_type) |
| 3893 | { |
| 3894 | if (qual_type->isPointerType()) |
| 3895 | qual_type = ast->getPointerType(GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType())); |
| 3896 | else |
| 3897 | qual_type = qual_type.getUnqualifiedType(); |
| 3898 | qual_type.removeLocalConst(); |
| 3899 | qual_type.removeLocalRestrict(); |
| 3900 | qual_type.removeLocalVolatile(); |
| 3901 | return qual_type; |
| 3902 | } |
| 3903 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3904 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3905 | ClangASTContext::GetFullyUnqualifiedType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3906 | { |
| 3907 | if (type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3908 | return CompilerType(getASTContext(), GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type))); |
| 3909 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3910 | } |
| 3911 | |
| 3912 | |
| 3913 | int |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3914 | ClangASTContext::GetFunctionArgumentCount (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3915 | { |
| 3916 | if (type) |
| 3917 | { |
| 3918 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type)); |
| 3919 | if (func) |
| 3920 | return func->getNumParams(); |
| 3921 | } |
| 3922 | return -1; |
| 3923 | } |
| 3924 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3925 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3926 | ClangASTContext::GetFunctionArgumentTypeAtIndex (lldb::opaque_compiler_type_t type, size_t idx) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3927 | { |
| 3928 | if (type) |
| 3929 | { |
| 3930 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type)); |
| 3931 | if (func) |
| 3932 | { |
| 3933 | const uint32_t num_args = func->getNumParams(); |
| 3934 | if (idx < num_args) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3935 | return CompilerType(getASTContext(), func->getParamType(idx)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3936 | } |
| 3937 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3938 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3939 | } |
| 3940 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3941 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3942 | ClangASTContext::GetFunctionReturnType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3943 | { |
| 3944 | if (type) |
| 3945 | { |
| 3946 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3947 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); |
| 3948 | if (func) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3949 | return CompilerType(getASTContext(), func->getReturnType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3950 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3951 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3955 | ClangASTContext::GetNumMemberFunctions (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3956 | { |
| 3957 | size_t num_functions = 0; |
| 3958 | if (type) |
| 3959 | { |
| 3960 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 3961 | switch (qual_type->getTypeClass()) { |
| 3962 | case clang::Type::Record: |
| 3963 | if (GetCompleteQualType (getASTContext(), qual_type)) |
| 3964 | { |
| 3965 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 3966 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 3967 | assert(record_decl); |
| 3968 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 3969 | if (cxx_record_decl) |
| 3970 | num_functions = std::distance(cxx_record_decl->method_begin(), cxx_record_decl->method_end()); |
| 3971 | } |
| 3972 | break; |
| 3973 | |
| 3974 | case clang::Type::ObjCObjectPointer: |
| 3975 | if (GetCompleteType(type)) |
| 3976 | { |
| 3977 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); |
| 3978 | if (objc_class_type) |
| 3979 | { |
| 3980 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); |
| 3981 | if (class_interface_decl) |
| 3982 | num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end()); |
| 3983 | } |
| 3984 | } |
| 3985 | break; |
| 3986 | |
| 3987 | case clang::Type::ObjCObject: |
| 3988 | case clang::Type::ObjCInterface: |
| 3989 | if (GetCompleteType(type)) |
| 3990 | { |
| 3991 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 3992 | if (objc_class_type) |
| 3993 | { |
| 3994 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 3995 | if (class_interface_decl) |
| 3996 | num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end()); |
| 3997 | } |
| 3998 | } |
| 3999 | break; |
| 4000 | |
| 4001 | |
| 4002 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4003 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumMemberFunctions(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4004 | |
| 4005 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4006 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumMemberFunctions(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4007 | |
| 4008 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4009 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumMemberFunctions(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4010 | |
| 4011 | default: |
| 4012 | break; |
| 4013 | } |
| 4014 | } |
| 4015 | return num_functions; |
| 4016 | } |
| 4017 | |
| 4018 | TypeMemberFunctionImpl |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4019 | ClangASTContext::GetMemberFunctionAtIndex (lldb::opaque_compiler_type_t type, size_t idx) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4020 | { |
| 4021 | std::string name(""); |
| 4022 | MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4023 | CompilerType clang_type{}; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4024 | clang::ObjCMethodDecl *method_decl(nullptr); |
| 4025 | if (type) |
| 4026 | { |
| 4027 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4028 | switch (qual_type->getTypeClass()) { |
| 4029 | case clang::Type::Record: |
| 4030 | if (GetCompleteQualType (getASTContext(), qual_type)) |
| 4031 | { |
| 4032 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4033 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4034 | assert(record_decl); |
| 4035 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 4036 | if (cxx_record_decl) |
| 4037 | { |
| 4038 | auto method_iter = cxx_record_decl->method_begin(); |
| 4039 | auto method_end = cxx_record_decl->method_end(); |
| 4040 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) |
| 4041 | { |
| 4042 | std::advance(method_iter, idx); |
| 4043 | auto method_decl = method_iter->getCanonicalDecl(); |
| 4044 | if (method_decl) |
| 4045 | { |
| 4046 | if (!method_decl->getName().empty()) |
| 4047 | name.assign(method_decl->getName().data()); |
| 4048 | else |
| 4049 | name.clear(); |
| 4050 | if (method_decl->isStatic()) |
| 4051 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4052 | else if (llvm::isa<clang::CXXConstructorDecl>(method_decl)) |
| 4053 | kind = lldb::eMemberFunctionKindConstructor; |
| 4054 | else if (llvm::isa<clang::CXXDestructorDecl>(method_decl)) |
| 4055 | kind = lldb::eMemberFunctionKindDestructor; |
| 4056 | else |
| 4057 | kind = lldb::eMemberFunctionKindInstanceMethod; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4058 | clang_type = CompilerType(getASTContext(),method_decl->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4059 | } |
| 4060 | } |
| 4061 | } |
| 4062 | } |
| 4063 | break; |
| 4064 | |
| 4065 | case clang::Type::ObjCObjectPointer: |
| 4066 | if (GetCompleteType(type)) |
| 4067 | { |
| 4068 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); |
| 4069 | if (objc_class_type) |
| 4070 | { |
| 4071 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); |
| 4072 | if (class_interface_decl) |
| 4073 | { |
| 4074 | auto method_iter = class_interface_decl->meth_begin(); |
| 4075 | auto method_end = class_interface_decl->meth_end(); |
| 4076 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) |
| 4077 | { |
| 4078 | std::advance(method_iter, idx); |
| 4079 | method_decl = method_iter->getCanonicalDecl(); |
| 4080 | if (method_decl) |
| 4081 | { |
| 4082 | name = method_decl->getSelector().getAsString(); |
| 4083 | if (method_decl->isClassMethod()) |
| 4084 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4085 | else |
| 4086 | kind = lldb::eMemberFunctionKindInstanceMethod; |
| 4087 | } |
| 4088 | } |
| 4089 | } |
| 4090 | } |
| 4091 | } |
| 4092 | break; |
| 4093 | |
| 4094 | case clang::Type::ObjCObject: |
| 4095 | case clang::Type::ObjCInterface: |
| 4096 | if (GetCompleteType(type)) |
| 4097 | { |
| 4098 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4099 | if (objc_class_type) |
| 4100 | { |
| 4101 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 4102 | if (class_interface_decl) |
| 4103 | { |
| 4104 | auto method_iter = class_interface_decl->meth_begin(); |
| 4105 | auto method_end = class_interface_decl->meth_end(); |
| 4106 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) |
| 4107 | { |
| 4108 | std::advance(method_iter, idx); |
| 4109 | method_decl = method_iter->getCanonicalDecl(); |
| 4110 | if (method_decl) |
| 4111 | { |
| 4112 | name = method_decl->getSelector().getAsString(); |
| 4113 | if (method_decl->isClassMethod()) |
| 4114 | kind = lldb::eMemberFunctionKindStaticMethod; |
| 4115 | else |
| 4116 | kind = lldb::eMemberFunctionKindInstanceMethod; |
| 4117 | } |
| 4118 | } |
| 4119 | } |
| 4120 | } |
| 4121 | } |
| 4122 | break; |
| 4123 | |
| 4124 | case clang::Type::Typedef: |
| 4125 | return GetMemberFunctionAtIndex(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx); |
| 4126 | |
| 4127 | case clang::Type::Elaborated: |
| 4128 | return GetMemberFunctionAtIndex(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx); |
| 4129 | |
| 4130 | case clang::Type::Paren: |
| 4131 | return GetMemberFunctionAtIndex(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx); |
| 4132 | |
| 4133 | default: |
| 4134 | break; |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | if (kind == eMemberFunctionKindUnknown) |
| 4139 | return TypeMemberFunctionImpl(); |
| 4140 | if (method_decl) |
| 4141 | return TypeMemberFunctionImpl(method_decl, name, kind); |
| 4142 | if (type) |
| 4143 | return TypeMemberFunctionImpl(clang_type, name, kind); |
| 4144 | |
| 4145 | return TypeMemberFunctionImpl(); |
| 4146 | } |
| 4147 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4148 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4149 | ClangASTContext::GetNonReferenceType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4150 | { |
| 4151 | if (type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4152 | return CompilerType(getASTContext(), GetQualType(type).getNonReferenceType()); |
| 4153 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4154 | } |
| 4155 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4156 | CompilerType |
| 4157 | ClangASTContext::CreateTypedefType (const CompilerType& type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4158 | const char *typedef_name, |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4159 | const CompilerDeclContext &compiler_decl_ctx) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4160 | { |
| 4161 | if (type && typedef_name && typedef_name[0]) |
| 4162 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 4163 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4164 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4165 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4166 | clang::ASTContext* clang_ast = ast->getASTContext(); |
| 4167 | clang::QualType qual_type (GetQualType(type)); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4168 | |
| 4169 | clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4170 | if (decl_ctx == nullptr) |
| 4171 | decl_ctx = ast->getASTContext()->getTranslationUnitDecl(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4172 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4173 | clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast, |
| 4174 | decl_ctx, |
| 4175 | clang::SourceLocation(), |
| 4176 | clang::SourceLocation(), |
| 4177 | &clang_ast->Idents.get(typedef_name), |
| 4178 | clang_ast->getTrivialTypeSourceInfo(qual_type)); |
| 4179 | |
| 4180 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier |
| 4181 | |
| 4182 | // Get a uniqued clang::QualType for the typedef decl type |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4183 | return CompilerType (clang_ast, clang_ast->getTypedefType (decl)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4184 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4185 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4186 | |
| 4187 | } |
| 4188 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4189 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4190 | ClangASTContext::GetPointeeType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4191 | { |
| 4192 | if (type) |
| 4193 | { |
| 4194 | clang::QualType qual_type(GetQualType(type)); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4195 | return CompilerType (getASTContext(), qual_type.getTypePtr()->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4196 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4197 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4198 | } |
| 4199 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4200 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4201 | ClangASTContext::GetPointerType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4202 | { |
| 4203 | if (type) |
| 4204 | { |
| 4205 | clang::QualType qual_type (GetQualType(type)); |
| 4206 | |
| 4207 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4208 | switch (type_class) |
| 4209 | { |
| 4210 | case clang::Type::ObjCObject: |
| 4211 | case clang::Type::ObjCInterface: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4212 | return CompilerType(getASTContext(), getASTContext()->getObjCObjectPointerType(qual_type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4213 | |
| 4214 | default: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4215 | return CompilerType(getASTContext(), getASTContext()->getPointerType(qual_type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4216 | } |
| 4217 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4218 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4221 | |
| 4222 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4223 | ClangASTContext::GetLValueReferenceType (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4224 | { |
| 4225 | if (type) |
| 4226 | return CompilerType(this, getASTContext()->getLValueReferenceType(GetQualType(type)).getAsOpaquePtr()); |
| 4227 | else |
| 4228 | return CompilerType(); |
| 4229 | } |
| 4230 | |
| 4231 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4232 | ClangASTContext::GetRValueReferenceType (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4233 | { |
| 4234 | if (type) |
| 4235 | return CompilerType(this, getASTContext()->getRValueReferenceType(GetQualType(type)).getAsOpaquePtr()); |
| 4236 | else |
| 4237 | return CompilerType(); |
| 4238 | } |
| 4239 | |
| 4240 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4241 | ClangASTContext::AddConstModifier (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4242 | { |
| 4243 | if (type) |
| 4244 | { |
| 4245 | clang::QualType result(GetQualType(type)); |
| 4246 | result.addConst(); |
| 4247 | return CompilerType (this, result.getAsOpaquePtr()); |
| 4248 | } |
| 4249 | return CompilerType(); |
| 4250 | } |
| 4251 | |
| 4252 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4253 | ClangASTContext::AddVolatileModifier (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4254 | { |
| 4255 | if (type) |
| 4256 | { |
| 4257 | clang::QualType result(GetQualType(type)); |
| 4258 | result.addVolatile(); |
| 4259 | return CompilerType (this, result.getAsOpaquePtr()); |
| 4260 | } |
| 4261 | return CompilerType(); |
| 4262 | |
| 4263 | } |
| 4264 | |
| 4265 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4266 | ClangASTContext::AddRestrictModifier (lldb::opaque_compiler_type_t type) |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4267 | { |
| 4268 | if (type) |
| 4269 | { |
| 4270 | clang::QualType result(GetQualType(type)); |
| 4271 | result.addRestrict(); |
| 4272 | return CompilerType (this, result.getAsOpaquePtr()); |
| 4273 | } |
| 4274 | return CompilerType(); |
| 4275 | |
| 4276 | } |
| 4277 | |
| 4278 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4279 | 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] | 4280 | { |
| 4281 | if (type) |
| 4282 | { |
| 4283 | clang::ASTContext* clang_ast = getASTContext(); |
| 4284 | clang::QualType qual_type (GetQualType(type)); |
| 4285 | |
| 4286 | clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); |
| 4287 | if (decl_ctx == nullptr) |
| 4288 | decl_ctx = getASTContext()->getTranslationUnitDecl(); |
| 4289 | |
| 4290 | clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast, |
| 4291 | decl_ctx, |
| 4292 | clang::SourceLocation(), |
| 4293 | clang::SourceLocation(), |
| 4294 | &clang_ast->Idents.get(typedef_name), |
| 4295 | clang_ast->getTrivialTypeSourceInfo(qual_type)); |
| 4296 | |
| 4297 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier |
| 4298 | |
| 4299 | // Get a uniqued clang::QualType for the typedef decl type |
| 4300 | return CompilerType (this, clang_ast->getTypedefType (decl).getAsOpaquePtr()); |
| 4301 | |
| 4302 | } |
| 4303 | return CompilerType(); |
| 4304 | |
| 4305 | } |
| 4306 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4307 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4308 | ClangASTContext::GetTypedefedType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4309 | { |
| 4310 | if (type) |
| 4311 | { |
| 4312 | const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(GetQualType(type)); |
| 4313 | if (typedef_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4314 | return CompilerType (getASTContext(), typedef_type->getDecl()->getUnderlyingType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4315 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4316 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4317 | } |
| 4318 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4319 | CompilerType |
| 4320 | ClangASTContext::RemoveFastQualifiers (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4321 | { |
Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 4322 | if (IsClangType(type)) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4323 | { |
| 4324 | clang::QualType qual_type(GetQualType(type)); |
| 4325 | qual_type.getQualifiers().removeFastQualifiers(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4326 | return CompilerType (type.GetTypeSystem(), qual_type.getAsOpaquePtr()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4327 | } |
| 4328 | return type; |
| 4329 | } |
| 4330 | |
| 4331 | |
| 4332 | //---------------------------------------------------------------------- |
| 4333 | // Create related types using the current type's AST |
| 4334 | //---------------------------------------------------------------------- |
| 4335 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4336 | CompilerType |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4337 | ClangASTContext::GetBasicTypeFromAST (lldb::BasicType basic_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4338 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4339 | return ClangASTContext::GetBasicType(getASTContext(), basic_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4340 | } |
| 4341 | //---------------------------------------------------------------------- |
| 4342 | // Exploring the type |
| 4343 | //---------------------------------------------------------------------- |
| 4344 | |
| 4345 | uint64_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4346 | ClangASTContext::GetBitSize (lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4347 | { |
| 4348 | if (GetCompleteType (type)) |
| 4349 | { |
| 4350 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4351 | switch (qual_type->getTypeClass()) |
| 4352 | { |
| 4353 | case clang::Type::ObjCInterface: |
| 4354 | case clang::Type::ObjCObject: |
| 4355 | { |
| 4356 | ExecutionContext exe_ctx (exe_scope); |
| 4357 | Process *process = exe_ctx.GetProcessPtr(); |
| 4358 | if (process) |
| 4359 | { |
| 4360 | ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime(); |
| 4361 | if (objc_runtime) |
| 4362 | { |
| 4363 | uint64_t bit_size = 0; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4364 | if (objc_runtime->GetTypeBitSize(CompilerType(getASTContext(), qual_type), bit_size)) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4365 | return bit_size; |
| 4366 | } |
| 4367 | } |
| 4368 | else |
| 4369 | { |
| 4370 | static bool g_printed = false; |
| 4371 | if (!g_printed) |
| 4372 | { |
| 4373 | StreamString s; |
| 4374 | DumpTypeDescription(&s); |
| 4375 | |
| 4376 | llvm::outs() << "warning: trying to determine the size of type "; |
| 4377 | llvm::outs() << s.GetString() << "\n"; |
| 4378 | llvm::outs() << "without a valid ExecutionContext. this is not reliable. please file a bug against LLDB.\n"; |
| 4379 | llvm::outs() << "backtrace:\n"; |
| 4380 | llvm::sys::PrintStackTrace(llvm::outs()); |
| 4381 | llvm::outs() << "\n"; |
| 4382 | g_printed = true; |
| 4383 | } |
| 4384 | } |
| 4385 | } |
| 4386 | // fallthrough |
| 4387 | default: |
| 4388 | const uint32_t bit_size = getASTContext()->getTypeSize (qual_type); |
| 4389 | if (bit_size == 0) |
| 4390 | { |
| 4391 | if (qual_type->isIncompleteArrayType()) |
| 4392 | return getASTContext()->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified()); |
| 4393 | } |
| 4394 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 4395 | return bit_size + getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy); |
| 4396 | return bit_size; |
| 4397 | } |
| 4398 | } |
| 4399 | return 0; |
| 4400 | } |
| 4401 | |
| 4402 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4403 | ClangASTContext::GetTypeBitAlign (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4404 | { |
| 4405 | if (GetCompleteType(type)) |
| 4406 | return getASTContext()->getTypeAlign(GetQualType(type)); |
| 4407 | return 0; |
| 4408 | } |
| 4409 | |
| 4410 | |
| 4411 | lldb::Encoding |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4412 | ClangASTContext::GetEncoding (lldb::opaque_compiler_type_t type, uint64_t &count) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4413 | { |
| 4414 | if (!type) |
| 4415 | return lldb::eEncodingInvalid; |
| 4416 | |
| 4417 | count = 1; |
| 4418 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4419 | |
| 4420 | switch (qual_type->getTypeClass()) |
| 4421 | { |
| 4422 | case clang::Type::UnaryTransform: |
| 4423 | break; |
| 4424 | |
| 4425 | case clang::Type::FunctionNoProto: |
| 4426 | case clang::Type::FunctionProto: |
| 4427 | break; |
| 4428 | |
| 4429 | case clang::Type::IncompleteArray: |
| 4430 | case clang::Type::VariableArray: |
| 4431 | break; |
| 4432 | |
| 4433 | case clang::Type::ConstantArray: |
| 4434 | break; |
| 4435 | |
| 4436 | case clang::Type::ExtVector: |
| 4437 | case clang::Type::Vector: |
| 4438 | // TODO: Set this to more than one??? |
| 4439 | break; |
| 4440 | |
| 4441 | case clang::Type::Builtin: |
| 4442 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 4443 | { |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4444 | case clang::BuiltinType::Void: |
| 4445 | break; |
| 4446 | |
| 4447 | case clang::BuiltinType::Bool: |
| 4448 | case clang::BuiltinType::Char_S: |
| 4449 | case clang::BuiltinType::SChar: |
| 4450 | case clang::BuiltinType::WChar_S: |
| 4451 | case clang::BuiltinType::Char16: |
| 4452 | case clang::BuiltinType::Char32: |
| 4453 | case clang::BuiltinType::Short: |
| 4454 | case clang::BuiltinType::Int: |
| 4455 | case clang::BuiltinType::Long: |
| 4456 | case clang::BuiltinType::LongLong: |
| 4457 | case clang::BuiltinType::Int128: return lldb::eEncodingSint; |
| 4458 | |
| 4459 | case clang::BuiltinType::Char_U: |
| 4460 | case clang::BuiltinType::UChar: |
| 4461 | case clang::BuiltinType::WChar_U: |
| 4462 | case clang::BuiltinType::UShort: |
| 4463 | case clang::BuiltinType::UInt: |
| 4464 | case clang::BuiltinType::ULong: |
| 4465 | case clang::BuiltinType::ULongLong: |
| 4466 | case clang::BuiltinType::UInt128: return lldb::eEncodingUint; |
| 4467 | |
| 4468 | case clang::BuiltinType::Float: |
| 4469 | case clang::BuiltinType::Double: |
| 4470 | case clang::BuiltinType::LongDouble: return lldb::eEncodingIEEE754; |
| 4471 | |
| 4472 | case clang::BuiltinType::ObjCClass: |
| 4473 | case clang::BuiltinType::ObjCId: |
| 4474 | case clang::BuiltinType::ObjCSel: return lldb::eEncodingUint; |
| 4475 | |
| 4476 | case clang::BuiltinType::NullPtr: return lldb::eEncodingUint; |
| 4477 | |
| 4478 | case clang::BuiltinType::Kind::ARCUnbridgedCast: |
| 4479 | case clang::BuiltinType::Kind::BoundMember: |
| 4480 | case clang::BuiltinType::Kind::BuiltinFn: |
| 4481 | case clang::BuiltinType::Kind::Dependent: |
| 4482 | case clang::BuiltinType::Kind::Half: |
Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4483 | case clang::BuiltinType::Kind::OCLClkEvent: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4484 | case clang::BuiltinType::Kind::OCLEvent: |
| 4485 | case clang::BuiltinType::Kind::OCLImage1d: |
| 4486 | case clang::BuiltinType::Kind::OCLImage1dArray: |
| 4487 | case clang::BuiltinType::Kind::OCLImage1dBuffer: |
| 4488 | case clang::BuiltinType::Kind::OCLImage2d: |
| 4489 | case clang::BuiltinType::Kind::OCLImage2dArray: |
Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4490 | case clang::BuiltinType::Kind::OCLImage2dArrayDepth: |
| 4491 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAA: |
| 4492 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepth: |
| 4493 | case clang::BuiltinType::Kind::OCLImage2dDepth: |
| 4494 | case clang::BuiltinType::Kind::OCLImage2dMSAA: |
| 4495 | case clang::BuiltinType::Kind::OCLImage2dMSAADepth: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4496 | case clang::BuiltinType::Kind::OCLImage3d: |
Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4497 | case clang::BuiltinType::Kind::OCLQueue: |
| 4498 | case clang::BuiltinType::Kind::OCLNDRange: |
| 4499 | case clang::BuiltinType::Kind::OCLReserveID: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4500 | case clang::BuiltinType::Kind::OCLSampler: |
Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4501 | case clang::BuiltinType::Kind::OMPArraySection: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4502 | case clang::BuiltinType::Kind::Overload: |
| 4503 | case clang::BuiltinType::Kind::PseudoObject: |
| 4504 | case clang::BuiltinType::Kind::UnknownAny: |
| 4505 | break; |
| 4506 | } |
| 4507 | break; |
| 4508 | // All pointer types are represented as unsigned integer encodings. |
| 4509 | // We may nee to add a eEncodingPointer if we ever need to know the |
| 4510 | // difference |
| 4511 | case clang::Type::ObjCObjectPointer: |
| 4512 | case clang::Type::BlockPointer: |
| 4513 | case clang::Type::Pointer: |
| 4514 | case clang::Type::LValueReference: |
| 4515 | case clang::Type::RValueReference: |
| 4516 | case clang::Type::MemberPointer: return lldb::eEncodingUint; |
| 4517 | case clang::Type::Complex: |
| 4518 | { |
| 4519 | lldb::Encoding encoding = lldb::eEncodingIEEE754; |
| 4520 | if (qual_type->isComplexType()) |
| 4521 | encoding = lldb::eEncodingIEEE754; |
| 4522 | else |
| 4523 | { |
| 4524 | const clang::ComplexType *complex_type = qual_type->getAsComplexIntegerType(); |
| 4525 | if (complex_type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4526 | encoding = CompilerType(getASTContext(), complex_type->getElementType()).GetEncoding(count); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4527 | else |
| 4528 | encoding = lldb::eEncodingSint; |
| 4529 | } |
| 4530 | count = 2; |
| 4531 | return encoding; |
| 4532 | } |
| 4533 | |
| 4534 | case clang::Type::ObjCInterface: break; |
| 4535 | case clang::Type::Record: break; |
| 4536 | case clang::Type::Enum: return lldb::eEncodingSint; |
| 4537 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4538 | 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] | 4539 | |
| 4540 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4541 | return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetEncoding(count); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4542 | |
| 4543 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4544 | return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetEncoding(count); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4545 | |
| 4546 | case clang::Type::DependentSizedArray: |
| 4547 | case clang::Type::DependentSizedExtVector: |
| 4548 | case clang::Type::UnresolvedUsing: |
| 4549 | case clang::Type::Attributed: |
| 4550 | case clang::Type::TemplateTypeParm: |
| 4551 | case clang::Type::SubstTemplateTypeParm: |
| 4552 | case clang::Type::SubstTemplateTypeParmPack: |
| 4553 | case clang::Type::Auto: |
| 4554 | case clang::Type::InjectedClassName: |
| 4555 | case clang::Type::DependentName: |
| 4556 | case clang::Type::DependentTemplateSpecialization: |
| 4557 | case clang::Type::PackExpansion: |
| 4558 | case clang::Type::ObjCObject: |
| 4559 | |
| 4560 | case clang::Type::TypeOfExpr: |
| 4561 | case clang::Type::TypeOf: |
| 4562 | case clang::Type::Decltype: |
| 4563 | case clang::Type::TemplateSpecialization: |
| 4564 | case clang::Type::Atomic: |
| 4565 | case clang::Type::Adjusted: |
| 4566 | break; |
| 4567 | |
| 4568 | // pointer type decayed from an array or function type. |
| 4569 | case clang::Type::Decayed: |
| 4570 | break; |
| 4571 | } |
| 4572 | count = 0; |
| 4573 | return lldb::eEncodingInvalid; |
| 4574 | } |
| 4575 | |
| 4576 | lldb::Format |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4577 | ClangASTContext::GetFormat (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4578 | { |
| 4579 | if (!type) |
| 4580 | return lldb::eFormatDefault; |
| 4581 | |
| 4582 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4583 | |
| 4584 | switch (qual_type->getTypeClass()) |
| 4585 | { |
| 4586 | case clang::Type::UnaryTransform: |
| 4587 | break; |
| 4588 | |
| 4589 | case clang::Type::FunctionNoProto: |
| 4590 | case clang::Type::FunctionProto: |
| 4591 | break; |
| 4592 | |
| 4593 | case clang::Type::IncompleteArray: |
| 4594 | case clang::Type::VariableArray: |
| 4595 | break; |
| 4596 | |
| 4597 | case clang::Type::ConstantArray: |
| 4598 | return lldb::eFormatVoid; // no value |
| 4599 | |
| 4600 | case clang::Type::ExtVector: |
| 4601 | case clang::Type::Vector: |
| 4602 | break; |
| 4603 | |
| 4604 | case clang::Type::Builtin: |
| 4605 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 4606 | { |
| 4607 | //default: assert(0 && "Unknown builtin type!"); |
| 4608 | case clang::BuiltinType::UnknownAny: |
| 4609 | case clang::BuiltinType::Void: |
| 4610 | case clang::BuiltinType::BoundMember: |
| 4611 | break; |
| 4612 | |
| 4613 | case clang::BuiltinType::Bool: return lldb::eFormatBoolean; |
| 4614 | case clang::BuiltinType::Char_S: |
| 4615 | case clang::BuiltinType::SChar: |
| 4616 | case clang::BuiltinType::WChar_S: |
| 4617 | case clang::BuiltinType::Char_U: |
| 4618 | case clang::BuiltinType::UChar: |
| 4619 | case clang::BuiltinType::WChar_U: return lldb::eFormatChar; |
| 4620 | case clang::BuiltinType::Char16: return lldb::eFormatUnicode16; |
| 4621 | case clang::BuiltinType::Char32: return lldb::eFormatUnicode32; |
| 4622 | case clang::BuiltinType::UShort: return lldb::eFormatUnsigned; |
| 4623 | case clang::BuiltinType::Short: return lldb::eFormatDecimal; |
| 4624 | case clang::BuiltinType::UInt: return lldb::eFormatUnsigned; |
| 4625 | case clang::BuiltinType::Int: return lldb::eFormatDecimal; |
| 4626 | case clang::BuiltinType::ULong: return lldb::eFormatUnsigned; |
| 4627 | case clang::BuiltinType::Long: return lldb::eFormatDecimal; |
| 4628 | case clang::BuiltinType::ULongLong: return lldb::eFormatUnsigned; |
| 4629 | case clang::BuiltinType::LongLong: return lldb::eFormatDecimal; |
| 4630 | case clang::BuiltinType::UInt128: return lldb::eFormatUnsigned; |
| 4631 | case clang::BuiltinType::Int128: return lldb::eFormatDecimal; |
| 4632 | case clang::BuiltinType::Float: return lldb::eFormatFloat; |
| 4633 | case clang::BuiltinType::Double: return lldb::eFormatFloat; |
| 4634 | case clang::BuiltinType::LongDouble: return lldb::eFormatFloat; |
Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 4635 | default: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4636 | return lldb::eFormatHex; |
| 4637 | } |
| 4638 | break; |
| 4639 | case clang::Type::ObjCObjectPointer: return lldb::eFormatHex; |
| 4640 | case clang::Type::BlockPointer: return lldb::eFormatHex; |
| 4641 | case clang::Type::Pointer: return lldb::eFormatHex; |
| 4642 | case clang::Type::LValueReference: |
| 4643 | case clang::Type::RValueReference: return lldb::eFormatHex; |
| 4644 | case clang::Type::MemberPointer: break; |
| 4645 | case clang::Type::Complex: |
| 4646 | { |
| 4647 | if (qual_type->isComplexType()) |
| 4648 | return lldb::eFormatComplex; |
| 4649 | else |
| 4650 | return lldb::eFormatComplexInteger; |
| 4651 | } |
| 4652 | case clang::Type::ObjCInterface: break; |
| 4653 | case clang::Type::Record: break; |
| 4654 | case clang::Type::Enum: return lldb::eFormatEnum; |
| 4655 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4656 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetFormat(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4657 | case clang::Type::Auto: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4658 | return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->desugar()).GetFormat(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4659 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4660 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetFormat(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4661 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4662 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetFormat(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4663 | case clang::Type::DependentSizedArray: |
| 4664 | case clang::Type::DependentSizedExtVector: |
| 4665 | case clang::Type::UnresolvedUsing: |
| 4666 | case clang::Type::Attributed: |
| 4667 | case clang::Type::TemplateTypeParm: |
| 4668 | case clang::Type::SubstTemplateTypeParm: |
| 4669 | case clang::Type::SubstTemplateTypeParmPack: |
| 4670 | case clang::Type::InjectedClassName: |
| 4671 | case clang::Type::DependentName: |
| 4672 | case clang::Type::DependentTemplateSpecialization: |
| 4673 | case clang::Type::PackExpansion: |
| 4674 | case clang::Type::ObjCObject: |
| 4675 | |
| 4676 | case clang::Type::TypeOfExpr: |
| 4677 | case clang::Type::TypeOf: |
| 4678 | case clang::Type::Decltype: |
| 4679 | case clang::Type::TemplateSpecialization: |
| 4680 | case clang::Type::Atomic: |
| 4681 | case clang::Type::Adjusted: |
| 4682 | break; |
| 4683 | |
| 4684 | // pointer type decayed from an array or function type. |
| 4685 | case clang::Type::Decayed: |
| 4686 | break; |
| 4687 | } |
| 4688 | // We don't know hot to display this type... |
| 4689 | return lldb::eFormatBytes; |
| 4690 | } |
| 4691 | |
| 4692 | static bool |
| 4693 | ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl, bool check_superclass) |
| 4694 | { |
| 4695 | while (class_interface_decl) |
| 4696 | { |
| 4697 | if (class_interface_decl->ivar_size() > 0) |
| 4698 | return true; |
| 4699 | |
| 4700 | if (check_superclass) |
| 4701 | class_interface_decl = class_interface_decl->getSuperClass(); |
| 4702 | else |
| 4703 | break; |
| 4704 | } |
| 4705 | return false; |
| 4706 | } |
| 4707 | |
| 4708 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4709 | 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] | 4710 | { |
| 4711 | if (!type) |
| 4712 | return 0; |
| 4713 | |
| 4714 | uint32_t num_children = 0; |
| 4715 | clang::QualType qual_type(GetQualType(type)); |
| 4716 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4717 | switch (type_class) |
| 4718 | { |
| 4719 | case clang::Type::Builtin: |
| 4720 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 4721 | { |
| 4722 | case clang::BuiltinType::ObjCId: // child is Class |
| 4723 | case clang::BuiltinType::ObjCClass: // child is Class |
| 4724 | num_children = 1; |
| 4725 | break; |
| 4726 | |
| 4727 | default: |
| 4728 | break; |
| 4729 | } |
| 4730 | break; |
| 4731 | |
| 4732 | case clang::Type::Complex: return 0; |
| 4733 | |
| 4734 | case clang::Type::Record: |
| 4735 | if (GetCompleteQualType (getASTContext(), qual_type)) |
| 4736 | { |
| 4737 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4738 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4739 | assert(record_decl); |
| 4740 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 4741 | if (cxx_record_decl) |
| 4742 | { |
| 4743 | if (omit_empty_base_classes) |
| 4744 | { |
| 4745 | // Check each base classes to see if it or any of its |
| 4746 | // base classes contain any fields. This can help |
| 4747 | // limit the noise in variable views by not having to |
| 4748 | // show base classes that contain no members. |
| 4749 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 4750 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 4751 | base_class != base_class_end; |
| 4752 | ++base_class) |
| 4753 | { |
| 4754 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 4755 | |
| 4756 | // Skip empty base classes |
| 4757 | if (ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 4758 | continue; |
| 4759 | |
| 4760 | num_children++; |
| 4761 | } |
| 4762 | } |
| 4763 | else |
| 4764 | { |
| 4765 | // Include all base classes |
| 4766 | num_children += cxx_record_decl->getNumBases(); |
| 4767 | } |
| 4768 | |
| 4769 | } |
| 4770 | clang::RecordDecl::field_iterator field, field_end; |
| 4771 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field) |
| 4772 | ++num_children; |
| 4773 | } |
| 4774 | break; |
| 4775 | |
| 4776 | case clang::Type::ObjCObject: |
| 4777 | case clang::Type::ObjCInterface: |
| 4778 | if (GetCompleteQualType (getASTContext(), qual_type)) |
| 4779 | { |
| 4780 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 4781 | assert (objc_class_type); |
| 4782 | if (objc_class_type) |
| 4783 | { |
| 4784 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 4785 | |
| 4786 | if (class_interface_decl) |
| 4787 | { |
| 4788 | |
| 4789 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 4790 | if (superclass_interface_decl) |
| 4791 | { |
| 4792 | if (omit_empty_base_classes) |
| 4793 | { |
| 4794 | if (ObjCDeclHasIVars (superclass_interface_decl, true)) |
| 4795 | ++num_children; |
| 4796 | } |
| 4797 | else |
| 4798 | ++num_children; |
| 4799 | } |
| 4800 | |
| 4801 | num_children += class_interface_decl->ivar_size(); |
| 4802 | } |
| 4803 | } |
| 4804 | } |
| 4805 | break; |
| 4806 | |
| 4807 | case clang::Type::ObjCObjectPointer: |
| 4808 | { |
| 4809 | const clang::ObjCObjectPointerType *pointer_type = llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()); |
| 4810 | clang::QualType pointee_type = pointer_type->getPointeeType(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4811 | 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] | 4812 | // If this type points to a simple type, then it has 1 child |
| 4813 | if (num_pointee_children == 0) |
| 4814 | num_children = 1; |
| 4815 | else |
| 4816 | num_children = num_pointee_children; |
| 4817 | } |
| 4818 | break; |
| 4819 | |
| 4820 | case clang::Type::Vector: |
| 4821 | case clang::Type::ExtVector: |
| 4822 | num_children = llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements(); |
| 4823 | break; |
| 4824 | |
| 4825 | case clang::Type::ConstantArray: |
| 4826 | num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())->getSize().getLimitedValue(); |
| 4827 | break; |
| 4828 | |
| 4829 | case clang::Type::Pointer: |
| 4830 | { |
| 4831 | const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr()); |
| 4832 | clang::QualType pointee_type (pointer_type->getPointeeType()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4833 | 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] | 4834 | if (num_pointee_children == 0) |
| 4835 | { |
| 4836 | // We have a pointer to a pointee type that claims it has no children. |
| 4837 | // We will want to look at |
| 4838 | num_children = GetNumPointeeChildren (pointee_type); |
| 4839 | } |
| 4840 | else |
| 4841 | num_children = num_pointee_children; |
| 4842 | } |
| 4843 | break; |
| 4844 | |
| 4845 | case clang::Type::LValueReference: |
| 4846 | case clang::Type::RValueReference: |
| 4847 | { |
| 4848 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 4849 | clang::QualType pointee_type = reference_type->getPointeeType(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4850 | 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] | 4851 | // If this type points to a simple type, then it has 1 child |
| 4852 | if (num_pointee_children == 0) |
| 4853 | num_children = 1; |
| 4854 | else |
| 4855 | num_children = num_pointee_children; |
| 4856 | } |
| 4857 | break; |
| 4858 | |
| 4859 | |
| 4860 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4861 | 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] | 4862 | break; |
| 4863 | |
| 4864 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4865 | 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] | 4866 | break; |
| 4867 | |
| 4868 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4869 | 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] | 4870 | break; |
| 4871 | default: |
| 4872 | break; |
| 4873 | } |
| 4874 | return num_children; |
| 4875 | } |
| 4876 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4877 | CompilerType |
| 4878 | ClangASTContext::GetBuiltinTypeByName (const ConstString &name) |
| 4879 | { |
| 4880 | return GetBasicType (GetBasicTypeEnumeration (name)); |
| 4881 | } |
| 4882 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4883 | lldb::BasicType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4884 | ClangASTContext::GetBasicTypeEnumeration (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4885 | { |
| 4886 | if (type) |
| 4887 | { |
| 4888 | clang::QualType qual_type(GetQualType(type)); |
| 4889 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4890 | if (type_class == clang::Type::Builtin) |
| 4891 | { |
| 4892 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 4893 | { |
| 4894 | case clang::BuiltinType::Void: return eBasicTypeVoid; |
| 4895 | case clang::BuiltinType::Bool: return eBasicTypeBool; |
| 4896 | case clang::BuiltinType::Char_S: return eBasicTypeSignedChar; |
| 4897 | case clang::BuiltinType::Char_U: return eBasicTypeUnsignedChar; |
| 4898 | case clang::BuiltinType::Char16: return eBasicTypeChar16; |
| 4899 | case clang::BuiltinType::Char32: return eBasicTypeChar32; |
| 4900 | case clang::BuiltinType::UChar: return eBasicTypeUnsignedChar; |
| 4901 | case clang::BuiltinType::SChar: return eBasicTypeSignedChar; |
| 4902 | case clang::BuiltinType::WChar_S: return eBasicTypeSignedWChar; |
| 4903 | case clang::BuiltinType::WChar_U: return eBasicTypeUnsignedWChar; |
| 4904 | case clang::BuiltinType::Short: return eBasicTypeShort; |
| 4905 | case clang::BuiltinType::UShort: return eBasicTypeUnsignedShort; |
| 4906 | case clang::BuiltinType::Int: return eBasicTypeInt; |
| 4907 | case clang::BuiltinType::UInt: return eBasicTypeUnsignedInt; |
| 4908 | case clang::BuiltinType::Long: return eBasicTypeLong; |
| 4909 | case clang::BuiltinType::ULong: return eBasicTypeUnsignedLong; |
| 4910 | case clang::BuiltinType::LongLong: return eBasicTypeLongLong; |
| 4911 | case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong; |
| 4912 | case clang::BuiltinType::Int128: return eBasicTypeInt128; |
| 4913 | case clang::BuiltinType::UInt128: return eBasicTypeUnsignedInt128; |
| 4914 | |
| 4915 | case clang::BuiltinType::Half: return eBasicTypeHalf; |
| 4916 | case clang::BuiltinType::Float: return eBasicTypeFloat; |
| 4917 | case clang::BuiltinType::Double: return eBasicTypeDouble; |
| 4918 | case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble; |
| 4919 | |
| 4920 | case clang::BuiltinType::NullPtr: return eBasicTypeNullPtr; |
| 4921 | case clang::BuiltinType::ObjCId: return eBasicTypeObjCID; |
| 4922 | case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass; |
| 4923 | case clang::BuiltinType::ObjCSel: return eBasicTypeObjCSel; |
Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 4924 | default: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4925 | return eBasicTypeOther; |
| 4926 | } |
| 4927 | } |
| 4928 | } |
| 4929 | return eBasicTypeInvalid; |
| 4930 | } |
| 4931 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4932 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4933 | 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] | 4934 | { |
| 4935 | const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)); |
| 4936 | if (enum_type) |
| 4937 | { |
| 4938 | const clang::EnumDecl *enum_decl = enum_type->getDecl(); |
| 4939 | if (enum_decl) |
| 4940 | { |
| 4941 | CompilerType integer_type(this, enum_decl->getIntegerType().getAsOpaquePtr()); |
| 4942 | |
| 4943 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 4944 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) |
| 4945 | { |
| 4946 | ConstString name(enum_pos->getNameAsString().c_str()); |
| 4947 | if (!callback (integer_type, name, enum_pos->getInitVal())) |
| 4948 | break; |
| 4949 | } |
| 4950 | } |
| 4951 | } |
| 4952 | } |
| 4953 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4954 | |
| 4955 | #pragma mark Aggregate Types |
| 4956 | |
| 4957 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4958 | ClangASTContext::GetNumFields (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4959 | { |
| 4960 | if (!type) |
| 4961 | return 0; |
| 4962 | |
| 4963 | uint32_t count = 0; |
| 4964 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 4965 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4966 | switch (type_class) |
| 4967 | { |
| 4968 | case clang::Type::Record: |
| 4969 | if (GetCompleteType(type)) |
| 4970 | { |
| 4971 | const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); |
| 4972 | if (record_type) |
| 4973 | { |
| 4974 | clang::RecordDecl *record_decl = record_type->getDecl(); |
| 4975 | if (record_decl) |
| 4976 | { |
| 4977 | uint32_t field_idx = 0; |
| 4978 | clang::RecordDecl::field_iterator field, field_end; |
| 4979 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field) |
| 4980 | ++field_idx; |
| 4981 | count = field_idx; |
| 4982 | } |
| 4983 | } |
| 4984 | } |
| 4985 | break; |
| 4986 | |
| 4987 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4988 | count = CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumFields(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4989 | break; |
| 4990 | |
| 4991 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4992 | count = CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumFields(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4993 | break; |
| 4994 | |
| 4995 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4996 | count = CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumFields(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4997 | break; |
| 4998 | |
| 4999 | case clang::Type::ObjCObjectPointer: |
| 5000 | if (GetCompleteType(type)) |
| 5001 | { |
| 5002 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); |
| 5003 | if (objc_class_type) |
| 5004 | { |
| 5005 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); |
| 5006 | |
| 5007 | if (class_interface_decl) |
| 5008 | count = class_interface_decl->ivar_size(); |
| 5009 | } |
| 5010 | } |
| 5011 | break; |
| 5012 | |
| 5013 | case clang::Type::ObjCObject: |
| 5014 | case clang::Type::ObjCInterface: |
| 5015 | if (GetCompleteType(type)) |
| 5016 | { |
| 5017 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5018 | if (objc_class_type) |
| 5019 | { |
| 5020 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 5021 | |
| 5022 | if (class_interface_decl) |
| 5023 | count = class_interface_decl->ivar_size(); |
| 5024 | } |
| 5025 | } |
| 5026 | break; |
| 5027 | |
| 5028 | default: |
| 5029 | break; |
| 5030 | } |
| 5031 | return count; |
| 5032 | } |
| 5033 | |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5034 | static lldb::opaque_compiler_type_t |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5035 | GetObjCFieldAtIndex (clang::ASTContext *ast, |
| 5036 | clang::ObjCInterfaceDecl *class_interface_decl, |
| 5037 | size_t idx, |
| 5038 | std::string& name, |
| 5039 | uint64_t *bit_offset_ptr, |
| 5040 | uint32_t *bitfield_bit_size_ptr, |
| 5041 | bool *is_bitfield_ptr) |
| 5042 | { |
| 5043 | if (class_interface_decl) |
| 5044 | { |
| 5045 | if (idx < (class_interface_decl->ivar_size())) |
| 5046 | { |
| 5047 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 5048 | uint32_t ivar_idx = 0; |
| 5049 | |
| 5050 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++ivar_idx) |
| 5051 | { |
| 5052 | if (ivar_idx == idx) |
| 5053 | { |
| 5054 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 5055 | |
| 5056 | clang::QualType ivar_qual_type(ivar_decl->getType()); |
| 5057 | |
| 5058 | name.assign(ivar_decl->getNameAsString()); |
| 5059 | |
| 5060 | if (bit_offset_ptr) |
| 5061 | { |
| 5062 | const clang::ASTRecordLayout &interface_layout = ast->getASTObjCInterfaceLayout(class_interface_decl); |
| 5063 | *bit_offset_ptr = interface_layout.getFieldOffset (ivar_idx); |
| 5064 | } |
| 5065 | |
| 5066 | const bool is_bitfield = ivar_pos->isBitField(); |
| 5067 | |
| 5068 | if (bitfield_bit_size_ptr) |
| 5069 | { |
| 5070 | *bitfield_bit_size_ptr = 0; |
| 5071 | |
| 5072 | if (is_bitfield && ast) |
| 5073 | { |
| 5074 | clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth(); |
| 5075 | llvm::APSInt bitfield_apsint; |
| 5076 | if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *ast)) |
| 5077 | { |
| 5078 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 5079 | } |
| 5080 | } |
| 5081 | } |
| 5082 | if (is_bitfield_ptr) |
| 5083 | *is_bitfield_ptr = is_bitfield; |
| 5084 | |
| 5085 | return ivar_qual_type.getAsOpaquePtr(); |
| 5086 | } |
| 5087 | } |
| 5088 | } |
| 5089 | } |
| 5090 | return nullptr; |
| 5091 | } |
| 5092 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5093 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5094 | ClangASTContext::GetFieldAtIndex (lldb::opaque_compiler_type_t type, size_t idx, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5095 | std::string& name, |
| 5096 | uint64_t *bit_offset_ptr, |
| 5097 | uint32_t *bitfield_bit_size_ptr, |
| 5098 | bool *is_bitfield_ptr) |
| 5099 | { |
| 5100 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5101 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5102 | |
| 5103 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5104 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5105 | switch (type_class) |
| 5106 | { |
| 5107 | case clang::Type::Record: |
| 5108 | if (GetCompleteType(type)) |
| 5109 | { |
| 5110 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 5111 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5112 | uint32_t field_idx = 0; |
| 5113 | clang::RecordDecl::field_iterator field, field_end; |
| 5114 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx) |
| 5115 | { |
| 5116 | if (idx == field_idx) |
| 5117 | { |
| 5118 | // Print the member type if requested |
| 5119 | // Print the member name and equal sign |
| 5120 | name.assign(field->getNameAsString()); |
| 5121 | |
| 5122 | // Figure out the type byte size (field_type_info.first) and |
| 5123 | // alignment (field_type_info.second) from the AST context. |
| 5124 | if (bit_offset_ptr) |
| 5125 | { |
| 5126 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); |
| 5127 | *bit_offset_ptr = record_layout.getFieldOffset (field_idx); |
| 5128 | } |
| 5129 | |
| 5130 | const bool is_bitfield = field->isBitField(); |
| 5131 | |
| 5132 | if (bitfield_bit_size_ptr) |
| 5133 | { |
| 5134 | *bitfield_bit_size_ptr = 0; |
| 5135 | |
| 5136 | if (is_bitfield) |
| 5137 | { |
| 5138 | clang::Expr *bitfield_bit_size_expr = field->getBitWidth(); |
| 5139 | llvm::APSInt bitfield_apsint; |
| 5140 | if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *getASTContext())) |
| 5141 | { |
| 5142 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 5143 | } |
| 5144 | } |
| 5145 | } |
| 5146 | if (is_bitfield_ptr) |
| 5147 | *is_bitfield_ptr = is_bitfield; |
| 5148 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5149 | return CompilerType (getASTContext(), field->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5150 | } |
| 5151 | } |
| 5152 | } |
| 5153 | break; |
| 5154 | |
| 5155 | case clang::Type::ObjCObjectPointer: |
| 5156 | if (GetCompleteType(type)) |
| 5157 | { |
| 5158 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); |
| 5159 | if (objc_class_type) |
| 5160 | { |
| 5161 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5162 | 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] | 5163 | } |
| 5164 | } |
| 5165 | break; |
| 5166 | |
| 5167 | case clang::Type::ObjCObject: |
| 5168 | case clang::Type::ObjCInterface: |
| 5169 | if (GetCompleteType(type)) |
| 5170 | { |
| 5171 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 5172 | assert (objc_class_type); |
| 5173 | if (objc_class_type) |
| 5174 | { |
| 5175 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5176 | 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] | 5177 | } |
| 5178 | } |
| 5179 | break; |
| 5180 | |
| 5181 | |
| 5182 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5183 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()). |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5184 | GetFieldAtIndex (idx, |
| 5185 | name, |
| 5186 | bit_offset_ptr, |
| 5187 | bitfield_bit_size_ptr, |
| 5188 | is_bitfield_ptr); |
| 5189 | |
| 5190 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5191 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()). |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5192 | GetFieldAtIndex (idx, |
| 5193 | name, |
| 5194 | bit_offset_ptr, |
| 5195 | bitfield_bit_size_ptr, |
| 5196 | is_bitfield_ptr); |
| 5197 | |
| 5198 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5199 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()). |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5200 | GetFieldAtIndex (idx, |
| 5201 | name, |
| 5202 | bit_offset_ptr, |
| 5203 | bitfield_bit_size_ptr, |
| 5204 | is_bitfield_ptr); |
| 5205 | |
| 5206 | default: |
| 5207 | break; |
| 5208 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5209 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5210 | } |
| 5211 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5212 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5213 | ClangASTContext::GetNumDirectBaseClasses (lldb::opaque_compiler_type_t type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5214 | { |
| 5215 | uint32_t count = 0; |
| 5216 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5217 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5218 | switch (type_class) |
| 5219 | { |
| 5220 | case clang::Type::Record: |
| 5221 | if (GetCompleteType(type)) |
| 5222 | { |
| 5223 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5224 | if (cxx_record_decl) |
| 5225 | count = cxx_record_decl->getNumBases(); |
| 5226 | } |
| 5227 | break; |
| 5228 | |
| 5229 | case clang::Type::ObjCObjectPointer: |
| 5230 | count = GetPointeeType(type).GetNumDirectBaseClasses(); |
| 5231 | break; |
| 5232 | |
| 5233 | case clang::Type::ObjCObject: |
| 5234 | if (GetCompleteType(type)) |
| 5235 | { |
| 5236 | const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType(); |
| 5237 | if (objc_class_type) |
| 5238 | { |
| 5239 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 5240 | |
| 5241 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 5242 | count = 1; |
| 5243 | } |
| 5244 | } |
| 5245 | break; |
| 5246 | case clang::Type::ObjCInterface: |
| 5247 | if (GetCompleteType(type)) |
| 5248 | { |
| 5249 | const clang::ObjCInterfaceType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>(); |
| 5250 | if (objc_interface_type) |
| 5251 | { |
| 5252 | clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface(); |
| 5253 | |
| 5254 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 5255 | count = 1; |
| 5256 | } |
| 5257 | } |
| 5258 | break; |
| 5259 | |
| 5260 | |
| 5261 | case clang::Type::Typedef: |
| 5262 | count = GetNumDirectBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 5263 | break; |
| 5264 | |
| 5265 | case clang::Type::Elaborated: |
| 5266 | count = GetNumDirectBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 5267 | break; |
| 5268 | |
| 5269 | case clang::Type::Paren: |
| 5270 | return GetNumDirectBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 5271 | |
| 5272 | default: |
| 5273 | break; |
| 5274 | } |
| 5275 | return count; |
| 5276 | |
| 5277 | } |
| 5278 | |
| 5279 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5280 | ClangASTContext::GetNumVirtualBaseClasses (lldb::opaque_compiler_type_t type) |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5281 | { |
| 5282 | uint32_t count = 0; |
| 5283 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5284 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5285 | switch (type_class) |
| 5286 | { |
| 5287 | case clang::Type::Record: |
| 5288 | if (GetCompleteType(type)) |
| 5289 | { |
| 5290 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5291 | if (cxx_record_decl) |
| 5292 | count = cxx_record_decl->getNumVBases(); |
| 5293 | } |
| 5294 | break; |
| 5295 | |
| 5296 | case clang::Type::Typedef: |
| 5297 | count = GetNumVirtualBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 5298 | break; |
| 5299 | |
| 5300 | case clang::Type::Elaborated: |
| 5301 | count = GetNumVirtualBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 5302 | break; |
| 5303 | |
| 5304 | case clang::Type::Paren: |
| 5305 | count = GetNumVirtualBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); |
| 5306 | break; |
| 5307 | |
| 5308 | default: |
| 5309 | break; |
| 5310 | } |
| 5311 | return count; |
| 5312 | |
| 5313 | } |
| 5314 | |
| 5315 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5316 | 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] | 5317 | { |
| 5318 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5319 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5320 | switch (type_class) |
| 5321 | { |
| 5322 | case clang::Type::Record: |
| 5323 | if (GetCompleteType(type)) |
| 5324 | { |
| 5325 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5326 | if (cxx_record_decl) |
| 5327 | { |
| 5328 | uint32_t curr_idx = 0; |
| 5329 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 5330 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 5331 | base_class != base_class_end; |
| 5332 | ++base_class, ++curr_idx) |
| 5333 | { |
| 5334 | if (curr_idx == idx) |
| 5335 | { |
| 5336 | if (bit_offset_ptr) |
| 5337 | { |
| 5338 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl); |
| 5339 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 5340 | if (base_class->isVirtual()) |
| 5341 | *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5342 | else |
| 5343 | *bit_offset_ptr = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5344 | } |
| 5345 | return CompilerType (this, base_class->getType().getAsOpaquePtr()); |
| 5346 | } |
| 5347 | } |
| 5348 | } |
| 5349 | } |
| 5350 | break; |
| 5351 | |
| 5352 | case clang::Type::ObjCObjectPointer: |
| 5353 | return GetPointeeType(type).GetDirectBaseClassAtIndex(idx, bit_offset_ptr); |
| 5354 | |
| 5355 | case clang::Type::ObjCObject: |
| 5356 | if (idx == 0 && GetCompleteType(type)) |
| 5357 | { |
| 5358 | const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType(); |
| 5359 | if (objc_class_type) |
| 5360 | { |
| 5361 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 5362 | |
| 5363 | if (class_interface_decl) |
| 5364 | { |
| 5365 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 5366 | if (superclass_interface_decl) |
| 5367 | { |
| 5368 | if (bit_offset_ptr) |
| 5369 | *bit_offset_ptr = 0; |
| 5370 | return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
| 5371 | } |
| 5372 | } |
| 5373 | } |
| 5374 | } |
| 5375 | break; |
| 5376 | case clang::Type::ObjCInterface: |
| 5377 | if (idx == 0 && GetCompleteType(type)) |
| 5378 | { |
| 5379 | const clang::ObjCObjectType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>(); |
| 5380 | if (objc_interface_type) |
| 5381 | { |
| 5382 | clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface(); |
| 5383 | |
| 5384 | if (class_interface_decl) |
| 5385 | { |
| 5386 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 5387 | if (superclass_interface_decl) |
| 5388 | { |
| 5389 | if (bit_offset_ptr) |
| 5390 | *bit_offset_ptr = 0; |
| 5391 | return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
| 5392 | } |
| 5393 | } |
| 5394 | } |
| 5395 | } |
| 5396 | break; |
| 5397 | |
| 5398 | |
| 5399 | case clang::Type::Typedef: |
| 5400 | return GetDirectBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5401 | |
| 5402 | case clang::Type::Elaborated: |
| 5403 | return GetDirectBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5404 | |
| 5405 | case clang::Type::Paren: |
| 5406 | return GetDirectBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5407 | |
| 5408 | default: |
| 5409 | break; |
| 5410 | } |
| 5411 | return CompilerType(); |
| 5412 | } |
| 5413 | |
| 5414 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5415 | ClangASTContext::GetVirtualBaseClassAtIndex (lldb::opaque_compiler_type_t type, |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5416 | size_t idx, |
| 5417 | uint32_t *bit_offset_ptr) |
| 5418 | { |
| 5419 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 5420 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5421 | switch (type_class) |
| 5422 | { |
| 5423 | case clang::Type::Record: |
| 5424 | if (GetCompleteType(type)) |
| 5425 | { |
| 5426 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5427 | if (cxx_record_decl) |
| 5428 | { |
| 5429 | uint32_t curr_idx = 0; |
| 5430 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 5431 | for (base_class = cxx_record_decl->vbases_begin(), base_class_end = cxx_record_decl->vbases_end(); |
| 5432 | base_class != base_class_end; |
| 5433 | ++base_class, ++curr_idx) |
| 5434 | { |
| 5435 | if (curr_idx == idx) |
| 5436 | { |
| 5437 | if (bit_offset_ptr) |
| 5438 | { |
| 5439 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl); |
| 5440 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 5441 | *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5442 | |
| 5443 | } |
| 5444 | return CompilerType (this, base_class->getType().getAsOpaquePtr()); |
| 5445 | } |
| 5446 | } |
| 5447 | } |
| 5448 | } |
| 5449 | break; |
| 5450 | |
| 5451 | case clang::Type::Typedef: |
| 5452 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5453 | |
| 5454 | case clang::Type::Elaborated: |
| 5455 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5456 | |
| 5457 | case clang::Type::Paren: |
| 5458 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr); |
| 5459 | |
| 5460 | default: |
| 5461 | break; |
| 5462 | } |
| 5463 | return CompilerType(); |
| 5464 | |
| 5465 | } |
| 5466 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5467 | // If a pointer to a pointee type (the clang_type arg) says that it has no |
| 5468 | // children, then we either need to trust it, or override it and return a |
| 5469 | // different result. For example, an "int *" has one child that is an integer, |
| 5470 | // but a function pointer doesn't have any children. Likewise if a Record type |
| 5471 | // claims it has no children, then there really is nothing to show. |
| 5472 | uint32_t |
| 5473 | ClangASTContext::GetNumPointeeChildren (clang::QualType type) |
| 5474 | { |
| 5475 | if (type.isNull()) |
| 5476 | return 0; |
| 5477 | |
| 5478 | clang::QualType qual_type(type.getCanonicalType()); |
| 5479 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5480 | switch (type_class) |
| 5481 | { |
| 5482 | case clang::Type::Builtin: |
| 5483 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) |
| 5484 | { |
| 5485 | case clang::BuiltinType::UnknownAny: |
| 5486 | case clang::BuiltinType::Void: |
| 5487 | case clang::BuiltinType::NullPtr: |
| 5488 | case clang::BuiltinType::OCLEvent: |
| 5489 | case clang::BuiltinType::OCLImage1d: |
| 5490 | case clang::BuiltinType::OCLImage1dArray: |
| 5491 | case clang::BuiltinType::OCLImage1dBuffer: |
| 5492 | case clang::BuiltinType::OCLImage2d: |
| 5493 | case clang::BuiltinType::OCLImage2dArray: |
| 5494 | case clang::BuiltinType::OCLImage3d: |
| 5495 | case clang::BuiltinType::OCLSampler: |
| 5496 | return 0; |
| 5497 | case clang::BuiltinType::Bool: |
| 5498 | case clang::BuiltinType::Char_U: |
| 5499 | case clang::BuiltinType::UChar: |
| 5500 | case clang::BuiltinType::WChar_U: |
| 5501 | case clang::BuiltinType::Char16: |
| 5502 | case clang::BuiltinType::Char32: |
| 5503 | case clang::BuiltinType::UShort: |
| 5504 | case clang::BuiltinType::UInt: |
| 5505 | case clang::BuiltinType::ULong: |
| 5506 | case clang::BuiltinType::ULongLong: |
| 5507 | case clang::BuiltinType::UInt128: |
| 5508 | case clang::BuiltinType::Char_S: |
| 5509 | case clang::BuiltinType::SChar: |
| 5510 | case clang::BuiltinType::WChar_S: |
| 5511 | case clang::BuiltinType::Short: |
| 5512 | case clang::BuiltinType::Int: |
| 5513 | case clang::BuiltinType::Long: |
| 5514 | case clang::BuiltinType::LongLong: |
| 5515 | case clang::BuiltinType::Int128: |
| 5516 | case clang::BuiltinType::Float: |
| 5517 | case clang::BuiltinType::Double: |
| 5518 | case clang::BuiltinType::LongDouble: |
| 5519 | case clang::BuiltinType::Dependent: |
| 5520 | case clang::BuiltinType::Overload: |
| 5521 | case clang::BuiltinType::ObjCId: |
| 5522 | case clang::BuiltinType::ObjCClass: |
| 5523 | case clang::BuiltinType::ObjCSel: |
| 5524 | case clang::BuiltinType::BoundMember: |
| 5525 | case clang::BuiltinType::Half: |
| 5526 | case clang::BuiltinType::ARCUnbridgedCast: |
| 5527 | case clang::BuiltinType::PseudoObject: |
| 5528 | case clang::BuiltinType::BuiltinFn: |
Zachary Turner | 84f5b0d | 2015-09-09 17:25:43 +0000 | [diff] [blame] | 5529 | case clang::BuiltinType::OMPArraySection: |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5530 | return 1; |
Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 5531 | default: |
| 5532 | return 0; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5533 | } |
| 5534 | break; |
| 5535 | |
| 5536 | case clang::Type::Complex: return 1; |
| 5537 | case clang::Type::Pointer: return 1; |
| 5538 | case clang::Type::BlockPointer: return 0; // If block pointers don't have debug info, then no children for them |
| 5539 | case clang::Type::LValueReference: return 1; |
| 5540 | case clang::Type::RValueReference: return 1; |
| 5541 | case clang::Type::MemberPointer: return 0; |
| 5542 | case clang::Type::ConstantArray: return 0; |
| 5543 | case clang::Type::IncompleteArray: return 0; |
| 5544 | case clang::Type::VariableArray: return 0; |
| 5545 | case clang::Type::DependentSizedArray: return 0; |
| 5546 | case clang::Type::DependentSizedExtVector: return 0; |
| 5547 | case clang::Type::Vector: return 0; |
| 5548 | case clang::Type::ExtVector: return 0; |
| 5549 | case clang::Type::FunctionProto: return 0; // When we function pointers, they have no children... |
| 5550 | case clang::Type::FunctionNoProto: return 0; // When we function pointers, they have no children... |
| 5551 | case clang::Type::UnresolvedUsing: return 0; |
| 5552 | case clang::Type::Paren: return GetNumPointeeChildren (llvm::cast<clang::ParenType>(qual_type)->desugar()); |
| 5553 | case clang::Type::Typedef: return GetNumPointeeChildren (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()); |
| 5554 | case clang::Type::Elaborated: return GetNumPointeeChildren (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); |
| 5555 | case clang::Type::TypeOfExpr: return 0; |
| 5556 | case clang::Type::TypeOf: return 0; |
| 5557 | case clang::Type::Decltype: return 0; |
| 5558 | case clang::Type::Record: return 0; |
| 5559 | case clang::Type::Enum: return 1; |
| 5560 | case clang::Type::TemplateTypeParm: return 1; |
| 5561 | case clang::Type::SubstTemplateTypeParm: return 1; |
| 5562 | case clang::Type::TemplateSpecialization: return 1; |
| 5563 | case clang::Type::InjectedClassName: return 0; |
| 5564 | case clang::Type::DependentName: return 1; |
| 5565 | case clang::Type::DependentTemplateSpecialization: return 1; |
| 5566 | case clang::Type::ObjCObject: return 0; |
| 5567 | case clang::Type::ObjCInterface: return 0; |
| 5568 | case clang::Type::ObjCObjectPointer: return 1; |
| 5569 | default: |
| 5570 | break; |
| 5571 | } |
| 5572 | return 0; |
| 5573 | } |
| 5574 | |
| 5575 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5576 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5577 | ClangASTContext::GetChildCompilerTypeAtIndex (lldb::opaque_compiler_type_t type, |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 5578 | ExecutionContext *exe_ctx, |
| 5579 | size_t idx, |
| 5580 | bool transparent_pointers, |
| 5581 | bool omit_empty_base_classes, |
| 5582 | bool ignore_array_bounds, |
| 5583 | std::string& child_name, |
| 5584 | uint32_t &child_byte_size, |
| 5585 | int32_t &child_byte_offset, |
| 5586 | uint32_t &child_bitfield_bit_size, |
| 5587 | uint32_t &child_bitfield_bit_offset, |
| 5588 | bool &child_is_base_class, |
| 5589 | bool &child_is_deref_of_parent, |
| 5590 | ValueObject *valobj) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5591 | { |
| 5592 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5593 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5594 | |
| 5595 | clang::QualType parent_qual_type(GetCanonicalQualType(type)); |
| 5596 | const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass(); |
| 5597 | child_bitfield_bit_size = 0; |
| 5598 | child_bitfield_bit_offset = 0; |
| 5599 | child_is_base_class = false; |
| 5600 | |
| 5601 | const bool idx_is_valid = idx < GetNumChildren (type, omit_empty_base_classes); |
| 5602 | uint32_t bit_offset; |
| 5603 | switch (parent_type_class) |
| 5604 | { |
| 5605 | case clang::Type::Builtin: |
| 5606 | if (idx_is_valid) |
| 5607 | { |
| 5608 | switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) |
| 5609 | { |
| 5610 | case clang::BuiltinType::ObjCId: |
| 5611 | case clang::BuiltinType::ObjCClass: |
| 5612 | child_name = "isa"; |
| 5613 | child_byte_size = getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) / CHAR_BIT; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5614 | return CompilerType (getASTContext(), getASTContext()->ObjCBuiltinClassTy); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5615 | |
| 5616 | default: |
| 5617 | break; |
| 5618 | } |
| 5619 | } |
| 5620 | break; |
| 5621 | |
| 5622 | case clang::Type::Record: |
| 5623 | if (idx_is_valid && GetCompleteType(type)) |
| 5624 | { |
| 5625 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr()); |
| 5626 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 5627 | assert(record_decl); |
| 5628 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); |
| 5629 | uint32_t child_idx = 0; |
| 5630 | |
| 5631 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 5632 | if (cxx_record_decl) |
| 5633 | { |
| 5634 | // We might have base classes to print out first |
| 5635 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 5636 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 5637 | base_class != base_class_end; |
| 5638 | ++base_class) |
| 5639 | { |
| 5640 | const clang::CXXRecordDecl *base_class_decl = nullptr; |
| 5641 | |
| 5642 | // Skip empty base classes |
| 5643 | if (omit_empty_base_classes) |
| 5644 | { |
| 5645 | base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 5646 | if (ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 5647 | continue; |
| 5648 | } |
| 5649 | |
| 5650 | if (idx == child_idx) |
| 5651 | { |
| 5652 | if (base_class_decl == nullptr) |
| 5653 | base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 5654 | |
| 5655 | |
| 5656 | if (base_class->isVirtual()) |
| 5657 | { |
| 5658 | bool handled = false; |
| 5659 | if (valobj) |
| 5660 | { |
| 5661 | Error err; |
| 5662 | AddressType addr_type = eAddressTypeInvalid; |
| 5663 | lldb::addr_t vtable_ptr_addr = valobj->GetCPPVTableAddress(addr_type); |
| 5664 | |
| 5665 | if (vtable_ptr_addr != LLDB_INVALID_ADDRESS && addr_type == eAddressTypeLoad) |
| 5666 | { |
| 5667 | |
| 5668 | ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); |
| 5669 | Process *process = exe_ctx.GetProcessPtr(); |
| 5670 | if (process) |
| 5671 | { |
| 5672 | clang::VTableContextBase *vtable_ctx = getASTContext()->getVTableContext(); |
| 5673 | if (vtable_ctx) |
| 5674 | { |
| 5675 | if (vtable_ctx->isMicrosoft()) |
| 5676 | { |
| 5677 | clang::MicrosoftVTableContext *msoft_vtable_ctx = static_cast<clang::MicrosoftVTableContext *>(vtable_ctx); |
| 5678 | |
| 5679 | if (vtable_ptr_addr) |
| 5680 | { |
| 5681 | const lldb::addr_t vbtable_ptr_addr = vtable_ptr_addr + record_layout.getVBPtrOffset().getQuantity(); |
| 5682 | |
| 5683 | const lldb::addr_t vbtable_ptr = process->ReadPointerFromMemory(vbtable_ptr_addr, err); |
| 5684 | if (vbtable_ptr != LLDB_INVALID_ADDRESS) |
| 5685 | { |
| 5686 | // Get the index into the virtual base table. The index is the index in uint32_t from vbtable_ptr |
| 5687 | const unsigned vbtable_index = msoft_vtable_ctx->getVBTableIndex(cxx_record_decl, base_class_decl); |
| 5688 | const lldb::addr_t base_offset_addr = vbtable_ptr + vbtable_index * 4; |
| 5689 | const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err); |
| 5690 | if (base_offset != UINT32_MAX) |
| 5691 | { |
| 5692 | handled = true; |
| 5693 | bit_offset = base_offset * 8; |
| 5694 | } |
| 5695 | } |
| 5696 | } |
| 5697 | } |
| 5698 | else |
| 5699 | { |
| 5700 | clang::ItaniumVTableContext *itanium_vtable_ctx = static_cast<clang::ItaniumVTableContext *>(vtable_ctx); |
| 5701 | if (vtable_ptr_addr) |
| 5702 | { |
| 5703 | const lldb::addr_t vtable_ptr = process->ReadPointerFromMemory(vtable_ptr_addr, err); |
| 5704 | if (vtable_ptr != LLDB_INVALID_ADDRESS) |
| 5705 | { |
| 5706 | clang::CharUnits base_offset_offset = itanium_vtable_ctx->getVirtualBaseOffsetOffset(cxx_record_decl, base_class_decl); |
| 5707 | const lldb::addr_t base_offset_addr = vtable_ptr + base_offset_offset.getQuantity(); |
| 5708 | const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err); |
| 5709 | if (base_offset != UINT32_MAX) |
| 5710 | { |
| 5711 | handled = true; |
| 5712 | bit_offset = base_offset * 8; |
| 5713 | } |
| 5714 | } |
| 5715 | } |
| 5716 | } |
| 5717 | } |
| 5718 | } |
| 5719 | } |
| 5720 | |
| 5721 | } |
| 5722 | if (!handled) |
| 5723 | bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5724 | } |
| 5725 | else |
| 5726 | bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 5727 | |
| 5728 | // Base classes should be a multiple of 8 bits in size |
| 5729 | child_byte_offset = bit_offset/8; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5730 | CompilerType base_class_clang_type(getASTContext(), base_class->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5731 | child_name = base_class_clang_type.GetTypeName().AsCString(""); |
| 5732 | uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5733 | |
| 5734 | // Base classes bit sizes should be a multiple of 8 bits in size |
| 5735 | assert (base_class_clang_type_bit_size % 8 == 0); |
| 5736 | child_byte_size = base_class_clang_type_bit_size / 8; |
| 5737 | child_is_base_class = true; |
| 5738 | return base_class_clang_type; |
| 5739 | } |
| 5740 | // We don't increment the child index in the for loop since we might |
| 5741 | // be skipping empty base classes |
| 5742 | ++child_idx; |
| 5743 | } |
| 5744 | } |
| 5745 | // Make sure index is in range... |
| 5746 | uint32_t field_idx = 0; |
| 5747 | clang::RecordDecl::field_iterator field, field_end; |
| 5748 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx) |
| 5749 | { |
| 5750 | if (idx == child_idx) |
| 5751 | { |
| 5752 | // Print the member type if requested |
| 5753 | // Print the member name and equal sign |
| 5754 | child_name.assign(field->getNameAsString().c_str()); |
| 5755 | |
| 5756 | // Figure out the type byte size (field_type_info.first) and |
| 5757 | // alignment (field_type_info.second) from the AST context. |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5758 | CompilerType field_clang_type (getASTContext(), field->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5759 | assert(field_idx < record_layout.getFieldCount()); |
| 5760 | child_byte_size = field_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5761 | |
| 5762 | // Figure out the field offset within the current struct/union/class type |
| 5763 | bit_offset = record_layout.getFieldOffset (field_idx); |
| 5764 | child_byte_offset = bit_offset / 8; |
| 5765 | if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, child_bitfield_bit_size)) |
| 5766 | child_bitfield_bit_offset = bit_offset % 8; |
| 5767 | |
| 5768 | return field_clang_type; |
| 5769 | } |
| 5770 | } |
| 5771 | } |
| 5772 | break; |
| 5773 | |
| 5774 | case clang::Type::ObjCObject: |
| 5775 | case clang::Type::ObjCInterface: |
| 5776 | if (idx_is_valid && GetCompleteType(type)) |
| 5777 | { |
| 5778 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr()); |
| 5779 | assert (objc_class_type); |
| 5780 | if (objc_class_type) |
| 5781 | { |
| 5782 | uint32_t child_idx = 0; |
| 5783 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 5784 | |
| 5785 | if (class_interface_decl) |
| 5786 | { |
| 5787 | |
| 5788 | const clang::ASTRecordLayout &interface_layout = getASTContext()->getASTObjCInterfaceLayout(class_interface_decl); |
| 5789 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 5790 | if (superclass_interface_decl) |
| 5791 | { |
| 5792 | if (omit_empty_base_classes) |
| 5793 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5794 | CompilerType base_class_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5795 | if (base_class_clang_type.GetNumChildren(omit_empty_base_classes) > 0) |
| 5796 | { |
| 5797 | if (idx == 0) |
| 5798 | { |
| 5799 | clang::QualType ivar_qual_type(getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
| 5800 | |
| 5801 | |
| 5802 | child_name.assign(superclass_interface_decl->getNameAsString().c_str()); |
| 5803 | |
| 5804 | clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 5805 | |
| 5806 | child_byte_size = ivar_type_info.Width / 8; |
| 5807 | child_byte_offset = 0; |
| 5808 | child_is_base_class = true; |
| 5809 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5810 | return CompilerType (getASTContext(), ivar_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | ++child_idx; |
| 5814 | } |
| 5815 | } |
| 5816 | else |
| 5817 | ++child_idx; |
| 5818 | } |
| 5819 | |
| 5820 | const uint32_t superclass_idx = child_idx; |
| 5821 | |
| 5822 | if (idx < (child_idx + class_interface_decl->ivar_size())) |
| 5823 | { |
| 5824 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 5825 | |
| 5826 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos) |
| 5827 | { |
| 5828 | if (child_idx == idx) |
| 5829 | { |
| 5830 | clang::ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 5831 | |
| 5832 | clang::QualType ivar_qual_type(ivar_decl->getType()); |
| 5833 | |
| 5834 | child_name.assign(ivar_decl->getNameAsString().c_str()); |
| 5835 | |
| 5836 | clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 5837 | |
| 5838 | child_byte_size = ivar_type_info.Width / 8; |
| 5839 | |
| 5840 | // Figure out the field offset within the current struct/union/class type |
| 5841 | // For ObjC objects, we can't trust the bit offset we get from the Clang AST, since |
| 5842 | // that doesn't account for the space taken up by unbacked properties, or from |
| 5843 | // the changing size of base classes that are newer than this class. |
| 5844 | // So if we have a process around that we can ask about this object, do so. |
| 5845 | child_byte_offset = LLDB_INVALID_IVAR_OFFSET; |
| 5846 | Process *process = nullptr; |
| 5847 | if (exe_ctx) |
| 5848 | process = exe_ctx->GetProcessPtr(); |
| 5849 | if (process) |
| 5850 | { |
| 5851 | ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime(); |
| 5852 | if (objc_runtime != nullptr) |
| 5853 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5854 | CompilerType parent_ast_type (getASTContext(), parent_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5855 | child_byte_offset = objc_runtime->GetByteOffsetForIvar (parent_ast_type, ivar_decl->getNameAsString().c_str()); |
| 5856 | } |
| 5857 | } |
| 5858 | |
| 5859 | // Setting this to UINT32_MAX to make sure we don't compute it twice... |
| 5860 | bit_offset = UINT32_MAX; |
| 5861 | |
| 5862 | if (child_byte_offset == static_cast<int32_t>(LLDB_INVALID_IVAR_OFFSET)) |
| 5863 | { |
| 5864 | bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx); |
| 5865 | child_byte_offset = bit_offset / 8; |
| 5866 | } |
| 5867 | |
| 5868 | // Note, the ObjC Ivar Byte offset is just that, it doesn't account for the bit offset |
| 5869 | // of a bitfield within its containing object. So regardless of where we get the byte |
| 5870 | // offset from, we still need to get the bit offset for bitfields from the layout. |
| 5871 | |
| 5872 | if (ClangASTContext::FieldIsBitfield (getASTContext(), ivar_decl, child_bitfield_bit_size)) |
| 5873 | { |
| 5874 | if (bit_offset == UINT32_MAX) |
| 5875 | bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx); |
| 5876 | |
| 5877 | child_bitfield_bit_offset = bit_offset % 8; |
| 5878 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5879 | return CompilerType (getASTContext(), ivar_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5880 | } |
| 5881 | ++child_idx; |
| 5882 | } |
| 5883 | } |
| 5884 | } |
| 5885 | } |
| 5886 | } |
| 5887 | break; |
| 5888 | |
| 5889 | case clang::Type::ObjCObjectPointer: |
| 5890 | if (idx_is_valid) |
| 5891 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5892 | CompilerType pointee_clang_type (GetPointeeType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5893 | |
| 5894 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) |
| 5895 | { |
| 5896 | child_is_deref_of_parent = false; |
| 5897 | bool tmp_child_is_deref_of_parent = false; |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 5898 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 5899 | idx, |
| 5900 | transparent_pointers, |
| 5901 | omit_empty_base_classes, |
| 5902 | ignore_array_bounds, |
| 5903 | child_name, |
| 5904 | child_byte_size, |
| 5905 | child_byte_offset, |
| 5906 | child_bitfield_bit_size, |
| 5907 | child_bitfield_bit_offset, |
| 5908 | child_is_base_class, |
| 5909 | tmp_child_is_deref_of_parent, |
| 5910 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5911 | } |
| 5912 | else |
| 5913 | { |
| 5914 | child_is_deref_of_parent = true; |
| 5915 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; |
| 5916 | if (parent_name) |
| 5917 | { |
| 5918 | child_name.assign(1, '*'); |
| 5919 | child_name += parent_name; |
| 5920 | } |
| 5921 | |
| 5922 | // We have a pointer to an simple type |
| 5923 | if (idx == 0 && pointee_clang_type.GetCompleteType()) |
| 5924 | { |
| 5925 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5926 | child_byte_offset = 0; |
| 5927 | return pointee_clang_type; |
| 5928 | } |
| 5929 | } |
| 5930 | } |
| 5931 | break; |
| 5932 | |
| 5933 | case clang::Type::Vector: |
| 5934 | case clang::Type::ExtVector: |
| 5935 | if (idx_is_valid) |
| 5936 | { |
| 5937 | const clang::VectorType *array = llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr()); |
| 5938 | if (array) |
| 5939 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5940 | CompilerType element_type (getASTContext(), array->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5941 | if (element_type.GetCompleteType()) |
| 5942 | { |
| 5943 | char element_name[64]; |
| 5944 | ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx)); |
| 5945 | child_name.assign(element_name); |
| 5946 | child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5947 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 5948 | return element_type; |
| 5949 | } |
| 5950 | } |
| 5951 | } |
| 5952 | break; |
| 5953 | |
| 5954 | case clang::Type::ConstantArray: |
| 5955 | case clang::Type::IncompleteArray: |
| 5956 | if (ignore_array_bounds || idx_is_valid) |
| 5957 | { |
| 5958 | const clang::ArrayType *array = GetQualType(type)->getAsArrayTypeUnsafe(); |
| 5959 | if (array) |
| 5960 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5961 | CompilerType element_type (getASTContext(), array->getElementType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5962 | if (element_type.GetCompleteType()) |
| 5963 | { |
| 5964 | char element_name[64]; |
| 5965 | ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx)); |
| 5966 | child_name.assign(element_name); |
| 5967 | child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 5968 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
| 5969 | return element_type; |
| 5970 | } |
| 5971 | } |
| 5972 | } |
| 5973 | break; |
| 5974 | |
| 5975 | |
| 5976 | case clang::Type::Pointer: |
| 5977 | if (idx_is_valid) |
| 5978 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5979 | CompilerType pointee_clang_type (GetPointeeType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5980 | |
| 5981 | // Don't dereference "void *" pointers |
| 5982 | if (pointee_clang_type.IsVoidType()) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5983 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5984 | |
| 5985 | if (transparent_pointers && pointee_clang_type.IsAggregateType ()) |
| 5986 | { |
| 5987 | child_is_deref_of_parent = false; |
| 5988 | bool tmp_child_is_deref_of_parent = false; |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 5989 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 5990 | idx, |
| 5991 | transparent_pointers, |
| 5992 | omit_empty_base_classes, |
| 5993 | ignore_array_bounds, |
| 5994 | child_name, |
| 5995 | child_byte_size, |
| 5996 | child_byte_offset, |
| 5997 | child_bitfield_bit_size, |
| 5998 | child_bitfield_bit_offset, |
| 5999 | child_is_base_class, |
| 6000 | tmp_child_is_deref_of_parent, |
| 6001 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6002 | } |
| 6003 | else |
| 6004 | { |
| 6005 | child_is_deref_of_parent = true; |
| 6006 | |
| 6007 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; |
| 6008 | if (parent_name) |
| 6009 | { |
| 6010 | child_name.assign(1, '*'); |
| 6011 | child_name += parent_name; |
| 6012 | } |
| 6013 | |
| 6014 | // We have a pointer to an simple type |
| 6015 | if (idx == 0) |
| 6016 | { |
| 6017 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6018 | child_byte_offset = 0; |
| 6019 | return pointee_clang_type; |
| 6020 | } |
| 6021 | } |
| 6022 | } |
| 6023 | break; |
| 6024 | |
| 6025 | case clang::Type::LValueReference: |
| 6026 | case clang::Type::RValueReference: |
| 6027 | if (idx_is_valid) |
| 6028 | { |
| 6029 | 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] | 6030 | CompilerType pointee_clang_type (getASTContext(), reference_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6031 | if (transparent_pointers && pointee_clang_type.IsAggregateType ()) |
| 6032 | { |
| 6033 | child_is_deref_of_parent = false; |
| 6034 | bool tmp_child_is_deref_of_parent = false; |
Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6035 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6036 | idx, |
| 6037 | transparent_pointers, |
| 6038 | omit_empty_base_classes, |
| 6039 | ignore_array_bounds, |
| 6040 | child_name, |
| 6041 | child_byte_size, |
| 6042 | child_byte_offset, |
| 6043 | child_bitfield_bit_size, |
| 6044 | child_bitfield_bit_offset, |
| 6045 | child_is_base_class, |
| 6046 | tmp_child_is_deref_of_parent, |
| 6047 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6048 | } |
| 6049 | else |
| 6050 | { |
| 6051 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; |
| 6052 | if (parent_name) |
| 6053 | { |
| 6054 | child_name.assign(1, '&'); |
| 6055 | child_name += parent_name; |
| 6056 | } |
| 6057 | |
| 6058 | // We have a pointer to an simple type |
| 6059 | if (idx == 0) |
| 6060 | { |
| 6061 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); |
| 6062 | child_byte_offset = 0; |
| 6063 | return pointee_clang_type; |
| 6064 | } |
| 6065 | } |
| 6066 | } |
| 6067 | break; |
| 6068 | |
| 6069 | case clang::Type::Typedef: |
| 6070 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6071 | 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] | 6072 | return typedefed_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6073 | idx, |
| 6074 | transparent_pointers, |
| 6075 | omit_empty_base_classes, |
| 6076 | ignore_array_bounds, |
| 6077 | child_name, |
| 6078 | child_byte_size, |
| 6079 | child_byte_offset, |
| 6080 | child_bitfield_bit_size, |
| 6081 | child_bitfield_bit_offset, |
| 6082 | child_is_base_class, |
| 6083 | child_is_deref_of_parent, |
| 6084 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6085 | } |
| 6086 | break; |
| 6087 | |
| 6088 | case clang::Type::Elaborated: |
| 6089 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6090 | 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] | 6091 | return elaborated_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6092 | idx, |
| 6093 | transparent_pointers, |
| 6094 | omit_empty_base_classes, |
| 6095 | ignore_array_bounds, |
| 6096 | child_name, |
| 6097 | child_byte_size, |
| 6098 | child_byte_offset, |
| 6099 | child_bitfield_bit_size, |
| 6100 | child_bitfield_bit_offset, |
| 6101 | child_is_base_class, |
| 6102 | child_is_deref_of_parent, |
| 6103 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6104 | } |
| 6105 | |
| 6106 | case clang::Type::Paren: |
| 6107 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6108 | 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] | 6109 | return paren_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, |
| 6110 | idx, |
| 6111 | transparent_pointers, |
| 6112 | omit_empty_base_classes, |
| 6113 | ignore_array_bounds, |
| 6114 | child_name, |
| 6115 | child_byte_size, |
| 6116 | child_byte_offset, |
| 6117 | child_bitfield_bit_size, |
| 6118 | child_bitfield_bit_offset, |
| 6119 | child_is_base_class, |
| 6120 | child_is_deref_of_parent, |
| 6121 | valobj); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6122 | } |
| 6123 | |
| 6124 | |
| 6125 | default: |
| 6126 | break; |
| 6127 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6128 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6129 | } |
| 6130 | |
| 6131 | static uint32_t |
| 6132 | GetIndexForRecordBase |
| 6133 | ( |
| 6134 | const clang::RecordDecl *record_decl, |
| 6135 | const clang::CXXBaseSpecifier *base_spec, |
| 6136 | bool omit_empty_base_classes |
| 6137 | ) |
| 6138 | { |
| 6139 | uint32_t child_idx = 0; |
| 6140 | |
| 6141 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6142 | |
| 6143 | // const char *super_name = record_decl->getNameAsCString(); |
| 6144 | // const char *base_name = base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString(); |
| 6145 | // printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name); |
| 6146 | // |
| 6147 | if (cxx_record_decl) |
| 6148 | { |
| 6149 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 6150 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 6151 | base_class != base_class_end; |
| 6152 | ++base_class) |
| 6153 | { |
| 6154 | if (omit_empty_base_classes) |
| 6155 | { |
| 6156 | if (BaseSpecifierIsEmpty (base_class)) |
| 6157 | continue; |
| 6158 | } |
| 6159 | |
| 6160 | // printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", super_name, base_name, |
| 6161 | // child_idx, |
| 6162 | // base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString()); |
| 6163 | // |
| 6164 | // |
| 6165 | if (base_class == base_spec) |
| 6166 | return child_idx; |
| 6167 | ++child_idx; |
| 6168 | } |
| 6169 | } |
| 6170 | |
| 6171 | return UINT32_MAX; |
| 6172 | } |
| 6173 | |
| 6174 | |
| 6175 | static uint32_t |
| 6176 | GetIndexForRecordChild (const clang::RecordDecl *record_decl, |
| 6177 | clang::NamedDecl *canonical_decl, |
| 6178 | bool omit_empty_base_classes) |
| 6179 | { |
| 6180 | uint32_t child_idx = ClangASTContext::GetNumBaseClasses (llvm::dyn_cast<clang::CXXRecordDecl>(record_decl), |
| 6181 | omit_empty_base_classes); |
| 6182 | |
| 6183 | clang::RecordDecl::field_iterator field, field_end; |
| 6184 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 6185 | field != field_end; |
| 6186 | ++field, ++child_idx) |
| 6187 | { |
| 6188 | if (field->getCanonicalDecl() == canonical_decl) |
| 6189 | return child_idx; |
| 6190 | } |
| 6191 | |
| 6192 | return UINT32_MAX; |
| 6193 | } |
| 6194 | |
| 6195 | // Look for a child member (doesn't include base classes, but it does include |
| 6196 | // their members) in the type hierarchy. Returns an index path into "clang_type" |
| 6197 | // on how to reach the appropriate member. |
| 6198 | // |
| 6199 | // class A |
| 6200 | // { |
| 6201 | // public: |
| 6202 | // int m_a; |
| 6203 | // int m_b; |
| 6204 | // }; |
| 6205 | // |
| 6206 | // class B |
| 6207 | // { |
| 6208 | // }; |
| 6209 | // |
| 6210 | // class C : |
| 6211 | // public B, |
| 6212 | // public A |
| 6213 | // { |
| 6214 | // }; |
| 6215 | // |
| 6216 | // If we have a clang type that describes "class C", and we wanted to looked |
| 6217 | // "m_b" in it: |
| 6218 | // |
| 6219 | // With omit_empty_base_classes == false we would get an integer array back with: |
| 6220 | // { 1, 1 } |
| 6221 | // The first index 1 is the child index for "class A" within class C |
| 6222 | // The second index 1 is the child index for "m_b" within class A |
| 6223 | // |
| 6224 | // With omit_empty_base_classes == true we would get an integer array back with: |
| 6225 | // { 0, 1 } |
| 6226 | // 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) |
| 6227 | // The second index 1 is the child index for "m_b" within class A |
| 6228 | |
| 6229 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6230 | ClangASTContext::GetIndexOfChildMemberWithName (lldb::opaque_compiler_type_t type, const char *name, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6231 | bool omit_empty_base_classes, |
| 6232 | std::vector<uint32_t>& child_indexes) |
| 6233 | { |
| 6234 | if (type && name && name[0]) |
| 6235 | { |
| 6236 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6237 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6238 | switch (type_class) |
| 6239 | { |
| 6240 | case clang::Type::Record: |
| 6241 | if (GetCompleteType(type)) |
| 6242 | { |
| 6243 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 6244 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 6245 | |
| 6246 | assert(record_decl); |
| 6247 | uint32_t child_idx = 0; |
| 6248 | |
| 6249 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6250 | |
| 6251 | // Try and find a field that matches NAME |
| 6252 | clang::RecordDecl::field_iterator field, field_end; |
| 6253 | llvm::StringRef name_sref(name); |
| 6254 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 6255 | field != field_end; |
| 6256 | ++field, ++child_idx) |
| 6257 | { |
| 6258 | llvm::StringRef field_name = field->getName(); |
| 6259 | if (field_name.empty()) |
| 6260 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6261 | CompilerType field_type(getASTContext(),field->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6262 | child_indexes.push_back(child_idx); |
| 6263 | if (field_type.GetIndexOfChildMemberWithName(name, omit_empty_base_classes, child_indexes)) |
| 6264 | return child_indexes.size(); |
| 6265 | child_indexes.pop_back(); |
| 6266 | |
| 6267 | } |
| 6268 | else if (field_name.equals (name_sref)) |
| 6269 | { |
| 6270 | // We have to add on the number of base classes to this index! |
| 6271 | child_indexes.push_back (child_idx + ClangASTContext::GetNumBaseClasses (cxx_record_decl, omit_empty_base_classes)); |
| 6272 | return child_indexes.size(); |
| 6273 | } |
| 6274 | } |
| 6275 | |
| 6276 | if (cxx_record_decl) |
| 6277 | { |
| 6278 | const clang::RecordDecl *parent_record_decl = cxx_record_decl; |
| 6279 | |
| 6280 | //printf ("parent = %s\n", parent_record_decl->getNameAsCString()); |
| 6281 | |
| 6282 | //const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl(); |
| 6283 | // Didn't find things easily, lets let clang do its thang... |
| 6284 | clang::IdentifierInfo & ident_ref = getASTContext()->Idents.get(name_sref); |
| 6285 | clang::DeclarationName decl_name(&ident_ref); |
| 6286 | |
| 6287 | clang::CXXBasePaths paths; |
| 6288 | if (cxx_record_decl->lookupInBases([decl_name](const clang::CXXBaseSpecifier *specifier, clang::CXXBasePath &path) { |
| 6289 | return clang::CXXRecordDecl::FindOrdinaryMember(specifier, path, decl_name); |
| 6290 | }, |
| 6291 | paths)) |
| 6292 | { |
| 6293 | clang::CXXBasePaths::const_paths_iterator path, path_end = paths.end(); |
| 6294 | for (path = paths.begin(); path != path_end; ++path) |
| 6295 | { |
| 6296 | const size_t num_path_elements = path->size(); |
| 6297 | for (size_t e=0; e<num_path_elements; ++e) |
| 6298 | { |
| 6299 | clang::CXXBasePathElement elem = (*path)[e]; |
| 6300 | |
| 6301 | child_idx = GetIndexForRecordBase (parent_record_decl, elem.Base, omit_empty_base_classes); |
| 6302 | if (child_idx == UINT32_MAX) |
| 6303 | { |
| 6304 | child_indexes.clear(); |
| 6305 | return 0; |
| 6306 | } |
| 6307 | else |
| 6308 | { |
| 6309 | child_indexes.push_back (child_idx); |
| 6310 | parent_record_decl = llvm::cast<clang::RecordDecl>(elem.Base->getType()->getAs<clang::RecordType>()->getDecl()); |
| 6311 | } |
| 6312 | } |
| 6313 | for (clang::NamedDecl *path_decl : path->Decls) |
| 6314 | { |
| 6315 | child_idx = GetIndexForRecordChild (parent_record_decl, path_decl, omit_empty_base_classes); |
| 6316 | if (child_idx == UINT32_MAX) |
| 6317 | { |
| 6318 | child_indexes.clear(); |
| 6319 | return 0; |
| 6320 | } |
| 6321 | else |
| 6322 | { |
| 6323 | child_indexes.push_back (child_idx); |
| 6324 | } |
| 6325 | } |
| 6326 | } |
| 6327 | return child_indexes.size(); |
| 6328 | } |
| 6329 | } |
| 6330 | |
| 6331 | } |
| 6332 | break; |
| 6333 | |
| 6334 | case clang::Type::ObjCObject: |
| 6335 | case clang::Type::ObjCInterface: |
| 6336 | if (GetCompleteType(type)) |
| 6337 | { |
| 6338 | llvm::StringRef name_sref(name); |
| 6339 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 6340 | assert (objc_class_type); |
| 6341 | if (objc_class_type) |
| 6342 | { |
| 6343 | uint32_t child_idx = 0; |
| 6344 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 6345 | |
| 6346 | if (class_interface_decl) |
| 6347 | { |
| 6348 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 6349 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 6350 | |
| 6351 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx) |
| 6352 | { |
| 6353 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 6354 | |
| 6355 | if (ivar_decl->getName().equals (name_sref)) |
| 6356 | { |
| 6357 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 6358 | ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true))) |
| 6359 | ++child_idx; |
| 6360 | |
| 6361 | child_indexes.push_back (child_idx); |
| 6362 | return child_indexes.size(); |
| 6363 | } |
| 6364 | } |
| 6365 | |
| 6366 | if (superclass_interface_decl) |
| 6367 | { |
| 6368 | // The super class index is always zero for ObjC classes, |
| 6369 | // so we push it onto the child indexes in case we find |
| 6370 | // an ivar in our superclass... |
| 6371 | child_indexes.push_back (0); |
| 6372 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6373 | CompilerType superclass_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6374 | if (superclass_clang_type.GetIndexOfChildMemberWithName (name, |
| 6375 | omit_empty_base_classes, |
| 6376 | child_indexes)) |
| 6377 | { |
| 6378 | // We did find an ivar in a superclass so just |
| 6379 | // return the results! |
| 6380 | return child_indexes.size(); |
| 6381 | } |
| 6382 | |
| 6383 | // We didn't find an ivar matching "name" in our |
| 6384 | // superclass, pop the superclass zero index that |
| 6385 | // we pushed on above. |
| 6386 | child_indexes.pop_back(); |
| 6387 | } |
| 6388 | } |
| 6389 | } |
| 6390 | } |
| 6391 | break; |
| 6392 | |
| 6393 | case clang::Type::ObjCObjectPointer: |
| 6394 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6395 | 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] | 6396 | return objc_object_clang_type.GetIndexOfChildMemberWithName (name, |
| 6397 | omit_empty_base_classes, |
| 6398 | child_indexes); |
| 6399 | } |
| 6400 | break; |
| 6401 | |
| 6402 | |
| 6403 | case clang::Type::ConstantArray: |
| 6404 | { |
| 6405 | // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 6406 | // const uint64_t element_count = array->getSize().getLimitedValue(); |
| 6407 | // |
| 6408 | // if (idx < element_count) |
| 6409 | // { |
| 6410 | // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); |
| 6411 | // |
| 6412 | // char element_name[32]; |
| 6413 | // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx); |
| 6414 | // |
| 6415 | // child_name.assign(element_name); |
| 6416 | // assert(field_type_info.first % 8 == 0); |
| 6417 | // child_byte_size = field_type_info.first / 8; |
| 6418 | // child_byte_offset = idx * child_byte_size; |
| 6419 | // return array->getElementType().getAsOpaquePtr(); |
| 6420 | // } |
| 6421 | } |
| 6422 | break; |
| 6423 | |
| 6424 | // case clang::Type::MemberPointerType: |
| 6425 | // { |
| 6426 | // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr()); |
| 6427 | // clang::QualType pointee_type = mem_ptr_type->getPointeeType(); |
| 6428 | // |
| 6429 | // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 6430 | // { |
| 6431 | // return GetIndexOfChildWithName (ast, |
| 6432 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 6433 | // name); |
| 6434 | // } |
| 6435 | // } |
| 6436 | // break; |
| 6437 | // |
| 6438 | case clang::Type::LValueReference: |
| 6439 | case clang::Type::RValueReference: |
| 6440 | { |
| 6441 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
| 6442 | clang::QualType pointee_type(reference_type->getPointeeType()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6443 | CompilerType pointee_clang_type (getASTContext(), pointee_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6444 | |
| 6445 | if (pointee_clang_type.IsAggregateType ()) |
| 6446 | { |
| 6447 | return pointee_clang_type.GetIndexOfChildMemberWithName (name, |
| 6448 | omit_empty_base_classes, |
| 6449 | child_indexes); |
| 6450 | } |
| 6451 | } |
| 6452 | break; |
| 6453 | |
| 6454 | case clang::Type::Pointer: |
| 6455 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6456 | CompilerType pointee_clang_type (GetPointeeType(type)); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6457 | |
| 6458 | if (pointee_clang_type.IsAggregateType ()) |
| 6459 | { |
| 6460 | return pointee_clang_type.GetIndexOfChildMemberWithName (name, |
| 6461 | omit_empty_base_classes, |
| 6462 | child_indexes); |
| 6463 | } |
| 6464 | } |
| 6465 | break; |
| 6466 | |
| 6467 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6468 | 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] | 6469 | omit_empty_base_classes, |
| 6470 | child_indexes); |
| 6471 | |
| 6472 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6473 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildMemberWithName (name, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6474 | omit_empty_base_classes, |
| 6475 | child_indexes); |
| 6476 | |
| 6477 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6478 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildMemberWithName (name, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6479 | omit_empty_base_classes, |
| 6480 | child_indexes); |
| 6481 | |
| 6482 | default: |
| 6483 | break; |
| 6484 | } |
| 6485 | } |
| 6486 | return 0; |
| 6487 | } |
| 6488 | |
| 6489 | |
| 6490 | // Get the index of the child of "clang_type" whose name matches. This function |
| 6491 | // doesn't descend into the children, but only looks one level deep and name |
| 6492 | // matches can include base class names. |
| 6493 | |
| 6494 | uint32_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6495 | 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] | 6496 | { |
| 6497 | if (type && name && name[0]) |
| 6498 | { |
| 6499 | clang::QualType qual_type(GetCanonicalQualType(type)); |
| 6500 | |
| 6501 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6502 | |
| 6503 | switch (type_class) |
| 6504 | { |
| 6505 | case clang::Type::Record: |
| 6506 | if (GetCompleteType(type)) |
| 6507 | { |
| 6508 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 6509 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 6510 | |
| 6511 | assert(record_decl); |
| 6512 | uint32_t child_idx = 0; |
| 6513 | |
| 6514 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 6515 | |
| 6516 | if (cxx_record_decl) |
| 6517 | { |
| 6518 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 6519 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 6520 | base_class != base_class_end; |
| 6521 | ++base_class) |
| 6522 | { |
| 6523 | // Skip empty base classes |
| 6524 | clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 6525 | if (omit_empty_base_classes && ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 6526 | continue; |
| 6527 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6528 | CompilerType base_class_clang_type (getASTContext(), base_class->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6529 | std::string base_class_type_name (base_class_clang_type.GetTypeName().AsCString("")); |
| 6530 | if (base_class_type_name.compare (name) == 0) |
| 6531 | return child_idx; |
| 6532 | ++child_idx; |
| 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | // Try and find a field that matches NAME |
| 6537 | clang::RecordDecl::field_iterator field, field_end; |
| 6538 | llvm::StringRef name_sref(name); |
| 6539 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 6540 | field != field_end; |
| 6541 | ++field, ++child_idx) |
| 6542 | { |
| 6543 | if (field->getName().equals (name_sref)) |
| 6544 | return child_idx; |
| 6545 | } |
| 6546 | |
| 6547 | } |
| 6548 | break; |
| 6549 | |
| 6550 | case clang::Type::ObjCObject: |
| 6551 | case clang::Type::ObjCInterface: |
| 6552 | if (GetCompleteType(type)) |
| 6553 | { |
| 6554 | llvm::StringRef name_sref(name); |
| 6555 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 6556 | assert (objc_class_type); |
| 6557 | if (objc_class_type) |
| 6558 | { |
| 6559 | uint32_t child_idx = 0; |
| 6560 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 6561 | |
| 6562 | if (class_interface_decl) |
| 6563 | { |
| 6564 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 6565 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 6566 | |
| 6567 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx) |
| 6568 | { |
| 6569 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 6570 | |
| 6571 | if (ivar_decl->getName().equals (name_sref)) |
| 6572 | { |
| 6573 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 6574 | ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true))) |
| 6575 | ++child_idx; |
| 6576 | |
| 6577 | return child_idx; |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | if (superclass_interface_decl) |
| 6582 | { |
| 6583 | if (superclass_interface_decl->getName().equals (name_sref)) |
| 6584 | return 0; |
| 6585 | } |
| 6586 | } |
| 6587 | } |
| 6588 | } |
| 6589 | break; |
| 6590 | |
| 6591 | case clang::Type::ObjCObjectPointer: |
| 6592 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6593 | 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] | 6594 | return pointee_clang_type.GetIndexOfChildWithName (name, omit_empty_base_classes); |
| 6595 | } |
| 6596 | break; |
| 6597 | |
| 6598 | case clang::Type::ConstantArray: |
| 6599 | { |
| 6600 | // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 6601 | // const uint64_t element_count = array->getSize().getLimitedValue(); |
| 6602 | // |
| 6603 | // if (idx < element_count) |
| 6604 | // { |
| 6605 | // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); |
| 6606 | // |
| 6607 | // char element_name[32]; |
| 6608 | // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx); |
| 6609 | // |
| 6610 | // child_name.assign(element_name); |
| 6611 | // assert(field_type_info.first % 8 == 0); |
| 6612 | // child_byte_size = field_type_info.first / 8; |
| 6613 | // child_byte_offset = idx * child_byte_size; |
| 6614 | // return array->getElementType().getAsOpaquePtr(); |
| 6615 | // } |
| 6616 | } |
| 6617 | break; |
| 6618 | |
| 6619 | // case clang::Type::MemberPointerType: |
| 6620 | // { |
| 6621 | // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr()); |
| 6622 | // clang::QualType pointee_type = mem_ptr_type->getPointeeType(); |
| 6623 | // |
| 6624 | // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 6625 | // { |
| 6626 | // return GetIndexOfChildWithName (ast, |
| 6627 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 6628 | // name); |
| 6629 | // } |
| 6630 | // } |
| 6631 | // break; |
| 6632 | // |
| 6633 | case clang::Type::LValueReference: |
| 6634 | case clang::Type::RValueReference: |
| 6635 | { |
| 6636 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6637 | CompilerType pointee_type (getASTContext(), reference_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6638 | |
| 6639 | if (pointee_type.IsAggregateType ()) |
| 6640 | { |
| 6641 | return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes); |
| 6642 | } |
| 6643 | } |
| 6644 | break; |
| 6645 | |
| 6646 | case clang::Type::Pointer: |
| 6647 | { |
| 6648 | const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr()); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6649 | CompilerType pointee_type (getASTContext(), pointer_type->getPointeeType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6650 | |
| 6651 | if (pointee_type.IsAggregateType ()) |
| 6652 | { |
| 6653 | return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes); |
| 6654 | } |
| 6655 | else |
| 6656 | { |
| 6657 | // if (parent_name) |
| 6658 | // { |
| 6659 | // child_name.assign(1, '*'); |
| 6660 | // child_name += parent_name; |
| 6661 | // } |
| 6662 | // |
| 6663 | // // We have a pointer to an simple type |
| 6664 | // if (idx == 0) |
| 6665 | // { |
| 6666 | // std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type); |
| 6667 | // assert(clang_type_info.first % 8 == 0); |
| 6668 | // child_byte_size = clang_type_info.first / 8; |
| 6669 | // child_byte_offset = 0; |
| 6670 | // return pointee_type.getAsOpaquePtr(); |
| 6671 | // } |
| 6672 | } |
| 6673 | } |
| 6674 | break; |
| 6675 | |
| 6676 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6677 | 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] | 6678 | |
| 6679 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6680 | 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] | 6681 | |
| 6682 | case clang::Type::Typedef: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6683 | 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] | 6684 | |
| 6685 | default: |
| 6686 | break; |
| 6687 | } |
| 6688 | } |
| 6689 | return UINT32_MAX; |
| 6690 | } |
| 6691 | |
| 6692 | |
| 6693 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6694 | ClangASTContext::GetNumTemplateArguments (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6695 | { |
| 6696 | if (!type) |
| 6697 | return 0; |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6698 | |
| 6699 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 6700 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6701 | switch (type_class) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6702 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6703 | case clang::Type::Record: |
| 6704 | if (GetCompleteType(type)) |
| 6705 | { |
| 6706 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 6707 | if (cxx_record_decl) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6708 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6709 | const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl); |
| 6710 | if (template_decl) |
| 6711 | return template_decl->getTemplateArgs().size(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6712 | } |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6713 | } |
| 6714 | break; |
| 6715 | |
| 6716 | case clang::Type::Typedef: |
| 6717 | return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetNumTemplateArguments(); |
| 6718 | |
| 6719 | case clang::Type::Elaborated: |
| 6720 | return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetNumTemplateArguments(); |
| 6721 | |
| 6722 | case clang::Type::Paren: |
| 6723 | return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetNumTemplateArguments(); |
| 6724 | |
| 6725 | default: |
| 6726 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6727 | } |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6728 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6729 | return 0; |
| 6730 | } |
| 6731 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6732 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6733 | 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] | 6734 | { |
| 6735 | if (!type) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6736 | return CompilerType(); |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6737 | |
| 6738 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 6739 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6740 | switch (type_class) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6741 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6742 | case clang::Type::Record: |
| 6743 | if (GetCompleteType(type)) |
| 6744 | { |
| 6745 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 6746 | if (cxx_record_decl) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6747 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6748 | const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl); |
| 6749 | if (template_decl && arg_idx < template_decl->getTemplateArgs().size()) |
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 | const clang::TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx]; |
| 6752 | switch (template_arg.getKind()) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6753 | { |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6754 | case clang::TemplateArgument::Null: |
| 6755 | kind = eTemplateArgumentKindNull; |
| 6756 | return CompilerType(); |
| 6757 | |
| 6758 | case clang::TemplateArgument::Type: |
| 6759 | kind = eTemplateArgumentKindType; |
| 6760 | return CompilerType(getASTContext(), template_arg.getAsType()); |
| 6761 | |
| 6762 | case clang::TemplateArgument::Declaration: |
| 6763 | kind = eTemplateArgumentKindDeclaration; |
| 6764 | return CompilerType(); |
| 6765 | |
| 6766 | case clang::TemplateArgument::Integral: |
| 6767 | kind = eTemplateArgumentKindIntegral; |
| 6768 | return CompilerType(getASTContext(), template_arg.getIntegralType()); |
| 6769 | |
| 6770 | case clang::TemplateArgument::Template: |
| 6771 | kind = eTemplateArgumentKindTemplate; |
| 6772 | return CompilerType(); |
| 6773 | |
| 6774 | case clang::TemplateArgument::TemplateExpansion: |
| 6775 | kind = eTemplateArgumentKindTemplateExpansion; |
| 6776 | return CompilerType(); |
| 6777 | |
| 6778 | case clang::TemplateArgument::Expression: |
| 6779 | kind = eTemplateArgumentKindExpression; |
| 6780 | return CompilerType(); |
| 6781 | |
| 6782 | case clang::TemplateArgument::Pack: |
| 6783 | kind = eTemplateArgumentKindPack; |
| 6784 | return CompilerType(); |
| 6785 | |
| 6786 | default: |
| 6787 | assert (!"Unhandled clang::TemplateArgument::ArgKind"); |
| 6788 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6789 | } |
| 6790 | } |
| 6791 | } |
Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 6792 | } |
| 6793 | break; |
| 6794 | |
| 6795 | case clang::Type::Typedef: |
| 6796 | return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetTemplateArgument(arg_idx, kind); |
| 6797 | |
| 6798 | case clang::Type::Elaborated: |
| 6799 | return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetTemplateArgument(arg_idx, kind); |
| 6800 | |
| 6801 | case clang::Type::Paren: |
| 6802 | return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetTemplateArgument(arg_idx, kind); |
| 6803 | |
| 6804 | default: |
| 6805 | break; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6806 | } |
| 6807 | kind = eTemplateArgumentKindNull; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6808 | return CompilerType (); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6809 | } |
| 6810 | |
Enrico Granata | c6bf2e2 | 2015-09-23 01:39:46 +0000 | [diff] [blame] | 6811 | CompilerType |
| 6812 | ClangASTContext::GetTypeForFormatters (void* type) |
| 6813 | { |
| 6814 | if (type) |
| 6815 | return RemoveFastQualifiers(CompilerType(this, type)); |
| 6816 | return CompilerType(); |
| 6817 | } |
| 6818 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6819 | static bool |
| 6820 | IsOperator (const char *name, clang::OverloadedOperatorKind &op_kind) |
| 6821 | { |
| 6822 | if (name == nullptr || name[0] == '\0') |
| 6823 | return false; |
| 6824 | |
| 6825 | #define OPERATOR_PREFIX "operator" |
| 6826 | #define OPERATOR_PREFIX_LENGTH (sizeof (OPERATOR_PREFIX) - 1) |
| 6827 | |
| 6828 | const char *post_op_name = nullptr; |
| 6829 | |
| 6830 | bool no_space = true; |
| 6831 | |
| 6832 | if (::strncmp(name, OPERATOR_PREFIX, OPERATOR_PREFIX_LENGTH)) |
| 6833 | return false; |
| 6834 | |
| 6835 | post_op_name = name + OPERATOR_PREFIX_LENGTH; |
| 6836 | |
| 6837 | if (post_op_name[0] == ' ') |
| 6838 | { |
| 6839 | post_op_name++; |
| 6840 | no_space = false; |
| 6841 | } |
| 6842 | |
| 6843 | #undef OPERATOR_PREFIX |
| 6844 | #undef OPERATOR_PREFIX_LENGTH |
| 6845 | |
| 6846 | // This is an operator, set the overloaded operator kind to invalid |
| 6847 | // in case this is a conversion operator... |
| 6848 | op_kind = clang::NUM_OVERLOADED_OPERATORS; |
| 6849 | |
| 6850 | switch (post_op_name[0]) |
| 6851 | { |
| 6852 | default: |
| 6853 | if (no_space) |
| 6854 | return false; |
| 6855 | break; |
| 6856 | case 'n': |
| 6857 | if (no_space) |
| 6858 | return false; |
| 6859 | if (strcmp (post_op_name, "new") == 0) |
| 6860 | op_kind = clang::OO_New; |
| 6861 | else if (strcmp (post_op_name, "new[]") == 0) |
| 6862 | op_kind = clang::OO_Array_New; |
| 6863 | break; |
| 6864 | |
| 6865 | case 'd': |
| 6866 | if (no_space) |
| 6867 | return false; |
| 6868 | if (strcmp (post_op_name, "delete") == 0) |
| 6869 | op_kind = clang::OO_Delete; |
| 6870 | else if (strcmp (post_op_name, "delete[]") == 0) |
| 6871 | op_kind = clang::OO_Array_Delete; |
| 6872 | break; |
| 6873 | |
| 6874 | case '+': |
| 6875 | if (post_op_name[1] == '\0') |
| 6876 | op_kind = clang::OO_Plus; |
| 6877 | else if (post_op_name[2] == '\0') |
| 6878 | { |
| 6879 | if (post_op_name[1] == '=') |
| 6880 | op_kind = clang::OO_PlusEqual; |
| 6881 | else if (post_op_name[1] == '+') |
| 6882 | op_kind = clang::OO_PlusPlus; |
| 6883 | } |
| 6884 | break; |
| 6885 | |
| 6886 | case '-': |
| 6887 | if (post_op_name[1] == '\0') |
| 6888 | op_kind = clang::OO_Minus; |
| 6889 | else if (post_op_name[2] == '\0') |
| 6890 | { |
| 6891 | switch (post_op_name[1]) |
| 6892 | { |
| 6893 | case '=': op_kind = clang::OO_MinusEqual; break; |
| 6894 | case '-': op_kind = clang::OO_MinusMinus; break; |
| 6895 | case '>': op_kind = clang::OO_Arrow; break; |
| 6896 | } |
| 6897 | } |
| 6898 | else if (post_op_name[3] == '\0') |
| 6899 | { |
| 6900 | if (post_op_name[2] == '*') |
| 6901 | op_kind = clang::OO_ArrowStar; break; |
| 6902 | } |
| 6903 | break; |
| 6904 | |
| 6905 | case '*': |
| 6906 | if (post_op_name[1] == '\0') |
| 6907 | op_kind = clang::OO_Star; |
| 6908 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6909 | op_kind = clang::OO_StarEqual; |
| 6910 | break; |
| 6911 | |
| 6912 | case '/': |
| 6913 | if (post_op_name[1] == '\0') |
| 6914 | op_kind = clang::OO_Slash; |
| 6915 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6916 | op_kind = clang::OO_SlashEqual; |
| 6917 | break; |
| 6918 | |
| 6919 | case '%': |
| 6920 | if (post_op_name[1] == '\0') |
| 6921 | op_kind = clang::OO_Percent; |
| 6922 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6923 | op_kind = clang::OO_PercentEqual; |
| 6924 | break; |
| 6925 | |
| 6926 | |
| 6927 | case '^': |
| 6928 | if (post_op_name[1] == '\0') |
| 6929 | op_kind = clang::OO_Caret; |
| 6930 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6931 | op_kind = clang::OO_CaretEqual; |
| 6932 | break; |
| 6933 | |
| 6934 | case '&': |
| 6935 | if (post_op_name[1] == '\0') |
| 6936 | op_kind = clang::OO_Amp; |
| 6937 | else if (post_op_name[2] == '\0') |
| 6938 | { |
| 6939 | switch (post_op_name[1]) |
| 6940 | { |
| 6941 | case '=': op_kind = clang::OO_AmpEqual; break; |
| 6942 | case '&': op_kind = clang::OO_AmpAmp; break; |
| 6943 | } |
| 6944 | } |
| 6945 | break; |
| 6946 | |
| 6947 | case '|': |
| 6948 | if (post_op_name[1] == '\0') |
| 6949 | op_kind = clang::OO_Pipe; |
| 6950 | else if (post_op_name[2] == '\0') |
| 6951 | { |
| 6952 | switch (post_op_name[1]) |
| 6953 | { |
| 6954 | case '=': op_kind = clang::OO_PipeEqual; break; |
| 6955 | case '|': op_kind = clang::OO_PipePipe; break; |
| 6956 | } |
| 6957 | } |
| 6958 | break; |
| 6959 | |
| 6960 | case '~': |
| 6961 | if (post_op_name[1] == '\0') |
| 6962 | op_kind = clang::OO_Tilde; |
| 6963 | break; |
| 6964 | |
| 6965 | case '!': |
| 6966 | if (post_op_name[1] == '\0') |
| 6967 | op_kind = clang::OO_Exclaim; |
| 6968 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6969 | op_kind = clang::OO_ExclaimEqual; |
| 6970 | break; |
| 6971 | |
| 6972 | case '=': |
| 6973 | if (post_op_name[1] == '\0') |
| 6974 | op_kind = clang::OO_Equal; |
| 6975 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 6976 | op_kind = clang::OO_EqualEqual; |
| 6977 | break; |
| 6978 | |
| 6979 | case '<': |
| 6980 | if (post_op_name[1] == '\0') |
| 6981 | op_kind = clang::OO_Less; |
| 6982 | else if (post_op_name[2] == '\0') |
| 6983 | { |
| 6984 | switch (post_op_name[1]) |
| 6985 | { |
| 6986 | case '<': op_kind = clang::OO_LessLess; break; |
| 6987 | case '=': op_kind = clang::OO_LessEqual; break; |
| 6988 | } |
| 6989 | } |
| 6990 | else if (post_op_name[3] == '\0') |
| 6991 | { |
| 6992 | if (post_op_name[2] == '=') |
| 6993 | op_kind = clang::OO_LessLessEqual; |
| 6994 | } |
| 6995 | break; |
| 6996 | |
| 6997 | case '>': |
| 6998 | if (post_op_name[1] == '\0') |
| 6999 | op_kind = clang::OO_Greater; |
| 7000 | else if (post_op_name[2] == '\0') |
| 7001 | { |
| 7002 | switch (post_op_name[1]) |
| 7003 | { |
| 7004 | case '>': op_kind = clang::OO_GreaterGreater; break; |
| 7005 | case '=': op_kind = clang::OO_GreaterEqual; break; |
| 7006 | } |
| 7007 | } |
| 7008 | else if (post_op_name[1] == '>' && |
| 7009 | post_op_name[2] == '=' && |
| 7010 | post_op_name[3] == '\0') |
| 7011 | { |
| 7012 | op_kind = clang::OO_GreaterGreaterEqual; |
| 7013 | } |
| 7014 | break; |
| 7015 | |
| 7016 | case ',': |
| 7017 | if (post_op_name[1] == '\0') |
| 7018 | op_kind = clang::OO_Comma; |
| 7019 | break; |
| 7020 | |
| 7021 | case '(': |
| 7022 | if (post_op_name[1] == ')' && post_op_name[2] == '\0') |
| 7023 | op_kind = clang::OO_Call; |
| 7024 | break; |
| 7025 | |
| 7026 | case '[': |
| 7027 | if (post_op_name[1] == ']' && post_op_name[2] == '\0') |
| 7028 | op_kind = clang::OO_Subscript; |
| 7029 | break; |
| 7030 | } |
| 7031 | |
| 7032 | return true; |
| 7033 | } |
| 7034 | |
| 7035 | clang::EnumDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7036 | ClangASTContext::GetAsEnumDecl (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7037 | { |
| 7038 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)); |
| 7039 | if (enutype) |
| 7040 | return enutype->getDecl(); |
| 7041 | return NULL; |
| 7042 | } |
| 7043 | |
| 7044 | clang::RecordDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7045 | ClangASTContext::GetAsRecordDecl (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7046 | { |
| 7047 | const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(GetCanonicalQualType(type)); |
| 7048 | if (record_type) |
| 7049 | return record_type->getDecl(); |
| 7050 | return nullptr; |
| 7051 | } |
| 7052 | |
| 7053 | clang::CXXRecordDecl * |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7054 | ClangASTContext::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7055 | { |
| 7056 | return GetCanonicalQualType(type)->getAsCXXRecordDecl(); |
| 7057 | } |
| 7058 | |
| 7059 | clang::ObjCInterfaceDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7060 | ClangASTContext::GetAsObjCInterfaceDecl (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7061 | { |
| 7062 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(GetCanonicalQualType(type)); |
| 7063 | if (objc_class_type) |
| 7064 | return objc_class_type->getInterface(); |
| 7065 | return nullptr; |
| 7066 | } |
| 7067 | |
| 7068 | clang::FieldDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7069 | ClangASTContext::AddFieldToRecordType (const CompilerType& type, const char *name, |
| 7070 | const CompilerType &field_clang_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7071 | AccessType access, |
| 7072 | uint32_t bitfield_bit_size) |
| 7073 | { |
| 7074 | if (!type.IsValid() || !field_clang_type.IsValid()) |
| 7075 | return nullptr; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7076 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7077 | if (!ast) |
| 7078 | return nullptr; |
| 7079 | clang::ASTContext* clang_ast = ast->getASTContext(); |
| 7080 | |
| 7081 | clang::FieldDecl *field = nullptr; |
| 7082 | |
| 7083 | clang::Expr *bit_width = nullptr; |
| 7084 | if (bitfield_bit_size != 0) |
| 7085 | { |
| 7086 | llvm::APInt bitfield_bit_size_apint(clang_ast->getTypeSize(clang_ast->IntTy), bitfield_bit_size); |
| 7087 | bit_width = new (*clang_ast)clang::IntegerLiteral (*clang_ast, bitfield_bit_size_apint, clang_ast->IntTy, clang::SourceLocation()); |
| 7088 | } |
| 7089 | |
| 7090 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type); |
| 7091 | if (record_decl) |
| 7092 | { |
| 7093 | field = clang::FieldDecl::Create (*clang_ast, |
| 7094 | record_decl, |
| 7095 | clang::SourceLocation(), |
| 7096 | clang::SourceLocation(), |
| 7097 | name ? &clang_ast->Idents.get(name) : nullptr, // Identifier |
| 7098 | GetQualType(field_clang_type), // Field type |
| 7099 | nullptr, // TInfo * |
| 7100 | bit_width, // BitWidth |
| 7101 | false, // Mutable |
| 7102 | clang::ICIS_NoInit); // HasInit |
| 7103 | |
| 7104 | if (!name) |
| 7105 | { |
| 7106 | // Determine whether this field corresponds to an anonymous |
| 7107 | // struct or union. |
| 7108 | if (const clang::TagType *TagT = field->getType()->getAs<clang::TagType>()) { |
| 7109 | if (clang::RecordDecl *Rec = llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl())) |
| 7110 | if (!Rec->getDeclName()) { |
| 7111 | Rec->setAnonymousStructOrUnion(true); |
| 7112 | field->setImplicit(); |
| 7113 | |
| 7114 | } |
| 7115 | } |
| 7116 | } |
| 7117 | |
| 7118 | if (field) |
| 7119 | { |
| 7120 | field->setAccess (ClangASTContext::ConvertAccessTypeToAccessSpecifier (access)); |
| 7121 | |
| 7122 | record_decl->addDecl(field); |
| 7123 | |
| 7124 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7125 | VerifyDecl(field); |
| 7126 | #endif |
| 7127 | } |
| 7128 | } |
| 7129 | else |
| 7130 | { |
| 7131 | clang::ObjCInterfaceDecl *class_interface_decl = ast->GetAsObjCInterfaceDecl (type); |
| 7132 | |
| 7133 | if (class_interface_decl) |
| 7134 | { |
| 7135 | const bool is_synthesized = false; |
| 7136 | |
| 7137 | field_clang_type.GetCompleteType(); |
| 7138 | |
| 7139 | field = clang::ObjCIvarDecl::Create (*clang_ast, |
| 7140 | class_interface_decl, |
| 7141 | clang::SourceLocation(), |
| 7142 | clang::SourceLocation(), |
| 7143 | name ? &clang_ast->Idents.get(name) : nullptr, // Identifier |
| 7144 | GetQualType(field_clang_type), // Field type |
| 7145 | nullptr, // TypeSourceInfo * |
| 7146 | ConvertAccessTypeToObjCIvarAccessControl (access), |
| 7147 | bit_width, |
| 7148 | is_synthesized); |
| 7149 | |
| 7150 | if (field) |
| 7151 | { |
| 7152 | class_interface_decl->addDecl(field); |
| 7153 | |
| 7154 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7155 | VerifyDecl(field); |
| 7156 | #endif |
| 7157 | } |
| 7158 | } |
| 7159 | } |
| 7160 | return field; |
| 7161 | } |
| 7162 | |
| 7163 | void |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7164 | ClangASTContext::BuildIndirectFields (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7165 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7166 | if (!type) |
| 7167 | return; |
| 7168 | |
| 7169 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7170 | if (!ast) |
| 7171 | return; |
| 7172 | |
| 7173 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); |
| 7174 | |
| 7175 | if (!record_decl) |
| 7176 | return; |
| 7177 | |
| 7178 | typedef llvm::SmallVector <clang::IndirectFieldDecl *, 1> IndirectFieldVector; |
| 7179 | |
| 7180 | IndirectFieldVector indirect_fields; |
| 7181 | clang::RecordDecl::field_iterator field_pos; |
| 7182 | clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end(); |
| 7183 | clang::RecordDecl::field_iterator last_field_pos = field_end_pos; |
| 7184 | for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; last_field_pos = field_pos++) |
| 7185 | { |
| 7186 | if (field_pos->isAnonymousStructOrUnion()) |
| 7187 | { |
| 7188 | clang::QualType field_qual_type = field_pos->getType(); |
| 7189 | |
| 7190 | const clang::RecordType *field_record_type = field_qual_type->getAs<clang::RecordType>(); |
| 7191 | |
| 7192 | if (!field_record_type) |
| 7193 | continue; |
| 7194 | |
| 7195 | clang::RecordDecl *field_record_decl = field_record_type->getDecl(); |
| 7196 | |
| 7197 | if (!field_record_decl) |
| 7198 | continue; |
| 7199 | |
| 7200 | for (clang::RecordDecl::decl_iterator di = field_record_decl->decls_begin(), de = field_record_decl->decls_end(); |
| 7201 | di != de; |
| 7202 | ++di) |
| 7203 | { |
| 7204 | if (clang::FieldDecl *nested_field_decl = llvm::dyn_cast<clang::FieldDecl>(*di)) |
| 7205 | { |
| 7206 | clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[2]; |
| 7207 | chain[0] = *field_pos; |
| 7208 | chain[1] = nested_field_decl; |
| 7209 | clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(), |
| 7210 | record_decl, |
| 7211 | clang::SourceLocation(), |
| 7212 | nested_field_decl->getIdentifier(), |
| 7213 | nested_field_decl->getType(), |
| 7214 | chain, |
| 7215 | 2); |
| 7216 | |
| 7217 | indirect_field->setImplicit(); |
| 7218 | |
| 7219 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(), |
| 7220 | nested_field_decl->getAccess())); |
| 7221 | |
| 7222 | indirect_fields.push_back(indirect_field); |
| 7223 | } |
| 7224 | else if (clang::IndirectFieldDecl *nested_indirect_field_decl = llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) |
| 7225 | { |
| 7226 | int nested_chain_size = nested_indirect_field_decl->getChainingSize(); |
| 7227 | clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[nested_chain_size + 1]; |
| 7228 | chain[0] = *field_pos; |
| 7229 | |
| 7230 | int chain_index = 1; |
| 7231 | for (clang::IndirectFieldDecl::chain_iterator nci = nested_indirect_field_decl->chain_begin(), |
| 7232 | nce = nested_indirect_field_decl->chain_end(); |
| 7233 | nci < nce; |
| 7234 | ++nci) |
| 7235 | { |
| 7236 | chain[chain_index] = *nci; |
| 7237 | chain_index++; |
| 7238 | } |
| 7239 | |
| 7240 | clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(), |
| 7241 | record_decl, |
| 7242 | clang::SourceLocation(), |
| 7243 | nested_indirect_field_decl->getIdentifier(), |
| 7244 | nested_indirect_field_decl->getType(), |
| 7245 | chain, |
| 7246 | nested_chain_size + 1); |
| 7247 | |
| 7248 | indirect_field->setImplicit(); |
| 7249 | |
| 7250 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(), |
| 7251 | nested_indirect_field_decl->getAccess())); |
| 7252 | |
| 7253 | indirect_fields.push_back(indirect_field); |
| 7254 | } |
| 7255 | } |
| 7256 | } |
| 7257 | } |
| 7258 | |
| 7259 | // Check the last field to see if it has an incomplete array type as its |
| 7260 | // last member and if it does, the tell the record decl about it |
| 7261 | if (last_field_pos != field_end_pos) |
| 7262 | { |
| 7263 | if (last_field_pos->getType()->isIncompleteArrayType()) |
| 7264 | record_decl->hasFlexibleArrayMember(); |
| 7265 | } |
| 7266 | |
| 7267 | for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), ife = indirect_fields.end(); |
| 7268 | ifi < ife; |
| 7269 | ++ifi) |
| 7270 | { |
| 7271 | record_decl->addDecl(*ifi); |
| 7272 | } |
| 7273 | } |
| 7274 | |
| 7275 | void |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7276 | ClangASTContext::SetIsPacked (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7277 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7278 | if (type) |
| 7279 | { |
| 7280 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 7281 | if (ast) |
| 7282 | { |
| 7283 | clang::RecordDecl *record_decl = GetAsRecordDecl(type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7284 | |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7285 | if (!record_decl) |
| 7286 | return; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7287 | |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7288 | record_decl->addAttr(clang::PackedAttr::CreateImplicit(*ast->getASTContext())); |
| 7289 | } |
| 7290 | } |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7291 | } |
| 7292 | |
| 7293 | clang::VarDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7294 | ClangASTContext::AddVariableToRecordType (const CompilerType& type, const char *name, |
| 7295 | const CompilerType &var_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7296 | AccessType access) |
| 7297 | { |
| 7298 | clang::VarDecl *var_decl = nullptr; |
| 7299 | |
| 7300 | if (!type.IsValid() || !var_type.IsValid()) |
| 7301 | return nullptr; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7302 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7303 | if (!ast) |
| 7304 | return nullptr; |
| 7305 | |
| 7306 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type); |
| 7307 | if (record_decl) |
| 7308 | { |
| 7309 | var_decl = clang::VarDecl::Create (*ast->getASTContext(), // ASTContext & |
| 7310 | record_decl, // DeclContext * |
| 7311 | clang::SourceLocation(), // clang::SourceLocation StartLoc |
| 7312 | clang::SourceLocation(), // clang::SourceLocation IdLoc |
| 7313 | name ? &ast->getASTContext()->Idents.get(name) : nullptr, // clang::IdentifierInfo * |
| 7314 | GetQualType(var_type), // Variable clang::QualType |
| 7315 | nullptr, // TypeSourceInfo * |
| 7316 | clang::SC_Static); // StorageClass |
| 7317 | if (var_decl) |
| 7318 | { |
| 7319 | var_decl->setAccess(ClangASTContext::ConvertAccessTypeToAccessSpecifier (access)); |
| 7320 | record_decl->addDecl(var_decl); |
| 7321 | |
| 7322 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7323 | VerifyDecl(var_decl); |
| 7324 | #endif |
| 7325 | } |
| 7326 | } |
| 7327 | return var_decl; |
| 7328 | } |
| 7329 | |
| 7330 | |
| 7331 | clang::CXXMethodDecl * |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7332 | ClangASTContext::AddMethodToCXXRecordType (lldb::opaque_compiler_type_t type, const char *name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7333 | const CompilerType &method_clang_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7334 | lldb::AccessType access, |
| 7335 | bool is_virtual, |
| 7336 | bool is_static, |
| 7337 | bool is_inline, |
| 7338 | bool is_explicit, |
| 7339 | bool is_attr_used, |
| 7340 | bool is_artificial) |
| 7341 | { |
| 7342 | if (!type || !method_clang_type.IsValid() || name == nullptr || name[0] == '\0') |
| 7343 | return nullptr; |
| 7344 | |
| 7345 | clang::QualType record_qual_type(GetCanonicalQualType(type)); |
| 7346 | |
| 7347 | clang::CXXRecordDecl *cxx_record_decl = record_qual_type->getAsCXXRecordDecl(); |
| 7348 | |
| 7349 | if (cxx_record_decl == nullptr) |
| 7350 | return nullptr; |
| 7351 | |
| 7352 | clang::QualType method_qual_type (GetQualType(method_clang_type)); |
| 7353 | |
| 7354 | clang::CXXMethodDecl *cxx_method_decl = nullptr; |
| 7355 | |
| 7356 | clang::DeclarationName decl_name (&getASTContext()->Idents.get(name)); |
| 7357 | |
| 7358 | const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr()); |
| 7359 | |
| 7360 | if (function_type == nullptr) |
| 7361 | return nullptr; |
| 7362 | |
| 7363 | const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(function_type)); |
| 7364 | |
| 7365 | if (!method_function_prototype) |
| 7366 | return nullptr; |
| 7367 | |
| 7368 | unsigned int num_params = method_function_prototype->getNumParams(); |
| 7369 | |
| 7370 | clang::CXXDestructorDecl *cxx_dtor_decl(nullptr); |
| 7371 | clang::CXXConstructorDecl *cxx_ctor_decl(nullptr); |
| 7372 | |
| 7373 | if (is_artificial) |
| 7374 | return nullptr; // skip everything artificial |
| 7375 | |
| 7376 | if (name[0] == '~') |
| 7377 | { |
| 7378 | cxx_dtor_decl = clang::CXXDestructorDecl::Create (*getASTContext(), |
| 7379 | cxx_record_decl, |
| 7380 | clang::SourceLocation(), |
| 7381 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXDestructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()), |
| 7382 | method_qual_type, |
| 7383 | nullptr, |
| 7384 | is_inline, |
| 7385 | is_artificial); |
| 7386 | cxx_method_decl = cxx_dtor_decl; |
| 7387 | } |
| 7388 | else if (decl_name == cxx_record_decl->getDeclName()) |
| 7389 | { |
| 7390 | cxx_ctor_decl = clang::CXXConstructorDecl::Create (*getASTContext(), |
| 7391 | cxx_record_decl, |
| 7392 | clang::SourceLocation(), |
| 7393 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConstructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()), |
| 7394 | method_qual_type, |
| 7395 | nullptr, // TypeSourceInfo * |
| 7396 | is_explicit, |
| 7397 | is_inline, |
| 7398 | is_artificial, |
| 7399 | false /*is_constexpr*/); |
| 7400 | cxx_method_decl = cxx_ctor_decl; |
| 7401 | } |
| 7402 | else |
| 7403 | { |
| 7404 | clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None; |
| 7405 | clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS; |
| 7406 | |
| 7407 | if (IsOperator (name, op_kind)) |
| 7408 | { |
| 7409 | if (op_kind != clang::NUM_OVERLOADED_OPERATORS) |
| 7410 | { |
| 7411 | // Check the number of operator parameters. Sometimes we have |
| 7412 | // seen bad DWARF that doesn't correctly describe operators and |
| 7413 | // if we try to create a method and add it to the class, clang |
| 7414 | // will assert and crash, so we need to make sure things are |
| 7415 | // acceptable. |
| 7416 | if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount (op_kind, num_params)) |
| 7417 | return nullptr; |
| 7418 | cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(), |
| 7419 | cxx_record_decl, |
| 7420 | clang::SourceLocation(), |
| 7421 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXOperatorName (op_kind), clang::SourceLocation()), |
| 7422 | method_qual_type, |
| 7423 | nullptr, // TypeSourceInfo * |
| 7424 | SC, |
| 7425 | is_inline, |
| 7426 | false /*is_constexpr*/, |
| 7427 | clang::SourceLocation()); |
| 7428 | } |
| 7429 | else if (num_params == 0) |
| 7430 | { |
| 7431 | // Conversion operators don't take params... |
| 7432 | cxx_method_decl = clang::CXXConversionDecl::Create (*getASTContext(), |
| 7433 | cxx_record_decl, |
| 7434 | clang::SourceLocation(), |
| 7435 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConversionFunctionName (getASTContext()->getCanonicalType (function_type->getReturnType())), clang::SourceLocation()), |
| 7436 | method_qual_type, |
| 7437 | nullptr, // TypeSourceInfo * |
| 7438 | is_inline, |
| 7439 | is_explicit, |
| 7440 | false /*is_constexpr*/, |
| 7441 | clang::SourceLocation()); |
| 7442 | } |
| 7443 | } |
| 7444 | |
| 7445 | if (cxx_method_decl == nullptr) |
| 7446 | { |
| 7447 | cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(), |
| 7448 | cxx_record_decl, |
| 7449 | clang::SourceLocation(), |
| 7450 | clang::DeclarationNameInfo (decl_name, clang::SourceLocation()), |
| 7451 | method_qual_type, |
| 7452 | nullptr, // TypeSourceInfo * |
| 7453 | SC, |
| 7454 | is_inline, |
| 7455 | false /*is_constexpr*/, |
| 7456 | clang::SourceLocation()); |
| 7457 | } |
| 7458 | } |
| 7459 | |
| 7460 | clang::AccessSpecifier access_specifier = ClangASTContext::ConvertAccessTypeToAccessSpecifier (access); |
| 7461 | |
| 7462 | cxx_method_decl->setAccess (access_specifier); |
| 7463 | cxx_method_decl->setVirtualAsWritten (is_virtual); |
| 7464 | |
| 7465 | if (is_attr_used) |
| 7466 | cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext())); |
| 7467 | |
| 7468 | // Populate the method decl with parameter decls |
| 7469 | |
| 7470 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; |
| 7471 | |
| 7472 | for (unsigned param_index = 0; |
| 7473 | param_index < num_params; |
| 7474 | ++param_index) |
| 7475 | { |
| 7476 | params.push_back (clang::ParmVarDecl::Create (*getASTContext(), |
| 7477 | cxx_method_decl, |
| 7478 | clang::SourceLocation(), |
| 7479 | clang::SourceLocation(), |
| 7480 | nullptr, // anonymous |
| 7481 | method_function_prototype->getParamType(param_index), |
| 7482 | nullptr, |
| 7483 | clang::SC_None, |
| 7484 | nullptr)); |
| 7485 | } |
| 7486 | |
| 7487 | cxx_method_decl->setParams (llvm::ArrayRef<clang::ParmVarDecl*>(params)); |
| 7488 | |
| 7489 | cxx_record_decl->addDecl (cxx_method_decl); |
| 7490 | |
| 7491 | // Sometimes the debug info will mention a constructor (default/copy/move), |
| 7492 | // destructor, or assignment operator (copy/move) but there won't be any |
| 7493 | // version of this in the code. So we check if the function was artificially |
| 7494 | // generated and if it is trivial and this lets the compiler/backend know |
| 7495 | // that it can inline the IR for these when it needs to and we can avoid a |
| 7496 | // "missing function" error when running expressions. |
| 7497 | |
| 7498 | if (is_artificial) |
| 7499 | { |
| 7500 | if (cxx_ctor_decl && |
| 7501 | ((cxx_ctor_decl->isDefaultConstructor() && cxx_record_decl->hasTrivialDefaultConstructor ()) || |
| 7502 | (cxx_ctor_decl->isCopyConstructor() && cxx_record_decl->hasTrivialCopyConstructor ()) || |
| 7503 | (cxx_ctor_decl->isMoveConstructor() && cxx_record_decl->hasTrivialMoveConstructor ()) )) |
| 7504 | { |
| 7505 | cxx_ctor_decl->setDefaulted(); |
| 7506 | cxx_ctor_decl->setTrivial(true); |
| 7507 | } |
| 7508 | else if (cxx_dtor_decl) |
| 7509 | { |
| 7510 | if (cxx_record_decl->hasTrivialDestructor()) |
| 7511 | { |
| 7512 | cxx_dtor_decl->setDefaulted(); |
| 7513 | cxx_dtor_decl->setTrivial(true); |
| 7514 | } |
| 7515 | } |
| 7516 | else if ((cxx_method_decl->isCopyAssignmentOperator() && cxx_record_decl->hasTrivialCopyAssignment()) || |
| 7517 | (cxx_method_decl->isMoveAssignmentOperator() && cxx_record_decl->hasTrivialMoveAssignment())) |
| 7518 | { |
| 7519 | cxx_method_decl->setDefaulted(); |
| 7520 | cxx_method_decl->setTrivial(true); |
| 7521 | } |
| 7522 | } |
| 7523 | |
| 7524 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7525 | VerifyDecl(cxx_method_decl); |
| 7526 | #endif |
| 7527 | |
| 7528 | // printf ("decl->isPolymorphic() = %i\n", cxx_record_decl->isPolymorphic()); |
| 7529 | // printf ("decl->isAggregate() = %i\n", cxx_record_decl->isAggregate()); |
| 7530 | // printf ("decl->isPOD() = %i\n", cxx_record_decl->isPOD()); |
| 7531 | // printf ("decl->isEmpty() = %i\n", cxx_record_decl->isEmpty()); |
| 7532 | // printf ("decl->isAbstract() = %i\n", cxx_record_decl->isAbstract()); |
| 7533 | // printf ("decl->hasTrivialConstructor() = %i\n", cxx_record_decl->hasTrivialConstructor()); |
| 7534 | // printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor()); |
| 7535 | // printf ("decl->hasTrivialCopyAssignment() = %i\n", cxx_record_decl->hasTrivialCopyAssignment()); |
| 7536 | // printf ("decl->hasTrivialDestructor() = %i\n", cxx_record_decl->hasTrivialDestructor()); |
| 7537 | return cxx_method_decl; |
| 7538 | } |
| 7539 | |
| 7540 | |
| 7541 | #pragma mark C++ Base Classes |
| 7542 | |
| 7543 | clang::CXXBaseSpecifier * |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7544 | 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] | 7545 | { |
| 7546 | if (type) |
| 7547 | return new clang::CXXBaseSpecifier (clang::SourceRange(), |
| 7548 | is_virtual, |
| 7549 | base_of_class, |
| 7550 | ClangASTContext::ConvertAccessTypeToAccessSpecifier (access), |
| 7551 | getASTContext()->getTrivialTypeSourceInfo (GetQualType(type)), |
| 7552 | clang::SourceLocation()); |
| 7553 | return nullptr; |
| 7554 | } |
| 7555 | |
| 7556 | void |
| 7557 | ClangASTContext::DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, unsigned num_base_classes) |
| 7558 | { |
| 7559 | for (unsigned i=0; i<num_base_classes; ++i) |
| 7560 | { |
| 7561 | delete base_classes[i]; |
| 7562 | base_classes[i] = nullptr; |
| 7563 | } |
| 7564 | } |
| 7565 | |
| 7566 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7567 | 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] | 7568 | unsigned num_base_classes) |
| 7569 | { |
| 7570 | if (type) |
| 7571 | { |
| 7572 | clang::CXXRecordDecl *cxx_record_decl = GetAsCXXRecordDecl(type); |
| 7573 | if (cxx_record_decl) |
| 7574 | { |
| 7575 | cxx_record_decl->setBases(base_classes, num_base_classes); |
| 7576 | return true; |
| 7577 | } |
| 7578 | } |
| 7579 | return false; |
| 7580 | } |
| 7581 | |
| 7582 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7583 | ClangASTContext::SetObjCSuperClass (const CompilerType& type, const CompilerType &superclass_clang_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7584 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7585 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7586 | if (!ast) |
| 7587 | return false; |
| 7588 | clang::ASTContext* clang_ast = ast->getASTContext(); |
| 7589 | |
| 7590 | if (type && superclass_clang_type.IsValid() && superclass_clang_type.GetTypeSystem() == type.GetTypeSystem()) |
| 7591 | { |
| 7592 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); |
| 7593 | clang::ObjCInterfaceDecl *super_interface_decl = GetAsObjCInterfaceDecl (superclass_clang_type); |
| 7594 | if (class_interface_decl && super_interface_decl) |
| 7595 | { |
| 7596 | class_interface_decl->setSuperClass(clang_ast->getTrivialTypeSourceInfo(clang_ast->getObjCInterfaceType(super_interface_decl))); |
| 7597 | return true; |
| 7598 | } |
| 7599 | } |
| 7600 | return false; |
| 7601 | } |
| 7602 | |
| 7603 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7604 | ClangASTContext::AddObjCClassProperty (const CompilerType& type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7605 | const char *property_name, |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7606 | const CompilerType &property_clang_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7607 | clang::ObjCIvarDecl *ivar_decl, |
| 7608 | const char *property_setter_name, |
| 7609 | const char *property_getter_name, |
| 7610 | uint32_t property_attributes, |
| 7611 | ClangASTMetadata *metadata) |
| 7612 | { |
| 7613 | if (!type || !property_clang_type.IsValid() || property_name == nullptr || property_name[0] == '\0') |
| 7614 | return false; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7615 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7616 | if (!ast) |
| 7617 | return false; |
| 7618 | clang::ASTContext* clang_ast = ast->getASTContext(); |
| 7619 | |
| 7620 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); |
| 7621 | |
| 7622 | if (class_interface_decl) |
| 7623 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7624 | CompilerType property_clang_type_to_access; |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7625 | |
| 7626 | if (property_clang_type.IsValid()) |
| 7627 | property_clang_type_to_access = property_clang_type; |
| 7628 | else if (ivar_decl) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7629 | property_clang_type_to_access = CompilerType (clang_ast, ivar_decl->getType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7630 | |
| 7631 | if (class_interface_decl && property_clang_type_to_access.IsValid()) |
| 7632 | { |
| 7633 | clang::TypeSourceInfo *prop_type_source; |
| 7634 | if (ivar_decl) |
| 7635 | prop_type_source = clang_ast->getTrivialTypeSourceInfo (ivar_decl->getType()); |
| 7636 | else |
| 7637 | prop_type_source = clang_ast->getTrivialTypeSourceInfo (GetQualType(property_clang_type)); |
| 7638 | |
| 7639 | clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create (*clang_ast, |
| 7640 | class_interface_decl, |
| 7641 | clang::SourceLocation(), // Source Location |
| 7642 | &clang_ast->Idents.get(property_name), |
| 7643 | clang::SourceLocation(), //Source Location for AT |
| 7644 | clang::SourceLocation(), //Source location for ( |
| 7645 | ivar_decl ? ivar_decl->getType() : ClangASTContext::GetQualType(property_clang_type), |
| 7646 | prop_type_source); |
| 7647 | |
| 7648 | if (property_decl) |
| 7649 | { |
| 7650 | if (metadata) |
| 7651 | ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata); |
| 7652 | |
| 7653 | class_interface_decl->addDecl (property_decl); |
| 7654 | |
| 7655 | clang::Selector setter_sel, getter_sel; |
| 7656 | |
| 7657 | if (property_setter_name != nullptr) |
| 7658 | { |
| 7659 | std::string property_setter_no_colon(property_setter_name, strlen(property_setter_name) - 1); |
| 7660 | clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(property_setter_no_colon.c_str()); |
| 7661 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); |
| 7662 | } |
| 7663 | else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) |
| 7664 | { |
| 7665 | std::string setter_sel_string("set"); |
| 7666 | setter_sel_string.push_back(::toupper(property_name[0])); |
| 7667 | setter_sel_string.append(&property_name[1]); |
| 7668 | clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(setter_sel_string.c_str()); |
| 7669 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); |
| 7670 | } |
| 7671 | property_decl->setSetterName(setter_sel); |
| 7672 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter); |
| 7673 | |
| 7674 | if (property_getter_name != nullptr) |
| 7675 | { |
| 7676 | clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_getter_name); |
| 7677 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); |
| 7678 | } |
| 7679 | else |
| 7680 | { |
| 7681 | clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_name); |
| 7682 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); |
| 7683 | } |
| 7684 | property_decl->setGetterName(getter_sel); |
| 7685 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter); |
| 7686 | |
| 7687 | if (ivar_decl) |
| 7688 | property_decl->setPropertyIvarDecl (ivar_decl); |
| 7689 | |
| 7690 | if (property_attributes & DW_APPLE_PROPERTY_readonly) |
| 7691 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readonly); |
| 7692 | if (property_attributes & DW_APPLE_PROPERTY_readwrite) |
| 7693 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readwrite); |
| 7694 | if (property_attributes & DW_APPLE_PROPERTY_assign) |
| 7695 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_assign); |
| 7696 | if (property_attributes & DW_APPLE_PROPERTY_retain) |
| 7697 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_retain); |
| 7698 | if (property_attributes & DW_APPLE_PROPERTY_copy) |
| 7699 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_copy); |
| 7700 | if (property_attributes & DW_APPLE_PROPERTY_nonatomic) |
| 7701 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_nonatomic); |
| 7702 | |
| 7703 | if (!getter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(getter_sel)) |
| 7704 | { |
| 7705 | const bool isInstance = true; |
| 7706 | const bool isVariadic = false; |
| 7707 | const bool isSynthesized = false; |
| 7708 | const bool isImplicitlyDeclared = true; |
| 7709 | const bool isDefined = false; |
| 7710 | const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None; |
| 7711 | const bool HasRelatedResultType = false; |
| 7712 | |
| 7713 | clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create (*clang_ast, |
| 7714 | clang::SourceLocation(), |
| 7715 | clang::SourceLocation(), |
| 7716 | getter_sel, |
| 7717 | GetQualType(property_clang_type_to_access), |
| 7718 | nullptr, |
| 7719 | class_interface_decl, |
| 7720 | isInstance, |
| 7721 | isVariadic, |
| 7722 | isSynthesized, |
| 7723 | isImplicitlyDeclared, |
| 7724 | isDefined, |
| 7725 | impControl, |
| 7726 | HasRelatedResultType); |
| 7727 | |
| 7728 | if (getter && metadata) |
| 7729 | ClangASTContext::SetMetadata(clang_ast, getter, *metadata); |
| 7730 | |
| 7731 | if (getter) |
| 7732 | { |
| 7733 | getter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(), llvm::ArrayRef<clang::SourceLocation>()); |
| 7734 | |
| 7735 | class_interface_decl->addDecl(getter); |
| 7736 | } |
| 7737 | } |
| 7738 | |
| 7739 | if (!setter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(setter_sel)) |
| 7740 | { |
| 7741 | clang::QualType result_type = clang_ast->VoidTy; |
| 7742 | |
| 7743 | const bool isInstance = true; |
| 7744 | const bool isVariadic = false; |
| 7745 | const bool isSynthesized = false; |
| 7746 | const bool isImplicitlyDeclared = true; |
| 7747 | const bool isDefined = false; |
| 7748 | const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None; |
| 7749 | const bool HasRelatedResultType = false; |
| 7750 | |
| 7751 | clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create (*clang_ast, |
| 7752 | clang::SourceLocation(), |
| 7753 | clang::SourceLocation(), |
| 7754 | setter_sel, |
| 7755 | result_type, |
| 7756 | nullptr, |
| 7757 | class_interface_decl, |
| 7758 | isInstance, |
| 7759 | isVariadic, |
| 7760 | isSynthesized, |
| 7761 | isImplicitlyDeclared, |
| 7762 | isDefined, |
| 7763 | impControl, |
| 7764 | HasRelatedResultType); |
| 7765 | |
| 7766 | if (setter && metadata) |
| 7767 | ClangASTContext::SetMetadata(clang_ast, setter, *metadata); |
| 7768 | |
| 7769 | llvm::SmallVector<clang::ParmVarDecl *, 1> params; |
| 7770 | |
| 7771 | params.push_back (clang::ParmVarDecl::Create (*clang_ast, |
| 7772 | setter, |
| 7773 | clang::SourceLocation(), |
| 7774 | clang::SourceLocation(), |
| 7775 | nullptr, // anonymous |
| 7776 | GetQualType(property_clang_type_to_access), |
| 7777 | nullptr, |
| 7778 | clang::SC_Auto, |
| 7779 | nullptr)); |
| 7780 | |
| 7781 | if (setter) |
| 7782 | { |
| 7783 | setter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>()); |
| 7784 | |
| 7785 | class_interface_decl->addDecl(setter); |
| 7786 | } |
| 7787 | } |
| 7788 | |
| 7789 | return true; |
| 7790 | } |
| 7791 | } |
| 7792 | } |
| 7793 | return false; |
| 7794 | } |
| 7795 | |
| 7796 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7797 | ClangASTContext::IsObjCClassTypeAndHasIVars (const CompilerType& type, bool check_superclass) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7798 | { |
| 7799 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); |
| 7800 | if (class_interface_decl) |
| 7801 | return ObjCDeclHasIVars (class_interface_decl, check_superclass); |
| 7802 | return false; |
| 7803 | } |
| 7804 | |
| 7805 | |
| 7806 | clang::ObjCMethodDecl * |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7807 | ClangASTContext::AddMethodToObjCObjectType (const CompilerType& type, |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7808 | 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] | 7809 | const CompilerType &method_clang_type, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7810 | lldb::AccessType access, |
| 7811 | bool is_artificial) |
| 7812 | { |
| 7813 | if (!type || !method_clang_type.IsValid()) |
| 7814 | return nullptr; |
| 7815 | |
| 7816 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); |
| 7817 | |
| 7818 | if (class_interface_decl == nullptr) |
| 7819 | return nullptr; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7820 | ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 7821 | if (lldb_ast == nullptr) |
| 7822 | return nullptr; |
| 7823 | clang::ASTContext *ast = lldb_ast->getASTContext(); |
| 7824 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7825 | const char *selector_start = ::strchr (name, ' '); |
| 7826 | if (selector_start == nullptr) |
| 7827 | return nullptr; |
| 7828 | |
| 7829 | selector_start++; |
| 7830 | llvm::SmallVector<clang::IdentifierInfo *, 12> selector_idents; |
| 7831 | |
| 7832 | size_t len = 0; |
| 7833 | const char *start; |
| 7834 | //printf ("name = '%s'\n", name); |
| 7835 | |
| 7836 | unsigned num_selectors_with_args = 0; |
| 7837 | for (start = selector_start; |
| 7838 | start && *start != '\0' && *start != ']'; |
| 7839 | start += len) |
| 7840 | { |
| 7841 | len = ::strcspn(start, ":]"); |
| 7842 | bool has_arg = (start[len] == ':'); |
| 7843 | if (has_arg) |
| 7844 | ++num_selectors_with_args; |
| 7845 | selector_idents.push_back (&ast->Idents.get (llvm::StringRef (start, len))); |
| 7846 | if (has_arg) |
| 7847 | len += 1; |
| 7848 | } |
| 7849 | |
| 7850 | |
| 7851 | if (selector_idents.size() == 0) |
| 7852 | return nullptr; |
| 7853 | |
| 7854 | clang::Selector method_selector = ast->Selectors.getSelector (num_selectors_with_args ? selector_idents.size() : 0, |
| 7855 | selector_idents.data()); |
| 7856 | |
| 7857 | clang::QualType method_qual_type (GetQualType(method_clang_type)); |
| 7858 | |
| 7859 | // Populate the method decl with parameter decls |
| 7860 | const clang::Type *method_type(method_qual_type.getTypePtr()); |
| 7861 | |
| 7862 | if (method_type == nullptr) |
| 7863 | return nullptr; |
| 7864 | |
| 7865 | const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(method_type)); |
| 7866 | |
| 7867 | if (!method_function_prototype) |
| 7868 | return nullptr; |
| 7869 | |
| 7870 | |
| 7871 | bool is_variadic = false; |
| 7872 | bool is_synthesized = false; |
| 7873 | bool is_defined = false; |
| 7874 | clang::ObjCMethodDecl::ImplementationControl imp_control = clang::ObjCMethodDecl::None; |
| 7875 | |
| 7876 | const unsigned num_args = method_function_prototype->getNumParams(); |
| 7877 | |
| 7878 | if (num_args != num_selectors_with_args) |
| 7879 | return nullptr; // some debug information is corrupt. We are not going to deal with it. |
| 7880 | |
| 7881 | clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create (*ast, |
| 7882 | clang::SourceLocation(), // beginLoc, |
| 7883 | clang::SourceLocation(), // endLoc, |
| 7884 | method_selector, |
| 7885 | method_function_prototype->getReturnType(), |
| 7886 | nullptr, // TypeSourceInfo *ResultTInfo, |
| 7887 | ClangASTContext::GetASTContext(ast)->GetDeclContextForType(GetQualType(type)), |
| 7888 | name[0] == '-', |
| 7889 | is_variadic, |
| 7890 | is_synthesized, |
| 7891 | true, // is_implicitly_declared; we force this to true because we don't have source locations |
| 7892 | is_defined, |
| 7893 | imp_control, |
| 7894 | false /*has_related_result_type*/); |
| 7895 | |
| 7896 | |
| 7897 | if (objc_method_decl == nullptr) |
| 7898 | return nullptr; |
| 7899 | |
| 7900 | if (num_args > 0) |
| 7901 | { |
| 7902 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; |
| 7903 | |
| 7904 | for (unsigned param_index = 0; param_index < num_args; ++param_index) |
| 7905 | { |
| 7906 | params.push_back (clang::ParmVarDecl::Create (*ast, |
| 7907 | objc_method_decl, |
| 7908 | clang::SourceLocation(), |
| 7909 | clang::SourceLocation(), |
| 7910 | nullptr, // anonymous |
| 7911 | method_function_prototype->getParamType(param_index), |
| 7912 | nullptr, |
| 7913 | clang::SC_Auto, |
| 7914 | nullptr)); |
| 7915 | } |
| 7916 | |
| 7917 | objc_method_decl->setMethodParams(*ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>()); |
| 7918 | } |
| 7919 | |
| 7920 | class_interface_decl->addDecl (objc_method_decl); |
| 7921 | |
| 7922 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 7923 | VerifyDecl(objc_method_decl); |
| 7924 | #endif |
| 7925 | |
| 7926 | return objc_method_decl; |
| 7927 | } |
| 7928 | |
| 7929 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7930 | ClangASTContext::SetHasExternalStorage (lldb::opaque_compiler_type_t type, bool has_extern) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7931 | { |
| 7932 | if (!type) |
| 7933 | return false; |
| 7934 | |
| 7935 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 7936 | |
| 7937 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 7938 | switch (type_class) |
| 7939 | { |
| 7940 | case clang::Type::Record: |
| 7941 | { |
| 7942 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 7943 | if (cxx_record_decl) |
| 7944 | { |
| 7945 | cxx_record_decl->setHasExternalLexicalStorage (has_extern); |
| 7946 | cxx_record_decl->setHasExternalVisibleStorage (has_extern); |
| 7947 | return true; |
| 7948 | } |
| 7949 | } |
| 7950 | break; |
| 7951 | |
| 7952 | case clang::Type::Enum: |
| 7953 | { |
| 7954 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 7955 | if (enum_decl) |
| 7956 | { |
| 7957 | enum_decl->setHasExternalLexicalStorage (has_extern); |
| 7958 | enum_decl->setHasExternalVisibleStorage (has_extern); |
| 7959 | return true; |
| 7960 | } |
| 7961 | } |
| 7962 | break; |
| 7963 | |
| 7964 | case clang::Type::ObjCObject: |
| 7965 | case clang::Type::ObjCInterface: |
| 7966 | { |
| 7967 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 7968 | assert (objc_class_type); |
| 7969 | if (objc_class_type) |
| 7970 | { |
| 7971 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 7972 | |
| 7973 | if (class_interface_decl) |
| 7974 | { |
| 7975 | class_interface_decl->setHasExternalLexicalStorage (has_extern); |
| 7976 | class_interface_decl->setHasExternalVisibleStorage (has_extern); |
| 7977 | return true; |
| 7978 | } |
| 7979 | } |
| 7980 | } |
| 7981 | break; |
| 7982 | |
| 7983 | case clang::Type::Typedef: |
| 7984 | return SetHasExternalStorage(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), has_extern); |
| 7985 | |
| 7986 | case clang::Type::Elaborated: |
| 7987 | return SetHasExternalStorage (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), has_extern); |
| 7988 | |
| 7989 | case clang::Type::Paren: |
| 7990 | return SetHasExternalStorage (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), has_extern); |
| 7991 | |
| 7992 | default: |
| 7993 | break; |
| 7994 | } |
| 7995 | return false; |
| 7996 | } |
| 7997 | |
| 7998 | |
| 7999 | #pragma mark TagDecl |
| 8000 | |
| 8001 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8002 | ClangASTContext::StartTagDeclarationDefinition (const CompilerType &type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8003 | { |
| 8004 | if (type) |
| 8005 | { |
| 8006 | |
| 8007 | clang::QualType qual_type (GetQualType(type)); |
| 8008 | const clang::Type *t = qual_type.getTypePtr(); |
| 8009 | if (t) |
| 8010 | { |
| 8011 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(t); |
| 8012 | if (tag_type) |
| 8013 | { |
| 8014 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8015 | if (tag_decl) |
| 8016 | { |
| 8017 | tag_decl->startDefinition(); |
| 8018 | return true; |
| 8019 | } |
| 8020 | } |
| 8021 | |
| 8022 | const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(t); |
| 8023 | if (object_type) |
| 8024 | { |
| 8025 | clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface(); |
| 8026 | if (interface_decl) |
| 8027 | { |
| 8028 | interface_decl->startDefinition(); |
| 8029 | return true; |
| 8030 | } |
| 8031 | } |
| 8032 | } |
| 8033 | } |
| 8034 | return false; |
| 8035 | } |
| 8036 | |
| 8037 | bool |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8038 | ClangASTContext::CompleteTagDeclarationDefinition (const CompilerType& type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8039 | { |
| 8040 | if (type) |
| 8041 | { |
| 8042 | clang::QualType qual_type (GetQualType(type)); |
| 8043 | if (qual_type.isNull()) |
| 8044 | return false; |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8045 | ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
| 8046 | if (lldb_ast == nullptr) |
| 8047 | return false; |
| 8048 | clang::ASTContext *ast = lldb_ast->getASTContext(); |
| 8049 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8050 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 8051 | |
| 8052 | if (cxx_record_decl) |
| 8053 | { |
| 8054 | cxx_record_decl->completeDefinition(); |
| 8055 | |
| 8056 | return true; |
| 8057 | } |
| 8058 | |
| 8059 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(qual_type.getTypePtr()); |
| 8060 | |
| 8061 | if (enutype) |
| 8062 | { |
| 8063 | clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8064 | |
| 8065 | if (enum_decl) |
| 8066 | { |
| 8067 | /// TODO This really needs to be fixed. |
| 8068 | |
| 8069 | unsigned NumPositiveBits = 1; |
| 8070 | unsigned NumNegativeBits = 0; |
| 8071 | |
| 8072 | clang::QualType promotion_qual_type; |
| 8073 | // If the enum integer type is less than an integer in bit width, |
| 8074 | // then we must promote it to an integer size. |
| 8075 | if (ast->getTypeSize(enum_decl->getIntegerType()) < ast->getTypeSize(ast->IntTy)) |
| 8076 | { |
| 8077 | if (enum_decl->getIntegerType()->isSignedIntegerType()) |
| 8078 | promotion_qual_type = ast->IntTy; |
| 8079 | else |
| 8080 | promotion_qual_type = ast->UnsignedIntTy; |
| 8081 | } |
| 8082 | else |
| 8083 | promotion_qual_type = enum_decl->getIntegerType(); |
| 8084 | |
| 8085 | enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits); |
| 8086 | return true; |
| 8087 | } |
| 8088 | } |
| 8089 | } |
| 8090 | return false; |
| 8091 | } |
| 8092 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8093 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8094 | ClangASTContext::AddEnumerationValueToEnumerationType (lldb::opaque_compiler_type_t type, |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8095 | const CompilerType &enumerator_clang_type, |
| 8096 | const Declaration &decl, |
| 8097 | const char *name, |
| 8098 | int64_t enum_value, |
| 8099 | uint32_t enum_value_bit_size) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8100 | { |
| 8101 | if (type && enumerator_clang_type.IsValid() && name && name[0]) |
| 8102 | { |
| 8103 | clang::QualType enum_qual_type (GetCanonicalQualType(type)); |
| 8104 | |
| 8105 | bool is_signed = false; |
| 8106 | enumerator_clang_type.IsIntegerType (is_signed); |
| 8107 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
| 8108 | if (clang_type) |
| 8109 | { |
| 8110 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type); |
| 8111 | |
| 8112 | if (enutype) |
| 8113 | { |
| 8114 | llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed); |
| 8115 | enum_llvm_apsint = enum_value; |
| 8116 | clang::EnumConstantDecl *enumerator_decl = |
| 8117 | clang::EnumConstantDecl::Create (*getASTContext(), |
| 8118 | enutype->getDecl(), |
| 8119 | clang::SourceLocation(), |
| 8120 | name ? &getASTContext()->Idents.get(name) : nullptr, // Identifier |
| 8121 | GetQualType(enumerator_clang_type), |
| 8122 | nullptr, |
| 8123 | enum_llvm_apsint); |
| 8124 | |
| 8125 | if (enumerator_decl) |
| 8126 | { |
| 8127 | enutype->getDecl()->addDecl(enumerator_decl); |
| 8128 | |
| 8129 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 8130 | VerifyDecl(enumerator_decl); |
| 8131 | #endif |
| 8132 | |
| 8133 | return true; |
| 8134 | } |
| 8135 | } |
| 8136 | } |
| 8137 | } |
| 8138 | return false; |
| 8139 | } |
| 8140 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8141 | CompilerType |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8142 | ClangASTContext::GetEnumerationIntegerType (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8143 | { |
| 8144 | clang::QualType enum_qual_type (GetCanonicalQualType(type)); |
| 8145 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
| 8146 | if (clang_type) |
| 8147 | { |
| 8148 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type); |
| 8149 | if (enutype) |
| 8150 | { |
| 8151 | clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8152 | if (enum_decl) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8153 | return CompilerType (getASTContext(), enum_decl->getIntegerType()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8154 | } |
| 8155 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8156 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8157 | } |
| 8158 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8159 | CompilerType |
| 8160 | ClangASTContext::CreateMemberPointerType (const CompilerType& type, const CompilerType &pointee_type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8161 | { |
| 8162 | if (type && pointee_type.IsValid() && type.GetTypeSystem() == pointee_type.GetTypeSystem()) |
| 8163 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8164 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8165 | if (!ast) |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8166 | return CompilerType(); |
| 8167 | return CompilerType (ast->getASTContext(), |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8168 | ast->getASTContext()->getMemberPointerType (GetQualType(pointee_type), |
| 8169 | GetQualType(type).getTypePtr())); |
| 8170 | } |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8171 | return CompilerType(); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8172 | } |
| 8173 | |
| 8174 | |
| 8175 | size_t |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8176 | 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] | 8177 | { |
| 8178 | if (type) |
| 8179 | { |
| 8180 | clang::QualType qual_type (GetCanonicalQualType(type)); |
| 8181 | uint32_t count = 0; |
| 8182 | bool is_complex = false; |
| 8183 | if (IsFloatingPointType (type, count, is_complex)) |
| 8184 | { |
| 8185 | // TODO: handle complex and vector types |
| 8186 | if (count != 1) |
| 8187 | return false; |
| 8188 | |
| 8189 | llvm::StringRef s_sref(s); |
| 8190 | llvm::APFloat ap_float(getASTContext()->getFloatTypeSemantics(qual_type), s_sref); |
| 8191 | |
| 8192 | const uint64_t bit_size = getASTContext()->getTypeSize (qual_type); |
| 8193 | const uint64_t byte_size = bit_size / 8; |
| 8194 | if (dst_size >= byte_size) |
| 8195 | { |
| 8196 | if (bit_size == sizeof(float)*8) |
| 8197 | { |
| 8198 | float float32 = ap_float.convertToFloat(); |
| 8199 | ::memcpy (dst, &float32, byte_size); |
| 8200 | return byte_size; |
| 8201 | } |
| 8202 | else if (bit_size >= 64) |
| 8203 | { |
| 8204 | llvm::APInt ap_int(ap_float.bitcastToAPInt()); |
| 8205 | ::memcpy (dst, ap_int.getRawData(), byte_size); |
| 8206 | return byte_size; |
| 8207 | } |
| 8208 | } |
| 8209 | } |
| 8210 | } |
| 8211 | return 0; |
| 8212 | } |
| 8213 | |
| 8214 | |
| 8215 | |
| 8216 | //---------------------------------------------------------------------- |
| 8217 | // Dumping types |
| 8218 | //---------------------------------------------------------------------- |
| 8219 | #define DEPTH_INCREMENT 2 |
| 8220 | |
| 8221 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8222 | ClangASTContext::DumpValue (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8223 | Stream *s, |
| 8224 | lldb::Format format, |
| 8225 | const lldb_private::DataExtractor &data, |
| 8226 | lldb::offset_t data_byte_offset, |
| 8227 | size_t data_byte_size, |
| 8228 | uint32_t bitfield_bit_size, |
| 8229 | uint32_t bitfield_bit_offset, |
| 8230 | bool show_types, |
| 8231 | bool show_summary, |
| 8232 | bool verbose, |
| 8233 | uint32_t depth) |
| 8234 | { |
| 8235 | if (!type) |
| 8236 | return; |
| 8237 | |
| 8238 | clang::QualType qual_type(GetQualType(type)); |
| 8239 | switch (qual_type->getTypeClass()) |
| 8240 | { |
| 8241 | case clang::Type::Record: |
| 8242 | if (GetCompleteType(type)) |
| 8243 | { |
| 8244 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 8245 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 8246 | assert(record_decl); |
| 8247 | uint32_t field_bit_offset = 0; |
| 8248 | uint32_t field_byte_offset = 0; |
| 8249 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); |
| 8250 | uint32_t child_idx = 0; |
| 8251 | |
| 8252 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 8253 | if (cxx_record_decl) |
| 8254 | { |
| 8255 | // We might have base classes to print out first |
| 8256 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 8257 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 8258 | base_class != base_class_end; |
| 8259 | ++base_class) |
| 8260 | { |
| 8261 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); |
| 8262 | |
| 8263 | // Skip empty base classes |
| 8264 | if (verbose == false && ClangASTContext::RecordHasFields(base_class_decl) == false) |
| 8265 | continue; |
| 8266 | |
| 8267 | if (base_class->isVirtual()) |
| 8268 | field_bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 8269 | else |
| 8270 | field_bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 8271 | field_byte_offset = field_bit_offset / 8; |
| 8272 | assert (field_bit_offset % 8 == 0); |
| 8273 | if (child_idx == 0) |
| 8274 | s->PutChar('{'); |
| 8275 | else |
| 8276 | s->PutChar(','); |
| 8277 | |
| 8278 | clang::QualType base_class_qual_type = base_class->getType(); |
| 8279 | std::string base_class_type_name(base_class_qual_type.getAsString()); |
| 8280 | |
| 8281 | // Indent and print the base class type name |
| 8282 | s->Printf("\n%*s%s ", depth + DEPTH_INCREMENT, "", base_class_type_name.c_str()); |
| 8283 | |
| 8284 | clang::TypeInfo base_class_type_info = getASTContext()->getTypeInfo(base_class_qual_type); |
| 8285 | |
| 8286 | // Dump the value of the member |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8287 | CompilerType base_clang_type(getASTContext(), base_class_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8288 | base_clang_type.DumpValue (exe_ctx, |
| 8289 | s, // Stream to dump to |
| 8290 | base_clang_type.GetFormat(), // The format with which to display the member |
| 8291 | data, // Data buffer containing all bytes for this type |
| 8292 | data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from |
| 8293 | base_class_type_info.Width / 8, // Size of this type in bytes |
| 8294 | 0, // Bitfield bit size |
| 8295 | 0, // Bitfield bit offset |
| 8296 | show_types, // Boolean indicating if we should show the variable types |
| 8297 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8298 | verbose, // Verbose output? |
| 8299 | depth + DEPTH_INCREMENT); // Scope depth for any types that have children |
| 8300 | |
| 8301 | ++child_idx; |
| 8302 | } |
| 8303 | } |
| 8304 | uint32_t field_idx = 0; |
| 8305 | clang::RecordDecl::field_iterator field, field_end; |
| 8306 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx) |
| 8307 | { |
| 8308 | // Print the starting squiggly bracket (if this is the |
| 8309 | // first member) or comma (for member 2 and beyond) for |
| 8310 | // the struct/union/class member. |
| 8311 | if (child_idx == 0) |
| 8312 | s->PutChar('{'); |
| 8313 | else |
| 8314 | s->PutChar(','); |
| 8315 | |
| 8316 | // Indent |
| 8317 | s->Printf("\n%*s", depth + DEPTH_INCREMENT, ""); |
| 8318 | |
| 8319 | clang::QualType field_type = field->getType(); |
| 8320 | // Print the member type if requested |
| 8321 | // Figure out the type byte size (field_type_info.first) and |
| 8322 | // alignment (field_type_info.second) from the AST context. |
| 8323 | clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(field_type); |
| 8324 | assert(field_idx < record_layout.getFieldCount()); |
| 8325 | // Figure out the field offset within the current struct/union/class type |
| 8326 | field_bit_offset = record_layout.getFieldOffset (field_idx); |
| 8327 | field_byte_offset = field_bit_offset / 8; |
| 8328 | uint32_t field_bitfield_bit_size = 0; |
| 8329 | uint32_t field_bitfield_bit_offset = 0; |
| 8330 | if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, field_bitfield_bit_size)) |
| 8331 | field_bitfield_bit_offset = field_bit_offset % 8; |
| 8332 | |
| 8333 | if (show_types) |
| 8334 | { |
| 8335 | std::string field_type_name(field_type.getAsString()); |
| 8336 | if (field_bitfield_bit_size > 0) |
| 8337 | s->Printf("(%s:%u) ", field_type_name.c_str(), field_bitfield_bit_size); |
| 8338 | else |
| 8339 | s->Printf("(%s) ", field_type_name.c_str()); |
| 8340 | } |
| 8341 | // Print the member name and equal sign |
| 8342 | s->Printf("%s = ", field->getNameAsString().c_str()); |
| 8343 | |
| 8344 | |
| 8345 | // Dump the value of the member |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8346 | CompilerType field_clang_type (getASTContext(), field_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8347 | field_clang_type.DumpValue (exe_ctx, |
| 8348 | s, // Stream to dump to |
| 8349 | field_clang_type.GetFormat(), // The format with which to display the member |
| 8350 | data, // Data buffer containing all bytes for this type |
| 8351 | data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from |
| 8352 | field_type_info.Width / 8, // Size of this type in bytes |
| 8353 | field_bitfield_bit_size, // Bitfield bit size |
| 8354 | field_bitfield_bit_offset, // Bitfield bit offset |
| 8355 | show_types, // Boolean indicating if we should show the variable types |
| 8356 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8357 | verbose, // Verbose output? |
| 8358 | depth + DEPTH_INCREMENT); // Scope depth for any types that have children |
| 8359 | } |
| 8360 | |
| 8361 | // Indent the trailing squiggly bracket |
| 8362 | if (child_idx > 0) |
| 8363 | s->Printf("\n%*s}", depth, ""); |
| 8364 | } |
| 8365 | return; |
| 8366 | |
| 8367 | case clang::Type::Enum: |
| 8368 | if (GetCompleteType(type)) |
| 8369 | { |
| 8370 | const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr()); |
| 8371 | const clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8372 | assert(enum_decl); |
| 8373 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 8374 | lldb::offset_t offset = data_byte_offset; |
| 8375 | const int64_t enum_value = data.GetMaxU64Bitfield(&offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 8376 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) |
| 8377 | { |
| 8378 | if (enum_pos->getInitVal() == enum_value) |
| 8379 | { |
| 8380 | s->Printf("%s", enum_pos->getNameAsString().c_str()); |
| 8381 | return; |
| 8382 | } |
| 8383 | } |
| 8384 | // If we have gotten here we didn't get find the enumerator in the |
| 8385 | // enum decl, so just print the integer. |
| 8386 | s->Printf("%" PRIi64, enum_value); |
| 8387 | } |
| 8388 | return; |
| 8389 | |
| 8390 | case clang::Type::ConstantArray: |
| 8391 | { |
| 8392 | const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr()); |
| 8393 | bool is_array_of_characters = false; |
| 8394 | clang::QualType element_qual_type = array->getElementType(); |
| 8395 | |
| 8396 | const clang::Type *canonical_type = element_qual_type->getCanonicalTypeInternal().getTypePtr(); |
| 8397 | if (canonical_type) |
| 8398 | is_array_of_characters = canonical_type->isCharType(); |
| 8399 | |
| 8400 | const uint64_t element_count = array->getSize().getLimitedValue(); |
| 8401 | |
| 8402 | clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(element_qual_type); |
| 8403 | |
| 8404 | uint32_t element_idx = 0; |
| 8405 | uint32_t element_offset = 0; |
| 8406 | uint64_t element_byte_size = field_type_info.Width / 8; |
| 8407 | uint32_t element_stride = element_byte_size; |
| 8408 | |
| 8409 | if (is_array_of_characters) |
| 8410 | { |
| 8411 | s->PutChar('"'); |
| 8412 | data.Dump(s, data_byte_offset, lldb::eFormatChar, element_byte_size, element_count, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); |
| 8413 | s->PutChar('"'); |
| 8414 | return; |
| 8415 | } |
| 8416 | else |
| 8417 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8418 | CompilerType element_clang_type(getASTContext(), element_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8419 | lldb::Format element_format = element_clang_type.GetFormat(); |
| 8420 | |
| 8421 | for (element_idx = 0; element_idx < element_count; ++element_idx) |
| 8422 | { |
| 8423 | // Print the starting squiggly bracket (if this is the |
| 8424 | // first member) or comman (for member 2 and beyong) for |
| 8425 | // the struct/union/class member. |
| 8426 | if (element_idx == 0) |
| 8427 | s->PutChar('{'); |
| 8428 | else |
| 8429 | s->PutChar(','); |
| 8430 | |
| 8431 | // Indent and print the index |
| 8432 | s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx); |
| 8433 | |
| 8434 | // Figure out the field offset within the current struct/union/class type |
| 8435 | element_offset = element_idx * element_stride; |
| 8436 | |
| 8437 | // Dump the value of the member |
| 8438 | element_clang_type.DumpValue (exe_ctx, |
| 8439 | s, // Stream to dump to |
| 8440 | element_format, // The format with which to display the element |
| 8441 | data, // Data buffer containing all bytes for this type |
| 8442 | data_byte_offset + element_offset,// Offset into "data" where to grab value from |
| 8443 | element_byte_size, // Size of this type in bytes |
| 8444 | 0, // Bitfield bit size |
| 8445 | 0, // Bitfield bit offset |
| 8446 | show_types, // Boolean indicating if we should show the variable types |
| 8447 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8448 | verbose, // Verbose output? |
| 8449 | depth + DEPTH_INCREMENT); // Scope depth for any types that have children |
| 8450 | } |
| 8451 | |
| 8452 | // Indent the trailing squiggly bracket |
| 8453 | if (element_idx > 0) |
| 8454 | s->Printf("\n%*s}", depth, ""); |
| 8455 | } |
| 8456 | } |
| 8457 | return; |
| 8458 | |
| 8459 | case clang::Type::Typedef: |
| 8460 | { |
| 8461 | clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(); |
| 8462 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8463 | CompilerType typedef_clang_type (getASTContext(), typedef_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8464 | lldb::Format typedef_format = typedef_clang_type.GetFormat(); |
| 8465 | clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type); |
| 8466 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; |
| 8467 | |
| 8468 | return typedef_clang_type.DumpValue (exe_ctx, |
| 8469 | s, // Stream to dump to |
| 8470 | typedef_format, // The format with which to display the element |
| 8471 | data, // Data buffer containing all bytes for this type |
| 8472 | data_byte_offset, // Offset into "data" where to grab value from |
| 8473 | typedef_byte_size, // Size of this type in bytes |
| 8474 | bitfield_bit_size, // Bitfield bit size |
| 8475 | bitfield_bit_offset,// Bitfield bit offset |
| 8476 | show_types, // Boolean indicating if we should show the variable types |
| 8477 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8478 | verbose, // Verbose output? |
| 8479 | depth); // Scope depth for any types that have children |
| 8480 | } |
| 8481 | break; |
| 8482 | |
| 8483 | case clang::Type::Elaborated: |
| 8484 | { |
| 8485 | clang::QualType elaborated_qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8486 | CompilerType elaborated_clang_type (getASTContext(), elaborated_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8487 | lldb::Format elaborated_format = elaborated_clang_type.GetFormat(); |
| 8488 | clang::TypeInfo elaborated_type_info = getASTContext()->getTypeInfo(elaborated_qual_type); |
| 8489 | uint64_t elaborated_byte_size = elaborated_type_info.Width / 8; |
| 8490 | |
| 8491 | return elaborated_clang_type.DumpValue (exe_ctx, |
| 8492 | s, // Stream to dump to |
| 8493 | elaborated_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 | elaborated_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::Paren: |
| 8507 | { |
| 8508 | clang::QualType desugar_qual_type = llvm::cast<clang::ParenType>(qual_type)->desugar(); |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8509 | CompilerType desugar_clang_type (getASTContext(), desugar_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8510 | |
| 8511 | lldb::Format desugar_format = desugar_clang_type.GetFormat(); |
| 8512 | clang::TypeInfo desugar_type_info = getASTContext()->getTypeInfo(desugar_qual_type); |
| 8513 | uint64_t desugar_byte_size = desugar_type_info.Width / 8; |
| 8514 | |
| 8515 | return desugar_clang_type.DumpValue (exe_ctx, |
| 8516 | s, // Stream to dump to |
| 8517 | desugar_format, // The format with which to display the element |
| 8518 | data, // Data buffer containing all bytes for this type |
| 8519 | data_byte_offset, // Offset into "data" where to grab value from |
| 8520 | desugar_byte_size, // Size of this type in bytes |
| 8521 | bitfield_bit_size, // Bitfield bit size |
| 8522 | bitfield_bit_offset,// Bitfield bit offset |
| 8523 | show_types, // Boolean indicating if we should show the variable types |
| 8524 | show_summary, // Boolean indicating if we should show a summary for the current type |
| 8525 | verbose, // Verbose output? |
| 8526 | depth); // Scope depth for any types that have children |
| 8527 | } |
| 8528 | break; |
| 8529 | |
| 8530 | default: |
| 8531 | // We are down to a scalar type that we just need to display. |
| 8532 | data.Dump(s, |
| 8533 | data_byte_offset, |
| 8534 | format, |
| 8535 | data_byte_size, |
| 8536 | 1, |
| 8537 | UINT32_MAX, |
| 8538 | LLDB_INVALID_ADDRESS, |
| 8539 | bitfield_bit_size, |
| 8540 | bitfield_bit_offset); |
| 8541 | |
| 8542 | if (show_summary) |
| 8543 | DumpSummary (type, exe_ctx, s, data, data_byte_offset, data_byte_size); |
| 8544 | break; |
| 8545 | } |
| 8546 | } |
| 8547 | |
| 8548 | |
| 8549 | |
| 8550 | |
| 8551 | bool |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8552 | ClangASTContext::DumpTypeValue (lldb::opaque_compiler_type_t type, Stream *s, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8553 | lldb::Format format, |
| 8554 | const lldb_private::DataExtractor &data, |
| 8555 | lldb::offset_t byte_offset, |
| 8556 | size_t byte_size, |
| 8557 | uint32_t bitfield_bit_size, |
| 8558 | uint32_t bitfield_bit_offset, |
| 8559 | ExecutionContextScope *exe_scope) |
| 8560 | { |
| 8561 | if (!type) |
| 8562 | return false; |
| 8563 | if (IsAggregateType(type)) |
| 8564 | { |
| 8565 | return false; |
| 8566 | } |
| 8567 | else |
| 8568 | { |
| 8569 | clang::QualType qual_type(GetQualType(type)); |
| 8570 | |
| 8571 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 8572 | switch (type_class) |
| 8573 | { |
| 8574 | case clang::Type::Typedef: |
| 8575 | { |
| 8576 | 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] | 8577 | CompilerType typedef_clang_type (getASTContext(), typedef_qual_type); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8578 | if (format == eFormatDefault) |
| 8579 | format = typedef_clang_type.GetFormat(); |
| 8580 | clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type); |
| 8581 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; |
| 8582 | |
| 8583 | return typedef_clang_type.DumpTypeValue (s, |
| 8584 | format, // The format with which to display the element |
| 8585 | data, // Data buffer containing all bytes for this type |
| 8586 | byte_offset, // Offset into "data" where to grab value from |
| 8587 | typedef_byte_size, // Size of this type in bytes |
| 8588 | bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield |
| 8589 | bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0 |
| 8590 | exe_scope); |
| 8591 | } |
| 8592 | break; |
| 8593 | |
| 8594 | case clang::Type::Enum: |
| 8595 | // If our format is enum or default, show the enumeration value as |
| 8596 | // its enumeration string value, else just display it as requested. |
| 8597 | if ((format == eFormatEnum || format == eFormatDefault) && GetCompleteType(type)) |
| 8598 | { |
| 8599 | const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr()); |
| 8600 | const clang::EnumDecl *enum_decl = enutype->getDecl(); |
| 8601 | assert(enum_decl); |
| 8602 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; |
| 8603 | const bool is_signed = qual_type->isSignedIntegerOrEnumerationType(); |
| 8604 | lldb::offset_t offset = byte_offset; |
| 8605 | if (is_signed) |
| 8606 | { |
| 8607 | const int64_t enum_svalue = data.GetMaxS64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 8608 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) |
| 8609 | { |
| 8610 | if (enum_pos->getInitVal().getSExtValue() == enum_svalue) |
| 8611 | { |
| 8612 | s->PutCString (enum_pos->getNameAsString().c_str()); |
| 8613 | return true; |
| 8614 | } |
| 8615 | } |
| 8616 | // If we have gotten here we didn't get find the enumerator in the |
| 8617 | // enum decl, so just print the integer. |
| 8618 | s->Printf("%" PRIi64, enum_svalue); |
| 8619 | } |
| 8620 | else |
| 8621 | { |
| 8622 | const uint64_t enum_uvalue = data.GetMaxU64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset); |
| 8623 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) |
| 8624 | { |
| 8625 | if (enum_pos->getInitVal().getZExtValue() == enum_uvalue) |
| 8626 | { |
| 8627 | s->PutCString (enum_pos->getNameAsString().c_str()); |
| 8628 | return true; |
| 8629 | } |
| 8630 | } |
| 8631 | // If we have gotten here we didn't get find the enumerator in the |
| 8632 | // enum decl, so just print the integer. |
| 8633 | s->Printf("%" PRIu64, enum_uvalue); |
| 8634 | } |
| 8635 | return true; |
| 8636 | } |
| 8637 | // format was not enum, just fall through and dump the value as requested.... |
| 8638 | |
| 8639 | default: |
| 8640 | // We are down to a scalar type that we just need to display. |
| 8641 | { |
| 8642 | uint32_t item_count = 1; |
| 8643 | // A few formats, we might need to modify our size and count for depending |
| 8644 | // on how we are trying to display the value... |
| 8645 | switch (format) |
| 8646 | { |
| 8647 | default: |
| 8648 | case eFormatBoolean: |
| 8649 | case eFormatBinary: |
| 8650 | case eFormatComplex: |
| 8651 | case eFormatCString: // NULL terminated C strings |
| 8652 | case eFormatDecimal: |
| 8653 | case eFormatEnum: |
| 8654 | case eFormatHex: |
| 8655 | case eFormatHexUppercase: |
| 8656 | case eFormatFloat: |
| 8657 | case eFormatOctal: |
| 8658 | case eFormatOSType: |
| 8659 | case eFormatUnsigned: |
| 8660 | case eFormatPointer: |
| 8661 | case eFormatVectorOfChar: |
| 8662 | case eFormatVectorOfSInt8: |
| 8663 | case eFormatVectorOfUInt8: |
| 8664 | case eFormatVectorOfSInt16: |
| 8665 | case eFormatVectorOfUInt16: |
| 8666 | case eFormatVectorOfSInt32: |
| 8667 | case eFormatVectorOfUInt32: |
| 8668 | case eFormatVectorOfSInt64: |
| 8669 | case eFormatVectorOfUInt64: |
| 8670 | case eFormatVectorOfFloat32: |
| 8671 | case eFormatVectorOfFloat64: |
| 8672 | case eFormatVectorOfUInt128: |
| 8673 | break; |
| 8674 | |
| 8675 | case eFormatChar: |
| 8676 | case eFormatCharPrintable: |
| 8677 | case eFormatCharArray: |
| 8678 | case eFormatBytes: |
| 8679 | case eFormatBytesWithASCII: |
| 8680 | item_count = byte_size; |
| 8681 | byte_size = 1; |
| 8682 | break; |
| 8683 | |
| 8684 | case eFormatUnicode16: |
| 8685 | item_count = byte_size / 2; |
| 8686 | byte_size = 2; |
| 8687 | break; |
| 8688 | |
| 8689 | case eFormatUnicode32: |
| 8690 | item_count = byte_size / 4; |
| 8691 | byte_size = 4; |
| 8692 | break; |
| 8693 | } |
| 8694 | return data.Dump (s, |
| 8695 | byte_offset, |
| 8696 | format, |
| 8697 | byte_size, |
| 8698 | item_count, |
| 8699 | UINT32_MAX, |
| 8700 | LLDB_INVALID_ADDRESS, |
| 8701 | bitfield_bit_size, |
| 8702 | bitfield_bit_offset, |
| 8703 | exe_scope); |
| 8704 | } |
| 8705 | break; |
| 8706 | } |
| 8707 | } |
| 8708 | return 0; |
| 8709 | } |
| 8710 | |
| 8711 | |
| 8712 | |
| 8713 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8714 | ClangASTContext::DumpSummary (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8715 | Stream *s, |
| 8716 | const lldb_private::DataExtractor &data, |
| 8717 | lldb::offset_t data_byte_offset, |
| 8718 | size_t data_byte_size) |
| 8719 | { |
| 8720 | uint32_t length = 0; |
| 8721 | if (IsCStringType (type, length)) |
| 8722 | { |
| 8723 | if (exe_ctx) |
| 8724 | { |
| 8725 | Process *process = exe_ctx->GetProcessPtr(); |
| 8726 | if (process) |
| 8727 | { |
| 8728 | lldb::offset_t offset = data_byte_offset; |
| 8729 | lldb::addr_t pointer_address = data.GetMaxU64(&offset, data_byte_size); |
| 8730 | std::vector<uint8_t> buf; |
| 8731 | if (length > 0) |
| 8732 | buf.resize (length); |
| 8733 | else |
| 8734 | buf.resize (256); |
| 8735 | |
| 8736 | lldb_private::DataExtractor cstr_data(&buf.front(), buf.size(), process->GetByteOrder(), 4); |
| 8737 | buf.back() = '\0'; |
| 8738 | size_t bytes_read; |
| 8739 | size_t total_cstr_len = 0; |
| 8740 | Error error; |
| 8741 | while ((bytes_read = process->ReadMemory (pointer_address, &buf.front(), buf.size(), error)) > 0) |
| 8742 | { |
| 8743 | const size_t len = strlen((const char *)&buf.front()); |
| 8744 | if (len == 0) |
| 8745 | break; |
| 8746 | if (total_cstr_len == 0) |
| 8747 | s->PutCString (" \""); |
| 8748 | cstr_data.Dump(s, 0, lldb::eFormatChar, 1, len, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); |
| 8749 | total_cstr_len += len; |
| 8750 | if (len < buf.size()) |
| 8751 | break; |
| 8752 | pointer_address += total_cstr_len; |
| 8753 | } |
| 8754 | if (total_cstr_len > 0) |
| 8755 | s->PutChar ('"'); |
| 8756 | } |
| 8757 | } |
| 8758 | } |
| 8759 | } |
| 8760 | |
| 8761 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8762 | ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8763 | { |
| 8764 | StreamFile s (stdout, false); |
| 8765 | DumpTypeDescription (&s); |
| 8766 | ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), type); |
| 8767 | if (metadata) |
| 8768 | { |
| 8769 | metadata->Dump (&s); |
| 8770 | } |
| 8771 | } |
| 8772 | |
| 8773 | void |
Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8774 | ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type, Stream *s) |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8775 | { |
| 8776 | if (type) |
| 8777 | { |
| 8778 | clang::QualType qual_type(GetQualType(type)); |
| 8779 | |
| 8780 | llvm::SmallVector<char, 1024> buf; |
| 8781 | llvm::raw_svector_ostream llvm_ostrm (buf); |
| 8782 | |
| 8783 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 8784 | switch (type_class) |
| 8785 | { |
| 8786 | case clang::Type::ObjCObject: |
| 8787 | case clang::Type::ObjCInterface: |
| 8788 | { |
| 8789 | GetCompleteType(type); |
| 8790 | |
| 8791 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); |
| 8792 | assert (objc_class_type); |
| 8793 | if (objc_class_type) |
| 8794 | { |
| 8795 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 8796 | if (class_interface_decl) |
| 8797 | { |
| 8798 | clang::PrintingPolicy policy = getASTContext()->getPrintingPolicy(); |
| 8799 | class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel()); |
| 8800 | } |
| 8801 | } |
| 8802 | } |
| 8803 | break; |
| 8804 | |
| 8805 | case clang::Type::Typedef: |
| 8806 | { |
| 8807 | const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>(); |
| 8808 | if (typedef_type) |
| 8809 | { |
| 8810 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); |
| 8811 | std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString()); |
| 8812 | if (!clang_typedef_name.empty()) |
| 8813 | { |
| 8814 | s->PutCString ("typedef "); |
| 8815 | s->PutCString (clang_typedef_name.c_str()); |
| 8816 | } |
| 8817 | } |
| 8818 | } |
| 8819 | break; |
| 8820 | |
| 8821 | case clang::Type::Elaborated: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8822 | CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).DumpTypeDescription(s); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8823 | return; |
| 8824 | |
| 8825 | case clang::Type::Paren: |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8826 | CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).DumpTypeDescription(s); |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8827 | return; |
| 8828 | |
| 8829 | case clang::Type::Record: |
| 8830 | { |
| 8831 | GetCompleteType(type); |
| 8832 | |
| 8833 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); |
| 8834 | const clang::RecordDecl *record_decl = record_type->getDecl(); |
| 8835 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); |
| 8836 | |
| 8837 | if (cxx_record_decl) |
| 8838 | cxx_record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel()); |
| 8839 | else |
| 8840 | record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel()); |
| 8841 | } |
| 8842 | break; |
| 8843 | |
| 8844 | default: |
| 8845 | { |
| 8846 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
| 8847 | if (tag_type) |
| 8848 | { |
| 8849 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 8850 | if (tag_decl) |
| 8851 | tag_decl->print(llvm_ostrm, 0); |
| 8852 | } |
| 8853 | else |
| 8854 | { |
| 8855 | std::string clang_type_name(qual_type.getAsString()); |
| 8856 | if (!clang_type_name.empty()) |
| 8857 | s->PutCString (clang_type_name.c_str()); |
| 8858 | } |
| 8859 | } |
| 8860 | } |
| 8861 | |
Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8862 | if (buf.size() > 0) |
| 8863 | { |
| 8864 | s->Write (buf.data(), buf.size()); |
| 8865 | } |
| 8866 | } |
| 8867 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8868 | |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8869 | clang::ClassTemplateDecl * |
Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 8870 | ClangASTContext::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8871 | lldb::AccessType access_type, |
| 8872 | const char *parent_name, |
| 8873 | int tag_decl_kind, |
| 8874 | const ClangASTContext::TemplateParameterInfos &template_param_infos) |
| 8875 | { |
| 8876 | if (template_param_infos.IsValid()) |
| 8877 | { |
| 8878 | std::string template_basename(parent_name); |
| 8879 | template_basename.erase (template_basename.find('<')); |
| 8880 | |
| 8881 | return CreateClassTemplateDecl (decl_ctx, |
| 8882 | access_type, |
| 8883 | template_basename.c_str(), |
| 8884 | tag_decl_kind, |
| 8885 | template_param_infos); |
| 8886 | } |
| 8887 | return NULL; |
| 8888 | } |
| 8889 | |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 8890 | void |
| 8891 | ClangASTContext::CompleteTagDecl (void *baton, clang::TagDecl *decl) |
| 8892 | { |
| 8893 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 8894 | SymbolFile *sym_file = ast->GetSymbolFile(); |
| 8895 | if (sym_file) |
| 8896 | { |
| 8897 | CompilerType clang_type = GetTypeForDecl (decl); |
| 8898 | if (clang_type) |
| 8899 | sym_file->CompleteType (clang_type); |
| 8900 | } |
| 8901 | } |
| 8902 | |
| 8903 | void |
| 8904 | ClangASTContext::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) |
| 8905 | { |
| 8906 | ClangASTContext *ast = (ClangASTContext *)baton; |
| 8907 | SymbolFile *sym_file = ast->GetSymbolFile(); |
| 8908 | if (sym_file) |
| 8909 | { |
| 8910 | CompilerType clang_type = GetTypeForDecl (decl); |
| 8911 | if (clang_type) |
| 8912 | sym_file->CompleteType (clang_type); |
| 8913 | } |
| 8914 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8915 | |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 8916 | |
| 8917 | DWARFASTParser * |
| 8918 | ClangASTContext::GetDWARFParser () |
| 8919 | { |
| 8920 | if (!m_dwarf_ast_parser_ap) |
| 8921 | m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this)); |
| 8922 | return m_dwarf_ast_parser_ap.get(); |
| 8923 | } |
| 8924 | |
| 8925 | |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8926 | bool |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 8927 | ClangASTContext::LayoutRecordType(void *baton, |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8928 | const clang::RecordDecl *record_decl, |
| 8929 | uint64_t &bit_size, |
| 8930 | uint64_t &alignment, |
| 8931 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
| 8932 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 8933 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 8934 | { |
Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 8935 | ClangASTContext *ast = (ClangASTContext *)baton; |
Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 8936 | DWARFASTParserClang *dwarf_ast_parser = (DWARFASTParserClang *)ast->GetDWARFParser(); |
| 8937 | 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] | 8938 | } |
| 8939 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 8940 | //---------------------------------------------------------------------- |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 8941 | // CompilerDecl override functions |
| 8942 | //---------------------------------------------------------------------- |
| 8943 | lldb::VariableSP |
| 8944 | ClangASTContext::DeclGetVariable (void *opaque_decl) |
| 8945 | { |
| 8946 | if (llvm::dyn_cast<clang::VarDecl>((clang::Decl *)opaque_decl)) |
| 8947 | { |
| 8948 | auto decl_search_it = m_decl_objects.find(opaque_decl); |
| 8949 | if (decl_search_it != m_decl_objects.end()) |
| 8950 | return std::static_pointer_cast<Variable>(decl_search_it->second); |
| 8951 | } |
| 8952 | return VariableSP(); |
| 8953 | } |
| 8954 | |
| 8955 | void |
| 8956 | ClangASTContext::DeclLinkToObject (void *opaque_decl, std::shared_ptr<void> object) |
| 8957 | { |
| 8958 | if (m_decl_objects.find(opaque_decl) == m_decl_objects.end()) |
| 8959 | m_decl_objects.insert(std::make_pair(opaque_decl, object)); |
| 8960 | } |
| 8961 | |
| 8962 | ConstString |
| 8963 | ClangASTContext::DeclGetName (void *opaque_decl) |
| 8964 | { |
| 8965 | if (opaque_decl) |
| 8966 | { |
| 8967 | clang::NamedDecl *nd = llvm::dyn_cast<NamedDecl>((clang::Decl*)opaque_decl); |
| 8968 | if (nd != nullptr) |
| 8969 | return ConstString(nd->getName()); |
| 8970 | } |
| 8971 | return ConstString(); |
| 8972 | } |
| 8973 | |
| 8974 | //---------------------------------------------------------------------- |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 8975 | // CompilerDeclContext functions |
| 8976 | //---------------------------------------------------------------------- |
| 8977 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 8978 | std::vector<void *> |
| 8979 | ClangASTContext::DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name) |
| 8980 | { |
| 8981 | std::vector<void *> found_decls; |
| 8982 | if (opaque_decl_ctx) |
| 8983 | { |
| 8984 | DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx; |
| 8985 | std::set<DeclContext *> searched; |
| 8986 | std::multimap<DeclContext *, DeclContext *> search_queue; |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 8987 | SymbolFile *symbol_file = GetSymbolFile(); |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 8988 | |
| 8989 | for (clang::DeclContext *decl_context = root_decl_ctx; decl_context != nullptr && found_decls.empty(); decl_context = decl_context->getParent()) |
| 8990 | { |
| 8991 | search_queue.insert(std::make_pair(decl_context, decl_context)); |
| 8992 | |
| 8993 | for (auto it = search_queue.find(decl_context); it != search_queue.end(); it++) |
| 8994 | { |
| 8995 | searched.insert(it->second); |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 8996 | symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second)); |
| 8997 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 8998 | for (clang::Decl *child : it->second->decls()) |
| 8999 | { |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9000 | if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9001 | { |
| 9002 | clang::DeclContext *from = ud->getCommonAncestor(); |
| 9003 | if (searched.find(ud->getNominatedNamespace()) == searched.end()) |
| 9004 | search_queue.insert(std::make_pair(from, ud->getNominatedNamespace())); |
| 9005 | } |
| 9006 | else if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child)) |
| 9007 | { |
| 9008 | for (clang::UsingShadowDecl *usd : ud->shadows()) |
| 9009 | { |
| 9010 | clang::Decl *target = usd->getTargetDecl(); |
| 9011 | if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target)) |
| 9012 | { |
| 9013 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9014 | if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) |
| 9015 | found_decls.push_back(nd); |
| 9016 | } |
| 9017 | } |
| 9018 | } |
Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9019 | else if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(child)) |
| 9020 | { |
| 9021 | IdentifierInfo *ii = nd->getIdentifier(); |
| 9022 | if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) |
| 9023 | found_decls.push_back(nd); |
| 9024 | } |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9025 | } |
| 9026 | } |
| 9027 | } |
| 9028 | } |
| 9029 | return found_decls; |
| 9030 | } |
| 9031 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9032 | bool |
| 9033 | ClangASTContext::DeclContextIsStructUnionOrClass (void *opaque_decl_ctx) |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9034 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9035 | if (opaque_decl_ctx) |
| 9036 | return ((clang::DeclContext *)opaque_decl_ctx)->isRecord(); |
| 9037 | else |
| 9038 | return false; |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9039 | } |
| 9040 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9041 | ConstString |
| 9042 | ClangASTContext::DeclContextGetName (void *opaque_decl_ctx) |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9043 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9044 | if (opaque_decl_ctx) |
| 9045 | { |
| 9046 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); |
| 9047 | if (named_decl) |
| 9048 | return ConstString(named_decl->getName()); |
| 9049 | } |
| 9050 | return ConstString(); |
| 9051 | } |
| 9052 | |
| 9053 | bool |
| 9054 | ClangASTContext::DeclContextIsClassMethod (void *opaque_decl_ctx, |
| 9055 | lldb::LanguageType *language_ptr, |
| 9056 | bool *is_instance_method_ptr, |
| 9057 | ConstString *language_object_name_ptr) |
| 9058 | { |
| 9059 | if (opaque_decl_ctx) |
| 9060 | { |
| 9061 | clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx; |
| 9062 | if (ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx)) |
| 9063 | { |
| 9064 | if (is_instance_method_ptr) |
| 9065 | *is_instance_method_ptr = objc_method->isInstanceMethod(); |
| 9066 | if (language_ptr) |
| 9067 | *language_ptr = eLanguageTypeObjC; |
| 9068 | if (language_object_name_ptr) |
| 9069 | language_object_name_ptr->SetCString("self"); |
| 9070 | return true; |
| 9071 | } |
| 9072 | else if (CXXMethodDecl *cxx_method = llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx)) |
| 9073 | { |
| 9074 | if (is_instance_method_ptr) |
| 9075 | *is_instance_method_ptr = cxx_method->isInstance(); |
| 9076 | if (language_ptr) |
| 9077 | *language_ptr = eLanguageTypeC_plus_plus; |
| 9078 | if (language_object_name_ptr) |
| 9079 | language_object_name_ptr->SetCString("this"); |
| 9080 | return true; |
| 9081 | } |
| 9082 | else if (clang::FunctionDecl *function_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) |
| 9083 | { |
| 9084 | ClangASTMetadata *metadata = GetMetadata (&decl_ctx->getParentASTContext(), function_decl); |
| 9085 | if (metadata && metadata->HasObjectPtr()) |
| 9086 | { |
| 9087 | if (is_instance_method_ptr) |
| 9088 | *is_instance_method_ptr = true; |
| 9089 | if (language_ptr) |
| 9090 | *language_ptr = eLanguageTypeObjC; |
| 9091 | if (language_object_name_ptr) |
| 9092 | language_object_name_ptr->SetCString (metadata->GetObjectPtrName()); |
| 9093 | return true; |
| 9094 | } |
| 9095 | } |
| 9096 | } |
| 9097 | return false; |
| 9098 | } |
| 9099 | |
| 9100 | clang::DeclContext * |
| 9101 | ClangASTContext::DeclContextGetAsDeclContext (const CompilerDeclContext &dc) |
| 9102 | { |
| 9103 | if (dc.IsClang()) |
| 9104 | return (clang::DeclContext *)dc.GetOpaqueDeclContext(); |
| 9105 | return nullptr; |
| 9106 | } |
| 9107 | |
| 9108 | |
| 9109 | ObjCMethodDecl * |
| 9110 | ClangASTContext::DeclContextGetAsObjCMethodDecl (const CompilerDeclContext &dc) |
| 9111 | { |
| 9112 | if (dc.IsClang()) |
| 9113 | return llvm::dyn_cast<clang::ObjCMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 9114 | return nullptr; |
| 9115 | } |
| 9116 | |
| 9117 | CXXMethodDecl * |
| 9118 | ClangASTContext::DeclContextGetAsCXXMethodDecl (const CompilerDeclContext &dc) |
| 9119 | { |
| 9120 | if (dc.IsClang()) |
| 9121 | return llvm::dyn_cast<clang::CXXMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 9122 | return nullptr; |
| 9123 | } |
| 9124 | |
| 9125 | clang::FunctionDecl * |
| 9126 | ClangASTContext::DeclContextGetAsFunctionDecl (const CompilerDeclContext &dc) |
| 9127 | { |
| 9128 | if (dc.IsClang()) |
| 9129 | return llvm::dyn_cast<clang::FunctionDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 9130 | return nullptr; |
| 9131 | } |
| 9132 | |
| 9133 | clang::NamespaceDecl * |
| 9134 | ClangASTContext::DeclContextGetAsNamespaceDecl (const CompilerDeclContext &dc) |
| 9135 | { |
| 9136 | if (dc.IsClang()) |
| 9137 | return llvm::dyn_cast<clang::NamespaceDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); |
| 9138 | return nullptr; |
| 9139 | } |
| 9140 | |
| 9141 | ClangASTMetadata * |
| 9142 | ClangASTContext::DeclContextGetMetaData (const CompilerDeclContext &dc, const void *object) |
| 9143 | { |
| 9144 | clang::ASTContext *ast = DeclContextGetClangASTContext (dc); |
| 9145 | if (ast) |
| 9146 | return ClangASTContext::GetMetadata (ast, object); |
| 9147 | return nullptr; |
| 9148 | } |
| 9149 | |
| 9150 | clang::ASTContext * |
| 9151 | ClangASTContext::DeclContextGetClangASTContext (const CompilerDeclContext &dc) |
| 9152 | { |
Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 9153 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(dc.GetTypeSystem()); |
| 9154 | if (ast) |
| 9155 | return ast->getASTContext(); |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9156 | return nullptr; |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9157 | } |
| 9158 | |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 9159 | ClangASTContextForExpressions::ClangASTContextForExpressions (Target &target) : |
| 9160 | ClangASTContext (target.GetArchitecture().GetTriple().getTriple().c_str()), |
| 9161 | m_target_wp(target.shared_from_this()) |
| 9162 | { |
| 9163 | } |
| 9164 | |
| 9165 | UserExpression * |
| 9166 | ClangASTContextForExpressions::GetUserExpression (const char *expr, |
| 9167 | const char *expr_prefix, |
| 9168 | lldb::LanguageType language, |
| 9169 | Expression::ResultType desired_type) |
| 9170 | { |
| 9171 | TargetSP target_sp = m_target_wp.lock(); |
| 9172 | if (!target_sp) |
| 9173 | return nullptr; |
| 9174 | |
| 9175 | return new ClangUserExpression(*target_sp.get(), expr, expr_prefix, language, desired_type); |
| 9176 | } |
| 9177 | |
| 9178 | FunctionCaller * |
| 9179 | ClangASTContextForExpressions::GetFunctionCaller (const CompilerType &return_type, |
| 9180 | const Address& function_address, |
| 9181 | const ValueList &arg_value_list, |
| 9182 | const char *name) |
| 9183 | { |
| 9184 | TargetSP target_sp = m_target_wp.lock(); |
| 9185 | if (!target_sp) |
| 9186 | return nullptr; |
| 9187 | |
| 9188 | Process *process = target_sp->GetProcessSP().get(); |
| 9189 | if (!process) |
| 9190 | return nullptr; |
| 9191 | |
| 9192 | return new ClangFunctionCaller (*process, return_type, function_address, arg_value_list, name); |
| 9193 | } |
| 9194 | |
| 9195 | UtilityFunction * |
| 9196 | ClangASTContextForExpressions::GetUtilityFunction (const char *text, |
| 9197 | const char *name) |
| 9198 | { |
| 9199 | TargetSP target_sp = m_target_wp.lock(); |
| 9200 | if (!target_sp) |
| 9201 | return nullptr; |
| 9202 | |
| 9203 | return new ClangUtilityFunction(*target_sp.get(), text, name); |
| 9204 | } |