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