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