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