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