| 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> | 
| Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame] | 16 | #include <vector> | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 |  | 
|  | 18 | // Other libraries and framework includes | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 19 |  | 
|  | 20 | // 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] | 21 | // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 22 | // or another. This is bad because it means that if clang was built in release | 
|  | 23 | // mode, it assumes that you are building in release mode which is not always | 
|  | 24 | // the case. You can end up with functions that are defined as empty in header | 
|  | 25 | // files when NDEBUG is not defined, and this can cause link errors with the | 
|  | 26 | // clang .a files that you have since you might be missing functions in the .a | 
|  | 27 | // file. So we have to define NDEBUG when including clang headers to avoid any | 
|  | 28 | // mismatches. This is covered by rdar://problem/8691220 | 
|  | 29 |  | 
| Sean Callanan | 3b1d4f6 | 2011-10-26 17:46:51 +0000 | [diff] [blame] | 30 | #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 31 | #define LLDB_DEFINED_NDEBUG_FOR_CLANG | 
| Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 32 | #define NDEBUG | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 33 | // Need to include assert.h so it is as clang would expect it to be (disabled) | 
|  | 34 | #include <assert.h> | 
|  | 35 | #endif | 
|  | 36 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | #include "clang/AST/ASTContext.h" | 
|  | 38 | #include "clang/AST/ASTImporter.h" | 
| Greg Clayton | f74c403 | 2012-12-03 18:29:55 +0000 | [diff] [blame] | 39 | #include "clang/AST/Attr.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "clang/AST/CXXInheritance.h" | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 41 | #include "clang/AST/DeclObjC.h" | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 42 | #include "clang/AST/DeclTemplate.h" | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 43 | #include "clang/AST/Mangle.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | #include "clang/AST/RecordLayout.h" | 
|  | 45 | #include "clang/AST/Type.h" | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 46 | #include "clang/AST/VTableBuilder.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | #include "clang/Basic/Builtins.h" | 
| Sean Callanan | 7e2863b | 2012-02-06 21:28:03 +0000 | [diff] [blame] | 48 | #include "clang/Basic/Diagnostic.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | #include "clang/Basic/FileManager.h" | 
| Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 50 | #include "clang/Basic/FileSystemOptions.h" | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | #include "clang/Basic/SourceManager.h" | 
|  | 52 | #include "clang/Basic/TargetInfo.h" | 
|  | 53 | #include "clang/Basic/TargetOptions.h" | 
|  | 54 | #include "clang/Frontend/FrontendOptions.h" | 
|  | 55 | #include "clang/Frontend/LangStandard.h" | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 56 |  | 
|  | 57 | #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG | 
| Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 58 | #undef NDEBUG | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 59 | #undef LLDB_DEFINED_NDEBUG_FOR_CLANG | 
|  | 60 | // Need to re-include assert.h so it is as _we_ would expect it to be (enabled) | 
|  | 61 | #include <assert.h> | 
|  | 62 | #endif | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 64 | #include "llvm/Support/Signals.h" | 
|  | 65 |  | 
| Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 66 | #include "lldb/Core/ArchSpec.h" | 
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 67 | #include "lldb/Core/Flags.h" | 
| Sean Callanan | fb8b709 | 2010-10-28 18:19:36 +0000 | [diff] [blame] | 68 | #include "lldb/Core/Log.h" | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 69 | #include "lldb/Core/Module.h" | 
|  | 70 | #include "lldb/Core/PluginManager.h" | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 71 | #include "lldb/Core/RegularExpression.h" | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 72 | #include "lldb/Core/StreamFile.h" | 
| Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 73 | #include "lldb/Core/ThreadSafeDenseMap.h" | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 74 | #include "lldb/Core/UniqueCStringMap.h" | 
| Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 75 | #include "Plugins/ExpressionParser/Clang/ClangUserExpression.h" | 
|  | 76 | #include "Plugins/ExpressionParser/Clang/ClangFunctionCaller.h" | 
|  | 77 | #include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h" | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 78 | #include "lldb/Symbol/ClangASTContext.h" | 
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 79 | #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" | 
| Sean Callanan | 3b107b1 | 2011-12-03 03:15:28 +0000 | [diff] [blame] | 80 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 81 | #include "lldb/Symbol/ObjectFile.h" | 
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 82 | #include "lldb/Symbol/SymbolFile.h" | 
| Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 83 | #include "lldb/Symbol/VerifyDecl.h" | 
| Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 84 | #include "lldb/Target/ExecutionContext.h" | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 85 | #include "lldb/Target/Language.h" | 
| Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 86 | #include "lldb/Target/ObjCLanguageRuntime.h" | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 87 | #include "lldb/Target/Process.h" | 
|  | 88 | #include "lldb/Target/Target.h" | 
| Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 89 |  | 
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 90 | #include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h" | 
|  | 91 |  | 
| Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 92 | #include <stdio.h> | 
|  | 93 |  | 
| Greg Clayton | 1341baf | 2013-07-11 23:36:31 +0000 | [diff] [blame] | 94 | #include <mutex> | 
|  | 95 |  | 
| Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 96 | using namespace lldb; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | using namespace lldb_private; | 
|  | 98 | using namespace llvm; | 
|  | 99 | using namespace clang; | 
|  | 100 |  | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 101 | namespace | 
|  | 102 | { | 
|  | 103 | static inline bool ClangASTContextSupportsLanguage (lldb::LanguageType language) | 
|  | 104 | { | 
|  | 105 | return language == eLanguageTypeUnknown || // Clang is the default type system | 
|  | 106 | Language::LanguageIsC (language) || | 
|  | 107 | Language::LanguageIsCPlusPlus (language) || | 
| Ewan Crawford | 75f0ff5 | 2016-02-03 09:17:03 +0000 | [diff] [blame] | 108 | Language::LanguageIsObjC (language) || | 
|  | 109 | language == eLanguageTypeExtRenderScript; | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 110 | } | 
|  | 111 | } | 
|  | 112 |  | 
| Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 113 | typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, ClangASTContext*> ClangASTMap; | 
| Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 114 |  | 
|  | 115 | static ClangASTMap & | 
|  | 116 | GetASTMap() | 
|  | 117 | { | 
| Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 118 | static ClangASTMap *g_map_ptr = nullptr; | 
|  | 119 | static std::once_flag g_once_flag; | 
|  | 120 | std::call_once(g_once_flag,  []() { | 
|  | 121 | g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins | 
|  | 122 | }); | 
|  | 123 | return *g_map_ptr; | 
| Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 124 | } | 
|  | 125 |  | 
|  | 126 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 127 | clang::AccessSpecifier | 
|  | 128 | ClangASTContext::ConvertAccessTypeToAccessSpecifier (AccessType access) | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 129 | { | 
|  | 130 | switch (access) | 
|  | 131 | { | 
| Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 132 | default:               break; | 
|  | 133 | case eAccessNone:      return AS_none; | 
|  | 134 | case eAccessPublic:    return AS_public; | 
|  | 135 | case eAccessPrivate:   return AS_private; | 
|  | 136 | case eAccessProtected: return AS_protected; | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 137 | } | 
|  | 138 | return AS_none; | 
|  | 139 | } | 
|  | 140 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | static void | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 142 | ParseLangArgs (LangOptions &Opts, InputKind IK, const char* triple) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | { | 
|  | 144 | // FIXME: Cleanup per-file based stuff. | 
|  | 145 |  | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 146 | // 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] | 147 | // to move these to the language standard, and have the driver resolve the | 
|  | 148 | // input kind + language standard. | 
| Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 149 | if (IK == IK_Asm) { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | Opts.AsmPreprocessor = 1; | 
| Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 151 | } else if (IK == IK_ObjC || | 
|  | 152 | IK == IK_ObjCXX || | 
|  | 153 | IK == IK_PreprocessedObjC || | 
|  | 154 | IK == IK_PreprocessedObjCXX) { | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 155 | Opts.ObjC1 = Opts.ObjC2 = 1; | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; | 
|  | 159 |  | 
|  | 160 | if (LangStd == LangStandard::lang_unspecified) { | 
|  | 161 | // Based on the base language, pick one. | 
|  | 162 | switch (IK) { | 
| Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 163 | case IK_None: | 
|  | 164 | case IK_AST: | 
| Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 165 | case IK_LLVM_IR: | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 166 | assert (!"Invalid input kind!"); | 
| Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 167 | case IK_OpenCL: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 168 | LangStd = LangStandard::lang_opencl; | 
|  | 169 | break; | 
| Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 170 | case IK_CUDA: | 
| Artem Belevich | 52210ae | 2015-03-19 18:12:26 +0000 | [diff] [blame] | 171 | case IK_PreprocessedCuda: | 
| Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 172 | LangStd = LangStandard::lang_cuda; | 
|  | 173 | break; | 
| Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 174 | case IK_Asm: | 
|  | 175 | case IK_C: | 
|  | 176 | case IK_PreprocessedC: | 
|  | 177 | case IK_ObjC: | 
|  | 178 | case IK_PreprocessedObjC: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | LangStd = LangStandard::lang_gnu99; | 
|  | 180 | break; | 
| Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 181 | case IK_CXX: | 
|  | 182 | case IK_PreprocessedCXX: | 
|  | 183 | case IK_ObjCXX: | 
|  | 184 | case IK_PreprocessedObjCXX: | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 185 | LangStd = LangStandard::lang_gnucxx98; | 
|  | 186 | break; | 
|  | 187 | } | 
|  | 188 | } | 
|  | 189 |  | 
|  | 190 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); | 
| Filipe Cabecinhas | e818ca2 | 2012-11-12 21:26:32 +0000 | [diff] [blame] | 191 | Opts.LineComment = Std.hasLineComments(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | Opts.C99 = Std.isC99(); | 
|  | 193 | Opts.CPlusPlus = Std.isCPlusPlus(); | 
| Chandler Carruth | 38336a1 | 2013-01-02 12:55:00 +0000 | [diff] [blame] | 194 | Opts.CPlusPlus11 = Std.isCPlusPlus11(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 195 | Opts.Digraphs = Std.hasDigraphs(); | 
|  | 196 | Opts.GNUMode = Std.isGNUMode(); | 
|  | 197 | Opts.GNUInline = !Std.isC99(); | 
|  | 198 | Opts.HexFloats = Std.hasHexFloats(); | 
|  | 199 | Opts.ImplicitInt = Std.hasImplicitInt(); | 
| Enrico Granata | c921e34 | 2013-01-10 02:37:22 +0000 | [diff] [blame] | 200 |  | 
|  | 201 | Opts.WChar = true; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 202 |  | 
|  | 203 | // OpenCL has some additional defaults. | 
|  | 204 | if (LangStd == LangStandard::lang_opencl) { | 
|  | 205 | Opts.OpenCL = 1; | 
|  | 206 | Opts.AltiVec = 1; | 
|  | 207 | Opts.CXXOperatorNames = 1; | 
|  | 208 | Opts.LaxVectorConversions = 1; | 
|  | 209 | } | 
|  | 210 |  | 
|  | 211 | // OpenCL and C++ both have bool, true, false keywords. | 
|  | 212 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; | 
|  | 213 |  | 
|  | 214 | //    if (Opts.CPlusPlus) | 
|  | 215 | //        Opts.CXXOperatorNames = !Args.hasArg(OPT_fno_operator_names); | 
|  | 216 | // | 
|  | 217 | //    if (Args.hasArg(OPT_fobjc_gc_only)) | 
|  | 218 | //        Opts.setGCMode(LangOptions::GCOnly); | 
|  | 219 | //    else if (Args.hasArg(OPT_fobjc_gc)) | 
|  | 220 | //        Opts.setGCMode(LangOptions::HybridGC); | 
|  | 221 | // | 
|  | 222 | //    if (Args.hasArg(OPT_print_ivar_layout)) | 
|  | 223 | //        Opts.ObjCGCBitmapPrint = 1; | 
|  | 224 | // | 
|  | 225 | //    if (Args.hasArg(OPT_faltivec)) | 
|  | 226 | //        Opts.AltiVec = 1; | 
|  | 227 | // | 
|  | 228 | //    if (Args.hasArg(OPT_pthread)) | 
|  | 229 | //        Opts.POSIXThreads = 1; | 
|  | 230 | // | 
|  | 231 | //    llvm::StringRef Vis = getLastArgValue(Args, OPT_fvisibility, | 
|  | 232 | //                                          "default"); | 
|  | 233 | //    if (Vis == "default") | 
| Sean Callanan | 37f76e5 | 2013-02-19 19:16:37 +0000 | [diff] [blame] | 234 | Opts.setValueVisibilityMode(DefaultVisibility); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 235 | //    else if (Vis == "hidden") | 
|  | 236 | //        Opts.setVisibilityMode(LangOptions::Hidden); | 
|  | 237 | //    else if (Vis == "protected") | 
|  | 238 | //        Opts.setVisibilityMode(LangOptions::Protected); | 
|  | 239 | //    else | 
|  | 240 | //        Diags.Report(diag::err_drv_invalid_value) | 
|  | 241 | //        << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis; | 
|  | 242 |  | 
|  | 243 | //    Opts.OverflowChecking = Args.hasArg(OPT_ftrapv); | 
|  | 244 |  | 
|  | 245 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs | 
|  | 246 | // is specified, or -std is set to a conforming mode. | 
|  | 247 | Opts.Trigraphs = !Opts.GNUMode; | 
|  | 248 | //    if (Args.hasArg(OPT_trigraphs)) | 
|  | 249 | //        Opts.Trigraphs = 1; | 
|  | 250 | // | 
|  | 251 | //    Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, | 
|  | 252 | //                                     OPT_fno_dollars_in_identifiers, | 
|  | 253 | //                                     !Opts.AsmPreprocessor); | 
|  | 254 | //    Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); | 
|  | 255 | //    Opts.Microsoft = Args.hasArg(OPT_fms_extensions); | 
|  | 256 | //    Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); | 
|  | 257 | //    if (Args.hasArg(OPT_fno_lax_vector_conversions)) | 
|  | 258 | //        Opts.LaxVectorConversions = 0; | 
|  | 259 | //    Opts.Exceptions = Args.hasArg(OPT_fexceptions); | 
|  | 260 | //    Opts.RTTI = !Args.hasArg(OPT_fno_rtti); | 
|  | 261 | //    Opts.Blocks = Args.hasArg(OPT_fblocks); | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 262 | Opts.CharIsSigned = ArchSpec(triple).CharIsSignedByDefault(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | //    Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar); | 
|  | 264 | //    Opts.Freestanding = Args.hasArg(OPT_ffreestanding); | 
|  | 265 | //    Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; | 
|  | 266 | //    Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); | 
|  | 267 | //    Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); | 
|  | 268 | //    Opts.AccessControl = Args.hasArg(OPT_faccess_control); | 
|  | 269 | //    Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); | 
|  | 270 | //    Opts.MathErrno = !Args.hasArg(OPT_fno_math_errno); | 
|  | 271 | //    Opts.InstantiationDepth = getLastArgIntValue(Args, OPT_ftemplate_depth, 99, | 
|  | 272 | //                                                 Diags); | 
|  | 273 | //    Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime); | 
|  | 274 | //    Opts.ObjCConstantStringClass = getLastArgValue(Args, | 
|  | 275 | //                                                   OPT_fconstant_string_class); | 
|  | 276 | //    Opts.ObjCNonFragileABI = Args.hasArg(OPT_fobjc_nonfragile_abi); | 
|  | 277 | //    Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior); | 
|  | 278 | //    Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); | 
|  | 279 | //    Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); | 
|  | 280 | //    Opts.Static = Args.hasArg(OPT_static_define); | 
|  | 281 | Opts.OptimizeSize = 0; | 
|  | 282 |  | 
|  | 283 | // FIXME: Eliminate this dependency. | 
|  | 284 | //    unsigned Opt = | 
|  | 285 | //    Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags); | 
|  | 286 | //    Opts.Optimize = Opt != 0; | 
|  | 287 | unsigned Opt = 0; | 
|  | 288 |  | 
|  | 289 | // This is the __NO_INLINE__ define, which just depends on things like the | 
|  | 290 | // optimization level and -fno-inline, not actually whether the backend has | 
|  | 291 | // inlining enabled. | 
|  | 292 | // | 
|  | 293 | // FIXME: This is affected by other options (-fno-inline). | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 294 | Opts.NoInlineDefine = !Opt; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 |  | 
|  | 296 | //    unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags); | 
|  | 297 | //    switch (SSP) { | 
|  | 298 | //        default: | 
|  | 299 | //            Diags.Report(diag::err_drv_invalid_value) | 
|  | 300 | //            << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; | 
|  | 301 | //            break; | 
|  | 302 | //        case 0: Opts.setStackProtectorMode(LangOptions::SSPOff); break; | 
|  | 303 | //        case 1: Opts.setStackProtectorMode(LangOptions::SSPOn);  break; | 
|  | 304 | //        case 2: Opts.setStackProtectorMode(LangOptions::SSPReq); break; | 
|  | 305 | //    } | 
|  | 306 | } | 
|  | 307 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 308 |  | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 309 | ClangASTContext::ClangASTContext (const char *target_triple) : | 
|  | 310 | TypeSystem (TypeSystem::eKindClang), | 
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 311 | m_target_triple (), | 
|  | 312 | m_ast_ap (), | 
|  | 313 | m_language_options_ap (), | 
|  | 314 | m_source_manager_ap (), | 
|  | 315 | m_diagnostics_engine_ap (), | 
|  | 316 | m_target_options_rp (), | 
|  | 317 | m_target_info_ap (), | 
|  | 318 | m_identifier_table_ap (), | 
|  | 319 | m_selector_table_ap (), | 
|  | 320 | m_builtins_ap (), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 321 | m_callback_tag_decl (nullptr), | 
|  | 322 | m_callback_objc_decl (nullptr), | 
|  | 323 | m_callback_baton (nullptr), | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 324 | m_pointer_byte_size (0), | 
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 325 | m_ast_owned (false) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 326 | { | 
|  | 327 | if (target_triple && target_triple[0]) | 
| Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 328 | SetTargetTriple (target_triple); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | } | 
|  | 330 |  | 
|  | 331 | //---------------------------------------------------------------------- | 
|  | 332 | // Destructor | 
|  | 333 | //---------------------------------------------------------------------- | 
|  | 334 | ClangASTContext::~ClangASTContext() | 
|  | 335 | { | 
| Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 336 | if (m_ast_ap.get()) | 
|  | 337 | { | 
| Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 338 | GetASTMap().Erase(m_ast_ap.get()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 339 | if (!m_ast_owned) | 
|  | 340 | m_ast_ap.release(); | 
| Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 341 | } | 
|  | 342 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | m_builtins_ap.reset(); | 
|  | 344 | m_selector_table_ap.reset(); | 
|  | 345 | m_identifier_table_ap.reset(); | 
|  | 346 | m_target_info_ap.reset(); | 
| Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 347 | m_target_options_rp.reset(); | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 348 | m_diagnostics_engine_ap.reset(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 349 | m_source_manager_ap.reset(); | 
|  | 350 | m_language_options_ap.reset(); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 351 | m_ast_ap.reset(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | } | 
|  | 353 |  | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 354 | ConstString | 
|  | 355 | ClangASTContext::GetPluginNameStatic() | 
|  | 356 | { | 
|  | 357 | return ConstString("clang"); | 
|  | 358 | } | 
|  | 359 |  | 
|  | 360 | ConstString | 
|  | 361 | ClangASTContext::GetPluginName() | 
|  | 362 | { | 
|  | 363 | return ClangASTContext::GetPluginNameStatic(); | 
|  | 364 | } | 
|  | 365 |  | 
|  | 366 | uint32_t | 
|  | 367 | ClangASTContext::GetPluginVersion() | 
|  | 368 | { | 
|  | 369 | return 1; | 
|  | 370 | } | 
|  | 371 |  | 
|  | 372 | lldb::TypeSystemSP | 
| Tamas Berghammer | 3a6b82b | 2015-10-09 12:06:10 +0000 | [diff] [blame] | 373 | ClangASTContext::CreateInstance (lldb::LanguageType language, | 
|  | 374 | lldb_private::Module *module, | 
|  | 375 | Target *target) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 376 | { | 
|  | 377 | if (ClangASTContextSupportsLanguage(language)) | 
|  | 378 | { | 
| Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 379 | ArchSpec arch; | 
|  | 380 | if (module) | 
|  | 381 | arch = module->GetArchitecture(); | 
|  | 382 | else if (target) | 
|  | 383 | arch = target->GetArchitecture(); | 
|  | 384 |  | 
|  | 385 | if (arch.IsValid()) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 386 | { | 
| Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 387 | ArchSpec fixed_arch = arch; | 
|  | 388 | // LLVM wants this to be set to iOS or MacOSX; if we're working on | 
|  | 389 | // a bare-boards type image, change the triple for llvm's benefit. | 
|  | 390 | if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple && | 
|  | 391 | fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 392 | { | 
| Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 393 | if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm || | 
|  | 394 | fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 || | 
|  | 395 | fixed_arch.GetTriple().getArch() == llvm::Triple::thumb) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 396 | { | 
| Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 397 | fixed_arch.GetTriple().setOS(llvm::Triple::IOS); | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 398 | } | 
| Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 399 | else | 
|  | 400 | { | 
|  | 401 | fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX); | 
|  | 402 | } | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | if (module) | 
|  | 406 | { | 
|  | 407 | std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext); | 
|  | 408 | if (ast_sp) | 
|  | 409 | { | 
|  | 410 | ast_sp->SetArchitecture (fixed_arch); | 
|  | 411 | } | 
|  | 412 | return ast_sp; | 
|  | 413 | } | 
| Sean Callanan | a3444ff | 2015-11-10 22:54:42 +0000 | [diff] [blame] | 414 | else if (target && target->IsValid()) | 
| Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 415 | { | 
|  | 416 | std::shared_ptr<ClangASTContextForExpressions> ast_sp(new ClangASTContextForExpressions(*target)); | 
|  | 417 | if (ast_sp) | 
|  | 418 | { | 
|  | 419 | ast_sp->SetArchitecture(fixed_arch); | 
|  | 420 | ast_sp->m_scratch_ast_source_ap.reset (new ClangASTSource(target->shared_from_this())); | 
|  | 421 | ast_sp->m_scratch_ast_source_ap->InstallASTContext(ast_sp->getASTContext()); | 
|  | 422 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(ast_sp->m_scratch_ast_source_ap->CreateProxy()); | 
|  | 423 | ast_sp->SetExternalSource(proxy_ast_source); | 
|  | 424 | return ast_sp; | 
|  | 425 | } | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 426 | } | 
|  | 427 | } | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 428 | } | 
|  | 429 | return lldb::TypeSystemSP(); | 
|  | 430 | } | 
|  | 431 |  | 
| Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame] | 432 | void | 
|  | 433 | ClangASTContext::EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions) | 
|  | 434 | { | 
|  | 435 | static std::vector<lldb::LanguageType> s_supported_languages_for_types({ | 
|  | 436 | lldb::eLanguageTypeC89, | 
|  | 437 | lldb::eLanguageTypeC, | 
|  | 438 | lldb::eLanguageTypeC11, | 
|  | 439 | lldb::eLanguageTypeC_plus_plus, | 
|  | 440 | lldb::eLanguageTypeC99, | 
|  | 441 | lldb::eLanguageTypeObjC, | 
|  | 442 | lldb::eLanguageTypeObjC_plus_plus, | 
|  | 443 | lldb::eLanguageTypeC_plus_plus_03, | 
|  | 444 | lldb::eLanguageTypeC_plus_plus_11, | 
|  | 445 | lldb::eLanguageTypeC11, | 
|  | 446 | lldb::eLanguageTypeC_plus_plus_14}); | 
|  | 447 |  | 
|  | 448 | static std::vector<lldb::LanguageType> s_supported_languages_for_expressions({ | 
|  | 449 | lldb::eLanguageTypeC_plus_plus, | 
|  | 450 | lldb::eLanguageTypeObjC_plus_plus, | 
|  | 451 | lldb::eLanguageTypeC_plus_plus_03, | 
|  | 452 | lldb::eLanguageTypeC_plus_plus_11, | 
|  | 453 | lldb::eLanguageTypeC_plus_plus_14}); | 
|  | 454 |  | 
|  | 455 | languages_for_types.insert(s_supported_languages_for_types.begin(), s_supported_languages_for_types.end()); | 
|  | 456 | languages_for_expressions.insert(s_supported_languages_for_expressions.begin(), s_supported_languages_for_expressions.end()); | 
|  | 457 | } | 
|  | 458 |  | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 459 |  | 
|  | 460 | void | 
|  | 461 | ClangASTContext::Initialize() | 
|  | 462 | { | 
|  | 463 | PluginManager::RegisterPlugin (GetPluginNameStatic(), | 
|  | 464 | "clang base AST context plug-in", | 
| Sean Callanan | fe38c85 | 2015-10-08 23:07:53 +0000 | [diff] [blame] | 465 | CreateInstance, | 
|  | 466 | EnumerateSupportedLanguages); | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 467 | } | 
|  | 468 |  | 
|  | 469 | void | 
|  | 470 | ClangASTContext::Terminate() | 
|  | 471 | { | 
|  | 472 | PluginManager::UnregisterPlugin (CreateInstance); | 
|  | 473 | } | 
|  | 474 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 475 |  | 
|  | 476 | void | 
|  | 477 | ClangASTContext::Clear() | 
|  | 478 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 479 | m_ast_ap.reset(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 480 | m_language_options_ap.reset(); | 
|  | 481 | m_source_manager_ap.reset(); | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 482 | m_diagnostics_engine_ap.reset(); | 
| Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 483 | m_target_options_rp.reset(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 484 | m_target_info_ap.reset(); | 
|  | 485 | m_identifier_table_ap.reset(); | 
|  | 486 | m_selector_table_ap.reset(); | 
|  | 487 | m_builtins_ap.reset(); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 488 | m_pointer_byte_size = 0; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | } | 
|  | 490 |  | 
|  | 491 | const char * | 
|  | 492 | ClangASTContext::GetTargetTriple () | 
|  | 493 | { | 
|  | 494 | return m_target_triple.c_str(); | 
|  | 495 | } | 
|  | 496 |  | 
|  | 497 | void | 
|  | 498 | ClangASTContext::SetTargetTriple (const char *target_triple) | 
|  | 499 | { | 
|  | 500 | Clear(); | 
|  | 501 | m_target_triple.assign(target_triple); | 
|  | 502 | } | 
|  | 503 |  | 
| Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 504 | void | 
|  | 505 | ClangASTContext::SetArchitecture (const ArchSpec &arch) | 
|  | 506 | { | 
| Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 507 | SetTargetTriple(arch.GetTriple().str().c_str()); | 
| Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 508 | } | 
|  | 509 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 510 | bool | 
|  | 511 | ClangASTContext::HasExternalSource () | 
|  | 512 | { | 
|  | 513 | ASTContext *ast = getASTContext(); | 
|  | 514 | if (ast) | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 515 | return ast->getExternalSource () != nullptr; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 516 | return false; | 
|  | 517 | } | 
|  | 518 |  | 
|  | 519 | void | 
| Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 520 | ClangASTContext::SetExternalSource (llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_ap) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 521 | { | 
|  | 522 | ASTContext *ast = getASTContext(); | 
|  | 523 | if (ast) | 
|  | 524 | { | 
|  | 525 | ast->setExternalSource (ast_source_ap); | 
|  | 526 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true); | 
|  | 527 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(true); | 
|  | 528 | } | 
|  | 529 | } | 
|  | 530 |  | 
|  | 531 | void | 
|  | 532 | ClangASTContext::RemoveExternalSource () | 
|  | 533 | { | 
|  | 534 | ASTContext *ast = getASTContext(); | 
|  | 535 |  | 
|  | 536 | if (ast) | 
|  | 537 | { | 
| Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 538 | llvm::IntrusiveRefCntPtr<ExternalASTSource> empty_ast_source_ap; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 539 | ast->setExternalSource (empty_ast_source_ap); | 
|  | 540 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(false); | 
|  | 541 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(false); | 
|  | 542 | } | 
|  | 543 | } | 
|  | 544 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 545 | void | 
|  | 546 | ClangASTContext::setASTContext(clang::ASTContext *ast_ctx) | 
|  | 547 | { | 
|  | 548 | if (!m_ast_owned) { | 
|  | 549 | m_ast_ap.release(); | 
|  | 550 | } | 
|  | 551 | m_ast_owned = false; | 
|  | 552 | m_ast_ap.reset(ast_ctx); | 
|  | 553 | GetASTMap().Insert(ast_ctx, this); | 
|  | 554 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 |  | 
|  | 556 | ASTContext * | 
|  | 557 | ClangASTContext::getASTContext() | 
|  | 558 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 559 | if (m_ast_ap.get() == nullptr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 560 | { | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 561 | m_ast_owned = true; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 562 | m_ast_ap.reset(new ASTContext (*getLanguageOptions(), | 
|  | 563 | *getSourceManager(), | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 564 | *getIdentifierTable(), | 
|  | 565 | *getSelectorTable(), | 
| Alp Toker | cf55e88 | 2014-05-03 15:05:45 +0000 | [diff] [blame] | 566 | *getBuiltinContext())); | 
| Sean Callanan | 6d61b63 | 2015-04-09 17:42:48 +0000 | [diff] [blame] | 567 |  | 
|  | 568 | m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false); | 
| Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 569 |  | 
|  | 570 | // This can be NULL if we don't know anything about the architecture or if the | 
|  | 571 | // target for an architecture isn't enabled in the llvm/clang that we built | 
|  | 572 | TargetInfo *target_info = getTargetInfo(); | 
|  | 573 | if (target_info) | 
|  | 574 | m_ast_ap->InitBuiltinTypes(*target_info); | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 575 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 576 | if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton) | 
|  | 577 | { | 
|  | 578 | m_ast_ap->getTranslationUnitDecl()->setHasExternalLexicalStorage(); | 
|  | 579 | //m_ast_ap->getTranslationUnitDecl()->setHasExternalVisibleStorage(); | 
|  | 580 | } | 
|  | 581 |  | 
| Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 582 | GetASTMap().Insert(m_ast_ap.get(), this); | 
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 583 |  | 
|  | 584 | llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (new ClangExternalASTSourceCallbacks (ClangASTContext::CompleteTagDecl, | 
|  | 585 | ClangASTContext::CompleteObjCInterfaceDecl, | 
|  | 586 | nullptr, | 
|  | 587 | ClangASTContext::LayoutRecordType, | 
|  | 588 | this)); | 
|  | 589 | SetExternalSource (ast_source_ap); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 590 | } | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 591 | return m_ast_ap.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 592 | } | 
|  | 593 |  | 
| Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 594 | ClangASTContext* | 
|  | 595 | ClangASTContext::GetASTContext (clang::ASTContext* ast) | 
|  | 596 | { | 
| Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 597 | ClangASTContext *clang_ast = GetASTMap().Lookup(ast); | 
| Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 598 | return clang_ast; | 
|  | 599 | } | 
|  | 600 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 601 | Builtin::Context * | 
|  | 602 | ClangASTContext::getBuiltinContext() | 
|  | 603 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 604 | if (m_builtins_ap.get() == nullptr) | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 605 | m_builtins_ap.reset (new Builtin::Context()); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 606 | return m_builtins_ap.get(); | 
|  | 607 | } | 
|  | 608 |  | 
|  | 609 | IdentifierTable * | 
|  | 610 | ClangASTContext::getIdentifierTable() | 
|  | 611 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 612 | if (m_identifier_table_ap.get() == nullptr) | 
|  | 613 | m_identifier_table_ap.reset(new IdentifierTable (*ClangASTContext::getLanguageOptions(), nullptr)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 614 | return m_identifier_table_ap.get(); | 
|  | 615 | } | 
|  | 616 |  | 
|  | 617 | LangOptions * | 
|  | 618 | ClangASTContext::getLanguageOptions() | 
|  | 619 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 620 | if (m_language_options_ap.get() == nullptr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | { | 
|  | 622 | m_language_options_ap.reset(new LangOptions()); | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 623 | ParseLangArgs(*m_language_options_ap, IK_ObjCXX, GetTargetTriple()); | 
| Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 624 | //        InitializeLangOptions(*m_language_options_ap, IK_ObjCXX); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | } | 
|  | 626 | return m_language_options_ap.get(); | 
|  | 627 | } | 
|  | 628 |  | 
|  | 629 | SelectorTable * | 
|  | 630 | ClangASTContext::getSelectorTable() | 
|  | 631 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 632 | if (m_selector_table_ap.get() == nullptr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 633 | m_selector_table_ap.reset (new SelectorTable()); | 
|  | 634 | return m_selector_table_ap.get(); | 
|  | 635 | } | 
|  | 636 |  | 
| Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 637 | clang::FileManager * | 
|  | 638 | ClangASTContext::getFileManager() | 
|  | 639 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 640 | if (m_file_manager_ap.get() == nullptr) | 
| Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 641 | { | 
|  | 642 | clang::FileSystemOptions file_system_options; | 
|  | 643 | m_file_manager_ap.reset(new clang::FileManager(file_system_options)); | 
|  | 644 | } | 
| Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 645 | return m_file_manager_ap.get(); | 
|  | 646 | } | 
|  | 647 |  | 
| Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 648 | clang::SourceManager * | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 649 | ClangASTContext::getSourceManager() | 
|  | 650 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 651 | if (m_source_manager_ap.get() == nullptr) | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 652 | m_source_manager_ap.reset(new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager())); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 653 | return m_source_manager_ap.get(); | 
|  | 654 | } | 
|  | 655 |  | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 656 | clang::DiagnosticsEngine * | 
|  | 657 | ClangASTContext::getDiagnosticsEngine() | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 658 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 659 | if (m_diagnostics_engine_ap.get() == nullptr) | 
| Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 660 | { | 
|  | 661 | llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs()); | 
| Sean Callanan | ec8f1ef | 2012-10-25 01:00:25 +0000 | [diff] [blame] | 662 | m_diagnostics_engine_ap.reset(new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions())); | 
| Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 663 | } | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 664 | return m_diagnostics_engine_ap.get(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 665 | } | 
|  | 666 |  | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 667 | clang::MangleContext * | 
|  | 668 | ClangASTContext::getMangleContext() | 
|  | 669 | { | 
|  | 670 | if (m_mangle_ctx_ap.get() == nullptr) | 
|  | 671 | m_mangle_ctx_ap.reset (getASTContext()->createMangleContext()); | 
|  | 672 | return m_mangle_ctx_ap.get(); | 
|  | 673 | } | 
|  | 674 |  | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 675 | class NullDiagnosticConsumer : public DiagnosticConsumer | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 676 | { | 
|  | 677 | public: | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 678 | NullDiagnosticConsumer () | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 679 | { | 
|  | 680 | m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); | 
|  | 681 | } | 
|  | 682 |  | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 683 | void HandleDiagnostic (DiagnosticsEngine::Level DiagLevel, const Diagnostic &info) | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 684 | { | 
|  | 685 | if (m_log) | 
|  | 686 | { | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 687 | llvm::SmallVector<char, 32> diag_str(10); | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 688 | info.FormatDiagnostic(diag_str); | 
|  | 689 | diag_str.push_back('\0'); | 
|  | 690 | m_log->Printf("Compiler diagnostic: %s\n", diag_str.data()); | 
|  | 691 | } | 
|  | 692 | } | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 693 |  | 
|  | 694 | DiagnosticConsumer *clone (DiagnosticsEngine &Diags) const | 
|  | 695 | { | 
|  | 696 | return new NullDiagnosticConsumer (); | 
|  | 697 | } | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 698 | private: | 
| Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 699 | Log * m_log; | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 700 | }; | 
|  | 701 |  | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 702 | DiagnosticConsumer * | 
|  | 703 | ClangASTContext::getDiagnosticConsumer() | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 704 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 705 | if (m_diagnostic_consumer_ap.get() == nullptr) | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 706 | m_diagnostic_consumer_ap.reset(new NullDiagnosticConsumer); | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 707 |  | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 708 | return m_diagnostic_consumer_ap.get(); | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 709 | } | 
|  | 710 |  | 
| Jason Molenda | 45938b9 | 2014-07-08 23:46:39 +0000 | [diff] [blame] | 711 | std::shared_ptr<TargetOptions> & | 
|  | 712 | ClangASTContext::getTargetOptions() { | 
| Alp Toker | edc902f | 2014-07-05 03:06:05 +0000 | [diff] [blame] | 713 | if (m_target_options_rp.get() == nullptr && !m_target_triple.empty()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | { | 
| Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 715 | m_target_options_rp = std::make_shared<TargetOptions>(); | 
| Alp Toker | edc902f | 2014-07-05 03:06:05 +0000 | [diff] [blame] | 716 | if (m_target_options_rp.get() != nullptr) | 
| Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 717 | m_target_options_rp->Triple = m_target_triple; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | } | 
| Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 719 | return m_target_options_rp; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 720 | } | 
|  | 721 |  | 
|  | 722 |  | 
|  | 723 | TargetInfo * | 
|  | 724 | ClangASTContext::getTargetInfo() | 
|  | 725 | { | 
| Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 726 | // target_triple should be something like "x86_64-apple-macosx" | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 727 | if (m_target_info_ap.get() == nullptr && !m_target_triple.empty()) | 
| Greg Clayton | 38d880a | 2012-11-16 21:35:22 +0000 | [diff] [blame] | 728 | m_target_info_ap.reset (TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(), getTargetOptions())); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 729 | return m_target_info_ap.get(); | 
|  | 730 | } | 
|  | 731 |  | 
|  | 732 | #pragma mark Basic Types | 
|  | 733 |  | 
|  | 734 | static inline bool | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 735 | QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext *ast, QualType qual_type) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 736 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 737 | uint64_t qual_type_bit_size = ast->getTypeSize(qual_type); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 738 | if (qual_type_bit_size == bit_size) | 
|  | 739 | return true; | 
|  | 740 | return false; | 
|  | 741 | } | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 742 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 743 | CompilerType | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 744 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (Encoding encoding, size_t bit_size) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 745 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 746 | return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (getASTContext(), encoding, bit_size); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 747 | } | 
|  | 748 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 749 | CompilerType | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 750 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (ASTContext *ast, Encoding encoding, uint32_t bit_size) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 751 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 752 | if (!ast) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 753 | return CompilerType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | switch (encoding) | 
|  | 755 | { | 
| Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 756 | case eEncodingInvalid: | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 757 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 758 | return CompilerType (ast, ast->VoidPtrTy); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 759 | break; | 
|  | 760 |  | 
| Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 761 | case eEncodingUint: | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 762 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 763 | return CompilerType (ast, ast->UnsignedCharTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 764 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 765 | return CompilerType (ast, ast->UnsignedShortTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 766 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 767 | return CompilerType (ast, ast->UnsignedIntTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 768 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 769 | return CompilerType (ast, ast->UnsignedLongTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 770 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 771 | return CompilerType (ast, ast->UnsignedLongLongTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 772 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 773 | return CompilerType (ast, ast->UnsignedInt128Ty); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 774 | break; | 
|  | 775 |  | 
| Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 776 | case eEncodingSint: | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 777 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 778 | return CompilerType (ast, ast->CharTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 779 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 780 | return CompilerType (ast, ast->ShortTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 781 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 782 | return CompilerType (ast, ast->IntTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 783 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 784 | return CompilerType (ast, ast->LongTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 785 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 786 | return CompilerType (ast, ast->LongLongTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 787 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 788 | return CompilerType (ast, ast->Int128Ty); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 789 | break; | 
|  | 790 |  | 
| Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 791 | case eEncodingIEEE754: | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 792 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 793 | return CompilerType (ast, ast->FloatTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 794 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 795 | return CompilerType (ast, ast->DoubleTy); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 796 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 797 | return CompilerType (ast, ast->LongDoubleTy); | 
| Greg Clayton | dee40e7 | 2015-11-03 23:23:22 +0000 | [diff] [blame] | 798 | if (QualTypeMatchesBitSize (bit_size, ast, ast->HalfTy)) | 
|  | 799 | return CompilerType (ast, ast->HalfTy); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 800 | break; | 
|  | 801 |  | 
| Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 802 | case eEncodingVector: | 
| Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 803 | // Sanity check that bit_size is a multiple of 8's. | 
|  | 804 | if (bit_size && !(bit_size & 0x7u)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 805 | return CompilerType (ast, ast->getExtVectorType (ast->UnsignedCharTy, bit_size/8)); | 
| Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 806 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 807 | } | 
|  | 808 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 809 | return CompilerType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 810 | } | 
|  | 811 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 812 |  | 
|  | 813 |  | 
|  | 814 | lldb::BasicType | 
|  | 815 | ClangASTContext::GetBasicTypeEnumeration (const ConstString &name) | 
|  | 816 | { | 
|  | 817 | if (name) | 
|  | 818 | { | 
|  | 819 | typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; | 
|  | 820 | static TypeNameToBasicTypeMap g_type_map; | 
|  | 821 | static std::once_flag g_once_flag; | 
|  | 822 | std::call_once(g_once_flag, [](){ | 
|  | 823 | // "void" | 
|  | 824 | g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); | 
|  | 825 |  | 
|  | 826 | // "char" | 
|  | 827 | g_type_map.Append(ConstString("char").GetCString(), eBasicTypeChar); | 
|  | 828 | g_type_map.Append(ConstString("signed char").GetCString(), eBasicTypeSignedChar); | 
|  | 829 | g_type_map.Append(ConstString("unsigned char").GetCString(), eBasicTypeUnsignedChar); | 
|  | 830 | g_type_map.Append(ConstString("wchar_t").GetCString(), eBasicTypeWChar); | 
|  | 831 | g_type_map.Append(ConstString("signed wchar_t").GetCString(), eBasicTypeSignedWChar); | 
|  | 832 | g_type_map.Append(ConstString("unsigned wchar_t").GetCString(), eBasicTypeUnsignedWChar); | 
|  | 833 | // "short" | 
|  | 834 | g_type_map.Append(ConstString("short").GetCString(), eBasicTypeShort); | 
|  | 835 | g_type_map.Append(ConstString("short int").GetCString(), eBasicTypeShort); | 
|  | 836 | g_type_map.Append(ConstString("unsigned short").GetCString(), eBasicTypeUnsignedShort); | 
|  | 837 | g_type_map.Append(ConstString("unsigned short int").GetCString(), eBasicTypeUnsignedShort); | 
|  | 838 |  | 
|  | 839 | // "int" | 
|  | 840 | g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); | 
|  | 841 | g_type_map.Append(ConstString("signed int").GetCString(), eBasicTypeInt); | 
|  | 842 | g_type_map.Append(ConstString("unsigned int").GetCString(), eBasicTypeUnsignedInt); | 
|  | 843 | g_type_map.Append(ConstString("unsigned").GetCString(), eBasicTypeUnsignedInt); | 
|  | 844 |  | 
|  | 845 | // "long" | 
|  | 846 | g_type_map.Append(ConstString("long").GetCString(), eBasicTypeLong); | 
|  | 847 | g_type_map.Append(ConstString("long int").GetCString(), eBasicTypeLong); | 
|  | 848 | g_type_map.Append(ConstString("unsigned long").GetCString(), eBasicTypeUnsignedLong); | 
|  | 849 | g_type_map.Append(ConstString("unsigned long int").GetCString(), eBasicTypeUnsignedLong); | 
|  | 850 |  | 
|  | 851 | // "long long" | 
|  | 852 | g_type_map.Append(ConstString("long long").GetCString(), eBasicTypeLongLong); | 
|  | 853 | g_type_map.Append(ConstString("long long int").GetCString(), eBasicTypeLongLong); | 
|  | 854 | g_type_map.Append(ConstString("unsigned long long").GetCString(), eBasicTypeUnsignedLongLong); | 
|  | 855 | g_type_map.Append(ConstString("unsigned long long int").GetCString(), eBasicTypeUnsignedLongLong); | 
|  | 856 |  | 
|  | 857 | // "int128" | 
|  | 858 | g_type_map.Append(ConstString("__int128_t").GetCString(), eBasicTypeInt128); | 
|  | 859 | g_type_map.Append(ConstString("__uint128_t").GetCString(), eBasicTypeUnsignedInt128); | 
|  | 860 |  | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 861 | // Miscellaneous | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 862 | g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); | 
|  | 863 | g_type_map.Append(ConstString("float").GetCString(), eBasicTypeFloat); | 
|  | 864 | g_type_map.Append(ConstString("double").GetCString(), eBasicTypeDouble); | 
|  | 865 | g_type_map.Append(ConstString("long double").GetCString(), eBasicTypeLongDouble); | 
|  | 866 | g_type_map.Append(ConstString("id").GetCString(), eBasicTypeObjCID); | 
|  | 867 | g_type_map.Append(ConstString("SEL").GetCString(), eBasicTypeObjCSel); | 
|  | 868 | g_type_map.Append(ConstString("nullptr").GetCString(), eBasicTypeNullPtr); | 
|  | 869 | g_type_map.Sort(); | 
|  | 870 | }); | 
|  | 871 |  | 
|  | 872 | return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); | 
|  | 873 | } | 
|  | 874 | return eBasicTypeInvalid; | 
|  | 875 | } | 
|  | 876 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 877 | CompilerType | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 878 | ClangASTContext::GetBasicType (ASTContext *ast, const ConstString &name) | 
|  | 879 | { | 
|  | 880 | if (ast) | 
|  | 881 | { | 
|  | 882 | lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration (name); | 
|  | 883 | return ClangASTContext::GetBasicType (ast, basic_type); | 
|  | 884 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 885 | return CompilerType(); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 886 | } | 
|  | 887 |  | 
|  | 888 | uint32_t | 
|  | 889 | ClangASTContext::GetPointerByteSize () | 
|  | 890 | { | 
|  | 891 | if (m_pointer_byte_size == 0) | 
| Enrico Granata | 1cd5e92 | 2015-01-28 00:07:51 +0000 | [diff] [blame] | 892 | m_pointer_byte_size = GetBasicType(lldb::eBasicTypeVoid).GetPointerType().GetByteSize(nullptr); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 893 | return m_pointer_byte_size; | 
|  | 894 | } | 
|  | 895 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 896 | CompilerType | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 897 | ClangASTContext::GetBasicType (lldb::BasicType basic_type) | 
|  | 898 | { | 
|  | 899 | return GetBasicType (getASTContext(), basic_type); | 
|  | 900 | } | 
|  | 901 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 902 | CompilerType | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 903 | ClangASTContext::GetBasicType (ASTContext *ast, lldb::BasicType basic_type) | 
|  | 904 | { | 
|  | 905 | if (ast) | 
|  | 906 | { | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 907 | lldb::opaque_compiler_type_t clang_type = nullptr; | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 908 |  | 
|  | 909 | switch (basic_type) | 
|  | 910 | { | 
|  | 911 | case eBasicTypeInvalid: | 
|  | 912 | case eBasicTypeOther: | 
|  | 913 | break; | 
|  | 914 | case eBasicTypeVoid: | 
|  | 915 | clang_type = ast->VoidTy.getAsOpaquePtr(); | 
|  | 916 | break; | 
|  | 917 | case eBasicTypeChar: | 
|  | 918 | clang_type = ast->CharTy.getAsOpaquePtr(); | 
|  | 919 | break; | 
|  | 920 | case eBasicTypeSignedChar: | 
|  | 921 | clang_type = ast->SignedCharTy.getAsOpaquePtr(); | 
|  | 922 | break; | 
|  | 923 | case eBasicTypeUnsignedChar: | 
|  | 924 | clang_type = ast->UnsignedCharTy.getAsOpaquePtr(); | 
|  | 925 | break; | 
|  | 926 | case eBasicTypeWChar: | 
|  | 927 | clang_type = ast->getWCharType().getAsOpaquePtr(); | 
|  | 928 | break; | 
|  | 929 | case eBasicTypeSignedWChar: | 
|  | 930 | clang_type = ast->getSignedWCharType().getAsOpaquePtr(); | 
|  | 931 | break; | 
|  | 932 | case eBasicTypeUnsignedWChar: | 
|  | 933 | clang_type = ast->getUnsignedWCharType().getAsOpaquePtr(); | 
|  | 934 | break; | 
|  | 935 | case eBasicTypeChar16: | 
|  | 936 | clang_type = ast->Char16Ty.getAsOpaquePtr(); | 
|  | 937 | break; | 
|  | 938 | case eBasicTypeChar32: | 
|  | 939 | clang_type = ast->Char32Ty.getAsOpaquePtr(); | 
|  | 940 | break; | 
|  | 941 | case eBasicTypeShort: | 
|  | 942 | clang_type = ast->ShortTy.getAsOpaquePtr(); | 
|  | 943 | break; | 
|  | 944 | case eBasicTypeUnsignedShort: | 
|  | 945 | clang_type = ast->UnsignedShortTy.getAsOpaquePtr(); | 
|  | 946 | break; | 
|  | 947 | case eBasicTypeInt: | 
|  | 948 | clang_type = ast->IntTy.getAsOpaquePtr(); | 
|  | 949 | break; | 
|  | 950 | case eBasicTypeUnsignedInt: | 
|  | 951 | clang_type = ast->UnsignedIntTy.getAsOpaquePtr(); | 
|  | 952 | break; | 
|  | 953 | case eBasicTypeLong: | 
|  | 954 | clang_type = ast->LongTy.getAsOpaquePtr(); | 
|  | 955 | break; | 
|  | 956 | case eBasicTypeUnsignedLong: | 
|  | 957 | clang_type = ast->UnsignedLongTy.getAsOpaquePtr(); | 
|  | 958 | break; | 
|  | 959 | case eBasicTypeLongLong: | 
|  | 960 | clang_type = ast->LongLongTy.getAsOpaquePtr(); | 
|  | 961 | break; | 
|  | 962 | case eBasicTypeUnsignedLongLong: | 
|  | 963 | clang_type = ast->UnsignedLongLongTy.getAsOpaquePtr(); | 
|  | 964 | break; | 
|  | 965 | case eBasicTypeInt128: | 
|  | 966 | clang_type = ast->Int128Ty.getAsOpaquePtr(); | 
|  | 967 | break; | 
|  | 968 | case eBasicTypeUnsignedInt128: | 
|  | 969 | clang_type = ast->UnsignedInt128Ty.getAsOpaquePtr(); | 
|  | 970 | break; | 
|  | 971 | case eBasicTypeBool: | 
|  | 972 | clang_type = ast->BoolTy.getAsOpaquePtr(); | 
|  | 973 | break; | 
|  | 974 | case eBasicTypeHalf: | 
|  | 975 | clang_type = ast->HalfTy.getAsOpaquePtr(); | 
|  | 976 | break; | 
|  | 977 | case eBasicTypeFloat: | 
|  | 978 | clang_type = ast->FloatTy.getAsOpaquePtr(); | 
|  | 979 | break; | 
|  | 980 | case eBasicTypeDouble: | 
|  | 981 | clang_type = ast->DoubleTy.getAsOpaquePtr(); | 
|  | 982 | break; | 
|  | 983 | case eBasicTypeLongDouble: | 
|  | 984 | clang_type = ast->LongDoubleTy.getAsOpaquePtr(); | 
|  | 985 | break; | 
|  | 986 | case eBasicTypeFloatComplex: | 
|  | 987 | clang_type = ast->FloatComplexTy.getAsOpaquePtr(); | 
|  | 988 | break; | 
|  | 989 | case eBasicTypeDoubleComplex: | 
|  | 990 | clang_type = ast->DoubleComplexTy.getAsOpaquePtr(); | 
|  | 991 | break; | 
|  | 992 | case eBasicTypeLongDoubleComplex: | 
|  | 993 | clang_type = ast->LongDoubleComplexTy.getAsOpaquePtr(); | 
|  | 994 | break; | 
|  | 995 | case eBasicTypeObjCID: | 
|  | 996 | clang_type = ast->getObjCIdType().getAsOpaquePtr(); | 
|  | 997 | break; | 
|  | 998 | case eBasicTypeObjCClass: | 
|  | 999 | clang_type = ast->getObjCClassType().getAsOpaquePtr(); | 
|  | 1000 | break; | 
|  | 1001 | case eBasicTypeObjCSel: | 
|  | 1002 | clang_type = ast->getObjCSelType().getAsOpaquePtr(); | 
|  | 1003 | break; | 
|  | 1004 | case eBasicTypeNullPtr: | 
|  | 1005 | clang_type = ast->NullPtrTy.getAsOpaquePtr(); | 
|  | 1006 | break; | 
|  | 1007 | } | 
|  | 1008 |  | 
|  | 1009 | if (clang_type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1010 | return CompilerType (GetASTContext(ast), clang_type); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1011 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1012 | return CompilerType(); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1013 | } | 
|  | 1014 |  | 
|  | 1015 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1016 | CompilerType | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1017 | ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name, uint32_t dw_ate, uint32_t bit_size) | 
|  | 1018 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1019 | ASTContext *ast = getASTContext(); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1020 |  | 
|  | 1021 | #define streq(a,b) strcmp(a,b) == 0 | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1022 | assert (ast != nullptr); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1023 | if (ast) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1024 | { | 
|  | 1025 | switch (dw_ate) | 
|  | 1026 | { | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1027 | default: | 
|  | 1028 | break; | 
| Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1029 |  | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1030 | case DW_ATE_address: | 
|  | 1031 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1032 | return CompilerType (ast, ast->VoidPtrTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1033 | break; | 
|  | 1034 |  | 
|  | 1035 | case DW_ATE_boolean: | 
|  | 1036 | if (QualTypeMatchesBitSize (bit_size, ast, ast->BoolTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1037 | return CompilerType (ast, ast->BoolTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1038 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1039 | return CompilerType (ast, ast->UnsignedCharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1040 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1041 | return CompilerType (ast, ast->UnsignedShortTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1042 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1043 | return CompilerType (ast, ast->UnsignedIntTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1044 | break; | 
|  | 1045 |  | 
|  | 1046 | case DW_ATE_lo_user: | 
|  | 1047 | // This has been seen to mean DW_AT_complex_integer | 
|  | 1048 | if (type_name) | 
| Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1049 | { | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1050 | if (::strstr(type_name, "complex")) | 
|  | 1051 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1052 | CompilerType complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("int", DW_ATE_signed, bit_size/2); | 
|  | 1053 | return CompilerType (ast, ast->getComplexType (GetQualType(complex_int_clang_type))); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1054 | } | 
| Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1055 | } | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1056 | break; | 
|  | 1057 |  | 
|  | 1058 | case DW_ATE_complex_float: | 
|  | 1059 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatComplexTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1060 | return CompilerType (ast, ast->FloatComplexTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1061 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleComplexTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1062 | return CompilerType (ast, ast->DoubleComplexTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1063 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleComplexTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1064 | return CompilerType (ast, ast->LongDoubleComplexTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1065 | else | 
| Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1066 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1067 | CompilerType complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("float", DW_ATE_float, bit_size/2); | 
|  | 1068 | return CompilerType (ast, ast->getComplexType (GetQualType(complex_float_clang_type))); | 
| Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 1069 | } | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1070 | break; | 
|  | 1071 |  | 
|  | 1072 | case DW_ATE_float: | 
| Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1073 | if (streq(type_name, "float") && QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1074 | return CompilerType (ast, ast->FloatTy); | 
| Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1075 | if (streq(type_name, "double") && QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1076 | return CompilerType (ast, ast->DoubleTy); | 
| Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 1077 | if (streq(type_name, "long double") && QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1078 | return CompilerType (ast, ast->LongDoubleTy); | 
| Bruce Mitchener | e171da5 | 2015-07-22 00:16:02 +0000 | [diff] [blame] | 1079 | // Fall back to not requiring a name match | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1080 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1081 | return CompilerType (ast, ast->FloatTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1082 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1083 | return CompilerType (ast, ast->DoubleTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1084 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1085 | return CompilerType (ast, ast->LongDoubleTy); | 
| Greg Clayton | dee40e7 | 2015-11-03 23:23:22 +0000 | [diff] [blame] | 1086 | if (QualTypeMatchesBitSize (bit_size, ast, ast->HalfTy)) | 
|  | 1087 | return CompilerType (ast, ast->HalfTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1088 | break; | 
|  | 1089 |  | 
|  | 1090 | case DW_ATE_signed: | 
|  | 1091 | if (type_name) | 
|  | 1092 | { | 
|  | 1093 | if (streq(type_name, "wchar_t") && | 
| Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1094 | QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy) && | 
| Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 1095 | (getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType()))) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1096 | return CompilerType (ast, ast->WCharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1097 | if (streq(type_name, "void") && | 
|  | 1098 | QualTypeMatchesBitSize (bit_size, ast, ast->VoidTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1099 | return CompilerType (ast, ast->VoidTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1100 | if (strstr(type_name, "long long") && | 
|  | 1101 | QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1102 | return CompilerType (ast, ast->LongLongTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1103 | if (strstr(type_name, "long") && | 
|  | 1104 | QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1105 | return CompilerType (ast, ast->LongTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1106 | if (strstr(type_name, "short") && | 
|  | 1107 | QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1108 | return CompilerType (ast, ast->ShortTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1109 | if (strstr(type_name, "char")) | 
|  | 1110 | { | 
|  | 1111 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1112 | return CompilerType (ast, ast->CharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1113 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1114 | return CompilerType (ast, ast->SignedCharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1115 | } | 
|  | 1116 | if (strstr(type_name, "int")) | 
|  | 1117 | { | 
|  | 1118 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1119 | return CompilerType (ast, ast->IntTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1120 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1121 | return CompilerType (ast, ast->Int128Ty); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1122 | } | 
|  | 1123 | } | 
|  | 1124 | // We weren't able to match up a type name, just search by size | 
|  | 1125 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1126 | return CompilerType (ast, ast->CharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1127 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1128 | return CompilerType (ast, ast->ShortTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1129 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1130 | return CompilerType (ast, ast->IntTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1131 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1132 | return CompilerType (ast, ast->LongTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1133 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1134 | return CompilerType (ast, ast->LongLongTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1135 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1136 | return CompilerType (ast, ast->Int128Ty); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1137 | break; | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1138 |  | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1139 | case DW_ATE_signed_char: | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1140 | if (ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char")) | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1141 | { | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1142 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1143 | return CompilerType (ast, ast->CharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1144 | } | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1145 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1146 | return CompilerType (ast, ast->SignedCharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1147 | break; | 
|  | 1148 |  | 
|  | 1149 | case DW_ATE_unsigned: | 
|  | 1150 | if (type_name) | 
|  | 1151 | { | 
| Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1152 | if (streq(type_name, "wchar_t")) | 
|  | 1153 | { | 
|  | 1154 | if (QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy)) | 
|  | 1155 | { | 
| Greg Clayton | 28eb7bf | 2015-05-07 00:07:44 +0000 | [diff] [blame] | 1156 | if (!(getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType()))) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1157 | return CompilerType (ast, ast->WCharTy); | 
| Tamas Berghammer | 3c0d005 | 2015-04-01 09:48:02 +0000 | [diff] [blame] | 1158 | } | 
|  | 1159 | } | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1160 | if (strstr(type_name, "long long")) | 
|  | 1161 | { | 
|  | 1162 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1163 | return CompilerType (ast, ast->UnsignedLongLongTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1164 | } | 
|  | 1165 | else if (strstr(type_name, "long")) | 
|  | 1166 | { | 
|  | 1167 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1168 | return CompilerType (ast, ast->UnsignedLongTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1169 | } | 
|  | 1170 | else if (strstr(type_name, "short")) | 
|  | 1171 | { | 
|  | 1172 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1173 | return CompilerType (ast, ast->UnsignedShortTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1174 | } | 
|  | 1175 | else if (strstr(type_name, "char")) | 
|  | 1176 | { | 
|  | 1177 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1178 | return CompilerType (ast, ast->UnsignedCharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1179 | } | 
|  | 1180 | else if (strstr(type_name, "int")) | 
|  | 1181 | { | 
|  | 1182 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1183 | return CompilerType (ast, ast->UnsignedIntTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1184 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1185 | return CompilerType (ast, ast->UnsignedInt128Ty); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1186 | } | 
|  | 1187 | } | 
|  | 1188 | // We weren't able to match up a type name, just search by size | 
|  | 1189 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1190 | return CompilerType (ast, ast->UnsignedCharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1191 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1192 | return CompilerType (ast, ast->UnsignedShortTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1193 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1194 | return CompilerType (ast, ast->UnsignedIntTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1195 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1196 | return CompilerType (ast, ast->UnsignedLongTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1197 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1198 | return CompilerType (ast, ast->UnsignedLongLongTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1199 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1200 | return CompilerType (ast, ast->UnsignedInt128Ty); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1201 | break; | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1202 |  | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1203 | case DW_ATE_unsigned_char: | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1204 | if (!ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char")) | 
|  | 1205 | { | 
|  | 1206 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1207 | return CompilerType (ast, ast->CharTy); | 
| Tamas Berghammer | dccbfaf | 2015-03-31 10:21:50 +0000 | [diff] [blame] | 1208 | } | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1209 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1210 | return CompilerType (ast, ast->UnsignedCharTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1211 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1212 | return CompilerType (ast, ast->UnsignedShortTy); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1213 | break; | 
|  | 1214 |  | 
|  | 1215 | case DW_ATE_imaginary_float: | 
|  | 1216 | break; | 
|  | 1217 |  | 
|  | 1218 | case DW_ATE_UTF: | 
|  | 1219 | if (type_name) | 
|  | 1220 | { | 
|  | 1221 | if (streq(type_name, "char16_t")) | 
|  | 1222 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1223 | return CompilerType (ast, ast->Char16Ty); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1224 | } | 
|  | 1225 | else if (streq(type_name, "char32_t")) | 
|  | 1226 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1227 | return CompilerType (ast, ast->Char32Ty); | 
| Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1228 | } | 
|  | 1229 | } | 
|  | 1230 | break; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1231 | } | 
|  | 1232 | } | 
|  | 1233 | // This assert should fire for anything that we don't catch above so we know | 
|  | 1234 | // to fix any issues we run into. | 
| Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 1235 | if (type_name) | 
|  | 1236 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1237 | 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] | 1238 | } | 
|  | 1239 | else | 
|  | 1240 | { | 
| Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1241 | 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] | 1242 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1243 | return CompilerType (); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1244 | } | 
|  | 1245 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1246 | CompilerType | 
| Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1247 | ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast) | 
|  | 1248 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1249 | if (ast) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1250 | return CompilerType (ast, ast->UnknownAnyTy); | 
|  | 1251 | return CompilerType(); | 
| Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1252 | } | 
|  | 1253 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1254 | CompilerType | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | ClangASTContext::GetCStringType (bool is_const) | 
|  | 1256 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1257 | ASTContext *ast = getASTContext(); | 
|  | 1258 | QualType char_type(ast->CharTy); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1259 |  | 
|  | 1260 | if (is_const) | 
|  | 1261 | char_type.addConst(); | 
|  | 1262 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1263 | return CompilerType (ast, ast->getPointerType(char_type)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1264 | } | 
|  | 1265 |  | 
| Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 1266 | clang::DeclContext * | 
|  | 1267 | ClangASTContext::GetTranslationUnitDecl (clang::ASTContext *ast) | 
|  | 1268 | { | 
|  | 1269 | return ast->getTranslationUnitDecl(); | 
|  | 1270 | } | 
|  | 1271 |  | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1272 | clang::Decl * | 
| Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1273 | ClangASTContext::CopyDecl (ASTContext *dst_ast, | 
|  | 1274 | ASTContext *src_ast, | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1275 | clang::Decl *source_decl) | 
| Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 1276 | { | 
| Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 1277 | FileSystemOptions file_system_options; | 
| Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1278 | FileManager file_manager (file_system_options); | 
|  | 1279 | ASTImporter importer(*dst_ast, file_manager, | 
| Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1280 | *src_ast, file_manager, | 
|  | 1281 | false); | 
| Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1282 |  | 
|  | 1283 | return importer.Import(source_decl); | 
|  | 1284 | } | 
|  | 1285 |  | 
| Sean Callanan | 23a3027 | 2010-07-16 00:00:27 +0000 | [diff] [blame] | 1286 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1287 | ClangASTContext::AreTypesSame (CompilerType type1, | 
|  | 1288 | CompilerType type2, | 
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1289 | bool ignore_qualifiers) | 
| Sean Callanan | 4dcca262 | 2010-07-15 22:30:52 +0000 | [diff] [blame] | 1290 | { | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 1291 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type1.GetTypeSystem()); | 
|  | 1292 | if (!ast || ast != type2.GetTypeSystem()) | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1293 | return false; | 
|  | 1294 |  | 
|  | 1295 | if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType()) | 
| Greg Clayton | 55995eb | 2012-04-06 17:38:55 +0000 | [diff] [blame] | 1296 | return true; | 
|  | 1297 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 1298 | QualType type1_qual = GetQualType(type1); | 
|  | 1299 | QualType type2_qual = GetQualType(type2); | 
| Sean Callanan | 5056ab0 | 2012-02-18 02:01:03 +0000 | [diff] [blame] | 1300 |  | 
|  | 1301 | if (ignore_qualifiers) | 
|  | 1302 | { | 
|  | 1303 | type1_qual = type1_qual.getUnqualifiedType(); | 
|  | 1304 | type2_qual = type2_qual.getUnqualifiedType(); | 
|  | 1305 | } | 
|  | 1306 |  | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 1307 | return ast->getASTContext()->hasSameType (type1_qual, type2_qual); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1308 | } | 
|  | 1309 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1310 | CompilerType | 
| Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1311 | ClangASTContext::GetTypeForDecl (clang::NamedDecl *decl) | 
|  | 1312 | { | 
|  | 1313 | if (clang::ObjCInterfaceDecl *interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) | 
|  | 1314 | return GetTypeForDecl(interface_decl); | 
|  | 1315 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) | 
|  | 1316 | return GetTypeForDecl(tag_decl); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1317 | return CompilerType(); | 
| Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1318 | } | 
|  | 1319 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1320 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1321 | CompilerType | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1322 | ClangASTContext::GetTypeForDecl (TagDecl *decl) | 
|  | 1323 | { | 
|  | 1324 | // No need to call the getASTContext() accessor (which can create the AST | 
|  | 1325 | // if it isn't created yet, because we can't have created a decl in this | 
|  | 1326 | // AST if our AST didn't already exist... | 
| Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1327 | ASTContext *ast = &decl->getASTContext(); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1328 | if (ast) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1329 | return CompilerType (ast, ast->getTagDeclType(decl)); | 
|  | 1330 | return CompilerType(); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1331 | } | 
|  | 1332 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1333 | CompilerType | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1334 | ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl) | 
|  | 1335 | { | 
|  | 1336 | // No need to call the getASTContext() accessor (which can create the AST | 
|  | 1337 | // if it isn't created yet, because we can't have created a decl in this | 
|  | 1338 | // AST if our AST didn't already exist... | 
| Sean Callanan | 9998acd | 2014-12-05 01:21:59 +0000 | [diff] [blame] | 1339 | ASTContext *ast = &decl->getASTContext(); | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1340 | if (ast) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1341 | return CompilerType (ast, ast->getObjCInterfaceType(decl)); | 
|  | 1342 | return CompilerType(); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1343 | } | 
|  | 1344 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1345 | #pragma mark Structure, Unions, Classes | 
|  | 1346 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1347 | CompilerType | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1348 | ClangASTContext::CreateRecordType (DeclContext *decl_ctx, | 
|  | 1349 | AccessType access_type, | 
|  | 1350 | const char *name, | 
|  | 1351 | int kind, | 
|  | 1352 | LanguageType language, | 
|  | 1353 | ClangASTMetadata *metadata) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1354 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1355 | ASTContext *ast = getASTContext(); | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1356 | assert (ast != nullptr); | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1357 |  | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1358 | if (decl_ctx == nullptr) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1359 | decl_ctx = ast->getTranslationUnitDecl(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1360 |  | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1361 |  | 
| Greg Clayton | e1be996 | 2011-08-24 23:50:00 +0000 | [diff] [blame] | 1362 | if (language == eLanguageTypeObjC || language == eLanguageTypeObjC_plus_plus) | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1363 | { | 
| Greg Clayton | aaf99e0 | 2010-10-11 02:25:34 +0000 | [diff] [blame] | 1364 | bool isForwardDecl = true; | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1365 | bool isInternal = false; | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1366 | return CreateObjCClass (name, decl_ctx, isForwardDecl, isInternal, metadata); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1367 | } | 
|  | 1368 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1369 | // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and | 
|  | 1370 | // we will need to update this code. I was told to currently always use | 
|  | 1371 | // the CXXRecordDecl class since we often don't know from debug information | 
|  | 1372 | // if something is struct or a class, so we default to always use the more | 
|  | 1373 | // complete definition just in case. | 
| Sean Callanan | 11e32d3 | 2014-02-18 00:31:38 +0000 | [diff] [blame] | 1374 |  | 
|  | 1375 | bool is_anonymous = (!name) || (!name[0]); | 
|  | 1376 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1377 | CXXRecordDecl *decl = CXXRecordDecl::Create (*ast, | 
|  | 1378 | (TagDecl::TagKind)kind, | 
|  | 1379 | decl_ctx, | 
|  | 1380 | SourceLocation(), | 
|  | 1381 | SourceLocation(), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1382 | is_anonymous ? nullptr : &ast->Idents.get(name)); | 
| Sean Callanan | 11e32d3 | 2014-02-18 00:31:38 +0000 | [diff] [blame] | 1383 |  | 
|  | 1384 | if (is_anonymous) | 
|  | 1385 | decl->setAnonymousStructOrUnion(true); | 
| Sean Callanan | 7282e2a | 2012-01-13 22:10:18 +0000 | [diff] [blame] | 1386 |  | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1387 | if (decl) | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1388 | { | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1389 | if (metadata) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1390 | SetMetadata(ast, decl, *metadata); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1391 |  | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1392 | if (access_type != eAccessNone) | 
|  | 1393 | decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); | 
| Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1394 |  | 
|  | 1395 | if (decl_ctx) | 
|  | 1396 | decl_ctx->addDecl (decl); | 
|  | 1397 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1398 | return CompilerType(ast, ast->getTagDeclType(decl)); | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1399 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1400 | return CompilerType(); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1401 | } | 
|  | 1402 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1403 | static TemplateParameterList * | 
|  | 1404 | CreateTemplateParameterList (ASTContext *ast, | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1405 | const ClangASTContext::TemplateParameterInfos &template_param_infos, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1406 | llvm::SmallVector<NamedDecl *, 8> &template_param_decls) | 
|  | 1407 | { | 
|  | 1408 | const bool parameter_pack = false; | 
|  | 1409 | const bool is_typename = false; | 
|  | 1410 | const unsigned depth = 0; | 
|  | 1411 | const size_t num_template_params = template_param_infos.GetSize(); | 
|  | 1412 | for (size_t i=0; i<num_template_params; ++i) | 
|  | 1413 | { | 
|  | 1414 | const char *name = template_param_infos.names[i]; | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1415 |  | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1416 | IdentifierInfo *identifier_info = nullptr; | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1417 | if (name && name[0]) | 
|  | 1418 | identifier_info = &ast->Idents.get(name); | 
| Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1419 | if (template_param_infos.args[i].getKind() == TemplateArgument::Integral) | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1420 | { | 
|  | 1421 | template_param_decls.push_back (NonTypeTemplateParmDecl::Create (*ast, | 
|  | 1422 | ast->getTranslationUnitDecl(), // Is this the right decl context?, SourceLocation StartLoc, | 
|  | 1423 | SourceLocation(), | 
|  | 1424 | SourceLocation(), | 
|  | 1425 | depth, | 
|  | 1426 | i, | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1427 | identifier_info, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1428 | template_param_infos.args[i].getIntegralType(), | 
|  | 1429 | parameter_pack, | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1430 | nullptr)); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1431 |  | 
|  | 1432 | } | 
|  | 1433 | else | 
|  | 1434 | { | 
|  | 1435 | template_param_decls.push_back (TemplateTypeParmDecl::Create (*ast, | 
|  | 1436 | ast->getTranslationUnitDecl(), // Is this the right decl context? | 
|  | 1437 | SourceLocation(), | 
|  | 1438 | SourceLocation(), | 
|  | 1439 | depth, | 
|  | 1440 | i, | 
| Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1441 | identifier_info, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1442 | is_typename, | 
|  | 1443 | parameter_pack)); | 
|  | 1444 | } | 
|  | 1445 | } | 
|  | 1446 |  | 
|  | 1447 | TemplateParameterList *template_param_list = TemplateParameterList::Create (*ast, | 
|  | 1448 | SourceLocation(), | 
|  | 1449 | SourceLocation(), | 
| David Majnemer | 48a065d | 2015-12-27 07:16:55 +0000 | [diff] [blame] | 1450 | template_param_decls, | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1451 | SourceLocation()); | 
|  | 1452 | return template_param_list; | 
|  | 1453 | } | 
|  | 1454 |  | 
|  | 1455 | clang::FunctionTemplateDecl * | 
|  | 1456 | ClangASTContext::CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx, | 
|  | 1457 | clang::FunctionDecl *func_decl, | 
|  | 1458 | const char *name, | 
|  | 1459 | const TemplateParameterInfos &template_param_infos) | 
|  | 1460 | { | 
|  | 1461 | //    /// \brief Create a function template node. | 
|  | 1462 | ASTContext *ast = getASTContext(); | 
|  | 1463 |  | 
|  | 1464 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; | 
|  | 1465 |  | 
|  | 1466 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, | 
|  | 1467 | template_param_infos, | 
|  | 1468 | template_param_decls); | 
|  | 1469 | FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create (*ast, | 
|  | 1470 | decl_ctx, | 
|  | 1471 | func_decl->getLocation(), | 
|  | 1472 | func_decl->getDeclName(), | 
|  | 1473 | template_param_list, | 
|  | 1474 | func_decl); | 
|  | 1475 |  | 
|  | 1476 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); | 
|  | 1477 | i < template_param_decl_count; | 
|  | 1478 | ++i) | 
|  | 1479 | { | 
|  | 1480 | // TODO: verify which decl context we should put template_param_decls into.. | 
|  | 1481 | template_param_decls[i]->setDeclContext (func_decl); | 
|  | 1482 | } | 
|  | 1483 |  | 
|  | 1484 | return func_tmpl_decl; | 
|  | 1485 | } | 
|  | 1486 |  | 
|  | 1487 | void | 
|  | 1488 | ClangASTContext::CreateFunctionTemplateSpecializationInfo (FunctionDecl *func_decl, | 
|  | 1489 | clang::FunctionTemplateDecl *func_tmpl_decl, | 
|  | 1490 | const TemplateParameterInfos &infos) | 
|  | 1491 | { | 
|  | 1492 | TemplateArgumentList template_args (TemplateArgumentList::OnStack, | 
|  | 1493 | infos.args.data(), | 
|  | 1494 | infos.args.size()); | 
|  | 1495 |  | 
|  | 1496 | func_decl->setFunctionTemplateSpecialization (func_tmpl_decl, | 
|  | 1497 | &template_args, | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1498 | nullptr); | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1499 | } | 
|  | 1500 |  | 
|  | 1501 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1502 | ClassTemplateDecl * | 
|  | 1503 | ClangASTContext::CreateClassTemplateDecl (DeclContext *decl_ctx, | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1504 | lldb::AccessType access_type, | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1505 | const char *class_name, | 
|  | 1506 | int kind, | 
|  | 1507 | const TemplateParameterInfos &template_param_infos) | 
|  | 1508 | { | 
|  | 1509 | ASTContext *ast = getASTContext(); | 
|  | 1510 |  | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1511 | ClassTemplateDecl *class_template_decl = nullptr; | 
|  | 1512 | if (decl_ctx == nullptr) | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1513 | decl_ctx = ast->getTranslationUnitDecl(); | 
|  | 1514 |  | 
|  | 1515 | IdentifierInfo &identifier_info = ast->Idents.get(class_name); | 
|  | 1516 | DeclarationName decl_name (&identifier_info); | 
|  | 1517 |  | 
|  | 1518 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); | 
| Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1519 |  | 
|  | 1520 | for (NamedDecl *decl : result) | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1521 | { | 
| Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1522 | class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1523 | if (class_template_decl) | 
|  | 1524 | return class_template_decl; | 
|  | 1525 | } | 
|  | 1526 |  | 
|  | 1527 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1528 |  | 
| Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1529 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, | 
|  | 1530 | template_param_infos, | 
|  | 1531 | template_param_decls); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1532 |  | 
|  | 1533 | CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create (*ast, | 
|  | 1534 | (TagDecl::TagKind)kind, | 
|  | 1535 | decl_ctx,  // What decl context do we use here? TU? The actual decl context? | 
|  | 1536 | SourceLocation(), | 
|  | 1537 | SourceLocation(), | 
|  | 1538 | &identifier_info); | 
| Greg Clayton | e04741d | 2011-12-02 02:09:28 +0000 | [diff] [blame] | 1539 |  | 
|  | 1540 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); | 
|  | 1541 | i < template_param_decl_count; | 
|  | 1542 | ++i) | 
|  | 1543 | { | 
|  | 1544 | template_param_decls[i]->setDeclContext (template_cxx_decl); | 
|  | 1545 | } | 
|  | 1546 |  | 
| Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1547 | // With templated classes, we say that a class is templated with | 
|  | 1548 | // specializations, but that the bare class has no functions. | 
| Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame] | 1549 | //template_cxx_decl->startDefinition(); | 
|  | 1550 | //template_cxx_decl->completeDefinition(); | 
| Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1551 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1552 | class_template_decl = ClassTemplateDecl::Create (*ast, | 
|  | 1553 | decl_ctx,  // What decl context do we use here? TU? The actual decl context? | 
|  | 1554 | SourceLocation(), | 
|  | 1555 | decl_name, | 
|  | 1556 | template_param_list, | 
|  | 1557 | template_cxx_decl, | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1558 | nullptr); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1559 |  | 
|  | 1560 | if (class_template_decl) | 
| Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1561 | { | 
| Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1562 | if (access_type != eAccessNone) | 
|  | 1563 | class_template_decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1564 |  | 
|  | 1565 | //if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx)) | 
|  | 1566 | //    CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl)); | 
|  | 1567 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1568 | decl_ctx->addDecl (class_template_decl); | 
| Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1569 |  | 
|  | 1570 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 1571 | VerifyDecl(class_template_decl); | 
|  | 1572 | #endif | 
|  | 1573 | } | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1574 |  | 
|  | 1575 | return class_template_decl; | 
|  | 1576 | } | 
|  | 1577 |  | 
|  | 1578 |  | 
|  | 1579 | ClassTemplateSpecializationDecl * | 
|  | 1580 | ClangASTContext::CreateClassTemplateSpecializationDecl (DeclContext *decl_ctx, | 
|  | 1581 | ClassTemplateDecl *class_template_decl, | 
|  | 1582 | int kind, | 
|  | 1583 | const TemplateParameterInfos &template_param_infos) | 
|  | 1584 | { | 
|  | 1585 | ASTContext *ast = getASTContext(); | 
|  | 1586 | ClassTemplateSpecializationDecl *class_template_specialization_decl = ClassTemplateSpecializationDecl::Create (*ast, | 
|  | 1587 | (TagDecl::TagKind)kind, | 
|  | 1588 | decl_ctx, | 
|  | 1589 | SourceLocation(), | 
|  | 1590 | SourceLocation(), | 
|  | 1591 | class_template_decl, | 
|  | 1592 | &template_param_infos.args.front(), | 
|  | 1593 | template_param_infos.args.size(), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1594 | nullptr); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1595 |  | 
| Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame] | 1596 | class_template_specialization_decl->setSpecializationKind(TSK_ExplicitSpecialization); | 
|  | 1597 |  | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1598 | return class_template_specialization_decl; | 
|  | 1599 | } | 
|  | 1600 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1601 | CompilerType | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1602 | ClangASTContext::CreateClassTemplateSpecializationType (ClassTemplateSpecializationDecl *class_template_specialization_decl) | 
|  | 1603 | { | 
|  | 1604 | if (class_template_specialization_decl) | 
|  | 1605 | { | 
|  | 1606 | ASTContext *ast = getASTContext(); | 
|  | 1607 | if (ast) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1608 | return CompilerType(ast, ast->getTagDeclType(class_template_specialization_decl)); | 
| Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1609 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1610 | return CompilerType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1611 | } | 
|  | 1612 |  | 
| Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1613 | static inline bool | 
| Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1614 | 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] | 1615 | { | 
| Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1616 | // Special-case call since it can take any number of operands | 
|  | 1617 | if(op_kind == OO_Call) | 
|  | 1618 | return true; | 
|  | 1619 |  | 
| Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1620 | // The parameter count doesn't include "this" | 
| Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1621 | if (num_params == 0) | 
|  | 1622 | return unary; | 
|  | 1623 | if (num_params == 1) | 
|  | 1624 | return binary; | 
| Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1625 | else | 
| Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1626 | return false; | 
|  | 1627 | } | 
| Daniel Dunbar | dacdfb5 | 2011-10-31 22:50:57 +0000 | [diff] [blame] | 1628 |  | 
| Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1629 | bool | 
|  | 1630 | ClangASTContext::CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, uint32_t num_params) | 
|  | 1631 | { | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1632 | switch (op_kind) | 
|  | 1633 | { | 
|  | 1634 | default: | 
|  | 1635 | break; | 
|  | 1636 | // C++ standard allows any number of arguments to new/delete | 
|  | 1637 | case OO_New: | 
|  | 1638 | case OO_Array_New: | 
|  | 1639 | case OO_Delete: | 
|  | 1640 | case OO_Array_Delete: | 
|  | 1641 | return true; | 
|  | 1642 | } | 
|  | 1643 |  | 
| Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1644 | #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] | 1645 | switch (op_kind) | 
|  | 1646 | { | 
|  | 1647 | #include "clang/Basic/OperatorKinds.def" | 
|  | 1648 | default: break; | 
|  | 1649 | } | 
|  | 1650 | return false; | 
|  | 1651 | } | 
|  | 1652 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1653 | clang::AccessSpecifier | 
|  | 1654 | ClangASTContext::UnifyAccessSpecifiers (clang::AccessSpecifier lhs, clang::AccessSpecifier rhs) | 
| Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 1655 | { | 
|  | 1656 | clang::AccessSpecifier ret = lhs; | 
|  | 1657 |  | 
|  | 1658 | // Make the access equal to the stricter of the field and the nested field's access | 
|  | 1659 | switch (ret) | 
|  | 1660 | { | 
|  | 1661 | case clang::AS_none: | 
|  | 1662 | break; | 
|  | 1663 | case clang::AS_private: | 
|  | 1664 | break; | 
|  | 1665 | case clang::AS_protected: | 
|  | 1666 | if (rhs == AS_private) | 
|  | 1667 | ret = AS_private; | 
|  | 1668 | break; | 
|  | 1669 | case clang::AS_public: | 
|  | 1670 | ret = rhs; | 
|  | 1671 | break; | 
|  | 1672 | } | 
|  | 1673 |  | 
|  | 1674 | return ret; | 
|  | 1675 | } | 
|  | 1676 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1677 | bool | 
|  | 1678 | ClangASTContext::FieldIsBitfield (FieldDecl* field, uint32_t& bitfield_bit_size) | 
|  | 1679 | { | 
|  | 1680 | return FieldIsBitfield(getASTContext(), field, bitfield_bit_size); | 
|  | 1681 | } | 
|  | 1682 |  | 
|  | 1683 | bool | 
|  | 1684 | ClangASTContext::FieldIsBitfield | 
|  | 1685 | ( | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1686 | ASTContext *ast, | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1687 | FieldDecl* field, | 
|  | 1688 | uint32_t& bitfield_bit_size | 
|  | 1689 | ) | 
|  | 1690 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1691 | if (ast == nullptr || field == nullptr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1692 | return false; | 
|  | 1693 |  | 
|  | 1694 | if (field->isBitField()) | 
|  | 1695 | { | 
|  | 1696 | Expr* bit_width_expr = field->getBitWidth(); | 
|  | 1697 | if (bit_width_expr) | 
|  | 1698 | { | 
|  | 1699 | llvm::APSInt bit_width_apsint; | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1700 | if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast)) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1701 | { | 
|  | 1702 | bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX); | 
|  | 1703 | return true; | 
|  | 1704 | } | 
|  | 1705 | } | 
|  | 1706 | } | 
|  | 1707 | return false; | 
|  | 1708 | } | 
|  | 1709 |  | 
|  | 1710 | bool | 
|  | 1711 | ClangASTContext::RecordHasFields (const RecordDecl *record_decl) | 
|  | 1712 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1713 | if (record_decl == nullptr) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1714 | return false; | 
|  | 1715 |  | 
|  | 1716 | if (!record_decl->field_empty()) | 
|  | 1717 | return true; | 
|  | 1718 |  | 
|  | 1719 | // No fields, lets check this is a CXX record and check the base classes | 
|  | 1720 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); | 
|  | 1721 | if (cxx_record_decl) | 
|  | 1722 | { | 
|  | 1723 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 1724 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); | 
|  | 1725 | base_class != base_class_end; | 
|  | 1726 | ++base_class) | 
|  | 1727 | { | 
|  | 1728 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); | 
|  | 1729 | if (RecordHasFields(base_class_decl)) | 
|  | 1730 | return true; | 
|  | 1731 | } | 
|  | 1732 | } | 
|  | 1733 | return false; | 
|  | 1734 | } | 
|  | 1735 |  | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1736 | #pragma mark Objective C Classes | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1737 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1738 | CompilerType | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1739 | ClangASTContext::CreateObjCClass | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1740 | ( | 
|  | 1741 | const char *name, | 
|  | 1742 | DeclContext *decl_ctx, | 
|  | 1743 | bool isForwardDecl, | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1744 | bool isInternal, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1745 | ClangASTMetadata *metadata | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1746 | ) | 
|  | 1747 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1748 | ASTContext *ast = getASTContext(); | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1749 | assert (ast != nullptr); | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1750 | assert (name && name[0]); | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1751 | if (decl_ctx == nullptr) | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1752 | decl_ctx = ast->getTranslationUnitDecl(); | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1753 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1754 | ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create (*ast, | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1755 | decl_ctx, | 
|  | 1756 | SourceLocation(), | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1757 | &ast->Idents.get(name), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1758 | nullptr, | 
| Pavel Labath | 67add94 | 2015-07-07 10:11:16 +0000 | [diff] [blame] | 1759 | nullptr, | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1760 | SourceLocation(), | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1761 | /*isForwardDecl,*/ | 
| Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1762 | isInternal); | 
| Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1763 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1764 | if (decl && metadata) | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1765 | SetMetadata(ast, decl, *metadata); | 
| Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1766 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1767 | return CompilerType (ast, ast->getObjCInterfaceType(decl)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1768 | } | 
|  | 1769 |  | 
|  | 1770 | static inline bool | 
|  | 1771 | BaseSpecifierIsEmpty (const CXXBaseSpecifier *b) | 
|  | 1772 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1773 | return ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()) == false; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1774 | } | 
|  | 1775 |  | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1776 | uint32_t | 
|  | 1777 | ClangASTContext::GetNumBaseClasses (const CXXRecordDecl *cxx_record_decl, bool omit_empty_base_classes) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1778 | { | 
|  | 1779 | uint32_t num_bases = 0; | 
|  | 1780 | if (cxx_record_decl) | 
|  | 1781 | { | 
|  | 1782 | if (omit_empty_base_classes) | 
|  | 1783 | { | 
|  | 1784 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 1785 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); | 
|  | 1786 | base_class != base_class_end; | 
|  | 1787 | ++base_class) | 
|  | 1788 | { | 
|  | 1789 | // Skip empty base classes | 
|  | 1790 | if (omit_empty_base_classes) | 
|  | 1791 | { | 
|  | 1792 | if (BaseSpecifierIsEmpty (base_class)) | 
|  | 1793 | continue; | 
|  | 1794 | } | 
|  | 1795 | ++num_bases; | 
|  | 1796 | } | 
|  | 1797 | } | 
|  | 1798 | else | 
|  | 1799 | num_bases = cxx_record_decl->getNumBases(); | 
|  | 1800 | } | 
|  | 1801 | return num_bases; | 
|  | 1802 | } | 
|  | 1803 |  | 
|  | 1804 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1805 | #pragma mark Namespace Declarations | 
|  | 1806 |  | 
|  | 1807 | NamespaceDecl * | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1808 | ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *decl_ctx) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1809 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1810 | NamespaceDecl *namespace_decl = nullptr; | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1811 | ASTContext *ast = getASTContext(); | 
|  | 1812 | TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl (); | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1813 | if (decl_ctx == nullptr) | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1814 | decl_ctx = translation_unit_decl; | 
|  | 1815 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1816 | if (name) | 
|  | 1817 | { | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1818 | IdentifierInfo &identifier_info = ast->Idents.get(name); | 
|  | 1819 | DeclarationName decl_name (&identifier_info); | 
|  | 1820 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); | 
| Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1821 | for (NamedDecl *decl : result) | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1822 | { | 
| Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1823 | namespace_decl = dyn_cast<clang::NamespaceDecl>(decl); | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1824 | if (namespace_decl) | 
|  | 1825 | return namespace_decl; | 
|  | 1826 | } | 
|  | 1827 |  | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1828 | namespace_decl = NamespaceDecl::Create(*ast, | 
|  | 1829 | decl_ctx, | 
|  | 1830 | false, | 
|  | 1831 | SourceLocation(), | 
|  | 1832 | SourceLocation(), | 
|  | 1833 | &identifier_info, | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1834 | nullptr); | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1835 |  | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1836 | decl_ctx->addDecl (namespace_decl); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1837 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1838 | else | 
|  | 1839 | { | 
|  | 1840 | if (decl_ctx == translation_unit_decl) | 
|  | 1841 | { | 
|  | 1842 | namespace_decl = translation_unit_decl->getAnonymousNamespace(); | 
|  | 1843 | if (namespace_decl) | 
|  | 1844 | return namespace_decl; | 
|  | 1845 |  | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1846 | namespace_decl = NamespaceDecl::Create(*ast, | 
|  | 1847 | decl_ctx, | 
|  | 1848 | false, | 
|  | 1849 | SourceLocation(), | 
|  | 1850 | SourceLocation(), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1851 | nullptr, | 
|  | 1852 | nullptr); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1853 | translation_unit_decl->setAnonymousNamespace (namespace_decl); | 
|  | 1854 | translation_unit_decl->addDecl (namespace_decl); | 
|  | 1855 | assert (namespace_decl == translation_unit_decl->getAnonymousNamespace()); | 
|  | 1856 | } | 
|  | 1857 | else | 
|  | 1858 | { | 
|  | 1859 | NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx); | 
|  | 1860 | if (parent_namespace_decl) | 
|  | 1861 | { | 
|  | 1862 | namespace_decl = parent_namespace_decl->getAnonymousNamespace(); | 
|  | 1863 | if (namespace_decl) | 
|  | 1864 | return namespace_decl; | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1865 | namespace_decl = NamespaceDecl::Create(*ast, | 
|  | 1866 | decl_ctx, | 
|  | 1867 | false, | 
|  | 1868 | SourceLocation(), | 
|  | 1869 | SourceLocation(), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1870 | nullptr, | 
|  | 1871 | nullptr); | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1872 | parent_namespace_decl->setAnonymousNamespace (namespace_decl); | 
|  | 1873 | parent_namespace_decl->addDecl (namespace_decl); | 
|  | 1874 | assert (namespace_decl == parent_namespace_decl->getAnonymousNamespace()); | 
|  | 1875 | } | 
|  | 1876 | else | 
|  | 1877 | { | 
|  | 1878 | // BAD!!! | 
|  | 1879 | } | 
|  | 1880 | } | 
| Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1881 | } | 
|  | 1882 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 1883 | VerifyDecl(namespace_decl); | 
|  | 1884 | #endif | 
| Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1885 | return namespace_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1886 | } | 
|  | 1887 |  | 
| Siva Chandra | 375882d | 2016-02-04 18:38:35 +0000 | [diff] [blame] | 1888 | NamespaceDecl * | 
|  | 1889 | ClangASTContext::GetUniqueNamespaceDeclaration (clang::ASTContext *ast, | 
|  | 1890 | const char *name, | 
|  | 1891 | clang::DeclContext *decl_ctx) | 
|  | 1892 | { | 
|  | 1893 | ClangASTContext *ast_ctx = ClangASTContext::GetASTContext(ast); | 
|  | 1894 | if (ast_ctx == nullptr) | 
|  | 1895 | return nullptr; | 
|  | 1896 |  | 
|  | 1897 | return ast_ctx->GetUniqueNamespaceDeclaration(name, decl_ctx); | 
|  | 1898 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1899 |  | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1900 | clang::BlockDecl * | 
|  | 1901 | ClangASTContext::CreateBlockDeclaration (clang::DeclContext *ctx) | 
|  | 1902 | { | 
|  | 1903 | if (ctx != nullptr) | 
|  | 1904 | { | 
|  | 1905 | clang::BlockDecl *decl = clang::BlockDecl::Create(*getASTContext(), ctx, clang::SourceLocation()); | 
|  | 1906 | ctx->addDecl(decl); | 
|  | 1907 | return decl; | 
|  | 1908 | } | 
|  | 1909 | return nullptr; | 
|  | 1910 | } | 
|  | 1911 |  | 
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1912 | clang::DeclContext * | 
|  | 1913 | FindLCABetweenDecls(clang::DeclContext *left, clang::DeclContext *right, clang::DeclContext *root) | 
|  | 1914 | { | 
|  | 1915 | if (root == nullptr) | 
|  | 1916 | return nullptr; | 
|  | 1917 |  | 
|  | 1918 | std::set<clang::DeclContext *> path_left; | 
|  | 1919 | for (clang::DeclContext *d = left; d != nullptr; d = d->getParent()) | 
|  | 1920 | path_left.insert(d); | 
|  | 1921 |  | 
|  | 1922 | for (clang::DeclContext *d = right; d != nullptr; d = d->getParent()) | 
|  | 1923 | if (path_left.find(d) != path_left.end()) | 
|  | 1924 | return d; | 
|  | 1925 |  | 
|  | 1926 | return nullptr; | 
|  | 1927 | } | 
|  | 1928 |  | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1929 | clang::UsingDirectiveDecl * | 
|  | 1930 | ClangASTContext::CreateUsingDirectiveDeclaration (clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl) | 
|  | 1931 | { | 
|  | 1932 | if (decl_ctx != nullptr && ns_decl != nullptr) | 
|  | 1933 | { | 
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1934 | clang::TranslationUnitDecl *translation_unit = (clang::TranslationUnitDecl *)GetTranslationUnitDecl(getASTContext()); | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1935 | clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(*getASTContext(), | 
|  | 1936 | decl_ctx, | 
|  | 1937 | clang::SourceLocation(), | 
|  | 1938 | clang::SourceLocation(), | 
|  | 1939 | clang::NestedNameSpecifierLoc(), | 
|  | 1940 | clang::SourceLocation(), | 
|  | 1941 | ns_decl, | 
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 1942 | FindLCABetweenDecls(decl_ctx, ns_decl, translation_unit)); | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1943 | decl_ctx->addDecl(using_decl); | 
|  | 1944 | return using_decl; | 
|  | 1945 | } | 
|  | 1946 | return nullptr; | 
|  | 1947 | } | 
|  | 1948 |  | 
|  | 1949 | clang::UsingDecl * | 
|  | 1950 | ClangASTContext::CreateUsingDeclaration (clang::DeclContext *current_decl_ctx, clang::NamedDecl *target) | 
|  | 1951 | { | 
|  | 1952 | if (current_decl_ctx != nullptr && target != nullptr) | 
|  | 1953 | { | 
|  | 1954 | clang::UsingDecl *using_decl = clang::UsingDecl::Create(*getASTContext(), | 
|  | 1955 | current_decl_ctx, | 
|  | 1956 | clang::SourceLocation(), | 
|  | 1957 | clang::NestedNameSpecifierLoc(), | 
|  | 1958 | clang::DeclarationNameInfo(), | 
|  | 1959 | false); | 
|  | 1960 | clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(*getASTContext(), | 
|  | 1961 | current_decl_ctx, | 
|  | 1962 | clang::SourceLocation(), | 
|  | 1963 | using_decl, | 
|  | 1964 | target); | 
|  | 1965 | using_decl->addShadowDecl(shadow_decl); | 
|  | 1966 | current_decl_ctx->addDecl(using_decl); | 
|  | 1967 | return using_decl; | 
|  | 1968 | } | 
|  | 1969 | return nullptr; | 
|  | 1970 | } | 
|  | 1971 |  | 
|  | 1972 | clang::VarDecl * | 
|  | 1973 | ClangASTContext::CreateVariableDeclaration (clang::DeclContext *decl_context, const char *name, clang::QualType type) | 
|  | 1974 | { | 
|  | 1975 | if (decl_context != nullptr) | 
|  | 1976 | { | 
|  | 1977 | clang::VarDecl *var_decl = clang::VarDecl::Create(*getASTContext(), | 
|  | 1978 | decl_context, | 
|  | 1979 | clang::SourceLocation(), | 
|  | 1980 | clang::SourceLocation(), | 
|  | 1981 | name && name[0] ? &getASTContext()->Idents.getOwn(name) : nullptr, | 
|  | 1982 | type, | 
|  | 1983 | nullptr, | 
|  | 1984 | clang::SC_None); | 
|  | 1985 | var_decl->setAccess(clang::AS_public); | 
|  | 1986 | decl_context->addDecl(var_decl); | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 1987 | return var_decl; | 
|  | 1988 | } | 
|  | 1989 | return nullptr; | 
|  | 1990 | } | 
|  | 1991 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1992 | #pragma mark Function Types | 
|  | 1993 |  | 
|  | 1994 | FunctionDecl * | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1995 | ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx, | 
|  | 1996 | const char *name, | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 1997 | const CompilerType &function_clang_type, | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1998 | int storage, | 
|  | 1999 | bool is_inline) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2000 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2001 | FunctionDecl *func_decl = nullptr; | 
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 2002 | ASTContext *ast = getASTContext(); | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2003 | if (decl_ctx == nullptr) | 
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 2004 | decl_ctx = ast->getTranslationUnitDecl(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2005 |  | 
| Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 2006 |  | 
|  | 2007 | const bool hasWrittenPrototype = true; | 
|  | 2008 | const bool isConstexprSpecified = false; | 
|  | 2009 |  | 
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 2010 | if (name && name[0]) | 
|  | 2011 | { | 
|  | 2012 | func_decl = FunctionDecl::Create (*ast, | 
|  | 2013 | decl_ctx, | 
|  | 2014 | SourceLocation(), | 
|  | 2015 | SourceLocation(), | 
|  | 2016 | DeclarationName (&ast->Idents.get(name)), | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2017 | GetQualType(function_clang_type), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2018 | nullptr, | 
| Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 2019 | (clang::StorageClass)storage, | 
| Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 2020 | is_inline, | 
|  | 2021 | hasWrittenPrototype, | 
|  | 2022 | isConstexprSpecified); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2023 | } | 
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 2024 | else | 
|  | 2025 | { | 
|  | 2026 | func_decl = FunctionDecl::Create (*ast, | 
|  | 2027 | decl_ctx, | 
|  | 2028 | SourceLocation(), | 
|  | 2029 | SourceLocation(), | 
|  | 2030 | DeclarationName (), | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2031 | GetQualType(function_clang_type), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2032 | nullptr, | 
| Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 2033 | (clang::StorageClass)storage, | 
| Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 2034 | is_inline, | 
|  | 2035 | hasWrittenPrototype, | 
|  | 2036 | isConstexprSpecified); | 
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 2037 | } | 
|  | 2038 | if (func_decl) | 
|  | 2039 | decl_ctx->addDecl (func_decl); | 
| Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 2040 |  | 
|  | 2041 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 2042 | VerifyDecl(func_decl); | 
|  | 2043 | #endif | 
|  | 2044 |  | 
| Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 2045 | return func_decl; | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2046 | } | 
|  | 2047 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2048 | CompilerType | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2049 | ClangASTContext::CreateFunctionType (ASTContext *ast, | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2050 | const CompilerType& result_type, | 
|  | 2051 | const CompilerType *args, | 
| Sean Callanan | c81256a | 2010-09-16 20:40:25 +0000 | [diff] [blame] | 2052 | unsigned num_args, | 
|  | 2053 | bool is_variadic, | 
|  | 2054 | unsigned type_quals) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2055 | { | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2056 | assert (ast != nullptr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2057 | std::vector<QualType> qual_type_args; | 
|  | 2058 | for (unsigned i=0; i<num_args; ++i) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2059 | qual_type_args.push_back (GetQualType(args[i])); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2060 |  | 
|  | 2061 | // TODO: Detect calling convention in DWARF? | 
| Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 2062 | FunctionProtoType::ExtProtoInfo proto_info; | 
|  | 2063 | proto_info.Variadic = is_variadic; | 
| Sylvestre Ledru | 186ca7d | 2014-08-01 12:19:15 +0000 | [diff] [blame] | 2064 | proto_info.ExceptionSpec = EST_None; | 
| Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 2065 | proto_info.TypeQuals = type_quals; | 
| Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 2066 | proto_info.RefQualifier = RQ_None; | 
| Sylvestre Ledru | 186ca7d | 2014-08-01 12:19:15 +0000 | [diff] [blame] | 2067 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2068 | return CompilerType (ast, ast->getFunctionType (GetQualType(result_type), | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2069 | qual_type_args, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2070 | proto_info)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2071 | } | 
|  | 2072 |  | 
|  | 2073 | ParmVarDecl * | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2074 | ClangASTContext::CreateParameterDeclaration (const char *name, const CompilerType ¶m_type, int storage) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2075 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2076 | ASTContext *ast = getASTContext(); | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2077 | assert (ast != nullptr); | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2078 | return ParmVarDecl::Create(*ast, | 
|  | 2079 | ast->getTranslationUnitDecl(), | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2080 | SourceLocation(), | 
| Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 2081 | SourceLocation(), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2082 | name && name[0] ? &ast->Idents.get(name) : nullptr, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2083 | GetQualType(param_type), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2084 | nullptr, | 
| Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 2085 | (clang::StorageClass)storage, | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2086 | nullptr); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2087 | } | 
|  | 2088 |  | 
|  | 2089 | void | 
|  | 2090 | ClangASTContext::SetFunctionParameters (FunctionDecl *function_decl, ParmVarDecl **params, unsigned num_params) | 
|  | 2091 | { | 
|  | 2092 | if (function_decl) | 
| Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 2093 | function_decl->setParams (ArrayRef<ParmVarDecl*>(params, num_params)); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2094 | } | 
|  | 2095 |  | 
|  | 2096 |  | 
|  | 2097 | #pragma mark Array Types | 
|  | 2098 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2099 | CompilerType | 
|  | 2100 | ClangASTContext::CreateArrayType (const CompilerType &element_type, | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2101 | size_t element_count, | 
|  | 2102 | bool is_vector) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2103 | { | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2104 | if (element_type.IsValid()) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2105 | { | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2106 | ASTContext *ast = getASTContext(); | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2107 | assert (ast != nullptr); | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2108 |  | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2109 | if (is_vector) | 
|  | 2110 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2111 | return CompilerType (ast, ast->getExtVectorType(GetQualType(element_type), element_count)); | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2112 | } | 
|  | 2113 | else | 
|  | 2114 | { | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2115 |  | 
|  | 2116 | llvm::APInt ap_element_count (64, element_count); | 
|  | 2117 | if (element_count == 0) | 
|  | 2118 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2119 | return CompilerType (ast, ast->getIncompleteArrayType (GetQualType(element_type), | 
| Ewan Crawford | d0d85d2 | 2016-01-14 12:18:09 +0000 | [diff] [blame] | 2120 | clang::ArrayType::Normal, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2121 | 0)); | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2122 | } | 
|  | 2123 | else | 
|  | 2124 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2125 | return CompilerType (ast, ast->getConstantArrayType (GetQualType(element_type), | 
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2126 | ap_element_count, | 
| Ewan Crawford | d0d85d2 | 2016-01-14 12:18:09 +0000 | [diff] [blame] | 2127 | clang::ArrayType::Normal, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2128 | 0)); | 
| Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 2129 | } | 
| Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2130 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2131 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2132 | return CompilerType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2133 | } | 
|  | 2134 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2135 | CompilerType | 
| Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2136 | ClangASTContext::GetOrCreateStructForIdentifier (const ConstString &type_name, | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2137 | const std::initializer_list< std::pair < const char *, CompilerType > >& type_fields, | 
| Enrico Granata | a449e86 | 2014-10-30 00:53:28 +0000 | [diff] [blame] | 2138 | bool packed) | 
| Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2139 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2140 | CompilerType type; | 
| Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2141 | if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid()) | 
|  | 2142 | return type; | 
|  | 2143 | 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] | 2144 | StartTagDeclarationDefinition(type); | 
| Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2145 | for (const auto& field : type_fields) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2146 | AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic, 0); | 
| Enrico Granata | a449e86 | 2014-10-30 00:53:28 +0000 | [diff] [blame] | 2147 | if (packed) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2148 | SetIsPacked(type); | 
|  | 2149 | CompleteTagDeclarationDefinition(type); | 
| Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 2150 | return type; | 
|  | 2151 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2152 |  | 
|  | 2153 | #pragma mark Enumeration Types | 
|  | 2154 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2155 | CompilerType | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2156 | ClangASTContext::CreateEnumerationType | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2157 | ( | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2158 | const char *name, | 
|  | 2159 | DeclContext *decl_ctx, | 
|  | 2160 | const Declaration &decl, | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2161 | const CompilerType &integer_clang_type | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2162 | ) | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2163 | { | 
|  | 2164 | // TODO: Do something intelligent with the Declaration object passed in | 
|  | 2165 | // like maybe filling in the SourceLocation with it... | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2166 | ASTContext *ast = getASTContext(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2167 |  | 
| Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2168 | // TODO: ask about these... | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2169 | //    const bool IsScoped = false; | 
|  | 2170 | //    const bool IsFixed = false; | 
|  | 2171 |  | 
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2172 | EnumDecl *enum_decl = EnumDecl::Create (*ast, | 
| Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 2173 | decl_ctx, | 
| Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2174 | SourceLocation(), | 
| Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 2175 | SourceLocation(), | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2176 | name && name[0] ? &ast->Idents.get(name) : nullptr, | 
|  | 2177 | nullptr, | 
| Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 2178 | false,  // IsScoped | 
|  | 2179 | false,  // IsScopedUsingClassTag | 
|  | 2180 | false); // IsFixed | 
| Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 2181 |  | 
|  | 2182 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2183 | if (enum_decl) | 
| Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 2184 | { | 
|  | 2185 | // TODO: check if we should be setting the promotion type too? | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2186 | enum_decl->setIntegerType(GetQualType(integer_clang_type)); | 
| Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 2187 |  | 
|  | 2188 | enum_decl->setAccess(AS_public); // TODO respect what's in the debug info | 
|  | 2189 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2190 | return CompilerType (ast, ast->getTagDeclType(enum_decl)); | 
| Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 2191 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2192 | return CompilerType(); | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2193 | } | 
|  | 2194 |  | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2195 | // Disable this for now since I can't seem to get a nicely formatted float | 
|  | 2196 | // out of the APFloat class without just getting the float, double or quad | 
|  | 2197 | // and then using a formatted print on it which defeats the purpose. We ideally | 
|  | 2198 | // would like to get perfect string values for any kind of float semantics | 
|  | 2199 | // so we can support remote targets. The code below also requires a patch to | 
|  | 2200 | // llvm::APInt. | 
|  | 2201 | //bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2202 | //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] | 2203 | //{ | 
|  | 2204 | //  uint32_t count = 0; | 
|  | 2205 | //  bool is_complex = false; | 
|  | 2206 | //  if (ClangASTContext::IsFloatingPointType (clang_type, count, is_complex)) | 
|  | 2207 | //  { | 
|  | 2208 | //      unsigned num_bytes_per_float = byte_size / count; | 
|  | 2209 | //      unsigned num_bits_per_float = num_bytes_per_float * 8; | 
|  | 2210 | // | 
|  | 2211 | //      float_str.clear(); | 
|  | 2212 | //      uint32_t i; | 
|  | 2213 | //      for (i=0; i<count; i++) | 
|  | 2214 | //      { | 
|  | 2215 | //          APInt ap_int(num_bits_per_float, bytes + i * num_bytes_per_float, (APInt::ByteOrder)apint_byte_order); | 
|  | 2216 | //          bool is_ieee = false; | 
|  | 2217 | //          APFloat ap_float(ap_int, is_ieee); | 
|  | 2218 | //          char s[1024]; | 
|  | 2219 | //          unsigned int hex_digits = 0; | 
|  | 2220 | //          bool upper_case = false; | 
|  | 2221 | // | 
|  | 2222 | //          if (ap_float.convertToHexString(s, hex_digits, upper_case, APFloat::rmNearestTiesToEven) > 0) | 
|  | 2223 | //          { | 
|  | 2224 | //              if (i > 0) | 
|  | 2225 | //                  float_str.append(", "); | 
|  | 2226 | //              float_str.append(s); | 
|  | 2227 | //              if (i == 1 && is_complex) | 
|  | 2228 | //                  float_str.append(1, 'i'); | 
|  | 2229 | //          } | 
|  | 2230 | //      } | 
|  | 2231 | //      return !float_str.empty(); | 
|  | 2232 | //  } | 
|  | 2233 | //  return false; | 
|  | 2234 | //} | 
|  | 2235 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2236 | CompilerType | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2237 | ClangASTContext::GetIntTypeFromBitSize (clang::ASTContext *ast, | 
|  | 2238 | size_t bit_size, bool is_signed) | 
|  | 2239 | { | 
|  | 2240 | if (ast) | 
|  | 2241 | { | 
|  | 2242 | if (is_signed) | 
|  | 2243 | { | 
|  | 2244 | if (bit_size == ast->getTypeSize(ast->SignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2245 | return CompilerType(ast, ast->SignedCharTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2246 |  | 
|  | 2247 | if (bit_size == ast->getTypeSize(ast->ShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2248 | return CompilerType(ast, ast->ShortTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2249 |  | 
|  | 2250 | if (bit_size == ast->getTypeSize(ast->IntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2251 | return CompilerType(ast, ast->IntTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2252 |  | 
|  | 2253 | if (bit_size == ast->getTypeSize(ast->LongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2254 | return CompilerType(ast, ast->LongTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2255 |  | 
|  | 2256 | if (bit_size == ast->getTypeSize(ast->LongLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2257 | return CompilerType(ast, ast->LongLongTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2258 |  | 
|  | 2259 | if (bit_size == ast->getTypeSize(ast->Int128Ty)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2260 | return CompilerType(ast, ast->Int128Ty); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2261 | } | 
|  | 2262 | else | 
|  | 2263 | { | 
|  | 2264 | if (bit_size == ast->getTypeSize(ast->UnsignedCharTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2265 | return CompilerType(ast, ast->UnsignedCharTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2266 |  | 
|  | 2267 | if (bit_size == ast->getTypeSize(ast->UnsignedShortTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2268 | return CompilerType(ast, ast->UnsignedShortTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2269 |  | 
|  | 2270 | if (bit_size == ast->getTypeSize(ast->UnsignedIntTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2271 | return CompilerType(ast, ast->UnsignedIntTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2272 |  | 
|  | 2273 | if (bit_size == ast->getTypeSize(ast->UnsignedLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2274 | return CompilerType(ast, ast->UnsignedLongTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2275 |  | 
|  | 2276 | if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2277 | return CompilerType(ast, ast->UnsignedLongLongTy); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2278 |  | 
|  | 2279 | if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty)) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2280 | return CompilerType(ast, ast->UnsignedInt128Ty); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2281 | } | 
|  | 2282 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2283 | return CompilerType(); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2284 | } | 
|  | 2285 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2286 | CompilerType | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2287 | ClangASTContext::GetPointerSizedIntType (clang::ASTContext *ast, bool is_signed) | 
|  | 2288 | { | 
|  | 2289 | if (ast) | 
|  | 2290 | return GetIntTypeFromBitSize(ast, ast->getTypeSize(ast->VoidPtrTy), is_signed); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2291 | return CompilerType(); | 
| Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 2292 | } | 
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2293 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2294 | void | 
|  | 2295 | ClangASTContext::DumpDeclContextHiearchy (clang::DeclContext *decl_ctx) | 
|  | 2296 | { | 
|  | 2297 | if (decl_ctx) | 
|  | 2298 | { | 
|  | 2299 | DumpDeclContextHiearchy (decl_ctx->getParent()); | 
|  | 2300 |  | 
|  | 2301 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx); | 
|  | 2302 | if (named_decl) | 
|  | 2303 | { | 
|  | 2304 | printf ("%20s: %s\n", decl_ctx->getDeclKindName(), named_decl->getDeclName().getAsString().c_str()); | 
|  | 2305 | } | 
|  | 2306 | else | 
|  | 2307 | { | 
|  | 2308 | printf ("%20s\n", decl_ctx->getDeclKindName()); | 
|  | 2309 | } | 
|  | 2310 | } | 
|  | 2311 | } | 
|  | 2312 |  | 
|  | 2313 | void | 
|  | 2314 | ClangASTContext::DumpDeclHiearchy (clang::Decl *decl) | 
|  | 2315 | { | 
|  | 2316 | if (decl == nullptr) | 
|  | 2317 | return; | 
|  | 2318 | DumpDeclContextHiearchy(decl->getDeclContext()); | 
|  | 2319 |  | 
|  | 2320 | clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl); | 
|  | 2321 | if (record_decl) | 
|  | 2322 | { | 
|  | 2323 | printf ("%20s: %s%s\n", decl->getDeclKindName(), record_decl->getDeclName().getAsString().c_str(), record_decl->isInjectedClassName() ? " (injected class name)" : ""); | 
|  | 2324 |  | 
|  | 2325 | } | 
|  | 2326 | else | 
|  | 2327 | { | 
|  | 2328 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl); | 
|  | 2329 | if (named_decl) | 
|  | 2330 | { | 
|  | 2331 | printf ("%20s: %s\n", decl->getDeclKindName(), named_decl->getDeclName().getAsString().c_str()); | 
|  | 2332 | } | 
|  | 2333 | else | 
|  | 2334 | { | 
|  | 2335 | printf ("%20s\n", decl->getDeclKindName()); | 
|  | 2336 | } | 
|  | 2337 | } | 
|  | 2338 | } | 
|  | 2339 |  | 
|  | 2340 | bool | 
|  | 2341 | ClangASTContext::DeclsAreEquivalent (clang::Decl *lhs_decl, clang::Decl *rhs_decl) | 
|  | 2342 | { | 
|  | 2343 | if (lhs_decl && rhs_decl) | 
|  | 2344 | { | 
|  | 2345 | //---------------------------------------------------------------------- | 
|  | 2346 | // Make sure the decl kinds match first | 
|  | 2347 | //---------------------------------------------------------------------- | 
|  | 2348 | const clang::Decl::Kind lhs_decl_kind = lhs_decl->getKind(); | 
|  | 2349 | const clang::Decl::Kind rhs_decl_kind = rhs_decl->getKind(); | 
|  | 2350 |  | 
|  | 2351 | if (lhs_decl_kind == rhs_decl_kind) | 
|  | 2352 | { | 
|  | 2353 | //------------------------------------------------------------------ | 
|  | 2354 | // Now check that the decl contexts kinds are all equivalent | 
|  | 2355 | // before we have to check any names of the decl contexts... | 
|  | 2356 | //------------------------------------------------------------------ | 
|  | 2357 | clang::DeclContext *lhs_decl_ctx = lhs_decl->getDeclContext(); | 
|  | 2358 | clang::DeclContext *rhs_decl_ctx = rhs_decl->getDeclContext(); | 
|  | 2359 | if (lhs_decl_ctx && rhs_decl_ctx) | 
|  | 2360 | { | 
|  | 2361 | while (1) | 
|  | 2362 | { | 
|  | 2363 | if (lhs_decl_ctx && rhs_decl_ctx) | 
|  | 2364 | { | 
|  | 2365 | const clang::Decl::Kind lhs_decl_ctx_kind = lhs_decl_ctx->getDeclKind(); | 
|  | 2366 | const clang::Decl::Kind rhs_decl_ctx_kind = rhs_decl_ctx->getDeclKind(); | 
|  | 2367 | if (lhs_decl_ctx_kind == rhs_decl_ctx_kind) | 
|  | 2368 | { | 
|  | 2369 | lhs_decl_ctx = lhs_decl_ctx->getParent(); | 
|  | 2370 | rhs_decl_ctx = rhs_decl_ctx->getParent(); | 
|  | 2371 |  | 
|  | 2372 | if (lhs_decl_ctx == nullptr && rhs_decl_ctx == nullptr) | 
|  | 2373 | break; | 
|  | 2374 | } | 
|  | 2375 | else | 
|  | 2376 | return false; | 
|  | 2377 | } | 
|  | 2378 | else | 
|  | 2379 | return false; | 
|  | 2380 | } | 
|  | 2381 |  | 
|  | 2382 | //-------------------------------------------------------------- | 
|  | 2383 | // Now make sure the name of the decls match | 
|  | 2384 | //-------------------------------------------------------------- | 
|  | 2385 | clang::NamedDecl *lhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(lhs_decl); | 
|  | 2386 | clang::NamedDecl *rhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(rhs_decl); | 
|  | 2387 | if (lhs_named_decl && rhs_named_decl) | 
|  | 2388 | { | 
|  | 2389 | clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName(); | 
|  | 2390 | clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName(); | 
|  | 2391 | if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) | 
|  | 2392 | { | 
|  | 2393 | if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString()) | 
|  | 2394 | return false; | 
|  | 2395 | } | 
|  | 2396 | else | 
|  | 2397 | return false; | 
|  | 2398 | } | 
|  | 2399 | else | 
|  | 2400 | return false; | 
|  | 2401 |  | 
|  | 2402 | //-------------------------------------------------------------- | 
|  | 2403 | // We know that the decl context kinds all match, so now we need | 
|  | 2404 | // to make sure the names match as well | 
|  | 2405 | //-------------------------------------------------------------- | 
|  | 2406 | lhs_decl_ctx = lhs_decl->getDeclContext(); | 
|  | 2407 | rhs_decl_ctx = rhs_decl->getDeclContext(); | 
|  | 2408 | while (1) | 
|  | 2409 | { | 
|  | 2410 | switch (lhs_decl_ctx->getDeclKind()) | 
|  | 2411 | { | 
|  | 2412 | case clang::Decl::TranslationUnit: | 
|  | 2413 | // We don't care about the translation unit names | 
|  | 2414 | return true; | 
|  | 2415 | default: | 
|  | 2416 | { | 
|  | 2417 | clang::NamedDecl *lhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(lhs_decl_ctx); | 
|  | 2418 | clang::NamedDecl *rhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(rhs_decl_ctx); | 
|  | 2419 | if (lhs_named_decl && rhs_named_decl) | 
|  | 2420 | { | 
|  | 2421 | clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName(); | 
|  | 2422 | clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName(); | 
|  | 2423 | if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind()) | 
|  | 2424 | { | 
|  | 2425 | if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString()) | 
|  | 2426 | return false; | 
|  | 2427 | } | 
|  | 2428 | else | 
|  | 2429 | return false; | 
|  | 2430 | } | 
|  | 2431 | else | 
|  | 2432 | return false; | 
|  | 2433 | } | 
|  | 2434 | break; | 
|  | 2435 |  | 
|  | 2436 | } | 
|  | 2437 | lhs_decl_ctx = lhs_decl_ctx->getParent(); | 
|  | 2438 | rhs_decl_ctx = rhs_decl_ctx->getParent(); | 
|  | 2439 | } | 
|  | 2440 | } | 
|  | 2441 | } | 
|  | 2442 | } | 
|  | 2443 | return false; | 
|  | 2444 | } | 
| Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 2445 | bool | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2446 | ClangASTContext::GetCompleteDecl (clang::ASTContext *ast, | 
|  | 2447 | clang::Decl *decl) | 
|  | 2448 | { | 
|  | 2449 | if (!decl) | 
|  | 2450 | return false; | 
|  | 2451 |  | 
|  | 2452 | ExternalASTSource *ast_source = ast->getExternalSource(); | 
|  | 2453 |  | 
|  | 2454 | if (!ast_source) | 
|  | 2455 | return false; | 
|  | 2456 |  | 
|  | 2457 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) | 
|  | 2458 | { | 
| Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2459 | if (tag_decl->isCompleteDefinition()) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2460 | return true; | 
|  | 2461 |  | 
| Tamas Berghammer | fcf334b | 2015-12-02 11:35:54 +0000 | [diff] [blame] | 2462 | if (!tag_decl->hasExternalLexicalStorage()) | 
|  | 2463 | return false; | 
|  | 2464 |  | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2465 | ast_source->CompleteType(tag_decl); | 
|  | 2466 |  | 
|  | 2467 | return !tag_decl->getTypeForDecl()->isIncompleteType(); | 
|  | 2468 | } | 
|  | 2469 | else if (clang::ObjCInterfaceDecl *objc_interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) | 
|  | 2470 | { | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2471 | if (objc_interface_decl->getDefinition()) | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2472 | return true; | 
|  | 2473 |  | 
|  | 2474 | if (!objc_interface_decl->hasExternalLexicalStorage()) | 
|  | 2475 | return false; | 
|  | 2476 |  | 
|  | 2477 | ast_source->CompleteType(objc_interface_decl); | 
|  | 2478 |  | 
| Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2479 | return !objc_interface_decl->getTypeForDecl()->isIncompleteType(); | 
| Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2480 | } | 
|  | 2481 | else | 
|  | 2482 | { | 
|  | 2483 | return false; | 
|  | 2484 | } | 
|  | 2485 | } | 
|  | 2486 |  | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2487 | void | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2488 | ClangASTContext::SetMetadataAsUserID (const void *object, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2489 | user_id_t user_id) | 
|  | 2490 | { | 
|  | 2491 | ClangASTMetadata meta_data; | 
|  | 2492 | meta_data.SetUserID (user_id); | 
|  | 2493 | SetMetadata (object, meta_data); | 
|  | 2494 | } | 
|  | 2495 |  | 
|  | 2496 | void | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2497 | ClangASTContext::SetMetadata (clang::ASTContext *ast, | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2498 | const void *object, | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2499 | ClangASTMetadata &metadata) | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2500 | { | 
|  | 2501 | ClangExternalASTSourceCommon *external_source = | 
| Sean Callanan | ceeb74e | 2014-12-06 01:03:30 +0000 | [diff] [blame] | 2502 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2503 |  | 
|  | 2504 | if (external_source) | 
|  | 2505 | external_source->SetMetadata(object, metadata); | 
|  | 2506 | } | 
|  | 2507 |  | 
| Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2508 | ClangASTMetadata * | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2509 | ClangASTContext::GetMetadata (clang::ASTContext *ast, | 
| Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2510 | const void *object) | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2511 | { | 
|  | 2512 | ClangExternalASTSourceCommon *external_source = | 
| Sean Callanan | ceeb74e | 2014-12-06 01:03:30 +0000 | [diff] [blame] | 2513 | ClangExternalASTSourceCommon::Lookup(ast->getExternalSource()); | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2514 |  | 
|  | 2515 | if (external_source && external_source->HasMetadata(object)) | 
|  | 2516 | return external_source->GetMetadata(object); | 
|  | 2517 | else | 
| Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2518 | return nullptr; | 
| Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2519 | } | 
|  | 2520 |  | 
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2521 | clang::DeclContext * | 
|  | 2522 | ClangASTContext::GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl) | 
|  | 2523 | { | 
| Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 2524 | return llvm::dyn_cast<clang::DeclContext>(cxx_method_decl); | 
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2525 | } | 
|  | 2526 |  | 
|  | 2527 | clang::DeclContext * | 
|  | 2528 | ClangASTContext::GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl) | 
|  | 2529 | { | 
| Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 2530 | return llvm::dyn_cast<clang::DeclContext>(objc_method_decl); | 
| Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2531 | } | 
|  | 2532 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2533 | bool | 
|  | 2534 | ClangASTContext::SetTagTypeKind (clang::QualType tag_qual_type, int kind) const | 
|  | 2535 | { | 
|  | 2536 | const clang::Type *clang_type = tag_qual_type.getTypePtr(); | 
|  | 2537 | if (clang_type) | 
|  | 2538 | { | 
|  | 2539 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(clang_type); | 
|  | 2540 | if (tag_type) | 
|  | 2541 | { | 
|  | 2542 | clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(tag_type->getDecl()); | 
|  | 2543 | if (tag_decl) | 
|  | 2544 | { | 
|  | 2545 | tag_decl->setTagKind ((clang::TagDecl::TagKind)kind); | 
|  | 2546 | return true; | 
|  | 2547 | } | 
|  | 2548 | } | 
|  | 2549 | } | 
|  | 2550 | return false; | 
|  | 2551 | } | 
|  | 2552 |  | 
|  | 2553 |  | 
|  | 2554 | bool | 
|  | 2555 | ClangASTContext::SetDefaultAccessForRecordFields (clang::RecordDecl* record_decl, | 
|  | 2556 | int default_accessibility, | 
|  | 2557 | int *assigned_accessibilities, | 
|  | 2558 | size_t num_assigned_accessibilities) | 
|  | 2559 | { | 
|  | 2560 | if (record_decl) | 
|  | 2561 | { | 
|  | 2562 | uint32_t field_idx; | 
|  | 2563 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 2564 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(), field_idx = 0; | 
|  | 2565 | field != field_end; | 
|  | 2566 | ++field, ++field_idx) | 
|  | 2567 | { | 
|  | 2568 | // If no accessibility was assigned, assign the correct one | 
|  | 2569 | if (field_idx < num_assigned_accessibilities && assigned_accessibilities[field_idx] == clang::AS_none) | 
|  | 2570 | field->setAccess ((clang::AccessSpecifier)default_accessibility); | 
|  | 2571 | } | 
|  | 2572 | return true; | 
|  | 2573 | } | 
|  | 2574 | return false; | 
|  | 2575 | } | 
|  | 2576 |  | 
|  | 2577 | clang::DeclContext * | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2578 | ClangASTContext::GetDeclContextForType (const CompilerType& type) | 
|  | 2579 | { | 
|  | 2580 | return GetDeclContextForType(GetQualType(type)); | 
|  | 2581 | } | 
|  | 2582 |  | 
|  | 2583 | clang::DeclContext * | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2584 | ClangASTContext::GetDeclContextForType (clang::QualType type) | 
|  | 2585 | { | 
|  | 2586 | if (type.isNull()) | 
|  | 2587 | return nullptr; | 
|  | 2588 |  | 
|  | 2589 | clang::QualType qual_type = type.getCanonicalType(); | 
|  | 2590 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 2591 | switch (type_class) | 
|  | 2592 | { | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2593 | case clang::Type::ObjCInterface:            return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())->getInterface(); | 
|  | 2594 | case clang::Type::ObjCObjectPointer:        return GetDeclContextForType (llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType()); | 
|  | 2595 | case clang::Type::Record:                   return llvm::cast<clang::RecordType>(qual_type)->getDecl(); | 
|  | 2596 | case clang::Type::Enum:                     return llvm::cast<clang::EnumType>(qual_type)->getDecl(); | 
|  | 2597 | case clang::Type::Typedef:                  return GetDeclContextForType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 2598 | case clang::Type::Auto:                     return GetDeclContextForType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2599 | case clang::Type::Elaborated:               return GetDeclContextForType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); | 
|  | 2600 | 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] | 2601 | default: | 
|  | 2602 | break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2603 | } | 
|  | 2604 | // No DeclContext in this type... | 
|  | 2605 | return nullptr; | 
|  | 2606 | } | 
|  | 2607 |  | 
|  | 2608 | static bool | 
|  | 2609 | GetCompleteQualType (clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion = true) | 
|  | 2610 | { | 
|  | 2611 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 2612 | switch (type_class) | 
|  | 2613 | { | 
|  | 2614 | case clang::Type::ConstantArray: | 
|  | 2615 | case clang::Type::IncompleteArray: | 
|  | 2616 | case clang::Type::VariableArray: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2617 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2618 | const clang::ArrayType *array_type = llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr()); | 
|  | 2619 |  | 
|  | 2620 | if (array_type) | 
|  | 2621 | return GetCompleteQualType (ast, array_type->getElementType(), allow_completion); | 
|  | 2622 | } | 
|  | 2623 | break; | 
|  | 2624 | case clang::Type::Record: | 
|  | 2625 | { | 
|  | 2626 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 2627 | if (cxx_record_decl) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2628 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2629 | if (cxx_record_decl->hasExternalLexicalStorage()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2630 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2631 | const bool is_complete = cxx_record_decl->isCompleteDefinition(); | 
|  | 2632 | const bool fields_loaded = cxx_record_decl->hasLoadedFieldsFromExternalStorage(); | 
|  | 2633 | if (is_complete && fields_loaded) | 
|  | 2634 | return true; | 
|  | 2635 |  | 
|  | 2636 | if (!allow_completion) | 
|  | 2637 | return false; | 
|  | 2638 |  | 
|  | 2639 | // Call the field_begin() accessor to for it to use the external source | 
|  | 2640 | // to load the fields... | 
|  | 2641 | clang::ExternalASTSource *external_ast_source = ast->getExternalSource(); | 
|  | 2642 | if (external_ast_source) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2643 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2644 | external_ast_source->CompleteType(cxx_record_decl); | 
|  | 2645 | if (cxx_record_decl->isCompleteDefinition()) | 
| Greg Clayton | 5dfc4a4 | 2015-12-02 00:43:32 +0000 | [diff] [blame] | 2646 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2647 | cxx_record_decl->setHasLoadedFieldsFromExternalStorage (true); | 
|  | 2648 | cxx_record_decl->field_begin(); | 
| Greg Clayton | 5dfc4a4 | 2015-12-02 00:43:32 +0000 | [diff] [blame] | 2649 | } | 
|  | 2650 | } | 
| Greg Clayton | 5dfc4a4 | 2015-12-02 00:43:32 +0000 | [diff] [blame] | 2651 | } | 
|  | 2652 | } | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2653 | const clang::TagType *tag_type = llvm::cast<clang::TagType>(qual_type.getTypePtr()); | 
|  | 2654 | return !tag_type->isIncompleteType(); | 
| Greg Clayton | 5dfc4a4 | 2015-12-02 00:43:32 +0000 | [diff] [blame] | 2655 | } | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2656 | break; | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2657 |  | 
|  | 2658 | case clang::Type::Enum: | 
|  | 2659 | { | 
|  | 2660 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); | 
|  | 2661 | if (tag_type) | 
|  | 2662 | { | 
|  | 2663 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 2664 | if (tag_decl) | 
|  | 2665 | { | 
|  | 2666 | if (tag_decl->getDefinition()) | 
|  | 2667 | return true; | 
|  | 2668 |  | 
|  | 2669 | if (!allow_completion) | 
|  | 2670 | return false; | 
|  | 2671 |  | 
|  | 2672 | if (tag_decl->hasExternalLexicalStorage()) | 
|  | 2673 | { | 
|  | 2674 | if (ast) | 
|  | 2675 | { | 
|  | 2676 | clang::ExternalASTSource *external_ast_source = ast->getExternalSource(); | 
|  | 2677 | if (external_ast_source) | 
|  | 2678 | { | 
|  | 2679 | external_ast_source->CompleteType(tag_decl); | 
|  | 2680 | return !tag_type->isIncompleteType(); | 
|  | 2681 | } | 
|  | 2682 | } | 
|  | 2683 | } | 
|  | 2684 | return false; | 
|  | 2685 | } | 
|  | 2686 | } | 
|  | 2687 |  | 
|  | 2688 | } | 
|  | 2689 | break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2690 | case clang::Type::ObjCObject: | 
|  | 2691 | case clang::Type::ObjCInterface: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2692 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2693 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); | 
|  | 2694 | if (objc_class_type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2695 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2696 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 2697 | // We currently can't complete objective C types through the newly added ASTContext | 
|  | 2698 | // because it only supports TagDecl objects right now... | 
|  | 2699 | if (class_interface_decl) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2700 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2701 | if (class_interface_decl->getDefinition()) | 
|  | 2702 | return true; | 
|  | 2703 |  | 
|  | 2704 | if (!allow_completion) | 
|  | 2705 | return false; | 
|  | 2706 |  | 
|  | 2707 | if (class_interface_decl->hasExternalLexicalStorage()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2708 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2709 | if (ast) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2710 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2711 | clang::ExternalASTSource *external_ast_source = ast->getExternalSource(); | 
|  | 2712 | if (external_ast_source) | 
|  | 2713 | { | 
|  | 2714 | external_ast_source->CompleteType (class_interface_decl); | 
|  | 2715 | return !objc_class_type->isIncompleteType(); | 
|  | 2716 | } | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2717 | } | 
|  | 2718 | } | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2719 | return false; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2720 | } | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2721 | } | 
|  | 2722 | } | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2723 | break; | 
|  | 2724 |  | 
|  | 2725 | case clang::Type::Typedef: | 
|  | 2726 | return GetCompleteQualType (ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(), allow_completion); | 
|  | 2727 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 2728 | case clang::Type::Auto: | 
|  | 2729 | return GetCompleteQualType (ast, llvm::cast<clang::AutoType>(qual_type)->getDeducedType(), allow_completion); | 
|  | 2730 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2731 | case clang::Type::Elaborated: | 
|  | 2732 | return GetCompleteQualType (ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(), allow_completion); | 
|  | 2733 |  | 
|  | 2734 | case clang::Type::Paren: | 
|  | 2735 | return GetCompleteQualType (ast, llvm::cast<clang::ParenType>(qual_type)->desugar(), allow_completion); | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 2736 |  | 
|  | 2737 | case clang::Type::Attributed: | 
|  | 2738 | return GetCompleteQualType (ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(), allow_completion); | 
|  | 2739 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2740 | default: | 
|  | 2741 | break; | 
|  | 2742 | } | 
|  | 2743 |  | 
|  | 2744 | return true; | 
|  | 2745 | } | 
|  | 2746 |  | 
|  | 2747 | static clang::ObjCIvarDecl::AccessControl | 
|  | 2748 | ConvertAccessTypeToObjCIvarAccessControl (AccessType access) | 
|  | 2749 | { | 
|  | 2750 | switch (access) | 
|  | 2751 | { | 
|  | 2752 | case eAccessNone:      return clang::ObjCIvarDecl::None; | 
|  | 2753 | case eAccessPublic:    return clang::ObjCIvarDecl::Public; | 
|  | 2754 | case eAccessPrivate:   return clang::ObjCIvarDecl::Private; | 
|  | 2755 | case eAccessProtected: return clang::ObjCIvarDecl::Protected; | 
|  | 2756 | case eAccessPackage:   return clang::ObjCIvarDecl::Package; | 
|  | 2757 | } | 
|  | 2758 | return clang::ObjCIvarDecl::None; | 
|  | 2759 | } | 
|  | 2760 |  | 
|  | 2761 |  | 
|  | 2762 | //---------------------------------------------------------------------- | 
|  | 2763 | // Tests | 
|  | 2764 | //---------------------------------------------------------------------- | 
|  | 2765 |  | 
|  | 2766 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2767 | ClangASTContext::IsAggregateType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2768 | { | 
|  | 2769 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 2770 |  | 
|  | 2771 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 2772 | switch (type_class) | 
|  | 2773 | { | 
|  | 2774 | case clang::Type::IncompleteArray: | 
|  | 2775 | case clang::Type::VariableArray: | 
|  | 2776 | case clang::Type::ConstantArray: | 
|  | 2777 | case clang::Type::ExtVector: | 
|  | 2778 | case clang::Type::Vector: | 
|  | 2779 | case clang::Type::Record: | 
|  | 2780 | case clang::Type::ObjCObject: | 
|  | 2781 | case clang::Type::ObjCInterface: | 
|  | 2782 | return true; | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 2783 | case clang::Type::Auto: | 
|  | 2784 | return IsAggregateType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2785 | case clang::Type::Elaborated: | 
|  | 2786 | return IsAggregateType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); | 
|  | 2787 | case clang::Type::Typedef: | 
|  | 2788 | return IsAggregateType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); | 
|  | 2789 | case clang::Type::Paren: | 
|  | 2790 | return IsAggregateType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); | 
|  | 2791 | default: | 
|  | 2792 | break; | 
|  | 2793 | } | 
|  | 2794 | // The clang type does have a value | 
|  | 2795 | return false; | 
|  | 2796 | } | 
|  | 2797 |  | 
|  | 2798 | bool | 
| Enrico Granata | 7123e2b | 2015-11-07 02:06:57 +0000 | [diff] [blame] | 2799 | ClangASTContext::IsAnonymousType (lldb::opaque_compiler_type_t type) | 
|  | 2800 | { | 
|  | 2801 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 2802 |  | 
|  | 2803 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 2804 | switch (type_class) | 
|  | 2805 | { | 
|  | 2806 | case clang::Type::Record: | 
|  | 2807 | { | 
|  | 2808 | if (const clang::RecordType *record_type = llvm::dyn_cast_or_null<clang::RecordType>(qual_type.getTypePtrOrNull())) | 
|  | 2809 | { | 
|  | 2810 | if (const clang::RecordDecl *record_decl = record_type->getDecl()) | 
|  | 2811 | { | 
|  | 2812 | return record_decl->isAnonymousStructOrUnion(); | 
|  | 2813 | } | 
|  | 2814 | } | 
|  | 2815 | break; | 
|  | 2816 | } | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 2817 | case clang::Type::Auto: | 
|  | 2818 | return IsAnonymousType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()); | 
| Enrico Granata | 7123e2b | 2015-11-07 02:06:57 +0000 | [diff] [blame] | 2819 | case clang::Type::Elaborated: | 
|  | 2820 | return IsAnonymousType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); | 
|  | 2821 | case clang::Type::Typedef: | 
|  | 2822 | return IsAnonymousType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); | 
|  | 2823 | case clang::Type::Paren: | 
|  | 2824 | return IsAnonymousType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); | 
|  | 2825 | default: | 
|  | 2826 | break; | 
|  | 2827 | } | 
|  | 2828 | // The clang type does have a value | 
|  | 2829 | return false; | 
|  | 2830 | } | 
|  | 2831 |  | 
|  | 2832 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2833 | ClangASTContext::IsArrayType (lldb::opaque_compiler_type_t type, | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2834 | CompilerType *element_type_ptr, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2835 | uint64_t *size, | 
|  | 2836 | bool *is_incomplete) | 
|  | 2837 | { | 
|  | 2838 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 2839 |  | 
|  | 2840 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 2841 | switch (type_class) | 
|  | 2842 | { | 
|  | 2843 | default: | 
|  | 2844 | break; | 
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2845 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2846 | case clang::Type::ConstantArray: | 
|  | 2847 | if (element_type_ptr) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2848 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2849 | if (size) | 
|  | 2850 | *size = llvm::cast<clang::ConstantArrayType>(qual_type)->getSize().getLimitedValue(ULLONG_MAX); | 
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2851 | if (is_incomplete) | 
|  | 2852 | *is_incomplete = false; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2853 | return true; | 
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2854 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2855 | case clang::Type::IncompleteArray: | 
|  | 2856 | if (element_type_ptr) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2857 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2858 | if (size) | 
|  | 2859 | *size = 0; | 
|  | 2860 | if (is_incomplete) | 
|  | 2861 | *is_incomplete = true; | 
|  | 2862 | return true; | 
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2863 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2864 | case clang::Type::VariableArray: | 
|  | 2865 | if (element_type_ptr) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2866 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::VariableArrayType>(qual_type)->getElementType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2867 | if (size) | 
|  | 2868 | *size = 0; | 
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2869 | if (is_incomplete) | 
|  | 2870 | *is_incomplete = false; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2871 | return true; | 
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2872 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2873 | case clang::Type::DependentSizedArray: | 
|  | 2874 | if (element_type_ptr) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2875 | element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::DependentSizedArrayType>(qual_type)->getElementType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2876 | if (size) | 
|  | 2877 | *size = 0; | 
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2878 | if (is_incomplete) | 
|  | 2879 | *is_incomplete = false; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2880 | return true; | 
| Tamas Berghammer | 69d0b33 | 2015-10-09 12:43:08 +0000 | [diff] [blame] | 2881 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2882 | case clang::Type::Typedef: | 
|  | 2883 | return IsArrayType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), | 
|  | 2884 | element_type_ptr, | 
|  | 2885 | size, | 
|  | 2886 | is_incomplete); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 2887 | case clang::Type::Auto: | 
|  | 2888 | return IsArrayType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), | 
|  | 2889 | element_type_ptr, | 
|  | 2890 | size, | 
|  | 2891 | is_incomplete); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2892 | case clang::Type::Elaborated: | 
|  | 2893 | return IsArrayType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), | 
|  | 2894 | element_type_ptr, | 
|  | 2895 | size, | 
|  | 2896 | is_incomplete); | 
|  | 2897 | case clang::Type::Paren: | 
|  | 2898 | return IsArrayType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), | 
|  | 2899 | element_type_ptr, | 
|  | 2900 | size, | 
|  | 2901 | is_incomplete); | 
|  | 2902 | } | 
|  | 2903 | if (element_type_ptr) | 
|  | 2904 | element_type_ptr->Clear(); | 
|  | 2905 | if (size) | 
|  | 2906 | *size = 0; | 
|  | 2907 | if (is_incomplete) | 
|  | 2908 | *is_incomplete = false; | 
| Bruce Mitchener | 778e7ab | 2015-09-16 00:00:16 +0000 | [diff] [blame] | 2909 | return false; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2910 | } | 
|  | 2911 |  | 
|  | 2912 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2913 | ClangASTContext::IsVectorType (lldb::opaque_compiler_type_t type, | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2914 | CompilerType *element_type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2915 | uint64_t *size) | 
|  | 2916 | { | 
|  | 2917 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 2918 |  | 
|  | 2919 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 2920 | switch (type_class) | 
|  | 2921 | { | 
|  | 2922 | case clang::Type::Vector: | 
|  | 2923 | { | 
|  | 2924 | const clang::VectorType *vector_type = qual_type->getAs<clang::VectorType>(); | 
|  | 2925 | if (vector_type) | 
|  | 2926 | { | 
|  | 2927 | if (size) | 
|  | 2928 | *size = vector_type->getNumElements(); | 
|  | 2929 | if (element_type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2930 | *element_type = CompilerType(getASTContext(), vector_type->getElementType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2931 | } | 
|  | 2932 | return true; | 
|  | 2933 | } | 
|  | 2934 | break; | 
|  | 2935 | case clang::Type::ExtVector: | 
|  | 2936 | { | 
|  | 2937 | const clang::ExtVectorType *ext_vector_type = qual_type->getAs<clang::ExtVectorType>(); | 
|  | 2938 | if (ext_vector_type) | 
|  | 2939 | { | 
|  | 2940 | if (size) | 
|  | 2941 | *size = ext_vector_type->getNumElements(); | 
|  | 2942 | if (element_type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2943 | *element_type = CompilerType(getASTContext(), ext_vector_type->getElementType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2944 | } | 
|  | 2945 | return true; | 
|  | 2946 | } | 
|  | 2947 | default: | 
|  | 2948 | break; | 
|  | 2949 | } | 
|  | 2950 | return false; | 
|  | 2951 | } | 
|  | 2952 |  | 
|  | 2953 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2954 | ClangASTContext::IsRuntimeGeneratedType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2955 | { | 
|  | 2956 | clang::DeclContext* decl_ctx = ClangASTContext::GetASTContext(getASTContext())->GetDeclContextForType(GetQualType(type)); | 
|  | 2957 | if (!decl_ctx) | 
|  | 2958 | return false; | 
|  | 2959 |  | 
|  | 2960 | if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx)) | 
|  | 2961 | return false; | 
|  | 2962 |  | 
|  | 2963 | clang::ObjCInterfaceDecl *result_iface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx); | 
|  | 2964 |  | 
|  | 2965 | ClangASTMetadata* ast_metadata = ClangASTContext::GetMetadata(getASTContext(), result_iface_decl); | 
|  | 2966 | if (!ast_metadata) | 
|  | 2967 | return false; | 
|  | 2968 | return (ast_metadata->GetISAPtr() != 0); | 
|  | 2969 | } | 
|  | 2970 |  | 
|  | 2971 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2972 | ClangASTContext::IsCharType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2973 | { | 
|  | 2974 | return GetQualType(type).getUnqualifiedType()->isCharType(); | 
|  | 2975 | } | 
|  | 2976 |  | 
|  | 2977 |  | 
|  | 2978 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2979 | ClangASTContext::IsCompleteType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2980 | { | 
|  | 2981 | const bool allow_completion = false; | 
|  | 2982 | return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion); | 
|  | 2983 | } | 
|  | 2984 |  | 
|  | 2985 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2986 | ClangASTContext::IsConst(lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2987 | { | 
|  | 2988 | return GetQualType(type).isConstQualified(); | 
|  | 2989 | } | 
|  | 2990 |  | 
|  | 2991 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 2992 | ClangASTContext::IsCStringType (lldb::opaque_compiler_type_t type, uint32_t &length) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2993 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2994 | CompilerType pointee_or_element_clang_type; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 2995 | length = 0; | 
|  | 2996 | Flags type_flags (GetTypeInfo (type, &pointee_or_element_clang_type)); | 
|  | 2997 |  | 
|  | 2998 | if (!pointee_or_element_clang_type.IsValid()) | 
|  | 2999 | return false; | 
|  | 3000 |  | 
|  | 3001 | if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer)) | 
|  | 3002 | { | 
|  | 3003 | if (pointee_or_element_clang_type.IsCharType()) | 
|  | 3004 | { | 
|  | 3005 | if (type_flags.Test (eTypeIsArray)) | 
|  | 3006 | { | 
|  | 3007 | // We know the size of the array and it could be a C string | 
|  | 3008 | // since it is an array of characters | 
|  | 3009 | length = llvm::cast<clang::ConstantArrayType>(GetCanonicalQualType(type).getTypePtr())->getSize().getLimitedValue(); | 
|  | 3010 | } | 
|  | 3011 | return true; | 
|  | 3012 |  | 
|  | 3013 | } | 
|  | 3014 | } | 
|  | 3015 | return false; | 
|  | 3016 | } | 
|  | 3017 |  | 
|  | 3018 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3019 | ClangASTContext::IsFunctionType (lldb::opaque_compiler_type_t type, bool *is_variadic_ptr) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3020 | { | 
|  | 3021 | if (type) | 
|  | 3022 | { | 
|  | 3023 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3024 |  | 
|  | 3025 | if (qual_type->isFunctionType()) | 
|  | 3026 | { | 
|  | 3027 | if (is_variadic_ptr) | 
|  | 3028 | { | 
|  | 3029 | const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); | 
|  | 3030 | if (function_proto_type) | 
|  | 3031 | *is_variadic_ptr = function_proto_type->isVariadic(); | 
|  | 3032 | else | 
|  | 3033 | *is_variadic_ptr = false; | 
|  | 3034 | } | 
|  | 3035 | return true; | 
|  | 3036 | } | 
|  | 3037 |  | 
|  | 3038 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3039 | switch (type_class) | 
|  | 3040 | { | 
|  | 3041 | default: | 
|  | 3042 | break; | 
|  | 3043 | case clang::Type::Typedef: | 
|  | 3044 | return IsFunctionType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), nullptr); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 3045 | case clang::Type::Auto: | 
|  | 3046 | return IsFunctionType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), nullptr); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3047 | case clang::Type::Elaborated: | 
|  | 3048 | return IsFunctionType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), nullptr); | 
|  | 3049 | case clang::Type::Paren: | 
|  | 3050 | return IsFunctionType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), nullptr); | 
|  | 3051 | case clang::Type::LValueReference: | 
|  | 3052 | case clang::Type::RValueReference: | 
|  | 3053 | { | 
|  | 3054 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); | 
|  | 3055 | if (reference_type) | 
|  | 3056 | return IsFunctionType(reference_type->getPointeeType().getAsOpaquePtr(), nullptr); | 
|  | 3057 | } | 
|  | 3058 | break; | 
|  | 3059 | } | 
|  | 3060 | } | 
|  | 3061 | return false; | 
|  | 3062 | } | 
|  | 3063 |  | 
|  | 3064 | // Used to detect "Homogeneous Floating-point Aggregates" | 
|  | 3065 | uint32_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3066 | ClangASTContext::IsHomogeneousAggregate (lldb::opaque_compiler_type_t type, CompilerType* base_type_ptr) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3067 | { | 
|  | 3068 | if (!type) | 
|  | 3069 | return 0; | 
|  | 3070 |  | 
|  | 3071 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 3072 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3073 | switch (type_class) | 
|  | 3074 | { | 
|  | 3075 | case clang::Type::Record: | 
|  | 3076 | if (GetCompleteType (type)) | 
|  | 3077 | { | 
|  | 3078 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 3079 | if (cxx_record_decl) | 
|  | 3080 | { | 
|  | 3081 | if (cxx_record_decl->getNumBases() || | 
|  | 3082 | cxx_record_decl->isDynamicClass()) | 
|  | 3083 | return 0; | 
|  | 3084 | } | 
|  | 3085 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 3086 | if (record_type) | 
|  | 3087 | { | 
|  | 3088 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 3089 | if (record_decl) | 
|  | 3090 | { | 
|  | 3091 | // We are looking for a structure that contains only floating point types | 
|  | 3092 | clang::RecordDecl::field_iterator field_pos, field_end = record_decl->field_end(); | 
|  | 3093 | uint32_t num_fields = 0; | 
|  | 3094 | bool is_hva = false; | 
|  | 3095 | bool is_hfa = false; | 
|  | 3096 | clang::QualType base_qual_type; | 
|  | 3097 | for (field_pos = record_decl->field_begin(); field_pos != field_end; ++field_pos) | 
|  | 3098 | { | 
|  | 3099 | clang::QualType field_qual_type = field_pos->getType(); | 
|  | 3100 | if (field_qual_type->isFloatingType()) | 
|  | 3101 | { | 
|  | 3102 | if (field_qual_type->isComplexType()) | 
|  | 3103 | return 0; | 
|  | 3104 | else | 
|  | 3105 | { | 
|  | 3106 | if (num_fields == 0) | 
|  | 3107 | base_qual_type = field_qual_type; | 
|  | 3108 | else | 
|  | 3109 | { | 
|  | 3110 | if (is_hva) | 
|  | 3111 | return 0; | 
|  | 3112 | is_hfa = true; | 
|  | 3113 | if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr()) | 
|  | 3114 | return 0; | 
|  | 3115 | } | 
|  | 3116 | } | 
|  | 3117 | } | 
|  | 3118 | else if (field_qual_type->isVectorType() || field_qual_type->isExtVectorType()) | 
|  | 3119 | { | 
|  | 3120 | const clang::VectorType *array = field_qual_type.getTypePtr()->getAs<clang::VectorType>(); | 
|  | 3121 | if (array && array->getNumElements() <= 4) | 
|  | 3122 | { | 
|  | 3123 | if (num_fields == 0) | 
|  | 3124 | base_qual_type = array->getElementType(); | 
|  | 3125 | else | 
|  | 3126 | { | 
|  | 3127 | if (is_hfa) | 
|  | 3128 | return 0; | 
|  | 3129 | is_hva = true; | 
|  | 3130 | if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr()) | 
|  | 3131 | return 0; | 
|  | 3132 | } | 
|  | 3133 | } | 
|  | 3134 | else | 
|  | 3135 | return 0; | 
|  | 3136 | } | 
|  | 3137 | else | 
|  | 3138 | return 0; | 
|  | 3139 | ++num_fields; | 
|  | 3140 | } | 
|  | 3141 | if (base_type_ptr) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3142 | *base_type_ptr = CompilerType (getASTContext(), base_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3143 | return num_fields; | 
|  | 3144 | } | 
|  | 3145 | } | 
|  | 3146 | } | 
|  | 3147 | break; | 
|  | 3148 |  | 
|  | 3149 | case clang::Type::Typedef: | 
|  | 3150 | return IsHomogeneousAggregate(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), base_type_ptr); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 3151 |  | 
|  | 3152 | case clang::Type::Auto: | 
|  | 3153 | return IsHomogeneousAggregate(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), base_type_ptr); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3154 |  | 
|  | 3155 | case clang::Type::Elaborated: | 
|  | 3156 | return IsHomogeneousAggregate(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), base_type_ptr); | 
|  | 3157 | default: | 
|  | 3158 | break; | 
|  | 3159 | } | 
|  | 3160 | return 0; | 
|  | 3161 | } | 
|  | 3162 |  | 
|  | 3163 | size_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3164 | ClangASTContext::GetNumberOfFunctionArguments (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3165 | { | 
|  | 3166 | if (type) | 
|  | 3167 | { | 
|  | 3168 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3169 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); | 
|  | 3170 | if (func) | 
|  | 3171 | return func->getNumParams(); | 
|  | 3172 | } | 
|  | 3173 | return 0; | 
|  | 3174 | } | 
|  | 3175 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3176 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3177 | ClangASTContext::GetFunctionArgumentAtIndex (lldb::opaque_compiler_type_t type, const size_t index) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3178 | { | 
|  | 3179 | if (type) | 
|  | 3180 | { | 
|  | 3181 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3182 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); | 
|  | 3183 | if (func) | 
|  | 3184 | { | 
|  | 3185 | if (index < func->getNumParams()) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3186 | return CompilerType(getASTContext(), func->getParamType(index)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3187 | } | 
|  | 3188 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3189 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3190 | } | 
|  | 3191 |  | 
|  | 3192 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3193 | ClangASTContext::IsFunctionPointerType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3194 | { | 
|  | 3195 | if (type) | 
|  | 3196 | { | 
|  | 3197 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3198 |  | 
|  | 3199 | if (qual_type->isFunctionPointerType()) | 
|  | 3200 | return true; | 
|  | 3201 |  | 
|  | 3202 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3203 | switch (type_class) | 
|  | 3204 | { | 
|  | 3205 | default: | 
|  | 3206 | break; | 
|  | 3207 | case clang::Type::Typedef: | 
|  | 3208 | return IsFunctionPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 3209 | case clang::Type::Auto: | 
|  | 3210 | return IsFunctionPointerType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3211 | case clang::Type::Elaborated: | 
|  | 3212 | return IsFunctionPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); | 
|  | 3213 | case clang::Type::Paren: | 
|  | 3214 | return IsFunctionPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); | 
|  | 3215 |  | 
|  | 3216 | case clang::Type::LValueReference: | 
|  | 3217 | case clang::Type::RValueReference: | 
|  | 3218 | { | 
|  | 3219 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); | 
|  | 3220 | if (reference_type) | 
|  | 3221 | return IsFunctionPointerType(reference_type->getPointeeType().getAsOpaquePtr()); | 
|  | 3222 | } | 
|  | 3223 | break; | 
|  | 3224 | } | 
|  | 3225 | } | 
|  | 3226 | return false; | 
|  | 3227 |  | 
|  | 3228 | } | 
|  | 3229 |  | 
|  | 3230 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3231 | ClangASTContext::IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_signed) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3232 | { | 
|  | 3233 | if (!type) | 
|  | 3234 | return false; | 
|  | 3235 |  | 
|  | 3236 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3237 | const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()); | 
|  | 3238 |  | 
|  | 3239 | if (builtin_type) | 
|  | 3240 | { | 
|  | 3241 | if (builtin_type->isInteger()) | 
|  | 3242 | { | 
|  | 3243 | is_signed = builtin_type->isSignedInteger(); | 
|  | 3244 | return true; | 
|  | 3245 | } | 
|  | 3246 | } | 
|  | 3247 |  | 
|  | 3248 | return false; | 
|  | 3249 | } | 
|  | 3250 |  | 
|  | 3251 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3252 | ClangASTContext::IsPointerType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3253 | { | 
|  | 3254 | if (type) | 
|  | 3255 | { | 
|  | 3256 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3257 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3258 | switch (type_class) | 
|  | 3259 | { | 
|  | 3260 | case clang::Type::Builtin: | 
|  | 3261 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) | 
|  | 3262 | { | 
|  | 3263 | default: | 
|  | 3264 | break; | 
|  | 3265 | case clang::BuiltinType::ObjCId: | 
|  | 3266 | case clang::BuiltinType::ObjCClass: | 
|  | 3267 | return true; | 
|  | 3268 | } | 
|  | 3269 | return false; | 
|  | 3270 | case clang::Type::ObjCObjectPointer: | 
|  | 3271 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3272 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3273 | return true; | 
|  | 3274 | case clang::Type::BlockPointer: | 
|  | 3275 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3276 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3277 | return true; | 
|  | 3278 | case clang::Type::Pointer: | 
|  | 3279 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3280 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3281 | return true; | 
|  | 3282 | case clang::Type::MemberPointer: | 
|  | 3283 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3284 | pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3285 | return true; | 
|  | 3286 | case clang::Type::Typedef: | 
|  | 3287 | return IsPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 3288 | case clang::Type::Auto: | 
|  | 3289 | return IsPointerType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3290 | case clang::Type::Elaborated: | 
|  | 3291 | return IsPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type); | 
|  | 3292 | case clang::Type::Paren: | 
|  | 3293 | return IsPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type); | 
|  | 3294 | default: | 
|  | 3295 | break; | 
|  | 3296 | } | 
|  | 3297 | } | 
|  | 3298 | if (pointee_type) | 
|  | 3299 | pointee_type->Clear(); | 
|  | 3300 | return false; | 
|  | 3301 | } | 
|  | 3302 |  | 
|  | 3303 |  | 
|  | 3304 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3305 | ClangASTContext::IsPointerOrReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3306 | { | 
|  | 3307 | if (type) | 
|  | 3308 | { | 
|  | 3309 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3310 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3311 | switch (type_class) | 
|  | 3312 | { | 
|  | 3313 | case clang::Type::Builtin: | 
|  | 3314 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) | 
|  | 3315 | { | 
|  | 3316 | default: | 
|  | 3317 | break; | 
|  | 3318 | case clang::BuiltinType::ObjCId: | 
|  | 3319 | case clang::BuiltinType::ObjCClass: | 
|  | 3320 | return true; | 
|  | 3321 | } | 
|  | 3322 | return false; | 
|  | 3323 | case clang::Type::ObjCObjectPointer: | 
|  | 3324 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3325 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3326 | return true; | 
|  | 3327 | case clang::Type::BlockPointer: | 
|  | 3328 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3329 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3330 | return true; | 
|  | 3331 | case clang::Type::Pointer: | 
|  | 3332 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3333 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3334 | return true; | 
|  | 3335 | case clang::Type::MemberPointer: | 
|  | 3336 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3337 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3338 | return true; | 
|  | 3339 | case clang::Type::LValueReference: | 
|  | 3340 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3341 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3342 | return true; | 
|  | 3343 | case clang::Type::RValueReference: | 
|  | 3344 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3345 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3346 | return true; | 
|  | 3347 | case clang::Type::Typedef: | 
|  | 3348 | return IsPointerOrReferenceType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 3349 | case clang::Type::Auto: | 
|  | 3350 | return IsPointerOrReferenceType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3351 | case clang::Type::Elaborated: | 
|  | 3352 | return IsPointerOrReferenceType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type); | 
|  | 3353 | case clang::Type::Paren: | 
|  | 3354 | return IsPointerOrReferenceType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type); | 
|  | 3355 | default: | 
|  | 3356 | break; | 
|  | 3357 | } | 
|  | 3358 | } | 
|  | 3359 | if (pointee_type) | 
|  | 3360 | pointee_type->Clear(); | 
|  | 3361 | return false; | 
|  | 3362 | } | 
|  | 3363 |  | 
|  | 3364 |  | 
|  | 3365 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3366 | ClangASTContext::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] | 3367 | { | 
|  | 3368 | if (type) | 
|  | 3369 | { | 
|  | 3370 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3371 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3372 |  | 
|  | 3373 | switch (type_class) | 
|  | 3374 | { | 
|  | 3375 | case clang::Type::LValueReference: | 
|  | 3376 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3377 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3378 | if (is_rvalue) | 
|  | 3379 | *is_rvalue = false; | 
|  | 3380 | return true; | 
|  | 3381 | case clang::Type::RValueReference: | 
|  | 3382 | if (pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3383 | pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3384 | if (is_rvalue) | 
|  | 3385 | *is_rvalue = true; | 
|  | 3386 | return true; | 
|  | 3387 | case clang::Type::Typedef: | 
|  | 3388 | return IsReferenceType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type, is_rvalue); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 3389 | case clang::Type::Auto: | 
|  | 3390 | return IsReferenceType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type, is_rvalue); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3391 | case clang::Type::Elaborated: | 
|  | 3392 | return IsReferenceType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type, is_rvalue); | 
|  | 3393 | case clang::Type::Paren: | 
|  | 3394 | return IsReferenceType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type, is_rvalue); | 
|  | 3395 |  | 
|  | 3396 | default: | 
|  | 3397 | break; | 
|  | 3398 | } | 
|  | 3399 | } | 
|  | 3400 | if (pointee_type) | 
|  | 3401 | pointee_type->Clear(); | 
|  | 3402 | return false; | 
|  | 3403 | } | 
|  | 3404 |  | 
|  | 3405 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3406 | 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] | 3407 | { | 
|  | 3408 | if (type) | 
|  | 3409 | { | 
|  | 3410 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3411 |  | 
|  | 3412 | if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal())) | 
|  | 3413 | { | 
|  | 3414 | clang::BuiltinType::Kind kind = BT->getKind(); | 
|  | 3415 | if (kind >= clang::BuiltinType::Float && kind <= clang::BuiltinType::LongDouble) | 
|  | 3416 | { | 
|  | 3417 | count = 1; | 
|  | 3418 | is_complex = false; | 
|  | 3419 | return true; | 
|  | 3420 | } | 
|  | 3421 | } | 
|  | 3422 | else if (const clang::ComplexType *CT = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal())) | 
|  | 3423 | { | 
|  | 3424 | if (IsFloatingPointType (CT->getElementType().getAsOpaquePtr(), count, is_complex)) | 
|  | 3425 | { | 
|  | 3426 | count = 2; | 
|  | 3427 | is_complex = true; | 
|  | 3428 | return true; | 
|  | 3429 | } | 
|  | 3430 | } | 
|  | 3431 | else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal())) | 
|  | 3432 | { | 
|  | 3433 | if (IsFloatingPointType (VT->getElementType().getAsOpaquePtr(), count, is_complex)) | 
|  | 3434 | { | 
|  | 3435 | count = VT->getNumElements(); | 
|  | 3436 | is_complex = false; | 
|  | 3437 | return true; | 
|  | 3438 | } | 
|  | 3439 | } | 
|  | 3440 | } | 
|  | 3441 | count = 0; | 
|  | 3442 | is_complex = false; | 
|  | 3443 | return false; | 
|  | 3444 | } | 
|  | 3445 |  | 
|  | 3446 |  | 
|  | 3447 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3448 | ClangASTContext::IsDefined(lldb::opaque_compiler_type_t type) | 
| 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(GetQualType(type)); | 
|  | 3454 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); | 
|  | 3455 | if (tag_type) | 
|  | 3456 | { | 
|  | 3457 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 3458 | if (tag_decl) | 
|  | 3459 | return tag_decl->isCompleteDefinition(); | 
|  | 3460 | return false; | 
|  | 3461 | } | 
|  | 3462 | else | 
|  | 3463 | { | 
|  | 3464 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); | 
|  | 3465 | if (objc_class_type) | 
|  | 3466 | { | 
|  | 3467 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 3468 | if (class_interface_decl) | 
|  | 3469 | return class_interface_decl->getDefinition() != nullptr; | 
|  | 3470 | return false; | 
|  | 3471 | } | 
|  | 3472 | } | 
|  | 3473 | return true; | 
|  | 3474 | } | 
|  | 3475 |  | 
|  | 3476 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3477 | ClangASTContext::IsObjCClassType (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3478 | { | 
|  | 3479 | if (type) | 
|  | 3480 | { | 
|  | 3481 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3482 |  | 
|  | 3483 | const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); | 
|  | 3484 |  | 
|  | 3485 | if (obj_pointer_type) | 
|  | 3486 | return obj_pointer_type->isObjCClassType(); | 
|  | 3487 | } | 
|  | 3488 | return false; | 
|  | 3489 | } | 
|  | 3490 |  | 
|  | 3491 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3492 | ClangASTContext::IsObjCObjectOrInterfaceType (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3493 | { | 
| Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3494 | if (IsClangType(type)) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3495 | return GetCanonicalQualType(type)->isObjCObjectOrInterfaceType(); | 
|  | 3496 | return false; | 
|  | 3497 | } | 
|  | 3498 |  | 
|  | 3499 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3500 | ClangASTContext::IsPolymorphicClass (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3501 | { | 
|  | 3502 | if (type) | 
|  | 3503 | { | 
|  | 3504 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 3505 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3506 | switch (type_class) | 
|  | 3507 | { | 
|  | 3508 | case clang::Type::Record: | 
|  | 3509 | if (GetCompleteType(type)) | 
|  | 3510 | { | 
|  | 3511 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 3512 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 3513 | if (record_decl) | 
|  | 3514 | { | 
|  | 3515 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 3516 | if (cxx_record_decl) | 
|  | 3517 | return cxx_record_decl->isPolymorphic(); | 
|  | 3518 | } | 
|  | 3519 | } | 
|  | 3520 | break; | 
|  | 3521 |  | 
|  | 3522 | default: | 
|  | 3523 | break; | 
|  | 3524 | } | 
|  | 3525 | } | 
|  | 3526 | return false; | 
|  | 3527 | } | 
|  | 3528 |  | 
|  | 3529 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3530 | ClangASTContext::IsPossibleDynamicType (lldb::opaque_compiler_type_t type, CompilerType *dynamic_pointee_type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3531 | bool check_cplusplus, | 
|  | 3532 | bool check_objc) | 
|  | 3533 | { | 
|  | 3534 | clang::QualType pointee_qual_type; | 
|  | 3535 | if (type) | 
|  | 3536 | { | 
|  | 3537 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3538 | bool success = false; | 
|  | 3539 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3540 | switch (type_class) | 
|  | 3541 | { | 
|  | 3542 | case clang::Type::Builtin: | 
|  | 3543 | if (check_objc && llvm::cast<clang::BuiltinType>(qual_type)->getKind() == clang::BuiltinType::ObjCId) | 
|  | 3544 | { | 
|  | 3545 | if (dynamic_pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3546 | dynamic_pointee_type->SetCompilerType(this, type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3547 | return true; | 
|  | 3548 | } | 
|  | 3549 | break; | 
|  | 3550 |  | 
|  | 3551 | case clang::Type::ObjCObjectPointer: | 
|  | 3552 | if (check_objc) | 
|  | 3553 | { | 
|  | 3554 | if (dynamic_pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3555 | dynamic_pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3556 | return true; | 
|  | 3557 | } | 
|  | 3558 | break; | 
|  | 3559 |  | 
|  | 3560 | case clang::Type::Pointer: | 
|  | 3561 | pointee_qual_type = llvm::cast<clang::PointerType>(qual_type)->getPointeeType(); | 
|  | 3562 | success = true; | 
|  | 3563 | break; | 
|  | 3564 |  | 
|  | 3565 | case clang::Type::LValueReference: | 
|  | 3566 | case clang::Type::RValueReference: | 
|  | 3567 | pointee_qual_type = llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType(); | 
|  | 3568 | success = true; | 
|  | 3569 | break; | 
|  | 3570 |  | 
|  | 3571 | case clang::Type::Typedef: | 
|  | 3572 | return IsPossibleDynamicType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), | 
|  | 3573 | dynamic_pointee_type, | 
|  | 3574 | check_cplusplus, | 
|  | 3575 | check_objc); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 3576 |  | 
|  | 3577 | case clang::Type::Auto: | 
|  | 3578 | return IsPossibleDynamicType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), | 
|  | 3579 | dynamic_pointee_type, | 
|  | 3580 | check_cplusplus, | 
|  | 3581 | check_objc); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3582 |  | 
|  | 3583 | case clang::Type::Elaborated: | 
|  | 3584 | return IsPossibleDynamicType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), | 
|  | 3585 | dynamic_pointee_type, | 
|  | 3586 | check_cplusplus, | 
|  | 3587 | check_objc); | 
|  | 3588 |  | 
|  | 3589 | case clang::Type::Paren: | 
|  | 3590 | return IsPossibleDynamicType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), | 
|  | 3591 | dynamic_pointee_type, | 
|  | 3592 | check_cplusplus, | 
|  | 3593 | check_objc); | 
|  | 3594 | default: | 
|  | 3595 | break; | 
|  | 3596 | } | 
|  | 3597 |  | 
|  | 3598 | if (success) | 
|  | 3599 | { | 
|  | 3600 | // Check to make sure what we are pointing too is a possible dynamic C++ type | 
|  | 3601 | // We currently accept any "void *" (in case we have a class that has been | 
|  | 3602 | // watered down to an opaque pointer) and virtual C++ classes. | 
|  | 3603 | const clang::Type::TypeClass pointee_type_class = pointee_qual_type.getCanonicalType()->getTypeClass(); | 
|  | 3604 | switch (pointee_type_class) | 
|  | 3605 | { | 
|  | 3606 | case clang::Type::Builtin: | 
|  | 3607 | switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind()) | 
|  | 3608 | { | 
|  | 3609 | case clang::BuiltinType::UnknownAny: | 
|  | 3610 | case clang::BuiltinType::Void: | 
|  | 3611 | if (dynamic_pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3612 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3613 | return true; | 
| Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 3614 | default: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3615 | break; | 
|  | 3616 | } | 
|  | 3617 | break; | 
|  | 3618 |  | 
|  | 3619 | case clang::Type::Record: | 
|  | 3620 | if (check_cplusplus) | 
|  | 3621 | { | 
|  | 3622 | clang::CXXRecordDecl *cxx_record_decl = pointee_qual_type->getAsCXXRecordDecl(); | 
|  | 3623 | if (cxx_record_decl) | 
|  | 3624 | { | 
|  | 3625 | bool is_complete = cxx_record_decl->isCompleteDefinition(); | 
|  | 3626 |  | 
|  | 3627 | if (is_complete) | 
|  | 3628 | success = cxx_record_decl->isDynamicClass(); | 
|  | 3629 | else | 
|  | 3630 | { | 
|  | 3631 | ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), cxx_record_decl); | 
|  | 3632 | if (metadata) | 
|  | 3633 | success = metadata->GetIsDynamicCXXType(); | 
|  | 3634 | else | 
|  | 3635 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3636 | is_complete = CompilerType(getASTContext(), pointee_qual_type).GetCompleteType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3637 | if (is_complete) | 
|  | 3638 | success = cxx_record_decl->isDynamicClass(); | 
|  | 3639 | else | 
|  | 3640 | success = false; | 
|  | 3641 | } | 
|  | 3642 | } | 
|  | 3643 |  | 
|  | 3644 | if (success) | 
|  | 3645 | { | 
|  | 3646 | if (dynamic_pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3647 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3648 | return true; | 
|  | 3649 | } | 
|  | 3650 | } | 
|  | 3651 | } | 
|  | 3652 | break; | 
|  | 3653 |  | 
|  | 3654 | case clang::Type::ObjCObject: | 
|  | 3655 | case clang::Type::ObjCInterface: | 
|  | 3656 | if (check_objc) | 
|  | 3657 | { | 
|  | 3658 | if (dynamic_pointee_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3659 | dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3660 | return true; | 
|  | 3661 | } | 
|  | 3662 | break; | 
|  | 3663 |  | 
|  | 3664 | default: | 
|  | 3665 | break; | 
|  | 3666 | } | 
|  | 3667 | } | 
|  | 3668 | } | 
|  | 3669 | if (dynamic_pointee_type) | 
|  | 3670 | dynamic_pointee_type->Clear(); | 
|  | 3671 | return false; | 
|  | 3672 | } | 
|  | 3673 |  | 
|  | 3674 |  | 
|  | 3675 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3676 | ClangASTContext::IsScalarType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3677 | { | 
|  | 3678 | if (!type) | 
|  | 3679 | return false; | 
|  | 3680 |  | 
|  | 3681 | return (GetTypeInfo (type, nullptr) & eTypeIsScalar) != 0; | 
|  | 3682 | } | 
|  | 3683 |  | 
|  | 3684 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3685 | ClangASTContext::IsTypedefType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3686 | { | 
|  | 3687 | if (!type) | 
|  | 3688 | return false; | 
|  | 3689 | return GetQualType(type)->getTypeClass() == clang::Type::Typedef; | 
|  | 3690 | } | 
|  | 3691 |  | 
|  | 3692 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3693 | ClangASTContext::IsVoidType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3694 | { | 
|  | 3695 | if (!type) | 
|  | 3696 | return false; | 
|  | 3697 | return GetCanonicalQualType(type)->isVoidType(); | 
|  | 3698 | } | 
|  | 3699 |  | 
|  | 3700 | bool | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 3701 | ClangASTContext::SupportsLanguage (lldb::LanguageType language) | 
|  | 3702 | { | 
|  | 3703 | return ClangASTContextSupportsLanguage(language); | 
|  | 3704 | } | 
|  | 3705 |  | 
|  | 3706 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3707 | ClangASTContext::GetCXXClassName (const CompilerType& type, std::string &class_name) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3708 | { | 
|  | 3709 | if (type) | 
|  | 3710 | { | 
|  | 3711 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
| Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3712 | if (!qual_type.isNull()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3713 | { | 
| Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3714 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 3715 | if (cxx_record_decl) | 
|  | 3716 | { | 
|  | 3717 | class_name.assign(cxx_record_decl->getIdentifier()->getNameStart()); | 
|  | 3718 | return true; | 
|  | 3719 | } | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3720 | } | 
|  | 3721 | } | 
|  | 3722 | class_name.clear(); | 
|  | 3723 | return false; | 
|  | 3724 | } | 
|  | 3725 |  | 
|  | 3726 |  | 
|  | 3727 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3728 | ClangASTContext::IsCXXClassType (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3729 | { | 
|  | 3730 | if (!type) | 
|  | 3731 | return false; | 
|  | 3732 |  | 
|  | 3733 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
| Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3734 | if (!qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3735 | return true; | 
|  | 3736 | return false; | 
|  | 3737 | } | 
|  | 3738 |  | 
|  | 3739 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3740 | ClangASTContext::IsBeingDefined (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3741 | { | 
|  | 3742 | if (!type) | 
|  | 3743 | return false; | 
|  | 3744 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3745 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type); | 
|  | 3746 | if (tag_type) | 
|  | 3747 | return tag_type->isBeingDefined(); | 
|  | 3748 | return false; | 
|  | 3749 | } | 
|  | 3750 |  | 
|  | 3751 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3752 | ClangASTContext::IsObjCObjectPointerType (const CompilerType& type, CompilerType *class_type_ptr) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3753 | { | 
|  | 3754 | if (!type) | 
|  | 3755 | return false; | 
|  | 3756 |  | 
|  | 3757 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
| Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 3758 |  | 
|  | 3759 | if (!qual_type.isNull() && qual_type->isObjCObjectPointerType()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3760 | { | 
|  | 3761 | if (class_type_ptr) | 
|  | 3762 | { | 
|  | 3763 | if (!qual_type->isObjCClassType() && | 
|  | 3764 | !qual_type->isObjCIdType()) | 
|  | 3765 | { | 
|  | 3766 | const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type); | 
|  | 3767 | if (obj_pointer_type == nullptr) | 
|  | 3768 | class_type_ptr->Clear(); | 
|  | 3769 | else | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3770 | 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] | 3771 | } | 
|  | 3772 | } | 
|  | 3773 | return true; | 
|  | 3774 | } | 
|  | 3775 | if (class_type_ptr) | 
|  | 3776 | class_type_ptr->Clear(); | 
|  | 3777 | return false; | 
|  | 3778 | } | 
|  | 3779 |  | 
|  | 3780 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3781 | ClangASTContext::GetObjCClassName (const CompilerType& type, std::string &class_name) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3782 | { | 
|  | 3783 | if (!type) | 
|  | 3784 | return false; | 
|  | 3785 |  | 
|  | 3786 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 3787 |  | 
|  | 3788 | const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); | 
|  | 3789 | if (object_type) | 
|  | 3790 | { | 
|  | 3791 | const clang::ObjCInterfaceDecl *interface = object_type->getInterface(); | 
|  | 3792 | if (interface) | 
|  | 3793 | { | 
|  | 3794 | class_name = interface->getNameAsString(); | 
|  | 3795 | return true; | 
|  | 3796 | } | 
|  | 3797 | } | 
|  | 3798 | return false; | 
|  | 3799 | } | 
|  | 3800 |  | 
|  | 3801 |  | 
|  | 3802 | //---------------------------------------------------------------------- | 
|  | 3803 | // Type Completion | 
|  | 3804 | //---------------------------------------------------------------------- | 
|  | 3805 |  | 
|  | 3806 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3807 | ClangASTContext::GetCompleteType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3808 | { | 
|  | 3809 | if (!type) | 
|  | 3810 | return false; | 
|  | 3811 | const bool allow_completion = true; | 
|  | 3812 | return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion); | 
|  | 3813 | } | 
|  | 3814 |  | 
|  | 3815 | ConstString | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3816 | ClangASTContext::GetTypeName (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3817 | { | 
|  | 3818 | std::string type_name; | 
|  | 3819 | if (type) | 
|  | 3820 | { | 
|  | 3821 | clang::PrintingPolicy printing_policy (getASTContext()->getPrintingPolicy()); | 
|  | 3822 | clang::QualType qual_type(GetQualType(type)); | 
|  | 3823 | printing_policy.SuppressTagKeyword = true; | 
|  | 3824 | printing_policy.LangOpts.WChar = true; | 
|  | 3825 | const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>(); | 
|  | 3826 | if (typedef_type) | 
|  | 3827 | { | 
|  | 3828 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); | 
|  | 3829 | type_name = typedef_decl->getQualifiedNameAsString(); | 
|  | 3830 | } | 
|  | 3831 | else | 
|  | 3832 | { | 
|  | 3833 | type_name = qual_type.getAsString(printing_policy); | 
|  | 3834 | } | 
|  | 3835 | } | 
|  | 3836 | return ConstString(type_name); | 
|  | 3837 | } | 
|  | 3838 |  | 
|  | 3839 | uint32_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 3840 | 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] | 3841 | { | 
|  | 3842 | if (!type) | 
|  | 3843 | return 0; | 
|  | 3844 |  | 
|  | 3845 | if (pointee_or_element_clang_type) | 
|  | 3846 | pointee_or_element_clang_type->Clear(); | 
|  | 3847 |  | 
|  | 3848 | clang::QualType qual_type (GetQualType(type)); | 
|  | 3849 |  | 
|  | 3850 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 3851 | switch (type_class) | 
|  | 3852 | { | 
|  | 3853 | case clang::Type::Builtin: | 
|  | 3854 | { | 
|  | 3855 | const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()); | 
|  | 3856 |  | 
|  | 3857 | uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue; | 
|  | 3858 | switch (builtin_type->getKind()) | 
|  | 3859 | { | 
|  | 3860 | case clang::BuiltinType::ObjCId: | 
|  | 3861 | case clang::BuiltinType::ObjCClass: | 
|  | 3862 | if (pointee_or_element_clang_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3863 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->ObjCBuiltinClassTy); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3864 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; | 
|  | 3865 | break; | 
|  | 3866 |  | 
|  | 3867 | case clang::BuiltinType::ObjCSel: | 
|  | 3868 | if (pointee_or_element_clang_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3869 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->CharTy); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3870 | builtin_type_flags |= eTypeIsPointer | eTypeIsObjC; | 
|  | 3871 | break; | 
|  | 3872 |  | 
|  | 3873 | case clang::BuiltinType::Bool: | 
|  | 3874 | case clang::BuiltinType::Char_U: | 
|  | 3875 | case clang::BuiltinType::UChar: | 
|  | 3876 | case clang::BuiltinType::WChar_U: | 
|  | 3877 | case clang::BuiltinType::Char16: | 
|  | 3878 | case clang::BuiltinType::Char32: | 
|  | 3879 | case clang::BuiltinType::UShort: | 
|  | 3880 | case clang::BuiltinType::UInt: | 
|  | 3881 | case clang::BuiltinType::ULong: | 
|  | 3882 | case clang::BuiltinType::ULongLong: | 
|  | 3883 | case clang::BuiltinType::UInt128: | 
|  | 3884 | case clang::BuiltinType::Char_S: | 
|  | 3885 | case clang::BuiltinType::SChar: | 
|  | 3886 | case clang::BuiltinType::WChar_S: | 
|  | 3887 | case clang::BuiltinType::Short: | 
|  | 3888 | case clang::BuiltinType::Int: | 
|  | 3889 | case clang::BuiltinType::Long: | 
|  | 3890 | case clang::BuiltinType::LongLong: | 
|  | 3891 | case clang::BuiltinType::Int128: | 
|  | 3892 | case clang::BuiltinType::Float: | 
|  | 3893 | case clang::BuiltinType::Double: | 
|  | 3894 | case clang::BuiltinType::LongDouble: | 
|  | 3895 | builtin_type_flags |= eTypeIsScalar; | 
|  | 3896 | if (builtin_type->isInteger()) | 
|  | 3897 | { | 
|  | 3898 | builtin_type_flags |= eTypeIsInteger; | 
|  | 3899 | if (builtin_type->isSignedInteger()) | 
|  | 3900 | builtin_type_flags |= eTypeIsSigned; | 
|  | 3901 | } | 
|  | 3902 | else if (builtin_type->isFloatingPoint()) | 
|  | 3903 | builtin_type_flags |= eTypeIsFloat; | 
|  | 3904 | break; | 
|  | 3905 | default: | 
|  | 3906 | break; | 
|  | 3907 | } | 
|  | 3908 | return builtin_type_flags; | 
|  | 3909 | } | 
|  | 3910 |  | 
|  | 3911 | case clang::Type::BlockPointer: | 
|  | 3912 | if (pointee_or_element_clang_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3913 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3914 | return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock; | 
|  | 3915 |  | 
|  | 3916 | case clang::Type::Complex: | 
|  | 3917 | { | 
|  | 3918 | uint32_t complex_type_flags = eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex; | 
|  | 3919 | const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal()); | 
|  | 3920 | if (complex_type) | 
|  | 3921 | { | 
|  | 3922 | clang::QualType complex_element_type (complex_type->getElementType()); | 
|  | 3923 | if (complex_element_type->isIntegerType()) | 
|  | 3924 | complex_type_flags |= eTypeIsFloat; | 
|  | 3925 | else if (complex_element_type->isFloatingType()) | 
|  | 3926 | complex_type_flags |= eTypeIsInteger; | 
|  | 3927 | } | 
|  | 3928 | return complex_type_flags; | 
|  | 3929 | } | 
|  | 3930 | break; | 
|  | 3931 |  | 
|  | 3932 | case clang::Type::ConstantArray: | 
|  | 3933 | case clang::Type::DependentSizedArray: | 
|  | 3934 | case clang::Type::IncompleteArray: | 
|  | 3935 | case clang::Type::VariableArray: | 
|  | 3936 | if (pointee_or_element_clang_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3937 | 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] | 3938 | return eTypeHasChildren | eTypeIsArray; | 
|  | 3939 |  | 
|  | 3940 | case clang::Type::DependentName:                    return 0; | 
|  | 3941 | case clang::Type::DependentSizedExtVector:          return eTypeHasChildren | eTypeIsVector; | 
|  | 3942 | case clang::Type::DependentTemplateSpecialization:  return eTypeIsTemplate; | 
|  | 3943 | case clang::Type::Decltype:                         return 0; | 
|  | 3944 |  | 
|  | 3945 | case clang::Type::Enum: | 
|  | 3946 | if (pointee_or_element_clang_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3947 | 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] | 3948 | return eTypeIsEnumeration | eTypeHasValue; | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 3949 |  | 
|  | 3950 | case clang::Type::Auto: | 
|  | 3951 | return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetTypeInfo (pointee_or_element_clang_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3952 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3953 | 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] | 3954 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3955 | 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] | 3956 |  | 
|  | 3957 | case clang::Type::FunctionProto:                    return eTypeIsFuncPrototype | eTypeHasValue; | 
|  | 3958 | case clang::Type::FunctionNoProto:                  return eTypeIsFuncPrototype | eTypeHasValue; | 
|  | 3959 | case clang::Type::InjectedClassName:                return 0; | 
|  | 3960 |  | 
|  | 3961 | case clang::Type::LValueReference: | 
|  | 3962 | case clang::Type::RValueReference: | 
|  | 3963 | if (pointee_or_element_clang_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3964 | 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] | 3965 | return eTypeHasChildren | eTypeIsReference | eTypeHasValue; | 
|  | 3966 |  | 
|  | 3967 | case clang::Type::MemberPointer:                    return eTypeIsPointer   | eTypeIsMember | eTypeHasValue; | 
|  | 3968 |  | 
|  | 3969 | case clang::Type::ObjCObjectPointer: | 
|  | 3970 | if (pointee_or_element_clang_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3971 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3972 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | eTypeHasValue; | 
|  | 3973 |  | 
|  | 3974 | case clang::Type::ObjCObject:                       return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; | 
|  | 3975 | case clang::Type::ObjCInterface:                    return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; | 
|  | 3976 |  | 
|  | 3977 | case clang::Type::Pointer: | 
|  | 3978 | if (pointee_or_element_clang_type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3979 | pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 3980 | return eTypeHasChildren | eTypeIsPointer | eTypeHasValue; | 
|  | 3981 |  | 
|  | 3982 | case clang::Type::Record: | 
|  | 3983 | if (qual_type->getAsCXXRecordDecl()) | 
|  | 3984 | return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus; | 
|  | 3985 | else | 
|  | 3986 | return eTypeHasChildren | eTypeIsStructUnion; | 
|  | 3987 | break; | 
|  | 3988 | case clang::Type::SubstTemplateTypeParm:            return eTypeIsTemplate; | 
|  | 3989 | case clang::Type::TemplateTypeParm:                 return eTypeIsTemplate; | 
|  | 3990 | case clang::Type::TemplateSpecialization:           return eTypeIsTemplate; | 
|  | 3991 |  | 
|  | 3992 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3993 | 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] | 3994 | case clang::Type::TypeOfExpr:                       return 0; | 
|  | 3995 | case clang::Type::TypeOf:                           return 0; | 
|  | 3996 | case clang::Type::UnresolvedUsing:                  return 0; | 
|  | 3997 |  | 
|  | 3998 | case clang::Type::ExtVector: | 
|  | 3999 | case clang::Type::Vector: | 
|  | 4000 | { | 
|  | 4001 | uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector; | 
|  | 4002 | const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal()); | 
|  | 4003 | if (vector_type) | 
|  | 4004 | { | 
|  | 4005 | if (vector_type->isIntegerType()) | 
|  | 4006 | vector_type_flags |= eTypeIsFloat; | 
|  | 4007 | else if (vector_type->isFloatingType()) | 
|  | 4008 | vector_type_flags |= eTypeIsInteger; | 
|  | 4009 | } | 
|  | 4010 | return vector_type_flags; | 
|  | 4011 | } | 
|  | 4012 | default:                                            return 0; | 
|  | 4013 | } | 
|  | 4014 | return 0; | 
|  | 4015 | } | 
|  | 4016 |  | 
|  | 4017 |  | 
|  | 4018 |  | 
|  | 4019 | lldb::LanguageType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4020 | ClangASTContext::GetMinimumLanguage (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4021 | { | 
|  | 4022 | if (!type) | 
|  | 4023 | return lldb::eLanguageTypeC; | 
|  | 4024 |  | 
|  | 4025 | // If the type is a reference, then resolve it to what it refers to first: | 
|  | 4026 | clang::QualType qual_type (GetCanonicalQualType(type).getNonReferenceType()); | 
|  | 4027 | if (qual_type->isAnyPointerType()) | 
|  | 4028 | { | 
|  | 4029 | if (qual_type->isObjCObjectPointerType()) | 
|  | 4030 | return lldb::eLanguageTypeObjC; | 
|  | 4031 |  | 
|  | 4032 | clang::QualType pointee_type (qual_type->getPointeeType()); | 
|  | 4033 | if (pointee_type->getPointeeCXXRecordDecl() != nullptr) | 
|  | 4034 | return lldb::eLanguageTypeC_plus_plus; | 
|  | 4035 | if (pointee_type->isObjCObjectOrInterfaceType()) | 
|  | 4036 | return lldb::eLanguageTypeObjC; | 
|  | 4037 | if (pointee_type->isObjCClassType()) | 
|  | 4038 | return lldb::eLanguageTypeObjC; | 
|  | 4039 | if (pointee_type.getTypePtr() == getASTContext()->ObjCBuiltinIdTy.getTypePtr()) | 
|  | 4040 | return lldb::eLanguageTypeObjC; | 
|  | 4041 | } | 
|  | 4042 | else | 
|  | 4043 | { | 
|  | 4044 | if (qual_type->isObjCObjectOrInterfaceType()) | 
|  | 4045 | return lldb::eLanguageTypeObjC; | 
|  | 4046 | if (qual_type->getAsCXXRecordDecl()) | 
|  | 4047 | return lldb::eLanguageTypeC_plus_plus; | 
|  | 4048 | switch (qual_type->getTypeClass()) | 
|  | 4049 | { | 
|  | 4050 | default: | 
|  | 4051 | break; | 
|  | 4052 | case clang::Type::Builtin: | 
|  | 4053 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) | 
|  | 4054 | { | 
|  | 4055 | default: | 
|  | 4056 | case clang::BuiltinType::Void: | 
|  | 4057 | case clang::BuiltinType::Bool: | 
|  | 4058 | case clang::BuiltinType::Char_U: | 
|  | 4059 | case clang::BuiltinType::UChar: | 
|  | 4060 | case clang::BuiltinType::WChar_U: | 
|  | 4061 | case clang::BuiltinType::Char16: | 
|  | 4062 | case clang::BuiltinType::Char32: | 
|  | 4063 | case clang::BuiltinType::UShort: | 
|  | 4064 | case clang::BuiltinType::UInt: | 
|  | 4065 | case clang::BuiltinType::ULong: | 
|  | 4066 | case clang::BuiltinType::ULongLong: | 
|  | 4067 | case clang::BuiltinType::UInt128: | 
|  | 4068 | case clang::BuiltinType::Char_S: | 
|  | 4069 | case clang::BuiltinType::SChar: | 
|  | 4070 | case clang::BuiltinType::WChar_S: | 
|  | 4071 | case clang::BuiltinType::Short: | 
|  | 4072 | case clang::BuiltinType::Int: | 
|  | 4073 | case clang::BuiltinType::Long: | 
|  | 4074 | case clang::BuiltinType::LongLong: | 
|  | 4075 | case clang::BuiltinType::Int128: | 
|  | 4076 | case clang::BuiltinType::Float: | 
|  | 4077 | case clang::BuiltinType::Double: | 
|  | 4078 | case clang::BuiltinType::LongDouble: | 
|  | 4079 | break; | 
|  | 4080 |  | 
|  | 4081 | case clang::BuiltinType::NullPtr: | 
|  | 4082 | return eLanguageTypeC_plus_plus; | 
|  | 4083 |  | 
|  | 4084 | case clang::BuiltinType::ObjCId: | 
|  | 4085 | case clang::BuiltinType::ObjCClass: | 
|  | 4086 | case clang::BuiltinType::ObjCSel: | 
|  | 4087 | return eLanguageTypeObjC; | 
|  | 4088 |  | 
|  | 4089 | case clang::BuiltinType::Dependent: | 
|  | 4090 | case clang::BuiltinType::Overload: | 
|  | 4091 | case clang::BuiltinType::BoundMember: | 
|  | 4092 | case clang::BuiltinType::UnknownAny: | 
|  | 4093 | break; | 
|  | 4094 | } | 
|  | 4095 | break; | 
|  | 4096 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4097 | return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetMinimumLanguage(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4098 | } | 
|  | 4099 | } | 
|  | 4100 | return lldb::eLanguageTypeC; | 
|  | 4101 | } | 
|  | 4102 |  | 
|  | 4103 | lldb::TypeClass | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4104 | ClangASTContext::GetTypeClass (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4105 | { | 
|  | 4106 | if (!type) | 
|  | 4107 | return lldb::eTypeClassInvalid; | 
|  | 4108 |  | 
|  | 4109 | clang::QualType qual_type(GetQualType(type)); | 
|  | 4110 |  | 
|  | 4111 | switch (qual_type->getTypeClass()) | 
|  | 4112 | { | 
|  | 4113 | case clang::Type::UnaryTransform:           break; | 
|  | 4114 | case clang::Type::FunctionNoProto:          return lldb::eTypeClassFunction; | 
|  | 4115 | case clang::Type::FunctionProto:            return lldb::eTypeClassFunction; | 
|  | 4116 | case clang::Type::IncompleteArray:          return lldb::eTypeClassArray; | 
|  | 4117 | case clang::Type::VariableArray:            return lldb::eTypeClassArray; | 
|  | 4118 | case clang::Type::ConstantArray:            return lldb::eTypeClassArray; | 
|  | 4119 | case clang::Type::DependentSizedArray:      return lldb::eTypeClassArray; | 
|  | 4120 | case clang::Type::DependentSizedExtVector:  return lldb::eTypeClassVector; | 
|  | 4121 | case clang::Type::ExtVector:                return lldb::eTypeClassVector; | 
|  | 4122 | case clang::Type::Vector:                   return lldb::eTypeClassVector; | 
|  | 4123 | case clang::Type::Builtin:                  return lldb::eTypeClassBuiltin; | 
|  | 4124 | case clang::Type::ObjCObjectPointer:        return lldb::eTypeClassObjCObjectPointer; | 
|  | 4125 | case clang::Type::BlockPointer:             return lldb::eTypeClassBlockPointer; | 
|  | 4126 | case clang::Type::Pointer:                  return lldb::eTypeClassPointer; | 
|  | 4127 | case clang::Type::LValueReference:          return lldb::eTypeClassReference; | 
|  | 4128 | case clang::Type::RValueReference:          return lldb::eTypeClassReference; | 
|  | 4129 | case clang::Type::MemberPointer:            return lldb::eTypeClassMemberPointer; | 
|  | 4130 | case clang::Type::Complex: | 
|  | 4131 | if (qual_type->isComplexType()) | 
|  | 4132 | return lldb::eTypeClassComplexFloat; | 
|  | 4133 | else | 
|  | 4134 | return lldb::eTypeClassComplexInteger; | 
|  | 4135 | case clang::Type::ObjCObject:               return lldb::eTypeClassObjCObject; | 
|  | 4136 | case clang::Type::ObjCInterface:            return lldb::eTypeClassObjCInterface; | 
|  | 4137 | case clang::Type::Record: | 
|  | 4138 | { | 
|  | 4139 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 4140 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 4141 | if (record_decl->isUnion()) | 
|  | 4142 | return lldb::eTypeClassUnion; | 
|  | 4143 | else if (record_decl->isStruct()) | 
|  | 4144 | return lldb::eTypeClassStruct; | 
|  | 4145 | else | 
|  | 4146 | return lldb::eTypeClassClass; | 
|  | 4147 | } | 
|  | 4148 | break; | 
|  | 4149 | case clang::Type::Enum:                     return lldb::eTypeClassEnumeration; | 
|  | 4150 | case clang::Type::Typedef:                  return lldb::eTypeClassTypedef; | 
|  | 4151 | case clang::Type::UnresolvedUsing:          break; | 
|  | 4152 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4153 | return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeClass(); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 4154 | case clang::Type::Auto: | 
|  | 4155 | return CompilerType(getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetTypeClass(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4156 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4157 | return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeClass(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4158 |  | 
|  | 4159 | case clang::Type::Attributed:               break; | 
|  | 4160 | case clang::Type::TemplateTypeParm:         break; | 
|  | 4161 | case clang::Type::SubstTemplateTypeParm:    break; | 
|  | 4162 | case clang::Type::SubstTemplateTypeParmPack:break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4163 | case clang::Type::InjectedClassName:        break; | 
|  | 4164 | case clang::Type::DependentName:            break; | 
|  | 4165 | case clang::Type::DependentTemplateSpecialization: break; | 
|  | 4166 | case clang::Type::PackExpansion:            break; | 
|  | 4167 |  | 
|  | 4168 | case clang::Type::TypeOfExpr:               break; | 
|  | 4169 | case clang::Type::TypeOf:                   break; | 
|  | 4170 | case clang::Type::Decltype:                 break; | 
|  | 4171 | case clang::Type::TemplateSpecialization:   break; | 
|  | 4172 | case clang::Type::Atomic:                   break; | 
| Pavel Labath | 484f0a3 | 2016-01-12 08:51:28 +0000 | [diff] [blame] | 4173 | case clang::Type::Pipe:                     break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4174 |  | 
|  | 4175 | // pointer type decayed from an array or function type. | 
|  | 4176 | case clang::Type::Decayed:                  break; | 
|  | 4177 | case clang::Type::Adjusted:                 break; | 
|  | 4178 | } | 
|  | 4179 | // We don't know hot to display this type... | 
|  | 4180 | return lldb::eTypeClassOther; | 
|  | 4181 |  | 
|  | 4182 | } | 
|  | 4183 |  | 
|  | 4184 | unsigned | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4185 | ClangASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4186 | { | 
|  | 4187 | if (type) | 
|  | 4188 | return GetQualType(type).getQualifiers().getCVRQualifiers(); | 
|  | 4189 | return 0; | 
|  | 4190 | } | 
|  | 4191 |  | 
|  | 4192 | //---------------------------------------------------------------------- | 
|  | 4193 | // Creating related types | 
|  | 4194 | //---------------------------------------------------------------------- | 
|  | 4195 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4196 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4197 | ClangASTContext::GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4198 | { | 
|  | 4199 | if (type) | 
|  | 4200 | { | 
|  | 4201 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 4202 |  | 
|  | 4203 | const clang::Type *array_eletype = qual_type.getTypePtr()->getArrayElementTypeNoTypeQual(); | 
|  | 4204 |  | 
|  | 4205 | if (!array_eletype) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4206 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4207 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4208 | CompilerType element_type (getASTContext(), array_eletype->getCanonicalTypeUnqualified()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4209 |  | 
|  | 4210 | // TODO: the real stride will be >= this value.. find the real one! | 
|  | 4211 | if (stride) | 
|  | 4212 | *stride = element_type.GetByteSize(nullptr); | 
|  | 4213 |  | 
|  | 4214 | return element_type; | 
|  | 4215 |  | 
|  | 4216 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4217 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4218 | } | 
|  | 4219 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4220 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4221 | ClangASTContext::GetCanonicalType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4222 | { | 
|  | 4223 | if (type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4224 | return CompilerType (getASTContext(), GetCanonicalQualType(type)); | 
|  | 4225 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4226 | } | 
|  | 4227 |  | 
|  | 4228 | static clang::QualType | 
|  | 4229 | GetFullyUnqualifiedType_Impl (clang::ASTContext *ast, clang::QualType qual_type) | 
|  | 4230 | { | 
|  | 4231 | if (qual_type->isPointerType()) | 
|  | 4232 | qual_type = ast->getPointerType(GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType())); | 
|  | 4233 | else | 
|  | 4234 | qual_type = qual_type.getUnqualifiedType(); | 
|  | 4235 | qual_type.removeLocalConst(); | 
|  | 4236 | qual_type.removeLocalRestrict(); | 
|  | 4237 | qual_type.removeLocalVolatile(); | 
|  | 4238 | return qual_type; | 
|  | 4239 | } | 
|  | 4240 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4241 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4242 | ClangASTContext::GetFullyUnqualifiedType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4243 | { | 
|  | 4244 | if (type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4245 | return CompilerType(getASTContext(), GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type))); | 
|  | 4246 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4247 | } | 
|  | 4248 |  | 
|  | 4249 |  | 
|  | 4250 | int | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4251 | ClangASTContext::GetFunctionArgumentCount (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4252 | { | 
|  | 4253 | if (type) | 
|  | 4254 | { | 
|  | 4255 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type)); | 
|  | 4256 | if (func) | 
|  | 4257 | return func->getNumParams(); | 
|  | 4258 | } | 
|  | 4259 | return -1; | 
|  | 4260 | } | 
|  | 4261 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4262 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4263 | ClangASTContext::GetFunctionArgumentTypeAtIndex (lldb::opaque_compiler_type_t type, size_t idx) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4264 | { | 
|  | 4265 | if (type) | 
|  | 4266 | { | 
| Greg Clayton | 8b8874e | 2015-12-17 00:58:41 +0000 | [diff] [blame] | 4267 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetQualType(type)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4268 | if (func) | 
|  | 4269 | { | 
|  | 4270 | const uint32_t num_args = func->getNumParams(); | 
|  | 4271 | if (idx < num_args) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4272 | return CompilerType(getASTContext(), func->getParamType(idx)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4273 | } | 
|  | 4274 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4275 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4276 | } | 
|  | 4277 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4278 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4279 | ClangASTContext::GetFunctionReturnType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4280 | { | 
|  | 4281 | if (type) | 
|  | 4282 | { | 
| Greg Clayton | 8b8874e | 2015-12-17 00:58:41 +0000 | [diff] [blame] | 4283 | clang::QualType qual_type(GetQualType(type)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4284 | const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr()); | 
|  | 4285 | if (func) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4286 | return CompilerType(getASTContext(), func->getReturnType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4287 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4288 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4289 | } | 
|  | 4290 |  | 
|  | 4291 | size_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4292 | ClangASTContext::GetNumMemberFunctions (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4293 | { | 
|  | 4294 | size_t num_functions = 0; | 
|  | 4295 | if (type) | 
|  | 4296 | { | 
|  | 4297 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 4298 | switch (qual_type->getTypeClass()) { | 
|  | 4299 | case clang::Type::Record: | 
|  | 4300 | if (GetCompleteQualType (getASTContext(), qual_type)) | 
|  | 4301 | { | 
|  | 4302 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 4303 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 4304 | assert(record_decl); | 
|  | 4305 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 4306 | if (cxx_record_decl) | 
|  | 4307 | num_functions = std::distance(cxx_record_decl->method_begin(), cxx_record_decl->method_end()); | 
|  | 4308 | } | 
|  | 4309 | break; | 
|  | 4310 |  | 
|  | 4311 | case clang::Type::ObjCObjectPointer: | 
|  | 4312 | if (GetCompleteType(type)) | 
|  | 4313 | { | 
|  | 4314 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); | 
|  | 4315 | if (objc_class_type) | 
|  | 4316 | { | 
|  | 4317 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); | 
|  | 4318 | if (class_interface_decl) | 
|  | 4319 | num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end()); | 
|  | 4320 | } | 
|  | 4321 | } | 
|  | 4322 | break; | 
|  | 4323 |  | 
|  | 4324 | case clang::Type::ObjCObject: | 
|  | 4325 | case clang::Type::ObjCInterface: | 
|  | 4326 | if (GetCompleteType(type)) | 
|  | 4327 | { | 
|  | 4328 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 4329 | if (objc_class_type) | 
|  | 4330 | { | 
|  | 4331 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 4332 | if (class_interface_decl) | 
|  | 4333 | num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end()); | 
|  | 4334 | } | 
|  | 4335 | } | 
|  | 4336 | break; | 
|  | 4337 |  | 
|  | 4338 |  | 
|  | 4339 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4340 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumMemberFunctions(); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 4341 |  | 
|  | 4342 | case clang::Type::Auto: | 
|  | 4343 | return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumMemberFunctions(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4344 |  | 
|  | 4345 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4346 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumMemberFunctions(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4347 |  | 
|  | 4348 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4349 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumMemberFunctions(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4350 |  | 
|  | 4351 | default: | 
|  | 4352 | break; | 
|  | 4353 | } | 
|  | 4354 | } | 
|  | 4355 | return num_functions; | 
|  | 4356 | } | 
|  | 4357 |  | 
|  | 4358 | TypeMemberFunctionImpl | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4359 | ClangASTContext::GetMemberFunctionAtIndex (lldb::opaque_compiler_type_t type, size_t idx) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4360 | { | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4361 | std::string name; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4362 | MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown); | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4363 | CompilerType clang_type; | 
|  | 4364 | CompilerDecl clang_decl; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4365 | if (type) | 
|  | 4366 | { | 
|  | 4367 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 4368 | switch (qual_type->getTypeClass()) { | 
|  | 4369 | case clang::Type::Record: | 
|  | 4370 | if (GetCompleteQualType (getASTContext(), qual_type)) | 
|  | 4371 | { | 
|  | 4372 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 4373 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 4374 | assert(record_decl); | 
|  | 4375 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 4376 | if (cxx_record_decl) | 
|  | 4377 | { | 
|  | 4378 | auto method_iter = cxx_record_decl->method_begin(); | 
|  | 4379 | auto method_end = cxx_record_decl->method_end(); | 
|  | 4380 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) | 
|  | 4381 | { | 
|  | 4382 | std::advance(method_iter, idx); | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4383 | clang::CXXMethodDecl *cxx_method_decl = method_iter->getCanonicalDecl(); | 
|  | 4384 | if (cxx_method_decl) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4385 | { | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4386 | name = cxx_method_decl->getDeclName().getAsString(); | 
|  | 4387 | if (cxx_method_decl->isStatic()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4388 | kind = lldb::eMemberFunctionKindStaticMethod; | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4389 | else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl)) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4390 | kind = lldb::eMemberFunctionKindConstructor; | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4391 | else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl)) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4392 | kind = lldb::eMemberFunctionKindDestructor; | 
|  | 4393 | else | 
|  | 4394 | kind = lldb::eMemberFunctionKindInstanceMethod; | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4395 | clang_type = CompilerType(this, cxx_method_decl->getType().getAsOpaquePtr()); | 
|  | 4396 | clang_decl = CompilerDecl(this, cxx_method_decl); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4397 | } | 
|  | 4398 | } | 
|  | 4399 | } | 
|  | 4400 | } | 
|  | 4401 | break; | 
|  | 4402 |  | 
|  | 4403 | case clang::Type::ObjCObjectPointer: | 
|  | 4404 | if (GetCompleteType(type)) | 
|  | 4405 | { | 
|  | 4406 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); | 
|  | 4407 | if (objc_class_type) | 
|  | 4408 | { | 
|  | 4409 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); | 
|  | 4410 | if (class_interface_decl) | 
|  | 4411 | { | 
|  | 4412 | auto method_iter = class_interface_decl->meth_begin(); | 
|  | 4413 | auto method_end = class_interface_decl->meth_end(); | 
|  | 4414 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) | 
|  | 4415 | { | 
|  | 4416 | std::advance(method_iter, idx); | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4417 | clang::ObjCMethodDecl *objc_method_decl = method_iter->getCanonicalDecl(); | 
|  | 4418 | if (objc_method_decl) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4419 | { | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4420 | clang_decl = CompilerDecl(this, objc_method_decl); | 
|  | 4421 | name = objc_method_decl->getSelector().getAsString(); | 
|  | 4422 | if (objc_method_decl->isClassMethod()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4423 | kind = lldb::eMemberFunctionKindStaticMethod; | 
|  | 4424 | else | 
|  | 4425 | kind = lldb::eMemberFunctionKindInstanceMethod; | 
|  | 4426 | } | 
|  | 4427 | } | 
|  | 4428 | } | 
|  | 4429 | } | 
|  | 4430 | } | 
|  | 4431 | break; | 
|  | 4432 |  | 
|  | 4433 | case clang::Type::ObjCObject: | 
|  | 4434 | case clang::Type::ObjCInterface: | 
|  | 4435 | if (GetCompleteType(type)) | 
|  | 4436 | { | 
|  | 4437 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 4438 | if (objc_class_type) | 
|  | 4439 | { | 
|  | 4440 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 4441 | if (class_interface_decl) | 
|  | 4442 | { | 
|  | 4443 | auto method_iter = class_interface_decl->meth_begin(); | 
|  | 4444 | auto method_end = class_interface_decl->meth_end(); | 
|  | 4445 | if (idx < static_cast<size_t>(std::distance(method_iter, method_end))) | 
|  | 4446 | { | 
|  | 4447 | std::advance(method_iter, idx); | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4448 | clang::ObjCMethodDecl *objc_method_decl = method_iter->getCanonicalDecl(); | 
|  | 4449 | if (objc_method_decl) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4450 | { | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4451 | clang_decl = CompilerDecl(this, objc_method_decl); | 
|  | 4452 | name = objc_method_decl->getSelector().getAsString(); | 
|  | 4453 | if (objc_method_decl->isClassMethod()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4454 | kind = lldb::eMemberFunctionKindStaticMethod; | 
|  | 4455 | else | 
|  | 4456 | kind = lldb::eMemberFunctionKindInstanceMethod; | 
|  | 4457 | } | 
|  | 4458 | } | 
|  | 4459 | } | 
|  | 4460 | } | 
|  | 4461 | } | 
|  | 4462 | break; | 
|  | 4463 |  | 
|  | 4464 | case clang::Type::Typedef: | 
|  | 4465 | return GetMemberFunctionAtIndex(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 4466 |  | 
|  | 4467 | case clang::Type::Auto: | 
|  | 4468 | return GetMemberFunctionAtIndex(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4469 |  | 
|  | 4470 | case clang::Type::Elaborated: | 
|  | 4471 | return GetMemberFunctionAtIndex(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx); | 
|  | 4472 |  | 
|  | 4473 | case clang::Type::Paren: | 
|  | 4474 | return GetMemberFunctionAtIndex(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx); | 
|  | 4475 |  | 
|  | 4476 | default: | 
|  | 4477 | break; | 
|  | 4478 | } | 
|  | 4479 | } | 
|  | 4480 |  | 
|  | 4481 | if (kind == eMemberFunctionKindUnknown) | 
|  | 4482 | return TypeMemberFunctionImpl(); | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 4483 | else | 
|  | 4484 | return TypeMemberFunctionImpl(clang_type, clang_decl, name, kind); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4485 | } | 
|  | 4486 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4487 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4488 | ClangASTContext::GetNonReferenceType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4489 | { | 
|  | 4490 | if (type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4491 | return CompilerType(getASTContext(), GetQualType(type).getNonReferenceType()); | 
|  | 4492 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4493 | } | 
|  | 4494 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4495 | CompilerType | 
|  | 4496 | ClangASTContext::CreateTypedefType (const CompilerType& type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4497 | const char *typedef_name, | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4498 | const CompilerDeclContext &compiler_decl_ctx) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4499 | { | 
|  | 4500 | if (type && typedef_name && typedef_name[0]) | 
|  | 4501 | { | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 4502 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4503 | if (!ast) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4504 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4505 | clang::ASTContext* clang_ast = ast->getASTContext(); | 
|  | 4506 | clang::QualType qual_type (GetQualType(type)); | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4507 |  | 
|  | 4508 | clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4509 | if (decl_ctx == nullptr) | 
|  | 4510 | decl_ctx = ast->getASTContext()->getTranslationUnitDecl(); | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4511 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4512 | clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast, | 
|  | 4513 | decl_ctx, | 
|  | 4514 | clang::SourceLocation(), | 
|  | 4515 | clang::SourceLocation(), | 
|  | 4516 | &clang_ast->Idents.get(typedef_name), | 
|  | 4517 | clang_ast->getTrivialTypeSourceInfo(qual_type)); | 
|  | 4518 |  | 
|  | 4519 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier | 
|  | 4520 |  | 
|  | 4521 | // Get a uniqued clang::QualType for the typedef decl type | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4522 | return CompilerType (clang_ast, clang_ast->getTypedefType (decl)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4523 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4524 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4525 |  | 
|  | 4526 | } | 
|  | 4527 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4528 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4529 | ClangASTContext::GetPointeeType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4530 | { | 
|  | 4531 | if (type) | 
|  | 4532 | { | 
|  | 4533 | clang::QualType qual_type(GetQualType(type)); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4534 | return CompilerType (getASTContext(), qual_type.getTypePtr()->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4535 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4536 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4537 | } | 
|  | 4538 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4539 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4540 | ClangASTContext::GetPointerType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4541 | { | 
|  | 4542 | if (type) | 
|  | 4543 | { | 
|  | 4544 | clang::QualType qual_type (GetQualType(type)); | 
|  | 4545 |  | 
|  | 4546 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 4547 | switch (type_class) | 
|  | 4548 | { | 
|  | 4549 | case clang::Type::ObjCObject: | 
|  | 4550 | case clang::Type::ObjCInterface: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4551 | return CompilerType(getASTContext(), getASTContext()->getObjCObjectPointerType(qual_type)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4552 |  | 
|  | 4553 | default: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4554 | return CompilerType(getASTContext(), getASTContext()->getPointerType(qual_type)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4555 | } | 
|  | 4556 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4557 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4558 | } | 
|  | 4559 |  | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4560 |  | 
|  | 4561 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4562 | ClangASTContext::GetLValueReferenceType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4563 | { | 
|  | 4564 | if (type) | 
|  | 4565 | return CompilerType(this, getASTContext()->getLValueReferenceType(GetQualType(type)).getAsOpaquePtr()); | 
|  | 4566 | else | 
|  | 4567 | return CompilerType(); | 
|  | 4568 | } | 
|  | 4569 |  | 
|  | 4570 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4571 | ClangASTContext::GetRValueReferenceType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4572 | { | 
|  | 4573 | if (type) | 
|  | 4574 | return CompilerType(this, getASTContext()->getRValueReferenceType(GetQualType(type)).getAsOpaquePtr()); | 
|  | 4575 | else | 
|  | 4576 | return CompilerType(); | 
|  | 4577 | } | 
|  | 4578 |  | 
|  | 4579 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4580 | ClangASTContext::AddConstModifier (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4581 | { | 
|  | 4582 | if (type) | 
|  | 4583 | { | 
|  | 4584 | clang::QualType result(GetQualType(type)); | 
|  | 4585 | result.addConst(); | 
|  | 4586 | return CompilerType (this, result.getAsOpaquePtr()); | 
|  | 4587 | } | 
|  | 4588 | return CompilerType(); | 
|  | 4589 | } | 
|  | 4590 |  | 
|  | 4591 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4592 | ClangASTContext::AddVolatileModifier (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4593 | { | 
|  | 4594 | if (type) | 
|  | 4595 | { | 
|  | 4596 | clang::QualType result(GetQualType(type)); | 
|  | 4597 | result.addVolatile(); | 
|  | 4598 | return CompilerType (this, result.getAsOpaquePtr()); | 
|  | 4599 | } | 
|  | 4600 | return CompilerType(); | 
|  | 4601 |  | 
|  | 4602 | } | 
|  | 4603 |  | 
|  | 4604 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4605 | ClangASTContext::AddRestrictModifier (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 4606 | { | 
|  | 4607 | if (type) | 
|  | 4608 | { | 
|  | 4609 | clang::QualType result(GetQualType(type)); | 
|  | 4610 | result.addRestrict(); | 
|  | 4611 | return CompilerType (this, result.getAsOpaquePtr()); | 
|  | 4612 | } | 
|  | 4613 | return CompilerType(); | 
|  | 4614 |  | 
|  | 4615 | } | 
|  | 4616 |  | 
|  | 4617 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4618 | 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] | 4619 | { | 
|  | 4620 | if (type) | 
|  | 4621 | { | 
|  | 4622 | clang::ASTContext* clang_ast = getASTContext(); | 
|  | 4623 | clang::QualType qual_type (GetQualType(type)); | 
|  | 4624 |  | 
|  | 4625 | clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx); | 
|  | 4626 | if (decl_ctx == nullptr) | 
|  | 4627 | decl_ctx = getASTContext()->getTranslationUnitDecl(); | 
|  | 4628 |  | 
|  | 4629 | clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast, | 
|  | 4630 | decl_ctx, | 
|  | 4631 | clang::SourceLocation(), | 
|  | 4632 | clang::SourceLocation(), | 
|  | 4633 | &clang_ast->Idents.get(typedef_name), | 
|  | 4634 | clang_ast->getTrivialTypeSourceInfo(qual_type)); | 
|  | 4635 |  | 
|  | 4636 | decl->setAccess(clang::AS_public); // TODO respect proper access specifier | 
|  | 4637 |  | 
|  | 4638 | // Get a uniqued clang::QualType for the typedef decl type | 
|  | 4639 | return CompilerType (this, clang_ast->getTypedefType (decl).getAsOpaquePtr()); | 
|  | 4640 |  | 
|  | 4641 | } | 
|  | 4642 | return CompilerType(); | 
|  | 4643 |  | 
|  | 4644 | } | 
|  | 4645 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4646 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4647 | ClangASTContext::GetTypedefedType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4648 | { | 
|  | 4649 | if (type) | 
|  | 4650 | { | 
|  | 4651 | const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(GetQualType(type)); | 
|  | 4652 | if (typedef_type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4653 | return CompilerType (getASTContext(), typedef_type->getDecl()->getUnderlyingType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4654 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4655 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4656 | } | 
|  | 4657 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4658 | CompilerType | 
|  | 4659 | ClangASTContext::RemoveFastQualifiers (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4660 | { | 
| Ryan Brown | 57bee1e | 2015-09-14 22:45:11 +0000 | [diff] [blame] | 4661 | if (IsClangType(type)) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4662 | { | 
|  | 4663 | clang::QualType qual_type(GetQualType(type)); | 
|  | 4664 | qual_type.getQualifiers().removeFastQualifiers(); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4665 | return CompilerType (type.GetTypeSystem(), qual_type.getAsOpaquePtr()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4666 | } | 
|  | 4667 | return type; | 
|  | 4668 | } | 
|  | 4669 |  | 
|  | 4670 |  | 
|  | 4671 | //---------------------------------------------------------------------- | 
|  | 4672 | // Create related types using the current type's AST | 
|  | 4673 | //---------------------------------------------------------------------- | 
|  | 4674 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4675 | CompilerType | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4676 | ClangASTContext::GetBasicTypeFromAST (lldb::BasicType basic_type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4677 | { | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4678 | return ClangASTContext::GetBasicType(getASTContext(), basic_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4679 | } | 
|  | 4680 | //---------------------------------------------------------------------- | 
|  | 4681 | // Exploring the type | 
|  | 4682 | //---------------------------------------------------------------------- | 
|  | 4683 |  | 
|  | 4684 | uint64_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4685 | ClangASTContext::GetBitSize (lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4686 | { | 
|  | 4687 | if (GetCompleteType (type)) | 
|  | 4688 | { | 
|  | 4689 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 4690 | switch (qual_type->getTypeClass()) | 
|  | 4691 | { | 
|  | 4692 | case clang::Type::ObjCInterface: | 
|  | 4693 | case clang::Type::ObjCObject: | 
|  | 4694 | { | 
|  | 4695 | ExecutionContext exe_ctx (exe_scope); | 
|  | 4696 | Process *process = exe_ctx.GetProcessPtr(); | 
|  | 4697 | if (process) | 
|  | 4698 | { | 
|  | 4699 | ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime(); | 
|  | 4700 | if (objc_runtime) | 
|  | 4701 | { | 
|  | 4702 | uint64_t bit_size = 0; | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4703 | if (objc_runtime->GetTypeBitSize(CompilerType(getASTContext(), qual_type), bit_size)) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4704 | return bit_size; | 
|  | 4705 | } | 
|  | 4706 | } | 
|  | 4707 | else | 
|  | 4708 | { | 
|  | 4709 | static bool g_printed = false; | 
|  | 4710 | if (!g_printed) | 
|  | 4711 | { | 
|  | 4712 | StreamString s; | 
| Enrico Granata | c3ef0ed | 2015-10-14 22:44:50 +0000 | [diff] [blame] | 4713 | DumpTypeDescription(type, &s); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4714 |  | 
|  | 4715 | llvm::outs() << "warning: trying to determine the size of type "; | 
|  | 4716 | llvm::outs() << s.GetString() << "\n"; | 
|  | 4717 | llvm::outs() << "without a valid ExecutionContext. this is not reliable. please file a bug against LLDB.\n"; | 
|  | 4718 | llvm::outs() << "backtrace:\n"; | 
|  | 4719 | llvm::sys::PrintStackTrace(llvm::outs()); | 
|  | 4720 | llvm::outs() << "\n"; | 
|  | 4721 | g_printed = true; | 
|  | 4722 | } | 
|  | 4723 | } | 
|  | 4724 | } | 
|  | 4725 | // fallthrough | 
|  | 4726 | default: | 
|  | 4727 | const uint32_t bit_size = getASTContext()->getTypeSize (qual_type); | 
|  | 4728 | if (bit_size == 0) | 
|  | 4729 | { | 
|  | 4730 | if (qual_type->isIncompleteArrayType()) | 
|  | 4731 | return getASTContext()->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified()); | 
|  | 4732 | } | 
|  | 4733 | if (qual_type->isObjCObjectOrInterfaceType()) | 
|  | 4734 | return bit_size + getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy); | 
|  | 4735 | return bit_size; | 
|  | 4736 | } | 
|  | 4737 | } | 
|  | 4738 | return 0; | 
|  | 4739 | } | 
|  | 4740 |  | 
|  | 4741 | size_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4742 | ClangASTContext::GetTypeBitAlign (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4743 | { | 
|  | 4744 | if (GetCompleteType(type)) | 
|  | 4745 | return getASTContext()->getTypeAlign(GetQualType(type)); | 
|  | 4746 | return 0; | 
|  | 4747 | } | 
|  | 4748 |  | 
|  | 4749 |  | 
|  | 4750 | lldb::Encoding | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4751 | ClangASTContext::GetEncoding (lldb::opaque_compiler_type_t type, uint64_t &count) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4752 | { | 
|  | 4753 | if (!type) | 
|  | 4754 | return lldb::eEncodingInvalid; | 
|  | 4755 |  | 
|  | 4756 | count = 1; | 
|  | 4757 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 4758 |  | 
|  | 4759 | switch (qual_type->getTypeClass()) | 
|  | 4760 | { | 
|  | 4761 | case clang::Type::UnaryTransform: | 
|  | 4762 | break; | 
|  | 4763 |  | 
|  | 4764 | case clang::Type::FunctionNoProto: | 
|  | 4765 | case clang::Type::FunctionProto: | 
|  | 4766 | break; | 
|  | 4767 |  | 
|  | 4768 | case clang::Type::IncompleteArray: | 
|  | 4769 | case clang::Type::VariableArray: | 
|  | 4770 | break; | 
|  | 4771 |  | 
|  | 4772 | case clang::Type::ConstantArray: | 
|  | 4773 | break; | 
|  | 4774 |  | 
|  | 4775 | case clang::Type::ExtVector: | 
|  | 4776 | case clang::Type::Vector: | 
|  | 4777 | // TODO: Set this to more than one??? | 
|  | 4778 | break; | 
|  | 4779 |  | 
|  | 4780 | case clang::Type::Builtin: | 
|  | 4781 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) | 
|  | 4782 | { | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4783 | case clang::BuiltinType::Void: | 
|  | 4784 | break; | 
|  | 4785 |  | 
|  | 4786 | case clang::BuiltinType::Bool: | 
|  | 4787 | case clang::BuiltinType::Char_S: | 
|  | 4788 | case clang::BuiltinType::SChar: | 
|  | 4789 | case clang::BuiltinType::WChar_S: | 
|  | 4790 | case clang::BuiltinType::Char16: | 
|  | 4791 | case clang::BuiltinType::Char32: | 
|  | 4792 | case clang::BuiltinType::Short: | 
|  | 4793 | case clang::BuiltinType::Int: | 
|  | 4794 | case clang::BuiltinType::Long: | 
|  | 4795 | case clang::BuiltinType::LongLong: | 
|  | 4796 | case clang::BuiltinType::Int128:        return lldb::eEncodingSint; | 
|  | 4797 |  | 
|  | 4798 | case clang::BuiltinType::Char_U: | 
|  | 4799 | case clang::BuiltinType::UChar: | 
|  | 4800 | case clang::BuiltinType::WChar_U: | 
|  | 4801 | case clang::BuiltinType::UShort: | 
|  | 4802 | case clang::BuiltinType::UInt: | 
|  | 4803 | case clang::BuiltinType::ULong: | 
|  | 4804 | case clang::BuiltinType::ULongLong: | 
|  | 4805 | case clang::BuiltinType::UInt128:       return lldb::eEncodingUint; | 
|  | 4806 |  | 
| Greg Clayton | dee40e7 | 2015-11-03 23:23:22 +0000 | [diff] [blame] | 4807 | case clang::BuiltinType::Half: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4808 | case clang::BuiltinType::Float: | 
|  | 4809 | case clang::BuiltinType::Double: | 
|  | 4810 | case clang::BuiltinType::LongDouble:    return lldb::eEncodingIEEE754; | 
|  | 4811 |  | 
|  | 4812 | case clang::BuiltinType::ObjCClass: | 
|  | 4813 | case clang::BuiltinType::ObjCId: | 
|  | 4814 | case clang::BuiltinType::ObjCSel:       return lldb::eEncodingUint; | 
|  | 4815 |  | 
|  | 4816 | case clang::BuiltinType::NullPtr:       return lldb::eEncodingUint; | 
|  | 4817 |  | 
|  | 4818 | case clang::BuiltinType::Kind::ARCUnbridgedCast: | 
|  | 4819 | case clang::BuiltinType::Kind::BoundMember: | 
|  | 4820 | case clang::BuiltinType::Kind::BuiltinFn: | 
|  | 4821 | case clang::BuiltinType::Kind::Dependent: | 
| Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4822 | case clang::BuiltinType::Kind::OCLClkEvent: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4823 | case clang::BuiltinType::Kind::OCLEvent: | 
|  | 4824 | case clang::BuiltinType::Kind::OCLImage1d: | 
|  | 4825 | case clang::BuiltinType::Kind::OCLImage1dArray: | 
|  | 4826 | case clang::BuiltinType::Kind::OCLImage1dBuffer: | 
|  | 4827 | case clang::BuiltinType::Kind::OCLImage2d: | 
|  | 4828 | case clang::BuiltinType::Kind::OCLImage2dArray: | 
| Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4829 | case clang::BuiltinType::Kind::OCLImage2dArrayDepth: | 
|  | 4830 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAA: | 
|  | 4831 | case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepth: | 
|  | 4832 | case clang::BuiltinType::Kind::OCLImage2dDepth: | 
|  | 4833 | case clang::BuiltinType::Kind::OCLImage2dMSAA: | 
|  | 4834 | case clang::BuiltinType::Kind::OCLImage2dMSAADepth: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4835 | case clang::BuiltinType::Kind::OCLImage3d: | 
| Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4836 | case clang::BuiltinType::Kind::OCLQueue: | 
|  | 4837 | case clang::BuiltinType::Kind::OCLNDRange: | 
|  | 4838 | case clang::BuiltinType::Kind::OCLReserveID: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4839 | case clang::BuiltinType::Kind::OCLSampler: | 
| Ed Maste | c6dd651 | 2015-09-23 18:32:34 +0000 | [diff] [blame] | 4840 | case clang::BuiltinType::Kind::OMPArraySection: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4841 | case clang::BuiltinType::Kind::Overload: | 
|  | 4842 | case clang::BuiltinType::Kind::PseudoObject: | 
|  | 4843 | case clang::BuiltinType::Kind::UnknownAny: | 
|  | 4844 | break; | 
|  | 4845 | } | 
|  | 4846 | break; | 
|  | 4847 | // All pointer types are represented as unsigned integer encodings. | 
|  | 4848 | // We may nee to add a eEncodingPointer if we ever need to know the | 
|  | 4849 | // difference | 
|  | 4850 | case clang::Type::ObjCObjectPointer: | 
|  | 4851 | case clang::Type::BlockPointer: | 
|  | 4852 | case clang::Type::Pointer: | 
|  | 4853 | case clang::Type::LValueReference: | 
|  | 4854 | case clang::Type::RValueReference: | 
|  | 4855 | case clang::Type::MemberPointer:            return lldb::eEncodingUint; | 
|  | 4856 | case clang::Type::Complex: | 
|  | 4857 | { | 
|  | 4858 | lldb::Encoding encoding = lldb::eEncodingIEEE754; | 
|  | 4859 | if (qual_type->isComplexType()) | 
|  | 4860 | encoding = lldb::eEncodingIEEE754; | 
|  | 4861 | else | 
|  | 4862 | { | 
|  | 4863 | const clang::ComplexType *complex_type = qual_type->getAsComplexIntegerType(); | 
|  | 4864 | if (complex_type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4865 | encoding = CompilerType(getASTContext(), complex_type->getElementType()).GetEncoding(count); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4866 | else | 
|  | 4867 | encoding = lldb::eEncodingSint; | 
|  | 4868 | } | 
|  | 4869 | count = 2; | 
|  | 4870 | return encoding; | 
|  | 4871 | } | 
|  | 4872 |  | 
|  | 4873 | case clang::Type::ObjCInterface:            break; | 
|  | 4874 | case clang::Type::Record:                   break; | 
|  | 4875 | case clang::Type::Enum:                     return lldb::eEncodingSint; | 
|  | 4876 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4877 | return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetEncoding(count); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 4878 |  | 
|  | 4879 | case clang::Type::Auto: | 
|  | 4880 | return CompilerType(getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetEncoding(count); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4881 |  | 
|  | 4882 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4883 | return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetEncoding(count); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4884 |  | 
|  | 4885 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4886 | return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetEncoding(count); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4887 |  | 
|  | 4888 | case clang::Type::DependentSizedArray: | 
|  | 4889 | case clang::Type::DependentSizedExtVector: | 
|  | 4890 | case clang::Type::UnresolvedUsing: | 
|  | 4891 | case clang::Type::Attributed: | 
|  | 4892 | case clang::Type::TemplateTypeParm: | 
|  | 4893 | case clang::Type::SubstTemplateTypeParm: | 
|  | 4894 | case clang::Type::SubstTemplateTypeParmPack: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4895 | case clang::Type::InjectedClassName: | 
|  | 4896 | case clang::Type::DependentName: | 
|  | 4897 | case clang::Type::DependentTemplateSpecialization: | 
|  | 4898 | case clang::Type::PackExpansion: | 
|  | 4899 | case clang::Type::ObjCObject: | 
|  | 4900 |  | 
|  | 4901 | case clang::Type::TypeOfExpr: | 
|  | 4902 | case clang::Type::TypeOf: | 
|  | 4903 | case clang::Type::Decltype: | 
|  | 4904 | case clang::Type::TemplateSpecialization: | 
|  | 4905 | case clang::Type::Atomic: | 
|  | 4906 | case clang::Type::Adjusted: | 
| Pavel Labath | 484f0a3 | 2016-01-12 08:51:28 +0000 | [diff] [blame] | 4907 | case clang::Type::Pipe: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4908 | break; | 
|  | 4909 |  | 
|  | 4910 | // pointer type decayed from an array or function type. | 
|  | 4911 | case clang::Type::Decayed: | 
|  | 4912 | break; | 
|  | 4913 | } | 
|  | 4914 | count = 0; | 
|  | 4915 | return lldb::eEncodingInvalid; | 
|  | 4916 | } | 
|  | 4917 |  | 
|  | 4918 | lldb::Format | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 4919 | ClangASTContext::GetFormat (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4920 | { | 
|  | 4921 | if (!type) | 
|  | 4922 | return lldb::eFormatDefault; | 
|  | 4923 |  | 
|  | 4924 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 4925 |  | 
|  | 4926 | switch (qual_type->getTypeClass()) | 
|  | 4927 | { | 
|  | 4928 | case clang::Type::UnaryTransform: | 
|  | 4929 | break; | 
|  | 4930 |  | 
|  | 4931 | case clang::Type::FunctionNoProto: | 
|  | 4932 | case clang::Type::FunctionProto: | 
|  | 4933 | break; | 
|  | 4934 |  | 
|  | 4935 | case clang::Type::IncompleteArray: | 
|  | 4936 | case clang::Type::VariableArray: | 
|  | 4937 | break; | 
|  | 4938 |  | 
|  | 4939 | case clang::Type::ConstantArray: | 
|  | 4940 | return lldb::eFormatVoid; // no value | 
|  | 4941 |  | 
|  | 4942 | case clang::Type::ExtVector: | 
|  | 4943 | case clang::Type::Vector: | 
|  | 4944 | break; | 
|  | 4945 |  | 
|  | 4946 | case clang::Type::Builtin: | 
|  | 4947 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) | 
|  | 4948 | { | 
|  | 4949 | //default: assert(0 && "Unknown builtin type!"); | 
|  | 4950 | case clang::BuiltinType::UnknownAny: | 
|  | 4951 | case clang::BuiltinType::Void: | 
|  | 4952 | case clang::BuiltinType::BoundMember: | 
|  | 4953 | break; | 
|  | 4954 |  | 
|  | 4955 | case clang::BuiltinType::Bool:          return lldb::eFormatBoolean; | 
|  | 4956 | case clang::BuiltinType::Char_S: | 
|  | 4957 | case clang::BuiltinType::SChar: | 
|  | 4958 | case clang::BuiltinType::WChar_S: | 
|  | 4959 | case clang::BuiltinType::Char_U: | 
|  | 4960 | case clang::BuiltinType::UChar: | 
|  | 4961 | case clang::BuiltinType::WChar_U:       return lldb::eFormatChar; | 
|  | 4962 | case clang::BuiltinType::Char16:        return lldb::eFormatUnicode16; | 
|  | 4963 | case clang::BuiltinType::Char32:        return lldb::eFormatUnicode32; | 
|  | 4964 | case clang::BuiltinType::UShort:        return lldb::eFormatUnsigned; | 
|  | 4965 | case clang::BuiltinType::Short:         return lldb::eFormatDecimal; | 
|  | 4966 | case clang::BuiltinType::UInt:          return lldb::eFormatUnsigned; | 
|  | 4967 | case clang::BuiltinType::Int:           return lldb::eFormatDecimal; | 
|  | 4968 | case clang::BuiltinType::ULong:         return lldb::eFormatUnsigned; | 
|  | 4969 | case clang::BuiltinType::Long:          return lldb::eFormatDecimal; | 
|  | 4970 | case clang::BuiltinType::ULongLong:     return lldb::eFormatUnsigned; | 
|  | 4971 | case clang::BuiltinType::LongLong:      return lldb::eFormatDecimal; | 
|  | 4972 | case clang::BuiltinType::UInt128:       return lldb::eFormatUnsigned; | 
|  | 4973 | case clang::BuiltinType::Int128:        return lldb::eFormatDecimal; | 
| Greg Clayton | dee40e7 | 2015-11-03 23:23:22 +0000 | [diff] [blame] | 4974 | case clang::BuiltinType::Half: | 
|  | 4975 | case clang::BuiltinType::Float: | 
|  | 4976 | case clang::BuiltinType::Double: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4977 | case clang::BuiltinType::LongDouble:    return lldb::eFormatFloat; | 
| Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 4978 | default: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 4979 | return lldb::eFormatHex; | 
|  | 4980 | } | 
|  | 4981 | break; | 
|  | 4982 | case clang::Type::ObjCObjectPointer:        return lldb::eFormatHex; | 
|  | 4983 | case clang::Type::BlockPointer:             return lldb::eFormatHex; | 
|  | 4984 | case clang::Type::Pointer:                  return lldb::eFormatHex; | 
|  | 4985 | case clang::Type::LValueReference: | 
|  | 4986 | case clang::Type::RValueReference:          return lldb::eFormatHex; | 
|  | 4987 | case clang::Type::MemberPointer:            break; | 
|  | 4988 | case clang::Type::Complex: | 
|  | 4989 | { | 
|  | 4990 | if (qual_type->isComplexType()) | 
|  | 4991 | return lldb::eFormatComplex; | 
|  | 4992 | else | 
|  | 4993 | return lldb::eFormatComplexInteger; | 
|  | 4994 | } | 
|  | 4995 | case clang::Type::ObjCInterface:            break; | 
|  | 4996 | case clang::Type::Record:                   break; | 
|  | 4997 | case clang::Type::Enum:                     return lldb::eFormatEnum; | 
|  | 4998 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4999 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetFormat(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5000 | case clang::Type::Auto: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5001 | return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->desugar()).GetFormat(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5002 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5003 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetFormat(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5004 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5005 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetFormat(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5006 | case clang::Type::DependentSizedArray: | 
|  | 5007 | case clang::Type::DependentSizedExtVector: | 
|  | 5008 | case clang::Type::UnresolvedUsing: | 
|  | 5009 | case clang::Type::Attributed: | 
|  | 5010 | case clang::Type::TemplateTypeParm: | 
|  | 5011 | case clang::Type::SubstTemplateTypeParm: | 
|  | 5012 | case clang::Type::SubstTemplateTypeParmPack: | 
|  | 5013 | case clang::Type::InjectedClassName: | 
|  | 5014 | case clang::Type::DependentName: | 
|  | 5015 | case clang::Type::DependentTemplateSpecialization: | 
|  | 5016 | case clang::Type::PackExpansion: | 
|  | 5017 | case clang::Type::ObjCObject: | 
|  | 5018 |  | 
|  | 5019 | case clang::Type::TypeOfExpr: | 
|  | 5020 | case clang::Type::TypeOf: | 
|  | 5021 | case clang::Type::Decltype: | 
|  | 5022 | case clang::Type::TemplateSpecialization: | 
|  | 5023 | case clang::Type::Atomic: | 
|  | 5024 | case clang::Type::Adjusted: | 
| Pavel Labath | 484f0a3 | 2016-01-12 08:51:28 +0000 | [diff] [blame] | 5025 | case clang::Type::Pipe: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5026 | break; | 
|  | 5027 |  | 
|  | 5028 | // pointer type decayed from an array or function type. | 
|  | 5029 | case clang::Type::Decayed: | 
|  | 5030 | break; | 
|  | 5031 | } | 
|  | 5032 | // We don't know hot to display this type... | 
|  | 5033 | return lldb::eFormatBytes; | 
|  | 5034 | } | 
|  | 5035 |  | 
|  | 5036 | static bool | 
|  | 5037 | ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl, bool check_superclass) | 
|  | 5038 | { | 
|  | 5039 | while (class_interface_decl) | 
|  | 5040 | { | 
|  | 5041 | if (class_interface_decl->ivar_size() > 0) | 
|  | 5042 | return true; | 
|  | 5043 |  | 
|  | 5044 | if (check_superclass) | 
|  | 5045 | class_interface_decl = class_interface_decl->getSuperClass(); | 
|  | 5046 | else | 
|  | 5047 | break; | 
|  | 5048 | } | 
|  | 5049 | return false; | 
|  | 5050 | } | 
|  | 5051 |  | 
|  | 5052 | uint32_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5053 | 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] | 5054 | { | 
|  | 5055 | if (!type) | 
|  | 5056 | return 0; | 
|  | 5057 |  | 
|  | 5058 | uint32_t num_children = 0; | 
|  | 5059 | clang::QualType qual_type(GetQualType(type)); | 
|  | 5060 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5061 | switch (type_class) | 
|  | 5062 | { | 
|  | 5063 | case clang::Type::Builtin: | 
|  | 5064 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) | 
|  | 5065 | { | 
|  | 5066 | case clang::BuiltinType::ObjCId:    // child is Class | 
|  | 5067 | case clang::BuiltinType::ObjCClass: // child is Class | 
|  | 5068 | num_children = 1; | 
|  | 5069 | break; | 
|  | 5070 |  | 
|  | 5071 | default: | 
|  | 5072 | break; | 
|  | 5073 | } | 
|  | 5074 | break; | 
|  | 5075 |  | 
|  | 5076 | case clang::Type::Complex: return 0; | 
|  | 5077 |  | 
|  | 5078 | case clang::Type::Record: | 
|  | 5079 | if (GetCompleteQualType (getASTContext(), qual_type)) | 
|  | 5080 | { | 
|  | 5081 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 5082 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 5083 | assert(record_decl); | 
|  | 5084 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 5085 | if (cxx_record_decl) | 
|  | 5086 | { | 
|  | 5087 | if (omit_empty_base_classes) | 
|  | 5088 | { | 
|  | 5089 | // Check each base classes to see if it or any of its | 
|  | 5090 | // base classes contain any fields. This can help | 
|  | 5091 | // limit the noise in variable views by not having to | 
|  | 5092 | // show base classes that contain no members. | 
|  | 5093 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 5094 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); | 
|  | 5095 | base_class != base_class_end; | 
|  | 5096 | ++base_class) | 
|  | 5097 | { | 
|  | 5098 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); | 
|  | 5099 |  | 
|  | 5100 | // Skip empty base classes | 
|  | 5101 | if (ClangASTContext::RecordHasFields(base_class_decl) == false) | 
|  | 5102 | continue; | 
|  | 5103 |  | 
|  | 5104 | num_children++; | 
|  | 5105 | } | 
|  | 5106 | } | 
|  | 5107 | else | 
|  | 5108 | { | 
|  | 5109 | // Include all base classes | 
|  | 5110 | num_children += cxx_record_decl->getNumBases(); | 
|  | 5111 | } | 
|  | 5112 |  | 
|  | 5113 | } | 
|  | 5114 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 5115 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field) | 
|  | 5116 | ++num_children; | 
|  | 5117 | } | 
|  | 5118 | break; | 
|  | 5119 |  | 
|  | 5120 | case clang::Type::ObjCObject: | 
|  | 5121 | case clang::Type::ObjCInterface: | 
|  | 5122 | if (GetCompleteQualType (getASTContext(), qual_type)) | 
|  | 5123 | { | 
|  | 5124 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 5125 | assert (objc_class_type); | 
|  | 5126 | if (objc_class_type) | 
|  | 5127 | { | 
|  | 5128 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 5129 |  | 
|  | 5130 | if (class_interface_decl) | 
|  | 5131 | { | 
|  | 5132 |  | 
|  | 5133 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); | 
|  | 5134 | if (superclass_interface_decl) | 
|  | 5135 | { | 
|  | 5136 | if (omit_empty_base_classes) | 
|  | 5137 | { | 
|  | 5138 | if (ObjCDeclHasIVars (superclass_interface_decl, true)) | 
|  | 5139 | ++num_children; | 
|  | 5140 | } | 
|  | 5141 | else | 
|  | 5142 | ++num_children; | 
|  | 5143 | } | 
|  | 5144 |  | 
|  | 5145 | num_children += class_interface_decl->ivar_size(); | 
|  | 5146 | } | 
|  | 5147 | } | 
|  | 5148 | } | 
|  | 5149 | break; | 
|  | 5150 |  | 
|  | 5151 | case clang::Type::ObjCObjectPointer: | 
|  | 5152 | { | 
|  | 5153 | const clang::ObjCObjectPointerType *pointer_type = llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr()); | 
|  | 5154 | clang::QualType pointee_type = pointer_type->getPointeeType(); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5155 | 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] | 5156 | // If this type points to a simple type, then it has 1 child | 
|  | 5157 | if (num_pointee_children == 0) | 
|  | 5158 | num_children = 1; | 
|  | 5159 | else | 
|  | 5160 | num_children = num_pointee_children; | 
|  | 5161 | } | 
|  | 5162 | break; | 
|  | 5163 |  | 
|  | 5164 | case clang::Type::Vector: | 
|  | 5165 | case clang::Type::ExtVector: | 
|  | 5166 | num_children = llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements(); | 
|  | 5167 | break; | 
|  | 5168 |  | 
|  | 5169 | case clang::Type::ConstantArray: | 
|  | 5170 | num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())->getSize().getLimitedValue(); | 
|  | 5171 | break; | 
|  | 5172 |  | 
|  | 5173 | case clang::Type::Pointer: | 
|  | 5174 | { | 
|  | 5175 | const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr()); | 
|  | 5176 | clang::QualType pointee_type (pointer_type->getPointeeType()); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5177 | 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] | 5178 | if (num_pointee_children == 0) | 
|  | 5179 | { | 
|  | 5180 | // We have a pointer to a pointee type that claims it has no children. | 
|  | 5181 | // We will want to look at | 
|  | 5182 | num_children = GetNumPointeeChildren (pointee_type); | 
|  | 5183 | } | 
|  | 5184 | else | 
|  | 5185 | num_children = num_pointee_children; | 
|  | 5186 | } | 
|  | 5187 | break; | 
|  | 5188 |  | 
|  | 5189 | case clang::Type::LValueReference: | 
|  | 5190 | case clang::Type::RValueReference: | 
|  | 5191 | { | 
|  | 5192 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); | 
|  | 5193 | clang::QualType pointee_type = reference_type->getPointeeType(); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5194 | 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] | 5195 | // If this type points to a simple type, then it has 1 child | 
|  | 5196 | if (num_pointee_children == 0) | 
|  | 5197 | num_children = 1; | 
|  | 5198 | else | 
|  | 5199 | num_children = num_pointee_children; | 
|  | 5200 | } | 
|  | 5201 | break; | 
|  | 5202 |  | 
|  | 5203 |  | 
|  | 5204 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5205 | 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] | 5206 | break; | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5207 |  | 
|  | 5208 | case clang::Type::Auto: | 
|  | 5209 | num_children = CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumChildren (omit_empty_base_classes); | 
|  | 5210 | break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5211 |  | 
|  | 5212 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5213 | 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] | 5214 | break; | 
|  | 5215 |  | 
|  | 5216 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5217 | 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] | 5218 | break; | 
|  | 5219 | default: | 
|  | 5220 | break; | 
|  | 5221 | } | 
|  | 5222 | return num_children; | 
|  | 5223 | } | 
|  | 5224 |  | 
| Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 5225 | CompilerType | 
|  | 5226 | ClangASTContext::GetBuiltinTypeByName (const ConstString &name) | 
|  | 5227 | { | 
|  | 5228 | return GetBasicType (GetBasicTypeEnumeration (name)); | 
|  | 5229 | } | 
|  | 5230 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5231 | lldb::BasicType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5232 | ClangASTContext::GetBasicTypeEnumeration (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5233 | { | 
|  | 5234 | if (type) | 
|  | 5235 | { | 
|  | 5236 | clang::QualType qual_type(GetQualType(type)); | 
|  | 5237 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5238 | if (type_class == clang::Type::Builtin) | 
|  | 5239 | { | 
|  | 5240 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) | 
|  | 5241 | { | 
|  | 5242 | case clang::BuiltinType::Void:      return eBasicTypeVoid; | 
|  | 5243 | case clang::BuiltinType::Bool:      return eBasicTypeBool; | 
|  | 5244 | case clang::BuiltinType::Char_S:    return eBasicTypeSignedChar; | 
|  | 5245 | case clang::BuiltinType::Char_U:    return eBasicTypeUnsignedChar; | 
|  | 5246 | case clang::BuiltinType::Char16:    return eBasicTypeChar16; | 
|  | 5247 | case clang::BuiltinType::Char32:    return eBasicTypeChar32; | 
|  | 5248 | case clang::BuiltinType::UChar:     return eBasicTypeUnsignedChar; | 
|  | 5249 | case clang::BuiltinType::SChar:     return eBasicTypeSignedChar; | 
|  | 5250 | case clang::BuiltinType::WChar_S:   return eBasicTypeSignedWChar; | 
|  | 5251 | case clang::BuiltinType::WChar_U:   return eBasicTypeUnsignedWChar; | 
|  | 5252 | case clang::BuiltinType::Short:     return eBasicTypeShort; | 
|  | 5253 | case clang::BuiltinType::UShort:    return eBasicTypeUnsignedShort; | 
|  | 5254 | case clang::BuiltinType::Int:       return eBasicTypeInt; | 
|  | 5255 | case clang::BuiltinType::UInt:      return eBasicTypeUnsignedInt; | 
|  | 5256 | case clang::BuiltinType::Long:      return eBasicTypeLong; | 
|  | 5257 | case clang::BuiltinType::ULong:     return eBasicTypeUnsignedLong; | 
|  | 5258 | case clang::BuiltinType::LongLong:  return eBasicTypeLongLong; | 
|  | 5259 | case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong; | 
|  | 5260 | case clang::BuiltinType::Int128:    return eBasicTypeInt128; | 
|  | 5261 | case clang::BuiltinType::UInt128:   return eBasicTypeUnsignedInt128; | 
|  | 5262 |  | 
|  | 5263 | case clang::BuiltinType::Half:      return eBasicTypeHalf; | 
|  | 5264 | case clang::BuiltinType::Float:     return eBasicTypeFloat; | 
|  | 5265 | case clang::BuiltinType::Double:    return eBasicTypeDouble; | 
|  | 5266 | case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble; | 
|  | 5267 |  | 
|  | 5268 | case clang::BuiltinType::NullPtr:   return eBasicTypeNullPtr; | 
|  | 5269 | case clang::BuiltinType::ObjCId:    return eBasicTypeObjCID; | 
|  | 5270 | case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass; | 
|  | 5271 | case clang::BuiltinType::ObjCSel:   return eBasicTypeObjCSel; | 
| Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 5272 | default: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5273 | return eBasicTypeOther; | 
|  | 5274 | } | 
|  | 5275 | } | 
|  | 5276 | } | 
|  | 5277 | return eBasicTypeInvalid; | 
|  | 5278 | } | 
|  | 5279 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5280 | void | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5281 | 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] | 5282 | { | 
|  | 5283 | const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)); | 
|  | 5284 | if (enum_type) | 
|  | 5285 | { | 
|  | 5286 | const clang::EnumDecl *enum_decl = enum_type->getDecl(); | 
|  | 5287 | if (enum_decl) | 
|  | 5288 | { | 
|  | 5289 | CompilerType integer_type(this, enum_decl->getIntegerType().getAsOpaquePtr()); | 
|  | 5290 |  | 
|  | 5291 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; | 
|  | 5292 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) | 
|  | 5293 | { | 
|  | 5294 | ConstString name(enum_pos->getNameAsString().c_str()); | 
|  | 5295 | if (!callback (integer_type, name, enum_pos->getInitVal())) | 
|  | 5296 | break; | 
|  | 5297 | } | 
|  | 5298 | } | 
|  | 5299 | } | 
|  | 5300 | } | 
|  | 5301 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5302 |  | 
|  | 5303 | #pragma mark Aggregate Types | 
|  | 5304 |  | 
|  | 5305 | uint32_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5306 | ClangASTContext::GetNumFields (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5307 | { | 
|  | 5308 | if (!type) | 
|  | 5309 | return 0; | 
|  | 5310 |  | 
|  | 5311 | uint32_t count = 0; | 
|  | 5312 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 5313 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5314 | switch (type_class) | 
|  | 5315 | { | 
|  | 5316 | case clang::Type::Record: | 
|  | 5317 | if (GetCompleteType(type)) | 
|  | 5318 | { | 
|  | 5319 | const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 5320 | if (record_type) | 
|  | 5321 | { | 
|  | 5322 | clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 5323 | if (record_decl) | 
|  | 5324 | { | 
|  | 5325 | uint32_t field_idx = 0; | 
|  | 5326 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 5327 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field) | 
|  | 5328 | ++field_idx; | 
|  | 5329 | count = field_idx; | 
|  | 5330 | } | 
|  | 5331 | } | 
|  | 5332 | } | 
|  | 5333 | break; | 
|  | 5334 |  | 
|  | 5335 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5336 | count = CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumFields(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5337 | break; | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5338 |  | 
|  | 5339 | case clang::Type::Auto: | 
|  | 5340 | count = CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumFields(); | 
|  | 5341 | break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5342 |  | 
|  | 5343 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5344 | count = CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumFields(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5345 | break; | 
|  | 5346 |  | 
|  | 5347 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5348 | count = CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumFields(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5349 | break; | 
|  | 5350 |  | 
|  | 5351 | case clang::Type::ObjCObjectPointer: | 
|  | 5352 | if (GetCompleteType(type)) | 
|  | 5353 | { | 
|  | 5354 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); | 
|  | 5355 | if (objc_class_type) | 
|  | 5356 | { | 
|  | 5357 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); | 
|  | 5358 |  | 
|  | 5359 | if (class_interface_decl) | 
|  | 5360 | count = class_interface_decl->ivar_size(); | 
|  | 5361 | } | 
|  | 5362 | } | 
|  | 5363 | break; | 
|  | 5364 |  | 
|  | 5365 | case clang::Type::ObjCObject: | 
|  | 5366 | case clang::Type::ObjCInterface: | 
|  | 5367 | if (GetCompleteType(type)) | 
|  | 5368 | { | 
|  | 5369 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 5370 | if (objc_class_type) | 
|  | 5371 | { | 
|  | 5372 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 5373 |  | 
|  | 5374 | if (class_interface_decl) | 
|  | 5375 | count = class_interface_decl->ivar_size(); | 
|  | 5376 | } | 
|  | 5377 | } | 
|  | 5378 | break; | 
|  | 5379 |  | 
|  | 5380 | default: | 
|  | 5381 | break; | 
|  | 5382 | } | 
|  | 5383 | return count; | 
|  | 5384 | } | 
|  | 5385 |  | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5386 | static lldb::opaque_compiler_type_t | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5387 | GetObjCFieldAtIndex (clang::ASTContext *ast, | 
|  | 5388 | clang::ObjCInterfaceDecl *class_interface_decl, | 
|  | 5389 | size_t idx, | 
|  | 5390 | std::string& name, | 
|  | 5391 | uint64_t *bit_offset_ptr, | 
|  | 5392 | uint32_t *bitfield_bit_size_ptr, | 
|  | 5393 | bool *is_bitfield_ptr) | 
|  | 5394 | { | 
|  | 5395 | if (class_interface_decl) | 
|  | 5396 | { | 
|  | 5397 | if (idx < (class_interface_decl->ivar_size())) | 
|  | 5398 | { | 
|  | 5399 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); | 
|  | 5400 | uint32_t ivar_idx = 0; | 
|  | 5401 |  | 
|  | 5402 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++ivar_idx) | 
|  | 5403 | { | 
|  | 5404 | if (ivar_idx == idx) | 
|  | 5405 | { | 
|  | 5406 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; | 
|  | 5407 |  | 
|  | 5408 | clang::QualType ivar_qual_type(ivar_decl->getType()); | 
|  | 5409 |  | 
|  | 5410 | name.assign(ivar_decl->getNameAsString()); | 
|  | 5411 |  | 
|  | 5412 | if (bit_offset_ptr) | 
|  | 5413 | { | 
|  | 5414 | const clang::ASTRecordLayout &interface_layout = ast->getASTObjCInterfaceLayout(class_interface_decl); | 
|  | 5415 | *bit_offset_ptr = interface_layout.getFieldOffset (ivar_idx); | 
|  | 5416 | } | 
|  | 5417 |  | 
|  | 5418 | const bool is_bitfield = ivar_pos->isBitField(); | 
|  | 5419 |  | 
|  | 5420 | if (bitfield_bit_size_ptr) | 
|  | 5421 | { | 
|  | 5422 | *bitfield_bit_size_ptr = 0; | 
|  | 5423 |  | 
|  | 5424 | if (is_bitfield && ast) | 
|  | 5425 | { | 
|  | 5426 | clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth(); | 
|  | 5427 | llvm::APSInt bitfield_apsint; | 
|  | 5428 | if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *ast)) | 
|  | 5429 | { | 
|  | 5430 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); | 
|  | 5431 | } | 
|  | 5432 | } | 
|  | 5433 | } | 
|  | 5434 | if (is_bitfield_ptr) | 
|  | 5435 | *is_bitfield_ptr = is_bitfield; | 
|  | 5436 |  | 
|  | 5437 | return ivar_qual_type.getAsOpaquePtr(); | 
|  | 5438 | } | 
|  | 5439 | } | 
|  | 5440 | } | 
|  | 5441 | } | 
|  | 5442 | return nullptr; | 
|  | 5443 | } | 
|  | 5444 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5445 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5446 | ClangASTContext::GetFieldAtIndex (lldb::opaque_compiler_type_t type, size_t idx, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5447 | std::string& name, | 
|  | 5448 | uint64_t *bit_offset_ptr, | 
|  | 5449 | uint32_t *bitfield_bit_size_ptr, | 
|  | 5450 | bool *is_bitfield_ptr) | 
|  | 5451 | { | 
|  | 5452 | if (!type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5453 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5454 |  | 
|  | 5455 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 5456 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5457 | switch (type_class) | 
|  | 5458 | { | 
|  | 5459 | case clang::Type::Record: | 
|  | 5460 | if (GetCompleteType(type)) | 
|  | 5461 | { | 
|  | 5462 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 5463 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 5464 | uint32_t field_idx = 0; | 
|  | 5465 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 5466 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx) | 
|  | 5467 | { | 
|  | 5468 | if (idx == field_idx) | 
|  | 5469 | { | 
|  | 5470 | // Print the member type if requested | 
|  | 5471 | // Print the member name and equal sign | 
|  | 5472 | name.assign(field->getNameAsString()); | 
|  | 5473 |  | 
|  | 5474 | // Figure out the type byte size (field_type_info.first) and | 
|  | 5475 | // alignment (field_type_info.second) from the AST context. | 
|  | 5476 | if (bit_offset_ptr) | 
|  | 5477 | { | 
|  | 5478 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); | 
|  | 5479 | *bit_offset_ptr = record_layout.getFieldOffset (field_idx); | 
|  | 5480 | } | 
|  | 5481 |  | 
|  | 5482 | const bool is_bitfield = field->isBitField(); | 
|  | 5483 |  | 
|  | 5484 | if (bitfield_bit_size_ptr) | 
|  | 5485 | { | 
|  | 5486 | *bitfield_bit_size_ptr = 0; | 
|  | 5487 |  | 
|  | 5488 | if (is_bitfield) | 
|  | 5489 | { | 
|  | 5490 | clang::Expr *bitfield_bit_size_expr = field->getBitWidth(); | 
|  | 5491 | llvm::APSInt bitfield_apsint; | 
|  | 5492 | if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *getASTContext())) | 
|  | 5493 | { | 
|  | 5494 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); | 
|  | 5495 | } | 
|  | 5496 | } | 
|  | 5497 | } | 
|  | 5498 | if (is_bitfield_ptr) | 
|  | 5499 | *is_bitfield_ptr = is_bitfield; | 
|  | 5500 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5501 | return CompilerType (getASTContext(), field->getType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5502 | } | 
|  | 5503 | } | 
|  | 5504 | } | 
|  | 5505 | break; | 
|  | 5506 |  | 
|  | 5507 | case clang::Type::ObjCObjectPointer: | 
|  | 5508 | if (GetCompleteType(type)) | 
|  | 5509 | { | 
|  | 5510 | const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType(); | 
|  | 5511 | if (objc_class_type) | 
|  | 5512 | { | 
|  | 5513 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl(); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5514 | 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] | 5515 | } | 
|  | 5516 | } | 
|  | 5517 | break; | 
|  | 5518 |  | 
|  | 5519 | case clang::Type::ObjCObject: | 
|  | 5520 | case clang::Type::ObjCInterface: | 
|  | 5521 | if (GetCompleteType(type)) | 
|  | 5522 | { | 
|  | 5523 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 5524 | assert (objc_class_type); | 
|  | 5525 | if (objc_class_type) | 
|  | 5526 | { | 
|  | 5527 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5528 | 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] | 5529 | } | 
|  | 5530 | } | 
|  | 5531 | break; | 
|  | 5532 |  | 
|  | 5533 |  | 
|  | 5534 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5535 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()). | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5536 | GetFieldAtIndex (idx, | 
|  | 5537 | name, | 
|  | 5538 | bit_offset_ptr, | 
|  | 5539 | bitfield_bit_size_ptr, | 
|  | 5540 | is_bitfield_ptr); | 
|  | 5541 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5542 | case clang::Type::Auto: | 
|  | 5543 | return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()). | 
|  | 5544 | GetFieldAtIndex (idx, | 
|  | 5545 | name, | 
|  | 5546 | bit_offset_ptr, | 
|  | 5547 | bitfield_bit_size_ptr, | 
|  | 5548 | is_bitfield_ptr); | 
|  | 5549 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5550 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5551 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()). | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5552 | GetFieldAtIndex (idx, | 
|  | 5553 | name, | 
|  | 5554 | bit_offset_ptr, | 
|  | 5555 | bitfield_bit_size_ptr, | 
|  | 5556 | is_bitfield_ptr); | 
|  | 5557 |  | 
|  | 5558 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5559 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()). | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5560 | GetFieldAtIndex (idx, | 
|  | 5561 | name, | 
|  | 5562 | bit_offset_ptr, | 
|  | 5563 | bitfield_bit_size_ptr, | 
|  | 5564 | is_bitfield_ptr); | 
|  | 5565 |  | 
|  | 5566 | default: | 
|  | 5567 | break; | 
|  | 5568 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5569 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5570 | } | 
|  | 5571 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5572 | uint32_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5573 | ClangASTContext::GetNumDirectBaseClasses (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5574 | { | 
|  | 5575 | uint32_t count = 0; | 
|  | 5576 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 5577 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5578 | switch (type_class) | 
|  | 5579 | { | 
|  | 5580 | case clang::Type::Record: | 
|  | 5581 | if (GetCompleteType(type)) | 
|  | 5582 | { | 
|  | 5583 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 5584 | if (cxx_record_decl) | 
|  | 5585 | count = cxx_record_decl->getNumBases(); | 
|  | 5586 | } | 
|  | 5587 | break; | 
|  | 5588 |  | 
|  | 5589 | case clang::Type::ObjCObjectPointer: | 
|  | 5590 | count = GetPointeeType(type).GetNumDirectBaseClasses(); | 
|  | 5591 | break; | 
|  | 5592 |  | 
|  | 5593 | case clang::Type::ObjCObject: | 
|  | 5594 | if (GetCompleteType(type)) | 
|  | 5595 | { | 
|  | 5596 | const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType(); | 
|  | 5597 | if (objc_class_type) | 
|  | 5598 | { | 
|  | 5599 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 5600 |  | 
|  | 5601 | if (class_interface_decl && class_interface_decl->getSuperClass()) | 
|  | 5602 | count = 1; | 
|  | 5603 | } | 
|  | 5604 | } | 
|  | 5605 | break; | 
|  | 5606 | case clang::Type::ObjCInterface: | 
|  | 5607 | if (GetCompleteType(type)) | 
|  | 5608 | { | 
|  | 5609 | const clang::ObjCInterfaceType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>(); | 
|  | 5610 | if (objc_interface_type) | 
|  | 5611 | { | 
|  | 5612 | clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface(); | 
|  | 5613 |  | 
|  | 5614 | if (class_interface_decl && class_interface_decl->getSuperClass()) | 
|  | 5615 | count = 1; | 
|  | 5616 | } | 
|  | 5617 | } | 
|  | 5618 | break; | 
|  | 5619 |  | 
|  | 5620 |  | 
|  | 5621 | case clang::Type::Typedef: | 
|  | 5622 | count = GetNumDirectBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); | 
|  | 5623 | break; | 
|  | 5624 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5625 | case clang::Type::Auto: | 
|  | 5626 | count = GetNumDirectBaseClasses(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()); | 
|  | 5627 | break; | 
|  | 5628 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5629 | case clang::Type::Elaborated: | 
|  | 5630 | count = GetNumDirectBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); | 
|  | 5631 | break; | 
|  | 5632 |  | 
|  | 5633 | case clang::Type::Paren: | 
|  | 5634 | return GetNumDirectBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); | 
|  | 5635 |  | 
|  | 5636 | default: | 
|  | 5637 | break; | 
|  | 5638 | } | 
|  | 5639 | return count; | 
|  | 5640 |  | 
|  | 5641 | } | 
|  | 5642 |  | 
|  | 5643 | uint32_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5644 | ClangASTContext::GetNumVirtualBaseClasses (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5645 | { | 
|  | 5646 | uint32_t count = 0; | 
|  | 5647 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 5648 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5649 | switch (type_class) | 
|  | 5650 | { | 
|  | 5651 | case clang::Type::Record: | 
|  | 5652 | if (GetCompleteType(type)) | 
|  | 5653 | { | 
|  | 5654 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 5655 | if (cxx_record_decl) | 
|  | 5656 | count = cxx_record_decl->getNumVBases(); | 
|  | 5657 | } | 
|  | 5658 | break; | 
|  | 5659 |  | 
|  | 5660 | case clang::Type::Typedef: | 
|  | 5661 | count = GetNumVirtualBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); | 
|  | 5662 | break; | 
|  | 5663 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5664 | case clang::Type::Auto: | 
|  | 5665 | count = GetNumVirtualBaseClasses(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()); | 
|  | 5666 | break; | 
|  | 5667 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5668 | case clang::Type::Elaborated: | 
|  | 5669 | count = GetNumVirtualBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); | 
|  | 5670 | break; | 
|  | 5671 |  | 
|  | 5672 | case clang::Type::Paren: | 
|  | 5673 | count = GetNumVirtualBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()); | 
|  | 5674 | break; | 
|  | 5675 |  | 
|  | 5676 | default: | 
|  | 5677 | break; | 
|  | 5678 | } | 
|  | 5679 | return count; | 
|  | 5680 |  | 
|  | 5681 | } | 
|  | 5682 |  | 
|  | 5683 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5684 | 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] | 5685 | { | 
|  | 5686 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 5687 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5688 | switch (type_class) | 
|  | 5689 | { | 
|  | 5690 | case clang::Type::Record: | 
|  | 5691 | if (GetCompleteType(type)) | 
|  | 5692 | { | 
|  | 5693 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 5694 | if (cxx_record_decl) | 
|  | 5695 | { | 
|  | 5696 | uint32_t curr_idx = 0; | 
|  | 5697 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 5698 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); | 
|  | 5699 | base_class != base_class_end; | 
|  | 5700 | ++base_class, ++curr_idx) | 
|  | 5701 | { | 
|  | 5702 | if (curr_idx == idx) | 
|  | 5703 | { | 
|  | 5704 | if (bit_offset_ptr) | 
|  | 5705 | { | 
|  | 5706 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl); | 
|  | 5707 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); | 
|  | 5708 | if (base_class->isVirtual()) | 
|  | 5709 | *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; | 
|  | 5710 | else | 
|  | 5711 | *bit_offset_ptr = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; | 
|  | 5712 | } | 
|  | 5713 | return CompilerType (this, base_class->getType().getAsOpaquePtr()); | 
|  | 5714 | } | 
|  | 5715 | } | 
|  | 5716 | } | 
|  | 5717 | } | 
|  | 5718 | break; | 
|  | 5719 |  | 
|  | 5720 | case clang::Type::ObjCObjectPointer: | 
|  | 5721 | return GetPointeeType(type).GetDirectBaseClassAtIndex(idx, bit_offset_ptr); | 
|  | 5722 |  | 
|  | 5723 | case clang::Type::ObjCObject: | 
|  | 5724 | if (idx == 0 && GetCompleteType(type)) | 
|  | 5725 | { | 
|  | 5726 | const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType(); | 
|  | 5727 | if (objc_class_type) | 
|  | 5728 | { | 
|  | 5729 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 5730 |  | 
|  | 5731 | if (class_interface_decl) | 
|  | 5732 | { | 
|  | 5733 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); | 
|  | 5734 | if (superclass_interface_decl) | 
|  | 5735 | { | 
|  | 5736 | if (bit_offset_ptr) | 
|  | 5737 | *bit_offset_ptr = 0; | 
|  | 5738 | return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); | 
|  | 5739 | } | 
|  | 5740 | } | 
|  | 5741 | } | 
|  | 5742 | } | 
|  | 5743 | break; | 
|  | 5744 | case clang::Type::ObjCInterface: | 
|  | 5745 | if (idx == 0 && GetCompleteType(type)) | 
|  | 5746 | { | 
|  | 5747 | const clang::ObjCObjectType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>(); | 
|  | 5748 | if (objc_interface_type) | 
|  | 5749 | { | 
|  | 5750 | clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface(); | 
|  | 5751 |  | 
|  | 5752 | if (class_interface_decl) | 
|  | 5753 | { | 
|  | 5754 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); | 
|  | 5755 | if (superclass_interface_decl) | 
|  | 5756 | { | 
|  | 5757 | if (bit_offset_ptr) | 
|  | 5758 | *bit_offset_ptr = 0; | 
|  | 5759 | return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); | 
|  | 5760 | } | 
|  | 5761 | } | 
|  | 5762 | } | 
|  | 5763 | } | 
|  | 5764 | break; | 
|  | 5765 |  | 
|  | 5766 |  | 
|  | 5767 | case clang::Type::Typedef: | 
|  | 5768 | return GetDirectBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr); | 
|  | 5769 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5770 | case clang::Type::Auto: | 
|  | 5771 | return GetDirectBaseClassAtIndex (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx, bit_offset_ptr); | 
|  | 5772 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5773 | case clang::Type::Elaborated: | 
|  | 5774 | return GetDirectBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr); | 
|  | 5775 |  | 
|  | 5776 | case clang::Type::Paren: | 
|  | 5777 | return GetDirectBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr); | 
|  | 5778 |  | 
|  | 5779 | default: | 
|  | 5780 | break; | 
|  | 5781 | } | 
|  | 5782 | return CompilerType(); | 
|  | 5783 | } | 
|  | 5784 |  | 
|  | 5785 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5786 | ClangASTContext::GetVirtualBaseClassAtIndex (lldb::opaque_compiler_type_t type, | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5787 | size_t idx, | 
|  | 5788 | uint32_t *bit_offset_ptr) | 
|  | 5789 | { | 
|  | 5790 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 5791 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5792 | switch (type_class) | 
|  | 5793 | { | 
|  | 5794 | case clang::Type::Record: | 
|  | 5795 | if (GetCompleteType(type)) | 
|  | 5796 | { | 
|  | 5797 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 5798 | if (cxx_record_decl) | 
|  | 5799 | { | 
|  | 5800 | uint32_t curr_idx = 0; | 
|  | 5801 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 5802 | for (base_class = cxx_record_decl->vbases_begin(), base_class_end = cxx_record_decl->vbases_end(); | 
|  | 5803 | base_class != base_class_end; | 
|  | 5804 | ++base_class, ++curr_idx) | 
|  | 5805 | { | 
|  | 5806 | if (curr_idx == idx) | 
|  | 5807 | { | 
|  | 5808 | if (bit_offset_ptr) | 
|  | 5809 | { | 
|  | 5810 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl); | 
|  | 5811 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); | 
|  | 5812 | *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; | 
|  | 5813 |  | 
|  | 5814 | } | 
|  | 5815 | return CompilerType (this, base_class->getType().getAsOpaquePtr()); | 
|  | 5816 | } | 
|  | 5817 | } | 
|  | 5818 | } | 
|  | 5819 | } | 
|  | 5820 | break; | 
|  | 5821 |  | 
|  | 5822 | case clang::Type::Typedef: | 
|  | 5823 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5824 |  | 
|  | 5825 | case clang::Type::Auto: | 
|  | 5826 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx, bit_offset_ptr); | 
|  | 5827 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 5828 | case clang::Type::Elaborated: | 
|  | 5829 | return GetVirtualBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr); | 
|  | 5830 |  | 
|  | 5831 | case clang::Type::Paren: | 
|  | 5832 | return  GetVirtualBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr); | 
|  | 5833 |  | 
|  | 5834 | default: | 
|  | 5835 | break; | 
|  | 5836 | } | 
|  | 5837 | return CompilerType(); | 
|  | 5838 |  | 
|  | 5839 | } | 
|  | 5840 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5841 | // If a pointer to a pointee type (the clang_type arg) says that it has no | 
|  | 5842 | // children, then we either need to trust it, or override it and return a | 
|  | 5843 | // different result. For example, an "int *" has one child that is an integer, | 
|  | 5844 | // but a function pointer doesn't have any children. Likewise if a Record type | 
|  | 5845 | // claims it has no children, then there really is nothing to show. | 
|  | 5846 | uint32_t | 
|  | 5847 | ClangASTContext::GetNumPointeeChildren (clang::QualType type) | 
|  | 5848 | { | 
|  | 5849 | if (type.isNull()) | 
|  | 5850 | return 0; | 
|  | 5851 |  | 
|  | 5852 | clang::QualType qual_type(type.getCanonicalType()); | 
|  | 5853 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 5854 | switch (type_class) | 
|  | 5855 | { | 
|  | 5856 | case clang::Type::Builtin: | 
|  | 5857 | switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind()) | 
|  | 5858 | { | 
|  | 5859 | case clang::BuiltinType::UnknownAny: | 
|  | 5860 | case clang::BuiltinType::Void: | 
|  | 5861 | case clang::BuiltinType::NullPtr: | 
|  | 5862 | case clang::BuiltinType::OCLEvent: | 
|  | 5863 | case clang::BuiltinType::OCLImage1d: | 
|  | 5864 | case clang::BuiltinType::OCLImage1dArray: | 
|  | 5865 | case clang::BuiltinType::OCLImage1dBuffer: | 
|  | 5866 | case clang::BuiltinType::OCLImage2d: | 
|  | 5867 | case clang::BuiltinType::OCLImage2dArray: | 
|  | 5868 | case clang::BuiltinType::OCLImage3d: | 
|  | 5869 | case clang::BuiltinType::OCLSampler: | 
|  | 5870 | return 0; | 
|  | 5871 | case clang::BuiltinType::Bool: | 
|  | 5872 | case clang::BuiltinType::Char_U: | 
|  | 5873 | case clang::BuiltinType::UChar: | 
|  | 5874 | case clang::BuiltinType::WChar_U: | 
|  | 5875 | case clang::BuiltinType::Char16: | 
|  | 5876 | case clang::BuiltinType::Char32: | 
|  | 5877 | case clang::BuiltinType::UShort: | 
|  | 5878 | case clang::BuiltinType::UInt: | 
|  | 5879 | case clang::BuiltinType::ULong: | 
|  | 5880 | case clang::BuiltinType::ULongLong: | 
|  | 5881 | case clang::BuiltinType::UInt128: | 
|  | 5882 | case clang::BuiltinType::Char_S: | 
|  | 5883 | case clang::BuiltinType::SChar: | 
|  | 5884 | case clang::BuiltinType::WChar_S: | 
|  | 5885 | case clang::BuiltinType::Short: | 
|  | 5886 | case clang::BuiltinType::Int: | 
|  | 5887 | case clang::BuiltinType::Long: | 
|  | 5888 | case clang::BuiltinType::LongLong: | 
|  | 5889 | case clang::BuiltinType::Int128: | 
|  | 5890 | case clang::BuiltinType::Float: | 
|  | 5891 | case clang::BuiltinType::Double: | 
|  | 5892 | case clang::BuiltinType::LongDouble: | 
|  | 5893 | case clang::BuiltinType::Dependent: | 
|  | 5894 | case clang::BuiltinType::Overload: | 
|  | 5895 | case clang::BuiltinType::ObjCId: | 
|  | 5896 | case clang::BuiltinType::ObjCClass: | 
|  | 5897 | case clang::BuiltinType::ObjCSel: | 
|  | 5898 | case clang::BuiltinType::BoundMember: | 
|  | 5899 | case clang::BuiltinType::Half: | 
|  | 5900 | case clang::BuiltinType::ARCUnbridgedCast: | 
|  | 5901 | case clang::BuiltinType::PseudoObject: | 
|  | 5902 | case clang::BuiltinType::BuiltinFn: | 
| Zachary Turner | 84f5b0d | 2015-09-09 17:25:43 +0000 | [diff] [blame] | 5903 | case clang::BuiltinType::OMPArraySection: | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5904 | return 1; | 
| Zachary Turner | dd07e00 | 2015-09-16 18:08:45 +0000 | [diff] [blame] | 5905 | default: | 
|  | 5906 | return 0; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5907 | } | 
|  | 5908 | break; | 
|  | 5909 |  | 
|  | 5910 | case clang::Type::Complex:                  return 1; | 
|  | 5911 | case clang::Type::Pointer:                  return 1; | 
|  | 5912 | case clang::Type::BlockPointer:             return 0;   // If block pointers don't have debug info, then no children for them | 
|  | 5913 | case clang::Type::LValueReference:          return 1; | 
|  | 5914 | case clang::Type::RValueReference:          return 1; | 
|  | 5915 | case clang::Type::MemberPointer:            return 0; | 
|  | 5916 | case clang::Type::ConstantArray:            return 0; | 
|  | 5917 | case clang::Type::IncompleteArray:          return 0; | 
|  | 5918 | case clang::Type::VariableArray:            return 0; | 
|  | 5919 | case clang::Type::DependentSizedArray:      return 0; | 
|  | 5920 | case clang::Type::DependentSizedExtVector:  return 0; | 
|  | 5921 | case clang::Type::Vector:                   return 0; | 
|  | 5922 | case clang::Type::ExtVector:                return 0; | 
|  | 5923 | case clang::Type::FunctionProto:            return 0;   // When we function pointers, they have no children... | 
|  | 5924 | case clang::Type::FunctionNoProto:          return 0;   // When we function pointers, they have no children... | 
|  | 5925 | case clang::Type::UnresolvedUsing:          return 0; | 
|  | 5926 | case clang::Type::Paren:                    return GetNumPointeeChildren (llvm::cast<clang::ParenType>(qual_type)->desugar()); | 
|  | 5927 | case clang::Type::Typedef:                  return GetNumPointeeChildren (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 5928 | case clang::Type::Auto:                     return GetNumPointeeChildren (llvm::cast<clang::AutoType>(qual_type)->getDeducedType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5929 | case clang::Type::Elaborated:               return GetNumPointeeChildren (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()); | 
|  | 5930 | case clang::Type::TypeOfExpr:               return 0; | 
|  | 5931 | case clang::Type::TypeOf:                   return 0; | 
|  | 5932 | case clang::Type::Decltype:                 return 0; | 
|  | 5933 | case clang::Type::Record:                   return 0; | 
|  | 5934 | case clang::Type::Enum:                     return 1; | 
|  | 5935 | case clang::Type::TemplateTypeParm:         return 1; | 
|  | 5936 | case clang::Type::SubstTemplateTypeParm:    return 1; | 
|  | 5937 | case clang::Type::TemplateSpecialization:   return 1; | 
|  | 5938 | case clang::Type::InjectedClassName:        return 0; | 
|  | 5939 | case clang::Type::DependentName:            return 1; | 
|  | 5940 | case clang::Type::DependentTemplateSpecialization:  return 1; | 
|  | 5941 | case clang::Type::ObjCObject:               return 0; | 
|  | 5942 | case clang::Type::ObjCInterface:            return 0; | 
|  | 5943 | case clang::Type::ObjCObjectPointer:        return 1; | 
|  | 5944 | default: | 
|  | 5945 | break; | 
|  | 5946 | } | 
|  | 5947 | return 0; | 
|  | 5948 | } | 
|  | 5949 |  | 
|  | 5950 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5951 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 5952 | ClangASTContext::GetChildCompilerTypeAtIndex (lldb::opaque_compiler_type_t type, | 
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 5953 | ExecutionContext *exe_ctx, | 
|  | 5954 | size_t idx, | 
|  | 5955 | bool transparent_pointers, | 
|  | 5956 | bool omit_empty_base_classes, | 
|  | 5957 | bool ignore_array_bounds, | 
|  | 5958 | std::string& child_name, | 
|  | 5959 | uint32_t &child_byte_size, | 
|  | 5960 | int32_t &child_byte_offset, | 
|  | 5961 | uint32_t &child_bitfield_bit_size, | 
|  | 5962 | uint32_t &child_bitfield_bit_offset, | 
|  | 5963 | bool &child_is_base_class, | 
|  | 5964 | bool &child_is_deref_of_parent, | 
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 5965 | ValueObject *valobj, | 
|  | 5966 | uint64_t &language_flags) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5967 | { | 
|  | 5968 | if (!type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5969 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5970 |  | 
|  | 5971 | clang::QualType parent_qual_type(GetCanonicalQualType(type)); | 
|  | 5972 | const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass(); | 
|  | 5973 | child_bitfield_bit_size = 0; | 
|  | 5974 | child_bitfield_bit_offset = 0; | 
|  | 5975 | child_is_base_class = false; | 
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 5976 | language_flags = 0; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5977 |  | 
|  | 5978 | const bool idx_is_valid = idx < GetNumChildren (type, omit_empty_base_classes); | 
|  | 5979 | uint32_t bit_offset; | 
|  | 5980 | switch (parent_type_class) | 
|  | 5981 | { | 
|  | 5982 | case clang::Type::Builtin: | 
|  | 5983 | if (idx_is_valid) | 
|  | 5984 | { | 
|  | 5985 | switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind()) | 
|  | 5986 | { | 
|  | 5987 | case clang::BuiltinType::ObjCId: | 
|  | 5988 | case clang::BuiltinType::ObjCClass: | 
|  | 5989 | child_name = "isa"; | 
|  | 5990 | child_byte_size = getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) / CHAR_BIT; | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 5991 | return CompilerType (getASTContext(), getASTContext()->ObjCBuiltinClassTy); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 5992 |  | 
|  | 5993 | default: | 
|  | 5994 | break; | 
|  | 5995 | } | 
|  | 5996 | } | 
|  | 5997 | break; | 
|  | 5998 |  | 
|  | 5999 | case clang::Type::Record: | 
|  | 6000 | if (idx_is_valid && GetCompleteType(type)) | 
|  | 6001 | { | 
|  | 6002 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr()); | 
|  | 6003 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 6004 | assert(record_decl); | 
|  | 6005 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); | 
|  | 6006 | uint32_t child_idx = 0; | 
|  | 6007 |  | 
|  | 6008 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 6009 | if (cxx_record_decl) | 
|  | 6010 | { | 
|  | 6011 | // We might have base classes to print out first | 
|  | 6012 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 6013 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); | 
|  | 6014 | base_class != base_class_end; | 
|  | 6015 | ++base_class) | 
|  | 6016 | { | 
|  | 6017 | const clang::CXXRecordDecl *base_class_decl = nullptr; | 
|  | 6018 |  | 
|  | 6019 | // Skip empty base classes | 
|  | 6020 | if (omit_empty_base_classes) | 
|  | 6021 | { | 
|  | 6022 | base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); | 
|  | 6023 | if (ClangASTContext::RecordHasFields(base_class_decl) == false) | 
|  | 6024 | continue; | 
|  | 6025 | } | 
|  | 6026 |  | 
|  | 6027 | if (idx == child_idx) | 
|  | 6028 | { | 
|  | 6029 | if (base_class_decl == nullptr) | 
|  | 6030 | base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); | 
|  | 6031 |  | 
|  | 6032 |  | 
|  | 6033 | if (base_class->isVirtual()) | 
|  | 6034 | { | 
|  | 6035 | bool handled = false; | 
|  | 6036 | if (valobj) | 
|  | 6037 | { | 
|  | 6038 | Error err; | 
|  | 6039 | AddressType addr_type = eAddressTypeInvalid; | 
|  | 6040 | lldb::addr_t vtable_ptr_addr = valobj->GetCPPVTableAddress(addr_type); | 
|  | 6041 |  | 
|  | 6042 | if (vtable_ptr_addr != LLDB_INVALID_ADDRESS && addr_type == eAddressTypeLoad) | 
|  | 6043 | { | 
|  | 6044 |  | 
|  | 6045 | ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); | 
|  | 6046 | Process *process = exe_ctx.GetProcessPtr(); | 
|  | 6047 | if (process) | 
|  | 6048 | { | 
|  | 6049 | clang::VTableContextBase *vtable_ctx = getASTContext()->getVTableContext(); | 
|  | 6050 | if (vtable_ctx) | 
|  | 6051 | { | 
|  | 6052 | if (vtable_ctx->isMicrosoft()) | 
|  | 6053 | { | 
|  | 6054 | clang::MicrosoftVTableContext *msoft_vtable_ctx = static_cast<clang::MicrosoftVTableContext *>(vtable_ctx); | 
|  | 6055 |  | 
|  | 6056 | if (vtable_ptr_addr) | 
|  | 6057 | { | 
|  | 6058 | const lldb::addr_t vbtable_ptr_addr = vtable_ptr_addr + record_layout.getVBPtrOffset().getQuantity(); | 
|  | 6059 |  | 
|  | 6060 | const lldb::addr_t vbtable_ptr = process->ReadPointerFromMemory(vbtable_ptr_addr, err); | 
|  | 6061 | if (vbtable_ptr != LLDB_INVALID_ADDRESS) | 
|  | 6062 | { | 
|  | 6063 | // Get the index into the virtual base table. The index is the index in uint32_t from vbtable_ptr | 
|  | 6064 | const unsigned vbtable_index = msoft_vtable_ctx->getVBTableIndex(cxx_record_decl, base_class_decl); | 
|  | 6065 | const lldb::addr_t base_offset_addr = vbtable_ptr + vbtable_index * 4; | 
|  | 6066 | const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err); | 
|  | 6067 | if (base_offset != UINT32_MAX) | 
|  | 6068 | { | 
|  | 6069 | handled = true; | 
|  | 6070 | bit_offset = base_offset * 8; | 
|  | 6071 | } | 
|  | 6072 | } | 
|  | 6073 | } | 
|  | 6074 | } | 
|  | 6075 | else | 
|  | 6076 | { | 
|  | 6077 | clang::ItaniumVTableContext *itanium_vtable_ctx = static_cast<clang::ItaniumVTableContext *>(vtable_ctx); | 
|  | 6078 | if (vtable_ptr_addr) | 
|  | 6079 | { | 
|  | 6080 | const lldb::addr_t vtable_ptr = process->ReadPointerFromMemory(vtable_ptr_addr, err); | 
|  | 6081 | if (vtable_ptr != LLDB_INVALID_ADDRESS) | 
|  | 6082 | { | 
|  | 6083 | clang::CharUnits base_offset_offset = itanium_vtable_ctx->getVirtualBaseOffsetOffset(cxx_record_decl, base_class_decl); | 
|  | 6084 | const lldb::addr_t base_offset_addr = vtable_ptr + base_offset_offset.getQuantity(); | 
|  | 6085 | const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err); | 
|  | 6086 | if (base_offset != UINT32_MAX) | 
|  | 6087 | { | 
|  | 6088 | handled = true; | 
|  | 6089 | bit_offset = base_offset * 8; | 
|  | 6090 | } | 
|  | 6091 | } | 
|  | 6092 | } | 
|  | 6093 | } | 
|  | 6094 | } | 
|  | 6095 | } | 
|  | 6096 | } | 
|  | 6097 |  | 
|  | 6098 | } | 
|  | 6099 | if (!handled) | 
|  | 6100 | bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; | 
|  | 6101 | } | 
|  | 6102 | else | 
|  | 6103 | bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; | 
|  | 6104 |  | 
|  | 6105 | // Base classes should be a multiple of 8 bits in size | 
|  | 6106 | child_byte_offset = bit_offset/8; | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6107 | CompilerType base_class_clang_type(getASTContext(), base_class->getType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6108 | child_name = base_class_clang_type.GetTypeName().AsCString(""); | 
|  | 6109 | uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); | 
|  | 6110 |  | 
|  | 6111 | // Base classes bit sizes should be a multiple of 8 bits in size | 
|  | 6112 | assert (base_class_clang_type_bit_size % 8 == 0); | 
|  | 6113 | child_byte_size = base_class_clang_type_bit_size / 8; | 
|  | 6114 | child_is_base_class = true; | 
|  | 6115 | return base_class_clang_type; | 
|  | 6116 | } | 
|  | 6117 | // We don't increment the child index in the for loop since we might | 
|  | 6118 | // be skipping empty base classes | 
|  | 6119 | ++child_idx; | 
|  | 6120 | } | 
|  | 6121 | } | 
|  | 6122 | // Make sure index is in range... | 
|  | 6123 | uint32_t field_idx = 0; | 
|  | 6124 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 6125 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx) | 
|  | 6126 | { | 
|  | 6127 | if (idx == child_idx) | 
|  | 6128 | { | 
|  | 6129 | // Print the member type if requested | 
|  | 6130 | // Print the member name and equal sign | 
|  | 6131 | child_name.assign(field->getNameAsString().c_str()); | 
|  | 6132 |  | 
|  | 6133 | // Figure out the type byte size (field_type_info.first) and | 
|  | 6134 | // alignment (field_type_info.second) from the AST context. | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6135 | CompilerType field_clang_type (getASTContext(), field->getType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6136 | assert(field_idx < record_layout.getFieldCount()); | 
|  | 6137 | child_byte_size = field_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); | 
|  | 6138 |  | 
|  | 6139 | // Figure out the field offset within the current struct/union/class type | 
|  | 6140 | bit_offset = record_layout.getFieldOffset (field_idx); | 
|  | 6141 | child_byte_offset = bit_offset / 8; | 
|  | 6142 | if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, child_bitfield_bit_size)) | 
|  | 6143 | child_bitfield_bit_offset = bit_offset % 8; | 
|  | 6144 |  | 
|  | 6145 | return field_clang_type; | 
|  | 6146 | } | 
|  | 6147 | } | 
|  | 6148 | } | 
|  | 6149 | break; | 
|  | 6150 |  | 
|  | 6151 | case clang::Type::ObjCObject: | 
|  | 6152 | case clang::Type::ObjCInterface: | 
|  | 6153 | if (idx_is_valid && GetCompleteType(type)) | 
|  | 6154 | { | 
|  | 6155 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr()); | 
|  | 6156 | assert (objc_class_type); | 
|  | 6157 | if (objc_class_type) | 
|  | 6158 | { | 
|  | 6159 | uint32_t child_idx = 0; | 
|  | 6160 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 6161 |  | 
|  | 6162 | if (class_interface_decl) | 
|  | 6163 | { | 
|  | 6164 |  | 
|  | 6165 | const clang::ASTRecordLayout &interface_layout = getASTContext()->getASTObjCInterfaceLayout(class_interface_decl); | 
|  | 6166 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); | 
|  | 6167 | if (superclass_interface_decl) | 
|  | 6168 | { | 
|  | 6169 | if (omit_empty_base_classes) | 
|  | 6170 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6171 | CompilerType base_class_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6172 | if (base_class_clang_type.GetNumChildren(omit_empty_base_classes) > 0) | 
|  | 6173 | { | 
|  | 6174 | if (idx == 0) | 
|  | 6175 | { | 
|  | 6176 | clang::QualType ivar_qual_type(getASTContext()->getObjCInterfaceType(superclass_interface_decl)); | 
|  | 6177 |  | 
|  | 6178 |  | 
|  | 6179 | child_name.assign(superclass_interface_decl->getNameAsString().c_str()); | 
|  | 6180 |  | 
|  | 6181 | clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); | 
|  | 6182 |  | 
|  | 6183 | child_byte_size = ivar_type_info.Width / 8; | 
|  | 6184 | child_byte_offset = 0; | 
|  | 6185 | child_is_base_class = true; | 
|  | 6186 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6187 | return CompilerType (getASTContext(), ivar_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6188 | } | 
|  | 6189 |  | 
|  | 6190 | ++child_idx; | 
|  | 6191 | } | 
|  | 6192 | } | 
|  | 6193 | else | 
|  | 6194 | ++child_idx; | 
|  | 6195 | } | 
|  | 6196 |  | 
|  | 6197 | const uint32_t superclass_idx = child_idx; | 
|  | 6198 |  | 
|  | 6199 | if (idx < (child_idx + class_interface_decl->ivar_size())) | 
|  | 6200 | { | 
|  | 6201 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); | 
|  | 6202 |  | 
|  | 6203 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos) | 
|  | 6204 | { | 
|  | 6205 | if (child_idx == idx) | 
|  | 6206 | { | 
|  | 6207 | clang::ObjCIvarDecl* ivar_decl = *ivar_pos; | 
|  | 6208 |  | 
|  | 6209 | clang::QualType ivar_qual_type(ivar_decl->getType()); | 
|  | 6210 |  | 
|  | 6211 | child_name.assign(ivar_decl->getNameAsString().c_str()); | 
|  | 6212 |  | 
|  | 6213 | clang::TypeInfo  ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr()); | 
|  | 6214 |  | 
|  | 6215 | child_byte_size = ivar_type_info.Width / 8; | 
|  | 6216 |  | 
|  | 6217 | // Figure out the field offset within the current struct/union/class type | 
|  | 6218 | // For ObjC objects, we can't trust the bit offset we get from the Clang AST, since | 
|  | 6219 | // that doesn't account for the space taken up by unbacked properties, or from | 
|  | 6220 | // the changing size of base classes that are newer than this class. | 
|  | 6221 | // So if we have a process around that we can ask about this object, do so. | 
|  | 6222 | child_byte_offset = LLDB_INVALID_IVAR_OFFSET; | 
|  | 6223 | Process *process = nullptr; | 
|  | 6224 | if (exe_ctx) | 
|  | 6225 | process = exe_ctx->GetProcessPtr(); | 
|  | 6226 | if (process) | 
|  | 6227 | { | 
|  | 6228 | ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime(); | 
|  | 6229 | if (objc_runtime != nullptr) | 
|  | 6230 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6231 | CompilerType parent_ast_type (getASTContext(), parent_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6232 | child_byte_offset = objc_runtime->GetByteOffsetForIvar (parent_ast_type, ivar_decl->getNameAsString().c_str()); | 
|  | 6233 | } | 
|  | 6234 | } | 
|  | 6235 |  | 
|  | 6236 | // Setting this to UINT32_MAX to make sure we don't compute it twice... | 
|  | 6237 | bit_offset = UINT32_MAX; | 
|  | 6238 |  | 
|  | 6239 | if (child_byte_offset == static_cast<int32_t>(LLDB_INVALID_IVAR_OFFSET)) | 
|  | 6240 | { | 
|  | 6241 | bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx); | 
|  | 6242 | child_byte_offset = bit_offset / 8; | 
|  | 6243 | } | 
|  | 6244 |  | 
|  | 6245 | // Note, the ObjC Ivar Byte offset is just that, it doesn't account for the bit offset | 
|  | 6246 | // of a bitfield within its containing object.  So regardless of where we get the byte | 
|  | 6247 | // offset from, we still need to get the bit offset for bitfields from the layout. | 
|  | 6248 |  | 
|  | 6249 | if (ClangASTContext::FieldIsBitfield (getASTContext(), ivar_decl, child_bitfield_bit_size)) | 
|  | 6250 | { | 
|  | 6251 | if (bit_offset == UINT32_MAX) | 
|  | 6252 | bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx); | 
|  | 6253 |  | 
|  | 6254 | child_bitfield_bit_offset = bit_offset % 8; | 
|  | 6255 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6256 | return CompilerType (getASTContext(), ivar_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6257 | } | 
|  | 6258 | ++child_idx; | 
|  | 6259 | } | 
|  | 6260 | } | 
|  | 6261 | } | 
|  | 6262 | } | 
|  | 6263 | } | 
|  | 6264 | break; | 
|  | 6265 |  | 
|  | 6266 | case clang::Type::ObjCObjectPointer: | 
|  | 6267 | if (idx_is_valid) | 
|  | 6268 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6269 | CompilerType pointee_clang_type (GetPointeeType(type)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6270 |  | 
|  | 6271 | if (transparent_pointers && pointee_clang_type.IsAggregateType()) | 
|  | 6272 | { | 
|  | 6273 | child_is_deref_of_parent = false; | 
|  | 6274 | bool tmp_child_is_deref_of_parent = false; | 
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6275 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, | 
|  | 6276 | idx, | 
|  | 6277 | transparent_pointers, | 
|  | 6278 | omit_empty_base_classes, | 
|  | 6279 | ignore_array_bounds, | 
|  | 6280 | child_name, | 
|  | 6281 | child_byte_size, | 
|  | 6282 | child_byte_offset, | 
|  | 6283 | child_bitfield_bit_size, | 
|  | 6284 | child_bitfield_bit_offset, | 
|  | 6285 | child_is_base_class, | 
|  | 6286 | tmp_child_is_deref_of_parent, | 
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 6287 | valobj, | 
|  | 6288 | language_flags); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6289 | } | 
|  | 6290 | else | 
|  | 6291 | { | 
|  | 6292 | child_is_deref_of_parent = true; | 
|  | 6293 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; | 
|  | 6294 | if (parent_name) | 
|  | 6295 | { | 
|  | 6296 | child_name.assign(1, '*'); | 
|  | 6297 | child_name += parent_name; | 
|  | 6298 | } | 
|  | 6299 |  | 
|  | 6300 | // We have a pointer to an simple type | 
|  | 6301 | if (idx == 0 && pointee_clang_type.GetCompleteType()) | 
|  | 6302 | { | 
|  | 6303 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); | 
|  | 6304 | child_byte_offset = 0; | 
|  | 6305 | return pointee_clang_type; | 
|  | 6306 | } | 
|  | 6307 | } | 
|  | 6308 | } | 
|  | 6309 | break; | 
|  | 6310 |  | 
|  | 6311 | case clang::Type::Vector: | 
|  | 6312 | case clang::Type::ExtVector: | 
|  | 6313 | if (idx_is_valid) | 
|  | 6314 | { | 
|  | 6315 | const clang::VectorType *array = llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr()); | 
|  | 6316 | if (array) | 
|  | 6317 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6318 | CompilerType element_type (getASTContext(), array->getElementType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6319 | if (element_type.GetCompleteType()) | 
|  | 6320 | { | 
|  | 6321 | char element_name[64]; | 
|  | 6322 | ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx)); | 
|  | 6323 | child_name.assign(element_name); | 
|  | 6324 | child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); | 
|  | 6325 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; | 
|  | 6326 | return element_type; | 
|  | 6327 | } | 
|  | 6328 | } | 
|  | 6329 | } | 
|  | 6330 | break; | 
|  | 6331 |  | 
|  | 6332 | case clang::Type::ConstantArray: | 
|  | 6333 | case clang::Type::IncompleteArray: | 
|  | 6334 | if (ignore_array_bounds || idx_is_valid) | 
|  | 6335 | { | 
|  | 6336 | const clang::ArrayType *array = GetQualType(type)->getAsArrayTypeUnsafe(); | 
|  | 6337 | if (array) | 
|  | 6338 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6339 | CompilerType element_type (getASTContext(), array->getElementType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6340 | if (element_type.GetCompleteType()) | 
|  | 6341 | { | 
|  | 6342 | char element_name[64]; | 
|  | 6343 | ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx)); | 
|  | 6344 | child_name.assign(element_name); | 
|  | 6345 | child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); | 
|  | 6346 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; | 
|  | 6347 | return element_type; | 
|  | 6348 | } | 
|  | 6349 | } | 
|  | 6350 | } | 
|  | 6351 | break; | 
|  | 6352 |  | 
|  | 6353 |  | 
|  | 6354 | case clang::Type::Pointer: | 
|  | 6355 | if (idx_is_valid) | 
|  | 6356 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6357 | CompilerType pointee_clang_type (GetPointeeType(type)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6358 |  | 
|  | 6359 | // Don't dereference "void *" pointers | 
|  | 6360 | if (pointee_clang_type.IsVoidType()) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6361 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6362 |  | 
|  | 6363 | if (transparent_pointers && pointee_clang_type.IsAggregateType ()) | 
|  | 6364 | { | 
|  | 6365 | child_is_deref_of_parent = false; | 
|  | 6366 | bool tmp_child_is_deref_of_parent = false; | 
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6367 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, | 
|  | 6368 | idx, | 
|  | 6369 | transparent_pointers, | 
|  | 6370 | omit_empty_base_classes, | 
|  | 6371 | ignore_array_bounds, | 
|  | 6372 | child_name, | 
|  | 6373 | child_byte_size, | 
|  | 6374 | child_byte_offset, | 
|  | 6375 | child_bitfield_bit_size, | 
|  | 6376 | child_bitfield_bit_offset, | 
|  | 6377 | child_is_base_class, | 
|  | 6378 | tmp_child_is_deref_of_parent, | 
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 6379 | valobj, | 
|  | 6380 | language_flags); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6381 | } | 
|  | 6382 | else | 
|  | 6383 | { | 
|  | 6384 | child_is_deref_of_parent = true; | 
|  | 6385 |  | 
|  | 6386 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; | 
|  | 6387 | if (parent_name) | 
|  | 6388 | { | 
|  | 6389 | child_name.assign(1, '*'); | 
|  | 6390 | child_name += parent_name; | 
|  | 6391 | } | 
|  | 6392 |  | 
|  | 6393 | // We have a pointer to an simple type | 
|  | 6394 | if (idx == 0) | 
|  | 6395 | { | 
|  | 6396 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); | 
|  | 6397 | child_byte_offset = 0; | 
|  | 6398 | return pointee_clang_type; | 
|  | 6399 | } | 
|  | 6400 | } | 
|  | 6401 | } | 
|  | 6402 | break; | 
|  | 6403 |  | 
|  | 6404 | case clang::Type::LValueReference: | 
|  | 6405 | case clang::Type::RValueReference: | 
|  | 6406 | if (idx_is_valid) | 
|  | 6407 | { | 
|  | 6408 | 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] | 6409 | CompilerType pointee_clang_type (getASTContext(), reference_type->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6410 | if (transparent_pointers && pointee_clang_type.IsAggregateType ()) | 
|  | 6411 | { | 
|  | 6412 | child_is_deref_of_parent = false; | 
|  | 6413 | bool tmp_child_is_deref_of_parent = false; | 
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 6414 | return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, | 
|  | 6415 | idx, | 
|  | 6416 | transparent_pointers, | 
|  | 6417 | omit_empty_base_classes, | 
|  | 6418 | ignore_array_bounds, | 
|  | 6419 | child_name, | 
|  | 6420 | child_byte_size, | 
|  | 6421 | child_byte_offset, | 
|  | 6422 | child_bitfield_bit_size, | 
|  | 6423 | child_bitfield_bit_offset, | 
|  | 6424 | child_is_base_class, | 
|  | 6425 | tmp_child_is_deref_of_parent, | 
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 6426 | valobj, | 
|  | 6427 | language_flags); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6428 | } | 
|  | 6429 | else | 
|  | 6430 | { | 
|  | 6431 | const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL; | 
|  | 6432 | if (parent_name) | 
|  | 6433 | { | 
|  | 6434 | child_name.assign(1, '&'); | 
|  | 6435 | child_name += parent_name; | 
|  | 6436 | } | 
|  | 6437 |  | 
|  | 6438 | // We have a pointer to an simple type | 
|  | 6439 | if (idx == 0) | 
|  | 6440 | { | 
|  | 6441 | child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); | 
|  | 6442 | child_byte_offset = 0; | 
|  | 6443 | return pointee_clang_type; | 
|  | 6444 | } | 
|  | 6445 | } | 
|  | 6446 | } | 
|  | 6447 | break; | 
|  | 6448 |  | 
|  | 6449 | case clang::Type::Typedef: | 
|  | 6450 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6451 | 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] | 6452 | return typedefed_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, | 
|  | 6453 | idx, | 
|  | 6454 | transparent_pointers, | 
|  | 6455 | omit_empty_base_classes, | 
|  | 6456 | ignore_array_bounds, | 
|  | 6457 | child_name, | 
|  | 6458 | child_byte_size, | 
|  | 6459 | child_byte_offset, | 
|  | 6460 | child_bitfield_bit_size, | 
|  | 6461 | child_bitfield_bit_offset, | 
|  | 6462 | child_is_base_class, | 
|  | 6463 | child_is_deref_of_parent, | 
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 6464 | valobj, | 
|  | 6465 | language_flags); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6466 | } | 
|  | 6467 | break; | 
|  | 6468 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 6469 | case clang::Type::Auto: | 
|  | 6470 | { | 
|  | 6471 | CompilerType elaborated_clang_type (getASTContext(), llvm::cast<clang::AutoType>(parent_qual_type)->getDeducedType()); | 
|  | 6472 | return elaborated_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, | 
|  | 6473 | idx, | 
|  | 6474 | transparent_pointers, | 
|  | 6475 | omit_empty_base_classes, | 
|  | 6476 | ignore_array_bounds, | 
|  | 6477 | child_name, | 
|  | 6478 | child_byte_size, | 
|  | 6479 | child_byte_offset, | 
|  | 6480 | child_bitfield_bit_size, | 
|  | 6481 | child_bitfield_bit_offset, | 
|  | 6482 | child_is_base_class, | 
|  | 6483 | child_is_deref_of_parent, | 
|  | 6484 | valobj, | 
|  | 6485 | language_flags); | 
|  | 6486 | } | 
|  | 6487 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6488 | case clang::Type::Elaborated: | 
|  | 6489 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6490 | 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] | 6491 | return elaborated_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, | 
|  | 6492 | idx, | 
|  | 6493 | transparent_pointers, | 
|  | 6494 | omit_empty_base_classes, | 
|  | 6495 | ignore_array_bounds, | 
|  | 6496 | child_name, | 
|  | 6497 | child_byte_size, | 
|  | 6498 | child_byte_offset, | 
|  | 6499 | child_bitfield_bit_size, | 
|  | 6500 | child_bitfield_bit_offset, | 
|  | 6501 | child_is_base_class, | 
|  | 6502 | child_is_deref_of_parent, | 
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 6503 | valobj, | 
|  | 6504 | language_flags); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6505 | } | 
|  | 6506 |  | 
|  | 6507 | case clang::Type::Paren: | 
|  | 6508 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6509 | 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] | 6510 | return paren_clang_type.GetChildCompilerTypeAtIndex (exe_ctx, | 
|  | 6511 | idx, | 
|  | 6512 | transparent_pointers, | 
|  | 6513 | omit_empty_base_classes, | 
|  | 6514 | ignore_array_bounds, | 
|  | 6515 | child_name, | 
|  | 6516 | child_byte_size, | 
|  | 6517 | child_byte_offset, | 
|  | 6518 | child_bitfield_bit_size, | 
|  | 6519 | child_bitfield_bit_offset, | 
|  | 6520 | child_is_base_class, | 
|  | 6521 | child_is_deref_of_parent, | 
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 6522 | valobj, | 
|  | 6523 | language_flags); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6524 | } | 
|  | 6525 |  | 
|  | 6526 |  | 
|  | 6527 | default: | 
|  | 6528 | break; | 
|  | 6529 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6530 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6531 | } | 
|  | 6532 |  | 
|  | 6533 | static uint32_t | 
|  | 6534 | GetIndexForRecordBase | 
|  | 6535 | ( | 
|  | 6536 | const clang::RecordDecl *record_decl, | 
|  | 6537 | const clang::CXXBaseSpecifier *base_spec, | 
|  | 6538 | bool omit_empty_base_classes | 
|  | 6539 | ) | 
|  | 6540 | { | 
|  | 6541 | uint32_t child_idx = 0; | 
|  | 6542 |  | 
|  | 6543 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 6544 |  | 
|  | 6545 | //    const char *super_name = record_decl->getNameAsCString(); | 
|  | 6546 | //    const char *base_name = base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString(); | 
|  | 6547 | //    printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name); | 
|  | 6548 | // | 
|  | 6549 | if (cxx_record_decl) | 
|  | 6550 | { | 
|  | 6551 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 6552 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); | 
|  | 6553 | base_class != base_class_end; | 
|  | 6554 | ++base_class) | 
|  | 6555 | { | 
|  | 6556 | if (omit_empty_base_classes) | 
|  | 6557 | { | 
|  | 6558 | if (BaseSpecifierIsEmpty (base_class)) | 
|  | 6559 | continue; | 
|  | 6560 | } | 
|  | 6561 |  | 
|  | 6562 | //            printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", super_name, base_name, | 
|  | 6563 | //                    child_idx, | 
|  | 6564 | //                    base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString()); | 
|  | 6565 | // | 
|  | 6566 | // | 
|  | 6567 | if (base_class == base_spec) | 
|  | 6568 | return child_idx; | 
|  | 6569 | ++child_idx; | 
|  | 6570 | } | 
|  | 6571 | } | 
|  | 6572 |  | 
|  | 6573 | return UINT32_MAX; | 
|  | 6574 | } | 
|  | 6575 |  | 
|  | 6576 |  | 
|  | 6577 | static uint32_t | 
|  | 6578 | GetIndexForRecordChild (const clang::RecordDecl *record_decl, | 
|  | 6579 | clang::NamedDecl *canonical_decl, | 
|  | 6580 | bool omit_empty_base_classes) | 
|  | 6581 | { | 
|  | 6582 | uint32_t child_idx = ClangASTContext::GetNumBaseClasses (llvm::dyn_cast<clang::CXXRecordDecl>(record_decl), | 
|  | 6583 | omit_empty_base_classes); | 
|  | 6584 |  | 
|  | 6585 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 6586 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); | 
|  | 6587 | field != field_end; | 
|  | 6588 | ++field, ++child_idx) | 
|  | 6589 | { | 
|  | 6590 | if (field->getCanonicalDecl() == canonical_decl) | 
|  | 6591 | return child_idx; | 
|  | 6592 | } | 
|  | 6593 |  | 
|  | 6594 | return UINT32_MAX; | 
|  | 6595 | } | 
|  | 6596 |  | 
|  | 6597 | // Look for a child member (doesn't include base classes, but it does include | 
|  | 6598 | // their members) in the type hierarchy. Returns an index path into "clang_type" | 
|  | 6599 | // on how to reach the appropriate member. | 
|  | 6600 | // | 
|  | 6601 | //    class A | 
|  | 6602 | //    { | 
|  | 6603 | //    public: | 
|  | 6604 | //        int m_a; | 
|  | 6605 | //        int m_b; | 
|  | 6606 | //    }; | 
|  | 6607 | // | 
|  | 6608 | //    class B | 
|  | 6609 | //    { | 
|  | 6610 | //    }; | 
|  | 6611 | // | 
|  | 6612 | //    class C : | 
|  | 6613 | //        public B, | 
|  | 6614 | //        public A | 
|  | 6615 | //    { | 
|  | 6616 | //    }; | 
|  | 6617 | // | 
|  | 6618 | // If we have a clang type that describes "class C", and we wanted to looked | 
|  | 6619 | // "m_b" in it: | 
|  | 6620 | // | 
|  | 6621 | // With omit_empty_base_classes == false we would get an integer array back with: | 
|  | 6622 | // { 1,  1 } | 
|  | 6623 | // The first index 1 is the child index for "class A" within class C | 
|  | 6624 | // The second index 1 is the child index for "m_b" within class A | 
|  | 6625 | // | 
|  | 6626 | // With omit_empty_base_classes == true we would get an integer array back with: | 
|  | 6627 | // { 0,  1 } | 
|  | 6628 | // 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) | 
|  | 6629 | // The second index 1 is the child index for "m_b" within class A | 
|  | 6630 |  | 
|  | 6631 | size_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6632 | ClangASTContext::GetIndexOfChildMemberWithName (lldb::opaque_compiler_type_t type, const char *name, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6633 | bool omit_empty_base_classes, | 
|  | 6634 | std::vector<uint32_t>& child_indexes) | 
|  | 6635 | { | 
|  | 6636 | if (type && name && name[0]) | 
|  | 6637 | { | 
|  | 6638 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 6639 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 6640 | switch (type_class) | 
|  | 6641 | { | 
|  | 6642 | case clang::Type::Record: | 
|  | 6643 | if (GetCompleteType(type)) | 
|  | 6644 | { | 
|  | 6645 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 6646 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 6647 |  | 
|  | 6648 | assert(record_decl); | 
|  | 6649 | uint32_t child_idx = 0; | 
|  | 6650 |  | 
|  | 6651 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 6652 |  | 
|  | 6653 | // Try and find a field that matches NAME | 
|  | 6654 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 6655 | llvm::StringRef name_sref(name); | 
|  | 6656 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); | 
|  | 6657 | field != field_end; | 
|  | 6658 | ++field, ++child_idx) | 
|  | 6659 | { | 
|  | 6660 | llvm::StringRef field_name = field->getName(); | 
|  | 6661 | if (field_name.empty()) | 
|  | 6662 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6663 | CompilerType field_type(getASTContext(),field->getType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6664 | child_indexes.push_back(child_idx); | 
|  | 6665 | if (field_type.GetIndexOfChildMemberWithName(name,  omit_empty_base_classes, child_indexes)) | 
|  | 6666 | return child_indexes.size(); | 
|  | 6667 | child_indexes.pop_back(); | 
|  | 6668 |  | 
|  | 6669 | } | 
|  | 6670 | else if (field_name.equals (name_sref)) | 
|  | 6671 | { | 
|  | 6672 | // We have to add on the number of base classes to this index! | 
|  | 6673 | child_indexes.push_back (child_idx + ClangASTContext::GetNumBaseClasses (cxx_record_decl, omit_empty_base_classes)); | 
|  | 6674 | return child_indexes.size(); | 
|  | 6675 | } | 
|  | 6676 | } | 
|  | 6677 |  | 
|  | 6678 | if (cxx_record_decl) | 
|  | 6679 | { | 
|  | 6680 | const clang::RecordDecl *parent_record_decl = cxx_record_decl; | 
|  | 6681 |  | 
|  | 6682 | //printf ("parent = %s\n", parent_record_decl->getNameAsCString()); | 
|  | 6683 |  | 
|  | 6684 | //const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl(); | 
|  | 6685 | // Didn't find things easily, lets let clang do its thang... | 
|  | 6686 | clang::IdentifierInfo & ident_ref = getASTContext()->Idents.get(name_sref); | 
|  | 6687 | clang::DeclarationName decl_name(&ident_ref); | 
|  | 6688 |  | 
|  | 6689 | clang::CXXBasePaths paths; | 
|  | 6690 | if (cxx_record_decl->lookupInBases([decl_name](const clang::CXXBaseSpecifier *specifier, clang::CXXBasePath &path) { | 
|  | 6691 | return clang::CXXRecordDecl::FindOrdinaryMember(specifier, path, decl_name); | 
|  | 6692 | }, | 
|  | 6693 | paths)) | 
|  | 6694 | { | 
|  | 6695 | clang::CXXBasePaths::const_paths_iterator path, path_end = paths.end(); | 
|  | 6696 | for (path = paths.begin(); path != path_end; ++path) | 
|  | 6697 | { | 
|  | 6698 | const size_t num_path_elements = path->size(); | 
|  | 6699 | for (size_t e=0; e<num_path_elements; ++e) | 
|  | 6700 | { | 
|  | 6701 | clang::CXXBasePathElement elem = (*path)[e]; | 
|  | 6702 |  | 
|  | 6703 | child_idx = GetIndexForRecordBase (parent_record_decl, elem.Base, omit_empty_base_classes); | 
|  | 6704 | if (child_idx == UINT32_MAX) | 
|  | 6705 | { | 
|  | 6706 | child_indexes.clear(); | 
|  | 6707 | return 0; | 
|  | 6708 | } | 
|  | 6709 | else | 
|  | 6710 | { | 
|  | 6711 | child_indexes.push_back (child_idx); | 
|  | 6712 | parent_record_decl = llvm::cast<clang::RecordDecl>(elem.Base->getType()->getAs<clang::RecordType>()->getDecl()); | 
|  | 6713 | } | 
|  | 6714 | } | 
|  | 6715 | for (clang::NamedDecl *path_decl : path->Decls) | 
|  | 6716 | { | 
|  | 6717 | child_idx = GetIndexForRecordChild (parent_record_decl, path_decl, omit_empty_base_classes); | 
|  | 6718 | if (child_idx == UINT32_MAX) | 
|  | 6719 | { | 
|  | 6720 | child_indexes.clear(); | 
|  | 6721 | return 0; | 
|  | 6722 | } | 
|  | 6723 | else | 
|  | 6724 | { | 
|  | 6725 | child_indexes.push_back (child_idx); | 
|  | 6726 | } | 
|  | 6727 | } | 
|  | 6728 | } | 
|  | 6729 | return child_indexes.size(); | 
|  | 6730 | } | 
|  | 6731 | } | 
|  | 6732 |  | 
|  | 6733 | } | 
|  | 6734 | break; | 
|  | 6735 |  | 
|  | 6736 | case clang::Type::ObjCObject: | 
|  | 6737 | case clang::Type::ObjCInterface: | 
|  | 6738 | if (GetCompleteType(type)) | 
|  | 6739 | { | 
|  | 6740 | llvm::StringRef name_sref(name); | 
|  | 6741 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 6742 | assert (objc_class_type); | 
|  | 6743 | if (objc_class_type) | 
|  | 6744 | { | 
|  | 6745 | uint32_t child_idx = 0; | 
|  | 6746 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 6747 |  | 
|  | 6748 | if (class_interface_decl) | 
|  | 6749 | { | 
|  | 6750 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); | 
|  | 6751 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); | 
|  | 6752 |  | 
|  | 6753 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx) | 
|  | 6754 | { | 
|  | 6755 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; | 
|  | 6756 |  | 
|  | 6757 | if (ivar_decl->getName().equals (name_sref)) | 
|  | 6758 | { | 
|  | 6759 | if ((!omit_empty_base_classes && superclass_interface_decl) || | 
|  | 6760 | ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true))) | 
|  | 6761 | ++child_idx; | 
|  | 6762 |  | 
|  | 6763 | child_indexes.push_back (child_idx); | 
|  | 6764 | return child_indexes.size(); | 
|  | 6765 | } | 
|  | 6766 | } | 
|  | 6767 |  | 
|  | 6768 | if (superclass_interface_decl) | 
|  | 6769 | { | 
|  | 6770 | // The super class index is always zero for ObjC classes, | 
|  | 6771 | // so we push it onto the child indexes in case we find | 
|  | 6772 | // an ivar in our superclass... | 
|  | 6773 | child_indexes.push_back (0); | 
|  | 6774 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6775 | CompilerType superclass_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6776 | if (superclass_clang_type.GetIndexOfChildMemberWithName (name, | 
|  | 6777 | omit_empty_base_classes, | 
|  | 6778 | child_indexes)) | 
|  | 6779 | { | 
|  | 6780 | // We did find an ivar in a superclass so just | 
|  | 6781 | // return the results! | 
|  | 6782 | return child_indexes.size(); | 
|  | 6783 | } | 
|  | 6784 |  | 
|  | 6785 | // We didn't find an ivar matching "name" in our | 
|  | 6786 | // superclass, pop the superclass zero index that | 
|  | 6787 | // we pushed on above. | 
|  | 6788 | child_indexes.pop_back(); | 
|  | 6789 | } | 
|  | 6790 | } | 
|  | 6791 | } | 
|  | 6792 | } | 
|  | 6793 | break; | 
|  | 6794 |  | 
|  | 6795 | case clang::Type::ObjCObjectPointer: | 
|  | 6796 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6797 | 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] | 6798 | return objc_object_clang_type.GetIndexOfChildMemberWithName (name, | 
|  | 6799 | omit_empty_base_classes, | 
|  | 6800 | child_indexes); | 
|  | 6801 | } | 
|  | 6802 | break; | 
|  | 6803 |  | 
|  | 6804 |  | 
|  | 6805 | case clang::Type::ConstantArray: | 
|  | 6806 | { | 
|  | 6807 | //                const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); | 
|  | 6808 | //                const uint64_t element_count = array->getSize().getLimitedValue(); | 
|  | 6809 | // | 
|  | 6810 | //                if (idx < element_count) | 
|  | 6811 | //                { | 
|  | 6812 | //                    std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); | 
|  | 6813 | // | 
|  | 6814 | //                    char element_name[32]; | 
|  | 6815 | //                    ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx); | 
|  | 6816 | // | 
|  | 6817 | //                    child_name.assign(element_name); | 
|  | 6818 | //                    assert(field_type_info.first % 8 == 0); | 
|  | 6819 | //                    child_byte_size = field_type_info.first / 8; | 
|  | 6820 | //                    child_byte_offset = idx * child_byte_size; | 
|  | 6821 | //                    return array->getElementType().getAsOpaquePtr(); | 
|  | 6822 | //                } | 
|  | 6823 | } | 
|  | 6824 | break; | 
|  | 6825 |  | 
|  | 6826 | //        case clang::Type::MemberPointerType: | 
|  | 6827 | //            { | 
|  | 6828 | //                MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr()); | 
|  | 6829 | //                clang::QualType pointee_type = mem_ptr_type->getPointeeType(); | 
|  | 6830 | // | 
|  | 6831 | //                if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) | 
|  | 6832 | //                { | 
|  | 6833 | //                    return GetIndexOfChildWithName (ast, | 
|  | 6834 | //                                                    mem_ptr_type->getPointeeType().getAsOpaquePtr(), | 
|  | 6835 | //                                                    name); | 
|  | 6836 | //                } | 
|  | 6837 | //            } | 
|  | 6838 | //            break; | 
|  | 6839 | // | 
|  | 6840 | case clang::Type::LValueReference: | 
|  | 6841 | case clang::Type::RValueReference: | 
|  | 6842 | { | 
|  | 6843 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); | 
|  | 6844 | clang::QualType pointee_type(reference_type->getPointeeType()); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6845 | CompilerType pointee_clang_type (getASTContext(), pointee_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6846 |  | 
|  | 6847 | if (pointee_clang_type.IsAggregateType ()) | 
|  | 6848 | { | 
|  | 6849 | return pointee_clang_type.GetIndexOfChildMemberWithName (name, | 
|  | 6850 | omit_empty_base_classes, | 
|  | 6851 | child_indexes); | 
|  | 6852 | } | 
|  | 6853 | } | 
|  | 6854 | break; | 
|  | 6855 |  | 
|  | 6856 | case clang::Type::Pointer: | 
|  | 6857 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6858 | CompilerType pointee_clang_type (GetPointeeType(type)); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6859 |  | 
|  | 6860 | if (pointee_clang_type.IsAggregateType ()) | 
|  | 6861 | { | 
|  | 6862 | return pointee_clang_type.GetIndexOfChildMemberWithName (name, | 
|  | 6863 | omit_empty_base_classes, | 
|  | 6864 | child_indexes); | 
|  | 6865 | } | 
|  | 6866 | } | 
|  | 6867 | break; | 
|  | 6868 |  | 
|  | 6869 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6870 | return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildMemberWithName (name, | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 6871 | omit_empty_base_classes, | 
|  | 6872 | child_indexes); | 
|  | 6873 |  | 
|  | 6874 | case clang::Type::Auto: | 
|  | 6875 | return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetIndexOfChildMemberWithName (name, | 
|  | 6876 | omit_empty_base_classes, | 
|  | 6877 | child_indexes); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6878 |  | 
|  | 6879 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6880 | return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildMemberWithName (name, | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 6881 | omit_empty_base_classes, | 
|  | 6882 | child_indexes); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6883 |  | 
|  | 6884 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6885 | return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildMemberWithName (name, | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 6886 | omit_empty_base_classes, | 
|  | 6887 | child_indexes); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6888 |  | 
|  | 6889 | default: | 
|  | 6890 | break; | 
|  | 6891 | } | 
|  | 6892 | } | 
|  | 6893 | return 0; | 
|  | 6894 | } | 
|  | 6895 |  | 
|  | 6896 |  | 
|  | 6897 | // Get the index of the child of "clang_type" whose name matches. This function | 
|  | 6898 | // doesn't descend into the children, but only looks one level deep and name | 
|  | 6899 | // matches can include base class names. | 
|  | 6900 |  | 
|  | 6901 | uint32_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 6902 | 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] | 6903 | { | 
|  | 6904 | if (type && name && name[0]) | 
|  | 6905 | { | 
|  | 6906 | clang::QualType qual_type(GetCanonicalQualType(type)); | 
|  | 6907 |  | 
|  | 6908 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 6909 |  | 
|  | 6910 | switch (type_class) | 
|  | 6911 | { | 
|  | 6912 | case clang::Type::Record: | 
|  | 6913 | if (GetCompleteType(type)) | 
|  | 6914 | { | 
|  | 6915 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 6916 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 6917 |  | 
|  | 6918 | assert(record_decl); | 
|  | 6919 | uint32_t child_idx = 0; | 
|  | 6920 |  | 
|  | 6921 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 6922 |  | 
|  | 6923 | if (cxx_record_decl) | 
|  | 6924 | { | 
|  | 6925 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 6926 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); | 
|  | 6927 | base_class != base_class_end; | 
|  | 6928 | ++base_class) | 
|  | 6929 | { | 
|  | 6930 | // Skip empty base classes | 
|  | 6931 | clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); | 
|  | 6932 | if (omit_empty_base_classes && ClangASTContext::RecordHasFields(base_class_decl) == false) | 
|  | 6933 | continue; | 
|  | 6934 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 6935 | CompilerType base_class_clang_type (getASTContext(), base_class->getType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 6936 | std::string base_class_type_name (base_class_clang_type.GetTypeName().AsCString("")); | 
|  | 6937 | if (base_class_type_name.compare (name) == 0) | 
|  | 6938 | return child_idx; | 
|  | 6939 | ++child_idx; | 
|  | 6940 | } | 
|  | 6941 | } | 
|  | 6942 |  | 
|  | 6943 | // Try and find a field that matches NAME | 
|  | 6944 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 6945 | llvm::StringRef name_sref(name); | 
|  | 6946 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); | 
|  | 6947 | field != field_end; | 
|  | 6948 | ++field, ++child_idx) | 
|  | 6949 | { | 
|  | 6950 | if (field->getName().equals (name_sref)) | 
|  | 6951 | return child_idx; | 
|  | 6952 | } | 
|  | 6953 |  | 
|  | 6954 | } | 
|  | 6955 | break; | 
|  | 6956 |  | 
|  | 6957 | case clang::Type::ObjCObject: | 
|  | 6958 | case clang::Type::ObjCInterface: | 
|  | 6959 | if (GetCompleteType(type)) | 
|  | 6960 | { | 
|  | 6961 | llvm::StringRef name_sref(name); | 
|  | 6962 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 6963 | assert (objc_class_type); | 
|  | 6964 | if (objc_class_type) | 
|  | 6965 | { | 
|  | 6966 | uint32_t child_idx = 0; | 
|  | 6967 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 6968 |  | 
|  | 6969 | if (class_interface_decl) | 
|  | 6970 | { | 
|  | 6971 | clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); | 
|  | 6972 | clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); | 
|  | 6973 |  | 
|  | 6974 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx) | 
|  | 6975 | { | 
|  | 6976 | const clang::ObjCIvarDecl* ivar_decl = *ivar_pos; | 
|  | 6977 |  | 
|  | 6978 | if (ivar_decl->getName().equals (name_sref)) | 
|  | 6979 | { | 
|  | 6980 | if ((!omit_empty_base_classes && superclass_interface_decl) || | 
|  | 6981 | ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true))) | 
|  | 6982 | ++child_idx; | 
|  | 6983 |  | 
|  | 6984 | return child_idx; | 
|  | 6985 | } | 
|  | 6986 | } | 
|  | 6987 |  | 
|  | 6988 | if (superclass_interface_decl) | 
|  | 6989 | { | 
|  | 6990 | if (superclass_interface_decl->getName().equals (name_sref)) | 
|  | 6991 | return 0; | 
|  | 6992 | } | 
|  | 6993 | } | 
|  | 6994 | } | 
|  | 6995 | } | 
|  | 6996 | break; | 
|  | 6997 |  | 
|  | 6998 | case clang::Type::ObjCObjectPointer: | 
|  | 6999 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7000 | 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] | 7001 | return pointee_clang_type.GetIndexOfChildWithName (name, omit_empty_base_classes); | 
|  | 7002 | } | 
|  | 7003 | break; | 
|  | 7004 |  | 
|  | 7005 | case clang::Type::ConstantArray: | 
|  | 7006 | { | 
|  | 7007 | //                const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr()); | 
|  | 7008 | //                const uint64_t element_count = array->getSize().getLimitedValue(); | 
|  | 7009 | // | 
|  | 7010 | //                if (idx < element_count) | 
|  | 7011 | //                { | 
|  | 7012 | //                    std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); | 
|  | 7013 | // | 
|  | 7014 | //                    char element_name[32]; | 
|  | 7015 | //                    ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx); | 
|  | 7016 | // | 
|  | 7017 | //                    child_name.assign(element_name); | 
|  | 7018 | //                    assert(field_type_info.first % 8 == 0); | 
|  | 7019 | //                    child_byte_size = field_type_info.first / 8; | 
|  | 7020 | //                    child_byte_offset = idx * child_byte_size; | 
|  | 7021 | //                    return array->getElementType().getAsOpaquePtr(); | 
|  | 7022 | //                } | 
|  | 7023 | } | 
|  | 7024 | break; | 
|  | 7025 |  | 
|  | 7026 | //        case clang::Type::MemberPointerType: | 
|  | 7027 | //            { | 
|  | 7028 | //                MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr()); | 
|  | 7029 | //                clang::QualType pointee_type = mem_ptr_type->getPointeeType(); | 
|  | 7030 | // | 
|  | 7031 | //                if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) | 
|  | 7032 | //                { | 
|  | 7033 | //                    return GetIndexOfChildWithName (ast, | 
|  | 7034 | //                                                    mem_ptr_type->getPointeeType().getAsOpaquePtr(), | 
|  | 7035 | //                                                    name); | 
|  | 7036 | //                } | 
|  | 7037 | //            } | 
|  | 7038 | //            break; | 
|  | 7039 | // | 
|  | 7040 | case clang::Type::LValueReference: | 
|  | 7041 | case clang::Type::RValueReference: | 
|  | 7042 | { | 
|  | 7043 | const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr()); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7044 | CompilerType pointee_type (getASTContext(), reference_type->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7045 |  | 
|  | 7046 | if (pointee_type.IsAggregateType ()) | 
|  | 7047 | { | 
|  | 7048 | return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes); | 
|  | 7049 | } | 
|  | 7050 | } | 
|  | 7051 | break; | 
|  | 7052 |  | 
|  | 7053 | case clang::Type::Pointer: | 
|  | 7054 | { | 
|  | 7055 | const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr()); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7056 | CompilerType pointee_type (getASTContext(), pointer_type->getPointeeType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7057 |  | 
|  | 7058 | if (pointee_type.IsAggregateType ()) | 
|  | 7059 | { | 
|  | 7060 | return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes); | 
|  | 7061 | } | 
|  | 7062 | else | 
|  | 7063 | { | 
|  | 7064 | //                    if (parent_name) | 
|  | 7065 | //                    { | 
|  | 7066 | //                        child_name.assign(1, '*'); | 
|  | 7067 | //                        child_name += parent_name; | 
|  | 7068 | //                    } | 
|  | 7069 | // | 
|  | 7070 | //                    // We have a pointer to an simple type | 
|  | 7071 | //                    if (idx == 0) | 
|  | 7072 | //                    { | 
|  | 7073 | //                        std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type); | 
|  | 7074 | //                        assert(clang_type_info.first % 8 == 0); | 
|  | 7075 | //                        child_byte_size = clang_type_info.first / 8; | 
|  | 7076 | //                        child_byte_offset = 0; | 
|  | 7077 | //                        return pointee_type.getAsOpaquePtr(); | 
|  | 7078 | //                    } | 
|  | 7079 | } | 
|  | 7080 | } | 
|  | 7081 | break; | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 7082 |  | 
|  | 7083 | case clang::Type::Auto: | 
|  | 7084 | return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetIndexOfChildWithName (name, omit_empty_base_classes); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7085 |  | 
|  | 7086 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7087 | 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] | 7088 |  | 
|  | 7089 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7090 | 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] | 7091 |  | 
|  | 7092 | case clang::Type::Typedef: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7093 | 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] | 7094 |  | 
|  | 7095 | default: | 
|  | 7096 | break; | 
|  | 7097 | } | 
|  | 7098 | } | 
|  | 7099 | return UINT32_MAX; | 
|  | 7100 | } | 
|  | 7101 |  | 
|  | 7102 |  | 
|  | 7103 | size_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7104 | ClangASTContext::GetNumTemplateArguments (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7105 | { | 
|  | 7106 | if (!type) | 
|  | 7107 | return 0; | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7108 |  | 
|  | 7109 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 7110 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 7111 | switch (type_class) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7112 | { | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7113 | case clang::Type::Record: | 
|  | 7114 | if (GetCompleteType(type)) | 
|  | 7115 | { | 
|  | 7116 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 7117 | if (cxx_record_decl) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7118 | { | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7119 | const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl); | 
|  | 7120 | if (template_decl) | 
|  | 7121 | return template_decl->getTemplateArgs().size(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7122 | } | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7123 | } | 
|  | 7124 | break; | 
|  | 7125 |  | 
|  | 7126 | case clang::Type::Typedef: | 
|  | 7127 | return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetNumTemplateArguments(); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 7128 |  | 
|  | 7129 | case clang::Type::Auto: | 
|  | 7130 | return (CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType())).GetNumTemplateArguments(); | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7131 |  | 
|  | 7132 | case clang::Type::Elaborated: | 
|  | 7133 | return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetNumTemplateArguments(); | 
|  | 7134 |  | 
|  | 7135 | case clang::Type::Paren: | 
|  | 7136 | return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetNumTemplateArguments(); | 
|  | 7137 |  | 
|  | 7138 | default: | 
|  | 7139 | break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7140 | } | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7141 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7142 | return 0; | 
|  | 7143 | } | 
|  | 7144 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7145 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7146 | 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] | 7147 | { | 
|  | 7148 | if (!type) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7149 | return CompilerType(); | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7150 |  | 
|  | 7151 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 7152 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 7153 | switch (type_class) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7154 | { | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7155 | case clang::Type::Record: | 
|  | 7156 | if (GetCompleteType(type)) | 
|  | 7157 | { | 
|  | 7158 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 7159 | if (cxx_record_decl) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7160 | { | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7161 | const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl); | 
|  | 7162 | if (template_decl && arg_idx < template_decl->getTemplateArgs().size()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7163 | { | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7164 | const clang::TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx]; | 
|  | 7165 | switch (template_arg.getKind()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7166 | { | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7167 | case clang::TemplateArgument::Null: | 
|  | 7168 | kind = eTemplateArgumentKindNull; | 
|  | 7169 | return CompilerType(); | 
|  | 7170 |  | 
|  | 7171 | case clang::TemplateArgument::Type: | 
|  | 7172 | kind = eTemplateArgumentKindType; | 
|  | 7173 | return CompilerType(getASTContext(), template_arg.getAsType()); | 
|  | 7174 |  | 
|  | 7175 | case clang::TemplateArgument::Declaration: | 
|  | 7176 | kind = eTemplateArgumentKindDeclaration; | 
|  | 7177 | return CompilerType(); | 
|  | 7178 |  | 
|  | 7179 | case clang::TemplateArgument::Integral: | 
|  | 7180 | kind = eTemplateArgumentKindIntegral; | 
|  | 7181 | return CompilerType(getASTContext(), template_arg.getIntegralType()); | 
|  | 7182 |  | 
|  | 7183 | case clang::TemplateArgument::Template: | 
|  | 7184 | kind = eTemplateArgumentKindTemplate; | 
|  | 7185 | return CompilerType(); | 
|  | 7186 |  | 
|  | 7187 | case clang::TemplateArgument::TemplateExpansion: | 
|  | 7188 | kind = eTemplateArgumentKindTemplateExpansion; | 
|  | 7189 | return CompilerType(); | 
|  | 7190 |  | 
|  | 7191 | case clang::TemplateArgument::Expression: | 
|  | 7192 | kind = eTemplateArgumentKindExpression; | 
|  | 7193 | return CompilerType(); | 
|  | 7194 |  | 
|  | 7195 | case clang::TemplateArgument::Pack: | 
|  | 7196 | kind = eTemplateArgumentKindPack; | 
|  | 7197 | return CompilerType(); | 
|  | 7198 |  | 
|  | 7199 | default: | 
|  | 7200 | assert (!"Unhandled clang::TemplateArgument::ArgKind"); | 
|  | 7201 | break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7202 | } | 
|  | 7203 | } | 
|  | 7204 | } | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7205 | } | 
|  | 7206 | break; | 
|  | 7207 |  | 
|  | 7208 | case clang::Type::Typedef: | 
|  | 7209 | return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetTemplateArgument(arg_idx, kind); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 7210 |  | 
|  | 7211 | case clang::Type::Auto: | 
|  | 7212 | return (CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType())).GetTemplateArgument(arg_idx, kind); | 
| Enrico Granata | 53f2a4a | 2015-08-13 00:24:24 +0000 | [diff] [blame] | 7213 |  | 
|  | 7214 | case clang::Type::Elaborated: | 
|  | 7215 | return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetTemplateArgument(arg_idx, kind); | 
|  | 7216 |  | 
|  | 7217 | case clang::Type::Paren: | 
|  | 7218 | return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetTemplateArgument(arg_idx, kind); | 
|  | 7219 |  | 
|  | 7220 | default: | 
|  | 7221 | break; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7222 | } | 
|  | 7223 | kind = eTemplateArgumentKindNull; | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7224 | return CompilerType (); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7225 | } | 
|  | 7226 |  | 
| Enrico Granata | c6bf2e2 | 2015-09-23 01:39:46 +0000 | [diff] [blame] | 7227 | CompilerType | 
|  | 7228 | ClangASTContext::GetTypeForFormatters (void* type) | 
|  | 7229 | { | 
|  | 7230 | if (type) | 
|  | 7231 | return RemoveFastQualifiers(CompilerType(this, type)); | 
|  | 7232 | return CompilerType(); | 
|  | 7233 | } | 
|  | 7234 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7235 | static bool | 
|  | 7236 | IsOperator (const char *name, clang::OverloadedOperatorKind &op_kind) | 
|  | 7237 | { | 
|  | 7238 | if (name == nullptr || name[0] == '\0') | 
|  | 7239 | return false; | 
|  | 7240 |  | 
|  | 7241 | #define OPERATOR_PREFIX "operator" | 
|  | 7242 | #define OPERATOR_PREFIX_LENGTH (sizeof (OPERATOR_PREFIX) - 1) | 
|  | 7243 |  | 
|  | 7244 | const char *post_op_name = nullptr; | 
|  | 7245 |  | 
|  | 7246 | bool no_space = true; | 
|  | 7247 |  | 
|  | 7248 | if (::strncmp(name, OPERATOR_PREFIX, OPERATOR_PREFIX_LENGTH)) | 
|  | 7249 | return false; | 
|  | 7250 |  | 
|  | 7251 | post_op_name = name + OPERATOR_PREFIX_LENGTH; | 
|  | 7252 |  | 
|  | 7253 | if (post_op_name[0] == ' ') | 
|  | 7254 | { | 
|  | 7255 | post_op_name++; | 
|  | 7256 | no_space = false; | 
|  | 7257 | } | 
|  | 7258 |  | 
|  | 7259 | #undef OPERATOR_PREFIX | 
|  | 7260 | #undef OPERATOR_PREFIX_LENGTH | 
|  | 7261 |  | 
|  | 7262 | // This is an operator, set the overloaded operator kind to invalid | 
|  | 7263 | // in case this is a conversion operator... | 
|  | 7264 | op_kind = clang::NUM_OVERLOADED_OPERATORS; | 
|  | 7265 |  | 
|  | 7266 | switch (post_op_name[0]) | 
|  | 7267 | { | 
|  | 7268 | default: | 
|  | 7269 | if (no_space) | 
|  | 7270 | return false; | 
|  | 7271 | break; | 
|  | 7272 | case 'n': | 
|  | 7273 | if (no_space) | 
|  | 7274 | return false; | 
|  | 7275 | if  (strcmp (post_op_name, "new") == 0) | 
|  | 7276 | op_kind = clang::OO_New; | 
|  | 7277 | else if (strcmp (post_op_name, "new[]") == 0) | 
|  | 7278 | op_kind = clang::OO_Array_New; | 
|  | 7279 | break; | 
|  | 7280 |  | 
|  | 7281 | case 'd': | 
|  | 7282 | if (no_space) | 
|  | 7283 | return false; | 
|  | 7284 | if (strcmp (post_op_name, "delete") == 0) | 
|  | 7285 | op_kind = clang::OO_Delete; | 
|  | 7286 | else if (strcmp (post_op_name, "delete[]") == 0) | 
|  | 7287 | op_kind = clang::OO_Array_Delete; | 
|  | 7288 | break; | 
|  | 7289 |  | 
|  | 7290 | case '+': | 
|  | 7291 | if (post_op_name[1] == '\0') | 
|  | 7292 | op_kind = clang::OO_Plus; | 
|  | 7293 | else if (post_op_name[2] == '\0') | 
|  | 7294 | { | 
|  | 7295 | if (post_op_name[1] == '=') | 
|  | 7296 | op_kind = clang::OO_PlusEqual; | 
|  | 7297 | else if (post_op_name[1] == '+') | 
|  | 7298 | op_kind = clang::OO_PlusPlus; | 
|  | 7299 | } | 
|  | 7300 | break; | 
|  | 7301 |  | 
|  | 7302 | case '-': | 
|  | 7303 | if (post_op_name[1] == '\0') | 
|  | 7304 | op_kind = clang::OO_Minus; | 
|  | 7305 | else if (post_op_name[2] == '\0') | 
|  | 7306 | { | 
|  | 7307 | switch (post_op_name[1]) | 
|  | 7308 | { | 
|  | 7309 | case '=': op_kind = clang::OO_MinusEqual; break; | 
|  | 7310 | case '-': op_kind = clang::OO_MinusMinus; break; | 
|  | 7311 | case '>': op_kind = clang::OO_Arrow; break; | 
|  | 7312 | } | 
|  | 7313 | } | 
|  | 7314 | else if (post_op_name[3] == '\0') | 
|  | 7315 | { | 
|  | 7316 | if (post_op_name[2] == '*') | 
|  | 7317 | op_kind = clang::OO_ArrowStar; break; | 
|  | 7318 | } | 
|  | 7319 | break; | 
|  | 7320 |  | 
|  | 7321 | case '*': | 
|  | 7322 | if (post_op_name[1] == '\0') | 
|  | 7323 | op_kind = clang::OO_Star; | 
|  | 7324 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') | 
|  | 7325 | op_kind = clang::OO_StarEqual; | 
|  | 7326 | break; | 
|  | 7327 |  | 
|  | 7328 | case '/': | 
|  | 7329 | if (post_op_name[1] == '\0') | 
|  | 7330 | op_kind = clang::OO_Slash; | 
|  | 7331 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') | 
|  | 7332 | op_kind = clang::OO_SlashEqual; | 
|  | 7333 | break; | 
|  | 7334 |  | 
|  | 7335 | case '%': | 
|  | 7336 | if (post_op_name[1] == '\0') | 
|  | 7337 | op_kind = clang::OO_Percent; | 
|  | 7338 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') | 
|  | 7339 | op_kind = clang::OO_PercentEqual; | 
|  | 7340 | break; | 
|  | 7341 |  | 
|  | 7342 |  | 
|  | 7343 | case '^': | 
|  | 7344 | if (post_op_name[1] == '\0') | 
|  | 7345 | op_kind = clang::OO_Caret; | 
|  | 7346 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') | 
|  | 7347 | op_kind = clang::OO_CaretEqual; | 
|  | 7348 | break; | 
|  | 7349 |  | 
|  | 7350 | case '&': | 
|  | 7351 | if (post_op_name[1] == '\0') | 
|  | 7352 | op_kind = clang::OO_Amp; | 
|  | 7353 | else if (post_op_name[2] == '\0') | 
|  | 7354 | { | 
|  | 7355 | switch (post_op_name[1]) | 
|  | 7356 | { | 
|  | 7357 | case '=': op_kind = clang::OO_AmpEqual; break; | 
|  | 7358 | case '&': op_kind = clang::OO_AmpAmp; break; | 
|  | 7359 | } | 
|  | 7360 | } | 
|  | 7361 | break; | 
|  | 7362 |  | 
|  | 7363 | case '|': | 
|  | 7364 | if (post_op_name[1] == '\0') | 
|  | 7365 | op_kind = clang::OO_Pipe; | 
|  | 7366 | else if (post_op_name[2] == '\0') | 
|  | 7367 | { | 
|  | 7368 | switch (post_op_name[1]) | 
|  | 7369 | { | 
|  | 7370 | case '=': op_kind = clang::OO_PipeEqual; break; | 
|  | 7371 | case '|': op_kind = clang::OO_PipePipe; break; | 
|  | 7372 | } | 
|  | 7373 | } | 
|  | 7374 | break; | 
|  | 7375 |  | 
|  | 7376 | case '~': | 
|  | 7377 | if (post_op_name[1] == '\0') | 
|  | 7378 | op_kind = clang::OO_Tilde; | 
|  | 7379 | break; | 
|  | 7380 |  | 
|  | 7381 | case '!': | 
|  | 7382 | if (post_op_name[1] == '\0') | 
|  | 7383 | op_kind = clang::OO_Exclaim; | 
|  | 7384 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') | 
|  | 7385 | op_kind = clang::OO_ExclaimEqual; | 
|  | 7386 | break; | 
|  | 7387 |  | 
|  | 7388 | case '=': | 
|  | 7389 | if (post_op_name[1] == '\0') | 
|  | 7390 | op_kind = clang::OO_Equal; | 
|  | 7391 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') | 
|  | 7392 | op_kind = clang::OO_EqualEqual; | 
|  | 7393 | break; | 
|  | 7394 |  | 
|  | 7395 | case '<': | 
|  | 7396 | if (post_op_name[1] == '\0') | 
|  | 7397 | op_kind = clang::OO_Less; | 
|  | 7398 | else if (post_op_name[2] == '\0') | 
|  | 7399 | { | 
|  | 7400 | switch (post_op_name[1]) | 
|  | 7401 | { | 
|  | 7402 | case '<': op_kind = clang::OO_LessLess; break; | 
|  | 7403 | case '=': op_kind = clang::OO_LessEqual; break; | 
|  | 7404 | } | 
|  | 7405 | } | 
|  | 7406 | else if (post_op_name[3] == '\0') | 
|  | 7407 | { | 
|  | 7408 | if (post_op_name[2] == '=') | 
|  | 7409 | op_kind = clang::OO_LessLessEqual; | 
|  | 7410 | } | 
|  | 7411 | break; | 
|  | 7412 |  | 
|  | 7413 | case '>': | 
|  | 7414 | if (post_op_name[1] == '\0') | 
|  | 7415 | op_kind = clang::OO_Greater; | 
|  | 7416 | else if (post_op_name[2] == '\0') | 
|  | 7417 | { | 
|  | 7418 | switch (post_op_name[1]) | 
|  | 7419 | { | 
|  | 7420 | case '>': op_kind = clang::OO_GreaterGreater; break; | 
|  | 7421 | case '=': op_kind = clang::OO_GreaterEqual; break; | 
|  | 7422 | } | 
|  | 7423 | } | 
|  | 7424 | else if (post_op_name[1] == '>' && | 
|  | 7425 | post_op_name[2] == '=' && | 
|  | 7426 | post_op_name[3] == '\0') | 
|  | 7427 | { | 
|  | 7428 | op_kind = clang::OO_GreaterGreaterEqual; | 
|  | 7429 | } | 
|  | 7430 | break; | 
|  | 7431 |  | 
|  | 7432 | case ',': | 
|  | 7433 | if (post_op_name[1] == '\0') | 
|  | 7434 | op_kind = clang::OO_Comma; | 
|  | 7435 | break; | 
|  | 7436 |  | 
|  | 7437 | case '(': | 
|  | 7438 | if (post_op_name[1] == ')' && post_op_name[2] == '\0') | 
|  | 7439 | op_kind = clang::OO_Call; | 
|  | 7440 | break; | 
|  | 7441 |  | 
|  | 7442 | case '[': | 
|  | 7443 | if (post_op_name[1] == ']' && post_op_name[2] == '\0') | 
|  | 7444 | op_kind = clang::OO_Subscript; | 
|  | 7445 | break; | 
|  | 7446 | } | 
|  | 7447 |  | 
|  | 7448 | return true; | 
|  | 7449 | } | 
|  | 7450 |  | 
|  | 7451 | clang::EnumDecl * | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7452 | ClangASTContext::GetAsEnumDecl (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7453 | { | 
|  | 7454 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)); | 
|  | 7455 | if (enutype) | 
|  | 7456 | return enutype->getDecl(); | 
|  | 7457 | return NULL; | 
|  | 7458 | } | 
|  | 7459 |  | 
|  | 7460 | clang::RecordDecl * | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7461 | ClangASTContext::GetAsRecordDecl (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7462 | { | 
|  | 7463 | const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(GetCanonicalQualType(type)); | 
|  | 7464 | if (record_type) | 
|  | 7465 | return record_type->getDecl(); | 
|  | 7466 | return nullptr; | 
|  | 7467 | } | 
|  | 7468 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 7469 | clang::TagDecl * | 
|  | 7470 | ClangASTContext::GetAsTagDecl (const CompilerType& type) | 
|  | 7471 | { | 
|  | 7472 | clang::QualType qual_type = GetCanonicalQualType(type); | 
|  | 7473 | if (qual_type.isNull()) | 
|  | 7474 | return nullptr; | 
|  | 7475 | else | 
|  | 7476 | return qual_type->getAsTagDecl(); | 
|  | 7477 | } | 
|  | 7478 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7479 | clang::CXXRecordDecl * | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7480 | ClangASTContext::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7481 | { | 
|  | 7482 | return GetCanonicalQualType(type)->getAsCXXRecordDecl(); | 
|  | 7483 | } | 
|  | 7484 |  | 
|  | 7485 | clang::ObjCInterfaceDecl * | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7486 | ClangASTContext::GetAsObjCInterfaceDecl (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7487 | { | 
|  | 7488 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(GetCanonicalQualType(type)); | 
|  | 7489 | if (objc_class_type) | 
|  | 7490 | return objc_class_type->getInterface(); | 
|  | 7491 | return nullptr; | 
|  | 7492 | } | 
|  | 7493 |  | 
|  | 7494 | clang::FieldDecl * | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7495 | ClangASTContext::AddFieldToRecordType (const CompilerType& type, const char *name, | 
|  | 7496 | const CompilerType &field_clang_type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7497 | AccessType access, | 
|  | 7498 | uint32_t bitfield_bit_size) | 
|  | 7499 | { | 
|  | 7500 | if (!type.IsValid() || !field_clang_type.IsValid()) | 
|  | 7501 | return nullptr; | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7502 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7503 | if (!ast) | 
|  | 7504 | return nullptr; | 
|  | 7505 | clang::ASTContext* clang_ast = ast->getASTContext(); | 
|  | 7506 |  | 
|  | 7507 | clang::FieldDecl *field = nullptr; | 
|  | 7508 |  | 
|  | 7509 | clang::Expr *bit_width = nullptr; | 
|  | 7510 | if (bitfield_bit_size != 0) | 
|  | 7511 | { | 
|  | 7512 | llvm::APInt bitfield_bit_size_apint(clang_ast->getTypeSize(clang_ast->IntTy), bitfield_bit_size); | 
|  | 7513 | bit_width = new (*clang_ast)clang::IntegerLiteral (*clang_ast, bitfield_bit_size_apint, clang_ast->IntTy, clang::SourceLocation()); | 
|  | 7514 | } | 
|  | 7515 |  | 
|  | 7516 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type); | 
|  | 7517 | if (record_decl) | 
|  | 7518 | { | 
|  | 7519 | field = clang::FieldDecl::Create (*clang_ast, | 
|  | 7520 | record_decl, | 
|  | 7521 | clang::SourceLocation(), | 
|  | 7522 | clang::SourceLocation(), | 
|  | 7523 | name ? &clang_ast->Idents.get(name) : nullptr,  // Identifier | 
|  | 7524 | GetQualType(field_clang_type),             // Field type | 
|  | 7525 | nullptr,                                    // TInfo * | 
|  | 7526 | bit_width,                                  // BitWidth | 
|  | 7527 | false,                                      // Mutable | 
|  | 7528 | clang::ICIS_NoInit);                        // HasInit | 
|  | 7529 |  | 
|  | 7530 | if (!name) | 
|  | 7531 | { | 
|  | 7532 | // Determine whether this field corresponds to an anonymous | 
|  | 7533 | // struct or union. | 
|  | 7534 | if (const clang::TagType *TagT = field->getType()->getAs<clang::TagType>()) { | 
|  | 7535 | if (clang::RecordDecl *Rec = llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl())) | 
|  | 7536 | if (!Rec->getDeclName()) { | 
|  | 7537 | Rec->setAnonymousStructOrUnion(true); | 
|  | 7538 | field->setImplicit(); | 
|  | 7539 |  | 
|  | 7540 | } | 
|  | 7541 | } | 
|  | 7542 | } | 
|  | 7543 |  | 
|  | 7544 | if (field) | 
|  | 7545 | { | 
|  | 7546 | field->setAccess (ClangASTContext::ConvertAccessTypeToAccessSpecifier (access)); | 
|  | 7547 |  | 
|  | 7548 | record_decl->addDecl(field); | 
|  | 7549 |  | 
|  | 7550 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 7551 | VerifyDecl(field); | 
|  | 7552 | #endif | 
|  | 7553 | } | 
|  | 7554 | } | 
|  | 7555 | else | 
|  | 7556 | { | 
|  | 7557 | clang::ObjCInterfaceDecl *class_interface_decl = ast->GetAsObjCInterfaceDecl (type); | 
|  | 7558 |  | 
|  | 7559 | if (class_interface_decl) | 
|  | 7560 | { | 
|  | 7561 | const bool is_synthesized = false; | 
|  | 7562 |  | 
|  | 7563 | field_clang_type.GetCompleteType(); | 
|  | 7564 |  | 
|  | 7565 | field = clang::ObjCIvarDecl::Create (*clang_ast, | 
|  | 7566 | class_interface_decl, | 
|  | 7567 | clang::SourceLocation(), | 
|  | 7568 | clang::SourceLocation(), | 
|  | 7569 | name ? &clang_ast->Idents.get(name) : nullptr,   // Identifier | 
|  | 7570 | GetQualType(field_clang_type),           // Field type | 
|  | 7571 | nullptr,                                     // TypeSourceInfo * | 
|  | 7572 | ConvertAccessTypeToObjCIvarAccessControl (access), | 
|  | 7573 | bit_width, | 
|  | 7574 | is_synthesized); | 
|  | 7575 |  | 
|  | 7576 | if (field) | 
|  | 7577 | { | 
|  | 7578 | class_interface_decl->addDecl(field); | 
|  | 7579 |  | 
|  | 7580 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 7581 | VerifyDecl(field); | 
|  | 7582 | #endif | 
|  | 7583 | } | 
|  | 7584 | } | 
|  | 7585 | } | 
|  | 7586 | return field; | 
|  | 7587 | } | 
|  | 7588 |  | 
|  | 7589 | void | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7590 | ClangASTContext::BuildIndirectFields (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7591 | { | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7592 | if (!type) | 
|  | 7593 | return; | 
|  | 7594 |  | 
|  | 7595 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7596 | if (!ast) | 
|  | 7597 | return; | 
|  | 7598 |  | 
|  | 7599 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type); | 
|  | 7600 |  | 
|  | 7601 | if (!record_decl) | 
|  | 7602 | return; | 
|  | 7603 |  | 
|  | 7604 | typedef llvm::SmallVector <clang::IndirectFieldDecl *, 1> IndirectFieldVector; | 
|  | 7605 |  | 
|  | 7606 | IndirectFieldVector indirect_fields; | 
|  | 7607 | clang::RecordDecl::field_iterator field_pos; | 
|  | 7608 | clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end(); | 
|  | 7609 | clang::RecordDecl::field_iterator last_field_pos = field_end_pos; | 
|  | 7610 | for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; last_field_pos = field_pos++) | 
|  | 7611 | { | 
|  | 7612 | if (field_pos->isAnonymousStructOrUnion()) | 
|  | 7613 | { | 
|  | 7614 | clang::QualType field_qual_type = field_pos->getType(); | 
|  | 7615 |  | 
|  | 7616 | const clang::RecordType *field_record_type = field_qual_type->getAs<clang::RecordType>(); | 
|  | 7617 |  | 
|  | 7618 | if (!field_record_type) | 
|  | 7619 | continue; | 
|  | 7620 |  | 
|  | 7621 | clang::RecordDecl *field_record_decl = field_record_type->getDecl(); | 
|  | 7622 |  | 
|  | 7623 | if (!field_record_decl) | 
|  | 7624 | continue; | 
|  | 7625 |  | 
|  | 7626 | for (clang::RecordDecl::decl_iterator di = field_record_decl->decls_begin(), de = field_record_decl->decls_end(); | 
|  | 7627 | di != de; | 
|  | 7628 | ++di) | 
|  | 7629 | { | 
|  | 7630 | if (clang::FieldDecl *nested_field_decl = llvm::dyn_cast<clang::FieldDecl>(*di)) | 
|  | 7631 | { | 
|  | 7632 | clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[2]; | 
|  | 7633 | chain[0] = *field_pos; | 
|  | 7634 | chain[1] = nested_field_decl; | 
|  | 7635 | clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(), | 
|  | 7636 | record_decl, | 
|  | 7637 | clang::SourceLocation(), | 
|  | 7638 | nested_field_decl->getIdentifier(), | 
|  | 7639 | nested_field_decl->getType(), | 
|  | 7640 | chain, | 
|  | 7641 | 2); | 
|  | 7642 |  | 
|  | 7643 | indirect_field->setImplicit(); | 
|  | 7644 |  | 
|  | 7645 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(), | 
|  | 7646 | nested_field_decl->getAccess())); | 
|  | 7647 |  | 
|  | 7648 | indirect_fields.push_back(indirect_field); | 
|  | 7649 | } | 
|  | 7650 | else if (clang::IndirectFieldDecl *nested_indirect_field_decl = llvm::dyn_cast<clang::IndirectFieldDecl>(*di)) | 
|  | 7651 | { | 
|  | 7652 | int nested_chain_size = nested_indirect_field_decl->getChainingSize(); | 
|  | 7653 | clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[nested_chain_size + 1]; | 
|  | 7654 | chain[0] = *field_pos; | 
|  | 7655 |  | 
|  | 7656 | int chain_index = 1; | 
|  | 7657 | for (clang::IndirectFieldDecl::chain_iterator nci = nested_indirect_field_decl->chain_begin(), | 
|  | 7658 | nce = nested_indirect_field_decl->chain_end(); | 
|  | 7659 | nci < nce; | 
|  | 7660 | ++nci) | 
|  | 7661 | { | 
|  | 7662 | chain[chain_index] = *nci; | 
|  | 7663 | chain_index++; | 
|  | 7664 | } | 
|  | 7665 |  | 
|  | 7666 | clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(), | 
|  | 7667 | record_decl, | 
|  | 7668 | clang::SourceLocation(), | 
|  | 7669 | nested_indirect_field_decl->getIdentifier(), | 
|  | 7670 | nested_indirect_field_decl->getType(), | 
|  | 7671 | chain, | 
|  | 7672 | nested_chain_size + 1); | 
|  | 7673 |  | 
|  | 7674 | indirect_field->setImplicit(); | 
|  | 7675 |  | 
|  | 7676 | indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(), | 
|  | 7677 | nested_indirect_field_decl->getAccess())); | 
|  | 7678 |  | 
|  | 7679 | indirect_fields.push_back(indirect_field); | 
|  | 7680 | } | 
|  | 7681 | } | 
|  | 7682 | } | 
|  | 7683 | } | 
|  | 7684 |  | 
|  | 7685 | // Check the last field to see if it has an incomplete array type as its | 
|  | 7686 | // last member and if it does, the tell the record decl about it | 
|  | 7687 | if (last_field_pos != field_end_pos) | 
|  | 7688 | { | 
|  | 7689 | if (last_field_pos->getType()->isIncompleteArrayType()) | 
|  | 7690 | record_decl->hasFlexibleArrayMember(); | 
|  | 7691 | } | 
|  | 7692 |  | 
|  | 7693 | for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), ife = indirect_fields.end(); | 
|  | 7694 | ifi < ife; | 
|  | 7695 | ++ifi) | 
|  | 7696 | { | 
|  | 7697 | record_decl->addDecl(*ifi); | 
|  | 7698 | } | 
|  | 7699 | } | 
|  | 7700 |  | 
|  | 7701 | void | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7702 | ClangASTContext::SetIsPacked (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7703 | { | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7704 | if (type) | 
|  | 7705 | { | 
|  | 7706 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); | 
|  | 7707 | if (ast) | 
|  | 7708 | { | 
|  | 7709 | clang::RecordDecl *record_decl = GetAsRecordDecl(type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7710 |  | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7711 | if (!record_decl) | 
|  | 7712 | return; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7713 |  | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7714 | record_decl->addAttr(clang::PackedAttr::CreateImplicit(*ast->getASTContext())); | 
|  | 7715 | } | 
|  | 7716 | } | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7717 | } | 
|  | 7718 |  | 
|  | 7719 | clang::VarDecl * | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7720 | ClangASTContext::AddVariableToRecordType (const CompilerType& type, const char *name, | 
|  | 7721 | const CompilerType &var_type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7722 | AccessType access) | 
|  | 7723 | { | 
|  | 7724 | clang::VarDecl *var_decl = nullptr; | 
|  | 7725 |  | 
|  | 7726 | if (!type.IsValid() || !var_type.IsValid()) | 
|  | 7727 | return nullptr; | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 7728 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7729 | if (!ast) | 
|  | 7730 | return nullptr; | 
|  | 7731 |  | 
|  | 7732 | clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type); | 
|  | 7733 | if (record_decl) | 
|  | 7734 | { | 
|  | 7735 | var_decl = clang::VarDecl::Create (*ast->getASTContext(),                      // ASTContext & | 
|  | 7736 | record_decl,                                // DeclContext * | 
|  | 7737 | clang::SourceLocation(),                    // clang::SourceLocation StartLoc | 
|  | 7738 | clang::SourceLocation(),                    // clang::SourceLocation IdLoc | 
|  | 7739 | name ? &ast->getASTContext()->Idents.get(name) : nullptr,  // clang::IdentifierInfo * | 
|  | 7740 | GetQualType(var_type),                      // Variable clang::QualType | 
|  | 7741 | nullptr,                                    // TypeSourceInfo * | 
|  | 7742 | clang::SC_Static);                          // StorageClass | 
|  | 7743 | if (var_decl) | 
|  | 7744 | { | 
|  | 7745 | var_decl->setAccess(ClangASTContext::ConvertAccessTypeToAccessSpecifier (access)); | 
|  | 7746 | record_decl->addDecl(var_decl); | 
|  | 7747 |  | 
|  | 7748 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 7749 | VerifyDecl(var_decl); | 
|  | 7750 | #endif | 
|  | 7751 | } | 
|  | 7752 | } | 
|  | 7753 | return var_decl; | 
|  | 7754 | } | 
|  | 7755 |  | 
|  | 7756 |  | 
|  | 7757 | clang::CXXMethodDecl * | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7758 | ClangASTContext::AddMethodToCXXRecordType (lldb::opaque_compiler_type_t type, const char *name, | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 7759 | const CompilerType &method_clang_type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 7760 | lldb::AccessType access, | 
|  | 7761 | bool is_virtual, | 
|  | 7762 | bool is_static, | 
|  | 7763 | bool is_inline, | 
|  | 7764 | bool is_explicit, | 
|  | 7765 | bool is_attr_used, | 
|  | 7766 | bool is_artificial) | 
|  | 7767 | { | 
|  | 7768 | if (!type || !method_clang_type.IsValid() || name == nullptr || name[0] == '\0') | 
|  | 7769 | return nullptr; | 
|  | 7770 |  | 
|  | 7771 | clang::QualType record_qual_type(GetCanonicalQualType(type)); | 
|  | 7772 |  | 
|  | 7773 | clang::CXXRecordDecl *cxx_record_decl = record_qual_type->getAsCXXRecordDecl(); | 
|  | 7774 |  | 
|  | 7775 | if (cxx_record_decl == nullptr) | 
|  | 7776 | return nullptr; | 
|  | 7777 |  | 
|  | 7778 | clang::QualType method_qual_type (GetQualType(method_clang_type)); | 
|  | 7779 |  | 
|  | 7780 | clang::CXXMethodDecl *cxx_method_decl = nullptr; | 
|  | 7781 |  | 
|  | 7782 | clang::DeclarationName decl_name (&getASTContext()->Idents.get(name)); | 
|  | 7783 |  | 
|  | 7784 | const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr()); | 
|  | 7785 |  | 
|  | 7786 | if (function_type == nullptr) | 
|  | 7787 | return nullptr; | 
|  | 7788 |  | 
|  | 7789 | const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(function_type)); | 
|  | 7790 |  | 
|  | 7791 | if (!method_function_prototype) | 
|  | 7792 | return nullptr; | 
|  | 7793 |  | 
|  | 7794 | unsigned int num_params = method_function_prototype->getNumParams(); | 
|  | 7795 |  | 
|  | 7796 | clang::CXXDestructorDecl *cxx_dtor_decl(nullptr); | 
|  | 7797 | clang::CXXConstructorDecl *cxx_ctor_decl(nullptr); | 
|  | 7798 |  | 
|  | 7799 | if (is_artificial) | 
|  | 7800 | return nullptr; // skip everything artificial | 
|  | 7801 |  | 
|  | 7802 | if (name[0] == '~') | 
|  | 7803 | { | 
|  | 7804 | cxx_dtor_decl = clang::CXXDestructorDecl::Create (*getASTContext(), | 
|  | 7805 | cxx_record_decl, | 
|  | 7806 | clang::SourceLocation(), | 
|  | 7807 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXDestructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()), | 
|  | 7808 | method_qual_type, | 
|  | 7809 | nullptr, | 
|  | 7810 | is_inline, | 
|  | 7811 | is_artificial); | 
|  | 7812 | cxx_method_decl = cxx_dtor_decl; | 
|  | 7813 | } | 
|  | 7814 | else if (decl_name == cxx_record_decl->getDeclName()) | 
|  | 7815 | { | 
|  | 7816 | cxx_ctor_decl = clang::CXXConstructorDecl::Create (*getASTContext(), | 
|  | 7817 | cxx_record_decl, | 
|  | 7818 | clang::SourceLocation(), | 
|  | 7819 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConstructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()), | 
|  | 7820 | method_qual_type, | 
|  | 7821 | nullptr, // TypeSourceInfo * | 
|  | 7822 | is_explicit, | 
|  | 7823 | is_inline, | 
|  | 7824 | is_artificial, | 
|  | 7825 | false /*is_constexpr*/); | 
|  | 7826 | cxx_method_decl = cxx_ctor_decl; | 
|  | 7827 | } | 
|  | 7828 | else | 
|  | 7829 | { | 
|  | 7830 | clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None; | 
|  | 7831 | clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS; | 
|  | 7832 |  | 
|  | 7833 | if (IsOperator (name, op_kind)) | 
|  | 7834 | { | 
|  | 7835 | if (op_kind != clang::NUM_OVERLOADED_OPERATORS) | 
|  | 7836 | { | 
|  | 7837 | // Check the number of operator parameters. Sometimes we have | 
|  | 7838 | // seen bad DWARF that doesn't correctly describe operators and | 
|  | 7839 | // if we try to create a method and add it to the class, clang | 
|  | 7840 | // will assert and crash, so we need to make sure things are | 
|  | 7841 | // acceptable. | 
|  | 7842 | if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount (op_kind, num_params)) | 
|  | 7843 | return nullptr; | 
|  | 7844 | cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(), | 
|  | 7845 | cxx_record_decl, | 
|  | 7846 | clang::SourceLocation(), | 
|  | 7847 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXOperatorName (op_kind), clang::SourceLocation()), | 
|  | 7848 | method_qual_type, | 
|  | 7849 | nullptr, // TypeSourceInfo * | 
|  | 7850 | SC, | 
|  | 7851 | is_inline, | 
|  | 7852 | false /*is_constexpr*/, | 
|  | 7853 | clang::SourceLocation()); | 
|  | 7854 | } | 
|  | 7855 | else if (num_params == 0) | 
|  | 7856 | { | 
|  | 7857 | // Conversion operators don't take params... | 
|  | 7858 | cxx_method_decl = clang::CXXConversionDecl::Create (*getASTContext(), | 
|  | 7859 | cxx_record_decl, | 
|  | 7860 | clang::SourceLocation(), | 
|  | 7861 | clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConversionFunctionName (getASTContext()->getCanonicalType (function_type->getReturnType())), clang::SourceLocation()), | 
|  | 7862 | method_qual_type, | 
|  | 7863 | nullptr, // TypeSourceInfo * | 
|  | 7864 | is_inline, | 
|  | 7865 | is_explicit, | 
|  | 7866 | false /*is_constexpr*/, | 
|  | 7867 | clang::SourceLocation()); | 
|  | 7868 | } | 
|  | 7869 | } | 
|  | 7870 |  | 
|  | 7871 | if (cxx_method_decl == nullptr) | 
|  | 7872 | { | 
|  | 7873 | cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(), | 
|  | 7874 | cxx_record_decl, | 
|  | 7875 | clang::SourceLocation(), | 
|  | 7876 | clang::DeclarationNameInfo (decl_name, clang::SourceLocation()), | 
|  | 7877 | method_qual_type, | 
|  | 7878 | nullptr, // TypeSourceInfo * | 
|  | 7879 | SC, | 
|  | 7880 | is_inline, | 
|  | 7881 | false /*is_constexpr*/, | 
|  | 7882 | clang::SourceLocation()); | 
|  | 7883 | } | 
|  | 7884 | } | 
|  | 7885 |  | 
|  | 7886 | clang::AccessSpecifier access_specifier = ClangASTContext::ConvertAccessTypeToAccessSpecifier (access); | 
|  | 7887 |  | 
|  | 7888 | cxx_method_decl->setAccess (access_specifier); | 
|  | 7889 | cxx_method_decl->setVirtualAsWritten (is_virtual); | 
|  | 7890 |  | 
|  | 7891 | if (is_attr_used) | 
|  | 7892 | cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext())); | 
|  | 7893 |  | 
|  | 7894 | // Populate the method decl with parameter decls | 
|  | 7895 |  | 
|  | 7896 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; | 
|  | 7897 |  | 
|  | 7898 | for (unsigned param_index = 0; | 
|  | 7899 | param_index < num_params; | 
|  | 7900 | ++param_index) | 
|  | 7901 | { | 
|  | 7902 | params.push_back (clang::ParmVarDecl::Create (*getASTContext(), | 
|  | 7903 | cxx_method_decl, | 
|  | 7904 | clang::SourceLocation(), | 
|  | 7905 | clang::SourceLocation(), | 
|  | 7906 | nullptr, // anonymous | 
|  | 7907 | method_function_prototype->getParamType(param_index), | 
|  | 7908 | nullptr, | 
|  | 7909 | clang::SC_None, | 
|  | 7910 | nullptr)); | 
|  | 7911 | } | 
|  | 7912 |  | 
|  | 7913 | cxx_method_decl->setParams (llvm::ArrayRef<clang::ParmVarDecl*>(params)); | 
|  | 7914 |  | 
|  | 7915 | cxx_record_decl->addDecl (cxx_method_decl); | 
|  | 7916 |  | 
|  | 7917 | // Sometimes the debug info will mention a constructor (default/copy/move), | 
|  | 7918 | // destructor, or assignment operator (copy/move) but there won't be any | 
|  | 7919 | // version of this in the code. So we check if the function was artificially | 
|  | 7920 | // generated and if it is trivial and this lets the compiler/backend know | 
|  | 7921 | // that it can inline the IR for these when it needs to and we can avoid a | 
|  | 7922 | // "missing function" error when running expressions. | 
|  | 7923 |  | 
|  | 7924 | if (is_artificial) | 
|  | 7925 | { | 
|  | 7926 | if (cxx_ctor_decl && | 
|  | 7927 | ((cxx_ctor_decl->isDefaultConstructor() && cxx_record_decl->hasTrivialDefaultConstructor ()) || | 
|  | 7928 | (cxx_ctor_decl->isCopyConstructor()    && cxx_record_decl->hasTrivialCopyConstructor    ()) || | 
|  | 7929 | (cxx_ctor_decl->isMoveConstructor()    && cxx_record_decl->hasTrivialMoveConstructor    ()) )) | 
|  | 7930 | { | 
|  | 7931 | cxx_ctor_decl->setDefaulted(); | 
|  | 7932 | cxx_ctor_decl->setTrivial(true); | 
|  | 7933 | } | 
|  | 7934 | else if (cxx_dtor_decl) | 
|  | 7935 | { | 
|  | 7936 | if (cxx_record_decl->hasTrivialDestructor()) | 
|  | 7937 | { | 
|  | 7938 | cxx_dtor_decl->setDefaulted(); | 
|  | 7939 | cxx_dtor_decl->setTrivial(true); | 
|  | 7940 | } | 
|  | 7941 | } | 
|  | 7942 | else if ((cxx_method_decl->isCopyAssignmentOperator() && cxx_record_decl->hasTrivialCopyAssignment()) || | 
|  | 7943 | (cxx_method_decl->isMoveAssignmentOperator() && cxx_record_decl->hasTrivialMoveAssignment())) | 
|  | 7944 | { | 
|  | 7945 | cxx_method_decl->setDefaulted(); | 
|  | 7946 | cxx_method_decl->setTrivial(true); | 
|  | 7947 | } | 
|  | 7948 | } | 
|  | 7949 |  | 
|  | 7950 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 7951 | VerifyDecl(cxx_method_decl); | 
|  | 7952 | #endif | 
|  | 7953 |  | 
|  | 7954 | //    printf ("decl->isPolymorphic()             = %i\n", cxx_record_decl->isPolymorphic()); | 
|  | 7955 | //    printf ("decl->isAggregate()               = %i\n", cxx_record_decl->isAggregate()); | 
|  | 7956 | //    printf ("decl->isPOD()                     = %i\n", cxx_record_decl->isPOD()); | 
|  | 7957 | //    printf ("decl->isEmpty()                   = %i\n", cxx_record_decl->isEmpty()); | 
|  | 7958 | //    printf ("decl->isAbstract()                = %i\n", cxx_record_decl->isAbstract()); | 
|  | 7959 | //    printf ("decl->hasTrivialConstructor()     = %i\n", cxx_record_decl->hasTrivialConstructor()); | 
|  | 7960 | //    printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor()); | 
|  | 7961 | //    printf ("decl->hasTrivialCopyAssignment()  = %i\n", cxx_record_decl->hasTrivialCopyAssignment()); | 
|  | 7962 | //    printf ("decl->hasTrivialDestructor()      = %i\n", cxx_record_decl->hasTrivialDestructor()); | 
|  | 7963 | return cxx_method_decl; | 
|  | 7964 | } | 
|  | 7965 |  | 
|  | 7966 |  | 
|  | 7967 | #pragma mark C++ Base Classes | 
|  | 7968 |  | 
|  | 7969 | clang::CXXBaseSpecifier * | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7970 | 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] | 7971 | { | 
|  | 7972 | if (type) | 
|  | 7973 | return new clang::CXXBaseSpecifier (clang::SourceRange(), | 
|  | 7974 | is_virtual, | 
|  | 7975 | base_of_class, | 
|  | 7976 | ClangASTContext::ConvertAccessTypeToAccessSpecifier (access), | 
|  | 7977 | getASTContext()->getTrivialTypeSourceInfo (GetQualType(type)), | 
|  | 7978 | clang::SourceLocation()); | 
|  | 7979 | return nullptr; | 
|  | 7980 | } | 
|  | 7981 |  | 
|  | 7982 | void | 
|  | 7983 | ClangASTContext::DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, unsigned num_base_classes) | 
|  | 7984 | { | 
|  | 7985 | for (unsigned i=0; i<num_base_classes; ++i) | 
|  | 7986 | { | 
|  | 7987 | delete base_classes[i]; | 
|  | 7988 | base_classes[i] = nullptr; | 
|  | 7989 | } | 
|  | 7990 | } | 
|  | 7991 |  | 
|  | 7992 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 7993 | 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] | 7994 | unsigned num_base_classes) | 
|  | 7995 | { | 
|  | 7996 | if (type) | 
|  | 7997 | { | 
|  | 7998 | clang::CXXRecordDecl *cxx_record_decl = GetAsCXXRecordDecl(type); | 
|  | 7999 | if (cxx_record_decl) | 
|  | 8000 | { | 
|  | 8001 | cxx_record_decl->setBases(base_classes, num_base_classes); | 
|  | 8002 | return true; | 
|  | 8003 | } | 
|  | 8004 | } | 
|  | 8005 | return false; | 
|  | 8006 | } | 
|  | 8007 |  | 
|  | 8008 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8009 | ClangASTContext::SetObjCSuperClass (const CompilerType& type, const CompilerType &superclass_clang_type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8010 | { | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8011 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8012 | if (!ast) | 
|  | 8013 | return false; | 
|  | 8014 | clang::ASTContext* clang_ast = ast->getASTContext(); | 
|  | 8015 |  | 
|  | 8016 | if (type && superclass_clang_type.IsValid() && superclass_clang_type.GetTypeSystem() == type.GetTypeSystem()) | 
|  | 8017 | { | 
|  | 8018 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); | 
|  | 8019 | clang::ObjCInterfaceDecl *super_interface_decl = GetAsObjCInterfaceDecl (superclass_clang_type); | 
|  | 8020 | if (class_interface_decl && super_interface_decl) | 
|  | 8021 | { | 
|  | 8022 | class_interface_decl->setSuperClass(clang_ast->getTrivialTypeSourceInfo(clang_ast->getObjCInterfaceType(super_interface_decl))); | 
|  | 8023 | return true; | 
|  | 8024 | } | 
|  | 8025 | } | 
|  | 8026 | return false; | 
|  | 8027 | } | 
|  | 8028 |  | 
|  | 8029 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8030 | ClangASTContext::AddObjCClassProperty (const CompilerType& type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8031 | const char *property_name, | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8032 | const CompilerType &property_clang_type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8033 | clang::ObjCIvarDecl *ivar_decl, | 
|  | 8034 | const char *property_setter_name, | 
|  | 8035 | const char *property_getter_name, | 
|  | 8036 | uint32_t property_attributes, | 
|  | 8037 | ClangASTMetadata *metadata) | 
|  | 8038 | { | 
|  | 8039 | if (!type || !property_clang_type.IsValid() || property_name == nullptr || property_name[0] == '\0') | 
|  | 8040 | return false; | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8041 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8042 | if (!ast) | 
|  | 8043 | return false; | 
|  | 8044 | clang::ASTContext* clang_ast = ast->getASTContext(); | 
|  | 8045 |  | 
|  | 8046 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); | 
|  | 8047 |  | 
|  | 8048 | if (class_interface_decl) | 
|  | 8049 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8050 | CompilerType property_clang_type_to_access; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8051 |  | 
|  | 8052 | if (property_clang_type.IsValid()) | 
|  | 8053 | property_clang_type_to_access = property_clang_type; | 
|  | 8054 | else if (ivar_decl) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8055 | property_clang_type_to_access = CompilerType (clang_ast, ivar_decl->getType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8056 |  | 
|  | 8057 | if (class_interface_decl && property_clang_type_to_access.IsValid()) | 
|  | 8058 | { | 
|  | 8059 | clang::TypeSourceInfo *prop_type_source; | 
|  | 8060 | if (ivar_decl) | 
|  | 8061 | prop_type_source = clang_ast->getTrivialTypeSourceInfo (ivar_decl->getType()); | 
|  | 8062 | else | 
|  | 8063 | prop_type_source = clang_ast->getTrivialTypeSourceInfo (GetQualType(property_clang_type)); | 
|  | 8064 |  | 
|  | 8065 | clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create (*clang_ast, | 
|  | 8066 | class_interface_decl, | 
|  | 8067 | clang::SourceLocation(), // Source Location | 
|  | 8068 | &clang_ast->Idents.get(property_name), | 
|  | 8069 | clang::SourceLocation(), //Source Location for AT | 
|  | 8070 | clang::SourceLocation(), //Source location for ( | 
|  | 8071 | ivar_decl ? ivar_decl->getType() : ClangASTContext::GetQualType(property_clang_type), | 
|  | 8072 | prop_type_source); | 
|  | 8073 |  | 
|  | 8074 | if (property_decl) | 
|  | 8075 | { | 
|  | 8076 | if (metadata) | 
|  | 8077 | ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata); | 
|  | 8078 |  | 
|  | 8079 | class_interface_decl->addDecl (property_decl); | 
|  | 8080 |  | 
|  | 8081 | clang::Selector setter_sel, getter_sel; | 
|  | 8082 |  | 
|  | 8083 | if (property_setter_name != nullptr) | 
|  | 8084 | { | 
|  | 8085 | std::string property_setter_no_colon(property_setter_name, strlen(property_setter_name) - 1); | 
|  | 8086 | clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(property_setter_no_colon.c_str()); | 
|  | 8087 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); | 
|  | 8088 | } | 
|  | 8089 | else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) | 
|  | 8090 | { | 
|  | 8091 | std::string setter_sel_string("set"); | 
|  | 8092 | setter_sel_string.push_back(::toupper(property_name[0])); | 
|  | 8093 | setter_sel_string.append(&property_name[1]); | 
|  | 8094 | clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(setter_sel_string.c_str()); | 
|  | 8095 | setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident); | 
|  | 8096 | } | 
|  | 8097 | property_decl->setSetterName(setter_sel); | 
|  | 8098 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter); | 
|  | 8099 |  | 
|  | 8100 | if (property_getter_name != nullptr) | 
|  | 8101 | { | 
|  | 8102 | clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_getter_name); | 
|  | 8103 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); | 
|  | 8104 | } | 
|  | 8105 | else | 
|  | 8106 | { | 
|  | 8107 | clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_name); | 
|  | 8108 | getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident); | 
|  | 8109 | } | 
|  | 8110 | property_decl->setGetterName(getter_sel); | 
|  | 8111 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter); | 
|  | 8112 |  | 
|  | 8113 | if (ivar_decl) | 
|  | 8114 | property_decl->setPropertyIvarDecl (ivar_decl); | 
|  | 8115 |  | 
|  | 8116 | if (property_attributes & DW_APPLE_PROPERTY_readonly) | 
|  | 8117 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readonly); | 
|  | 8118 | if (property_attributes & DW_APPLE_PROPERTY_readwrite) | 
|  | 8119 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readwrite); | 
|  | 8120 | if (property_attributes & DW_APPLE_PROPERTY_assign) | 
|  | 8121 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_assign); | 
|  | 8122 | if (property_attributes & DW_APPLE_PROPERTY_retain) | 
|  | 8123 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_retain); | 
|  | 8124 | if (property_attributes & DW_APPLE_PROPERTY_copy) | 
|  | 8125 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_copy); | 
|  | 8126 | if (property_attributes & DW_APPLE_PROPERTY_nonatomic) | 
|  | 8127 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_nonatomic); | 
|  | 8128 |  | 
|  | 8129 | if (!getter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(getter_sel)) | 
|  | 8130 | { | 
|  | 8131 | const bool isInstance = true; | 
|  | 8132 | const bool isVariadic = false; | 
|  | 8133 | const bool isSynthesized = false; | 
|  | 8134 | const bool isImplicitlyDeclared = true; | 
|  | 8135 | const bool isDefined = false; | 
|  | 8136 | const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None; | 
|  | 8137 | const bool HasRelatedResultType = false; | 
|  | 8138 |  | 
|  | 8139 | clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create (*clang_ast, | 
|  | 8140 | clang::SourceLocation(), | 
|  | 8141 | clang::SourceLocation(), | 
|  | 8142 | getter_sel, | 
|  | 8143 | GetQualType(property_clang_type_to_access), | 
|  | 8144 | nullptr, | 
|  | 8145 | class_interface_decl, | 
|  | 8146 | isInstance, | 
|  | 8147 | isVariadic, | 
|  | 8148 | isSynthesized, | 
|  | 8149 | isImplicitlyDeclared, | 
|  | 8150 | isDefined, | 
|  | 8151 | impControl, | 
|  | 8152 | HasRelatedResultType); | 
|  | 8153 |  | 
|  | 8154 | if (getter && metadata) | 
|  | 8155 | ClangASTContext::SetMetadata(clang_ast, getter, *metadata); | 
|  | 8156 |  | 
|  | 8157 | if (getter) | 
|  | 8158 | { | 
|  | 8159 | getter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(), llvm::ArrayRef<clang::SourceLocation>()); | 
|  | 8160 |  | 
|  | 8161 | class_interface_decl->addDecl(getter); | 
|  | 8162 | } | 
|  | 8163 | } | 
|  | 8164 |  | 
|  | 8165 | if (!setter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(setter_sel)) | 
|  | 8166 | { | 
|  | 8167 | clang::QualType result_type = clang_ast->VoidTy; | 
|  | 8168 |  | 
|  | 8169 | const bool isInstance = true; | 
|  | 8170 | const bool isVariadic = false; | 
|  | 8171 | const bool isSynthesized = false; | 
|  | 8172 | const bool isImplicitlyDeclared = true; | 
|  | 8173 | const bool isDefined = false; | 
|  | 8174 | const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None; | 
|  | 8175 | const bool HasRelatedResultType = false; | 
|  | 8176 |  | 
|  | 8177 | clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create (*clang_ast, | 
|  | 8178 | clang::SourceLocation(), | 
|  | 8179 | clang::SourceLocation(), | 
|  | 8180 | setter_sel, | 
|  | 8181 | result_type, | 
|  | 8182 | nullptr, | 
|  | 8183 | class_interface_decl, | 
|  | 8184 | isInstance, | 
|  | 8185 | isVariadic, | 
|  | 8186 | isSynthesized, | 
|  | 8187 | isImplicitlyDeclared, | 
|  | 8188 | isDefined, | 
|  | 8189 | impControl, | 
|  | 8190 | HasRelatedResultType); | 
|  | 8191 |  | 
|  | 8192 | if (setter && metadata) | 
|  | 8193 | ClangASTContext::SetMetadata(clang_ast, setter, *metadata); | 
|  | 8194 |  | 
|  | 8195 | llvm::SmallVector<clang::ParmVarDecl *, 1> params; | 
|  | 8196 |  | 
|  | 8197 | params.push_back (clang::ParmVarDecl::Create (*clang_ast, | 
|  | 8198 | setter, | 
|  | 8199 | clang::SourceLocation(), | 
|  | 8200 | clang::SourceLocation(), | 
|  | 8201 | nullptr, // anonymous | 
|  | 8202 | GetQualType(property_clang_type_to_access), | 
|  | 8203 | nullptr, | 
|  | 8204 | clang::SC_Auto, | 
|  | 8205 | nullptr)); | 
|  | 8206 |  | 
|  | 8207 | if (setter) | 
|  | 8208 | { | 
|  | 8209 | setter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>()); | 
|  | 8210 |  | 
|  | 8211 | class_interface_decl->addDecl(setter); | 
|  | 8212 | } | 
|  | 8213 | } | 
|  | 8214 |  | 
|  | 8215 | return true; | 
|  | 8216 | } | 
|  | 8217 | } | 
|  | 8218 | } | 
|  | 8219 | return false; | 
|  | 8220 | } | 
|  | 8221 |  | 
|  | 8222 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8223 | ClangASTContext::IsObjCClassTypeAndHasIVars (const CompilerType& type, bool check_superclass) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8224 | { | 
|  | 8225 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type); | 
|  | 8226 | if (class_interface_decl) | 
|  | 8227 | return ObjCDeclHasIVars (class_interface_decl, check_superclass); | 
|  | 8228 | return false; | 
|  | 8229 | } | 
|  | 8230 |  | 
|  | 8231 |  | 
|  | 8232 | clang::ObjCMethodDecl * | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8233 | ClangASTContext::AddMethodToObjCObjectType (const CompilerType& type, | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8234 | 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] | 8235 | const CompilerType &method_clang_type, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8236 | lldb::AccessType access, | 
|  | 8237 | bool is_artificial) | 
|  | 8238 | { | 
|  | 8239 | if (!type || !method_clang_type.IsValid()) | 
|  | 8240 | return nullptr; | 
|  | 8241 |  | 
|  | 8242 | clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type); | 
|  | 8243 |  | 
|  | 8244 | if (class_interface_decl == nullptr) | 
|  | 8245 | return nullptr; | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8246 | ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); | 
|  | 8247 | if (lldb_ast == nullptr) | 
|  | 8248 | return nullptr; | 
|  | 8249 | clang::ASTContext *ast = lldb_ast->getASTContext(); | 
|  | 8250 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8251 | const char *selector_start = ::strchr (name, ' '); | 
|  | 8252 | if (selector_start == nullptr) | 
|  | 8253 | return nullptr; | 
|  | 8254 |  | 
|  | 8255 | selector_start++; | 
|  | 8256 | llvm::SmallVector<clang::IdentifierInfo *, 12> selector_idents; | 
|  | 8257 |  | 
|  | 8258 | size_t len = 0; | 
|  | 8259 | const char *start; | 
|  | 8260 | //printf ("name = '%s'\n", name); | 
|  | 8261 |  | 
|  | 8262 | unsigned num_selectors_with_args = 0; | 
|  | 8263 | for (start = selector_start; | 
|  | 8264 | start && *start != '\0' && *start != ']'; | 
|  | 8265 | start += len) | 
|  | 8266 | { | 
|  | 8267 | len = ::strcspn(start, ":]"); | 
|  | 8268 | bool has_arg = (start[len] == ':'); | 
|  | 8269 | if (has_arg) | 
|  | 8270 | ++num_selectors_with_args; | 
|  | 8271 | selector_idents.push_back (&ast->Idents.get (llvm::StringRef (start, len))); | 
|  | 8272 | if (has_arg) | 
|  | 8273 | len += 1; | 
|  | 8274 | } | 
|  | 8275 |  | 
|  | 8276 |  | 
|  | 8277 | if (selector_idents.size() == 0) | 
|  | 8278 | return nullptr; | 
|  | 8279 |  | 
|  | 8280 | clang::Selector method_selector = ast->Selectors.getSelector (num_selectors_with_args ? selector_idents.size() : 0, | 
|  | 8281 | selector_idents.data()); | 
|  | 8282 |  | 
|  | 8283 | clang::QualType method_qual_type (GetQualType(method_clang_type)); | 
|  | 8284 |  | 
|  | 8285 | // Populate the method decl with parameter decls | 
|  | 8286 | const clang::Type *method_type(method_qual_type.getTypePtr()); | 
|  | 8287 |  | 
|  | 8288 | if (method_type == nullptr) | 
|  | 8289 | return nullptr; | 
|  | 8290 |  | 
|  | 8291 | const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(method_type)); | 
|  | 8292 |  | 
|  | 8293 | if (!method_function_prototype) | 
|  | 8294 | return nullptr; | 
|  | 8295 |  | 
|  | 8296 |  | 
|  | 8297 | bool is_variadic = false; | 
|  | 8298 | bool is_synthesized = false; | 
|  | 8299 | bool is_defined = false; | 
|  | 8300 | clang::ObjCMethodDecl::ImplementationControl imp_control = clang::ObjCMethodDecl::None; | 
|  | 8301 |  | 
|  | 8302 | const unsigned num_args = method_function_prototype->getNumParams(); | 
|  | 8303 |  | 
|  | 8304 | if (num_args != num_selectors_with_args) | 
|  | 8305 | return nullptr; // some debug information is corrupt.  We are not going to deal with it. | 
|  | 8306 |  | 
|  | 8307 | clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create (*ast, | 
|  | 8308 | clang::SourceLocation(), // beginLoc, | 
|  | 8309 | clang::SourceLocation(), // endLoc, | 
|  | 8310 | method_selector, | 
|  | 8311 | method_function_prototype->getReturnType(), | 
|  | 8312 | nullptr, // TypeSourceInfo *ResultTInfo, | 
|  | 8313 | ClangASTContext::GetASTContext(ast)->GetDeclContextForType(GetQualType(type)), | 
|  | 8314 | name[0] == '-', | 
|  | 8315 | is_variadic, | 
|  | 8316 | is_synthesized, | 
|  | 8317 | true, // is_implicitly_declared; we force this to true because we don't have source locations | 
|  | 8318 | is_defined, | 
|  | 8319 | imp_control, | 
|  | 8320 | false /*has_related_result_type*/); | 
|  | 8321 |  | 
|  | 8322 |  | 
|  | 8323 | if (objc_method_decl == nullptr) | 
|  | 8324 | return nullptr; | 
|  | 8325 |  | 
|  | 8326 | if (num_args > 0) | 
|  | 8327 | { | 
|  | 8328 | llvm::SmallVector<clang::ParmVarDecl *, 12> params; | 
|  | 8329 |  | 
|  | 8330 | for (unsigned param_index = 0; param_index < num_args; ++param_index) | 
|  | 8331 | { | 
|  | 8332 | params.push_back (clang::ParmVarDecl::Create (*ast, | 
|  | 8333 | objc_method_decl, | 
|  | 8334 | clang::SourceLocation(), | 
|  | 8335 | clang::SourceLocation(), | 
|  | 8336 | nullptr, // anonymous | 
|  | 8337 | method_function_prototype->getParamType(param_index), | 
|  | 8338 | nullptr, | 
|  | 8339 | clang::SC_Auto, | 
|  | 8340 | nullptr)); | 
|  | 8341 | } | 
|  | 8342 |  | 
|  | 8343 | objc_method_decl->setMethodParams(*ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>()); | 
|  | 8344 | } | 
|  | 8345 |  | 
|  | 8346 | class_interface_decl->addDecl (objc_method_decl); | 
|  | 8347 |  | 
|  | 8348 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 8349 | VerifyDecl(objc_method_decl); | 
|  | 8350 | #endif | 
|  | 8351 |  | 
|  | 8352 | return objc_method_decl; | 
|  | 8353 | } | 
|  | 8354 |  | 
|  | 8355 | bool | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8356 | ClangASTContext::GetHasExternalStorage (const CompilerType &type) | 
|  | 8357 | { | 
|  | 8358 | if (IsClangType(type)) | 
|  | 8359 | return false; | 
|  | 8360 |  | 
|  | 8361 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 8362 |  | 
|  | 8363 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 8364 | switch (type_class) | 
|  | 8365 | { | 
|  | 8366 | case clang::Type::Record: | 
|  | 8367 | { | 
|  | 8368 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 8369 | if (cxx_record_decl) | 
|  | 8370 | return cxx_record_decl->hasExternalLexicalStorage () || cxx_record_decl->hasExternalVisibleStorage(); | 
|  | 8371 | } | 
|  | 8372 | break; | 
|  | 8373 |  | 
|  | 8374 | case clang::Type::Enum: | 
|  | 8375 | { | 
|  | 8376 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); | 
|  | 8377 | if (enum_decl) | 
|  | 8378 | return enum_decl->hasExternalLexicalStorage () || enum_decl->hasExternalVisibleStorage(); | 
|  | 8379 | } | 
|  | 8380 | break; | 
|  | 8381 |  | 
|  | 8382 | case clang::Type::ObjCObject: | 
|  | 8383 | case clang::Type::ObjCInterface: | 
|  | 8384 | { | 
|  | 8385 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 8386 | assert (objc_class_type); | 
|  | 8387 | if (objc_class_type) | 
|  | 8388 | { | 
|  | 8389 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 8390 |  | 
|  | 8391 | if (class_interface_decl) | 
|  | 8392 | return class_interface_decl->hasExternalLexicalStorage () || class_interface_decl->hasExternalVisibleStorage (); | 
|  | 8393 | } | 
|  | 8394 | } | 
|  | 8395 | break; | 
|  | 8396 |  | 
|  | 8397 | case clang::Type::Typedef: | 
|  | 8398 | return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr())); | 
|  | 8399 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 8400 | case clang::Type::Auto: | 
|  | 8401 | return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr())); | 
|  | 8402 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8403 | case clang::Type::Elaborated: | 
|  | 8404 | return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr())); | 
|  | 8405 |  | 
|  | 8406 | case clang::Type::Paren: | 
|  | 8407 | return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())); | 
|  | 8408 |  | 
|  | 8409 | default: | 
|  | 8410 | break; | 
|  | 8411 | } | 
|  | 8412 | return false; | 
|  | 8413 | } | 
|  | 8414 |  | 
|  | 8415 |  | 
|  | 8416 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8417 | ClangASTContext::SetHasExternalStorage (lldb::opaque_compiler_type_t type, bool has_extern) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8418 | { | 
|  | 8419 | if (!type) | 
|  | 8420 | return false; | 
|  | 8421 |  | 
|  | 8422 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 8423 |  | 
|  | 8424 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 8425 | switch (type_class) | 
|  | 8426 | { | 
|  | 8427 | case clang::Type::Record: | 
|  | 8428 | { | 
|  | 8429 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 8430 | if (cxx_record_decl) | 
|  | 8431 | { | 
|  | 8432 | cxx_record_decl->setHasExternalLexicalStorage (has_extern); | 
|  | 8433 | cxx_record_decl->setHasExternalVisibleStorage (has_extern); | 
|  | 8434 | return true; | 
|  | 8435 | } | 
|  | 8436 | } | 
|  | 8437 | break; | 
|  | 8438 |  | 
|  | 8439 | case clang::Type::Enum: | 
|  | 8440 | { | 
|  | 8441 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); | 
|  | 8442 | if (enum_decl) | 
|  | 8443 | { | 
|  | 8444 | enum_decl->setHasExternalLexicalStorage (has_extern); | 
|  | 8445 | enum_decl->setHasExternalVisibleStorage (has_extern); | 
|  | 8446 | return true; | 
|  | 8447 | } | 
|  | 8448 | } | 
|  | 8449 | break; | 
|  | 8450 |  | 
|  | 8451 | case clang::Type::ObjCObject: | 
|  | 8452 | case clang::Type::ObjCInterface: | 
|  | 8453 | { | 
|  | 8454 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 8455 | assert (objc_class_type); | 
|  | 8456 | if (objc_class_type) | 
|  | 8457 | { | 
|  | 8458 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 8459 |  | 
|  | 8460 | if (class_interface_decl) | 
|  | 8461 | { | 
|  | 8462 | class_interface_decl->setHasExternalLexicalStorage (has_extern); | 
|  | 8463 | class_interface_decl->setHasExternalVisibleStorage (has_extern); | 
|  | 8464 | return true; | 
|  | 8465 | } | 
|  | 8466 | } | 
|  | 8467 | } | 
|  | 8468 | break; | 
|  | 8469 |  | 
|  | 8470 | case clang::Type::Typedef: | 
|  | 8471 | return SetHasExternalStorage(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), has_extern); | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 8472 |  | 
|  | 8473 | case clang::Type::Auto: | 
|  | 8474 | return SetHasExternalStorage (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), has_extern); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8475 |  | 
|  | 8476 | case clang::Type::Elaborated: | 
|  | 8477 | return SetHasExternalStorage (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), has_extern); | 
|  | 8478 |  | 
|  | 8479 | case clang::Type::Paren: | 
|  | 8480 | return SetHasExternalStorage (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), has_extern); | 
|  | 8481 |  | 
|  | 8482 | default: | 
|  | 8483 | break; | 
|  | 8484 | } | 
|  | 8485 | return false; | 
|  | 8486 | } | 
|  | 8487 |  | 
|  | 8488 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8489 | bool | 
|  | 8490 | ClangASTContext::CanImport (const CompilerType &type, lldb_private::ClangASTImporter &importer) | 
|  | 8491 | { | 
|  | 8492 | if (IsClangType(type)) | 
|  | 8493 | { | 
|  | 8494 | // TODO: remove external completion BOOL | 
|  | 8495 | // CompleteAndFetchChildren should get the Decl out and check for the | 
|  | 8496 |  | 
|  | 8497 | clang::QualType qual_type(GetCanonicalQualType(RemoveFastQualifiers(type))); | 
|  | 8498 |  | 
|  | 8499 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 8500 | switch (type_class) | 
|  | 8501 | { | 
|  | 8502 | case clang::Type::Record: | 
|  | 8503 | { | 
|  | 8504 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 8505 | if (cxx_record_decl) | 
|  | 8506 | { | 
|  | 8507 | if (importer.ResolveDeclOrigin (cxx_record_decl, NULL, NULL)) | 
|  | 8508 | return true; | 
|  | 8509 | } | 
|  | 8510 | } | 
|  | 8511 | break; | 
|  | 8512 |  | 
|  | 8513 | case clang::Type::Enum: | 
|  | 8514 | { | 
|  | 8515 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); | 
|  | 8516 | if (enum_decl) | 
|  | 8517 | { | 
|  | 8518 | if (importer.ResolveDeclOrigin (enum_decl, NULL, NULL)) | 
|  | 8519 | return true; | 
|  | 8520 | } | 
|  | 8521 | } | 
|  | 8522 | break; | 
|  | 8523 |  | 
|  | 8524 | case clang::Type::ObjCObject: | 
|  | 8525 | case clang::Type::ObjCInterface: | 
|  | 8526 | { | 
|  | 8527 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); | 
|  | 8528 | if (objc_class_type) | 
|  | 8529 | { | 
|  | 8530 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 8531 | // We currently can't complete objective C types through the newly added ASTContext | 
|  | 8532 | // because it only supports TagDecl objects right now... | 
|  | 8533 | if (class_interface_decl) | 
|  | 8534 | { | 
|  | 8535 | if (importer.ResolveDeclOrigin (class_interface_decl, NULL, NULL)) | 
|  | 8536 | return true; | 
|  | 8537 | } | 
|  | 8538 | } | 
|  | 8539 | } | 
|  | 8540 | break; | 
|  | 8541 |  | 
|  | 8542 |  | 
|  | 8543 | case clang::Type::Typedef: | 
|  | 8544 | return CanImport(CompilerType (type.GetTypeSystem(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()), importer); | 
|  | 8545 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 8546 | case clang::Type::Auto: | 
|  | 8547 | return CanImport(CompilerType (type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()), importer); | 
|  | 8548 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8549 | case clang::Type::Elaborated: | 
|  | 8550 | return CanImport(CompilerType (type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()), importer); | 
|  | 8551 |  | 
|  | 8552 | case clang::Type::Paren: | 
|  | 8553 | return CanImport(CompilerType (type.GetTypeSystem(), llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()), importer); | 
|  | 8554 |  | 
|  | 8555 | default: | 
|  | 8556 | break; | 
|  | 8557 | } | 
|  | 8558 | } | 
|  | 8559 | return false; | 
|  | 8560 | } | 
|  | 8561 | bool | 
|  | 8562 | ClangASTContext::Import (const CompilerType &type, lldb_private::ClangASTImporter &importer) | 
|  | 8563 | { | 
|  | 8564 | if (IsClangType(type)) | 
|  | 8565 | { | 
|  | 8566 | // TODO: remove external completion BOOL | 
|  | 8567 | // CompleteAndFetchChildren should get the Decl out and check for the | 
|  | 8568 |  | 
|  | 8569 | clang::QualType qual_type(GetCanonicalQualType(RemoveFastQualifiers(type))); | 
|  | 8570 |  | 
|  | 8571 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 8572 | switch (type_class) | 
|  | 8573 | { | 
|  | 8574 | case clang::Type::Record: | 
|  | 8575 | { | 
|  | 8576 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 8577 | if (cxx_record_decl) | 
|  | 8578 | { | 
|  | 8579 | if (importer.ResolveDeclOrigin (cxx_record_decl, NULL, NULL)) | 
|  | 8580 | return importer.CompleteAndFetchChildren(qual_type); | 
|  | 8581 | } | 
|  | 8582 | } | 
|  | 8583 | break; | 
|  | 8584 |  | 
|  | 8585 | case clang::Type::Enum: | 
|  | 8586 | { | 
|  | 8587 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); | 
|  | 8588 | if (enum_decl) | 
|  | 8589 | { | 
|  | 8590 | if (importer.ResolveDeclOrigin (enum_decl, NULL, NULL)) | 
|  | 8591 | return importer.CompleteAndFetchChildren(qual_type); | 
|  | 8592 | } | 
|  | 8593 | } | 
|  | 8594 | break; | 
|  | 8595 |  | 
|  | 8596 | case clang::Type::ObjCObject: | 
|  | 8597 | case clang::Type::ObjCInterface: | 
|  | 8598 | { | 
|  | 8599 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); | 
|  | 8600 | if (objc_class_type) | 
|  | 8601 | { | 
|  | 8602 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 8603 | // We currently can't complete objective C types through the newly added ASTContext | 
|  | 8604 | // because it only supports TagDecl objects right now... | 
|  | 8605 | if (class_interface_decl) | 
|  | 8606 | { | 
|  | 8607 | if (importer.ResolveDeclOrigin (class_interface_decl, NULL, NULL)) | 
|  | 8608 | return importer.CompleteAndFetchChildren(qual_type); | 
|  | 8609 | } | 
|  | 8610 | } | 
|  | 8611 | } | 
|  | 8612 | break; | 
|  | 8613 |  | 
|  | 8614 |  | 
|  | 8615 | case clang::Type::Typedef: | 
|  | 8616 | return Import (CompilerType(type.GetTypeSystem(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()), importer); | 
|  | 8617 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 8618 | case clang::Type::Auto: | 
|  | 8619 | return Import (CompilerType(type.GetTypeSystem(),llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()), importer); | 
|  | 8620 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8621 | case clang::Type::Elaborated: | 
|  | 8622 | return Import (CompilerType(type.GetTypeSystem(),llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()), importer); | 
|  | 8623 |  | 
|  | 8624 | case clang::Type::Paren: | 
|  | 8625 | return Import (CompilerType(type.GetTypeSystem(),llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()), importer); | 
|  | 8626 |  | 
|  | 8627 | default: | 
|  | 8628 | break; | 
|  | 8629 | } | 
|  | 8630 | } | 
|  | 8631 | return false; | 
|  | 8632 | } | 
|  | 8633 |  | 
|  | 8634 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8635 | #pragma mark TagDecl | 
|  | 8636 |  | 
|  | 8637 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8638 | ClangASTContext::StartTagDeclarationDefinition (const CompilerType &type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8639 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8640 | clang::QualType qual_type (ClangASTContext::GetQualType(type)); | 
|  | 8641 | if (!qual_type.isNull()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8642 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8643 | const clang::TagType *tag_type = qual_type->getAs<clang::TagType>(); | 
|  | 8644 | if (tag_type) | 
| Greg Clayton | 5dfc4a4 | 2015-12-02 00:43:32 +0000 | [diff] [blame] | 8645 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8646 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 8647 | if (tag_decl) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8648 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8649 | tag_decl->startDefinition(); | 
|  | 8650 | return true; | 
| Tamas Berghammer | fcf334b | 2015-12-02 11:35:54 +0000 | [diff] [blame] | 8651 | } | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8652 | } | 
|  | 8653 |  | 
|  | 8654 | const clang::ObjCObjectType *object_type = qual_type->getAs<clang::ObjCObjectType>(); | 
|  | 8655 | if (object_type) | 
|  | 8656 | { | 
|  | 8657 | clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface(); | 
|  | 8658 | if (interface_decl) | 
| Tamas Berghammer | fcf334b | 2015-12-02 11:35:54 +0000 | [diff] [blame] | 8659 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8660 | interface_decl->startDefinition(); | 
|  | 8661 | return true; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8662 | } | 
|  | 8663 | } | 
|  | 8664 | } | 
|  | 8665 | return false; | 
|  | 8666 | } | 
|  | 8667 |  | 
|  | 8668 | bool | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8669 | ClangASTContext::CompleteTagDeclarationDefinition (const CompilerType& type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8670 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8671 | clang::QualType qual_type (ClangASTContext::GetQualType(type)); | 
|  | 8672 | if (!qual_type.isNull()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8673 | { | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8674 | clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 8675 |  | 
|  | 8676 | if (cxx_record_decl) | 
|  | 8677 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8678 | if (!cxx_record_decl->isCompleteDefinition()) | 
|  | 8679 | cxx_record_decl->completeDefinition(); | 
|  | 8680 | cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true); | 
|  | 8681 | cxx_record_decl->setHasExternalLexicalStorage (false); | 
|  | 8682 | cxx_record_decl->setHasExternalVisibleStorage (false); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8683 | return true; | 
|  | 8684 | } | 
|  | 8685 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8686 | const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8687 |  | 
|  | 8688 | if (enutype) | 
|  | 8689 | { | 
|  | 8690 | clang::EnumDecl *enum_decl = enutype->getDecl(); | 
|  | 8691 |  | 
|  | 8692 | if (enum_decl) | 
|  | 8693 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8694 | if (!enum_decl->isCompleteDefinition()) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8695 | { | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8696 | ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); | 
|  | 8697 | if (lldb_ast == nullptr) | 
|  | 8698 | return false; | 
|  | 8699 | clang::ASTContext *ast = lldb_ast->getASTContext(); | 
|  | 8700 |  | 
|  | 8701 | /// TODO This really needs to be fixed. | 
|  | 8702 |  | 
|  | 8703 | unsigned NumPositiveBits = 1; | 
|  | 8704 | unsigned NumNegativeBits = 0; | 
|  | 8705 |  | 
|  | 8706 | clang::QualType promotion_qual_type; | 
|  | 8707 | // If the enum integer type is less than an integer in bit width, | 
|  | 8708 | // then we must promote it to an integer size. | 
|  | 8709 | if (ast->getTypeSize(enum_decl->getIntegerType()) < ast->getTypeSize(ast->IntTy)) | 
|  | 8710 | { | 
|  | 8711 | if (enum_decl->getIntegerType()->isSignedIntegerType()) | 
|  | 8712 | promotion_qual_type = ast->IntTy; | 
|  | 8713 | else | 
|  | 8714 | promotion_qual_type = ast->UnsignedIntTy; | 
|  | 8715 | } | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8716 | else | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 8717 | promotion_qual_type = enum_decl->getIntegerType(); | 
|  | 8718 |  | 
|  | 8719 | enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8720 | } | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8721 | return true; | 
|  | 8722 | } | 
|  | 8723 | } | 
|  | 8724 | } | 
|  | 8725 | return false; | 
|  | 8726 | } | 
|  | 8727 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8728 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8729 | ClangASTContext::AddEnumerationValueToEnumerationType (lldb::opaque_compiler_type_t type, | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 8730 | const CompilerType &enumerator_clang_type, | 
|  | 8731 | const Declaration &decl, | 
|  | 8732 | const char *name, | 
|  | 8733 | int64_t enum_value, | 
|  | 8734 | uint32_t enum_value_bit_size) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8735 | { | 
|  | 8736 | if (type && enumerator_clang_type.IsValid() && name && name[0]) | 
|  | 8737 | { | 
|  | 8738 | clang::QualType enum_qual_type (GetCanonicalQualType(type)); | 
|  | 8739 |  | 
|  | 8740 | bool is_signed = false; | 
|  | 8741 | enumerator_clang_type.IsIntegerType (is_signed); | 
|  | 8742 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); | 
|  | 8743 | if (clang_type) | 
|  | 8744 | { | 
|  | 8745 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type); | 
|  | 8746 |  | 
|  | 8747 | if (enutype) | 
|  | 8748 | { | 
|  | 8749 | llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed); | 
|  | 8750 | enum_llvm_apsint = enum_value; | 
|  | 8751 | clang::EnumConstantDecl *enumerator_decl = | 
|  | 8752 | clang::EnumConstantDecl::Create (*getASTContext(), | 
|  | 8753 | enutype->getDecl(), | 
|  | 8754 | clang::SourceLocation(), | 
|  | 8755 | name ? &getASTContext()->Idents.get(name) : nullptr,    // Identifier | 
|  | 8756 | GetQualType(enumerator_clang_type), | 
|  | 8757 | nullptr, | 
|  | 8758 | enum_llvm_apsint); | 
|  | 8759 |  | 
|  | 8760 | if (enumerator_decl) | 
|  | 8761 | { | 
|  | 8762 | enutype->getDecl()->addDecl(enumerator_decl); | 
|  | 8763 |  | 
|  | 8764 | #ifdef LLDB_CONFIGURATION_DEBUG | 
|  | 8765 | VerifyDecl(enumerator_decl); | 
|  | 8766 | #endif | 
|  | 8767 |  | 
|  | 8768 | return true; | 
|  | 8769 | } | 
|  | 8770 | } | 
|  | 8771 | } | 
|  | 8772 | } | 
|  | 8773 | return false; | 
|  | 8774 | } | 
|  | 8775 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8776 | CompilerType | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8777 | ClangASTContext::GetEnumerationIntegerType (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8778 | { | 
|  | 8779 | clang::QualType enum_qual_type (GetCanonicalQualType(type)); | 
|  | 8780 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); | 
|  | 8781 | if (clang_type) | 
|  | 8782 | { | 
|  | 8783 | const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type); | 
|  | 8784 | if (enutype) | 
|  | 8785 | { | 
|  | 8786 | clang::EnumDecl *enum_decl = enutype->getDecl(); | 
|  | 8787 | if (enum_decl) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8788 | return CompilerType (getASTContext(), enum_decl->getIntegerType()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8789 | } | 
|  | 8790 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8791 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8792 | } | 
|  | 8793 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8794 | CompilerType | 
|  | 8795 | ClangASTContext::CreateMemberPointerType (const CompilerType& type, const CompilerType &pointee_type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8796 | { | 
|  | 8797 | if (type && pointee_type.IsValid() && type.GetTypeSystem() == pointee_type.GetTypeSystem()) | 
|  | 8798 | { | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 8799 | ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem()); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8800 | if (!ast) | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8801 | return CompilerType(); | 
|  | 8802 | return CompilerType (ast->getASTContext(), | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8803 | ast->getASTContext()->getMemberPointerType (GetQualType(pointee_type), | 
|  | 8804 | GetQualType(type).getTypePtr())); | 
|  | 8805 | } | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8806 | return CompilerType(); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8807 | } | 
|  | 8808 |  | 
|  | 8809 |  | 
|  | 8810 | size_t | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8811 | 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] | 8812 | { | 
|  | 8813 | if (type) | 
|  | 8814 | { | 
|  | 8815 | clang::QualType qual_type (GetCanonicalQualType(type)); | 
|  | 8816 | uint32_t count = 0; | 
|  | 8817 | bool is_complex = false; | 
|  | 8818 | if (IsFloatingPointType (type, count, is_complex)) | 
|  | 8819 | { | 
|  | 8820 | // TODO: handle complex and vector types | 
|  | 8821 | if (count != 1) | 
|  | 8822 | return false; | 
|  | 8823 |  | 
|  | 8824 | llvm::StringRef s_sref(s); | 
|  | 8825 | llvm::APFloat ap_float(getASTContext()->getFloatTypeSemantics(qual_type), s_sref); | 
|  | 8826 |  | 
|  | 8827 | const uint64_t bit_size = getASTContext()->getTypeSize (qual_type); | 
|  | 8828 | const uint64_t byte_size = bit_size / 8; | 
|  | 8829 | if (dst_size >= byte_size) | 
|  | 8830 | { | 
|  | 8831 | if (bit_size == sizeof(float)*8) | 
|  | 8832 | { | 
|  | 8833 | float float32 = ap_float.convertToFloat(); | 
|  | 8834 | ::memcpy (dst, &float32, byte_size); | 
|  | 8835 | return byte_size; | 
|  | 8836 | } | 
|  | 8837 | else if (bit_size >= 64) | 
|  | 8838 | { | 
|  | 8839 | llvm::APInt ap_int(ap_float.bitcastToAPInt()); | 
|  | 8840 | ::memcpy (dst, ap_int.getRawData(), byte_size); | 
|  | 8841 | return byte_size; | 
|  | 8842 | } | 
|  | 8843 | } | 
|  | 8844 | } | 
|  | 8845 | } | 
|  | 8846 | return 0; | 
|  | 8847 | } | 
|  | 8848 |  | 
|  | 8849 |  | 
|  | 8850 |  | 
|  | 8851 | //---------------------------------------------------------------------- | 
|  | 8852 | // Dumping types | 
|  | 8853 | //---------------------------------------------------------------------- | 
|  | 8854 | #define DEPTH_INCREMENT 2 | 
|  | 8855 |  | 
|  | 8856 | void | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 8857 | ClangASTContext::DumpValue (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8858 | Stream *s, | 
|  | 8859 | lldb::Format format, | 
|  | 8860 | const lldb_private::DataExtractor &data, | 
|  | 8861 | lldb::offset_t data_byte_offset, | 
|  | 8862 | size_t data_byte_size, | 
|  | 8863 | uint32_t bitfield_bit_size, | 
|  | 8864 | uint32_t bitfield_bit_offset, | 
|  | 8865 | bool show_types, | 
|  | 8866 | bool show_summary, | 
|  | 8867 | bool verbose, | 
|  | 8868 | uint32_t depth) | 
|  | 8869 | { | 
|  | 8870 | if (!type) | 
|  | 8871 | return; | 
|  | 8872 |  | 
|  | 8873 | clang::QualType qual_type(GetQualType(type)); | 
|  | 8874 | switch (qual_type->getTypeClass()) | 
|  | 8875 | { | 
|  | 8876 | case clang::Type::Record: | 
|  | 8877 | if (GetCompleteType(type)) | 
|  | 8878 | { | 
|  | 8879 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 8880 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 8881 | assert(record_decl); | 
|  | 8882 | uint32_t field_bit_offset = 0; | 
|  | 8883 | uint32_t field_byte_offset = 0; | 
|  | 8884 | const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl); | 
|  | 8885 | uint32_t child_idx = 0; | 
|  | 8886 |  | 
|  | 8887 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 8888 | if (cxx_record_decl) | 
|  | 8889 | { | 
|  | 8890 | // We might have base classes to print out first | 
|  | 8891 | clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end; | 
|  | 8892 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); | 
|  | 8893 | base_class != base_class_end; | 
|  | 8894 | ++base_class) | 
|  | 8895 | { | 
|  | 8896 | const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl()); | 
|  | 8897 |  | 
|  | 8898 | // Skip empty base classes | 
|  | 8899 | if (verbose == false && ClangASTContext::RecordHasFields(base_class_decl) == false) | 
|  | 8900 | continue; | 
|  | 8901 |  | 
|  | 8902 | if (base_class->isVirtual()) | 
|  | 8903 | field_bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; | 
|  | 8904 | else | 
|  | 8905 | field_bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; | 
|  | 8906 | field_byte_offset = field_bit_offset / 8; | 
|  | 8907 | assert (field_bit_offset % 8 == 0); | 
|  | 8908 | if (child_idx == 0) | 
|  | 8909 | s->PutChar('{'); | 
|  | 8910 | else | 
|  | 8911 | s->PutChar(','); | 
|  | 8912 |  | 
|  | 8913 | clang::QualType base_class_qual_type = base_class->getType(); | 
|  | 8914 | std::string base_class_type_name(base_class_qual_type.getAsString()); | 
|  | 8915 |  | 
|  | 8916 | // Indent and print the base class type name | 
|  | 8917 | s->Printf("\n%*s%s ", depth + DEPTH_INCREMENT, "", base_class_type_name.c_str()); | 
|  | 8918 |  | 
|  | 8919 | clang::TypeInfo base_class_type_info = getASTContext()->getTypeInfo(base_class_qual_type); | 
|  | 8920 |  | 
|  | 8921 | // Dump the value of the member | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8922 | CompilerType base_clang_type(getASTContext(), base_class_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8923 | base_clang_type.DumpValue (exe_ctx, | 
|  | 8924 | s,                                   // Stream to dump to | 
|  | 8925 | base_clang_type.GetFormat(),         // The format with which to display the member | 
|  | 8926 | data,                                // Data buffer containing all bytes for this type | 
|  | 8927 | data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from | 
|  | 8928 | base_class_type_info.Width / 8,      // Size of this type in bytes | 
|  | 8929 | 0,                                   // Bitfield bit size | 
|  | 8930 | 0,                                   // Bitfield bit offset | 
|  | 8931 | show_types,                          // Boolean indicating if we should show the variable types | 
|  | 8932 | show_summary,                        // Boolean indicating if we should show a summary for the current type | 
|  | 8933 | verbose,                             // Verbose output? | 
|  | 8934 | depth + DEPTH_INCREMENT);            // Scope depth for any types that have children | 
|  | 8935 |  | 
|  | 8936 | ++child_idx; | 
|  | 8937 | } | 
|  | 8938 | } | 
|  | 8939 | uint32_t field_idx = 0; | 
|  | 8940 | clang::RecordDecl::field_iterator field, field_end; | 
|  | 8941 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx) | 
|  | 8942 | { | 
|  | 8943 | // Print the starting squiggly bracket (if this is the | 
|  | 8944 | // first member) or comma (for member 2 and beyond) for | 
|  | 8945 | // the struct/union/class member. | 
|  | 8946 | if (child_idx == 0) | 
|  | 8947 | s->PutChar('{'); | 
|  | 8948 | else | 
|  | 8949 | s->PutChar(','); | 
|  | 8950 |  | 
|  | 8951 | // Indent | 
|  | 8952 | s->Printf("\n%*s", depth + DEPTH_INCREMENT, ""); | 
|  | 8953 |  | 
|  | 8954 | clang::QualType field_type = field->getType(); | 
|  | 8955 | // Print the member type if requested | 
|  | 8956 | // Figure out the type byte size (field_type_info.first) and | 
|  | 8957 | // alignment (field_type_info.second) from the AST context. | 
|  | 8958 | clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(field_type); | 
|  | 8959 | assert(field_idx < record_layout.getFieldCount()); | 
|  | 8960 | // Figure out the field offset within the current struct/union/class type | 
|  | 8961 | field_bit_offset = record_layout.getFieldOffset (field_idx); | 
|  | 8962 | field_byte_offset = field_bit_offset / 8; | 
|  | 8963 | uint32_t field_bitfield_bit_size = 0; | 
|  | 8964 | uint32_t field_bitfield_bit_offset = 0; | 
|  | 8965 | if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, field_bitfield_bit_size)) | 
|  | 8966 | field_bitfield_bit_offset = field_bit_offset % 8; | 
|  | 8967 |  | 
|  | 8968 | if (show_types) | 
|  | 8969 | { | 
|  | 8970 | std::string field_type_name(field_type.getAsString()); | 
|  | 8971 | if (field_bitfield_bit_size > 0) | 
|  | 8972 | s->Printf("(%s:%u) ", field_type_name.c_str(), field_bitfield_bit_size); | 
|  | 8973 | else | 
|  | 8974 | s->Printf("(%s) ", field_type_name.c_str()); | 
|  | 8975 | } | 
|  | 8976 | // Print the member name and equal sign | 
|  | 8977 | s->Printf("%s = ", field->getNameAsString().c_str()); | 
|  | 8978 |  | 
|  | 8979 |  | 
|  | 8980 | // Dump the value of the member | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 8981 | CompilerType field_clang_type (getASTContext(), field_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 8982 | field_clang_type.DumpValue (exe_ctx, | 
|  | 8983 | s,                              // Stream to dump to | 
|  | 8984 | field_clang_type.GetFormat(),   // The format with which to display the member | 
|  | 8985 | data,                           // Data buffer containing all bytes for this type | 
|  | 8986 | data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from | 
|  | 8987 | field_type_info.Width / 8,      // Size of this type in bytes | 
|  | 8988 | field_bitfield_bit_size,        // Bitfield bit size | 
|  | 8989 | field_bitfield_bit_offset,      // Bitfield bit offset | 
|  | 8990 | show_types,                     // Boolean indicating if we should show the variable types | 
|  | 8991 | show_summary,                   // Boolean indicating if we should show a summary for the current type | 
|  | 8992 | verbose,                        // Verbose output? | 
|  | 8993 | depth + DEPTH_INCREMENT);       // Scope depth for any types that have children | 
|  | 8994 | } | 
|  | 8995 |  | 
|  | 8996 | // Indent the trailing squiggly bracket | 
|  | 8997 | if (child_idx > 0) | 
|  | 8998 | s->Printf("\n%*s}", depth, ""); | 
|  | 8999 | } | 
|  | 9000 | return; | 
|  | 9001 |  | 
|  | 9002 | case clang::Type::Enum: | 
|  | 9003 | if (GetCompleteType(type)) | 
|  | 9004 | { | 
|  | 9005 | const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr()); | 
|  | 9006 | const clang::EnumDecl *enum_decl = enutype->getDecl(); | 
|  | 9007 | assert(enum_decl); | 
|  | 9008 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; | 
|  | 9009 | lldb::offset_t offset = data_byte_offset; | 
|  | 9010 | const int64_t enum_value = data.GetMaxU64Bitfield(&offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset); | 
|  | 9011 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) | 
|  | 9012 | { | 
|  | 9013 | if (enum_pos->getInitVal() == enum_value) | 
|  | 9014 | { | 
|  | 9015 | s->Printf("%s", enum_pos->getNameAsString().c_str()); | 
|  | 9016 | return; | 
|  | 9017 | } | 
|  | 9018 | } | 
|  | 9019 | // If we have gotten here we didn't get find the enumerator in the | 
|  | 9020 | // enum decl, so just print the integer. | 
|  | 9021 | s->Printf("%" PRIi64, enum_value); | 
|  | 9022 | } | 
|  | 9023 | return; | 
|  | 9024 |  | 
|  | 9025 | case clang::Type::ConstantArray: | 
|  | 9026 | { | 
|  | 9027 | const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr()); | 
|  | 9028 | bool is_array_of_characters = false; | 
|  | 9029 | clang::QualType element_qual_type = array->getElementType(); | 
|  | 9030 |  | 
|  | 9031 | const clang::Type *canonical_type = element_qual_type->getCanonicalTypeInternal().getTypePtr(); | 
|  | 9032 | if (canonical_type) | 
|  | 9033 | is_array_of_characters = canonical_type->isCharType(); | 
|  | 9034 |  | 
|  | 9035 | const uint64_t element_count = array->getSize().getLimitedValue(); | 
|  | 9036 |  | 
|  | 9037 | clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(element_qual_type); | 
|  | 9038 |  | 
|  | 9039 | uint32_t element_idx = 0; | 
|  | 9040 | uint32_t element_offset = 0; | 
|  | 9041 | uint64_t element_byte_size = field_type_info.Width / 8; | 
|  | 9042 | uint32_t element_stride = element_byte_size; | 
|  | 9043 |  | 
|  | 9044 | if (is_array_of_characters) | 
|  | 9045 | { | 
|  | 9046 | s->PutChar('"'); | 
|  | 9047 | data.Dump(s, data_byte_offset, lldb::eFormatChar, element_byte_size, element_count, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); | 
|  | 9048 | s->PutChar('"'); | 
|  | 9049 | return; | 
|  | 9050 | } | 
|  | 9051 | else | 
|  | 9052 | { | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 9053 | CompilerType element_clang_type(getASTContext(), element_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9054 | lldb::Format element_format = element_clang_type.GetFormat(); | 
|  | 9055 |  | 
|  | 9056 | for (element_idx = 0; element_idx < element_count; ++element_idx) | 
|  | 9057 | { | 
|  | 9058 | // Print the starting squiggly bracket (if this is the | 
|  | 9059 | // first member) or comman (for member 2 and beyong) for | 
|  | 9060 | // the struct/union/class member. | 
|  | 9061 | if (element_idx == 0) | 
|  | 9062 | s->PutChar('{'); | 
|  | 9063 | else | 
|  | 9064 | s->PutChar(','); | 
|  | 9065 |  | 
|  | 9066 | // Indent and print the index | 
|  | 9067 | s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx); | 
|  | 9068 |  | 
|  | 9069 | // Figure out the field offset within the current struct/union/class type | 
|  | 9070 | element_offset = element_idx * element_stride; | 
|  | 9071 |  | 
|  | 9072 | // Dump the value of the member | 
|  | 9073 | element_clang_type.DumpValue (exe_ctx, | 
|  | 9074 | s,                              // Stream to dump to | 
|  | 9075 | element_format,                 // The format with which to display the element | 
|  | 9076 | data,                           // Data buffer containing all bytes for this type | 
|  | 9077 | data_byte_offset + element_offset,// Offset into "data" where to grab value from | 
|  | 9078 | element_byte_size,              // Size of this type in bytes | 
|  | 9079 | 0,                              // Bitfield bit size | 
|  | 9080 | 0,                              // Bitfield bit offset | 
|  | 9081 | show_types,                     // Boolean indicating if we should show the variable types | 
|  | 9082 | show_summary,                   // Boolean indicating if we should show a summary for the current type | 
|  | 9083 | verbose,                        // Verbose output? | 
|  | 9084 | depth + DEPTH_INCREMENT);       // Scope depth for any types that have children | 
|  | 9085 | } | 
|  | 9086 |  | 
|  | 9087 | // Indent the trailing squiggly bracket | 
|  | 9088 | if (element_idx > 0) | 
|  | 9089 | s->Printf("\n%*s}", depth, ""); | 
|  | 9090 | } | 
|  | 9091 | } | 
|  | 9092 | return; | 
|  | 9093 |  | 
|  | 9094 | case clang::Type::Typedef: | 
|  | 9095 | { | 
|  | 9096 | clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(); | 
|  | 9097 |  | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 9098 | CompilerType typedef_clang_type (getASTContext(), typedef_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9099 | lldb::Format typedef_format = typedef_clang_type.GetFormat(); | 
|  | 9100 | clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type); | 
|  | 9101 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; | 
|  | 9102 |  | 
|  | 9103 | return typedef_clang_type.DumpValue (exe_ctx, | 
|  | 9104 | s,                  // Stream to dump to | 
|  | 9105 | typedef_format,     // The format with which to display the element | 
|  | 9106 | data,               // Data buffer containing all bytes for this type | 
|  | 9107 | data_byte_offset,   // Offset into "data" where to grab value from | 
|  | 9108 | typedef_byte_size,  // Size of this type in bytes | 
|  | 9109 | bitfield_bit_size,  // Bitfield bit size | 
|  | 9110 | bitfield_bit_offset,// Bitfield bit offset | 
|  | 9111 | show_types,         // Boolean indicating if we should show the variable types | 
|  | 9112 | show_summary,       // Boolean indicating if we should show a summary for the current type | 
|  | 9113 | verbose,            // Verbose output? | 
|  | 9114 | depth);             // Scope depth for any types that have children | 
|  | 9115 | } | 
|  | 9116 | break; | 
|  | 9117 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 9118 | case clang::Type::Auto: | 
|  | 9119 | { | 
|  | 9120 | clang::QualType elaborated_qual_type = llvm::cast<clang::AutoType>(qual_type)->getDeducedType(); | 
|  | 9121 | CompilerType elaborated_clang_type (getASTContext(), elaborated_qual_type); | 
|  | 9122 | lldb::Format elaborated_format = elaborated_clang_type.GetFormat(); | 
|  | 9123 | clang::TypeInfo elaborated_type_info = getASTContext()->getTypeInfo(elaborated_qual_type); | 
|  | 9124 | uint64_t elaborated_byte_size = elaborated_type_info.Width / 8; | 
|  | 9125 |  | 
|  | 9126 | return elaborated_clang_type.DumpValue (exe_ctx, | 
|  | 9127 | s,                  // Stream to dump to | 
|  | 9128 | elaborated_format,  // The format with which to display the element | 
|  | 9129 | data,               // Data buffer containing all bytes for this type | 
|  | 9130 | data_byte_offset,   // Offset into "data" where to grab value from | 
|  | 9131 | elaborated_byte_size,  // Size of this type in bytes | 
|  | 9132 | bitfield_bit_size,  // Bitfield bit size | 
|  | 9133 | bitfield_bit_offset,// Bitfield bit offset | 
|  | 9134 | show_types,         // Boolean indicating if we should show the variable types | 
|  | 9135 | show_summary,       // Boolean indicating if we should show a summary for the current type | 
|  | 9136 | verbose,            // Verbose output? | 
|  | 9137 | depth);             // Scope depth for any types that have children | 
|  | 9138 | } | 
|  | 9139 | break; | 
|  | 9140 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9141 | case clang::Type::Elaborated: | 
|  | 9142 | { | 
|  | 9143 | clang::QualType elaborated_qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 9144 | CompilerType elaborated_clang_type (getASTContext(), elaborated_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9145 | lldb::Format elaborated_format = elaborated_clang_type.GetFormat(); | 
|  | 9146 | clang::TypeInfo elaborated_type_info = getASTContext()->getTypeInfo(elaborated_qual_type); | 
|  | 9147 | uint64_t elaborated_byte_size = elaborated_type_info.Width / 8; | 
|  | 9148 |  | 
|  | 9149 | return elaborated_clang_type.DumpValue (exe_ctx, | 
|  | 9150 | s,                  // Stream to dump to | 
|  | 9151 | elaborated_format,  // The format with which to display the element | 
|  | 9152 | data,               // Data buffer containing all bytes for this type | 
|  | 9153 | data_byte_offset,   // Offset into "data" where to grab value from | 
|  | 9154 | elaborated_byte_size,  // Size of this type in bytes | 
|  | 9155 | bitfield_bit_size,  // Bitfield bit size | 
|  | 9156 | bitfield_bit_offset,// Bitfield bit offset | 
|  | 9157 | show_types,         // Boolean indicating if we should show the variable types | 
|  | 9158 | show_summary,       // Boolean indicating if we should show a summary for the current type | 
|  | 9159 | verbose,            // Verbose output? | 
|  | 9160 | depth);             // Scope depth for any types that have children | 
|  | 9161 | } | 
|  | 9162 | break; | 
|  | 9163 |  | 
|  | 9164 | case clang::Type::Paren: | 
|  | 9165 | { | 
|  | 9166 | clang::QualType desugar_qual_type = llvm::cast<clang::ParenType>(qual_type)->desugar(); | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 9167 | CompilerType desugar_clang_type (getASTContext(), desugar_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9168 |  | 
|  | 9169 | lldb::Format desugar_format = desugar_clang_type.GetFormat(); | 
|  | 9170 | clang::TypeInfo desugar_type_info = getASTContext()->getTypeInfo(desugar_qual_type); | 
|  | 9171 | uint64_t desugar_byte_size = desugar_type_info.Width / 8; | 
|  | 9172 |  | 
|  | 9173 | return desugar_clang_type.DumpValue (exe_ctx, | 
|  | 9174 | s,                  // Stream to dump to | 
|  | 9175 | desugar_format,  // The format with which to display the element | 
|  | 9176 | data,               // Data buffer containing all bytes for this type | 
|  | 9177 | data_byte_offset,   // Offset into "data" where to grab value from | 
|  | 9178 | desugar_byte_size,  // Size of this type in bytes | 
|  | 9179 | bitfield_bit_size,  // Bitfield bit size | 
|  | 9180 | bitfield_bit_offset,// Bitfield bit offset | 
|  | 9181 | show_types,         // Boolean indicating if we should show the variable types | 
|  | 9182 | show_summary,       // Boolean indicating if we should show a summary for the current type | 
|  | 9183 | verbose,            // Verbose output? | 
|  | 9184 | depth);             // Scope depth for any types that have children | 
|  | 9185 | } | 
|  | 9186 | break; | 
|  | 9187 |  | 
|  | 9188 | default: | 
|  | 9189 | // We are down to a scalar type that we just need to display. | 
|  | 9190 | data.Dump(s, | 
|  | 9191 | data_byte_offset, | 
|  | 9192 | format, | 
|  | 9193 | data_byte_size, | 
|  | 9194 | 1, | 
|  | 9195 | UINT32_MAX, | 
|  | 9196 | LLDB_INVALID_ADDRESS, | 
|  | 9197 | bitfield_bit_size, | 
|  | 9198 | bitfield_bit_offset); | 
|  | 9199 |  | 
|  | 9200 | if (show_summary) | 
|  | 9201 | DumpSummary (type, exe_ctx, s, data, data_byte_offset, data_byte_size); | 
|  | 9202 | break; | 
|  | 9203 | } | 
|  | 9204 | } | 
|  | 9205 |  | 
|  | 9206 |  | 
|  | 9207 |  | 
|  | 9208 |  | 
|  | 9209 | bool | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 9210 | ClangASTContext::DumpTypeValue (lldb::opaque_compiler_type_t type, Stream *s, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9211 | lldb::Format format, | 
|  | 9212 | const lldb_private::DataExtractor &data, | 
|  | 9213 | lldb::offset_t byte_offset, | 
|  | 9214 | size_t byte_size, | 
|  | 9215 | uint32_t bitfield_bit_size, | 
|  | 9216 | uint32_t bitfield_bit_offset, | 
|  | 9217 | ExecutionContextScope *exe_scope) | 
|  | 9218 | { | 
|  | 9219 | if (!type) | 
|  | 9220 | return false; | 
|  | 9221 | if (IsAggregateType(type)) | 
|  | 9222 | { | 
|  | 9223 | return false; | 
|  | 9224 | } | 
|  | 9225 | else | 
|  | 9226 | { | 
|  | 9227 | clang::QualType qual_type(GetQualType(type)); | 
|  | 9228 |  | 
|  | 9229 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 9230 | switch (type_class) | 
|  | 9231 | { | 
|  | 9232 | case clang::Type::Typedef: | 
|  | 9233 | { | 
|  | 9234 | 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] | 9235 | CompilerType typedef_clang_type (getASTContext(), typedef_qual_type); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9236 | if (format == eFormatDefault) | 
|  | 9237 | format = typedef_clang_type.GetFormat(); | 
|  | 9238 | clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type); | 
|  | 9239 | uint64_t typedef_byte_size = typedef_type_info.Width / 8; | 
|  | 9240 |  | 
|  | 9241 | return typedef_clang_type.DumpTypeValue (s, | 
|  | 9242 | format,                 // The format with which to display the element | 
|  | 9243 | data,                   // Data buffer containing all bytes for this type | 
|  | 9244 | byte_offset,            // Offset into "data" where to grab value from | 
|  | 9245 | typedef_byte_size,      // Size of this type in bytes | 
|  | 9246 | bitfield_bit_size,      // Size in bits of a bitfield value, if zero don't treat as a bitfield | 
|  | 9247 | bitfield_bit_offset,    // Offset in bits of a bitfield value if bitfield_bit_size != 0 | 
|  | 9248 | exe_scope); | 
|  | 9249 | } | 
|  | 9250 | break; | 
|  | 9251 |  | 
|  | 9252 | case clang::Type::Enum: | 
|  | 9253 | // If our format is enum or default, show the enumeration value as | 
|  | 9254 | // its enumeration string value, else just display it as requested. | 
|  | 9255 | if ((format == eFormatEnum || format == eFormatDefault) && GetCompleteType(type)) | 
|  | 9256 | { | 
|  | 9257 | const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr()); | 
|  | 9258 | const clang::EnumDecl *enum_decl = enutype->getDecl(); | 
|  | 9259 | assert(enum_decl); | 
|  | 9260 | clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos; | 
|  | 9261 | const bool is_signed = qual_type->isSignedIntegerOrEnumerationType(); | 
|  | 9262 | lldb::offset_t offset = byte_offset; | 
|  | 9263 | if (is_signed) | 
|  | 9264 | { | 
|  | 9265 | const int64_t enum_svalue = data.GetMaxS64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset); | 
|  | 9266 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) | 
|  | 9267 | { | 
|  | 9268 | if (enum_pos->getInitVal().getSExtValue() == enum_svalue) | 
|  | 9269 | { | 
|  | 9270 | s->PutCString (enum_pos->getNameAsString().c_str()); | 
|  | 9271 | return true; | 
|  | 9272 | } | 
|  | 9273 | } | 
|  | 9274 | // If we have gotten here we didn't get find the enumerator in the | 
|  | 9275 | // enum decl, so just print the integer. | 
|  | 9276 | s->Printf("%" PRIi64, enum_svalue); | 
|  | 9277 | } | 
|  | 9278 | else | 
|  | 9279 | { | 
|  | 9280 | const uint64_t enum_uvalue = data.GetMaxU64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset); | 
|  | 9281 | for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos) | 
|  | 9282 | { | 
|  | 9283 | if (enum_pos->getInitVal().getZExtValue() == enum_uvalue) | 
|  | 9284 | { | 
|  | 9285 | s->PutCString (enum_pos->getNameAsString().c_str()); | 
|  | 9286 | return true; | 
|  | 9287 | } | 
|  | 9288 | } | 
|  | 9289 | // If we have gotten here we didn't get find the enumerator in the | 
|  | 9290 | // enum decl, so just print the integer. | 
|  | 9291 | s->Printf("%" PRIu64, enum_uvalue); | 
|  | 9292 | } | 
|  | 9293 | return true; | 
|  | 9294 | } | 
|  | 9295 | // format was not enum, just fall through and dump the value as requested.... | 
|  | 9296 |  | 
|  | 9297 | default: | 
|  | 9298 | // We are down to a scalar type that we just need to display. | 
|  | 9299 | { | 
|  | 9300 | uint32_t item_count = 1; | 
|  | 9301 | // A few formats, we might need to modify our size and count for depending | 
|  | 9302 | // on how we are trying to display the value... | 
|  | 9303 | switch (format) | 
|  | 9304 | { | 
|  | 9305 | default: | 
|  | 9306 | case eFormatBoolean: | 
|  | 9307 | case eFormatBinary: | 
|  | 9308 | case eFormatComplex: | 
|  | 9309 | case eFormatCString:         // NULL terminated C strings | 
|  | 9310 | case eFormatDecimal: | 
|  | 9311 | case eFormatEnum: | 
|  | 9312 | case eFormatHex: | 
|  | 9313 | case eFormatHexUppercase: | 
|  | 9314 | case eFormatFloat: | 
|  | 9315 | case eFormatOctal: | 
|  | 9316 | case eFormatOSType: | 
|  | 9317 | case eFormatUnsigned: | 
|  | 9318 | case eFormatPointer: | 
|  | 9319 | case eFormatVectorOfChar: | 
|  | 9320 | case eFormatVectorOfSInt8: | 
|  | 9321 | case eFormatVectorOfUInt8: | 
|  | 9322 | case eFormatVectorOfSInt16: | 
|  | 9323 | case eFormatVectorOfUInt16: | 
|  | 9324 | case eFormatVectorOfSInt32: | 
|  | 9325 | case eFormatVectorOfUInt32: | 
|  | 9326 | case eFormatVectorOfSInt64: | 
|  | 9327 | case eFormatVectorOfUInt64: | 
|  | 9328 | case eFormatVectorOfFloat32: | 
|  | 9329 | case eFormatVectorOfFloat64: | 
|  | 9330 | case eFormatVectorOfUInt128: | 
|  | 9331 | break; | 
|  | 9332 |  | 
|  | 9333 | case eFormatChar: | 
|  | 9334 | case eFormatCharPrintable: | 
|  | 9335 | case eFormatCharArray: | 
|  | 9336 | case eFormatBytes: | 
|  | 9337 | case eFormatBytesWithASCII: | 
|  | 9338 | item_count = byte_size; | 
|  | 9339 | byte_size = 1; | 
|  | 9340 | break; | 
|  | 9341 |  | 
|  | 9342 | case eFormatUnicode16: | 
|  | 9343 | item_count = byte_size / 2; | 
|  | 9344 | byte_size = 2; | 
|  | 9345 | break; | 
|  | 9346 |  | 
|  | 9347 | case eFormatUnicode32: | 
|  | 9348 | item_count = byte_size / 4; | 
|  | 9349 | byte_size = 4; | 
|  | 9350 | break; | 
|  | 9351 | } | 
|  | 9352 | return data.Dump (s, | 
|  | 9353 | byte_offset, | 
|  | 9354 | format, | 
|  | 9355 | byte_size, | 
|  | 9356 | item_count, | 
|  | 9357 | UINT32_MAX, | 
|  | 9358 | LLDB_INVALID_ADDRESS, | 
|  | 9359 | bitfield_bit_size, | 
|  | 9360 | bitfield_bit_offset, | 
|  | 9361 | exe_scope); | 
|  | 9362 | } | 
|  | 9363 | break; | 
|  | 9364 | } | 
|  | 9365 | } | 
|  | 9366 | return 0; | 
|  | 9367 | } | 
|  | 9368 |  | 
|  | 9369 |  | 
|  | 9370 |  | 
|  | 9371 | void | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 9372 | ClangASTContext::DumpSummary (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9373 | Stream *s, | 
|  | 9374 | const lldb_private::DataExtractor &data, | 
|  | 9375 | lldb::offset_t data_byte_offset, | 
|  | 9376 | size_t data_byte_size) | 
|  | 9377 | { | 
|  | 9378 | uint32_t length = 0; | 
|  | 9379 | if (IsCStringType (type, length)) | 
|  | 9380 | { | 
|  | 9381 | if (exe_ctx) | 
|  | 9382 | { | 
|  | 9383 | Process *process = exe_ctx->GetProcessPtr(); | 
|  | 9384 | if (process) | 
|  | 9385 | { | 
|  | 9386 | lldb::offset_t offset = data_byte_offset; | 
|  | 9387 | lldb::addr_t pointer_address = data.GetMaxU64(&offset, data_byte_size); | 
|  | 9388 | std::vector<uint8_t> buf; | 
|  | 9389 | if (length > 0) | 
|  | 9390 | buf.resize (length); | 
|  | 9391 | else | 
|  | 9392 | buf.resize (256); | 
|  | 9393 |  | 
|  | 9394 | lldb_private::DataExtractor cstr_data(&buf.front(), buf.size(), process->GetByteOrder(), 4); | 
|  | 9395 | buf.back() = '\0'; | 
|  | 9396 | size_t bytes_read; | 
|  | 9397 | size_t total_cstr_len = 0; | 
|  | 9398 | Error error; | 
|  | 9399 | while ((bytes_read = process->ReadMemory (pointer_address, &buf.front(), buf.size(), error)) > 0) | 
|  | 9400 | { | 
|  | 9401 | const size_t len = strlen((const char *)&buf.front()); | 
|  | 9402 | if (len == 0) | 
|  | 9403 | break; | 
|  | 9404 | if (total_cstr_len == 0) | 
|  | 9405 | s->PutCString (" \""); | 
|  | 9406 | cstr_data.Dump(s, 0, lldb::eFormatChar, 1, len, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); | 
|  | 9407 | total_cstr_len += len; | 
|  | 9408 | if (len < buf.size()) | 
|  | 9409 | break; | 
|  | 9410 | pointer_address += total_cstr_len; | 
|  | 9411 | } | 
|  | 9412 | if (total_cstr_len > 0) | 
|  | 9413 | s->PutChar ('"'); | 
|  | 9414 | } | 
|  | 9415 | } | 
|  | 9416 | } | 
|  | 9417 | } | 
|  | 9418 |  | 
|  | 9419 | void | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 9420 | ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9421 | { | 
|  | 9422 | StreamFile s (stdout, false); | 
| Enrico Granata | c3ef0ed | 2015-10-14 22:44:50 +0000 | [diff] [blame] | 9423 | DumpTypeDescription (type, &s); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9424 | ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), type); | 
|  | 9425 | if (metadata) | 
|  | 9426 | { | 
|  | 9427 | metadata->Dump (&s); | 
|  | 9428 | } | 
|  | 9429 | } | 
|  | 9430 |  | 
|  | 9431 | void | 
| Bruce Mitchener | 48ea900 | 2015-09-23 00:18:24 +0000 | [diff] [blame] | 9432 | ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type, Stream *s) | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9433 | { | 
|  | 9434 | if (type) | 
|  | 9435 | { | 
|  | 9436 | clang::QualType qual_type(GetQualType(type)); | 
|  | 9437 |  | 
|  | 9438 | llvm::SmallVector<char, 1024> buf; | 
|  | 9439 | llvm::raw_svector_ostream llvm_ostrm (buf); | 
|  | 9440 |  | 
|  | 9441 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 9442 | switch (type_class) | 
|  | 9443 | { | 
|  | 9444 | case clang::Type::ObjCObject: | 
|  | 9445 | case clang::Type::ObjCInterface: | 
|  | 9446 | { | 
|  | 9447 | GetCompleteType(type); | 
|  | 9448 |  | 
|  | 9449 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr()); | 
|  | 9450 | assert (objc_class_type); | 
|  | 9451 | if (objc_class_type) | 
|  | 9452 | { | 
|  | 9453 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 9454 | if (class_interface_decl) | 
|  | 9455 | { | 
|  | 9456 | clang::PrintingPolicy policy = getASTContext()->getPrintingPolicy(); | 
|  | 9457 | class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel()); | 
|  | 9458 | } | 
|  | 9459 | } | 
|  | 9460 | } | 
|  | 9461 | break; | 
|  | 9462 |  | 
|  | 9463 | case clang::Type::Typedef: | 
|  | 9464 | { | 
|  | 9465 | const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>(); | 
|  | 9466 | if (typedef_type) | 
|  | 9467 | { | 
|  | 9468 | const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); | 
|  | 9469 | std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString()); | 
|  | 9470 | if (!clang_typedef_name.empty()) | 
|  | 9471 | { | 
|  | 9472 | s->PutCString ("typedef "); | 
|  | 9473 | s->PutCString (clang_typedef_name.c_str()); | 
|  | 9474 | } | 
|  | 9475 | } | 
|  | 9476 | } | 
|  | 9477 | break; | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 9478 |  | 
|  | 9479 | case clang::Type::Auto: | 
|  | 9480 | CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).DumpTypeDescription(s); | 
|  | 9481 | return; | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9482 |  | 
|  | 9483 | case clang::Type::Elaborated: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 9484 | CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).DumpTypeDescription(s); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9485 | return; | 
|  | 9486 |  | 
|  | 9487 | case clang::Type::Paren: | 
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 9488 | CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).DumpTypeDescription(s); | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9489 | return; | 
|  | 9490 |  | 
|  | 9491 | case clang::Type::Record: | 
|  | 9492 | { | 
|  | 9493 | GetCompleteType(type); | 
|  | 9494 |  | 
|  | 9495 | const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr()); | 
|  | 9496 | const clang::RecordDecl *record_decl = record_type->getDecl(); | 
|  | 9497 | const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl); | 
|  | 9498 |  | 
|  | 9499 | if (cxx_record_decl) | 
|  | 9500 | cxx_record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel()); | 
|  | 9501 | else | 
|  | 9502 | record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel()); | 
|  | 9503 | } | 
|  | 9504 | break; | 
|  | 9505 |  | 
|  | 9506 | default: | 
|  | 9507 | { | 
|  | 9508 | const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()); | 
|  | 9509 | if (tag_type) | 
|  | 9510 | { | 
|  | 9511 | clang::TagDecl *tag_decl = tag_type->getDecl(); | 
|  | 9512 | if (tag_decl) | 
|  | 9513 | tag_decl->print(llvm_ostrm, 0); | 
|  | 9514 | } | 
|  | 9515 | else | 
|  | 9516 | { | 
|  | 9517 | std::string clang_type_name(qual_type.getAsString()); | 
|  | 9518 | if (!clang_type_name.empty()) | 
|  | 9519 | s->PutCString (clang_type_name.c_str()); | 
|  | 9520 | } | 
|  | 9521 | } | 
|  | 9522 | } | 
|  | 9523 |  | 
| Greg Clayton | d8d4a57 | 2015-08-11 21:38:15 +0000 | [diff] [blame] | 9524 | if (buf.size() > 0) | 
|  | 9525 | { | 
|  | 9526 | s->Write (buf.data(), buf.size()); | 
|  | 9527 | } | 
|  | 9528 | } | 
|  | 9529 | } | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9530 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 9531 | void | 
|  | 9532 | ClangASTContext::DumpTypeName (const CompilerType &type) | 
|  | 9533 | { | 
|  | 9534 | if (IsClangType(type)) | 
|  | 9535 | { | 
|  | 9536 | clang::QualType qual_type(GetCanonicalQualType(RemoveFastQualifiers(type))); | 
|  | 9537 |  | 
|  | 9538 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | 
|  | 9539 | switch (type_class) | 
|  | 9540 | { | 
|  | 9541 | case clang::Type::Record: | 
|  | 9542 | { | 
|  | 9543 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); | 
|  | 9544 | if (cxx_record_decl) | 
|  | 9545 | printf("class %s", cxx_record_decl->getName().str().c_str()); | 
|  | 9546 | } | 
|  | 9547 | break; | 
|  | 9548 |  | 
|  | 9549 | case clang::Type::Enum: | 
|  | 9550 | { | 
|  | 9551 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); | 
|  | 9552 | if (enum_decl) | 
|  | 9553 | { | 
|  | 9554 | printf("enum %s", enum_decl->getName().str().c_str()); | 
|  | 9555 | } | 
|  | 9556 | } | 
|  | 9557 | break; | 
|  | 9558 |  | 
|  | 9559 | case clang::Type::ObjCObject: | 
|  | 9560 | case clang::Type::ObjCInterface: | 
|  | 9561 | { | 
|  | 9562 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); | 
|  | 9563 | if (objc_class_type) | 
|  | 9564 | { | 
|  | 9565 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); | 
|  | 9566 | // We currently can't complete objective C types through the newly added ASTContext | 
|  | 9567 | // because it only supports TagDecl objects right now... | 
|  | 9568 | if (class_interface_decl) | 
|  | 9569 | printf("@class %s", class_interface_decl->getName().str().c_str()); | 
|  | 9570 | } | 
|  | 9571 | } | 
|  | 9572 | break; | 
|  | 9573 |  | 
|  | 9574 |  | 
|  | 9575 | case clang::Type::Typedef: | 
|  | 9576 | printf("typedef %s", llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getName().str().c_str()); | 
|  | 9577 | break; | 
|  | 9578 |  | 
| Enrico Granata | 36f51e4 | 2015-12-18 22:41:25 +0000 | [diff] [blame] | 9579 | case clang::Type::Auto: | 
|  | 9580 | printf("auto "); | 
|  | 9581 | return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr())); | 
|  | 9582 |  | 
| Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 9583 | case clang::Type::Elaborated: | 
|  | 9584 | printf("elaborated "); | 
|  | 9585 | return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr())); | 
|  | 9586 |  | 
|  | 9587 | case clang::Type::Paren: | 
|  | 9588 | printf("paren "); | 
|  | 9589 | return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())); | 
|  | 9590 |  | 
|  | 9591 | default: | 
|  | 9592 | printf("ClangASTContext::DumpTypeName() type_class = %u", type_class); | 
|  | 9593 | break; | 
|  | 9594 | } | 
|  | 9595 | } | 
|  | 9596 |  | 
|  | 9597 | } | 
|  | 9598 |  | 
|  | 9599 |  | 
|  | 9600 |  | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9601 | clang::ClassTemplateDecl * | 
| Greg Clayton | 6071e6f | 2015-08-26 22:57:51 +0000 | [diff] [blame] | 9602 | ClangASTContext::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9603 | lldb::AccessType access_type, | 
|  | 9604 | const char *parent_name, | 
|  | 9605 | int tag_decl_kind, | 
|  | 9606 | const ClangASTContext::TemplateParameterInfos &template_param_infos) | 
|  | 9607 | { | 
|  | 9608 | if (template_param_infos.IsValid()) | 
|  | 9609 | { | 
|  | 9610 | std::string template_basename(parent_name); | 
|  | 9611 | template_basename.erase (template_basename.find('<')); | 
|  | 9612 |  | 
|  | 9613 | return CreateClassTemplateDecl (decl_ctx, | 
|  | 9614 | access_type, | 
|  | 9615 | template_basename.c_str(), | 
|  | 9616 | tag_decl_kind, | 
|  | 9617 | template_param_infos); | 
|  | 9618 | } | 
|  | 9619 | return NULL; | 
|  | 9620 | } | 
|  | 9621 |  | 
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9622 | void | 
|  | 9623 | ClangASTContext::CompleteTagDecl (void *baton, clang::TagDecl *decl) | 
|  | 9624 | { | 
|  | 9625 | ClangASTContext *ast = (ClangASTContext *)baton; | 
|  | 9626 | SymbolFile *sym_file = ast->GetSymbolFile(); | 
|  | 9627 | if (sym_file) | 
|  | 9628 | { | 
|  | 9629 | CompilerType clang_type = GetTypeForDecl (decl); | 
|  | 9630 | if (clang_type) | 
|  | 9631 | sym_file->CompleteType (clang_type); | 
|  | 9632 | } | 
|  | 9633 | } | 
|  | 9634 |  | 
|  | 9635 | void | 
|  | 9636 | ClangASTContext::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) | 
|  | 9637 | { | 
|  | 9638 | ClangASTContext *ast = (ClangASTContext *)baton; | 
|  | 9639 | SymbolFile *sym_file = ast->GetSymbolFile(); | 
|  | 9640 | if (sym_file) | 
|  | 9641 | { | 
|  | 9642 | CompilerType clang_type = GetTypeForDecl (decl); | 
|  | 9643 | if (clang_type) | 
|  | 9644 | sym_file->CompleteType (clang_type); | 
|  | 9645 | } | 
|  | 9646 | } | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9647 |  | 
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 9648 |  | 
|  | 9649 | DWARFASTParser * | 
|  | 9650 | ClangASTContext::GetDWARFParser () | 
|  | 9651 | { | 
|  | 9652 | if (!m_dwarf_ast_parser_ap) | 
|  | 9653 | m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this)); | 
|  | 9654 | return m_dwarf_ast_parser_ap.get(); | 
|  | 9655 | } | 
|  | 9656 |  | 
|  | 9657 |  | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9658 | bool | 
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9659 | ClangASTContext::LayoutRecordType(void *baton, | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9660 | const clang::RecordDecl *record_decl, | 
|  | 9661 | uint64_t &bit_size, | 
|  | 9662 | uint64_t &alignment, | 
|  | 9663 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, | 
|  | 9664 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, | 
|  | 9665 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) | 
|  | 9666 | { | 
| Greg Clayton | 6dc8d58 | 2015-08-18 22:32:36 +0000 | [diff] [blame] | 9667 | ClangASTContext *ast = (ClangASTContext *)baton; | 
| Greg Clayton | 261ac3f | 2015-08-28 01:01:03 +0000 | [diff] [blame] | 9668 | DWARFASTParserClang *dwarf_ast_parser = (DWARFASTParserClang *)ast->GetDWARFParser(); | 
|  | 9669 | 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] | 9670 | } | 
|  | 9671 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9672 | //---------------------------------------------------------------------- | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9673 | // CompilerDecl override functions | 
|  | 9674 | //---------------------------------------------------------------------- | 
|  | 9675 | lldb::VariableSP | 
|  | 9676 | ClangASTContext::DeclGetVariable (void *opaque_decl) | 
|  | 9677 | { | 
|  | 9678 | if (llvm::dyn_cast<clang::VarDecl>((clang::Decl *)opaque_decl)) | 
|  | 9679 | { | 
|  | 9680 | auto decl_search_it = m_decl_objects.find(opaque_decl); | 
|  | 9681 | if (decl_search_it != m_decl_objects.end()) | 
|  | 9682 | return std::static_pointer_cast<Variable>(decl_search_it->second); | 
|  | 9683 | } | 
|  | 9684 | return VariableSP(); | 
|  | 9685 | } | 
|  | 9686 |  | 
|  | 9687 | void | 
|  | 9688 | ClangASTContext::DeclLinkToObject (void *opaque_decl, std::shared_ptr<void> object) | 
|  | 9689 | { | 
|  | 9690 | if (m_decl_objects.find(opaque_decl) == m_decl_objects.end()) | 
|  | 9691 | m_decl_objects.insert(std::make_pair(opaque_decl, object)); | 
|  | 9692 | } | 
|  | 9693 |  | 
|  | 9694 | ConstString | 
|  | 9695 | ClangASTContext::DeclGetName (void *opaque_decl) | 
|  | 9696 | { | 
|  | 9697 | if (opaque_decl) | 
|  | 9698 | { | 
|  | 9699 | clang::NamedDecl *nd = llvm::dyn_cast<NamedDecl>((clang::Decl*)opaque_decl); | 
|  | 9700 | if (nd != nullptr) | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9701 | return ConstString(nd->getDeclName().getAsString()); | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9702 | } | 
|  | 9703 | return ConstString(); | 
|  | 9704 | } | 
|  | 9705 |  | 
| Greg Clayton | fe68904 | 2015-11-10 17:47:04 +0000 | [diff] [blame] | 9706 | ConstString | 
|  | 9707 | ClangASTContext::DeclGetMangledName (void *opaque_decl) | 
|  | 9708 | { | 
|  | 9709 | if (opaque_decl) | 
|  | 9710 | { | 
|  | 9711 | clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>((clang::Decl*)opaque_decl); | 
|  | 9712 | if (nd != nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd)) | 
|  | 9713 | { | 
|  | 9714 | clang::MangleContext *mc = getMangleContext(); | 
|  | 9715 | if (mc && mc->shouldMangleCXXName(nd)) | 
|  | 9716 | { | 
|  | 9717 | llvm::SmallVector<char, 1024> buf; | 
|  | 9718 | llvm::raw_svector_ostream llvm_ostrm (buf); | 
|  | 9719 | if (llvm::isa<clang::CXXConstructorDecl>(nd)) | 
|  | 9720 | { | 
|  | 9721 | mc->mangleCXXCtor(llvm::dyn_cast<clang::CXXConstructorDecl>(nd), Ctor_Complete, llvm_ostrm); | 
|  | 9722 | } | 
|  | 9723 | else if (llvm::isa<clang::CXXDestructorDecl>(nd)) | 
|  | 9724 | { | 
|  | 9725 | mc->mangleCXXDtor(llvm::dyn_cast<clang::CXXDestructorDecl>(nd), Dtor_Complete, llvm_ostrm); | 
|  | 9726 | } | 
|  | 9727 | else | 
|  | 9728 | { | 
|  | 9729 | mc->mangleName(nd, llvm_ostrm); | 
|  | 9730 | } | 
|  | 9731 | if (buf.size() > 0) | 
|  | 9732 | return ConstString(buf.data(), buf.size()); | 
|  | 9733 | } | 
|  | 9734 | } | 
|  | 9735 | } | 
|  | 9736 | return ConstString(); | 
|  | 9737 | } | 
|  | 9738 |  | 
|  | 9739 | CompilerDeclContext | 
|  | 9740 | ClangASTContext::DeclGetDeclContext (void *opaque_decl) | 
|  | 9741 | { | 
|  | 9742 | if (opaque_decl) | 
|  | 9743 | return CompilerDeclContext(this, ((clang::Decl*)opaque_decl)->getDeclContext()); | 
|  | 9744 | else | 
|  | 9745 | return CompilerDeclContext(); | 
|  | 9746 | } | 
|  | 9747 |  | 
|  | 9748 | CompilerType | 
|  | 9749 | ClangASTContext::DeclGetFunctionReturnType(void *opaque_decl) | 
|  | 9750 | { | 
|  | 9751 | if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl)) | 
|  | 9752 | return CompilerType(this, func_decl->getReturnType().getAsOpaquePtr()); | 
|  | 9753 | if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl)) | 
|  | 9754 | return CompilerType(this, objc_method->getReturnType().getAsOpaquePtr()); | 
|  | 9755 | else | 
|  | 9756 | return CompilerType(); | 
|  | 9757 | } | 
|  | 9758 |  | 
|  | 9759 | size_t | 
|  | 9760 | ClangASTContext::DeclGetFunctionNumArguments(void *opaque_decl) | 
|  | 9761 | { | 
|  | 9762 | if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl)) | 
|  | 9763 | return func_decl->param_size(); | 
|  | 9764 | if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl)) | 
|  | 9765 | return  objc_method->param_size(); | 
|  | 9766 | else | 
|  | 9767 | return 0; | 
|  | 9768 | } | 
|  | 9769 |  | 
|  | 9770 | CompilerType | 
|  | 9771 | ClangASTContext::DeclGetFunctionArgumentType (void *opaque_decl, size_t idx) | 
|  | 9772 | { | 
|  | 9773 | if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl)) | 
|  | 9774 | { | 
|  | 9775 | if (idx < func_decl->param_size()) | 
|  | 9776 | { | 
|  | 9777 | ParmVarDecl *var_decl = func_decl->getParamDecl(idx); | 
|  | 9778 | if (var_decl) | 
|  | 9779 | return  CompilerType(this, var_decl->getOriginalType().getAsOpaquePtr()); | 
|  | 9780 | } | 
|  | 9781 | } | 
|  | 9782 | else if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl)) | 
|  | 9783 | { | 
|  | 9784 | if (idx < objc_method->param_size()) | 
|  | 9785 | return CompilerType(this, objc_method->parameters()[idx]->getOriginalType().getAsOpaquePtr()); | 
|  | 9786 | } | 
|  | 9787 | return CompilerType(); | 
|  | 9788 | } | 
|  | 9789 |  | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9790 | //---------------------------------------------------------------------- | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9791 | // CompilerDeclContext functions | 
|  | 9792 | //---------------------------------------------------------------------- | 
|  | 9793 |  | 
| Greg Clayton | dfc0962 | 2015-12-08 18:39:50 +0000 | [diff] [blame] | 9794 | std::vector<CompilerDecl> | 
| Siva Chandra | 375882d | 2016-02-04 18:38:35 +0000 | [diff] [blame] | 9795 | ClangASTContext::DeclContextFindDeclByName(void *opaque_decl_ctx, | 
|  | 9796 | ConstString name, | 
|  | 9797 | const bool ignore_using_decls) | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9798 | { | 
| Greg Clayton | dfc0962 | 2015-12-08 18:39:50 +0000 | [diff] [blame] | 9799 | std::vector<CompilerDecl> found_decls; | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9800 | if (opaque_decl_ctx) | 
|  | 9801 | { | 
|  | 9802 | DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx; | 
|  | 9803 | std::set<DeclContext *> searched; | 
|  | 9804 | std::multimap<DeclContext *, DeclContext *> search_queue; | 
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9805 | SymbolFile *symbol_file = GetSymbolFile(); | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9806 |  | 
|  | 9807 | for (clang::DeclContext *decl_context = root_decl_ctx; decl_context != nullptr && found_decls.empty(); decl_context = decl_context->getParent()) | 
|  | 9808 | { | 
|  | 9809 | search_queue.insert(std::make_pair(decl_context, decl_context)); | 
|  | 9810 |  | 
|  | 9811 | for (auto it = search_queue.find(decl_context); it != search_queue.end(); it++) | 
|  | 9812 | { | 
| Eugene Leviant | c1ba9fc | 2015-11-13 11:00:10 +0000 | [diff] [blame] | 9813 | if (!searched.insert(it->second).second) | 
|  | 9814 | continue; | 
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9815 | symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second)); | 
|  | 9816 |  | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9817 | for (clang::Decl *child : it->second->decls()) | 
|  | 9818 | { | 
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9819 | if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9820 | { | 
| Siva Chandra | 375882d | 2016-02-04 18:38:35 +0000 | [diff] [blame] | 9821 | if (ignore_using_decls) | 
|  | 9822 | continue; | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9823 | clang::DeclContext *from = ud->getCommonAncestor(); | 
|  | 9824 | if (searched.find(ud->getNominatedNamespace()) == searched.end()) | 
|  | 9825 | search_queue.insert(std::make_pair(from, ud->getNominatedNamespace())); | 
|  | 9826 | } | 
|  | 9827 | else if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child)) | 
|  | 9828 | { | 
| Siva Chandra | 375882d | 2016-02-04 18:38:35 +0000 | [diff] [blame] | 9829 | if (ignore_using_decls) | 
|  | 9830 | continue; | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9831 | for (clang::UsingShadowDecl *usd : ud->shadows()) | 
|  | 9832 | { | 
|  | 9833 | clang::Decl *target = usd->getTargetDecl(); | 
|  | 9834 | if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target)) | 
|  | 9835 | { | 
|  | 9836 | IdentifierInfo *ii = nd->getIdentifier(); | 
|  | 9837 | if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) | 
| Greg Clayton | dfc0962 | 2015-12-08 18:39:50 +0000 | [diff] [blame] | 9838 | found_decls.push_back(CompilerDecl(this, nd)); | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9839 | } | 
|  | 9840 | } | 
|  | 9841 | } | 
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9842 | else if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(child)) | 
|  | 9843 | { | 
|  | 9844 | IdentifierInfo *ii = nd->getIdentifier(); | 
|  | 9845 | if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr))) | 
| Greg Clayton | dfc0962 | 2015-12-08 18:39:50 +0000 | [diff] [blame] | 9846 | found_decls.push_back(CompilerDecl(this, nd)); | 
| Paul Herman | ea188fc | 2015-09-16 18:48:30 +0000 | [diff] [blame] | 9847 | } | 
| Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 9848 | } | 
|  | 9849 | } | 
|  | 9850 | } | 
|  | 9851 | } | 
|  | 9852 | return found_decls; | 
|  | 9853 | } | 
|  | 9854 |  | 
| Dawn Perchik | b592578 | 2015-12-12 19:31:41 +0000 | [diff] [blame] | 9855 | // Look for child_decl_ctx's lookup scope in frame_decl_ctx and its parents, | 
|  | 9856 | // and return the number of levels it took to find it, or LLDB_INVALID_DECL_LEVEL | 
|  | 9857 | // if not found.  If the decl was imported via a using declaration, its name and/or | 
|  | 9858 | // type, if set, will be used to check that the decl found in the scope is a match. | 
|  | 9859 | // | 
|  | 9860 | // The optional name is required by languages (like C++) to handle using declarations | 
|  | 9861 | // like: | 
|  | 9862 | // | 
|  | 9863 | //     void poo(); | 
|  | 9864 | //     namespace ns { | 
|  | 9865 | //         void foo(); | 
|  | 9866 | //         void goo(); | 
|  | 9867 | //     } | 
|  | 9868 | //     void bar() { | 
|  | 9869 | //         using ns::foo; | 
|  | 9870 | //         // CountDeclLevels returns 0 for 'foo', 1 for 'poo', and | 
|  | 9871 | //         // LLDB_INVALID_DECL_LEVEL for 'goo'. | 
|  | 9872 | //     } | 
|  | 9873 | // | 
|  | 9874 | // The optional type is useful in the case that there's a specific overload | 
|  | 9875 | // that we're looking for that might otherwise be shadowed, like: | 
|  | 9876 | // | 
|  | 9877 | //     void foo(int); | 
|  | 9878 | //     namespace ns { | 
|  | 9879 | //         void foo(); | 
|  | 9880 | //     } | 
|  | 9881 | //     void bar() { | 
|  | 9882 | //         using ns::foo; | 
|  | 9883 | //         // CountDeclLevels returns 0 for { 'foo', void() }, | 
|  | 9884 | //         // 1 for { 'foo', void(int) }, and | 
|  | 9885 | //         // LLDB_INVALID_DECL_LEVEL for { 'foo', void(int, int) }. | 
|  | 9886 | //     } | 
|  | 9887 | // | 
|  | 9888 | // NOTE: Because file statics are at the TranslationUnit along with globals, a | 
|  | 9889 | // function at file scope will return the same level as a function at global scope. | 
|  | 9890 | // Ideally we'd like to treat the file scope as an additional scope just below the | 
|  | 9891 | // global scope.  More work needs to be done to recognise that, if the decl we're | 
|  | 9892 | // trying to look up is static, we should compare its source file with that of the | 
|  | 9893 | // current scope and return a lower number for it. | 
|  | 9894 | uint32_t | 
|  | 9895 | ClangASTContext::CountDeclLevels (clang::DeclContext *frame_decl_ctx, | 
|  | 9896 | clang::DeclContext *child_decl_ctx, | 
|  | 9897 | ConstString *child_name, | 
|  | 9898 | CompilerType *child_type) | 
|  | 9899 | { | 
|  | 9900 | if (frame_decl_ctx) | 
|  | 9901 | { | 
|  | 9902 | std::set<DeclContext *> searched; | 
|  | 9903 | std::multimap<DeclContext *, DeclContext *> search_queue; | 
|  | 9904 | SymbolFile *symbol_file = GetSymbolFile(); | 
|  | 9905 |  | 
|  | 9906 | // Get the lookup scope for the decl we're trying to find. | 
|  | 9907 | clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent(); | 
|  | 9908 |  | 
|  | 9909 | // Look for it in our scope's decl context and its parents. | 
|  | 9910 | uint32_t level = 0; | 
|  | 9911 | for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx != nullptr; decl_ctx = decl_ctx->getParent()) | 
|  | 9912 | { | 
|  | 9913 | if (!decl_ctx->isLookupContext()) | 
|  | 9914 | continue; | 
|  | 9915 | if (decl_ctx == parent_decl_ctx) | 
|  | 9916 | // Found it! | 
|  | 9917 | return level; | 
|  | 9918 | search_queue.insert(std::make_pair(decl_ctx, decl_ctx)); | 
|  | 9919 | for (auto it = search_queue.find(decl_ctx); it != search_queue.end(); it++) | 
|  | 9920 | { | 
|  | 9921 | if (searched.find(it->second) != searched.end()) | 
|  | 9922 | continue; | 
|  | 9923 | searched.insert(it->second); | 
|  | 9924 | symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second)); | 
|  | 9925 |  | 
|  | 9926 | for (clang::Decl *child : it->second->decls()) | 
|  | 9927 | { | 
|  | 9928 | if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child)) | 
|  | 9929 | { | 
|  | 9930 | clang::DeclContext *ns = ud->getNominatedNamespace(); | 
|  | 9931 | if (ns == parent_decl_ctx) | 
|  | 9932 | // Found it! | 
|  | 9933 | return level; | 
|  | 9934 | clang::DeclContext *from = ud->getCommonAncestor(); | 
|  | 9935 | if (searched.find(ns) == searched.end()) | 
|  | 9936 | search_queue.insert(std::make_pair(from, ns)); | 
|  | 9937 | } | 
|  | 9938 | else if (child_name) | 
|  | 9939 | { | 
|  | 9940 | if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child)) | 
|  | 9941 | { | 
|  | 9942 | for (clang::UsingShadowDecl *usd : ud->shadows()) | 
|  | 9943 | { | 
|  | 9944 | clang::Decl *target = usd->getTargetDecl(); | 
|  | 9945 | clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target); | 
|  | 9946 | if (!nd) | 
|  | 9947 | continue; | 
|  | 9948 | // Check names. | 
|  | 9949 | IdentifierInfo *ii = nd->getIdentifier(); | 
|  | 9950 | if (ii == nullptr || !ii->getName().equals(child_name->AsCString(nullptr))) | 
|  | 9951 | continue; | 
|  | 9952 | // Check types, if one was provided. | 
|  | 9953 | if (child_type) | 
|  | 9954 | { | 
|  | 9955 | CompilerType clang_type = ClangASTContext::GetTypeForDecl(nd); | 
|  | 9956 | if (!AreTypesSame(clang_type, *child_type, /*ignore_qualifiers=*/true)) | 
|  | 9957 | continue; | 
|  | 9958 | } | 
|  | 9959 | // Found it! | 
|  | 9960 | return level; | 
|  | 9961 | } | 
|  | 9962 | } | 
|  | 9963 | } | 
|  | 9964 | } | 
|  | 9965 | } | 
|  | 9966 | ++level; | 
|  | 9967 | } | 
|  | 9968 | } | 
|  | 9969 | return LLDB_INVALID_DECL_LEVEL; | 
|  | 9970 | } | 
|  | 9971 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9972 | bool | 
|  | 9973 | ClangASTContext::DeclContextIsStructUnionOrClass (void *opaque_decl_ctx) | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9974 | { | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9975 | if (opaque_decl_ctx) | 
|  | 9976 | return ((clang::DeclContext *)opaque_decl_ctx)->isRecord(); | 
|  | 9977 | else | 
|  | 9978 | return false; | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9979 | } | 
|  | 9980 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9981 | ConstString | 
|  | 9982 | ClangASTContext::DeclContextGetName (void *opaque_decl_ctx) | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 9983 | { | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 9984 | if (opaque_decl_ctx) | 
|  | 9985 | { | 
|  | 9986 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); | 
|  | 9987 | if (named_decl) | 
|  | 9988 | return ConstString(named_decl->getName()); | 
|  | 9989 | } | 
|  | 9990 | return ConstString(); | 
|  | 9991 | } | 
|  | 9992 |  | 
| Siva Chandra | 9293fc4 | 2016-01-07 23:32:34 +0000 | [diff] [blame] | 9993 | ConstString | 
|  | 9994 | ClangASTContext::DeclContextGetScopeQualifiedName (void *opaque_decl_ctx) | 
|  | 9995 | { | 
|  | 9996 | if (opaque_decl_ctx) | 
|  | 9997 | { | 
|  | 9998 | clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx); | 
|  | 9999 | if (named_decl) | 
|  | 10000 | return ConstString(llvm::StringRef(named_decl->getQualifiedNameAsString())); | 
|  | 10001 | } | 
|  | 10002 | return ConstString(); | 
|  | 10003 | } | 
|  | 10004 |  | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10005 | bool | 
|  | 10006 | ClangASTContext::DeclContextIsClassMethod (void *opaque_decl_ctx, | 
|  | 10007 | lldb::LanguageType *language_ptr, | 
|  | 10008 | bool *is_instance_method_ptr, | 
|  | 10009 | ConstString *language_object_name_ptr) | 
|  | 10010 | { | 
|  | 10011 | if (opaque_decl_ctx) | 
|  | 10012 | { | 
|  | 10013 | clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx; | 
|  | 10014 | if (ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx)) | 
|  | 10015 | { | 
|  | 10016 | if (is_instance_method_ptr) | 
|  | 10017 | *is_instance_method_ptr = objc_method->isInstanceMethod(); | 
|  | 10018 | if (language_ptr) | 
|  | 10019 | *language_ptr = eLanguageTypeObjC; | 
|  | 10020 | if (language_object_name_ptr) | 
|  | 10021 | language_object_name_ptr->SetCString("self"); | 
|  | 10022 | return true; | 
|  | 10023 | } | 
|  | 10024 | else if (CXXMethodDecl *cxx_method = llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx)) | 
|  | 10025 | { | 
|  | 10026 | if (is_instance_method_ptr) | 
|  | 10027 | *is_instance_method_ptr = cxx_method->isInstance(); | 
|  | 10028 | if (language_ptr) | 
|  | 10029 | *language_ptr = eLanguageTypeC_plus_plus; | 
|  | 10030 | if (language_object_name_ptr) | 
|  | 10031 | language_object_name_ptr->SetCString("this"); | 
|  | 10032 | return true; | 
|  | 10033 | } | 
|  | 10034 | else if (clang::FunctionDecl *function_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) | 
|  | 10035 | { | 
|  | 10036 | ClangASTMetadata *metadata = GetMetadata (&decl_ctx->getParentASTContext(), function_decl); | 
|  | 10037 | if (metadata && metadata->HasObjectPtr()) | 
|  | 10038 | { | 
|  | 10039 | if (is_instance_method_ptr) | 
|  | 10040 | *is_instance_method_ptr = true; | 
|  | 10041 | if (language_ptr) | 
|  | 10042 | *language_ptr = eLanguageTypeObjC; | 
|  | 10043 | if (language_object_name_ptr) | 
|  | 10044 | language_object_name_ptr->SetCString (metadata->GetObjectPtrName()); | 
|  | 10045 | return true; | 
|  | 10046 | } | 
|  | 10047 | } | 
|  | 10048 | } | 
|  | 10049 | return false; | 
|  | 10050 | } | 
|  | 10051 |  | 
|  | 10052 | clang::DeclContext * | 
|  | 10053 | ClangASTContext::DeclContextGetAsDeclContext (const CompilerDeclContext &dc) | 
|  | 10054 | { | 
|  | 10055 | if (dc.IsClang()) | 
|  | 10056 | return (clang::DeclContext *)dc.GetOpaqueDeclContext(); | 
|  | 10057 | return nullptr; | 
|  | 10058 | } | 
|  | 10059 |  | 
|  | 10060 |  | 
|  | 10061 | ObjCMethodDecl * | 
|  | 10062 | ClangASTContext::DeclContextGetAsObjCMethodDecl (const CompilerDeclContext &dc) | 
|  | 10063 | { | 
|  | 10064 | if (dc.IsClang()) | 
|  | 10065 | return llvm::dyn_cast<clang::ObjCMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); | 
|  | 10066 | return nullptr; | 
|  | 10067 | } | 
|  | 10068 |  | 
|  | 10069 | CXXMethodDecl * | 
|  | 10070 | ClangASTContext::DeclContextGetAsCXXMethodDecl (const CompilerDeclContext &dc) | 
|  | 10071 | { | 
|  | 10072 | if (dc.IsClang()) | 
|  | 10073 | return llvm::dyn_cast<clang::CXXMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); | 
|  | 10074 | return nullptr; | 
|  | 10075 | } | 
|  | 10076 |  | 
|  | 10077 | clang::FunctionDecl * | 
|  | 10078 | ClangASTContext::DeclContextGetAsFunctionDecl (const CompilerDeclContext &dc) | 
|  | 10079 | { | 
|  | 10080 | if (dc.IsClang()) | 
|  | 10081 | return llvm::dyn_cast<clang::FunctionDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); | 
|  | 10082 | return nullptr; | 
|  | 10083 | } | 
|  | 10084 |  | 
|  | 10085 | clang::NamespaceDecl * | 
|  | 10086 | ClangASTContext::DeclContextGetAsNamespaceDecl (const CompilerDeclContext &dc) | 
|  | 10087 | { | 
|  | 10088 | if (dc.IsClang()) | 
|  | 10089 | return llvm::dyn_cast<clang::NamespaceDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext()); | 
|  | 10090 | return nullptr; | 
|  | 10091 | } | 
|  | 10092 |  | 
|  | 10093 | ClangASTMetadata * | 
|  | 10094 | ClangASTContext::DeclContextGetMetaData (const CompilerDeclContext &dc, const void *object) | 
|  | 10095 | { | 
|  | 10096 | clang::ASTContext *ast = DeclContextGetClangASTContext (dc); | 
|  | 10097 | if (ast) | 
|  | 10098 | return ClangASTContext::GetMetadata (ast, object); | 
|  | 10099 | return nullptr; | 
|  | 10100 | } | 
|  | 10101 |  | 
|  | 10102 | clang::ASTContext * | 
|  | 10103 | ClangASTContext::DeclContextGetClangASTContext (const CompilerDeclContext &dc) | 
|  | 10104 | { | 
| Greg Clayton | f73034f | 2015-09-08 18:15:05 +0000 | [diff] [blame] | 10105 | ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(dc.GetTypeSystem()); | 
|  | 10106 | if (ast) | 
|  | 10107 | return ast->getASTContext(); | 
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 10108 | return nullptr; | 
| Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 10109 | } | 
|  | 10110 |  | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10111 | ClangASTContextForExpressions::ClangASTContextForExpressions (Target &target) : | 
|  | 10112 | ClangASTContext (target.GetArchitecture().GetTriple().getTriple().c_str()), | 
| Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 10113 | m_target_wp(target.shared_from_this()), | 
|  | 10114 | m_persistent_variables (new ClangPersistentVariables) | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10115 | { | 
|  | 10116 | } | 
|  | 10117 |  | 
|  | 10118 | UserExpression * | 
|  | 10119 | ClangASTContextForExpressions::GetUserExpression (const char *expr, | 
|  | 10120 | const char *expr_prefix, | 
|  | 10121 | lldb::LanguageType language, | 
| Jim Ingham | 19a63fc | 2015-11-03 02:11:24 +0000 | [diff] [blame] | 10122 | Expression::ResultType desired_type, | 
|  | 10123 | const EvaluateExpressionOptions &options) | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10124 | { | 
|  | 10125 | TargetSP target_sp = m_target_wp.lock(); | 
|  | 10126 | if (!target_sp) | 
|  | 10127 | return nullptr; | 
|  | 10128 |  | 
| Jim Ingham | 19a63fc | 2015-11-03 02:11:24 +0000 | [diff] [blame] | 10129 | return new ClangUserExpression(*target_sp.get(), expr, expr_prefix, language, desired_type, options); | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10130 | } | 
|  | 10131 |  | 
|  | 10132 | FunctionCaller * | 
|  | 10133 | ClangASTContextForExpressions::GetFunctionCaller (const CompilerType &return_type, | 
|  | 10134 | const Address& function_address, | 
|  | 10135 | const ValueList &arg_value_list, | 
|  | 10136 | const char *name) | 
|  | 10137 | { | 
|  | 10138 | TargetSP target_sp = m_target_wp.lock(); | 
|  | 10139 | if (!target_sp) | 
|  | 10140 | return nullptr; | 
|  | 10141 |  | 
|  | 10142 | Process *process = target_sp->GetProcessSP().get(); | 
|  | 10143 | if (!process) | 
|  | 10144 | return nullptr; | 
|  | 10145 |  | 
|  | 10146 | return new ClangFunctionCaller (*process, return_type, function_address, arg_value_list, name); | 
|  | 10147 | } | 
|  | 10148 |  | 
|  | 10149 | UtilityFunction * | 
|  | 10150 | ClangASTContextForExpressions::GetUtilityFunction (const char *text, | 
|  | 10151 | const char *name) | 
|  | 10152 | { | 
| Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 10153 | TargetSP target_sp = m_target_wp.lock(); | 
| Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 10154 | if (!target_sp) | 
|  | 10155 | return nullptr; | 
|  | 10156 |  | 
|  | 10157 | return new ClangUtilityFunction(*target_sp.get(), text, name); | 
|  | 10158 | } | 
| Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 10159 |  | 
|  | 10160 | PersistentExpressionState * | 
|  | 10161 | ClangASTContextForExpressions::GetPersistentExpressionState () | 
|  | 10162 | { | 
|  | 10163 | return m_persistent_variables.get(); | 
|  | 10164 | } |