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 |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 14 | #include <mutex> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | |
| 17 | // Other libraries and framework includes |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 18 | |
| 19 | // Clang headers like to use NDEBUG inside of them to enable/disable debug |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 20 | // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 21 | // or another. This is bad because it means that if clang was built in release |
| 22 | // mode, it assumes that you are building in release mode which is not always |
| 23 | // the case. You can end up with functions that are defined as empty in header |
| 24 | // files when NDEBUG is not defined, and this can cause link errors with the |
| 25 | // clang .a files that you have since you might be missing functions in the .a |
| 26 | // file. So we have to define NDEBUG when including clang headers to avoid any |
| 27 | // mismatches. This is covered by rdar://problem/8691220 |
| 28 | |
Sean Callanan | 3b1d4f6 | 2011-10-26 17:46:51 +0000 | [diff] [blame] | 29 | #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 30 | #define LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 31 | #define NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 32 | // Need to include assert.h so it is as clang would expect it to be (disabled) |
| 33 | #include <assert.h> |
| 34 | #endif |
| 35 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | #include "clang/AST/ASTContext.h" |
| 37 | #include "clang/AST/ASTImporter.h" |
Greg Clayton | f74c403 | 2012-12-03 18:29:55 +0000 | [diff] [blame] | 38 | #include "clang/AST/Attr.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "clang/AST/CXXInheritance.h" |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 40 | #include "clang/AST/DeclObjC.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 41 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | #include "clang/AST/RecordLayout.h" |
| 43 | #include "clang/AST/Type.h" |
| 44 | #include "clang/Basic/Builtins.h" |
Sean Callanan | 7e2863b | 2012-02-06 21:28:03 +0000 | [diff] [blame] | 45 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | #include "clang/Basic/FileManager.h" |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 47 | #include "clang/Basic/FileSystemOptions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | #include "clang/Basic/SourceManager.h" |
| 49 | #include "clang/Basic/TargetInfo.h" |
| 50 | #include "clang/Basic/TargetOptions.h" |
| 51 | #include "clang/Frontend/FrontendOptions.h" |
| 52 | #include "clang/Frontend/LangStandard.h" |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 53 | |
| 54 | #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 55 | #undef NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 56 | #undef LLDB_DEFINED_NDEBUG_FOR_CLANG |
| 57 | // Need to re-include assert.h so it is as _we_ would expect it to be (enabled) |
| 58 | #include <assert.h> |
| 59 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 61 | #include "lldb/Core/ArchSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | #include "lldb/Core/dwarf.h" |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 63 | #include "lldb/Core/Flags.h" |
Sean Callanan | fb8b709 | 2010-10-28 18:19:36 +0000 | [diff] [blame] | 64 | #include "lldb/Core/Log.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 65 | #include "lldb/Core/RegularExpression.h" |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 66 | #include "lldb/Core/ThreadSafeDenseMap.h" |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 67 | #include "lldb/Core/UniqueCStringMap.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 68 | #include "lldb/Expression/ASTDumper.h" |
Sean Callanan | 3b107b1 | 2011-12-03 03:15:28 +0000 | [diff] [blame] | 69 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 70 | #include "lldb/Symbol/VerifyDecl.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 71 | #include "lldb/Target/ExecutionContext.h" |
| 72 | #include "lldb/Target/Process.h" |
| 73 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| 74 | |
Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 75 | #include <stdio.h> |
| 76 | |
Greg Clayton | 1341baf | 2013-07-11 23:36:31 +0000 | [diff] [blame] | 77 | #include <mutex> |
| 78 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 79 | using namespace lldb; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | using namespace lldb_private; |
| 81 | using namespace llvm; |
| 82 | using namespace clang; |
| 83 | |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 84 | typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, ClangASTContext*> ClangASTMap; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 85 | |
| 86 | static ClangASTMap & |
| 87 | GetASTMap() |
| 88 | { |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 89 | static ClangASTMap *g_map_ptr = nullptr; |
| 90 | static std::once_flag g_once_flag; |
| 91 | std::call_once(g_once_flag, []() { |
| 92 | g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins |
| 93 | }); |
| 94 | return *g_map_ptr; |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 98 | clang::AccessSpecifier |
| 99 | ClangASTContext::ConvertAccessTypeToAccessSpecifier (AccessType access) |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 100 | { |
| 101 | switch (access) |
| 102 | { |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 103 | default: break; |
| 104 | case eAccessNone: return AS_none; |
| 105 | case eAccessPublic: return AS_public; |
| 106 | case eAccessPrivate: return AS_private; |
| 107 | case eAccessProtected: return AS_protected; |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 108 | } |
| 109 | return AS_none; |
| 110 | } |
| 111 | |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 112 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 113 | static void |
| 114 | ParseLangArgs |
| 115 | ( |
| 116 | LangOptions &Opts, |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 117 | InputKind IK |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | ) |
| 119 | { |
| 120 | // FIXME: Cleanup per-file based stuff. |
| 121 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 122 | // 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] | 123 | // to move these to the language standard, and have the driver resolve the |
| 124 | // input kind + language standard. |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 125 | if (IK == IK_Asm) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 126 | Opts.AsmPreprocessor = 1; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 127 | } else if (IK == IK_ObjC || |
| 128 | IK == IK_ObjCXX || |
| 129 | IK == IK_PreprocessedObjC || |
| 130 | IK == IK_PreprocessedObjCXX) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | Opts.ObjC1 = Opts.ObjC2 = 1; |
| 132 | } |
| 133 | |
| 134 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 135 | |
| 136 | if (LangStd == LangStandard::lang_unspecified) { |
| 137 | // Based on the base language, pick one. |
| 138 | switch (IK) { |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 139 | case IK_None: |
| 140 | case IK_AST: |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 141 | case IK_LLVM_IR: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 142 | assert (!"Invalid input kind!"); |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 143 | case IK_OpenCL: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | LangStd = LangStandard::lang_opencl; |
| 145 | break; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 146 | case IK_CUDA: |
| 147 | LangStd = LangStandard::lang_cuda; |
| 148 | break; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 149 | case IK_Asm: |
| 150 | case IK_C: |
| 151 | case IK_PreprocessedC: |
| 152 | case IK_ObjC: |
| 153 | case IK_PreprocessedObjC: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 154 | LangStd = LangStandard::lang_gnu99; |
| 155 | break; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 156 | case IK_CXX: |
| 157 | case IK_PreprocessedCXX: |
| 158 | case IK_ObjCXX: |
| 159 | case IK_PreprocessedObjCXX: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | LangStd = LangStandard::lang_gnucxx98; |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
Filipe Cabecinhas | e818ca2 | 2012-11-12 21:26:32 +0000 | [diff] [blame] | 166 | Opts.LineComment = Std.hasLineComments(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | Opts.C99 = Std.isC99(); |
| 168 | Opts.CPlusPlus = Std.isCPlusPlus(); |
Chandler Carruth | 38336a1 | 2013-01-02 12:55:00 +0000 | [diff] [blame] | 169 | Opts.CPlusPlus11 = Std.isCPlusPlus11(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 170 | Opts.Digraphs = Std.hasDigraphs(); |
| 171 | Opts.GNUMode = Std.isGNUMode(); |
| 172 | Opts.GNUInline = !Std.isC99(); |
| 173 | Opts.HexFloats = Std.hasHexFloats(); |
| 174 | Opts.ImplicitInt = Std.hasImplicitInt(); |
Enrico Granata | c921e34 | 2013-01-10 02:37:22 +0000 | [diff] [blame] | 175 | |
| 176 | Opts.WChar = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | |
| 178 | // OpenCL has some additional defaults. |
| 179 | if (LangStd == LangStandard::lang_opencl) { |
| 180 | Opts.OpenCL = 1; |
| 181 | Opts.AltiVec = 1; |
| 182 | Opts.CXXOperatorNames = 1; |
| 183 | Opts.LaxVectorConversions = 1; |
| 184 | } |
| 185 | |
| 186 | // OpenCL and C++ both have bool, true, false keywords. |
| 187 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
| 188 | |
| 189 | // if (Opts.CPlusPlus) |
| 190 | // Opts.CXXOperatorNames = !Args.hasArg(OPT_fno_operator_names); |
| 191 | // |
| 192 | // if (Args.hasArg(OPT_fobjc_gc_only)) |
| 193 | // Opts.setGCMode(LangOptions::GCOnly); |
| 194 | // else if (Args.hasArg(OPT_fobjc_gc)) |
| 195 | // Opts.setGCMode(LangOptions::HybridGC); |
| 196 | // |
| 197 | // if (Args.hasArg(OPT_print_ivar_layout)) |
| 198 | // Opts.ObjCGCBitmapPrint = 1; |
| 199 | // |
| 200 | // if (Args.hasArg(OPT_faltivec)) |
| 201 | // Opts.AltiVec = 1; |
| 202 | // |
| 203 | // if (Args.hasArg(OPT_pthread)) |
| 204 | // Opts.POSIXThreads = 1; |
| 205 | // |
| 206 | // llvm::StringRef Vis = getLastArgValue(Args, OPT_fvisibility, |
| 207 | // "default"); |
| 208 | // if (Vis == "default") |
Sean Callanan | 37f76e5 | 2013-02-19 19:16:37 +0000 | [diff] [blame] | 209 | Opts.setValueVisibilityMode(DefaultVisibility); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 210 | // else if (Vis == "hidden") |
| 211 | // Opts.setVisibilityMode(LangOptions::Hidden); |
| 212 | // else if (Vis == "protected") |
| 213 | // Opts.setVisibilityMode(LangOptions::Protected); |
| 214 | // else |
| 215 | // Diags.Report(diag::err_drv_invalid_value) |
| 216 | // << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis; |
| 217 | |
| 218 | // Opts.OverflowChecking = Args.hasArg(OPT_ftrapv); |
| 219 | |
| 220 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 221 | // is specified, or -std is set to a conforming mode. |
| 222 | Opts.Trigraphs = !Opts.GNUMode; |
| 223 | // if (Args.hasArg(OPT_trigraphs)) |
| 224 | // Opts.Trigraphs = 1; |
| 225 | // |
| 226 | // Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, |
| 227 | // OPT_fno_dollars_in_identifiers, |
| 228 | // !Opts.AsmPreprocessor); |
| 229 | // Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); |
| 230 | // Opts.Microsoft = Args.hasArg(OPT_fms_extensions); |
| 231 | // Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); |
| 232 | // if (Args.hasArg(OPT_fno_lax_vector_conversions)) |
| 233 | // Opts.LaxVectorConversions = 0; |
| 234 | // Opts.Exceptions = Args.hasArg(OPT_fexceptions); |
| 235 | // Opts.RTTI = !Args.hasArg(OPT_fno_rtti); |
| 236 | // Opts.Blocks = Args.hasArg(OPT_fblocks); |
| 237 | // Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char); |
| 238 | // Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar); |
| 239 | // Opts.Freestanding = Args.hasArg(OPT_ffreestanding); |
| 240 | // Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; |
| 241 | // Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); |
| 242 | // Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); |
| 243 | // Opts.AccessControl = Args.hasArg(OPT_faccess_control); |
| 244 | // Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); |
| 245 | // Opts.MathErrno = !Args.hasArg(OPT_fno_math_errno); |
| 246 | // Opts.InstantiationDepth = getLastArgIntValue(Args, OPT_ftemplate_depth, 99, |
| 247 | // Diags); |
| 248 | // Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime); |
| 249 | // Opts.ObjCConstantStringClass = getLastArgValue(Args, |
| 250 | // OPT_fconstant_string_class); |
| 251 | // Opts.ObjCNonFragileABI = Args.hasArg(OPT_fobjc_nonfragile_abi); |
| 252 | // Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior); |
| 253 | // Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); |
| 254 | // Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); |
| 255 | // Opts.Static = Args.hasArg(OPT_static_define); |
| 256 | Opts.OptimizeSize = 0; |
| 257 | |
| 258 | // FIXME: Eliminate this dependency. |
| 259 | // unsigned Opt = |
| 260 | // Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags); |
| 261 | // Opts.Optimize = Opt != 0; |
| 262 | unsigned Opt = 0; |
| 263 | |
| 264 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 265 | // optimization level and -fno-inline, not actually whether the backend has |
| 266 | // inlining enabled. |
| 267 | // |
| 268 | // FIXME: This is affected by other options (-fno-inline). |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 269 | Opts.NoInlineDefine = !Opt; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 270 | |
| 271 | // unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags); |
| 272 | // switch (SSP) { |
| 273 | // default: |
| 274 | // Diags.Report(diag::err_drv_invalid_value) |
| 275 | // << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; |
| 276 | // break; |
| 277 | // case 0: Opts.setStackProtectorMode(LangOptions::SSPOff); break; |
| 278 | // case 1: Opts.setStackProtectorMode(LangOptions::SSPOn); break; |
| 279 | // case 2: Opts.setStackProtectorMode(LangOptions::SSPReq); break; |
| 280 | // } |
| 281 | } |
| 282 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 284 | ClangASTContext::ClangASTContext (const char *target_triple) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | m_target_triple(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 286 | m_ast_ap(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 287 | m_language_options_ap(), |
| 288 | m_source_manager_ap(), |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 289 | m_diagnostics_engine_ap(), |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 290 | m_target_options_rp(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 291 | m_target_info_ap(), |
| 292 | m_identifier_table_ap(), |
| 293 | m_selector_table_ap(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 294 | m_builtins_ap(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 295 | m_callback_tag_decl (nullptr), |
| 296 | m_callback_objc_decl (nullptr), |
| 297 | m_callback_baton (nullptr), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 298 | m_pointer_byte_size (0) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 299 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 300 | { |
| 301 | if (target_triple && target_triple[0]) |
Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 302 | SetTargetTriple (target_triple); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | //---------------------------------------------------------------------- |
| 306 | // Destructor |
| 307 | //---------------------------------------------------------------------- |
| 308 | ClangASTContext::~ClangASTContext() |
| 309 | { |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 310 | if (m_ast_ap.get()) |
| 311 | { |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 312 | GetASTMap().Erase(m_ast_ap.get()); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 315 | m_builtins_ap.reset(); |
| 316 | m_selector_table_ap.reset(); |
| 317 | m_identifier_table_ap.reset(); |
| 318 | m_target_info_ap.reset(); |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 319 | m_target_options_rp.reset(); |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 320 | m_diagnostics_engine_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 321 | m_source_manager_ap.reset(); |
| 322 | m_language_options_ap.reset(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 323 | m_ast_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | |
| 327 | void |
| 328 | ClangASTContext::Clear() |
| 329 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 330 | m_ast_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 331 | m_language_options_ap.reset(); |
| 332 | m_source_manager_ap.reset(); |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 333 | m_diagnostics_engine_ap.reset(); |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 334 | m_target_options_rp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | m_target_info_ap.reset(); |
| 336 | m_identifier_table_ap.reset(); |
| 337 | m_selector_table_ap.reset(); |
| 338 | m_builtins_ap.reset(); |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 339 | m_pointer_byte_size = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | const char * |
| 343 | ClangASTContext::GetTargetTriple () |
| 344 | { |
| 345 | return m_target_triple.c_str(); |
| 346 | } |
| 347 | |
| 348 | void |
| 349 | ClangASTContext::SetTargetTriple (const char *target_triple) |
| 350 | { |
| 351 | Clear(); |
| 352 | m_target_triple.assign(target_triple); |
| 353 | } |
| 354 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 355 | void |
| 356 | ClangASTContext::SetArchitecture (const ArchSpec &arch) |
| 357 | { |
Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 358 | SetTargetTriple(arch.GetTriple().str().c_str()); |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 361 | bool |
| 362 | ClangASTContext::HasExternalSource () |
| 363 | { |
| 364 | ASTContext *ast = getASTContext(); |
| 365 | if (ast) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 366 | return ast->getExternalSource () != nullptr; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 367 | return false; |
| 368 | } |
| 369 | |
| 370 | void |
Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 371 | ClangASTContext::SetExternalSource (llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_ap) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 372 | { |
| 373 | ASTContext *ast = getASTContext(); |
| 374 | if (ast) |
| 375 | { |
| 376 | ast->setExternalSource (ast_source_ap); |
| 377 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true); |
| 378 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(true); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | void |
| 383 | ClangASTContext::RemoveExternalSource () |
| 384 | { |
| 385 | ASTContext *ast = getASTContext(); |
| 386 | |
| 387 | if (ast) |
| 388 | { |
Todd Fiala | 955fe6f | 2014-02-27 17:18:23 +0000 | [diff] [blame] | 389 | llvm::IntrusiveRefCntPtr<ExternalASTSource> empty_ast_source_ap; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 390 | ast->setExternalSource (empty_ast_source_ap); |
| 391 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(false); |
| 392 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(false); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | |
| 398 | ASTContext * |
| 399 | ClangASTContext::getASTContext() |
| 400 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 401 | if (m_ast_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 402 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 403 | m_ast_ap.reset(new ASTContext (*getLanguageOptions(), |
| 404 | *getSourceManager(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 405 | *getIdentifierTable(), |
| 406 | *getSelectorTable(), |
Alp Toker | cf55e88 | 2014-05-03 15:05:45 +0000 | [diff] [blame] | 407 | *getBuiltinContext())); |
| 408 | m_ast_ap->InitBuiltinTypes(*getTargetInfo()); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 409 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 410 | if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton) |
| 411 | { |
| 412 | m_ast_ap->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
| 413 | //m_ast_ap->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 414 | } |
| 415 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 416 | m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 417 | |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 418 | GetASTMap().Insert(m_ast_ap.get(), this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 419 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 420 | return m_ast_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 423 | ClangASTContext* |
| 424 | ClangASTContext::GetASTContext (clang::ASTContext* ast) |
| 425 | { |
Enrico Granata | 2267ad4 | 2014-09-16 17:28:40 +0000 | [diff] [blame] | 426 | ClangASTContext *clang_ast = GetASTMap().Lookup(ast); |
Enrico Granata | 5d84a69 | 2014-08-19 21:46:37 +0000 | [diff] [blame] | 427 | return clang_ast; |
| 428 | } |
| 429 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 430 | Builtin::Context * |
| 431 | ClangASTContext::getBuiltinContext() |
| 432 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 433 | if (m_builtins_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 434 | m_builtins_ap.reset (new Builtin::Context()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | return m_builtins_ap.get(); |
| 436 | } |
| 437 | |
| 438 | IdentifierTable * |
| 439 | ClangASTContext::getIdentifierTable() |
| 440 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 441 | if (m_identifier_table_ap.get() == nullptr) |
| 442 | m_identifier_table_ap.reset(new IdentifierTable (*ClangASTContext::getLanguageOptions(), nullptr)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 443 | return m_identifier_table_ap.get(); |
| 444 | } |
| 445 | |
| 446 | LangOptions * |
| 447 | ClangASTContext::getLanguageOptions() |
| 448 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 449 | if (m_language_options_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 450 | { |
| 451 | m_language_options_ap.reset(new LangOptions()); |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 452 | ParseLangArgs(*m_language_options_ap, IK_ObjCXX); |
| 453 | // InitializeLangOptions(*m_language_options_ap, IK_ObjCXX); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | } |
| 455 | return m_language_options_ap.get(); |
| 456 | } |
| 457 | |
| 458 | SelectorTable * |
| 459 | ClangASTContext::getSelectorTable() |
| 460 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 461 | if (m_selector_table_ap.get() == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 462 | m_selector_table_ap.reset (new SelectorTable()); |
| 463 | return m_selector_table_ap.get(); |
| 464 | } |
| 465 | |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 466 | clang::FileManager * |
| 467 | ClangASTContext::getFileManager() |
| 468 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 469 | if (m_file_manager_ap.get() == nullptr) |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 470 | { |
| 471 | clang::FileSystemOptions file_system_options; |
| 472 | m_file_manager_ap.reset(new clang::FileManager(file_system_options)); |
| 473 | } |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 474 | return m_file_manager_ap.get(); |
| 475 | } |
| 476 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 477 | clang::SourceManager * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 478 | ClangASTContext::getSourceManager() |
| 479 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 480 | if (m_source_manager_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 481 | m_source_manager_ap.reset(new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 482 | return m_source_manager_ap.get(); |
| 483 | } |
| 484 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 485 | clang::DiagnosticsEngine * |
| 486 | ClangASTContext::getDiagnosticsEngine() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 488 | if (m_diagnostics_engine_ap.get() == nullptr) |
Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 489 | { |
| 490 | llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs()); |
Sean Callanan | ec8f1ef | 2012-10-25 01:00:25 +0000 | [diff] [blame] | 491 | m_diagnostics_engine_ap.reset(new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions())); |
Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 492 | } |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 493 | return m_diagnostics_engine_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 496 | class NullDiagnosticConsumer : public DiagnosticConsumer |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 497 | { |
| 498 | public: |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 499 | NullDiagnosticConsumer () |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 500 | { |
| 501 | m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 502 | } |
| 503 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 504 | void HandleDiagnostic (DiagnosticsEngine::Level DiagLevel, const Diagnostic &info) |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 505 | { |
| 506 | if (m_log) |
| 507 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 508 | llvm::SmallVector<char, 32> diag_str(10); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 509 | info.FormatDiagnostic(diag_str); |
| 510 | diag_str.push_back('\0'); |
| 511 | m_log->Printf("Compiler diagnostic: %s\n", diag_str.data()); |
| 512 | } |
| 513 | } |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 514 | |
| 515 | DiagnosticConsumer *clone (DiagnosticsEngine &Diags) const |
| 516 | { |
| 517 | return new NullDiagnosticConsumer (); |
| 518 | } |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 519 | private: |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 520 | Log * m_log; |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 521 | }; |
| 522 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 523 | DiagnosticConsumer * |
| 524 | ClangASTContext::getDiagnosticConsumer() |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 525 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 526 | if (m_diagnostic_consumer_ap.get() == nullptr) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 527 | m_diagnostic_consumer_ap.reset(new NullDiagnosticConsumer); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 528 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 529 | return m_diagnostic_consumer_ap.get(); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Jason Molenda | 45938b9 | 2014-07-08 23:46:39 +0000 | [diff] [blame] | 532 | std::shared_ptr<TargetOptions> & |
| 533 | ClangASTContext::getTargetOptions() { |
Alp Toker | edc902f | 2014-07-05 03:06:05 +0000 | [diff] [blame] | 534 | if (m_target_options_rp.get() == nullptr && !m_target_triple.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 535 | { |
Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 536 | m_target_options_rp = std::make_shared<TargetOptions>(); |
Alp Toker | edc902f | 2014-07-05 03:06:05 +0000 | [diff] [blame] | 537 | if (m_target_options_rp.get() != nullptr) |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 538 | m_target_options_rp->Triple = m_target_triple; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 539 | } |
Alp Toker | 5f83864 | 2014-07-06 05:36:57 +0000 | [diff] [blame] | 540 | return m_target_options_rp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | |
| 544 | TargetInfo * |
| 545 | ClangASTContext::getTargetInfo() |
| 546 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 547 | // target_triple should be something like "x86_64-apple-macosx" |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 548 | if (m_target_info_ap.get() == nullptr && !m_target_triple.empty()) |
Greg Clayton | 38d880a | 2012-11-16 21:35:22 +0000 | [diff] [blame] | 549 | m_target_info_ap.reset (TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(), getTargetOptions())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | return m_target_info_ap.get(); |
| 551 | } |
| 552 | |
| 553 | #pragma mark Basic Types |
| 554 | |
| 555 | static inline bool |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 556 | QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext *ast, QualType qual_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 557 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 558 | uint64_t qual_type_bit_size = ast->getTypeSize(qual_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 559 | if (qual_type_bit_size == bit_size) |
| 560 | return true; |
| 561 | return false; |
| 562 | } |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 563 | ClangASTType |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 564 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (Encoding encoding, uint32_t bit_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 565 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 566 | return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (getASTContext(), encoding, bit_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 569 | ClangASTType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 570 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (ASTContext *ast, Encoding encoding, uint32_t bit_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 571 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 572 | if (!ast) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 573 | return ClangASTType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 574 | |
| 575 | switch (encoding) |
| 576 | { |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 577 | case eEncodingInvalid: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 578 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 579 | return ClangASTType (ast, ast->VoidPtrTy.getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 580 | break; |
| 581 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 582 | case eEncodingUint: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 583 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 584 | return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 585 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 586 | return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 587 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 588 | return ClangASTType (ast, ast->UnsignedIntTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 589 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 590 | return ClangASTType (ast, ast->UnsignedLongTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 591 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 592 | return ClangASTType (ast, ast->UnsignedLongLongTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 593 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 594 | return ClangASTType (ast, ast->UnsignedInt128Ty.getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 595 | break; |
| 596 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 597 | case eEncodingSint: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 598 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 599 | return ClangASTType (ast, ast->CharTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 600 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 601 | return ClangASTType (ast, ast->ShortTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 602 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 603 | return ClangASTType (ast, ast->IntTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 604 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 605 | return ClangASTType (ast, ast->LongTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 606 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 607 | return ClangASTType (ast, ast->LongLongTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 608 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 609 | return ClangASTType (ast, ast->Int128Ty.getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 610 | break; |
| 611 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 612 | case eEncodingIEEE754: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 613 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 614 | return ClangASTType (ast, ast->FloatTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 615 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 616 | return ClangASTType (ast, ast->DoubleTy.getAsOpaquePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 617 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 618 | return ClangASTType (ast, ast->LongDoubleTy.getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 619 | break; |
| 620 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 621 | case eEncodingVector: |
Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 622 | // Sanity check that bit_size is a multiple of 8's. |
| 623 | if (bit_size && !(bit_size & 0x7u)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 624 | return ClangASTType (ast, ast->getExtVectorType (ast->UnsignedCharTy, bit_size/8).getAsOpaquePtr()); |
Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 625 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 628 | return ClangASTType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 629 | } |
| 630 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 631 | |
| 632 | |
| 633 | lldb::BasicType |
| 634 | ClangASTContext::GetBasicTypeEnumeration (const ConstString &name) |
| 635 | { |
| 636 | if (name) |
| 637 | { |
| 638 | typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; |
| 639 | static TypeNameToBasicTypeMap g_type_map; |
| 640 | static std::once_flag g_once_flag; |
| 641 | std::call_once(g_once_flag, [](){ |
| 642 | // "void" |
| 643 | g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); |
| 644 | |
| 645 | // "char" |
| 646 | g_type_map.Append(ConstString("char").GetCString(), eBasicTypeChar); |
| 647 | g_type_map.Append(ConstString("signed char").GetCString(), eBasicTypeSignedChar); |
| 648 | g_type_map.Append(ConstString("unsigned char").GetCString(), eBasicTypeUnsignedChar); |
| 649 | g_type_map.Append(ConstString("wchar_t").GetCString(), eBasicTypeWChar); |
| 650 | g_type_map.Append(ConstString("signed wchar_t").GetCString(), eBasicTypeSignedWChar); |
| 651 | g_type_map.Append(ConstString("unsigned wchar_t").GetCString(), eBasicTypeUnsignedWChar); |
| 652 | // "short" |
| 653 | g_type_map.Append(ConstString("short").GetCString(), eBasicTypeShort); |
| 654 | g_type_map.Append(ConstString("short int").GetCString(), eBasicTypeShort); |
| 655 | g_type_map.Append(ConstString("unsigned short").GetCString(), eBasicTypeUnsignedShort); |
| 656 | g_type_map.Append(ConstString("unsigned short int").GetCString(), eBasicTypeUnsignedShort); |
| 657 | |
| 658 | // "int" |
| 659 | g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); |
| 660 | g_type_map.Append(ConstString("signed int").GetCString(), eBasicTypeInt); |
| 661 | g_type_map.Append(ConstString("unsigned int").GetCString(), eBasicTypeUnsignedInt); |
| 662 | g_type_map.Append(ConstString("unsigned").GetCString(), eBasicTypeUnsignedInt); |
| 663 | |
| 664 | // "long" |
| 665 | g_type_map.Append(ConstString("long").GetCString(), eBasicTypeLong); |
| 666 | g_type_map.Append(ConstString("long int").GetCString(), eBasicTypeLong); |
| 667 | g_type_map.Append(ConstString("unsigned long").GetCString(), eBasicTypeUnsignedLong); |
| 668 | g_type_map.Append(ConstString("unsigned long int").GetCString(), eBasicTypeUnsignedLong); |
| 669 | |
| 670 | // "long long" |
| 671 | g_type_map.Append(ConstString("long long").GetCString(), eBasicTypeLongLong); |
| 672 | g_type_map.Append(ConstString("long long int").GetCString(), eBasicTypeLongLong); |
| 673 | g_type_map.Append(ConstString("unsigned long long").GetCString(), eBasicTypeUnsignedLongLong); |
| 674 | g_type_map.Append(ConstString("unsigned long long int").GetCString(), eBasicTypeUnsignedLongLong); |
| 675 | |
| 676 | // "int128" |
| 677 | g_type_map.Append(ConstString("__int128_t").GetCString(), eBasicTypeInt128); |
| 678 | g_type_map.Append(ConstString("__uint128_t").GetCString(), eBasicTypeUnsignedInt128); |
| 679 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 680 | // Miscellaneous |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 681 | g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); |
| 682 | g_type_map.Append(ConstString("float").GetCString(), eBasicTypeFloat); |
| 683 | g_type_map.Append(ConstString("double").GetCString(), eBasicTypeDouble); |
| 684 | g_type_map.Append(ConstString("long double").GetCString(), eBasicTypeLongDouble); |
| 685 | g_type_map.Append(ConstString("id").GetCString(), eBasicTypeObjCID); |
| 686 | g_type_map.Append(ConstString("SEL").GetCString(), eBasicTypeObjCSel); |
| 687 | g_type_map.Append(ConstString("nullptr").GetCString(), eBasicTypeNullPtr); |
| 688 | g_type_map.Sort(); |
| 689 | }); |
| 690 | |
| 691 | return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); |
| 692 | } |
| 693 | return eBasicTypeInvalid; |
| 694 | } |
| 695 | |
| 696 | ClangASTType |
| 697 | ClangASTContext::GetBasicType (ASTContext *ast, const ConstString &name) |
| 698 | { |
| 699 | if (ast) |
| 700 | { |
| 701 | lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration (name); |
| 702 | return ClangASTContext::GetBasicType (ast, basic_type); |
| 703 | } |
| 704 | return ClangASTType(); |
| 705 | } |
| 706 | |
| 707 | uint32_t |
| 708 | ClangASTContext::GetPointerByteSize () |
| 709 | { |
| 710 | if (m_pointer_byte_size == 0) |
| 711 | m_pointer_byte_size = GetBasicType(lldb::eBasicTypeVoid).GetPointerType().GetByteSize(); |
| 712 | return m_pointer_byte_size; |
| 713 | } |
| 714 | |
| 715 | ClangASTType |
| 716 | ClangASTContext::GetBasicType (lldb::BasicType basic_type) |
| 717 | { |
| 718 | return GetBasicType (getASTContext(), basic_type); |
| 719 | } |
| 720 | |
| 721 | ClangASTType |
| 722 | ClangASTContext::GetBasicType (ASTContext *ast, lldb::BasicType basic_type) |
| 723 | { |
| 724 | if (ast) |
| 725 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 726 | clang_type_t clang_type = nullptr; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 727 | |
| 728 | switch (basic_type) |
| 729 | { |
| 730 | case eBasicTypeInvalid: |
| 731 | case eBasicTypeOther: |
| 732 | break; |
| 733 | case eBasicTypeVoid: |
| 734 | clang_type = ast->VoidTy.getAsOpaquePtr(); |
| 735 | break; |
| 736 | case eBasicTypeChar: |
| 737 | clang_type = ast->CharTy.getAsOpaquePtr(); |
| 738 | break; |
| 739 | case eBasicTypeSignedChar: |
| 740 | clang_type = ast->SignedCharTy.getAsOpaquePtr(); |
| 741 | break; |
| 742 | case eBasicTypeUnsignedChar: |
| 743 | clang_type = ast->UnsignedCharTy.getAsOpaquePtr(); |
| 744 | break; |
| 745 | case eBasicTypeWChar: |
| 746 | clang_type = ast->getWCharType().getAsOpaquePtr(); |
| 747 | break; |
| 748 | case eBasicTypeSignedWChar: |
| 749 | clang_type = ast->getSignedWCharType().getAsOpaquePtr(); |
| 750 | break; |
| 751 | case eBasicTypeUnsignedWChar: |
| 752 | clang_type = ast->getUnsignedWCharType().getAsOpaquePtr(); |
| 753 | break; |
| 754 | case eBasicTypeChar16: |
| 755 | clang_type = ast->Char16Ty.getAsOpaquePtr(); |
| 756 | break; |
| 757 | case eBasicTypeChar32: |
| 758 | clang_type = ast->Char32Ty.getAsOpaquePtr(); |
| 759 | break; |
| 760 | case eBasicTypeShort: |
| 761 | clang_type = ast->ShortTy.getAsOpaquePtr(); |
| 762 | break; |
| 763 | case eBasicTypeUnsignedShort: |
| 764 | clang_type = ast->UnsignedShortTy.getAsOpaquePtr(); |
| 765 | break; |
| 766 | case eBasicTypeInt: |
| 767 | clang_type = ast->IntTy.getAsOpaquePtr(); |
| 768 | break; |
| 769 | case eBasicTypeUnsignedInt: |
| 770 | clang_type = ast->UnsignedIntTy.getAsOpaquePtr(); |
| 771 | break; |
| 772 | case eBasicTypeLong: |
| 773 | clang_type = ast->LongTy.getAsOpaquePtr(); |
| 774 | break; |
| 775 | case eBasicTypeUnsignedLong: |
| 776 | clang_type = ast->UnsignedLongTy.getAsOpaquePtr(); |
| 777 | break; |
| 778 | case eBasicTypeLongLong: |
| 779 | clang_type = ast->LongLongTy.getAsOpaquePtr(); |
| 780 | break; |
| 781 | case eBasicTypeUnsignedLongLong: |
| 782 | clang_type = ast->UnsignedLongLongTy.getAsOpaquePtr(); |
| 783 | break; |
| 784 | case eBasicTypeInt128: |
| 785 | clang_type = ast->Int128Ty.getAsOpaquePtr(); |
| 786 | break; |
| 787 | case eBasicTypeUnsignedInt128: |
| 788 | clang_type = ast->UnsignedInt128Ty.getAsOpaquePtr(); |
| 789 | break; |
| 790 | case eBasicTypeBool: |
| 791 | clang_type = ast->BoolTy.getAsOpaquePtr(); |
| 792 | break; |
| 793 | case eBasicTypeHalf: |
| 794 | clang_type = ast->HalfTy.getAsOpaquePtr(); |
| 795 | break; |
| 796 | case eBasicTypeFloat: |
| 797 | clang_type = ast->FloatTy.getAsOpaquePtr(); |
| 798 | break; |
| 799 | case eBasicTypeDouble: |
| 800 | clang_type = ast->DoubleTy.getAsOpaquePtr(); |
| 801 | break; |
| 802 | case eBasicTypeLongDouble: |
| 803 | clang_type = ast->LongDoubleTy.getAsOpaquePtr(); |
| 804 | break; |
| 805 | case eBasicTypeFloatComplex: |
| 806 | clang_type = ast->FloatComplexTy.getAsOpaquePtr(); |
| 807 | break; |
| 808 | case eBasicTypeDoubleComplex: |
| 809 | clang_type = ast->DoubleComplexTy.getAsOpaquePtr(); |
| 810 | break; |
| 811 | case eBasicTypeLongDoubleComplex: |
| 812 | clang_type = ast->LongDoubleComplexTy.getAsOpaquePtr(); |
| 813 | break; |
| 814 | case eBasicTypeObjCID: |
| 815 | clang_type = ast->getObjCIdType().getAsOpaquePtr(); |
| 816 | break; |
| 817 | case eBasicTypeObjCClass: |
| 818 | clang_type = ast->getObjCClassType().getAsOpaquePtr(); |
| 819 | break; |
| 820 | case eBasicTypeObjCSel: |
| 821 | clang_type = ast->getObjCSelType().getAsOpaquePtr(); |
| 822 | break; |
| 823 | case eBasicTypeNullPtr: |
| 824 | clang_type = ast->NullPtrTy.getAsOpaquePtr(); |
| 825 | break; |
| 826 | } |
| 827 | |
| 828 | if (clang_type) |
| 829 | return ClangASTType (ast, clang_type); |
| 830 | } |
| 831 | return ClangASTType(); |
| 832 | } |
| 833 | |
| 834 | |
| 835 | ClangASTType |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 836 | ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name, uint32_t dw_ate, uint32_t bit_size) |
| 837 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 838 | ASTContext *ast = getASTContext(); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 839 | |
| 840 | #define streq(a,b) strcmp(a,b) == 0 |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 841 | assert (ast != nullptr); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 842 | if (ast) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 843 | { |
| 844 | switch (dw_ate) |
| 845 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 846 | default: |
| 847 | break; |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 848 | |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 849 | case DW_ATE_address: |
| 850 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 851 | return ClangASTType (ast, ast->VoidPtrTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 852 | break; |
| 853 | |
| 854 | case DW_ATE_boolean: |
| 855 | if (QualTypeMatchesBitSize (bit_size, ast, ast->BoolTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 856 | return ClangASTType (ast, ast->BoolTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 857 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 858 | return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 859 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 860 | return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 861 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 862 | return ClangASTType (ast, ast->UnsignedIntTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 863 | break; |
| 864 | |
| 865 | case DW_ATE_lo_user: |
| 866 | // This has been seen to mean DW_AT_complex_integer |
| 867 | if (type_name) |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 868 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 869 | if (::strstr(type_name, "complex")) |
| 870 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 871 | ClangASTType complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("int", DW_ATE_signed, bit_size/2); |
| 872 | return ClangASTType (ast, ast->getComplexType (complex_int_clang_type.GetQualType()).getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 873 | } |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 874 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case DW_ATE_complex_float: |
| 878 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatComplexTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 879 | return ClangASTType (ast, ast->FloatComplexTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 880 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleComplexTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 881 | return ClangASTType (ast, ast->DoubleComplexTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 882 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleComplexTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 883 | return ClangASTType (ast, ast->LongDoubleComplexTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 884 | else |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 885 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 886 | ClangASTType complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("float", DW_ATE_float, bit_size/2); |
| 887 | return ClangASTType (ast, ast->getComplexType (complex_float_clang_type.GetQualType()).getAsOpaquePtr()); |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 888 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case DW_ATE_float: |
Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame^] | 892 | if (streq(type_name, "float") && QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
| 893 | return ClangASTType (ast, ast->FloatTy.getAsOpaquePtr()); |
| 894 | if (streq(type_name, "double") && QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
| 895 | return ClangASTType (ast, ast->DoubleTy.getAsOpaquePtr()); |
| 896 | if (streq(type_name, "long double") && QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
| 897 | return ClangASTType (ast, ast->LongDoubleTy.getAsOpaquePtr()); |
| 898 | // Fall back to not requring a name match |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 899 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 900 | return ClangASTType (ast, ast->FloatTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 901 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 902 | return ClangASTType (ast, ast->DoubleTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 903 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 904 | return ClangASTType (ast, ast->LongDoubleTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 905 | break; |
| 906 | |
| 907 | case DW_ATE_signed: |
| 908 | if (type_name) |
| 909 | { |
| 910 | if (streq(type_name, "wchar_t") && |
| 911 | QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 912 | return ClangASTType (ast, ast->WCharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 913 | if (streq(type_name, "void") && |
| 914 | QualTypeMatchesBitSize (bit_size, ast, ast->VoidTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 915 | return ClangASTType (ast, ast->VoidTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 916 | if (strstr(type_name, "long long") && |
| 917 | QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 918 | return ClangASTType (ast, ast->LongLongTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 919 | if (strstr(type_name, "long") && |
| 920 | QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 921 | return ClangASTType (ast, ast->LongTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 922 | if (strstr(type_name, "short") && |
| 923 | QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 924 | return ClangASTType (ast, ast->ShortTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 925 | if (strstr(type_name, "char")) |
| 926 | { |
| 927 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 928 | return ClangASTType (ast, ast->CharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 929 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 930 | return ClangASTType (ast, ast->SignedCharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 931 | } |
| 932 | if (strstr(type_name, "int")) |
| 933 | { |
| 934 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 935 | return ClangASTType (ast, ast->IntTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 936 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 937 | return ClangASTType (ast, ast->Int128Ty.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | // We weren't able to match up a type name, just search by size |
| 941 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 942 | return ClangASTType (ast, ast->CharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 943 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 944 | return ClangASTType (ast, ast->ShortTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 945 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 946 | return ClangASTType (ast, ast->IntTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 947 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 948 | return ClangASTType (ast, ast->LongTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 949 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 950 | return ClangASTType (ast, ast->LongLongTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 951 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 952 | return ClangASTType (ast, ast->Int128Ty.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 953 | break; |
| 954 | |
| 955 | case DW_ATE_signed_char: |
| 956 | if (type_name) |
| 957 | { |
| 958 | if (streq(type_name, "signed char")) |
| 959 | { |
| 960 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 961 | return ClangASTType (ast, ast->SignedCharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 965 | return ClangASTType (ast, ast->CharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 966 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 967 | return ClangASTType (ast, ast->SignedCharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 968 | break; |
| 969 | |
| 970 | case DW_ATE_unsigned: |
| 971 | if (type_name) |
| 972 | { |
| 973 | if (strstr(type_name, "long long")) |
| 974 | { |
| 975 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 976 | return ClangASTType (ast, ast->UnsignedLongLongTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 977 | } |
| 978 | else if (strstr(type_name, "long")) |
| 979 | { |
| 980 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 981 | return ClangASTType (ast, ast->UnsignedLongTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 982 | } |
| 983 | else if (strstr(type_name, "short")) |
| 984 | { |
| 985 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 986 | return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 987 | } |
| 988 | else if (strstr(type_name, "char")) |
| 989 | { |
| 990 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 991 | return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 992 | } |
| 993 | else if (strstr(type_name, "int")) |
| 994 | { |
| 995 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 996 | return ClangASTType (ast, ast->UnsignedIntTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 997 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 998 | return ClangASTType (ast, ast->UnsignedInt128Ty.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | // We weren't able to match up a type name, just search by size |
| 1002 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1003 | return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1004 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1005 | return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1006 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1007 | return ClangASTType (ast, ast->UnsignedIntTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1008 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1009 | return ClangASTType (ast, ast->UnsignedLongTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1010 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1011 | return ClangASTType (ast, ast->UnsignedLongLongTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1012 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1013 | return ClangASTType (ast, ast->UnsignedInt128Ty.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1014 | break; |
| 1015 | |
| 1016 | case DW_ATE_unsigned_char: |
| 1017 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1018 | return ClangASTType (ast, ast->UnsignedCharTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1019 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1020 | return ClangASTType (ast, ast->UnsignedShortTy.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1021 | break; |
| 1022 | |
| 1023 | case DW_ATE_imaginary_float: |
| 1024 | break; |
| 1025 | |
| 1026 | case DW_ATE_UTF: |
| 1027 | if (type_name) |
| 1028 | { |
| 1029 | if (streq(type_name, "char16_t")) |
| 1030 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1031 | return ClangASTType (ast, ast->Char16Ty.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1032 | } |
| 1033 | else if (streq(type_name, "char32_t")) |
| 1034 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1035 | return ClangASTType (ast, ast->Char32Ty.getAsOpaquePtr()); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | } |
| 1040 | } |
| 1041 | // This assert should fire for anything that we don't catch above so we know |
| 1042 | // to fix any issues we run into. |
Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 1043 | if (type_name) |
| 1044 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1045 | 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] | 1046 | } |
| 1047 | else |
| 1048 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 1049 | 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] | 1050 | } |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1051 | return ClangASTType (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1054 | ClangASTType |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1055 | ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast) |
| 1056 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1057 | if (ast) |
| 1058 | return ClangASTType (ast, ast->UnknownAnyTy.getAsOpaquePtr()); |
| 1059 | return ClangASTType(); |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1062 | ClangASTType |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1063 | ClangASTContext::GetCStringType (bool is_const) |
| 1064 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1065 | ASTContext *ast = getASTContext(); |
| 1066 | QualType char_type(ast->CharTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1067 | |
| 1068 | if (is_const) |
| 1069 | char_type.addConst(); |
| 1070 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1071 | return ClangASTType (ast, ast->getPointerType(char_type).getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 1074 | clang::DeclContext * |
| 1075 | ClangASTContext::GetTranslationUnitDecl (clang::ASTContext *ast) |
| 1076 | { |
| 1077 | return ast->getTranslationUnitDecl(); |
| 1078 | } |
| 1079 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1080 | ClangASTType |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1081 | ClangASTContext::CopyType (ASTContext *dst_ast, |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1082 | ClangASTType src) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1083 | { |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 1084 | FileSystemOptions file_system_options; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1085 | ASTContext *src_ast = src.GetASTContext(); |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1086 | FileManager file_manager (file_system_options); |
| 1087 | ASTImporter importer(*dst_ast, file_manager, |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1088 | *src_ast, file_manager, |
| 1089 | false); |
Sean Callanan | 0617fcb | 2010-11-09 22:37:10 +0000 | [diff] [blame] | 1090 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1091 | QualType dst (importer.Import(src.GetQualType())); |
Sean Callanan | 0617fcb | 2010-11-09 22:37:10 +0000 | [diff] [blame] | 1092 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1093 | return ClangASTType (dst_ast, dst.getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1096 | |
| 1097 | clang::Decl * |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1098 | ClangASTContext::CopyDecl (ASTContext *dst_ast, |
| 1099 | ASTContext *src_ast, |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1100 | clang::Decl *source_decl) |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 1101 | { |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 1102 | FileSystemOptions file_system_options; |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1103 | FileManager file_manager (file_system_options); |
| 1104 | ASTImporter importer(*dst_ast, file_manager, |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1105 | *src_ast, file_manager, |
| 1106 | false); |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1107 | |
| 1108 | return importer.Import(source_decl); |
| 1109 | } |
| 1110 | |
Sean Callanan | 23a3027 | 2010-07-16 00:00:27 +0000 | [diff] [blame] | 1111 | bool |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1112 | ClangASTContext::AreTypesSame (ClangASTType type1, |
| 1113 | ClangASTType type2, |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1114 | bool ignore_qualifiers) |
Sean Callanan | 4dcca262 | 2010-07-15 22:30:52 +0000 | [diff] [blame] | 1115 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1116 | ASTContext *ast = type1.GetASTContext(); |
| 1117 | if (ast != type2.GetASTContext()) |
| 1118 | return false; |
| 1119 | |
| 1120 | if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType()) |
Greg Clayton | 55995eb | 2012-04-06 17:38:55 +0000 | [diff] [blame] | 1121 | return true; |
| 1122 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1123 | QualType type1_qual = type1.GetQualType(); |
| 1124 | QualType type2_qual = type2.GetQualType(); |
Sean Callanan | 5056ab0 | 2012-02-18 02:01:03 +0000 | [diff] [blame] | 1125 | |
| 1126 | if (ignore_qualifiers) |
| 1127 | { |
| 1128 | type1_qual = type1_qual.getUnqualifiedType(); |
| 1129 | type2_qual = type2_qual.getUnqualifiedType(); |
| 1130 | } |
| 1131 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1132 | return ast->hasSameType (type1_qual, type2_qual); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1135 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1136 | ClangASTType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1137 | ClangASTContext::GetTypeForDecl (TagDecl *decl) |
| 1138 | { |
| 1139 | // No need to call the getASTContext() accessor (which can create the AST |
| 1140 | // if it isn't created yet, because we can't have created a decl in this |
| 1141 | // AST if our AST didn't already exist... |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1142 | ASTContext *ast = m_ast_ap.get(); |
| 1143 | if (ast) |
| 1144 | return ClangASTType (ast, ast->getTagDeclType(decl).getAsOpaquePtr()); |
| 1145 | return ClangASTType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1148 | ClangASTType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1149 | ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl) |
| 1150 | { |
| 1151 | // No need to call the getASTContext() accessor (which can create the AST |
| 1152 | // if it isn't created yet, because we can't have created a decl in this |
| 1153 | // AST if our AST didn't already exist... |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1154 | ASTContext *ast = m_ast_ap.get(); |
| 1155 | if (ast) |
| 1156 | return ClangASTType (ast, ast->getObjCInterfaceType(decl).getAsOpaquePtr()); |
| 1157 | return ClangASTType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1160 | #pragma mark Structure, Unions, Classes |
| 1161 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1162 | ClangASTType |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1163 | ClangASTContext::CreateRecordType (DeclContext *decl_ctx, |
| 1164 | AccessType access_type, |
| 1165 | const char *name, |
| 1166 | int kind, |
| 1167 | LanguageType language, |
| 1168 | ClangASTMetadata *metadata) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1170 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1171 | assert (ast != nullptr); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1172 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1173 | if (decl_ctx == nullptr) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1174 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1176 | |
Greg Clayton | e1be996 | 2011-08-24 23:50:00 +0000 | [diff] [blame] | 1177 | if (language == eLanguageTypeObjC || language == eLanguageTypeObjC_plus_plus) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1178 | { |
Greg Clayton | aaf99e0 | 2010-10-11 02:25:34 +0000 | [diff] [blame] | 1179 | bool isForwardDecl = true; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1180 | bool isInternal = false; |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1181 | return CreateObjCClass (name, decl_ctx, isForwardDecl, isInternal, metadata); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1184 | // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and |
| 1185 | // we will need to update this code. I was told to currently always use |
| 1186 | // the CXXRecordDecl class since we often don't know from debug information |
| 1187 | // if something is struct or a class, so we default to always use the more |
| 1188 | // complete definition just in case. |
Sean Callanan | 11e32d3 | 2014-02-18 00:31:38 +0000 | [diff] [blame] | 1189 | |
| 1190 | bool is_anonymous = (!name) || (!name[0]); |
| 1191 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1192 | CXXRecordDecl *decl = CXXRecordDecl::Create (*ast, |
| 1193 | (TagDecl::TagKind)kind, |
| 1194 | decl_ctx, |
| 1195 | SourceLocation(), |
| 1196 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1197 | is_anonymous ? nullptr : &ast->Idents.get(name)); |
Sean Callanan | 11e32d3 | 2014-02-18 00:31:38 +0000 | [diff] [blame] | 1198 | |
| 1199 | if (is_anonymous) |
| 1200 | decl->setAnonymousStructOrUnion(true); |
Sean Callanan | 7282e2a | 2012-01-13 22:10:18 +0000 | [diff] [blame] | 1201 | |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1202 | if (decl) |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1203 | { |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1204 | if (metadata) |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1205 | SetMetadata(ast, decl, *metadata); |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1206 | |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1207 | if (access_type != eAccessNone) |
| 1208 | decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); |
Greg Clayton | c4ffd66 | 2013-03-08 01:37:30 +0000 | [diff] [blame] | 1209 | |
| 1210 | if (decl_ctx) |
| 1211 | decl_ctx->addDecl (decl); |
| 1212 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1213 | return ClangASTType(ast, ast->getTagDeclType(decl).getAsOpaquePtr()); |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1214 | } |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1215 | return ClangASTType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1218 | static TemplateParameterList * |
| 1219 | CreateTemplateParameterList (ASTContext *ast, |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1220 | const ClangASTContext::TemplateParameterInfos &template_param_infos, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1221 | llvm::SmallVector<NamedDecl *, 8> &template_param_decls) |
| 1222 | { |
| 1223 | const bool parameter_pack = false; |
| 1224 | const bool is_typename = false; |
| 1225 | const unsigned depth = 0; |
| 1226 | const size_t num_template_params = template_param_infos.GetSize(); |
| 1227 | for (size_t i=0; i<num_template_params; ++i) |
| 1228 | { |
| 1229 | const char *name = template_param_infos.names[i]; |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1230 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1231 | IdentifierInfo *identifier_info = nullptr; |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1232 | if (name && name[0]) |
| 1233 | identifier_info = &ast->Idents.get(name); |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1234 | if (template_param_infos.args[i].getKind() == TemplateArgument::Integral) |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1235 | { |
| 1236 | template_param_decls.push_back (NonTypeTemplateParmDecl::Create (*ast, |
| 1237 | ast->getTranslationUnitDecl(), // Is this the right decl context?, SourceLocation StartLoc, |
| 1238 | SourceLocation(), |
| 1239 | SourceLocation(), |
| 1240 | depth, |
| 1241 | i, |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1242 | identifier_info, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1243 | template_param_infos.args[i].getIntegralType(), |
| 1244 | parameter_pack, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1245 | nullptr)); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1246 | |
| 1247 | } |
| 1248 | else |
| 1249 | { |
| 1250 | template_param_decls.push_back (TemplateTypeParmDecl::Create (*ast, |
| 1251 | ast->getTranslationUnitDecl(), // Is this the right decl context? |
| 1252 | SourceLocation(), |
| 1253 | SourceLocation(), |
| 1254 | depth, |
| 1255 | i, |
Greg Clayton | 283b265 | 2013-04-23 22:38:02 +0000 | [diff] [blame] | 1256 | identifier_info, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1257 | is_typename, |
| 1258 | parameter_pack)); |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | TemplateParameterList *template_param_list = TemplateParameterList::Create (*ast, |
| 1263 | SourceLocation(), |
| 1264 | SourceLocation(), |
| 1265 | &template_param_decls.front(), |
| 1266 | template_param_decls.size(), |
| 1267 | SourceLocation()); |
| 1268 | return template_param_list; |
| 1269 | } |
| 1270 | |
| 1271 | clang::FunctionTemplateDecl * |
| 1272 | ClangASTContext::CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx, |
| 1273 | clang::FunctionDecl *func_decl, |
| 1274 | const char *name, |
| 1275 | const TemplateParameterInfos &template_param_infos) |
| 1276 | { |
| 1277 | // /// \brief Create a function template node. |
| 1278 | ASTContext *ast = getASTContext(); |
| 1279 | |
| 1280 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
| 1281 | |
| 1282 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, |
| 1283 | template_param_infos, |
| 1284 | template_param_decls); |
| 1285 | FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create (*ast, |
| 1286 | decl_ctx, |
| 1287 | func_decl->getLocation(), |
| 1288 | func_decl->getDeclName(), |
| 1289 | template_param_list, |
| 1290 | func_decl); |
| 1291 | |
| 1292 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); |
| 1293 | i < template_param_decl_count; |
| 1294 | ++i) |
| 1295 | { |
| 1296 | // TODO: verify which decl context we should put template_param_decls into.. |
| 1297 | template_param_decls[i]->setDeclContext (func_decl); |
| 1298 | } |
| 1299 | |
| 1300 | return func_tmpl_decl; |
| 1301 | } |
| 1302 | |
| 1303 | void |
| 1304 | ClangASTContext::CreateFunctionTemplateSpecializationInfo (FunctionDecl *func_decl, |
| 1305 | clang::FunctionTemplateDecl *func_tmpl_decl, |
| 1306 | const TemplateParameterInfos &infos) |
| 1307 | { |
| 1308 | TemplateArgumentList template_args (TemplateArgumentList::OnStack, |
| 1309 | infos.args.data(), |
| 1310 | infos.args.size()); |
| 1311 | |
| 1312 | func_decl->setFunctionTemplateSpecialization (func_tmpl_decl, |
| 1313 | &template_args, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1314 | nullptr); |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1318 | ClassTemplateDecl * |
| 1319 | ClangASTContext::CreateClassTemplateDecl (DeclContext *decl_ctx, |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1320 | lldb::AccessType access_type, |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1321 | const char *class_name, |
| 1322 | int kind, |
| 1323 | const TemplateParameterInfos &template_param_infos) |
| 1324 | { |
| 1325 | ASTContext *ast = getASTContext(); |
| 1326 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1327 | ClassTemplateDecl *class_template_decl = nullptr; |
| 1328 | if (decl_ctx == nullptr) |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1329 | decl_ctx = ast->getTranslationUnitDecl(); |
| 1330 | |
| 1331 | IdentifierInfo &identifier_info = ast->Idents.get(class_name); |
| 1332 | DeclarationName decl_name (&identifier_info); |
| 1333 | |
| 1334 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1335 | |
| 1336 | for (NamedDecl *decl : result) |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1337 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1338 | class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1339 | if (class_template_decl) |
| 1340 | return class_template_decl; |
| 1341 | } |
| 1342 | |
| 1343 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1344 | |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1345 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, |
| 1346 | template_param_infos, |
| 1347 | template_param_decls); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1348 | |
| 1349 | CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create (*ast, |
| 1350 | (TagDecl::TagKind)kind, |
| 1351 | decl_ctx, // What decl context do we use here? TU? The actual decl context? |
| 1352 | SourceLocation(), |
| 1353 | SourceLocation(), |
| 1354 | &identifier_info); |
Greg Clayton | e04741d | 2011-12-02 02:09:28 +0000 | [diff] [blame] | 1355 | |
| 1356 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); |
| 1357 | i < template_param_decl_count; |
| 1358 | ++i) |
| 1359 | { |
| 1360 | template_param_decls[i]->setDeclContext (template_cxx_decl); |
| 1361 | } |
| 1362 | |
Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1363 | // With templated classes, we say that a class is templated with |
| 1364 | // specializations, but that the bare class has no functions. |
Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame] | 1365 | //template_cxx_decl->startDefinition(); |
| 1366 | //template_cxx_decl->completeDefinition(); |
Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1367 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1368 | class_template_decl = ClassTemplateDecl::Create (*ast, |
| 1369 | decl_ctx, // What decl context do we use here? TU? The actual decl context? |
| 1370 | SourceLocation(), |
| 1371 | decl_name, |
| 1372 | template_param_list, |
| 1373 | template_cxx_decl, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1374 | nullptr); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1375 | |
| 1376 | if (class_template_decl) |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1377 | { |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1378 | if (access_type != eAccessNone) |
| 1379 | class_template_decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1380 | |
| 1381 | //if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx)) |
| 1382 | // CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl)); |
| 1383 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1384 | decl_ctx->addDecl (class_template_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1385 | |
| 1386 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1387 | VerifyDecl(class_template_decl); |
| 1388 | #endif |
| 1389 | } |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1390 | |
| 1391 | return class_template_decl; |
| 1392 | } |
| 1393 | |
| 1394 | |
| 1395 | ClassTemplateSpecializationDecl * |
| 1396 | ClangASTContext::CreateClassTemplateSpecializationDecl (DeclContext *decl_ctx, |
| 1397 | ClassTemplateDecl *class_template_decl, |
| 1398 | int kind, |
| 1399 | const TemplateParameterInfos &template_param_infos) |
| 1400 | { |
| 1401 | ASTContext *ast = getASTContext(); |
| 1402 | ClassTemplateSpecializationDecl *class_template_specialization_decl = ClassTemplateSpecializationDecl::Create (*ast, |
| 1403 | (TagDecl::TagKind)kind, |
| 1404 | decl_ctx, |
| 1405 | SourceLocation(), |
| 1406 | SourceLocation(), |
| 1407 | class_template_decl, |
| 1408 | &template_param_infos.args.front(), |
| 1409 | template_param_infos.args.size(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1410 | nullptr); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1411 | |
Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame] | 1412 | class_template_specialization_decl->setSpecializationKind(TSK_ExplicitSpecialization); |
| 1413 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1414 | return class_template_specialization_decl; |
| 1415 | } |
| 1416 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1417 | ClangASTType |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1418 | ClangASTContext::CreateClassTemplateSpecializationType (ClassTemplateSpecializationDecl *class_template_specialization_decl) |
| 1419 | { |
| 1420 | if (class_template_specialization_decl) |
| 1421 | { |
| 1422 | ASTContext *ast = getASTContext(); |
| 1423 | if (ast) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1424 | return ClangASTType(ast, ast->getTagDeclType(class_template_specialization_decl).getAsOpaquePtr()); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1425 | } |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1426 | return ClangASTType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1429 | static inline bool |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1430 | 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] | 1431 | { |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1432 | // Special-case call since it can take any number of operands |
| 1433 | if(op_kind == OO_Call) |
| 1434 | return true; |
| 1435 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1436 | // The parameter count doesn't include "this" |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1437 | if (num_params == 0) |
| 1438 | return unary; |
| 1439 | if (num_params == 1) |
| 1440 | return binary; |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1441 | else |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1442 | return false; |
| 1443 | } |
Daniel Dunbar | dacdfb5 | 2011-10-31 22:50:57 +0000 | [diff] [blame] | 1444 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1445 | bool |
| 1446 | ClangASTContext::CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, uint32_t num_params) |
| 1447 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1448 | switch (op_kind) |
| 1449 | { |
| 1450 | default: |
| 1451 | break; |
| 1452 | // C++ standard allows any number of arguments to new/delete |
| 1453 | case OO_New: |
| 1454 | case OO_Array_New: |
| 1455 | case OO_Delete: |
| 1456 | case OO_Array_Delete: |
| 1457 | return true; |
| 1458 | } |
| 1459 | |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1460 | #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] | 1461 | switch (op_kind) |
| 1462 | { |
| 1463 | #include "clang/Basic/OperatorKinds.def" |
| 1464 | default: break; |
| 1465 | } |
| 1466 | return false; |
| 1467 | } |
| 1468 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1469 | clang::AccessSpecifier |
| 1470 | ClangASTContext::UnifyAccessSpecifiers (clang::AccessSpecifier lhs, clang::AccessSpecifier rhs) |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 1471 | { |
| 1472 | clang::AccessSpecifier ret = lhs; |
| 1473 | |
| 1474 | // Make the access equal to the stricter of the field and the nested field's access |
| 1475 | switch (ret) |
| 1476 | { |
| 1477 | case clang::AS_none: |
| 1478 | break; |
| 1479 | case clang::AS_private: |
| 1480 | break; |
| 1481 | case clang::AS_protected: |
| 1482 | if (rhs == AS_private) |
| 1483 | ret = AS_private; |
| 1484 | break; |
| 1485 | case clang::AS_public: |
| 1486 | ret = rhs; |
| 1487 | break; |
| 1488 | } |
| 1489 | |
| 1490 | return ret; |
| 1491 | } |
| 1492 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1493 | bool |
| 1494 | ClangASTContext::FieldIsBitfield (FieldDecl* field, uint32_t& bitfield_bit_size) |
| 1495 | { |
| 1496 | return FieldIsBitfield(getASTContext(), field, bitfield_bit_size); |
| 1497 | } |
| 1498 | |
| 1499 | bool |
| 1500 | ClangASTContext::FieldIsBitfield |
| 1501 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1502 | ASTContext *ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1503 | FieldDecl* field, |
| 1504 | uint32_t& bitfield_bit_size |
| 1505 | ) |
| 1506 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1507 | if (ast == nullptr || field == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1508 | return false; |
| 1509 | |
| 1510 | if (field->isBitField()) |
| 1511 | { |
| 1512 | Expr* bit_width_expr = field->getBitWidth(); |
| 1513 | if (bit_width_expr) |
| 1514 | { |
| 1515 | llvm::APSInt bit_width_apsint; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1516 | if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1517 | { |
| 1518 | bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX); |
| 1519 | return true; |
| 1520 | } |
| 1521 | } |
| 1522 | } |
| 1523 | return false; |
| 1524 | } |
| 1525 | |
| 1526 | bool |
| 1527 | ClangASTContext::RecordHasFields (const RecordDecl *record_decl) |
| 1528 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1529 | if (record_decl == nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1530 | return false; |
| 1531 | |
| 1532 | if (!record_decl->field_empty()) |
| 1533 | return true; |
| 1534 | |
| 1535 | // No fields, lets check this is a CXX record and check the base classes |
| 1536 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 1537 | if (cxx_record_decl) |
| 1538 | { |
| 1539 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1540 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 1541 | base_class != base_class_end; |
| 1542 | ++base_class) |
| 1543 | { |
| 1544 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 1545 | if (RecordHasFields(base_class_decl)) |
| 1546 | return true; |
| 1547 | } |
| 1548 | } |
| 1549 | return false; |
| 1550 | } |
| 1551 | |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1552 | #pragma mark Objective C Classes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1553 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1554 | ClangASTType |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1555 | ClangASTContext::CreateObjCClass |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1556 | ( |
| 1557 | const char *name, |
| 1558 | DeclContext *decl_ctx, |
| 1559 | bool isForwardDecl, |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1560 | bool isInternal, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1561 | ClangASTMetadata *metadata |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1562 | ) |
| 1563 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1564 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1565 | assert (ast != nullptr); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1566 | assert (name && name[0]); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1567 | if (decl_ctx == nullptr) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1568 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1569 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1570 | ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create (*ast, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1571 | decl_ctx, |
| 1572 | SourceLocation(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1573 | &ast->Idents.get(name), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1574 | nullptr, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1575 | SourceLocation(), |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1576 | /*isForwardDecl,*/ |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1577 | isInternal); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1578 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1579 | if (decl && metadata) |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 1580 | SetMetadata(ast, decl, *metadata); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1581 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1582 | return ClangASTType (ast, ast->getObjCInterfaceType(decl)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | static inline bool |
| 1586 | BaseSpecifierIsEmpty (const CXXBaseSpecifier *b) |
| 1587 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1588 | return ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()) == false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1591 | uint32_t |
| 1592 | ClangASTContext::GetNumBaseClasses (const CXXRecordDecl *cxx_record_decl, bool omit_empty_base_classes) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1593 | { |
| 1594 | uint32_t num_bases = 0; |
| 1595 | if (cxx_record_decl) |
| 1596 | { |
| 1597 | if (omit_empty_base_classes) |
| 1598 | { |
| 1599 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 1600 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 1601 | base_class != base_class_end; |
| 1602 | ++base_class) |
| 1603 | { |
| 1604 | // Skip empty base classes |
| 1605 | if (omit_empty_base_classes) |
| 1606 | { |
| 1607 | if (BaseSpecifierIsEmpty (base_class)) |
| 1608 | continue; |
| 1609 | } |
| 1610 | ++num_bases; |
| 1611 | } |
| 1612 | } |
| 1613 | else |
| 1614 | num_bases = cxx_record_decl->getNumBases(); |
| 1615 | } |
| 1616 | return num_bases; |
| 1617 | } |
| 1618 | |
| 1619 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1620 | #pragma mark Namespace Declarations |
| 1621 | |
| 1622 | NamespaceDecl * |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1623 | ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *decl_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1624 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1625 | NamespaceDecl *namespace_decl = nullptr; |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1626 | ASTContext *ast = getASTContext(); |
| 1627 | TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl (); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1628 | if (decl_ctx == nullptr) |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1629 | decl_ctx = translation_unit_decl; |
| 1630 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1631 | if (name) |
| 1632 | { |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1633 | IdentifierInfo &identifier_info = ast->Idents.get(name); |
| 1634 | DeclarationName decl_name (&identifier_info); |
| 1635 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1636 | for (NamedDecl *decl : result) |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1637 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1638 | namespace_decl = dyn_cast<clang::NamespaceDecl>(decl); |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1639 | if (namespace_decl) |
| 1640 | return namespace_decl; |
| 1641 | } |
| 1642 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1643 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1644 | decl_ctx, |
| 1645 | false, |
| 1646 | SourceLocation(), |
| 1647 | SourceLocation(), |
| 1648 | &identifier_info, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1649 | nullptr); |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1650 | |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1651 | decl_ctx->addDecl (namespace_decl); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1652 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1653 | else |
| 1654 | { |
| 1655 | if (decl_ctx == translation_unit_decl) |
| 1656 | { |
| 1657 | namespace_decl = translation_unit_decl->getAnonymousNamespace(); |
| 1658 | if (namespace_decl) |
| 1659 | return namespace_decl; |
| 1660 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1661 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1662 | decl_ctx, |
| 1663 | false, |
| 1664 | SourceLocation(), |
| 1665 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1666 | nullptr, |
| 1667 | nullptr); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1668 | translation_unit_decl->setAnonymousNamespace (namespace_decl); |
| 1669 | translation_unit_decl->addDecl (namespace_decl); |
| 1670 | assert (namespace_decl == translation_unit_decl->getAnonymousNamespace()); |
| 1671 | } |
| 1672 | else |
| 1673 | { |
| 1674 | NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx); |
| 1675 | if (parent_namespace_decl) |
| 1676 | { |
| 1677 | namespace_decl = parent_namespace_decl->getAnonymousNamespace(); |
| 1678 | if (namespace_decl) |
| 1679 | return namespace_decl; |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1680 | namespace_decl = NamespaceDecl::Create(*ast, |
| 1681 | decl_ctx, |
| 1682 | false, |
| 1683 | SourceLocation(), |
| 1684 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1685 | nullptr, |
| 1686 | nullptr); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 1687 | parent_namespace_decl->setAnonymousNamespace (namespace_decl); |
| 1688 | parent_namespace_decl->addDecl (namespace_decl); |
| 1689 | assert (namespace_decl == parent_namespace_decl->getAnonymousNamespace()); |
| 1690 | } |
| 1691 | else |
| 1692 | { |
| 1693 | // BAD!!! |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | |
| 1698 | if (namespace_decl) |
| 1699 | { |
| 1700 | // If we make it here, we are creating the anonymous namespace decl |
| 1701 | // for the first time, so we need to do the using directive magic |
| 1702 | // like SEMA does |
| 1703 | UsingDirectiveDecl* using_directive_decl = UsingDirectiveDecl::Create (*ast, |
| 1704 | decl_ctx, |
| 1705 | SourceLocation(), |
| 1706 | SourceLocation(), |
| 1707 | NestedNameSpecifierLoc(), |
| 1708 | SourceLocation(), |
| 1709 | namespace_decl, |
| 1710 | decl_ctx); |
| 1711 | using_directive_decl->setImplicit(); |
| 1712 | decl_ctx->addDecl(using_directive_decl); |
| 1713 | } |
| 1714 | } |
| 1715 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1716 | VerifyDecl(namespace_decl); |
| 1717 | #endif |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 1718 | return namespace_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | |
| 1722 | #pragma mark Function Types |
| 1723 | |
| 1724 | FunctionDecl * |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1725 | ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx, |
| 1726 | const char *name, |
| 1727 | const ClangASTType &function_clang_type, |
| 1728 | int storage, |
| 1729 | bool is_inline) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1730 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1731 | FunctionDecl *func_decl = nullptr; |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1732 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1733 | if (decl_ctx == nullptr) |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1734 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1735 | |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1736 | |
| 1737 | const bool hasWrittenPrototype = true; |
| 1738 | const bool isConstexprSpecified = false; |
| 1739 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1740 | if (name && name[0]) |
| 1741 | { |
| 1742 | func_decl = FunctionDecl::Create (*ast, |
| 1743 | decl_ctx, |
| 1744 | SourceLocation(), |
| 1745 | SourceLocation(), |
| 1746 | DeclarationName (&ast->Idents.get(name)), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1747 | function_clang_type.GetQualType(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1748 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 1749 | (clang::StorageClass)storage, |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1750 | is_inline, |
| 1751 | hasWrittenPrototype, |
| 1752 | isConstexprSpecified); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1753 | } |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1754 | else |
| 1755 | { |
| 1756 | func_decl = FunctionDecl::Create (*ast, |
| 1757 | decl_ctx, |
| 1758 | SourceLocation(), |
| 1759 | SourceLocation(), |
| 1760 | DeclarationName (), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1761 | function_clang_type.GetQualType(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1762 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 1763 | (clang::StorageClass)storage, |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1764 | is_inline, |
| 1765 | hasWrittenPrototype, |
| 1766 | isConstexprSpecified); |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1767 | } |
| 1768 | if (func_decl) |
| 1769 | decl_ctx->addDecl (func_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1770 | |
| 1771 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1772 | VerifyDecl(func_decl); |
| 1773 | #endif |
| 1774 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 1775 | return func_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1778 | ClangASTType |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1779 | ClangASTContext::CreateFunctionType (ASTContext *ast, |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1780 | const ClangASTType& result_type, |
| 1781 | const ClangASTType *args, |
Sean Callanan | c81256a | 2010-09-16 20:40:25 +0000 | [diff] [blame] | 1782 | unsigned num_args, |
| 1783 | bool is_variadic, |
| 1784 | unsigned type_quals) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1785 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1786 | assert (ast != nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1787 | std::vector<QualType> qual_type_args; |
| 1788 | for (unsigned i=0; i<num_args; ++i) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1789 | qual_type_args.push_back (args[i].GetQualType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1790 | |
| 1791 | // TODO: Detect calling convention in DWARF? |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1792 | FunctionProtoType::ExtProtoInfo proto_info; |
| 1793 | proto_info.Variadic = is_variadic; |
Sylvestre Ledru | 186ca7d | 2014-08-01 12:19:15 +0000 | [diff] [blame] | 1794 | proto_info.ExceptionSpec = EST_None; |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1795 | proto_info.TypeQuals = type_quals; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1796 | proto_info.RefQualifier = RQ_None; |
Sylvestre Ledru | 186ca7d | 2014-08-01 12:19:15 +0000 | [diff] [blame] | 1797 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1798 | return ClangASTType (ast, ast->getFunctionType (result_type.GetQualType(), |
| 1799 | qual_type_args, |
| 1800 | proto_info).getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | ParmVarDecl * |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1804 | ClangASTContext::CreateParameterDeclaration (const char *name, const ClangASTType ¶m_type, int storage) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1805 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1806 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1807 | assert (ast != nullptr); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1808 | return ParmVarDecl::Create(*ast, |
| 1809 | ast->getTranslationUnitDecl(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1810 | SourceLocation(), |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1811 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1812 | name && name[0] ? &ast->Idents.get(name) : nullptr, |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1813 | param_type.GetQualType(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1814 | nullptr, |
Shawn Best | 3ab672d | 2014-10-31 23:20:13 +0000 | [diff] [blame] | 1815 | (clang::StorageClass)storage, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1816 | nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void |
| 1820 | ClangASTContext::SetFunctionParameters (FunctionDecl *function_decl, ParmVarDecl **params, unsigned num_params) |
| 1821 | { |
| 1822 | if (function_decl) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1823 | function_decl->setParams (ArrayRef<ParmVarDecl*>(params, num_params)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | #pragma mark Array Types |
| 1828 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1829 | ClangASTType |
| 1830 | ClangASTContext::CreateArrayType (const ClangASTType &element_type, |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1831 | size_t element_count, |
| 1832 | bool is_vector) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1833 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1834 | if (element_type.IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1835 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1836 | ASTContext *ast = getASTContext(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1837 | assert (ast != nullptr); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 1838 | |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1839 | if (is_vector) |
| 1840 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1841 | return ClangASTType (ast, ast->getExtVectorType(element_type.GetQualType(), element_count).getAsOpaquePtr()); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 1842 | } |
| 1843 | else |
| 1844 | { |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1845 | |
| 1846 | llvm::APInt ap_element_count (64, element_count); |
| 1847 | if (element_count == 0) |
| 1848 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1849 | return ClangASTType (ast, ast->getIncompleteArrayType (element_type.GetQualType(), |
| 1850 | ArrayType::Normal, |
| 1851 | 0).getAsOpaquePtr()); |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1852 | } |
| 1853 | else |
| 1854 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1855 | return ClangASTType (ast, ast->getConstantArrayType (element_type.GetQualType(), |
| 1856 | ap_element_count, |
| 1857 | ArrayType::Normal, |
| 1858 | 0).getAsOpaquePtr()); |
Greg Clayton | 1c8ef47 | 2013-04-05 23:27:21 +0000 | [diff] [blame] | 1859 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 1860 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1861 | } |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1862 | return ClangASTType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 1865 | ClangASTType |
| 1866 | ClangASTContext::GetOrCreateStructForIdentifier (const ConstString &type_name, |
Enrico Granata | a449e86 | 2014-10-30 00:53:28 +0000 | [diff] [blame] | 1867 | const std::initializer_list< std::pair < const char *, ClangASTType > >& type_fields, |
| 1868 | bool packed) |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 1869 | { |
| 1870 | ClangASTType type; |
| 1871 | if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid()) |
| 1872 | return type; |
| 1873 | type = CreateRecordType(nullptr, lldb::eAccessPublic, type_name.GetCString(), clang::TTK_Struct, lldb::eLanguageTypeC); |
| 1874 | type.StartTagDeclarationDefinition(); |
| 1875 | for (const auto& field : type_fields) |
| 1876 | type.AddFieldToRecordType(field.first, field.second, lldb::eAccessPublic, 0); |
Enrico Granata | a449e86 | 2014-10-30 00:53:28 +0000 | [diff] [blame] | 1877 | if (packed) |
| 1878 | type.SetIsPacked(); |
Enrico Granata | 76b08d5 | 2014-10-29 23:08:02 +0000 | [diff] [blame] | 1879 | type.CompleteTagDeclarationDefinition(); |
| 1880 | return type; |
| 1881 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1882 | |
| 1883 | #pragma mark Enumeration Types |
| 1884 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1885 | ClangASTType |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1886 | ClangASTContext::CreateEnumerationType |
| 1887 | ( |
| 1888 | const char *name, |
| 1889 | DeclContext *decl_ctx, |
| 1890 | const Declaration &decl, |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1891 | const ClangASTType &integer_clang_type |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1892 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1893 | { |
| 1894 | // TODO: Do something intelligent with the Declaration object passed in |
| 1895 | // like maybe filling in the SourceLocation with it... |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1896 | ASTContext *ast = getASTContext(); |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 1897 | |
| 1898 | // TODO: ask about these... |
| 1899 | // const bool IsScoped = false; |
| 1900 | // const bool IsFixed = false; |
| 1901 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1902 | EnumDecl *enum_decl = EnumDecl::Create (*ast, |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 1903 | decl_ctx, |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 1904 | SourceLocation(), |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 1905 | SourceLocation(), |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1906 | name && name[0] ? &ast->Idents.get(name) : nullptr, |
| 1907 | nullptr, |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 1908 | false, // IsScoped |
| 1909 | false, // IsScopedUsingClassTag |
| 1910 | false); // IsFixed |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 1911 | |
| 1912 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1913 | if (enum_decl) |
Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 1914 | { |
| 1915 | // TODO: check if we should be setting the promotion type too? |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1916 | enum_decl->setIntegerType(integer_clang_type.GetQualType()); |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 1917 | |
| 1918 | enum_decl->setAccess(AS_public); // TODO respect what's in the debug info |
| 1919 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1920 | return ClangASTType (ast, ast->getTagDeclType(enum_decl).getAsOpaquePtr()); |
Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 1921 | } |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1922 | return ClangASTType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1925 | // Disable this for now since I can't seem to get a nicely formatted float |
| 1926 | // out of the APFloat class without just getting the float, double or quad |
| 1927 | // and then using a formatted print on it which defeats the purpose. We ideally |
| 1928 | // would like to get perfect string values for any kind of float semantics |
| 1929 | // so we can support remote targets. The code below also requires a patch to |
| 1930 | // llvm::APInt. |
| 1931 | //bool |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1932 | //ClangASTContext::ConvertFloatValueToString (ASTContext *ast, clang_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] | 1933 | //{ |
| 1934 | // uint32_t count = 0; |
| 1935 | // bool is_complex = false; |
| 1936 | // if (ClangASTContext::IsFloatingPointType (clang_type, count, is_complex)) |
| 1937 | // { |
| 1938 | // unsigned num_bytes_per_float = byte_size / count; |
| 1939 | // unsigned num_bits_per_float = num_bytes_per_float * 8; |
| 1940 | // |
| 1941 | // float_str.clear(); |
| 1942 | // uint32_t i; |
| 1943 | // for (i=0; i<count; i++) |
| 1944 | // { |
| 1945 | // APInt ap_int(num_bits_per_float, bytes + i * num_bytes_per_float, (APInt::ByteOrder)apint_byte_order); |
| 1946 | // bool is_ieee = false; |
| 1947 | // APFloat ap_float(ap_int, is_ieee); |
| 1948 | // char s[1024]; |
| 1949 | // unsigned int hex_digits = 0; |
| 1950 | // bool upper_case = false; |
| 1951 | // |
| 1952 | // if (ap_float.convertToHexString(s, hex_digits, upper_case, APFloat::rmNearestTiesToEven) > 0) |
| 1953 | // { |
| 1954 | // if (i > 0) |
| 1955 | // float_str.append(", "); |
| 1956 | // float_str.append(s); |
| 1957 | // if (i == 1 && is_complex) |
| 1958 | // float_str.append(1, 'i'); |
| 1959 | // } |
| 1960 | // } |
| 1961 | // return !float_str.empty(); |
| 1962 | // } |
| 1963 | // return false; |
| 1964 | //} |
| 1965 | |
Enrico Granata | e8bf749 | 2014-08-15 23:00:02 +0000 | [diff] [blame] | 1966 | ClangASTType |
| 1967 | ClangASTContext::GetIntTypeFromBitSize (clang::ASTContext *ast, |
| 1968 | size_t bit_size, bool is_signed) |
| 1969 | { |
| 1970 | if (ast) |
| 1971 | { |
| 1972 | if (is_signed) |
| 1973 | { |
| 1974 | if (bit_size == ast->getTypeSize(ast->SignedCharTy)) |
| 1975 | return ClangASTType(ast, ast->SignedCharTy.getAsOpaquePtr()); |
| 1976 | |
| 1977 | if (bit_size == ast->getTypeSize(ast->ShortTy)) |
| 1978 | return ClangASTType(ast, ast->ShortTy.getAsOpaquePtr()); |
| 1979 | |
| 1980 | if (bit_size == ast->getTypeSize(ast->IntTy)) |
| 1981 | return ClangASTType(ast, ast->IntTy.getAsOpaquePtr()); |
| 1982 | |
| 1983 | if (bit_size == ast->getTypeSize(ast->LongTy)) |
| 1984 | return ClangASTType(ast, ast->LongTy.getAsOpaquePtr()); |
| 1985 | |
| 1986 | if (bit_size == ast->getTypeSize(ast->LongLongTy)) |
| 1987 | return ClangASTType(ast, ast->LongLongTy.getAsOpaquePtr()); |
| 1988 | |
| 1989 | if (bit_size == ast->getTypeSize(ast->Int128Ty)) |
| 1990 | return ClangASTType(ast, ast->Int128Ty.getAsOpaquePtr()); |
| 1991 | } |
| 1992 | else |
| 1993 | { |
| 1994 | if (bit_size == ast->getTypeSize(ast->UnsignedCharTy)) |
| 1995 | return ClangASTType(ast, ast->UnsignedCharTy.getAsOpaquePtr()); |
| 1996 | |
| 1997 | if (bit_size == ast->getTypeSize(ast->UnsignedShortTy)) |
| 1998 | return ClangASTType(ast, ast->UnsignedShortTy.getAsOpaquePtr()); |
| 1999 | |
| 2000 | if (bit_size == ast->getTypeSize(ast->UnsignedIntTy)) |
| 2001 | return ClangASTType(ast, ast->UnsignedIntTy.getAsOpaquePtr()); |
| 2002 | |
| 2003 | if (bit_size == ast->getTypeSize(ast->UnsignedLongTy)) |
| 2004 | return ClangASTType(ast, ast->UnsignedLongTy.getAsOpaquePtr()); |
| 2005 | |
| 2006 | if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy)) |
| 2007 | return ClangASTType(ast, ast->UnsignedLongLongTy.getAsOpaquePtr()); |
| 2008 | |
| 2009 | if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty)) |
| 2010 | return ClangASTType(ast, ast->UnsignedInt128Ty.getAsOpaquePtr()); |
| 2011 | } |
| 2012 | } |
| 2013 | return ClangASTType(); |
| 2014 | } |
| 2015 | |
| 2016 | ClangASTType |
| 2017 | ClangASTContext::GetPointerSizedIntType (clang::ASTContext *ast, bool is_signed) |
| 2018 | { |
| 2019 | if (ast) |
| 2020 | return GetIntTypeFromBitSize(ast, ast->getTypeSize(ast->VoidPtrTy), is_signed); |
| 2021 | return ClangASTType(); |
| 2022 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2023 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2024 | ClangASTType |
Greg Clayton | bc8fc0f | 2013-06-11 21:56:55 +0000 | [diff] [blame] | 2025 | ClangASTContext::GetFloatTypeFromBitSize (clang::ASTContext *ast, |
| 2026 | size_t bit_size) |
| 2027 | { |
| 2028 | if (ast) |
| 2029 | { |
| 2030 | if (bit_size == ast->getTypeSize(ast->FloatTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2031 | return ClangASTType(ast, ast->FloatTy.getAsOpaquePtr()); |
Greg Clayton | bc8fc0f | 2013-06-11 21:56:55 +0000 | [diff] [blame] | 2032 | else if (bit_size == ast->getTypeSize(ast->DoubleTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2033 | return ClangASTType(ast, ast->DoubleTy.getAsOpaquePtr()); |
Greg Clayton | bc8fc0f | 2013-06-11 21:56:55 +0000 | [diff] [blame] | 2034 | else if (bit_size == ast->getTypeSize(ast->LongDoubleTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2035 | return ClangASTType(ast, ast->LongDoubleTy.getAsOpaquePtr()); |
Greg Clayton | bc8fc0f | 2013-06-11 21:56:55 +0000 | [diff] [blame] | 2036 | else if (bit_size == ast->getTypeSize(ast->HalfTy)) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2037 | return ClangASTType(ast, ast->HalfTy.getAsOpaquePtr()); |
Greg Clayton | bc8fc0f | 2013-06-11 21:56:55 +0000 | [diff] [blame] | 2038 | } |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2039 | return ClangASTType(); |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | bool |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2043 | ClangASTContext::GetCompleteDecl (clang::ASTContext *ast, |
| 2044 | clang::Decl *decl) |
| 2045 | { |
| 2046 | if (!decl) |
| 2047 | return false; |
| 2048 | |
| 2049 | ExternalASTSource *ast_source = ast->getExternalSource(); |
| 2050 | |
| 2051 | if (!ast_source) |
| 2052 | return false; |
| 2053 | |
| 2054 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) |
| 2055 | { |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 2056 | if (tag_decl->isCompleteDefinition()) |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2057 | return true; |
| 2058 | |
| 2059 | if (!tag_decl->hasExternalLexicalStorage()) |
| 2060 | return false; |
| 2061 | |
| 2062 | ast_source->CompleteType(tag_decl); |
| 2063 | |
| 2064 | return !tag_decl->getTypeForDecl()->isIncompleteType(); |
| 2065 | } |
| 2066 | else if (clang::ObjCInterfaceDecl *objc_interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) |
| 2067 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2068 | if (objc_interface_decl->getDefinition()) |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2069 | return true; |
| 2070 | |
| 2071 | if (!objc_interface_decl->hasExternalLexicalStorage()) |
| 2072 | return false; |
| 2073 | |
| 2074 | ast_source->CompleteType(objc_interface_decl); |
| 2075 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2076 | return !objc_interface_decl->getTypeForDecl()->isIncompleteType(); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 2077 | } |
| 2078 | else |
| 2079 | { |
| 2080 | return false; |
| 2081 | } |
| 2082 | } |
| 2083 | |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2084 | void |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2085 | ClangASTContext::SetMetadataAsUserID (const void *object, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2086 | user_id_t user_id) |
| 2087 | { |
| 2088 | ClangASTMetadata meta_data; |
| 2089 | meta_data.SetUserID (user_id); |
| 2090 | SetMetadata (object, meta_data); |
| 2091 | } |
| 2092 | |
| 2093 | void |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2094 | ClangASTContext::SetMetadata (clang::ASTContext *ast, |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2095 | const void *object, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2096 | ClangASTMetadata &metadata) |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2097 | { |
| 2098 | ClangExternalASTSourceCommon *external_source = |
| 2099 | static_cast<ClangExternalASTSourceCommon*>(ast->getExternalSource()); |
| 2100 | |
| 2101 | if (external_source) |
| 2102 | external_source->SetMetadata(object, metadata); |
| 2103 | } |
| 2104 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2105 | ClangASTMetadata * |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2106 | ClangASTContext::GetMetadata (clang::ASTContext *ast, |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2107 | const void *object) |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2108 | { |
| 2109 | ClangExternalASTSourceCommon *external_source = |
| 2110 | static_cast<ClangExternalASTSourceCommon*>(ast->getExternalSource()); |
| 2111 | |
| 2112 | if (external_source && external_source->HasMetadata(object)) |
| 2113 | return external_source->GetMetadata(object); |
| 2114 | else |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 2115 | return nullptr; |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2118 | clang::DeclContext * |
| 2119 | ClangASTContext::GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl) |
| 2120 | { |
Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 2121 | return llvm::dyn_cast<clang::DeclContext>(cxx_method_decl); |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | clang::DeclContext * |
| 2125 | ClangASTContext::GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl) |
| 2126 | { |
Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 2127 | return llvm::dyn_cast<clang::DeclContext>(objc_method_decl); |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 2128 | } |
| 2129 | |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 2130 | |
| 2131 | bool |
| 2132 | ClangASTContext::GetClassMethodInfoForDeclContext (clang::DeclContext *decl_ctx, |
| 2133 | lldb::LanguageType &language, |
| 2134 | bool &is_instance_method, |
| 2135 | ConstString &language_object_name) |
| 2136 | { |
| 2137 | language_object_name.Clear(); |
| 2138 | language = eLanguageTypeUnknown; |
| 2139 | is_instance_method = false; |
| 2140 | |
| 2141 | if (decl_ctx) |
| 2142 | { |
| 2143 | if (clang::CXXMethodDecl *method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx)) |
| 2144 | { |
| 2145 | if (method_decl->isStatic()) |
| 2146 | { |
| 2147 | is_instance_method = false; |
| 2148 | } |
| 2149 | else |
| 2150 | { |
| 2151 | language_object_name.SetCString("this"); |
| 2152 | is_instance_method = true; |
| 2153 | } |
| 2154 | language = eLanguageTypeC_plus_plus; |
| 2155 | return true; |
| 2156 | } |
| 2157 | else if (clang::ObjCMethodDecl *method_decl = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx)) |
| 2158 | { |
| 2159 | // Both static and instance methods have a "self" object in objective C |
| 2160 | language_object_name.SetCString("self"); |
| 2161 | if (method_decl->isInstanceMethod()) |
| 2162 | { |
| 2163 | is_instance_method = true; |
| 2164 | } |
| 2165 | else |
| 2166 | { |
| 2167 | is_instance_method = false; |
| 2168 | } |
| 2169 | language = eLanguageTypeObjC; |
| 2170 | return true; |
| 2171 | } |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2172 | else if (clang::FunctionDecl *function_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) |
| 2173 | { |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 2174 | ClangASTMetadata *metadata = GetMetadata (&decl_ctx->getParentASTContext(), function_decl); |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2175 | if (metadata && metadata->HasObjectPtr()) |
| 2176 | { |
| 2177 | language_object_name.SetCString (metadata->GetObjectPtrName()); |
| 2178 | language = eLanguageTypeObjC; |
| 2179 | is_instance_method = true; |
| 2180 | } |
| 2181 | return true; |
| 2182 | } |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 2183 | } |
| 2184 | return false; |
| 2185 | } |
| 2186 | |