1 //===-- ClangASTContext.cpp -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Symbol/ClangASTContext.h"
14 #include <mutex> // std::once
18 // Other libraries and framework includes
20 // Clang headers like to use NDEBUG inside of them to enable/disable debug
21 // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
22 // or another. This is bad because it means that if clang was built in release
23 // mode, it assumes that you are building in release mode which is not always
24 // the case. You can end up with functions that are defined as empty in header
25 // files when NDEBUG is not defined, and this can cause link errors with the
26 // clang .a files that you have since you might be missing functions in the .a
27 // file. So we have to define NDEBUG when including clang headers to avoid any
28 // mismatches. This is covered by rdar://problem/8691220
30 #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
31 #define LLDB_DEFINED_NDEBUG_FOR_CLANG
33 // Need to include assert.h so it is as clang would expect it to be (disabled)
37 #include "clang/AST/ASTContext.h"
38 #include "clang/AST/ASTImporter.h"
39 #include "clang/AST/Attr.h"
40 #include "clang/AST/CXXInheritance.h"
41 #include "clang/AST/DeclObjC.h"
42 #include "clang/AST/DeclTemplate.h"
43 #include "clang/AST/Mangle.h"
44 #include "clang/AST/RecordLayout.h"
45 #include "clang/AST/Type.h"
46 #include "clang/AST/VTableBuilder.h"
47 #include "clang/Basic/Builtins.h"
48 #include "clang/Basic/Diagnostic.h"
49 #include "clang/Basic/FileManager.h"
50 #include "clang/Basic/FileSystemOptions.h"
51 #include "clang/Basic/SourceManager.h"
52 #include "clang/Basic/TargetInfo.h"
53 #include "clang/Basic/TargetOptions.h"
54 #include "clang/Frontend/FrontendOptions.h"
55 #include "clang/Frontend/LangStandard.h"
57 #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
59 #undef LLDB_DEFINED_NDEBUG_FOR_CLANG
60 // Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
64 #include "llvm/Support/Signals.h"
66 #include "Plugins/ExpressionParser/Clang/ClangFunctionCaller.h"
67 #include "Plugins/ExpressionParser/Clang/ClangUserExpression.h"
68 #include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h"
69 #include "lldb/Core/ArchSpec.h"
70 #include "lldb/Core/Flags.h"
71 #include "lldb/Core/Log.h"
72 #include "lldb/Core/Module.h"
73 #include "lldb/Core/PluginManager.h"
74 #include "lldb/Core/RegularExpression.h"
75 #include "lldb/Core/Scalar.h"
76 #include "lldb/Core/StreamFile.h"
77 #include "lldb/Core/ThreadSafeDenseMap.h"
78 #include "lldb/Core/UniqueCStringMap.h"
79 #include "lldb/Symbol/ClangASTContext.h"
80 #include "lldb/Symbol/ClangASTImporter.h"
81 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
82 #include "lldb/Symbol/ClangExternalASTSourceCommon.h"
83 #include "lldb/Symbol/ClangUtil.h"
84 #include "lldb/Symbol/ObjectFile.h"
85 #include "lldb/Symbol/SymbolFile.h"
86 #include "lldb/Symbol/VerifyDecl.h"
87 #include "lldb/Target/ExecutionContext.h"
88 #include "lldb/Target/Language.h"
89 #include "lldb/Target/ObjCLanguageRuntime.h"
90 #include "lldb/Target/Process.h"
91 #include "lldb/Target/Target.h"
92 #include "lldb/Utility/LLDBAssert.h"
94 #include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
95 //#include "Plugins/SymbolFile/PDB/PDBASTParser.h"
101 using namespace lldb;
102 using namespace lldb_private;
103 using namespace llvm;
104 using namespace clang;
108 static inline bool ClangASTContextSupportsLanguage (lldb::LanguageType language)
110 return language == eLanguageTypeUnknown || // Clang is the default type system
111 Language::LanguageIsC (language) ||
112 Language::LanguageIsCPlusPlus (language) ||
113 Language::LanguageIsObjC (language) ||
114 // Use Clang for Rust until there is a proper language plugin for it
115 language == eLanguageTypeRust ||
116 language == eLanguageTypeExtRenderScript;
120 typedef lldb_private::ThreadSafeDenseMap<clang::ASTContext *, ClangASTContext*> ClangASTMap;
125 static ClangASTMap *g_map_ptr = nullptr;
126 static std::once_flag g_once_flag;
127 std::call_once(g_once_flag, []() {
128 g_map_ptr = new ClangASTMap(); // leaked on purpose to avoid spins
134 clang::AccessSpecifier
135 ClangASTContext::ConvertAccessTypeToAccessSpecifier (AccessType access)
140 case eAccessNone: return AS_none;
141 case eAccessPublic: return AS_public;
142 case eAccessPrivate: return AS_private;
143 case eAccessProtected: return AS_protected;
149 ParseLangArgs (LangOptions &Opts, InputKind IK, const char* triple)
151 // FIXME: Cleanup per-file based stuff.
153 // Set some properties which depend solely on the input kind; it would be nice
154 // to move these to the language standard, and have the driver resolve the
155 // input kind + language standard.
157 Opts.AsmPreprocessor = 1;
158 } else if (IK == IK_ObjC ||
160 IK == IK_PreprocessedObjC ||
161 IK == IK_PreprocessedObjCXX) {
162 Opts.ObjC1 = Opts.ObjC2 = 1;
165 LangStandard::Kind LangStd = LangStandard::lang_unspecified;
167 if (LangStd == LangStandard::lang_unspecified) {
168 // Based on the base language, pick one.
173 assert (!"Invalid input kind!");
175 LangStd = LangStandard::lang_opencl;
178 case IK_PreprocessedCuda:
179 LangStd = LangStandard::lang_cuda;
183 case IK_PreprocessedC:
185 case IK_PreprocessedObjC:
186 LangStd = LangStandard::lang_gnu99;
189 case IK_PreprocessedCXX:
191 case IK_PreprocessedObjCXX:
192 LangStd = LangStandard::lang_gnucxx98;
197 const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
198 Opts.LineComment = Std.hasLineComments();
199 Opts.C99 = Std.isC99();
200 Opts.CPlusPlus = Std.isCPlusPlus();
201 Opts.CPlusPlus11 = Std.isCPlusPlus11();
202 Opts.Digraphs = Std.hasDigraphs();
203 Opts.GNUMode = Std.isGNUMode();
204 Opts.GNUInline = !Std.isC99();
205 Opts.HexFloats = Std.hasHexFloats();
206 Opts.ImplicitInt = Std.hasImplicitInt();
210 // OpenCL has some additional defaults.
211 if (LangStd == LangStandard::lang_opencl) {
214 Opts.CXXOperatorNames = 1;
215 Opts.LaxVectorConversions = 1;
218 // OpenCL and C++ both have bool, true, false keywords.
219 Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
221 // if (Opts.CPlusPlus)
222 // Opts.CXXOperatorNames = !Args.hasArg(OPT_fno_operator_names);
224 // if (Args.hasArg(OPT_fobjc_gc_only))
225 // Opts.setGCMode(LangOptions::GCOnly);
226 // else if (Args.hasArg(OPT_fobjc_gc))
227 // Opts.setGCMode(LangOptions::HybridGC);
229 // if (Args.hasArg(OPT_print_ivar_layout))
230 // Opts.ObjCGCBitmapPrint = 1;
232 // if (Args.hasArg(OPT_faltivec))
235 // if (Args.hasArg(OPT_pthread))
236 // Opts.POSIXThreads = 1;
238 // llvm::StringRef Vis = getLastArgValue(Args, OPT_fvisibility,
240 // if (Vis == "default")
241 Opts.setValueVisibilityMode(DefaultVisibility);
242 // else if (Vis == "hidden")
243 // Opts.setVisibilityMode(LangOptions::Hidden);
244 // else if (Vis == "protected")
245 // Opts.setVisibilityMode(LangOptions::Protected);
247 // Diags.Report(diag::err_drv_invalid_value)
248 // << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis;
250 // Opts.OverflowChecking = Args.hasArg(OPT_ftrapv);
252 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
253 // is specified, or -std is set to a conforming mode.
254 Opts.Trigraphs = !Opts.GNUMode;
255 // if (Args.hasArg(OPT_trigraphs))
256 // Opts.Trigraphs = 1;
258 // Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
259 // OPT_fno_dollars_in_identifiers,
260 // !Opts.AsmPreprocessor);
261 // Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings);
262 // Opts.Microsoft = Args.hasArg(OPT_fms_extensions);
263 // Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
264 // if (Args.hasArg(OPT_fno_lax_vector_conversions))
265 // Opts.LaxVectorConversions = 0;
266 // Opts.Exceptions = Args.hasArg(OPT_fexceptions);
267 // Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
268 // Opts.Blocks = Args.hasArg(OPT_fblocks);
269 Opts.CharIsSigned = ArchSpec(triple).CharIsSignedByDefault();
270 // Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar);
271 // Opts.Freestanding = Args.hasArg(OPT_ffreestanding);
272 // Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
273 // Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new);
274 // Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
275 // Opts.AccessControl = Args.hasArg(OPT_faccess_control);
276 // Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);
277 // Opts.MathErrno = !Args.hasArg(OPT_fno_math_errno);
278 // Opts.InstantiationDepth = getLastArgIntValue(Args, OPT_ftemplate_depth, 99,
280 // Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime);
281 // Opts.ObjCConstantStringClass = getLastArgValue(Args,
282 // OPT_fconstant_string_class);
283 // Opts.ObjCNonFragileABI = Args.hasArg(OPT_fobjc_nonfragile_abi);
284 // Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior);
285 // Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
286 // Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
287 // Opts.Static = Args.hasArg(OPT_static_define);
288 Opts.OptimizeSize = 0;
290 // FIXME: Eliminate this dependency.
292 // Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags);
293 // Opts.Optimize = Opt != 0;
296 // This is the __NO_INLINE__ define, which just depends on things like the
297 // optimization level and -fno-inline, not actually whether the backend has
300 // FIXME: This is affected by other options (-fno-inline).
301 Opts.NoInlineDefine = !Opt;
303 // unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags);
306 // Diags.Report(diag::err_drv_invalid_value)
307 // << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP;
309 // case 0: Opts.setStackProtectorMode(LangOptions::SSPOff); break;
310 // case 1: Opts.setStackProtectorMode(LangOptions::SSPOn); break;
311 // case 2: Opts.setStackProtectorMode(LangOptions::SSPReq); break;
316 ClangASTContext::ClangASTContext (const char *target_triple) :
317 TypeSystem (TypeSystem::eKindClang),
320 m_language_options_ap (),
321 m_source_manager_ap (),
322 m_diagnostics_engine_ap (),
323 m_target_options_rp (),
325 m_identifier_table_ap (),
326 m_selector_table_ap (),
328 m_callback_tag_decl (nullptr),
329 m_callback_objc_decl (nullptr),
330 m_callback_baton (nullptr),
331 m_pointer_byte_size (0),
334 if (target_triple && target_triple[0])
335 SetTargetTriple (target_triple);
338 //----------------------------------------------------------------------
340 //----------------------------------------------------------------------
341 ClangASTContext::~ClangASTContext()
347 ClangASTContext::GetPluginNameStatic()
349 return ConstString("clang");
353 ClangASTContext::GetPluginName()
355 return ClangASTContext::GetPluginNameStatic();
359 ClangASTContext::GetPluginVersion()
365 ClangASTContext::CreateInstance (lldb::LanguageType language,
366 lldb_private::Module *module,
369 if (ClangASTContextSupportsLanguage(language))
373 arch = module->GetArchitecture();
375 arch = target->GetArchitecture();
379 ArchSpec fixed_arch = arch;
380 // LLVM wants this to be set to iOS or MacOSX; if we're working on
381 // a bare-boards type image, change the triple for llvm's benefit.
382 if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple &&
383 fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
385 if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm ||
386 fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
387 fixed_arch.GetTriple().getArch() == llvm::Triple::thumb)
389 fixed_arch.GetTriple().setOS(llvm::Triple::IOS);
393 fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX);
399 std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext);
402 ast_sp->SetArchitecture (fixed_arch);
406 else if (target && target->IsValid())
408 std::shared_ptr<ClangASTContextForExpressions> ast_sp(new ClangASTContextForExpressions(*target));
411 ast_sp->SetArchitecture(fixed_arch);
412 ast_sp->m_scratch_ast_source_ap.reset (new ClangASTSource(target->shared_from_this()));
413 ast_sp->m_scratch_ast_source_ap->InstallASTContext(ast_sp->getASTContext());
414 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> proxy_ast_source(ast_sp->m_scratch_ast_source_ap->CreateProxy());
415 ast_sp->SetExternalSource(proxy_ast_source);
421 return lldb::TypeSystemSP();
425 ClangASTContext::EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions)
427 static std::vector<lldb::LanguageType> s_supported_languages_for_types({
428 lldb::eLanguageTypeC89,
429 lldb::eLanguageTypeC,
430 lldb::eLanguageTypeC11,
431 lldb::eLanguageTypeC_plus_plus,
432 lldb::eLanguageTypeC99,
433 lldb::eLanguageTypeObjC,
434 lldb::eLanguageTypeObjC_plus_plus,
435 lldb::eLanguageTypeC_plus_plus_03,
436 lldb::eLanguageTypeC_plus_plus_11,
437 lldb::eLanguageTypeC11,
438 lldb::eLanguageTypeC_plus_plus_14});
440 static std::vector<lldb::LanguageType> s_supported_languages_for_expressions({
441 lldb::eLanguageTypeC_plus_plus,
442 lldb::eLanguageTypeObjC_plus_plus,
443 lldb::eLanguageTypeC_plus_plus_03,
444 lldb::eLanguageTypeC_plus_plus_11,
445 lldb::eLanguageTypeC_plus_plus_14});
447 languages_for_types.insert(s_supported_languages_for_types.begin(), s_supported_languages_for_types.end());
448 languages_for_expressions.insert(s_supported_languages_for_expressions.begin(), s_supported_languages_for_expressions.end());
453 ClangASTContext::Initialize()
455 PluginManager::RegisterPlugin (GetPluginNameStatic(),
456 "clang base AST context plug-in",
458 EnumerateSupportedLanguages);
462 ClangASTContext::Terminate()
464 PluginManager::UnregisterPlugin (CreateInstance);
468 ClangASTContext::Finalize()
472 GetASTMap().Erase(m_ast_ap.get());
477 m_builtins_ap.reset();
478 m_selector_table_ap.reset();
479 m_identifier_table_ap.reset();
480 m_target_info_ap.reset();
481 m_target_options_rp.reset();
482 m_diagnostics_engine_ap.reset();
483 m_source_manager_ap.reset();
484 m_language_options_ap.reset();
486 m_scratch_ast_source_ap.reset();
490 ClangASTContext::Clear()
493 m_language_options_ap.reset();
494 m_source_manager_ap.reset();
495 m_diagnostics_engine_ap.reset();
496 m_target_options_rp.reset();
497 m_target_info_ap.reset();
498 m_identifier_table_ap.reset();
499 m_selector_table_ap.reset();
500 m_builtins_ap.reset();
501 m_pointer_byte_size = 0;
505 ClangASTContext::GetTargetTriple ()
507 return m_target_triple.c_str();
511 ClangASTContext::SetTargetTriple (const char *target_triple)
514 m_target_triple.assign(target_triple);
518 ClangASTContext::SetArchitecture (const ArchSpec &arch)
520 SetTargetTriple(arch.GetTriple().str().c_str());
524 ClangASTContext::HasExternalSource ()
526 ASTContext *ast = getASTContext();
528 return ast->getExternalSource () != nullptr;
533 ClangASTContext::SetExternalSource (llvm::IntrusiveRefCntPtr<ExternalASTSource> &ast_source_ap)
535 ASTContext *ast = getASTContext();
538 ast->setExternalSource (ast_source_ap);
539 ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true);
540 //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(true);
545 ClangASTContext::RemoveExternalSource ()
547 ASTContext *ast = getASTContext();
551 llvm::IntrusiveRefCntPtr<ExternalASTSource> empty_ast_source_ap;
552 ast->setExternalSource (empty_ast_source_ap);
553 ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(false);
554 //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(false);
559 ClangASTContext::setASTContext(clang::ASTContext *ast_ctx)
565 m_ast_ap.reset(ast_ctx);
566 GetASTMap().Insert(ast_ctx, this);
570 ClangASTContext::getASTContext()
572 if (m_ast_ap.get() == nullptr)
575 m_ast_ap.reset(new ASTContext (*getLanguageOptions(),
577 *getIdentifierTable(),
579 *getBuiltinContext()));
581 m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false);
583 // This can be NULL if we don't know anything about the architecture or if the
584 // target for an architecture isn't enabled in the llvm/clang that we built
585 TargetInfo *target_info = getTargetInfo();
587 m_ast_ap->InitBuiltinTypes(*target_info);
589 if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton)
591 m_ast_ap->getTranslationUnitDecl()->setHasExternalLexicalStorage();
592 //m_ast_ap->getTranslationUnitDecl()->setHasExternalVisibleStorage();
595 GetASTMap().Insert(m_ast_ap.get(), this);
597 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap (new ClangExternalASTSourceCallbacks (ClangASTContext::CompleteTagDecl,
598 ClangASTContext::CompleteObjCInterfaceDecl,
600 ClangASTContext::LayoutRecordType,
602 SetExternalSource (ast_source_ap);
604 return m_ast_ap.get();
608 ClangASTContext::GetASTContext (clang::ASTContext* ast)
610 ClangASTContext *clang_ast = GetASTMap().Lookup(ast);
615 ClangASTContext::getBuiltinContext()
617 if (m_builtins_ap.get() == nullptr)
618 m_builtins_ap.reset (new Builtin::Context());
619 return m_builtins_ap.get();
623 ClangASTContext::getIdentifierTable()
625 if (m_identifier_table_ap.get() == nullptr)
626 m_identifier_table_ap.reset(new IdentifierTable (*ClangASTContext::getLanguageOptions(), nullptr));
627 return m_identifier_table_ap.get();
631 ClangASTContext::getLanguageOptions()
633 if (m_language_options_ap.get() == nullptr)
635 m_language_options_ap.reset(new LangOptions());
636 ParseLangArgs(*m_language_options_ap, IK_ObjCXX, GetTargetTriple());
637 // InitializeLangOptions(*m_language_options_ap, IK_ObjCXX);
639 return m_language_options_ap.get();
643 ClangASTContext::getSelectorTable()
645 if (m_selector_table_ap.get() == nullptr)
646 m_selector_table_ap.reset (new SelectorTable());
647 return m_selector_table_ap.get();
651 ClangASTContext::getFileManager()
653 if (m_file_manager_ap.get() == nullptr)
655 clang::FileSystemOptions file_system_options;
656 m_file_manager_ap.reset(new clang::FileManager(file_system_options));
658 return m_file_manager_ap.get();
661 clang::SourceManager *
662 ClangASTContext::getSourceManager()
664 if (m_source_manager_ap.get() == nullptr)
665 m_source_manager_ap.reset(new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager()));
666 return m_source_manager_ap.get();
669 clang::DiagnosticsEngine *
670 ClangASTContext::getDiagnosticsEngine()
672 if (m_diagnostics_engine_ap.get() == nullptr)
674 llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs());
675 m_diagnostics_engine_ap.reset(new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions()));
677 return m_diagnostics_engine_ap.get();
680 clang::MangleContext *
681 ClangASTContext::getMangleContext()
683 if (m_mangle_ctx_ap.get() == nullptr)
684 m_mangle_ctx_ap.reset (getASTContext()->createMangleContext());
685 return m_mangle_ctx_ap.get();
688 class NullDiagnosticConsumer : public DiagnosticConsumer
691 NullDiagnosticConsumer ()
693 m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
697 HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &info)
701 llvm::SmallVector<char, 32> diag_str(10);
702 info.FormatDiagnostic(diag_str);
703 diag_str.push_back('\0');
704 m_log->Printf("Compiler diagnostic: %s\n", diag_str.data());
708 DiagnosticConsumer *clone (DiagnosticsEngine &Diags) const
710 return new NullDiagnosticConsumer ();
717 ClangASTContext::getDiagnosticConsumer()
719 if (m_diagnostic_consumer_ap.get() == nullptr)
720 m_diagnostic_consumer_ap.reset(new NullDiagnosticConsumer);
722 return m_diagnostic_consumer_ap.get();
725 std::shared_ptr<clang::TargetOptions> &
726 ClangASTContext::getTargetOptions() {
727 if (m_target_options_rp.get() == nullptr && !m_target_triple.empty())
729 m_target_options_rp = std::make_shared<clang::TargetOptions>();
730 if (m_target_options_rp.get() != nullptr)
731 m_target_options_rp->Triple = m_target_triple;
733 return m_target_options_rp;
738 ClangASTContext::getTargetInfo()
740 // target_triple should be something like "x86_64-apple-macosx"
741 if (m_target_info_ap.get() == nullptr && !m_target_triple.empty())
742 m_target_info_ap.reset (TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(), getTargetOptions()));
743 return m_target_info_ap.get();
746 #pragma mark Basic Types
749 QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext *ast, QualType qual_type)
751 uint64_t qual_type_bit_size = ast->getTypeSize(qual_type);
752 if (qual_type_bit_size == bit_size)
758 ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (Encoding encoding, size_t bit_size)
760 return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (getASTContext(), encoding, bit_size);
764 ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (ASTContext *ast, Encoding encoding, uint32_t bit_size)
767 return CompilerType();
770 case eEncodingInvalid:
771 if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy))
772 return CompilerType (ast, ast->VoidPtrTy);
776 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
777 return CompilerType (ast, ast->UnsignedCharTy);
778 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
779 return CompilerType (ast, ast->UnsignedShortTy);
780 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy))
781 return CompilerType (ast, ast->UnsignedIntTy);
782 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy))
783 return CompilerType (ast, ast->UnsignedLongTy);
784 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy))
785 return CompilerType (ast, ast->UnsignedLongLongTy);
786 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty))
787 return CompilerType (ast, ast->UnsignedInt128Ty);
791 if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy))
792 return CompilerType (ast, ast->SignedCharTy);
793 if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy))
794 return CompilerType (ast, ast->ShortTy);
795 if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy))
796 return CompilerType (ast, ast->IntTy);
797 if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy))
798 return CompilerType (ast, ast->LongTy);
799 if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy))
800 return CompilerType (ast, ast->LongLongTy);
801 if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty))
802 return CompilerType (ast, ast->Int128Ty);
805 case eEncodingIEEE754:
806 if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy))
807 return CompilerType (ast, ast->FloatTy);
808 if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy))
809 return CompilerType (ast, ast->DoubleTy);
810 if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy))
811 return CompilerType (ast, ast->LongDoubleTy);
812 if (QualTypeMatchesBitSize (bit_size, ast, ast->HalfTy))
813 return CompilerType (ast, ast->HalfTy);
816 case eEncodingVector:
817 // Sanity check that bit_size is a multiple of 8's.
818 if (bit_size && !(bit_size & 0x7u))
819 return CompilerType (ast, ast->getExtVectorType (ast->UnsignedCharTy, bit_size/8));
823 return CompilerType();
829 ClangASTContext::GetBasicTypeEnumeration (const ConstString &name)
833 typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap;
834 static TypeNameToBasicTypeMap g_type_map;
835 static std::once_flag g_once_flag;
836 std::call_once(g_once_flag, [](){
838 g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid);
841 g_type_map.Append(ConstString("char").GetCString(), eBasicTypeChar);
842 g_type_map.Append(ConstString("signed char").GetCString(), eBasicTypeSignedChar);
843 g_type_map.Append(ConstString("unsigned char").GetCString(), eBasicTypeUnsignedChar);
844 g_type_map.Append(ConstString("wchar_t").GetCString(), eBasicTypeWChar);
845 g_type_map.Append(ConstString("signed wchar_t").GetCString(), eBasicTypeSignedWChar);
846 g_type_map.Append(ConstString("unsigned wchar_t").GetCString(), eBasicTypeUnsignedWChar);
848 g_type_map.Append(ConstString("short").GetCString(), eBasicTypeShort);
849 g_type_map.Append(ConstString("short int").GetCString(), eBasicTypeShort);
850 g_type_map.Append(ConstString("unsigned short").GetCString(), eBasicTypeUnsignedShort);
851 g_type_map.Append(ConstString("unsigned short int").GetCString(), eBasicTypeUnsignedShort);
854 g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt);
855 g_type_map.Append(ConstString("signed int").GetCString(), eBasicTypeInt);
856 g_type_map.Append(ConstString("unsigned int").GetCString(), eBasicTypeUnsignedInt);
857 g_type_map.Append(ConstString("unsigned").GetCString(), eBasicTypeUnsignedInt);
860 g_type_map.Append(ConstString("long").GetCString(), eBasicTypeLong);
861 g_type_map.Append(ConstString("long int").GetCString(), eBasicTypeLong);
862 g_type_map.Append(ConstString("unsigned long").GetCString(), eBasicTypeUnsignedLong);
863 g_type_map.Append(ConstString("unsigned long int").GetCString(), eBasicTypeUnsignedLong);
866 g_type_map.Append(ConstString("long long").GetCString(), eBasicTypeLongLong);
867 g_type_map.Append(ConstString("long long int").GetCString(), eBasicTypeLongLong);
868 g_type_map.Append(ConstString("unsigned long long").GetCString(), eBasicTypeUnsignedLongLong);
869 g_type_map.Append(ConstString("unsigned long long int").GetCString(), eBasicTypeUnsignedLongLong);
872 g_type_map.Append(ConstString("__int128_t").GetCString(), eBasicTypeInt128);
873 g_type_map.Append(ConstString("__uint128_t").GetCString(), eBasicTypeUnsignedInt128);
876 g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool);
877 g_type_map.Append(ConstString("float").GetCString(), eBasicTypeFloat);
878 g_type_map.Append(ConstString("double").GetCString(), eBasicTypeDouble);
879 g_type_map.Append(ConstString("long double").GetCString(), eBasicTypeLongDouble);
880 g_type_map.Append(ConstString("id").GetCString(), eBasicTypeObjCID);
881 g_type_map.Append(ConstString("SEL").GetCString(), eBasicTypeObjCSel);
882 g_type_map.Append(ConstString("nullptr").GetCString(), eBasicTypeNullPtr);
886 return g_type_map.Find(name.GetCString(), eBasicTypeInvalid);
888 return eBasicTypeInvalid;
892 ClangASTContext::GetBasicType (ASTContext *ast, const ConstString &name)
896 lldb::BasicType basic_type = ClangASTContext::GetBasicTypeEnumeration (name);
897 return ClangASTContext::GetBasicType (ast, basic_type);
899 return CompilerType();
903 ClangASTContext::GetPointerByteSize ()
905 if (m_pointer_byte_size == 0)
906 m_pointer_byte_size = GetBasicType(lldb::eBasicTypeVoid).GetPointerType().GetByteSize(nullptr);
907 return m_pointer_byte_size;
911 ClangASTContext::GetBasicType (lldb::BasicType basic_type)
913 return GetBasicType (getASTContext(), basic_type);
917 ClangASTContext::GetBasicType (ASTContext *ast, lldb::BasicType basic_type)
920 return CompilerType();
921 lldb::opaque_compiler_type_t clang_type = GetOpaqueCompilerType(ast, basic_type);
924 return CompilerType(GetASTContext(ast), clang_type);
925 return CompilerType();
930 ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name, uint32_t dw_ate, uint32_t bit_size)
932 ASTContext *ast = getASTContext();
934 #define streq(a,b) strcmp(a,b) == 0
935 assert (ast != nullptr);
944 if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy))
945 return CompilerType (ast, ast->VoidPtrTy);
949 if (QualTypeMatchesBitSize (bit_size, ast, ast->BoolTy))
950 return CompilerType (ast, ast->BoolTy);
951 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
952 return CompilerType (ast, ast->UnsignedCharTy);
953 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
954 return CompilerType (ast, ast->UnsignedShortTy);
955 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy))
956 return CompilerType (ast, ast->UnsignedIntTy);
960 // This has been seen to mean DW_AT_complex_integer
963 if (::strstr(type_name, "complex"))
965 CompilerType complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("int", DW_ATE_signed, bit_size/2);
966 return CompilerType(ast, ast->getComplexType(ClangUtil::GetQualType(complex_int_clang_type)));
971 case DW_ATE_complex_float:
972 if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatComplexTy))
973 return CompilerType (ast, ast->FloatComplexTy);
974 else if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleComplexTy))
975 return CompilerType (ast, ast->DoubleComplexTy);
976 else if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleComplexTy))
977 return CompilerType (ast, ast->LongDoubleComplexTy);
980 CompilerType complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("float", DW_ATE_float, bit_size/2);
981 return CompilerType(ast, ast->getComplexType(ClangUtil::GetQualType(complex_float_clang_type)));
986 if (streq(type_name, "float") && QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy))
987 return CompilerType (ast, ast->FloatTy);
988 if (streq(type_name, "double") && QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy))
989 return CompilerType (ast, ast->DoubleTy);
990 if (streq(type_name, "long double") && QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy))
991 return CompilerType (ast, ast->LongDoubleTy);
992 // Fall back to not requiring a name match
993 if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy))
994 return CompilerType (ast, ast->FloatTy);
995 if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy))
996 return CompilerType (ast, ast->DoubleTy);
997 if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy))
998 return CompilerType (ast, ast->LongDoubleTy);
999 if (QualTypeMatchesBitSize (bit_size, ast, ast->HalfTy))
1000 return CompilerType (ast, ast->HalfTy);
1006 if (streq(type_name, "wchar_t") &&
1007 QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy) &&
1008 (getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType())))
1009 return CompilerType (ast, ast->WCharTy);
1010 if (streq(type_name, "void") &&
1011 QualTypeMatchesBitSize (bit_size, ast, ast->VoidTy))
1012 return CompilerType (ast, ast->VoidTy);
1013 if (strstr(type_name, "long long") &&
1014 QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy))
1015 return CompilerType (ast, ast->LongLongTy);
1016 if (strstr(type_name, "long") &&
1017 QualTypeMatchesBitSize (bit_size, ast, ast->LongTy))
1018 return CompilerType (ast, ast->LongTy);
1019 if (strstr(type_name, "short") &&
1020 QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy))
1021 return CompilerType (ast, ast->ShortTy);
1022 if (strstr(type_name, "char"))
1024 if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
1025 return CompilerType (ast, ast->CharTy);
1026 if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy))
1027 return CompilerType (ast, ast->SignedCharTy);
1029 if (strstr(type_name, "int"))
1031 if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy))
1032 return CompilerType (ast, ast->IntTy);
1033 if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty))
1034 return CompilerType (ast, ast->Int128Ty);
1037 // We weren't able to match up a type name, just search by size
1038 if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
1039 return CompilerType (ast, ast->CharTy);
1040 if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy))
1041 return CompilerType (ast, ast->ShortTy);
1042 if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy))
1043 return CompilerType (ast, ast->IntTy);
1044 if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy))
1045 return CompilerType (ast, ast->LongTy);
1046 if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy))
1047 return CompilerType (ast, ast->LongLongTy);
1048 if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty))
1049 return CompilerType (ast, ast->Int128Ty);
1052 case DW_ATE_signed_char:
1053 if (ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char"))
1055 if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
1056 return CompilerType (ast, ast->CharTy);
1058 if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy))
1059 return CompilerType (ast, ast->SignedCharTy);
1062 case DW_ATE_unsigned:
1065 if (streq(type_name, "wchar_t"))
1067 if (QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy))
1069 if (!(getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType())))
1070 return CompilerType (ast, ast->WCharTy);
1073 if (strstr(type_name, "long long"))
1075 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy))
1076 return CompilerType (ast, ast->UnsignedLongLongTy);
1078 else if (strstr(type_name, "long"))
1080 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy))
1081 return CompilerType (ast, ast->UnsignedLongTy);
1083 else if (strstr(type_name, "short"))
1085 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
1086 return CompilerType (ast, ast->UnsignedShortTy);
1088 else if (strstr(type_name, "char"))
1090 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
1091 return CompilerType (ast, ast->UnsignedCharTy);
1093 else if (strstr(type_name, "int"))
1095 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy))
1096 return CompilerType (ast, ast->UnsignedIntTy);
1097 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty))
1098 return CompilerType (ast, ast->UnsignedInt128Ty);
1101 // We weren't able to match up a type name, just search by size
1102 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
1103 return CompilerType (ast, ast->UnsignedCharTy);
1104 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
1105 return CompilerType (ast, ast->UnsignedShortTy);
1106 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy))
1107 return CompilerType (ast, ast->UnsignedIntTy);
1108 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy))
1109 return CompilerType (ast, ast->UnsignedLongTy);
1110 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy))
1111 return CompilerType (ast, ast->UnsignedLongLongTy);
1112 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty))
1113 return CompilerType (ast, ast->UnsignedInt128Ty);
1116 case DW_ATE_unsigned_char:
1117 if (!ast->getLangOpts().CharIsSigned && type_name && streq(type_name, "char"))
1119 if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy))
1120 return CompilerType (ast, ast->CharTy);
1122 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy))
1123 return CompilerType (ast, ast->UnsignedCharTy);
1124 if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy))
1125 return CompilerType (ast, ast->UnsignedShortTy);
1128 case DW_ATE_imaginary_float:
1134 if (streq(type_name, "char16_t"))
1136 return CompilerType (ast, ast->Char16Ty);
1138 else if (streq(type_name, "char32_t"))
1140 return CompilerType (ast, ast->Char32Ty);
1146 // This assert should fire for anything that we don't catch above so we know
1147 // to fix any issues we run into.
1150 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);
1154 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);
1156 return CompilerType ();
1160 ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast)
1163 return CompilerType (ast, ast->UnknownAnyTy);
1164 return CompilerType();
1168 ClangASTContext::GetCStringType (bool is_const)
1170 ASTContext *ast = getASTContext();
1171 QualType char_type(ast->CharTy);
1174 char_type.addConst();
1176 return CompilerType (ast, ast->getPointerType(char_type));
1179 clang::DeclContext *
1180 ClangASTContext::GetTranslationUnitDecl (clang::ASTContext *ast)
1182 return ast->getTranslationUnitDecl();
1186 ClangASTContext::CopyDecl (ASTContext *dst_ast,
1187 ASTContext *src_ast,
1188 clang::Decl *source_decl)
1190 FileSystemOptions file_system_options;
1191 FileManager file_manager (file_system_options);
1192 ASTImporter importer(*dst_ast, file_manager,
1193 *src_ast, file_manager,
1196 return importer.Import(source_decl);
1200 ClangASTContext::AreTypesSame (CompilerType type1,
1202 bool ignore_qualifiers)
1204 ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type1.GetTypeSystem());
1205 if (!ast || ast != type2.GetTypeSystem())
1208 if (type1.GetOpaqueQualType() == type2.GetOpaqueQualType())
1211 QualType type1_qual = ClangUtil::GetQualType(type1);
1212 QualType type2_qual = ClangUtil::GetQualType(type2);
1214 if (ignore_qualifiers)
1216 type1_qual = type1_qual.getUnqualifiedType();
1217 type2_qual = type2_qual.getUnqualifiedType();
1220 return ast->getASTContext()->hasSameType (type1_qual, type2_qual);
1224 ClangASTContext::GetTypeForDecl (clang::NamedDecl *decl)
1226 if (clang::ObjCInterfaceDecl *interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
1227 return GetTypeForDecl(interface_decl);
1228 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
1229 return GetTypeForDecl(tag_decl);
1230 return CompilerType();
1235 ClangASTContext::GetTypeForDecl (TagDecl *decl)
1237 // No need to call the getASTContext() accessor (which can create the AST
1238 // if it isn't created yet, because we can't have created a decl in this
1239 // AST if our AST didn't already exist...
1240 ASTContext *ast = &decl->getASTContext();
1242 return CompilerType (ast, ast->getTagDeclType(decl));
1243 return CompilerType();
1247 ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl)
1249 // No need to call the getASTContext() accessor (which can create the AST
1250 // if it isn't created yet, because we can't have created a decl in this
1251 // AST if our AST didn't already exist...
1252 ASTContext *ast = &decl->getASTContext();
1254 return CompilerType (ast, ast->getObjCInterfaceType(decl));
1255 return CompilerType();
1258 #pragma mark Structure, Unions, Classes
1261 ClangASTContext::CreateRecordType (DeclContext *decl_ctx,
1262 AccessType access_type,
1265 LanguageType language,
1266 ClangASTMetadata *metadata)
1268 ASTContext *ast = getASTContext();
1269 assert (ast != nullptr);
1271 if (decl_ctx == nullptr)
1272 decl_ctx = ast->getTranslationUnitDecl();
1275 if (language == eLanguageTypeObjC || language == eLanguageTypeObjC_plus_plus)
1277 bool isForwardDecl = true;
1278 bool isInternal = false;
1279 return CreateObjCClass (name, decl_ctx, isForwardDecl, isInternal, metadata);
1282 // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and
1283 // we will need to update this code. I was told to currently always use
1284 // the CXXRecordDecl class since we often don't know from debug information
1285 // if something is struct or a class, so we default to always use the more
1286 // complete definition just in case.
1288 bool is_anonymous = (!name) || (!name[0]);
1290 CXXRecordDecl *decl = CXXRecordDecl::Create (*ast,
1291 (TagDecl::TagKind)kind,
1295 is_anonymous ? nullptr : &ast->Idents.get(name));
1298 decl->setAnonymousStructOrUnion(true);
1303 SetMetadata(ast, decl, *metadata);
1305 if (access_type != eAccessNone)
1306 decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type));
1309 decl_ctx->addDecl (decl);
1311 return CompilerType(ast, ast->getTagDeclType(decl));
1313 return CompilerType();
1316 static TemplateParameterList *
1317 CreateTemplateParameterList (ASTContext *ast,
1318 const ClangASTContext::TemplateParameterInfos &template_param_infos,
1319 llvm::SmallVector<NamedDecl *, 8> &template_param_decls)
1321 const bool parameter_pack = false;
1322 const bool is_typename = false;
1323 const unsigned depth = 0;
1324 const size_t num_template_params = template_param_infos.GetSize();
1325 for (size_t i=0; i<num_template_params; ++i)
1327 const char *name = template_param_infos.names[i];
1329 IdentifierInfo *identifier_info = nullptr;
1330 if (name && name[0])
1331 identifier_info = &ast->Idents.get(name);
1332 if (template_param_infos.args[i].getKind() == TemplateArgument::Integral)
1334 template_param_decls.push_back (NonTypeTemplateParmDecl::Create (*ast,
1335 ast->getTranslationUnitDecl(), // Is this the right decl context?, SourceLocation StartLoc,
1341 template_param_infos.args[i].getIntegralType(),
1348 template_param_decls.push_back (TemplateTypeParmDecl::Create (*ast,
1349 ast->getTranslationUnitDecl(), // Is this the right decl context?
1360 TemplateParameterList *template_param_list = TemplateParameterList::Create (*ast,
1363 template_param_decls,
1365 return template_param_list;
1368 clang::FunctionTemplateDecl *
1369 ClangASTContext::CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx,
1370 clang::FunctionDecl *func_decl,
1372 const TemplateParameterInfos &template_param_infos)
1374 // /// \brief Create a function template node.
1375 ASTContext *ast = getASTContext();
1377 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1379 TemplateParameterList *template_param_list = CreateTemplateParameterList (ast,
1380 template_param_infos,
1381 template_param_decls);
1382 FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create (*ast,
1384 func_decl->getLocation(),
1385 func_decl->getDeclName(),
1386 template_param_list,
1389 for (size_t i=0, template_param_decl_count = template_param_decls.size();
1390 i < template_param_decl_count;
1393 // TODO: verify which decl context we should put template_param_decls into..
1394 template_param_decls[i]->setDeclContext (func_decl);
1397 return func_tmpl_decl;
1401 ClangASTContext::CreateFunctionTemplateSpecializationInfo (FunctionDecl *func_decl,
1402 clang::FunctionTemplateDecl *func_tmpl_decl,
1403 const TemplateParameterInfos &infos)
1405 TemplateArgumentList template_args (TemplateArgumentList::OnStack, infos.args);
1407 func_decl->setFunctionTemplateSpecialization (func_tmpl_decl,
1414 ClangASTContext::CreateClassTemplateDecl (DeclContext *decl_ctx,
1415 lldb::AccessType access_type,
1416 const char *class_name,
1418 const TemplateParameterInfos &template_param_infos)
1420 ASTContext *ast = getASTContext();
1422 ClassTemplateDecl *class_template_decl = nullptr;
1423 if (decl_ctx == nullptr)
1424 decl_ctx = ast->getTranslationUnitDecl();
1426 IdentifierInfo &identifier_info = ast->Idents.get(class_name);
1427 DeclarationName decl_name (&identifier_info);
1429 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1431 for (NamedDecl *decl : result)
1433 class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl);
1434 if (class_template_decl)
1435 return class_template_decl;
1438 llvm::SmallVector<NamedDecl *, 8> template_param_decls;
1440 TemplateParameterList *template_param_list = CreateTemplateParameterList (ast,
1441 template_param_infos,
1442 template_param_decls);
1444 CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create (*ast,
1445 (TagDecl::TagKind)kind,
1446 decl_ctx, // What decl context do we use here? TU? The actual decl context?
1451 for (size_t i=0, template_param_decl_count = template_param_decls.size();
1452 i < template_param_decl_count;
1455 template_param_decls[i]->setDeclContext (template_cxx_decl);
1458 // With templated classes, we say that a class is templated with
1459 // specializations, but that the bare class has no functions.
1460 //template_cxx_decl->startDefinition();
1461 //template_cxx_decl->completeDefinition();
1463 class_template_decl = ClassTemplateDecl::Create (*ast,
1464 decl_ctx, // What decl context do we use here? TU? The actual decl context?
1467 template_param_list,
1471 if (class_template_decl)
1473 if (access_type != eAccessNone)
1474 class_template_decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type));
1476 //if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx))
1477 // CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl));
1479 decl_ctx->addDecl (class_template_decl);
1481 #ifdef LLDB_CONFIGURATION_DEBUG
1482 VerifyDecl(class_template_decl);
1486 return class_template_decl;
1490 ClassTemplateSpecializationDecl *
1491 ClangASTContext::CreateClassTemplateSpecializationDecl (DeclContext *decl_ctx,
1492 ClassTemplateDecl *class_template_decl,
1494 const TemplateParameterInfos &template_param_infos)
1496 ASTContext *ast = getASTContext();
1497 ClassTemplateSpecializationDecl *class_template_specialization_decl = ClassTemplateSpecializationDecl::Create (*ast,
1498 (TagDecl::TagKind)kind,
1502 class_template_decl,
1503 template_param_infos.args,
1506 class_template_specialization_decl->setSpecializationKind(TSK_ExplicitSpecialization);
1508 return class_template_specialization_decl;
1512 ClangASTContext::CreateClassTemplateSpecializationType (ClassTemplateSpecializationDecl *class_template_specialization_decl)
1514 if (class_template_specialization_decl)
1516 ASTContext *ast = getASTContext();
1518 return CompilerType(ast, ast->getTagDeclType(class_template_specialization_decl));
1520 return CompilerType();
1524 check_op_param (uint32_t op_kind, bool unary, bool binary, uint32_t num_params)
1526 // Special-case call since it can take any number of operands
1527 if(op_kind == OO_Call)
1530 // The parameter count doesn't include "this"
1531 if (num_params == 0)
1533 if (num_params == 1)
1540 ClangASTContext::CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, uint32_t num_params)
1546 // C++ standard allows any number of arguments to new/delete
1550 case OO_Array_Delete:
1554 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) case OO_##Name: return check_op_param (op_kind, Unary, Binary, num_params);
1557 #include "clang/Basic/OperatorKinds.def"
1563 clang::AccessSpecifier
1564 ClangASTContext::UnifyAccessSpecifiers (clang::AccessSpecifier lhs, clang::AccessSpecifier rhs)
1566 // Make the access equal to the stricter of the field and the nested field's access
1567 if (lhs == AS_none || rhs == AS_none)
1569 if (lhs == AS_private || rhs == AS_private)
1571 if (lhs == AS_protected || rhs == AS_protected)
1572 return AS_protected;
1577 ClangASTContext::FieldIsBitfield (FieldDecl* field, uint32_t& bitfield_bit_size)
1579 return FieldIsBitfield(getASTContext(), field, bitfield_bit_size);
1583 ClangASTContext::FieldIsBitfield
1587 uint32_t& bitfield_bit_size
1590 if (ast == nullptr || field == nullptr)
1593 if (field->isBitField())
1595 Expr* bit_width_expr = field->getBitWidth();
1598 llvm::APSInt bit_width_apsint;
1599 if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast))
1601 bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX);
1610 ClangASTContext::RecordHasFields (const RecordDecl *record_decl)
1612 if (record_decl == nullptr)
1615 if (!record_decl->field_empty())
1618 // No fields, lets check this is a CXX record and check the base classes
1619 const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl);
1620 if (cxx_record_decl)
1622 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1623 for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
1624 base_class != base_class_end;
1627 const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl());
1628 if (RecordHasFields(base_class_decl))
1635 #pragma mark Objective C Classes
1638 ClangASTContext::CreateObjCClass
1641 DeclContext *decl_ctx,
1644 ClangASTMetadata *metadata
1647 ASTContext *ast = getASTContext();
1648 assert (ast != nullptr);
1649 assert (name && name[0]);
1650 if (decl_ctx == nullptr)
1651 decl_ctx = ast->getTranslationUnitDecl();
1653 ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create (*ast,
1656 &ast->Idents.get(name),
1663 if (decl && metadata)
1664 SetMetadata(ast, decl, *metadata);
1666 return CompilerType (ast, ast->getObjCInterfaceType(decl));
1670 BaseSpecifierIsEmpty (const CXXBaseSpecifier *b)
1672 return ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()) == false;
1676 ClangASTContext::GetNumBaseClasses (const CXXRecordDecl *cxx_record_decl, bool omit_empty_base_classes)
1678 uint32_t num_bases = 0;
1679 if (cxx_record_decl)
1681 if (omit_empty_base_classes)
1683 CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
1684 for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
1685 base_class != base_class_end;
1688 // Skip empty base classes
1689 if (omit_empty_base_classes)
1691 if (BaseSpecifierIsEmpty (base_class))
1698 num_bases = cxx_record_decl->getNumBases();
1704 #pragma mark Namespace Declarations
1707 ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *decl_ctx)
1709 NamespaceDecl *namespace_decl = nullptr;
1710 ASTContext *ast = getASTContext();
1711 TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl ();
1712 if (decl_ctx == nullptr)
1713 decl_ctx = translation_unit_decl;
1717 IdentifierInfo &identifier_info = ast->Idents.get(name);
1718 DeclarationName decl_name (&identifier_info);
1719 clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name);
1720 for (NamedDecl *decl : result)
1722 namespace_decl = dyn_cast<clang::NamespaceDecl>(decl);
1724 return namespace_decl;
1727 namespace_decl = NamespaceDecl::Create(*ast,
1735 decl_ctx->addDecl (namespace_decl);
1739 if (decl_ctx == translation_unit_decl)
1741 namespace_decl = translation_unit_decl->getAnonymousNamespace();
1743 return namespace_decl;
1745 namespace_decl = NamespaceDecl::Create(*ast,
1752 translation_unit_decl->setAnonymousNamespace (namespace_decl);
1753 translation_unit_decl->addDecl (namespace_decl);
1754 assert (namespace_decl == translation_unit_decl->getAnonymousNamespace());
1758 NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx);
1759 if (parent_namespace_decl)
1761 namespace_decl = parent_namespace_decl->getAnonymousNamespace();
1763 return namespace_decl;
1764 namespace_decl = NamespaceDecl::Create(*ast,
1771 parent_namespace_decl->setAnonymousNamespace (namespace_decl);
1772 parent_namespace_decl->addDecl (namespace_decl);
1773 assert (namespace_decl == parent_namespace_decl->getAnonymousNamespace());
1781 #ifdef LLDB_CONFIGURATION_DEBUG
1782 VerifyDecl(namespace_decl);
1784 return namespace_decl;
1788 ClangASTContext::GetUniqueNamespaceDeclaration (clang::ASTContext *ast,
1790 clang::DeclContext *decl_ctx)
1792 ClangASTContext *ast_ctx = ClangASTContext::GetASTContext(ast);
1793 if (ast_ctx == nullptr)
1796 return ast_ctx->GetUniqueNamespaceDeclaration(name, decl_ctx);
1800 ClangASTContext::CreateBlockDeclaration (clang::DeclContext *ctx)
1804 clang::BlockDecl *decl = clang::BlockDecl::Create(*getASTContext(), ctx, clang::SourceLocation());
1811 clang::DeclContext *
1812 FindLCABetweenDecls(clang::DeclContext *left, clang::DeclContext *right, clang::DeclContext *root)
1814 if (root == nullptr)
1817 std::set<clang::DeclContext *> path_left;
1818 for (clang::DeclContext *d = left; d != nullptr; d = d->getParent())
1819 path_left.insert(d);
1821 for (clang::DeclContext *d = right; d != nullptr; d = d->getParent())
1822 if (path_left.find(d) != path_left.end())
1828 clang::UsingDirectiveDecl *
1829 ClangASTContext::CreateUsingDirectiveDeclaration (clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl)
1831 if (decl_ctx != nullptr && ns_decl != nullptr)
1833 clang::TranslationUnitDecl *translation_unit = (clang::TranslationUnitDecl *)GetTranslationUnitDecl(getASTContext());
1834 clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(*getASTContext(),
1836 clang::SourceLocation(),
1837 clang::SourceLocation(),
1838 clang::NestedNameSpecifierLoc(),
1839 clang::SourceLocation(),
1841 FindLCABetweenDecls(decl_ctx, ns_decl, translation_unit));
1842 decl_ctx->addDecl(using_decl);
1849 ClangASTContext::CreateUsingDeclaration (clang::DeclContext *current_decl_ctx, clang::NamedDecl *target)
1851 if (current_decl_ctx != nullptr && target != nullptr)
1853 clang::UsingDecl *using_decl = clang::UsingDecl::Create(*getASTContext(),
1855 clang::SourceLocation(),
1856 clang::NestedNameSpecifierLoc(),
1857 clang::DeclarationNameInfo(),
1859 clang::UsingShadowDecl *shadow_decl = clang::UsingShadowDecl::Create(*getASTContext(),
1861 clang::SourceLocation(),
1864 using_decl->addShadowDecl(shadow_decl);
1865 current_decl_ctx->addDecl(using_decl);
1872 ClangASTContext::CreateVariableDeclaration (clang::DeclContext *decl_context, const char *name, clang::QualType type)
1874 if (decl_context != nullptr)
1876 clang::VarDecl *var_decl = clang::VarDecl::Create(*getASTContext(),
1878 clang::SourceLocation(),
1879 clang::SourceLocation(),
1880 name && name[0] ? &getASTContext()->Idents.getOwn(name) : nullptr,
1884 var_decl->setAccess(clang::AS_public);
1885 decl_context->addDecl(var_decl);
1891 lldb::opaque_compiler_type_t
1892 ClangASTContext::GetOpaqueCompilerType(clang::ASTContext *ast, lldb::BasicType basic_type)
1896 case eBasicTypeVoid:
1897 return ast->VoidTy.getAsOpaquePtr();
1898 case eBasicTypeChar:
1899 return ast->CharTy.getAsOpaquePtr();
1900 case eBasicTypeSignedChar:
1901 return ast->SignedCharTy.getAsOpaquePtr();
1902 case eBasicTypeUnsignedChar:
1903 return ast->UnsignedCharTy.getAsOpaquePtr();
1904 case eBasicTypeWChar:
1905 return ast->getWCharType().getAsOpaquePtr();
1906 case eBasicTypeSignedWChar:
1907 return ast->getSignedWCharType().getAsOpaquePtr();
1908 case eBasicTypeUnsignedWChar:
1909 return ast->getUnsignedWCharType().getAsOpaquePtr();
1910 case eBasicTypeChar16:
1911 return ast->Char16Ty.getAsOpaquePtr();
1912 case eBasicTypeChar32:
1913 return ast->Char32Ty.getAsOpaquePtr();
1914 case eBasicTypeShort:
1915 return ast->ShortTy.getAsOpaquePtr();
1916 case eBasicTypeUnsignedShort:
1917 return ast->UnsignedShortTy.getAsOpaquePtr();
1919 return ast->IntTy.getAsOpaquePtr();
1920 case eBasicTypeUnsignedInt:
1921 return ast->UnsignedIntTy.getAsOpaquePtr();
1922 case eBasicTypeLong:
1923 return ast->LongTy.getAsOpaquePtr();
1924 case eBasicTypeUnsignedLong:
1925 return ast->UnsignedLongTy.getAsOpaquePtr();
1926 case eBasicTypeLongLong:
1927 return ast->LongLongTy.getAsOpaquePtr();
1928 case eBasicTypeUnsignedLongLong:
1929 return ast->UnsignedLongLongTy.getAsOpaquePtr();
1930 case eBasicTypeInt128:
1931 return ast->Int128Ty.getAsOpaquePtr();
1932 case eBasicTypeUnsignedInt128:
1933 return ast->UnsignedInt128Ty.getAsOpaquePtr();
1934 case eBasicTypeBool:
1935 return ast->BoolTy.getAsOpaquePtr();
1936 case eBasicTypeHalf:
1937 return ast->HalfTy.getAsOpaquePtr();
1938 case eBasicTypeFloat:
1939 return ast->FloatTy.getAsOpaquePtr();
1940 case eBasicTypeDouble:
1941 return ast->DoubleTy.getAsOpaquePtr();
1942 case eBasicTypeLongDouble:
1943 return ast->LongDoubleTy.getAsOpaquePtr();
1944 case eBasicTypeFloatComplex:
1945 return ast->FloatComplexTy.getAsOpaquePtr();
1946 case eBasicTypeDoubleComplex:
1947 return ast->DoubleComplexTy.getAsOpaquePtr();
1948 case eBasicTypeLongDoubleComplex:
1949 return ast->LongDoubleComplexTy.getAsOpaquePtr();
1950 case eBasicTypeObjCID:
1951 return ast->getObjCIdType().getAsOpaquePtr();
1952 case eBasicTypeObjCClass:
1953 return ast->getObjCClassType().getAsOpaquePtr();
1954 case eBasicTypeObjCSel:
1955 return ast->getObjCSelType().getAsOpaquePtr();
1956 case eBasicTypeNullPtr:
1957 return ast->NullPtrTy.getAsOpaquePtr();
1963 #pragma mark Function Types
1966 ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx,
1968 const CompilerType &function_clang_type,
1972 FunctionDecl *func_decl = nullptr;
1973 ASTContext *ast = getASTContext();
1974 if (decl_ctx == nullptr)
1975 decl_ctx = ast->getTranslationUnitDecl();
1978 const bool hasWrittenPrototype = true;
1979 const bool isConstexprSpecified = false;
1981 if (name && name[0])
1983 func_decl = FunctionDecl::Create(
1984 *ast, decl_ctx, SourceLocation(), SourceLocation(), DeclarationName(&ast->Idents.get(name)),
1985 ClangUtil::GetQualType(function_clang_type), nullptr, (clang::StorageClass)storage, is_inline,
1986 hasWrittenPrototype, isConstexprSpecified);
1991 FunctionDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(), DeclarationName(),
1992 ClangUtil::GetQualType(function_clang_type), nullptr, (clang::StorageClass)storage,
1993 is_inline, hasWrittenPrototype, isConstexprSpecified);
1996 decl_ctx->addDecl (func_decl);
1998 #ifdef LLDB_CONFIGURATION_DEBUG
1999 VerifyDecl(func_decl);
2006 ClangASTContext::CreateFunctionType (ASTContext *ast,
2007 const CompilerType& result_type,
2008 const CompilerType *args,
2011 unsigned type_quals)
2014 return CompilerType(); // invalid AST
2016 if (!result_type || !ClangUtil::IsClangType(result_type))
2017 return CompilerType(); // invalid return type
2019 std::vector<QualType> qual_type_args;
2020 if (num_args > 0 && args == nullptr)
2021 return CompilerType(); // invalid argument array passed in
2023 // Verify that all arguments are valid and the right type
2024 for (unsigned i=0; i<num_args; ++i)
2028 // Make sure we have a clang type in args[i] and not a type from another
2029 // language whose name might match
2030 const bool is_clang_type = ClangUtil::IsClangType(args[i]);
2031 lldbassert(is_clang_type);
2033 qual_type_args.push_back(ClangUtil::GetQualType(args[i]));
2035 return CompilerType(); // invalid argument type (must be a clang type)
2038 return CompilerType(); // invalid argument type (empty)
2041 // TODO: Detect calling convention in DWARF?
2042 FunctionProtoType::ExtProtoInfo proto_info;
2043 proto_info.Variadic = is_variadic;
2044 proto_info.ExceptionSpec = EST_None;
2045 proto_info.TypeQuals = type_quals;
2046 proto_info.RefQualifier = RQ_None;
2048 return CompilerType(ast, ast->getFunctionType(ClangUtil::GetQualType(result_type), qual_type_args, proto_info));
2052 ClangASTContext::CreateParameterDeclaration (const char *name, const CompilerType ¶m_type, int storage)
2054 ASTContext *ast = getASTContext();
2055 assert (ast != nullptr);
2056 return ParmVarDecl::Create(*ast, ast->getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
2057 name && name[0] ? &ast->Idents.get(name) : nullptr, ClangUtil::GetQualType(param_type),
2058 nullptr, (clang::StorageClass)storage, nullptr);
2062 ClangASTContext::SetFunctionParameters (FunctionDecl *function_decl, ParmVarDecl **params, unsigned num_params)
2065 function_decl->setParams (ArrayRef<ParmVarDecl*>(params, num_params));
2069 ClangASTContext::CreateBlockPointerType (const CompilerType &function_type)
2071 QualType block_type = m_ast_ap->getBlockPointerType(clang::QualType::getFromOpaquePtr(function_type.GetOpaqueQualType()));
2073 return CompilerType (this, block_type.getAsOpaquePtr());
2076 #pragma mark Array Types
2079 ClangASTContext::CreateArrayType (const CompilerType &element_type,
2080 size_t element_count,
2083 if (element_type.IsValid())
2085 ASTContext *ast = getASTContext();
2086 assert (ast != nullptr);
2090 return CompilerType(ast, ast->getExtVectorType(ClangUtil::GetQualType(element_type), element_count));
2095 llvm::APInt ap_element_count (64, element_count);
2096 if (element_count == 0)
2098 return CompilerType(ast, ast->getIncompleteArrayType(ClangUtil::GetQualType(element_type),
2099 clang::ArrayType::Normal, 0));
2103 return CompilerType(ast, ast->getConstantArrayType(ClangUtil::GetQualType(element_type),
2104 ap_element_count, clang::ArrayType::Normal, 0));
2108 return CompilerType();
2112 ClangASTContext::CreateStructForIdentifier (const ConstString &type_name,
2113 const std::initializer_list< std::pair < const char *, CompilerType > >& type_fields,
2117 if (!type_name.IsEmpty() && (type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2119 lldbassert("Trying to create a type for an existing name");
2123 type = CreateRecordType(nullptr, lldb::eAccessPublic, type_name.GetCString(), clang::TTK_Struct, lldb::eLanguageTypeC);
2124 StartTagDeclarationDefinition(type);
2125 for (const auto& field : type_fields)
2126 AddFieldToRecordType(type, field.first, field.second, lldb::eAccessPublic, 0);
2129 CompleteTagDeclarationDefinition(type);
2134 ClangASTContext::GetOrCreateStructForIdentifier (const ConstString &type_name,
2135 const std::initializer_list< std::pair < const char *, CompilerType > >& type_fields,
2139 if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid())
2142 return CreateStructForIdentifier (type_name,
2147 #pragma mark Enumeration Types
2150 ClangASTContext::CreateEnumerationType
2153 DeclContext *decl_ctx,
2154 const Declaration &decl,
2155 const CompilerType &integer_clang_type
2158 // TODO: Do something intelligent with the Declaration object passed in
2159 // like maybe filling in the SourceLocation with it...
2160 ASTContext *ast = getASTContext();
2162 // TODO: ask about these...
2163 // const bool IsScoped = false;
2164 // const bool IsFixed = false;
2166 EnumDecl *enum_decl = EnumDecl::Create (*ast,
2170 name && name[0] ? &ast->Idents.get(name) : nullptr,
2173 false, // IsScopedUsingClassTag
2179 // TODO: check if we should be setting the promotion type too?
2180 enum_decl->setIntegerType(ClangUtil::GetQualType(integer_clang_type));
2182 enum_decl->setAccess(AS_public); // TODO respect what's in the debug info
2184 return CompilerType (ast, ast->getTagDeclType(enum_decl));
2186 return CompilerType();
2189 // Disable this for now since I can't seem to get a nicely formatted float
2190 // out of the APFloat class without just getting the float, double or quad
2191 // and then using a formatted print on it which defeats the purpose. We ideally
2192 // would like to get perfect string values for any kind of float semantics
2193 // so we can support remote targets. The code below also requires a patch to
2196 //ClangASTContext::ConvertFloatValueToString (ASTContext *ast, lldb::opaque_compiler_type_t clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str)
2198 // uint32_t count = 0;
2199 // bool is_complex = false;
2200 // if (ClangASTContext::IsFloatingPointType (clang_type, count, is_complex))
2202 // unsigned num_bytes_per_float = byte_size / count;
2203 // unsigned num_bits_per_float = num_bytes_per_float * 8;
2205 // float_str.clear();
2207 // for (i=0; i<count; i++)
2209 // APInt ap_int(num_bits_per_float, bytes + i * num_bytes_per_float, (APInt::ByteOrder)apint_byte_order);
2210 // bool is_ieee = false;
2211 // APFloat ap_float(ap_int, is_ieee);
2213 // unsigned int hex_digits = 0;
2214 // bool upper_case = false;
2216 // if (ap_float.convertToHexString(s, hex_digits, upper_case, APFloat::rmNearestTiesToEven) > 0)
2219 // float_str.append(", ");
2220 // float_str.append(s);
2221 // if (i == 1 && is_complex)
2222 // float_str.append(1, 'i');
2225 // return !float_str.empty();
2231 ClangASTContext::GetIntTypeFromBitSize (clang::ASTContext *ast,
2232 size_t bit_size, bool is_signed)
2238 if (bit_size == ast->getTypeSize(ast->SignedCharTy))
2239 return CompilerType(ast, ast->SignedCharTy);
2241 if (bit_size == ast->getTypeSize(ast->ShortTy))
2242 return CompilerType(ast, ast->ShortTy);
2244 if (bit_size == ast->getTypeSize(ast->IntTy))
2245 return CompilerType(ast, ast->IntTy);
2247 if (bit_size == ast->getTypeSize(ast->LongTy))
2248 return CompilerType(ast, ast->LongTy);
2250 if (bit_size == ast->getTypeSize(ast->LongLongTy))
2251 return CompilerType(ast, ast->LongLongTy);
2253 if (bit_size == ast->getTypeSize(ast->Int128Ty))
2254 return CompilerType(ast, ast->Int128Ty);
2258 if (bit_size == ast->getTypeSize(ast->UnsignedCharTy))
2259 return CompilerType(ast, ast->UnsignedCharTy);
2261 if (bit_size == ast->getTypeSize(ast->UnsignedShortTy))
2262 return CompilerType(ast, ast->UnsignedShortTy);
2264 if (bit_size == ast->getTypeSize(ast->UnsignedIntTy))
2265 return CompilerType(ast, ast->UnsignedIntTy);
2267 if (bit_size == ast->getTypeSize(ast->UnsignedLongTy))
2268 return CompilerType(ast, ast->UnsignedLongTy);
2270 if (bit_size == ast->getTypeSize(ast->UnsignedLongLongTy))
2271 return CompilerType(ast, ast->UnsignedLongLongTy);
2273 if (bit_size == ast->getTypeSize(ast->UnsignedInt128Ty))
2274 return CompilerType(ast, ast->UnsignedInt128Ty);
2277 return CompilerType();
2281 ClangASTContext::GetPointerSizedIntType (clang::ASTContext *ast, bool is_signed)
2284 return GetIntTypeFromBitSize(ast, ast->getTypeSize(ast->VoidPtrTy), is_signed);
2285 return CompilerType();
2289 ClangASTContext::DumpDeclContextHiearchy (clang::DeclContext *decl_ctx)
2293 DumpDeclContextHiearchy (decl_ctx->getParent());
2295 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl_ctx);
2298 printf ("%20s: %s\n", decl_ctx->getDeclKindName(), named_decl->getDeclName().getAsString().c_str());
2302 printf ("%20s\n", decl_ctx->getDeclKindName());
2308 ClangASTContext::DumpDeclHiearchy (clang::Decl *decl)
2310 if (decl == nullptr)
2312 DumpDeclContextHiearchy(decl->getDeclContext());
2314 clang::RecordDecl *record_decl = llvm::dyn_cast<clang::RecordDecl>(decl);
2317 printf ("%20s: %s%s\n", decl->getDeclKindName(), record_decl->getDeclName().getAsString().c_str(), record_decl->isInjectedClassName() ? " (injected class name)" : "");
2322 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>(decl);
2325 printf ("%20s: %s\n", decl->getDeclKindName(), named_decl->getDeclName().getAsString().c_str());
2329 printf ("%20s\n", decl->getDeclKindName());
2335 ClangASTContext::DeclsAreEquivalent (clang::Decl *lhs_decl, clang::Decl *rhs_decl)
2337 if (lhs_decl && rhs_decl)
2339 //----------------------------------------------------------------------
2340 // Make sure the decl kinds match first
2341 //----------------------------------------------------------------------
2342 const clang::Decl::Kind lhs_decl_kind = lhs_decl->getKind();
2343 const clang::Decl::Kind rhs_decl_kind = rhs_decl->getKind();
2345 if (lhs_decl_kind == rhs_decl_kind)
2347 //------------------------------------------------------------------
2348 // Now check that the decl contexts kinds are all equivalent
2349 // before we have to check any names of the decl contexts...
2350 //------------------------------------------------------------------
2351 clang::DeclContext *lhs_decl_ctx = lhs_decl->getDeclContext();
2352 clang::DeclContext *rhs_decl_ctx = rhs_decl->getDeclContext();
2353 if (lhs_decl_ctx && rhs_decl_ctx)
2357 if (lhs_decl_ctx && rhs_decl_ctx)
2359 const clang::Decl::Kind lhs_decl_ctx_kind = lhs_decl_ctx->getDeclKind();
2360 const clang::Decl::Kind rhs_decl_ctx_kind = rhs_decl_ctx->getDeclKind();
2361 if (lhs_decl_ctx_kind == rhs_decl_ctx_kind)
2363 lhs_decl_ctx = lhs_decl_ctx->getParent();
2364 rhs_decl_ctx = rhs_decl_ctx->getParent();
2366 if (lhs_decl_ctx == nullptr && rhs_decl_ctx == nullptr)
2376 //--------------------------------------------------------------
2377 // Now make sure the name of the decls match
2378 //--------------------------------------------------------------
2379 clang::NamedDecl *lhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(lhs_decl);
2380 clang::NamedDecl *rhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(rhs_decl);
2381 if (lhs_named_decl && rhs_named_decl)
2383 clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName();
2384 clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName();
2385 if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind())
2387 if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString())
2396 //--------------------------------------------------------------
2397 // We know that the decl context kinds all match, so now we need
2398 // to make sure the names match as well
2399 //--------------------------------------------------------------
2400 lhs_decl_ctx = lhs_decl->getDeclContext();
2401 rhs_decl_ctx = rhs_decl->getDeclContext();
2404 switch (lhs_decl_ctx->getDeclKind())
2406 case clang::Decl::TranslationUnit:
2407 // We don't care about the translation unit names
2411 clang::NamedDecl *lhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(lhs_decl_ctx);
2412 clang::NamedDecl *rhs_named_decl = llvm::dyn_cast<clang::NamedDecl>(rhs_decl_ctx);
2413 if (lhs_named_decl && rhs_named_decl)
2415 clang::DeclarationName lhs_decl_name = lhs_named_decl->getDeclName();
2416 clang::DeclarationName rhs_decl_name = rhs_named_decl->getDeclName();
2417 if (lhs_decl_name.getNameKind() == rhs_decl_name.getNameKind())
2419 if (lhs_decl_name.getAsString() != rhs_decl_name.getAsString())
2431 lhs_decl_ctx = lhs_decl_ctx->getParent();
2432 rhs_decl_ctx = rhs_decl_ctx->getParent();
2440 ClangASTContext::GetCompleteDecl (clang::ASTContext *ast,
2446 ExternalASTSource *ast_source = ast->getExternalSource();
2451 if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
2453 if (tag_decl->isCompleteDefinition())
2456 if (!tag_decl->hasExternalLexicalStorage())
2459 ast_source->CompleteType(tag_decl);
2461 return !tag_decl->getTypeForDecl()->isIncompleteType();
2463 else if (clang::ObjCInterfaceDecl *objc_interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
2465 if (objc_interface_decl->getDefinition())
2468 if (!objc_interface_decl->hasExternalLexicalStorage())
2471 ast_source->CompleteType(objc_interface_decl);
2473 return !objc_interface_decl->getTypeForDecl()->isIncompleteType();
2482 ClangASTContext::SetMetadataAsUserID (const void *object,
2485 ClangASTMetadata meta_data;
2486 meta_data.SetUserID (user_id);
2487 SetMetadata (object, meta_data);
2491 ClangASTContext::SetMetadata (clang::ASTContext *ast,
2493 ClangASTMetadata &metadata)
2495 ClangExternalASTSourceCommon *external_source =
2496 ClangExternalASTSourceCommon::Lookup(ast->getExternalSource());
2498 if (external_source)
2499 external_source->SetMetadata(object, metadata);
2503 ClangASTContext::GetMetadata (clang::ASTContext *ast,
2506 ClangExternalASTSourceCommon *external_source =
2507 ClangExternalASTSourceCommon::Lookup(ast->getExternalSource());
2509 if (external_source && external_source->HasMetadata(object))
2510 return external_source->GetMetadata(object);
2515 clang::DeclContext *
2516 ClangASTContext::GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl)
2518 return llvm::dyn_cast<clang::DeclContext>(cxx_method_decl);
2521 clang::DeclContext *
2522 ClangASTContext::GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl)
2524 return llvm::dyn_cast<clang::DeclContext>(objc_method_decl);
2528 ClangASTContext::SetTagTypeKind (clang::QualType tag_qual_type, int kind) const
2530 const clang::Type *clang_type = tag_qual_type.getTypePtr();
2533 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(clang_type);
2536 clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(tag_type->getDecl());
2539 tag_decl->setTagKind ((clang::TagDecl::TagKind)kind);
2549 ClangASTContext::SetDefaultAccessForRecordFields (clang::RecordDecl* record_decl,
2550 int default_accessibility,
2551 int *assigned_accessibilities,
2552 size_t num_assigned_accessibilities)
2557 clang::RecordDecl::field_iterator field, field_end;
2558 for (field = record_decl->field_begin(), field_end = record_decl->field_end(), field_idx = 0;
2560 ++field, ++field_idx)
2562 // If no accessibility was assigned, assign the correct one
2563 if (field_idx < num_assigned_accessibilities && assigned_accessibilities[field_idx] == clang::AS_none)
2564 field->setAccess ((clang::AccessSpecifier)default_accessibility);
2571 clang::DeclContext *
2572 ClangASTContext::GetDeclContextForType (const CompilerType& type)
2574 return GetDeclContextForType(ClangUtil::GetQualType(type));
2577 clang::DeclContext *
2578 ClangASTContext::GetDeclContextForType (clang::QualType type)
2583 clang::QualType qual_type = type.getCanonicalType();
2584 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2587 case clang::Type::ObjCInterface: return llvm::cast<clang::ObjCObjectType>(qual_type.getTypePtr())->getInterface();
2588 case clang::Type::ObjCObjectPointer: return GetDeclContextForType (llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType());
2589 case clang::Type::Record: return llvm::cast<clang::RecordType>(qual_type)->getDecl();
2590 case clang::Type::Enum: return llvm::cast<clang::EnumType>(qual_type)->getDecl();
2591 case clang::Type::Typedef: return GetDeclContextForType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType());
2592 case clang::Type::Auto: return GetDeclContextForType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType());
2593 case clang::Type::Elaborated: return GetDeclContextForType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType());
2594 case clang::Type::Paren: return GetDeclContextForType (llvm::cast<clang::ParenType>(qual_type)->desugar());
2598 // No DeclContext in this type...
2603 GetCompleteQualType (clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion = true)
2605 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2608 case clang::Type::ConstantArray:
2609 case clang::Type::IncompleteArray:
2610 case clang::Type::VariableArray:
2612 const clang::ArrayType *array_type = llvm::dyn_cast<clang::ArrayType>(qual_type.getTypePtr());
2615 return GetCompleteQualType (ast, array_type->getElementType(), allow_completion);
2618 case clang::Type::Record:
2620 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
2621 if (cxx_record_decl)
2623 if (cxx_record_decl->hasExternalLexicalStorage())
2625 const bool is_complete = cxx_record_decl->isCompleteDefinition();
2626 const bool fields_loaded = cxx_record_decl->hasLoadedFieldsFromExternalStorage();
2627 if (is_complete && fields_loaded)
2630 if (!allow_completion)
2633 // Call the field_begin() accessor to for it to use the external source
2634 // to load the fields...
2635 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2636 if (external_ast_source)
2638 external_ast_source->CompleteType(cxx_record_decl);
2639 if (cxx_record_decl->isCompleteDefinition())
2641 cxx_record_decl->field_begin();
2642 cxx_record_decl->setHasLoadedFieldsFromExternalStorage (true);
2647 const clang::TagType *tag_type = llvm::cast<clang::TagType>(qual_type.getTypePtr());
2648 return !tag_type->isIncompleteType();
2652 case clang::Type::Enum:
2654 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
2657 clang::TagDecl *tag_decl = tag_type->getDecl();
2660 if (tag_decl->getDefinition())
2663 if (!allow_completion)
2666 if (tag_decl->hasExternalLexicalStorage())
2670 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2671 if (external_ast_source)
2673 external_ast_source->CompleteType(tag_decl);
2674 return !tag_type->isIncompleteType();
2684 case clang::Type::ObjCObject:
2685 case clang::Type::ObjCInterface:
2687 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
2688 if (objc_class_type)
2690 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
2691 // We currently can't complete objective C types through the newly added ASTContext
2692 // because it only supports TagDecl objects right now...
2693 if (class_interface_decl)
2695 if (class_interface_decl->getDefinition())
2698 if (!allow_completion)
2701 if (class_interface_decl->hasExternalLexicalStorage())
2705 clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
2706 if (external_ast_source)
2708 external_ast_source->CompleteType (class_interface_decl);
2709 return !objc_class_type->isIncompleteType();
2719 case clang::Type::Typedef:
2720 return GetCompleteQualType (ast, llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType(), allow_completion);
2722 case clang::Type::Auto:
2723 return GetCompleteQualType (ast, llvm::cast<clang::AutoType>(qual_type)->getDeducedType(), allow_completion);
2725 case clang::Type::Elaborated:
2726 return GetCompleteQualType (ast, llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType(), allow_completion);
2728 case clang::Type::Paren:
2729 return GetCompleteQualType (ast, llvm::cast<clang::ParenType>(qual_type)->desugar(), allow_completion);
2731 case clang::Type::Attributed:
2732 return GetCompleteQualType (ast, llvm::cast<clang::AttributedType>(qual_type)->getModifiedType(), allow_completion);
2741 static clang::ObjCIvarDecl::AccessControl
2742 ConvertAccessTypeToObjCIvarAccessControl (AccessType access)
2746 case eAccessNone: return clang::ObjCIvarDecl::None;
2747 case eAccessPublic: return clang::ObjCIvarDecl::Public;
2748 case eAccessPrivate: return clang::ObjCIvarDecl::Private;
2749 case eAccessProtected: return clang::ObjCIvarDecl::Protected;
2750 case eAccessPackage: return clang::ObjCIvarDecl::Package;
2752 return clang::ObjCIvarDecl::None;
2756 //----------------------------------------------------------------------
2758 //----------------------------------------------------------------------
2761 ClangASTContext::IsAggregateType (lldb::opaque_compiler_type_t type)
2763 clang::QualType qual_type (GetCanonicalQualType(type));
2765 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2768 case clang::Type::IncompleteArray:
2769 case clang::Type::VariableArray:
2770 case clang::Type::ConstantArray:
2771 case clang::Type::ExtVector:
2772 case clang::Type::Vector:
2773 case clang::Type::Record:
2774 case clang::Type::ObjCObject:
2775 case clang::Type::ObjCInterface:
2777 case clang::Type::Auto:
2778 return IsAggregateType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
2779 case clang::Type::Elaborated:
2780 return IsAggregateType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
2781 case clang::Type::Typedef:
2782 return IsAggregateType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
2783 case clang::Type::Paren:
2784 return IsAggregateType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
2788 // The clang type does have a value
2793 ClangASTContext::IsAnonymousType (lldb::opaque_compiler_type_t type)
2795 clang::QualType qual_type (GetCanonicalQualType(type));
2797 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2800 case clang::Type::Record:
2802 if (const clang::RecordType *record_type = llvm::dyn_cast_or_null<clang::RecordType>(qual_type.getTypePtrOrNull()))
2804 if (const clang::RecordDecl *record_decl = record_type->getDecl())
2806 return record_decl->isAnonymousStructOrUnion();
2811 case clang::Type::Auto:
2812 return IsAnonymousType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
2813 case clang::Type::Elaborated:
2814 return IsAnonymousType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
2815 case clang::Type::Typedef:
2816 return IsAnonymousType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
2817 case clang::Type::Paren:
2818 return IsAnonymousType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
2822 // The clang type does have a value
2827 ClangASTContext::IsArrayType (lldb::opaque_compiler_type_t type,
2828 CompilerType *element_type_ptr,
2830 bool *is_incomplete)
2832 clang::QualType qual_type (GetCanonicalQualType(type));
2834 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2840 case clang::Type::ConstantArray:
2841 if (element_type_ptr)
2842 element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::ConstantArrayType>(qual_type)->getElementType());
2844 *size = llvm::cast<clang::ConstantArrayType>(qual_type)->getSize().getLimitedValue(ULLONG_MAX);
2846 *is_incomplete = false;
2849 case clang::Type::IncompleteArray:
2850 if (element_type_ptr)
2851 element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::IncompleteArrayType>(qual_type)->getElementType());
2855 *is_incomplete = true;
2858 case clang::Type::VariableArray:
2859 if (element_type_ptr)
2860 element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::VariableArrayType>(qual_type)->getElementType());
2864 *is_incomplete = false;
2867 case clang::Type::DependentSizedArray:
2868 if (element_type_ptr)
2869 element_type_ptr->SetCompilerType (getASTContext(), llvm::cast<clang::DependentSizedArrayType>(qual_type)->getElementType());
2873 *is_incomplete = false;
2876 case clang::Type::Typedef:
2877 return IsArrayType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(),
2881 case clang::Type::Auto:
2882 return IsArrayType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(),
2886 case clang::Type::Elaborated:
2887 return IsArrayType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(),
2891 case clang::Type::Paren:
2892 return IsArrayType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(),
2897 if (element_type_ptr)
2898 element_type_ptr->Clear();
2902 *is_incomplete = false;
2907 ClangASTContext::IsVectorType (lldb::opaque_compiler_type_t type,
2908 CompilerType *element_type,
2911 clang::QualType qual_type (GetCanonicalQualType(type));
2913 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
2916 case clang::Type::Vector:
2918 const clang::VectorType *vector_type = qual_type->getAs<clang::VectorType>();
2922 *size = vector_type->getNumElements();
2924 *element_type = CompilerType(getASTContext(), vector_type->getElementType());
2929 case clang::Type::ExtVector:
2931 const clang::ExtVectorType *ext_vector_type = qual_type->getAs<clang::ExtVectorType>();
2932 if (ext_vector_type)
2935 *size = ext_vector_type->getNumElements();
2937 *element_type = CompilerType(getASTContext(), ext_vector_type->getElementType());
2948 ClangASTContext::IsRuntimeGeneratedType (lldb::opaque_compiler_type_t type)
2950 clang::DeclContext* decl_ctx = ClangASTContext::GetASTContext(getASTContext())->GetDeclContextForType(GetQualType(type));
2954 if (!llvm::isa<clang::ObjCInterfaceDecl>(decl_ctx))
2957 clang::ObjCInterfaceDecl *result_iface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl_ctx);
2959 ClangASTMetadata* ast_metadata = ClangASTContext::GetMetadata(getASTContext(), result_iface_decl);
2962 return (ast_metadata->GetISAPtr() != 0);
2966 ClangASTContext::IsCharType (lldb::opaque_compiler_type_t type)
2968 return GetQualType(type).getUnqualifiedType()->isCharType();
2973 ClangASTContext::IsCompleteType (lldb::opaque_compiler_type_t type)
2975 const bool allow_completion = false;
2976 return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion);
2980 ClangASTContext::IsConst(lldb::opaque_compiler_type_t type)
2982 return GetQualType(type).isConstQualified();
2986 ClangASTContext::IsCStringType (lldb::opaque_compiler_type_t type, uint32_t &length)
2988 CompilerType pointee_or_element_clang_type;
2990 Flags type_flags (GetTypeInfo (type, &pointee_or_element_clang_type));
2992 if (!pointee_or_element_clang_type.IsValid())
2995 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer))
2997 if (pointee_or_element_clang_type.IsCharType())
2999 if (type_flags.Test (eTypeIsArray))
3001 // We know the size of the array and it could be a C string
3002 // since it is an array of characters
3003 length = llvm::cast<clang::ConstantArrayType>(GetCanonicalQualType(type).getTypePtr())->getSize().getLimitedValue();
3013 ClangASTContext::IsFunctionType (lldb::opaque_compiler_type_t type, bool *is_variadic_ptr)
3017 clang::QualType qual_type (GetCanonicalQualType(type));
3019 if (qual_type->isFunctionType())
3021 if (is_variadic_ptr)
3023 const clang::FunctionProtoType *function_proto_type = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3024 if (function_proto_type)
3025 *is_variadic_ptr = function_proto_type->isVariadic();
3027 *is_variadic_ptr = false;
3032 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3037 case clang::Type::Typedef:
3038 return IsFunctionType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), nullptr);
3039 case clang::Type::Auto:
3040 return IsFunctionType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), nullptr);
3041 case clang::Type::Elaborated:
3042 return IsFunctionType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), nullptr);
3043 case clang::Type::Paren:
3044 return IsFunctionType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), nullptr);
3045 case clang::Type::LValueReference:
3046 case clang::Type::RValueReference:
3048 const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3050 return IsFunctionType(reference_type->getPointeeType().getAsOpaquePtr(), nullptr);
3058 // Used to detect "Homogeneous Floating-point Aggregates"
3060 ClangASTContext::IsHomogeneousAggregate (lldb::opaque_compiler_type_t type, CompilerType* base_type_ptr)
3065 clang::QualType qual_type(GetCanonicalQualType(type));
3066 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3069 case clang::Type::Record:
3070 if (GetCompleteType (type))
3072 const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3073 if (cxx_record_decl)
3075 if (cxx_record_decl->getNumBases() ||
3076 cxx_record_decl->isDynamicClass())
3079 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3082 const clang::RecordDecl *record_decl = record_type->getDecl();
3085 // We are looking for a structure that contains only floating point types
3086 clang::RecordDecl::field_iterator field_pos, field_end = record_decl->field_end();
3087 uint32_t num_fields = 0;
3088 bool is_hva = false;
3089 bool is_hfa = false;
3090 clang::QualType base_qual_type;
3091 uint64_t base_bitwidth = 0;
3092 for (field_pos = record_decl->field_begin(); field_pos != field_end; ++field_pos)
3094 clang::QualType field_qual_type = field_pos->getType();
3095 uint64_t field_bitwidth = getASTContext()->getTypeSize (qual_type);
3096 if (field_qual_type->isFloatingType())
3098 if (field_qual_type->isComplexType())
3102 if (num_fields == 0)
3103 base_qual_type = field_qual_type;
3109 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3114 else if (field_qual_type->isVectorType() || field_qual_type->isExtVectorType())
3116 if (num_fields == 0)
3118 base_qual_type = field_qual_type;
3119 base_bitwidth = field_bitwidth;
3126 if (base_bitwidth != field_bitwidth)
3128 if (field_qual_type.getTypePtr() != base_qual_type.getTypePtr())
3137 *base_type_ptr = CompilerType (getASTContext(), base_qual_type);
3144 case clang::Type::Typedef:
3145 return IsHomogeneousAggregate(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), base_type_ptr);
3147 case clang::Type::Auto:
3148 return IsHomogeneousAggregate(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), base_type_ptr);
3150 case clang::Type::Elaborated:
3151 return IsHomogeneousAggregate(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), base_type_ptr);
3159 ClangASTContext::GetNumberOfFunctionArguments (lldb::opaque_compiler_type_t type)
3163 clang::QualType qual_type (GetCanonicalQualType(type));
3164 const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3166 return func->getNumParams();
3172 ClangASTContext::GetFunctionArgumentAtIndex (lldb::opaque_compiler_type_t type, const size_t index)
3176 clang::QualType qual_type (GetQualType(type));
3177 const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
3180 if (index < func->getNumParams())
3181 return CompilerType(getASTContext(), func->getParamType(index));
3184 return CompilerType();
3188 ClangASTContext::IsFunctionPointerType (lldb::opaque_compiler_type_t type)
3192 clang::QualType qual_type (GetCanonicalQualType(type));
3194 if (qual_type->isFunctionPointerType())
3197 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3202 case clang::Type::Typedef:
3203 return IsFunctionPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
3204 case clang::Type::Auto:
3205 return IsFunctionPointerType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
3206 case clang::Type::Elaborated:
3207 return IsFunctionPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
3208 case clang::Type::Paren:
3209 return IsFunctionPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
3211 case clang::Type::LValueReference:
3212 case clang::Type::RValueReference:
3214 const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3216 return IsFunctionPointerType(reference_type->getPointeeType().getAsOpaquePtr());
3226 ClangASTContext::IsBlockPointerType (lldb::opaque_compiler_type_t type, CompilerType *function_pointer_type_ptr)
3230 clang::QualType qual_type (GetCanonicalQualType(type));
3232 if (qual_type->isBlockPointerType())
3234 if (function_pointer_type_ptr)
3236 const clang::BlockPointerType *block_pointer_type = qual_type->getAs<clang::BlockPointerType>();
3237 QualType pointee_type = block_pointer_type->getPointeeType();
3238 QualType function_pointer_type = m_ast_ap->getPointerType(pointee_type);
3239 *function_pointer_type_ptr = CompilerType (getASTContext(), function_pointer_type);
3244 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3249 case clang::Type::Typedef:
3250 return IsBlockPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), function_pointer_type_ptr);
3251 case clang::Type::Auto:
3252 return IsBlockPointerType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), function_pointer_type_ptr);
3253 case clang::Type::Elaborated:
3254 return IsBlockPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), function_pointer_type_ptr);
3255 case clang::Type::Paren:
3256 return IsBlockPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), function_pointer_type_ptr);
3258 case clang::Type::LValueReference:
3259 case clang::Type::RValueReference:
3261 const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3263 return IsBlockPointerType(reference_type->getPointeeType().getAsOpaquePtr(), function_pointer_type_ptr);
3272 ClangASTContext::IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_signed)
3277 clang::QualType qual_type (GetCanonicalQualType(type));
3278 const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3282 if (builtin_type->isInteger())
3284 is_signed = builtin_type->isSignedInteger();
3293 ClangASTContext::IsEnumerationType(lldb::opaque_compiler_type_t type, bool &is_signed)
3297 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)->getCanonicalTypeInternal());
3301 IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(), is_signed);
3310 ClangASTContext::IsPointerType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type)
3314 clang::QualType qual_type (GetCanonicalQualType(type));
3315 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3318 case clang::Type::Builtin:
3319 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
3323 case clang::BuiltinType::ObjCId:
3324 case clang::BuiltinType::ObjCClass:
3328 case clang::Type::ObjCObjectPointer:
3330 pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
3332 case clang::Type::BlockPointer:
3334 pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType());
3336 case clang::Type::Pointer:
3338 pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType());
3340 case clang::Type::MemberPointer:
3342 pointee_type->SetCompilerType (getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType());
3344 case clang::Type::Typedef:
3345 return IsPointerType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type);
3346 case clang::Type::Auto:
3347 return IsPointerType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type);
3348 case clang::Type::Elaborated:
3349 return IsPointerType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type);
3350 case clang::Type::Paren:
3351 return IsPointerType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type);
3357 pointee_type->Clear();
3363 ClangASTContext::IsPointerOrReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type)
3367 clang::QualType qual_type (GetCanonicalQualType(type));
3368 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3371 case clang::Type::Builtin:
3372 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
3376 case clang::BuiltinType::ObjCId:
3377 case clang::BuiltinType::ObjCClass:
3381 case clang::Type::ObjCObjectPointer:
3383 pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
3385 case clang::Type::BlockPointer:
3387 pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::BlockPointerType>(qual_type)->getPointeeType());
3389 case clang::Type::Pointer:
3391 pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::PointerType>(qual_type)->getPointeeType());
3393 case clang::Type::MemberPointer:
3395 pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::MemberPointerType>(qual_type)->getPointeeType());
3397 case clang::Type::LValueReference:
3399 pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar());
3401 case clang::Type::RValueReference:
3403 pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar());
3405 case clang::Type::Typedef:
3406 return IsPointerOrReferenceType(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type);
3407 case clang::Type::Auto:
3408 return IsPointerOrReferenceType(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type);
3409 case clang::Type::Elaborated:
3410 return IsPointerOrReferenceType(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type);
3411 case clang::Type::Paren:
3412 return IsPointerOrReferenceType(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type);
3418 pointee_type->Clear();
3424 ClangASTContext::IsReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool* is_rvalue)
3428 clang::QualType qual_type (GetCanonicalQualType(type));
3429 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3433 case clang::Type::LValueReference:
3435 pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::LValueReferenceType>(qual_type)->desugar());
3439 case clang::Type::RValueReference:
3441 pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::RValueReferenceType>(qual_type)->desugar());
3445 case clang::Type::Typedef:
3446 return IsReferenceType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), pointee_type, is_rvalue);
3447 case clang::Type::Auto:
3448 return IsReferenceType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), pointee_type, is_rvalue);
3449 case clang::Type::Elaborated:
3450 return IsReferenceType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), pointee_type, is_rvalue);
3451 case clang::Type::Paren:
3452 return IsReferenceType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), pointee_type, is_rvalue);
3459 pointee_type->Clear();
3464 ClangASTContext::IsFloatingPointType (lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex)
3468 clang::QualType qual_type (GetCanonicalQualType(type));
3470 if (const clang::BuiltinType *BT = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal()))
3472 clang::BuiltinType::Kind kind = BT->getKind();
3473 if (kind >= clang::BuiltinType::Float && kind <= clang::BuiltinType::LongDouble)
3480 else if (const clang::ComplexType *CT = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal()))
3482 if (IsFloatingPointType (CT->getElementType().getAsOpaquePtr(), count, is_complex))
3489 else if (const clang::VectorType *VT = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal()))
3491 if (IsFloatingPointType (VT->getElementType().getAsOpaquePtr(), count, is_complex))
3493 count = VT->getNumElements();
3506 ClangASTContext::IsDefined(lldb::opaque_compiler_type_t type)
3511 clang::QualType qual_type(GetQualType(type));
3512 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
3515 clang::TagDecl *tag_decl = tag_type->getDecl();
3517 return tag_decl->isCompleteDefinition();
3522 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3523 if (objc_class_type)
3525 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
3526 if (class_interface_decl)
3527 return class_interface_decl->getDefinition() != nullptr;
3535 ClangASTContext::IsObjCClassType (const CompilerType& type)
3539 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3541 const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3543 if (obj_pointer_type)
3544 return obj_pointer_type->isObjCClassType();
3550 ClangASTContext::IsObjCObjectOrInterfaceType (const CompilerType& type)
3552 if (ClangUtil::IsClangType(type))
3553 return ClangUtil::GetCanonicalQualType(type)->isObjCObjectOrInterfaceType();
3558 ClangASTContext::IsClassType(lldb::opaque_compiler_type_t type)
3562 clang::QualType qual_type(GetCanonicalQualType(type));
3563 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3564 return (type_class == clang::Type::Record);
3568 ClangASTContext::IsEnumType(lldb::opaque_compiler_type_t type)
3572 clang::QualType qual_type(GetCanonicalQualType(type));
3573 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3574 return (type_class == clang::Type::Enum);
3578 ClangASTContext::IsPolymorphicClass(lldb::opaque_compiler_type_t type)
3582 clang::QualType qual_type(GetCanonicalQualType(type));
3583 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3586 case clang::Type::Record:
3587 if (GetCompleteType(type))
3589 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
3590 const clang::RecordDecl *record_decl = record_type->getDecl();
3593 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
3594 if (cxx_record_decl)
3595 return cxx_record_decl->isPolymorphic();
3608 ClangASTContext::IsPossibleDynamicType (lldb::opaque_compiler_type_t type, CompilerType *dynamic_pointee_type,
3609 bool check_cplusplus,
3612 clang::QualType pointee_qual_type;
3615 clang::QualType qual_type (GetCanonicalQualType(type));
3616 bool success = false;
3617 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3620 case clang::Type::Builtin:
3621 if (check_objc && llvm::cast<clang::BuiltinType>(qual_type)->getKind() == clang::BuiltinType::ObjCId)
3623 if (dynamic_pointee_type)
3624 dynamic_pointee_type->SetCompilerType(this, type);
3629 case clang::Type::ObjCObjectPointer:
3632 if (auto objc_pointee_type = qual_type->getPointeeType().getTypePtrOrNull())
3634 if (auto objc_object_type = llvm::dyn_cast_or_null<clang::ObjCObjectType>(objc_pointee_type))
3636 if (objc_object_type->isObjCClass())
3640 if (dynamic_pointee_type)
3641 dynamic_pointee_type->SetCompilerType(getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type)->getPointeeType());
3646 case clang::Type::Pointer:
3647 pointee_qual_type = llvm::cast<clang::PointerType>(qual_type)->getPointeeType();
3651 case clang::Type::LValueReference:
3652 case clang::Type::RValueReference:
3653 pointee_qual_type = llvm::cast<clang::ReferenceType>(qual_type)->getPointeeType();
3657 case clang::Type::Typedef:
3658 return IsPossibleDynamicType (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(),
3659 dynamic_pointee_type,
3663 case clang::Type::Auto:
3664 return IsPossibleDynamicType (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(),
3665 dynamic_pointee_type,
3669 case clang::Type::Elaborated:
3670 return IsPossibleDynamicType (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(),
3671 dynamic_pointee_type,
3675 case clang::Type::Paren:
3676 return IsPossibleDynamicType (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(),
3677 dynamic_pointee_type,
3686 // Check to make sure what we are pointing too is a possible dynamic C++ type
3687 // We currently accept any "void *" (in case we have a class that has been
3688 // watered down to an opaque pointer) and virtual C++ classes.
3689 const clang::Type::TypeClass pointee_type_class = pointee_qual_type.getCanonicalType()->getTypeClass();
3690 switch (pointee_type_class)
3692 case clang::Type::Builtin:
3693 switch (llvm::cast<clang::BuiltinType>(pointee_qual_type)->getKind())
3695 case clang::BuiltinType::UnknownAny:
3696 case clang::BuiltinType::Void:
3697 if (dynamic_pointee_type)
3698 dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type);
3705 case clang::Type::Record:
3706 if (check_cplusplus)
3708 clang::CXXRecordDecl *cxx_record_decl = pointee_qual_type->getAsCXXRecordDecl();
3709 if (cxx_record_decl)
3711 bool is_complete = cxx_record_decl->isCompleteDefinition();
3714 success = cxx_record_decl->isDynamicClass();
3717 ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), cxx_record_decl);
3719 success = metadata->GetIsDynamicCXXType();
3722 is_complete = CompilerType(getASTContext(), pointee_qual_type).GetCompleteType();
3724 success = cxx_record_decl->isDynamicClass();
3732 if (dynamic_pointee_type)
3733 dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type);
3740 case clang::Type::ObjCObject:
3741 case clang::Type::ObjCInterface:
3744 if (dynamic_pointee_type)
3745 dynamic_pointee_type->SetCompilerType(getASTContext(), pointee_qual_type);
3755 if (dynamic_pointee_type)
3756 dynamic_pointee_type->Clear();
3762 ClangASTContext::IsScalarType (lldb::opaque_compiler_type_t type)
3767 return (GetTypeInfo (type, nullptr) & eTypeIsScalar) != 0;
3771 ClangASTContext::IsTypedefType (lldb::opaque_compiler_type_t type)
3775 return GetQualType(type)->getTypeClass() == clang::Type::Typedef;
3779 ClangASTContext::IsVoidType (lldb::opaque_compiler_type_t type)
3783 return GetCanonicalQualType(type)->isVoidType();
3787 ClangASTContext::SupportsLanguage (lldb::LanguageType language)
3789 return ClangASTContextSupportsLanguage(language);
3793 ClangASTContext::GetCXXClassName (const CompilerType& type, std::string &class_name)
3797 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3798 if (!qual_type.isNull())
3800 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
3801 if (cxx_record_decl)
3803 class_name.assign(cxx_record_decl->getIdentifier()->getNameStart());
3814 ClangASTContext::IsCXXClassType (const CompilerType& type)
3819 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3820 if (!qual_type.isNull() && qual_type->getAsCXXRecordDecl() != nullptr)
3826 ClangASTContext::IsBeingDefined (lldb::opaque_compiler_type_t type)
3830 clang::QualType qual_type (GetCanonicalQualType(type));
3831 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type);
3833 return tag_type->isBeingDefined();
3838 ClangASTContext::IsObjCObjectPointerType (const CompilerType& type, CompilerType *class_type_ptr)
3843 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3845 if (!qual_type.isNull() && qual_type->isObjCObjectPointerType())
3849 if (!qual_type->isObjCClassType() &&
3850 !qual_type->isObjCIdType())
3852 const clang::ObjCObjectPointerType *obj_pointer_type = llvm::dyn_cast<clang::ObjCObjectPointerType>(qual_type);
3853 if (obj_pointer_type == nullptr)
3854 class_type_ptr->Clear();
3856 class_type_ptr->SetCompilerType (type.GetTypeSystem(), clang::QualType(obj_pointer_type->getInterfaceType(), 0).getAsOpaquePtr());
3862 class_type_ptr->Clear();
3867 ClangASTContext::GetObjCClassName (const CompilerType& type, std::string &class_name)
3872 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
3874 const clang::ObjCObjectType *object_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
3877 const clang::ObjCInterfaceDecl *interface = object_type->getInterface();
3880 class_name = interface->getNameAsString();
3888 //----------------------------------------------------------------------
3890 //----------------------------------------------------------------------
3893 ClangASTContext::GetCompleteType (lldb::opaque_compiler_type_t type)
3897 const bool allow_completion = true;
3898 return GetCompleteQualType (getASTContext(), GetQualType(type), allow_completion);
3902 ClangASTContext::GetTypeName (lldb::opaque_compiler_type_t type)
3904 std::string type_name;
3907 clang::PrintingPolicy printing_policy (getASTContext()->getPrintingPolicy());
3908 clang::QualType qual_type(GetQualType(type));
3909 printing_policy.SuppressTagKeyword = true;
3910 const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
3913 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
3914 type_name = typedef_decl->getQualifiedNameAsString();
3918 type_name = qual_type.getAsString(printing_policy);
3921 return ConstString(type_name);
3925 ClangASTContext::GetTypeInfo (lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_clang_type)
3930 if (pointee_or_element_clang_type)
3931 pointee_or_element_clang_type->Clear();
3933 clang::QualType qual_type (GetQualType(type));
3935 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3938 case clang::Type::Builtin:
3940 const clang::BuiltinType *builtin_type = llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
3942 uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue;
3943 switch (builtin_type->getKind())
3945 case clang::BuiltinType::ObjCId:
3946 case clang::BuiltinType::ObjCClass:
3947 if (pointee_or_element_clang_type)
3948 pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->ObjCBuiltinClassTy);
3949 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3952 case clang::BuiltinType::ObjCSel:
3953 if (pointee_or_element_clang_type)
3954 pointee_or_element_clang_type->SetCompilerType(getASTContext(), getASTContext()->CharTy);
3955 builtin_type_flags |= eTypeIsPointer | eTypeIsObjC;
3958 case clang::BuiltinType::Bool:
3959 case clang::BuiltinType::Char_U:
3960 case clang::BuiltinType::UChar:
3961 case clang::BuiltinType::WChar_U:
3962 case clang::BuiltinType::Char16:
3963 case clang::BuiltinType::Char32:
3964 case clang::BuiltinType::UShort:
3965 case clang::BuiltinType::UInt:
3966 case clang::BuiltinType::ULong:
3967 case clang::BuiltinType::ULongLong:
3968 case clang::BuiltinType::UInt128:
3969 case clang::BuiltinType::Char_S:
3970 case clang::BuiltinType::SChar:
3971 case clang::BuiltinType::WChar_S:
3972 case clang::BuiltinType::Short:
3973 case clang::BuiltinType::Int:
3974 case clang::BuiltinType::Long:
3975 case clang::BuiltinType::LongLong:
3976 case clang::BuiltinType::Int128:
3977 case clang::BuiltinType::Float:
3978 case clang::BuiltinType::Double:
3979 case clang::BuiltinType::LongDouble:
3980 builtin_type_flags |= eTypeIsScalar;
3981 if (builtin_type->isInteger())
3983 builtin_type_flags |= eTypeIsInteger;
3984 if (builtin_type->isSignedInteger())
3985 builtin_type_flags |= eTypeIsSigned;
3987 else if (builtin_type->isFloatingPoint())
3988 builtin_type_flags |= eTypeIsFloat;
3993 return builtin_type_flags;
3996 case clang::Type::BlockPointer:
3997 if (pointee_or_element_clang_type)
3998 pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType());
3999 return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock;
4001 case clang::Type::Complex:
4003 uint32_t complex_type_flags = eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex;
4004 const clang::ComplexType *complex_type = llvm::dyn_cast<clang::ComplexType>(qual_type->getCanonicalTypeInternal());
4007 clang::QualType complex_element_type (complex_type->getElementType());
4008 if (complex_element_type->isIntegerType())
4009 complex_type_flags |= eTypeIsFloat;
4010 else if (complex_element_type->isFloatingType())
4011 complex_type_flags |= eTypeIsInteger;
4013 return complex_type_flags;
4017 case clang::Type::ConstantArray:
4018 case clang::Type::DependentSizedArray:
4019 case clang::Type::IncompleteArray:
4020 case clang::Type::VariableArray:
4021 if (pointee_or_element_clang_type)
4022 pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::ArrayType>(qual_type.getTypePtr())->getElementType());
4023 return eTypeHasChildren | eTypeIsArray;
4025 case clang::Type::DependentName: return 0;
4026 case clang::Type::DependentSizedExtVector: return eTypeHasChildren | eTypeIsVector;
4027 case clang::Type::DependentTemplateSpecialization: return eTypeIsTemplate;
4028 case clang::Type::Decltype: return 0;
4030 case clang::Type::Enum:
4031 if (pointee_or_element_clang_type)
4032 pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::EnumType>(qual_type)->getDecl()->getIntegerType());
4033 return eTypeIsEnumeration | eTypeHasValue;
4035 case clang::Type::Auto:
4036 return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetTypeInfo (pointee_or_element_clang_type);
4037 case clang::Type::Elaborated:
4038 return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeInfo (pointee_or_element_clang_type);
4039 case clang::Type::Paren:
4040 return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeInfo (pointee_or_element_clang_type);
4042 case clang::Type::FunctionProto: return eTypeIsFuncPrototype | eTypeHasValue;
4043 case clang::Type::FunctionNoProto: return eTypeIsFuncPrototype | eTypeHasValue;
4044 case clang::Type::InjectedClassName: return 0;
4046 case clang::Type::LValueReference:
4047 case clang::Type::RValueReference:
4048 if (pointee_or_element_clang_type)
4049 pointee_or_element_clang_type->SetCompilerType(getASTContext(), llvm::cast<clang::ReferenceType>(qual_type.getTypePtr())->getPointeeType());
4050 return eTypeHasChildren | eTypeIsReference | eTypeHasValue;
4052 case clang::Type::MemberPointer: return eTypeIsPointer | eTypeIsMember | eTypeHasValue;
4054 case clang::Type::ObjCObjectPointer:
4055 if (pointee_or_element_clang_type)
4056 pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType());
4057 return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | eTypeHasValue;
4059 case clang::Type::ObjCObject: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
4060 case clang::Type::ObjCInterface: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass;
4062 case clang::Type::Pointer:
4063 if (pointee_or_element_clang_type)
4064 pointee_or_element_clang_type->SetCompilerType(getASTContext(), qual_type->getPointeeType());
4065 return eTypeHasChildren | eTypeIsPointer | eTypeHasValue;
4067 case clang::Type::Record:
4068 if (qual_type->getAsCXXRecordDecl())
4069 return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus;
4071 return eTypeHasChildren | eTypeIsStructUnion;
4073 case clang::Type::SubstTemplateTypeParm: return eTypeIsTemplate;
4074 case clang::Type::TemplateTypeParm: return eTypeIsTemplate;
4075 case clang::Type::TemplateSpecialization: return eTypeIsTemplate;
4077 case clang::Type::Typedef:
4078 return eTypeIsTypedef | CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetTypeInfo (pointee_or_element_clang_type);
4079 case clang::Type::TypeOfExpr: return 0;
4080 case clang::Type::TypeOf: return 0;
4081 case clang::Type::UnresolvedUsing: return 0;
4083 case clang::Type::ExtVector:
4084 case clang::Type::Vector:
4086 uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector;
4087 const clang::VectorType *vector_type = llvm::dyn_cast<clang::VectorType>(qual_type->getCanonicalTypeInternal());
4090 if (vector_type->isIntegerType())
4091 vector_type_flags |= eTypeIsFloat;
4092 else if (vector_type->isFloatingType())
4093 vector_type_flags |= eTypeIsInteger;
4095 return vector_type_flags;
4105 ClangASTContext::GetMinimumLanguage (lldb::opaque_compiler_type_t type)
4108 return lldb::eLanguageTypeC;
4110 // If the type is a reference, then resolve it to what it refers to first:
4111 clang::QualType qual_type (GetCanonicalQualType(type).getNonReferenceType());
4112 if (qual_type->isAnyPointerType())
4114 if (qual_type->isObjCObjectPointerType())
4115 return lldb::eLanguageTypeObjC;
4117 clang::QualType pointee_type (qual_type->getPointeeType());
4118 if (pointee_type->getPointeeCXXRecordDecl() != nullptr)
4119 return lldb::eLanguageTypeC_plus_plus;
4120 if (pointee_type->isObjCObjectOrInterfaceType())
4121 return lldb::eLanguageTypeObjC;
4122 if (pointee_type->isObjCClassType())
4123 return lldb::eLanguageTypeObjC;
4124 if (pointee_type.getTypePtr() == getASTContext()->ObjCBuiltinIdTy.getTypePtr())
4125 return lldb::eLanguageTypeObjC;
4129 if (qual_type->isObjCObjectOrInterfaceType())
4130 return lldb::eLanguageTypeObjC;
4131 if (qual_type->getAsCXXRecordDecl())
4132 return lldb::eLanguageTypeC_plus_plus;
4133 switch (qual_type->getTypeClass())
4137 case clang::Type::Builtin:
4138 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
4141 case clang::BuiltinType::Void:
4142 case clang::BuiltinType::Bool:
4143 case clang::BuiltinType::Char_U:
4144 case clang::BuiltinType::UChar:
4145 case clang::BuiltinType::WChar_U:
4146 case clang::BuiltinType::Char16:
4147 case clang::BuiltinType::Char32:
4148 case clang::BuiltinType::UShort:
4149 case clang::BuiltinType::UInt:
4150 case clang::BuiltinType::ULong:
4151 case clang::BuiltinType::ULongLong:
4152 case clang::BuiltinType::UInt128:
4153 case clang::BuiltinType::Char_S:
4154 case clang::BuiltinType::SChar:
4155 case clang::BuiltinType::WChar_S:
4156 case clang::BuiltinType::Short:
4157 case clang::BuiltinType::Int:
4158 case clang::BuiltinType::Long:
4159 case clang::BuiltinType::LongLong:
4160 case clang::BuiltinType::Int128:
4161 case clang::BuiltinType::Float:
4162 case clang::BuiltinType::Double:
4163 case clang::BuiltinType::LongDouble:
4166 case clang::BuiltinType::NullPtr:
4167 return eLanguageTypeC_plus_plus;
4169 case clang::BuiltinType::ObjCId:
4170 case clang::BuiltinType::ObjCClass:
4171 case clang::BuiltinType::ObjCSel:
4172 return eLanguageTypeObjC;
4174 case clang::BuiltinType::Dependent:
4175 case clang::BuiltinType::Overload:
4176 case clang::BuiltinType::BoundMember:
4177 case clang::BuiltinType::UnknownAny:
4181 case clang::Type::Typedef:
4182 return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetMinimumLanguage();
4185 return lldb::eLanguageTypeC;
4189 ClangASTContext::GetTypeClass (lldb::opaque_compiler_type_t type)
4192 return lldb::eTypeClassInvalid;
4194 clang::QualType qual_type(GetQualType(type));
4196 switch (qual_type->getTypeClass())
4198 case clang::Type::UnaryTransform: break;
4199 case clang::Type::FunctionNoProto: return lldb::eTypeClassFunction;
4200 case clang::Type::FunctionProto: return lldb::eTypeClassFunction;
4201 case clang::Type::IncompleteArray: return lldb::eTypeClassArray;
4202 case clang::Type::VariableArray: return lldb::eTypeClassArray;
4203 case clang::Type::ConstantArray: return lldb::eTypeClassArray;
4204 case clang::Type::DependentSizedArray: return lldb::eTypeClassArray;
4205 case clang::Type::DependentSizedExtVector: return lldb::eTypeClassVector;
4206 case clang::Type::ExtVector: return lldb::eTypeClassVector;
4207 case clang::Type::Vector: return lldb::eTypeClassVector;
4208 case clang::Type::Builtin: return lldb::eTypeClassBuiltin;
4209 case clang::Type::ObjCObjectPointer: return lldb::eTypeClassObjCObjectPointer;
4210 case clang::Type::BlockPointer: return lldb::eTypeClassBlockPointer;
4211 case clang::Type::Pointer: return lldb::eTypeClassPointer;
4212 case clang::Type::LValueReference: return lldb::eTypeClassReference;
4213 case clang::Type::RValueReference: return lldb::eTypeClassReference;
4214 case clang::Type::MemberPointer: return lldb::eTypeClassMemberPointer;
4215 case clang::Type::Complex:
4216 if (qual_type->isComplexType())
4217 return lldb::eTypeClassComplexFloat;
4219 return lldb::eTypeClassComplexInteger;
4220 case clang::Type::ObjCObject: return lldb::eTypeClassObjCObject;
4221 case clang::Type::ObjCInterface: return lldb::eTypeClassObjCInterface;
4222 case clang::Type::Record:
4224 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4225 const clang::RecordDecl *record_decl = record_type->getDecl();
4226 if (record_decl->isUnion())
4227 return lldb::eTypeClassUnion;
4228 else if (record_decl->isStruct())
4229 return lldb::eTypeClassStruct;
4231 return lldb::eTypeClassClass;
4234 case clang::Type::Enum: return lldb::eTypeClassEnumeration;
4235 case clang::Type::Typedef: return lldb::eTypeClassTypedef;
4236 case clang::Type::UnresolvedUsing: break;
4237 case clang::Type::Paren:
4238 return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetTypeClass();
4239 case clang::Type::Auto:
4240 return CompilerType(getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetTypeClass();
4241 case clang::Type::Elaborated:
4242 return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetTypeClass();
4244 case clang::Type::Attributed: break;
4245 case clang::Type::TemplateTypeParm: break;
4246 case clang::Type::SubstTemplateTypeParm: break;
4247 case clang::Type::SubstTemplateTypeParmPack:break;
4248 case clang::Type::InjectedClassName: break;
4249 case clang::Type::DependentName: break;
4250 case clang::Type::DependentTemplateSpecialization: break;
4251 case clang::Type::PackExpansion: break;
4253 case clang::Type::TypeOfExpr: break;
4254 case clang::Type::TypeOf: break;
4255 case clang::Type::Decltype: break;
4256 case clang::Type::TemplateSpecialization: break;
4257 case clang::Type::Atomic: break;
4258 case clang::Type::Pipe: break;
4260 // pointer type decayed from an array or function type.
4261 case clang::Type::Decayed: break;
4262 case clang::Type::Adjusted: break;
4264 // We don't know hot to display this type...
4265 return lldb::eTypeClassOther;
4270 ClangASTContext::GetTypeQualifiers(lldb::opaque_compiler_type_t type)
4273 return GetQualType(type).getQualifiers().getCVRQualifiers();
4277 //----------------------------------------------------------------------
4278 // Creating related types
4279 //----------------------------------------------------------------------
4282 ClangASTContext::GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride)
4286 clang::QualType qual_type(GetCanonicalQualType(type));
4288 const clang::Type *array_eletype = qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
4291 return CompilerType();
4293 CompilerType element_type (getASTContext(), array_eletype->getCanonicalTypeUnqualified());
4295 // TODO: the real stride will be >= this value.. find the real one!
4297 *stride = element_type.GetByteSize(nullptr);
4299 return element_type;
4302 return CompilerType();
4306 ClangASTContext::GetCanonicalType (lldb::opaque_compiler_type_t type)
4309 return CompilerType (getASTContext(), GetCanonicalQualType(type));
4310 return CompilerType();
4313 static clang::QualType
4314 GetFullyUnqualifiedType_Impl (clang::ASTContext *ast, clang::QualType qual_type)
4316 if (qual_type->isPointerType())
4317 qual_type = ast->getPointerType(GetFullyUnqualifiedType_Impl(ast, qual_type->getPointeeType()));
4319 qual_type = qual_type.getUnqualifiedType();
4320 qual_type.removeLocalConst();
4321 qual_type.removeLocalRestrict();
4322 qual_type.removeLocalVolatile();
4327 ClangASTContext::GetFullyUnqualifiedType (lldb::opaque_compiler_type_t type)
4330 return CompilerType(getASTContext(), GetFullyUnqualifiedType_Impl(getASTContext(), GetQualType(type)));
4331 return CompilerType();
4336 ClangASTContext::GetFunctionArgumentCount (lldb::opaque_compiler_type_t type)
4340 const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetCanonicalQualType(type));
4342 return func->getNumParams();
4348 ClangASTContext::GetFunctionArgumentTypeAtIndex (lldb::opaque_compiler_type_t type, size_t idx)
4352 const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(GetQualType(type));
4355 const uint32_t num_args = func->getNumParams();
4357 return CompilerType(getASTContext(), func->getParamType(idx));
4360 return CompilerType();
4364 ClangASTContext::GetFunctionReturnType (lldb::opaque_compiler_type_t type)
4368 clang::QualType qual_type(GetQualType(type));
4369 const clang::FunctionProtoType* func = llvm::dyn_cast<clang::FunctionProtoType>(qual_type.getTypePtr());
4371 return CompilerType(getASTContext(), func->getReturnType());
4373 return CompilerType();
4377 ClangASTContext::GetNumMemberFunctions (lldb::opaque_compiler_type_t type)
4379 size_t num_functions = 0;
4382 clang::QualType qual_type(GetCanonicalQualType(type));
4383 switch (qual_type->getTypeClass()) {
4384 case clang::Type::Record:
4385 if (GetCompleteQualType (getASTContext(), qual_type))
4387 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4388 const clang::RecordDecl *record_decl = record_type->getDecl();
4389 assert(record_decl);
4390 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4391 if (cxx_record_decl)
4392 num_functions = std::distance(cxx_record_decl->method_begin(), cxx_record_decl->method_end());
4396 case clang::Type::ObjCObjectPointer:
4397 if (GetCompleteType(type))
4399 const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
4400 if (objc_class_type)
4402 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
4403 if (class_interface_decl)
4404 num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end());
4409 case clang::Type::ObjCObject:
4410 case clang::Type::ObjCInterface:
4411 if (GetCompleteType(type))
4413 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4414 if (objc_class_type)
4416 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
4417 if (class_interface_decl)
4418 num_functions = std::distance(class_interface_decl->meth_begin(), class_interface_decl->meth_end());
4424 case clang::Type::Typedef:
4425 return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumMemberFunctions();
4427 case clang::Type::Auto:
4428 return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumMemberFunctions();
4430 case clang::Type::Elaborated:
4431 return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumMemberFunctions();
4433 case clang::Type::Paren:
4434 return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumMemberFunctions();
4440 return num_functions;
4443 TypeMemberFunctionImpl
4444 ClangASTContext::GetMemberFunctionAtIndex (lldb::opaque_compiler_type_t type, size_t idx)
4447 MemberFunctionKind kind(MemberFunctionKind::eMemberFunctionKindUnknown);
4448 CompilerType clang_type;
4449 CompilerDecl clang_decl;
4452 clang::QualType qual_type(GetCanonicalQualType(type));
4453 switch (qual_type->getTypeClass()) {
4454 case clang::Type::Record:
4455 if (GetCompleteQualType (getASTContext(), qual_type))
4457 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
4458 const clang::RecordDecl *record_decl = record_type->getDecl();
4459 assert(record_decl);
4460 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
4461 if (cxx_record_decl)
4463 auto method_iter = cxx_record_decl->method_begin();
4464 auto method_end = cxx_record_decl->method_end();
4465 if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
4467 std::advance(method_iter, idx);
4468 clang::CXXMethodDecl *cxx_method_decl = method_iter->getCanonicalDecl();
4469 if (cxx_method_decl)
4471 name = cxx_method_decl->getDeclName().getAsString();
4472 if (cxx_method_decl->isStatic())
4473 kind = lldb::eMemberFunctionKindStaticMethod;
4474 else if (llvm::isa<clang::CXXConstructorDecl>(cxx_method_decl))
4475 kind = lldb::eMemberFunctionKindConstructor;
4476 else if (llvm::isa<clang::CXXDestructorDecl>(cxx_method_decl))
4477 kind = lldb::eMemberFunctionKindDestructor;
4479 kind = lldb::eMemberFunctionKindInstanceMethod;
4480 clang_type = CompilerType(this, cxx_method_decl->getType().getAsOpaquePtr());
4481 clang_decl = CompilerDecl(this, cxx_method_decl);
4488 case clang::Type::ObjCObjectPointer:
4489 if (GetCompleteType(type))
4491 const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
4492 if (objc_class_type)
4494 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
4495 if (class_interface_decl)
4497 auto method_iter = class_interface_decl->meth_begin();
4498 auto method_end = class_interface_decl->meth_end();
4499 if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
4501 std::advance(method_iter, idx);
4502 clang::ObjCMethodDecl *objc_method_decl = method_iter->getCanonicalDecl();
4503 if (objc_method_decl)
4505 clang_decl = CompilerDecl(this, objc_method_decl);
4506 name = objc_method_decl->getSelector().getAsString();
4507 if (objc_method_decl->isClassMethod())
4508 kind = lldb::eMemberFunctionKindStaticMethod;
4510 kind = lldb::eMemberFunctionKindInstanceMethod;
4518 case clang::Type::ObjCObject:
4519 case clang::Type::ObjCInterface:
4520 if (GetCompleteType(type))
4522 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
4523 if (objc_class_type)
4525 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
4526 if (class_interface_decl)
4528 auto method_iter = class_interface_decl->meth_begin();
4529 auto method_end = class_interface_decl->meth_end();
4530 if (idx < static_cast<size_t>(std::distance(method_iter, method_end)))
4532 std::advance(method_iter, idx);
4533 clang::ObjCMethodDecl *objc_method_decl = method_iter->getCanonicalDecl();
4534 if (objc_method_decl)
4536 clang_decl = CompilerDecl(this, objc_method_decl);
4537 name = objc_method_decl->getSelector().getAsString();
4538 if (objc_method_decl->isClassMethod())
4539 kind = lldb::eMemberFunctionKindStaticMethod;
4541 kind = lldb::eMemberFunctionKindInstanceMethod;
4549 case clang::Type::Typedef:
4550 return GetMemberFunctionAtIndex(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx);
4552 case clang::Type::Auto:
4553 return GetMemberFunctionAtIndex(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx);
4555 case clang::Type::Elaborated:
4556 return GetMemberFunctionAtIndex(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx);
4558 case clang::Type::Paren:
4559 return GetMemberFunctionAtIndex(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx);
4566 if (kind == eMemberFunctionKindUnknown)
4567 return TypeMemberFunctionImpl();
4569 return TypeMemberFunctionImpl(clang_type, clang_decl, name, kind);
4573 ClangASTContext::GetNonReferenceType (lldb::opaque_compiler_type_t type)
4576 return CompilerType(getASTContext(), GetQualType(type).getNonReferenceType());
4577 return CompilerType();
4581 ClangASTContext::CreateTypedefType (const CompilerType& type,
4582 const char *typedef_name,
4583 const CompilerDeclContext &compiler_decl_ctx)
4585 if (type && typedef_name && typedef_name[0])
4587 ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
4589 return CompilerType();
4590 clang::ASTContext* clang_ast = ast->getASTContext();
4591 clang::QualType qual_type(ClangUtil::GetQualType(type));
4593 clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx);
4594 if (decl_ctx == nullptr)
4595 decl_ctx = ast->getASTContext()->getTranslationUnitDecl();
4597 clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast,
4599 clang::SourceLocation(),
4600 clang::SourceLocation(),
4601 &clang_ast->Idents.get(typedef_name),
4602 clang_ast->getTrivialTypeSourceInfo(qual_type));
4604 decl->setAccess(clang::AS_public); // TODO respect proper access specifier
4606 // Get a uniqued clang::QualType for the typedef decl type
4607 return CompilerType (clang_ast, clang_ast->getTypedefType (decl));
4609 return CompilerType();
4614 ClangASTContext::GetPointeeType (lldb::opaque_compiler_type_t type)
4618 clang::QualType qual_type(GetQualType(type));
4619 return CompilerType (getASTContext(), qual_type.getTypePtr()->getPointeeType());
4621 return CompilerType();
4625 ClangASTContext::GetPointerType (lldb::opaque_compiler_type_t type)
4629 clang::QualType qual_type (GetQualType(type));
4631 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4634 case clang::Type::ObjCObject:
4635 case clang::Type::ObjCInterface:
4636 return CompilerType(getASTContext(), getASTContext()->getObjCObjectPointerType(qual_type));
4639 return CompilerType(getASTContext(), getASTContext()->getPointerType(qual_type));
4642 return CompilerType();
4647 ClangASTContext::GetLValueReferenceType (lldb::opaque_compiler_type_t type)
4650 return CompilerType(this, getASTContext()->getLValueReferenceType(GetQualType(type)).getAsOpaquePtr());
4652 return CompilerType();
4656 ClangASTContext::GetRValueReferenceType (lldb::opaque_compiler_type_t type)
4659 return CompilerType(this, getASTContext()->getRValueReferenceType(GetQualType(type)).getAsOpaquePtr());
4661 return CompilerType();
4665 ClangASTContext::AddConstModifier (lldb::opaque_compiler_type_t type)
4669 clang::QualType result(GetQualType(type));
4671 return CompilerType (this, result.getAsOpaquePtr());
4673 return CompilerType();
4677 ClangASTContext::AddVolatileModifier (lldb::opaque_compiler_type_t type)
4681 clang::QualType result(GetQualType(type));
4682 result.addVolatile();
4683 return CompilerType (this, result.getAsOpaquePtr());
4685 return CompilerType();
4690 ClangASTContext::AddRestrictModifier (lldb::opaque_compiler_type_t type)
4694 clang::QualType result(GetQualType(type));
4695 result.addRestrict();
4696 return CompilerType (this, result.getAsOpaquePtr());
4698 return CompilerType();
4703 ClangASTContext::CreateTypedef (lldb::opaque_compiler_type_t type, const char *typedef_name, const CompilerDeclContext &compiler_decl_ctx)
4707 clang::ASTContext* clang_ast = getASTContext();
4708 clang::QualType qual_type (GetQualType(type));
4710 clang::DeclContext *decl_ctx = ClangASTContext::DeclContextGetAsDeclContext(compiler_decl_ctx);
4711 if (decl_ctx == nullptr)
4712 decl_ctx = getASTContext()->getTranslationUnitDecl();
4714 clang::TypedefDecl *decl = clang::TypedefDecl::Create (*clang_ast,
4716 clang::SourceLocation(),
4717 clang::SourceLocation(),
4718 &clang_ast->Idents.get(typedef_name),
4719 clang_ast->getTrivialTypeSourceInfo(qual_type));
4721 clang::TagDecl *tdecl = nullptr;
4722 if (!qual_type.isNull())
4724 if (const clang::RecordType *rt = qual_type->getAs<clang::RecordType>())
4725 tdecl = rt->getDecl();
4726 if (const clang::EnumType *et = qual_type->getAs<clang::EnumType>())
4727 tdecl = et->getDecl();
4730 // Check whether this declaration is an anonymous struct, union, or enum, hidden behind a typedef. If so, we
4731 // try to check whether we have a typedef tag to attach to the original record declaration
4732 if (tdecl && !tdecl->getIdentifier() && !tdecl->getTypedefNameForAnonDecl())
4733 tdecl->setTypedefNameForAnonDecl(decl);
4735 decl->setAccess(clang::AS_public); // TODO respect proper access specifier
4737 // Get a uniqued clang::QualType for the typedef decl type
4738 return CompilerType (this, clang_ast->getTypedefType (decl).getAsOpaquePtr());
4741 return CompilerType();
4746 ClangASTContext::GetTypedefedType (lldb::opaque_compiler_type_t type)
4750 const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(GetQualType(type));
4752 return CompilerType (getASTContext(), typedef_type->getDecl()->getUnderlyingType());
4754 return CompilerType();
4758 //----------------------------------------------------------------------
4759 // Create related types using the current type's AST
4760 //----------------------------------------------------------------------
4763 ClangASTContext::GetBasicTypeFromAST (lldb::BasicType basic_type)
4765 return ClangASTContext::GetBasicType(getASTContext(), basic_type);
4767 //----------------------------------------------------------------------
4768 // Exploring the type
4769 //----------------------------------------------------------------------
4772 ClangASTContext::GetBitSize (lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope)
4774 if (GetCompleteType (type))
4776 clang::QualType qual_type(GetCanonicalQualType(type));
4777 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
4780 case clang::Type::Record:
4781 if (GetCompleteType(type))
4782 return getASTContext()->getTypeSize(qual_type);
4787 case clang::Type::ObjCInterface:
4788 case clang::Type::ObjCObject:
4790 ExecutionContext exe_ctx (exe_scope);
4791 Process *process = exe_ctx.GetProcessPtr();
4794 ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime();
4797 uint64_t bit_size = 0;
4798 if (objc_runtime->GetTypeBitSize(CompilerType(getASTContext(), qual_type), bit_size))
4804 static bool g_printed = false;
4808 DumpTypeDescription(type, &s);
4810 llvm::outs() << "warning: trying to determine the size of type ";
4811 llvm::outs() << s.GetString() << "\n";
4812 llvm::outs() << "without a valid ExecutionContext. this is not reliable. please file a bug against LLDB.\n";
4813 llvm::outs() << "backtrace:\n";
4814 llvm::sys::PrintStackTrace(llvm::outs());
4815 llvm::outs() << "\n";
4822 const uint32_t bit_size = getASTContext()->getTypeSize (qual_type);
4825 if (qual_type->isIncompleteArrayType())
4826 return getASTContext()->getTypeSize (qual_type->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified());
4828 if (qual_type->isObjCObjectOrInterfaceType())
4829 return bit_size + getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy);
4837 ClangASTContext::GetTypeBitAlign (lldb::opaque_compiler_type_t type)
4839 if (GetCompleteType(type))
4840 return getASTContext()->getTypeAlign(GetQualType(type));
4846 ClangASTContext::GetEncoding (lldb::opaque_compiler_type_t type, uint64_t &count)
4849 return lldb::eEncodingInvalid;
4852 clang::QualType qual_type(GetCanonicalQualType(type));
4854 switch (qual_type->getTypeClass())
4856 case clang::Type::UnaryTransform:
4859 case clang::Type::FunctionNoProto:
4860 case clang::Type::FunctionProto:
4863 case clang::Type::IncompleteArray:
4864 case clang::Type::VariableArray:
4867 case clang::Type::ConstantArray:
4870 case clang::Type::ExtVector:
4871 case clang::Type::Vector:
4872 // TODO: Set this to more than one???
4875 case clang::Type::Builtin:
4876 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
4878 case clang::BuiltinType::Void:
4881 case clang::BuiltinType::Bool:
4882 case clang::BuiltinType::Char_S:
4883 case clang::BuiltinType::SChar:
4884 case clang::BuiltinType::WChar_S:
4885 case clang::BuiltinType::Char16:
4886 case clang::BuiltinType::Char32:
4887 case clang::BuiltinType::Short:
4888 case clang::BuiltinType::Int:
4889 case clang::BuiltinType::Long:
4890 case clang::BuiltinType::LongLong:
4891 case clang::BuiltinType::Int128:
4892 return lldb::eEncodingSint;
4894 case clang::BuiltinType::Char_U:
4895 case clang::BuiltinType::UChar:
4896 case clang::BuiltinType::WChar_U:
4897 case clang::BuiltinType::UShort:
4898 case clang::BuiltinType::UInt:
4899 case clang::BuiltinType::ULong:
4900 case clang::BuiltinType::ULongLong:
4901 case clang::BuiltinType::UInt128:
4902 return lldb::eEncodingUint;
4904 case clang::BuiltinType::Half:
4905 case clang::BuiltinType::Float:
4906 case clang::BuiltinType::Float128:
4907 case clang::BuiltinType::Double:
4908 case clang::BuiltinType::LongDouble:
4909 return lldb::eEncodingIEEE754;
4911 case clang::BuiltinType::ObjCClass:
4912 case clang::BuiltinType::ObjCId:
4913 case clang::BuiltinType::ObjCSel:
4914 return lldb::eEncodingUint;
4916 case clang::BuiltinType::NullPtr:
4917 return lldb::eEncodingUint;
4919 case clang::BuiltinType::Kind::ARCUnbridgedCast:
4920 case clang::BuiltinType::Kind::BoundMember:
4921 case clang::BuiltinType::Kind::BuiltinFn:
4922 case clang::BuiltinType::Kind::Dependent:
4923 case clang::BuiltinType::Kind::OCLClkEvent:
4924 case clang::BuiltinType::Kind::OCLEvent:
4925 case clang::BuiltinType::Kind::OCLImage1dRO:
4926 case clang::BuiltinType::Kind::OCLImage1dWO:
4927 case clang::BuiltinType::Kind::OCLImage1dRW:
4928 case clang::BuiltinType::Kind::OCLImage1dArrayRO:
4929 case clang::BuiltinType::Kind::OCLImage1dArrayWO:
4930 case clang::BuiltinType::Kind::OCLImage1dArrayRW:
4931 case clang::BuiltinType::Kind::OCLImage1dBufferRO:
4932 case clang::BuiltinType::Kind::OCLImage1dBufferWO:
4933 case clang::BuiltinType::Kind::OCLImage1dBufferRW:
4934 case clang::BuiltinType::Kind::OCLImage2dRO:
4935 case clang::BuiltinType::Kind::OCLImage2dWO:
4936 case clang::BuiltinType::Kind::OCLImage2dRW:
4937 case clang::BuiltinType::Kind::OCLImage2dArrayRO:
4938 case clang::BuiltinType::Kind::OCLImage2dArrayWO:
4939 case clang::BuiltinType::Kind::OCLImage2dArrayRW:
4940 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRO:
4941 case clang::BuiltinType::Kind::OCLImage2dArrayDepthWO:
4942 case clang::BuiltinType::Kind::OCLImage2dArrayDepthRW:
4943 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARO:
4944 case clang::BuiltinType::Kind::OCLImage2dArrayMSAAWO:
4945 case clang::BuiltinType::Kind::OCLImage2dArrayMSAARW:
4946 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRO:
4947 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthWO:
4948 case clang::BuiltinType::Kind::OCLImage2dArrayMSAADepthRW:
4949 case clang::BuiltinType::Kind::OCLImage2dDepthRO:
4950 case clang::BuiltinType::Kind::OCLImage2dDepthWO:
4951 case clang::BuiltinType::Kind::OCLImage2dDepthRW:
4952 case clang::BuiltinType::Kind::OCLImage2dMSAARO:
4953 case clang::BuiltinType::Kind::OCLImage2dMSAAWO:
4954 case clang::BuiltinType::Kind::OCLImage2dMSAARW:
4955 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRO:
4956 case clang::BuiltinType::Kind::OCLImage2dMSAADepthWO:
4957 case clang::BuiltinType::Kind::OCLImage2dMSAADepthRW:
4958 case clang::BuiltinType::Kind::OCLImage3dRO:
4959 case clang::BuiltinType::Kind::OCLImage3dWO:
4960 case clang::BuiltinType::Kind::OCLImage3dRW:
4961 case clang::BuiltinType::Kind::OCLQueue:
4962 case clang::BuiltinType::Kind::OCLNDRange:
4963 case clang::BuiltinType::Kind::OCLReserveID:
4964 case clang::BuiltinType::Kind::OCLSampler:
4965 case clang::BuiltinType::Kind::OMPArraySection:
4966 case clang::BuiltinType::Kind::Overload:
4967 case clang::BuiltinType::Kind::PseudoObject:
4968 case clang::BuiltinType::Kind::UnknownAny:
4972 // All pointer types are represented as unsigned integer encodings.
4973 // We may nee to add a eEncodingPointer if we ever need to know the
4975 case clang::Type::ObjCObjectPointer:
4976 case clang::Type::BlockPointer:
4977 case clang::Type::Pointer:
4978 case clang::Type::LValueReference:
4979 case clang::Type::RValueReference:
4980 case clang::Type::MemberPointer: return lldb::eEncodingUint;
4981 case clang::Type::Complex:
4983 lldb::Encoding encoding = lldb::eEncodingIEEE754;
4984 if (qual_type->isComplexType())
4985 encoding = lldb::eEncodingIEEE754;
4988 const clang::ComplexType *complex_type = qual_type->getAsComplexIntegerType();
4990 encoding = CompilerType(getASTContext(), complex_type->getElementType()).GetEncoding(count);
4992 encoding = lldb::eEncodingSint;
4998 case clang::Type::ObjCInterface: break;
4999 case clang::Type::Record: break;
5000 case clang::Type::Enum: return lldb::eEncodingSint;
5001 case clang::Type::Typedef:
5002 return CompilerType(getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetEncoding(count);
5004 case clang::Type::Auto:
5005 return CompilerType(getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetEncoding(count);
5007 case clang::Type::Elaborated:
5008 return CompilerType(getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetEncoding(count);
5010 case clang::Type::Paren:
5011 return CompilerType(getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetEncoding(count);
5013 case clang::Type::DependentSizedArray:
5014 case clang::Type::DependentSizedExtVector:
5015 case clang::Type::UnresolvedUsing:
5016 case clang::Type::Attributed:
5017 case clang::Type::TemplateTypeParm:
5018 case clang::Type::SubstTemplateTypeParm:
5019 case clang::Type::SubstTemplateTypeParmPack:
5020 case clang::Type::InjectedClassName:
5021 case clang::Type::DependentName:
5022 case clang::Type::DependentTemplateSpecialization:
5023 case clang::Type::PackExpansion:
5024 case clang::Type::ObjCObject:
5026 case clang::Type::TypeOfExpr:
5027 case clang::Type::TypeOf:
5028 case clang::Type::Decltype:
5029 case clang::Type::TemplateSpecialization:
5030 case clang::Type::Atomic:
5031 case clang::Type::Adjusted:
5032 case clang::Type::Pipe:
5035 // pointer type decayed from an array or function type.
5036 case clang::Type::Decayed:
5040 return lldb::eEncodingInvalid;
5044 ClangASTContext::GetFormat (lldb::opaque_compiler_type_t type)
5047 return lldb::eFormatDefault;
5049 clang::QualType qual_type(GetCanonicalQualType(type));
5051 switch (qual_type->getTypeClass())
5053 case clang::Type::UnaryTransform:
5056 case clang::Type::FunctionNoProto:
5057 case clang::Type::FunctionProto:
5060 case clang::Type::IncompleteArray:
5061 case clang::Type::VariableArray:
5064 case clang::Type::ConstantArray:
5065 return lldb::eFormatVoid; // no value
5067 case clang::Type::ExtVector:
5068 case clang::Type::Vector:
5071 case clang::Type::Builtin:
5072 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
5074 //default: assert(0 && "Unknown builtin type!");
5075 case clang::BuiltinType::UnknownAny:
5076 case clang::BuiltinType::Void:
5077 case clang::BuiltinType::BoundMember:
5080 case clang::BuiltinType::Bool: return lldb::eFormatBoolean;
5081 case clang::BuiltinType::Char_S:
5082 case clang::BuiltinType::SChar:
5083 case clang::BuiltinType::WChar_S:
5084 case clang::BuiltinType::Char_U:
5085 case clang::BuiltinType::UChar:
5086 case clang::BuiltinType::WChar_U: return lldb::eFormatChar;
5087 case clang::BuiltinType::Char16: return lldb::eFormatUnicode16;
5088 case clang::BuiltinType::Char32: return lldb::eFormatUnicode32;
5089 case clang::BuiltinType::UShort: return lldb::eFormatUnsigned;
5090 case clang::BuiltinType::Short: return lldb::eFormatDecimal;
5091 case clang::BuiltinType::UInt: return lldb::eFormatUnsigned;
5092 case clang::BuiltinType::Int: return lldb::eFormatDecimal;
5093 case clang::BuiltinType::ULong: return lldb::eFormatUnsigned;
5094 case clang::BuiltinType::Long: return lldb::eFormatDecimal;
5095 case clang::BuiltinType::ULongLong: return lldb::eFormatUnsigned;
5096 case clang::BuiltinType::LongLong: return lldb::eFormatDecimal;
5097 case clang::BuiltinType::UInt128: return lldb::eFormatUnsigned;
5098 case clang::BuiltinType::Int128: return lldb::eFormatDecimal;
5099 case clang::BuiltinType::Half:
5100 case clang::BuiltinType::Float:
5101 case clang::BuiltinType::Double:
5102 case clang::BuiltinType::LongDouble: return lldb::eFormatFloat;
5104 return lldb::eFormatHex;
5107 case clang::Type::ObjCObjectPointer: return lldb::eFormatHex;
5108 case clang::Type::BlockPointer: return lldb::eFormatHex;
5109 case clang::Type::Pointer: return lldb::eFormatHex;
5110 case clang::Type::LValueReference:
5111 case clang::Type::RValueReference: return lldb::eFormatHex;
5112 case clang::Type::MemberPointer: break;
5113 case clang::Type::Complex:
5115 if (qual_type->isComplexType())
5116 return lldb::eFormatComplex;
5118 return lldb::eFormatComplexInteger;
5120 case clang::Type::ObjCInterface: break;
5121 case clang::Type::Record: break;
5122 case clang::Type::Enum: return lldb::eFormatEnum;
5123 case clang::Type::Typedef:
5124 return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetFormat();
5125 case clang::Type::Auto:
5126 return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->desugar()).GetFormat();
5127 case clang::Type::Paren:
5128 return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetFormat();
5129 case clang::Type::Elaborated:
5130 return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetFormat();
5131 case clang::Type::DependentSizedArray:
5132 case clang::Type::DependentSizedExtVector:
5133 case clang::Type::UnresolvedUsing:
5134 case clang::Type::Attributed:
5135 case clang::Type::TemplateTypeParm:
5136 case clang::Type::SubstTemplateTypeParm:
5137 case clang::Type::SubstTemplateTypeParmPack:
5138 case clang::Type::InjectedClassName:
5139 case clang::Type::DependentName:
5140 case clang::Type::DependentTemplateSpecialization:
5141 case clang::Type::PackExpansion:
5142 case clang::Type::ObjCObject:
5144 case clang::Type::TypeOfExpr:
5145 case clang::Type::TypeOf:
5146 case clang::Type::Decltype:
5147 case clang::Type::TemplateSpecialization:
5148 case clang::Type::Atomic:
5149 case clang::Type::Adjusted:
5150 case clang::Type::Pipe:
5153 // pointer type decayed from an array or function type.
5154 case clang::Type::Decayed:
5157 // We don't know hot to display this type...
5158 return lldb::eFormatBytes;
5162 ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl, bool check_superclass)
5164 while (class_interface_decl)
5166 if (class_interface_decl->ivar_size() > 0)
5169 if (check_superclass)
5170 class_interface_decl = class_interface_decl->getSuperClass();
5178 ClangASTContext::GetNumChildren (lldb::opaque_compiler_type_t type, bool omit_empty_base_classes)
5183 uint32_t num_children = 0;
5184 clang::QualType qual_type(GetQualType(type));
5185 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5188 case clang::Type::Builtin:
5189 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
5191 case clang::BuiltinType::ObjCId: // child is Class
5192 case clang::BuiltinType::ObjCClass: // child is Class
5201 case clang::Type::Complex: return 0;
5203 case clang::Type::Record:
5204 if (GetCompleteQualType (getASTContext(), qual_type))
5206 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5207 const clang::RecordDecl *record_decl = record_type->getDecl();
5208 assert(record_decl);
5209 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
5210 if (cxx_record_decl)
5212 if (omit_empty_base_classes)
5214 // Check each base classes to see if it or any of its
5215 // base classes contain any fields. This can help
5216 // limit the noise in variable views by not having to
5217 // show base classes that contain no members.
5218 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
5219 for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
5220 base_class != base_class_end;
5223 const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
5225 // Skip empty base classes
5226 if (ClangASTContext::RecordHasFields(base_class_decl) == false)
5234 // Include all base classes
5235 num_children += cxx_record_decl->getNumBases();
5239 clang::RecordDecl::field_iterator field, field_end;
5240 for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field)
5245 case clang::Type::ObjCObject:
5246 case clang::Type::ObjCInterface:
5247 if (GetCompleteQualType (getASTContext(), qual_type))
5249 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5250 assert (objc_class_type);
5251 if (objc_class_type)
5253 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
5255 if (class_interface_decl)
5258 clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
5259 if (superclass_interface_decl)
5261 if (omit_empty_base_classes)
5263 if (ObjCDeclHasIVars (superclass_interface_decl, true))
5270 num_children += class_interface_decl->ivar_size();
5276 case clang::Type::ObjCObjectPointer:
5278 const clang::ObjCObjectPointerType *pointer_type = llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr());
5279 clang::QualType pointee_type = pointer_type->getPointeeType();
5280 uint32_t num_pointee_children = CompilerType (getASTContext(),pointee_type).GetNumChildren (omit_empty_base_classes);
5281 // If this type points to a simple type, then it has 1 child
5282 if (num_pointee_children == 0)
5285 num_children = num_pointee_children;
5289 case clang::Type::Vector:
5290 case clang::Type::ExtVector:
5291 num_children = llvm::cast<clang::VectorType>(qual_type.getTypePtr())->getNumElements();
5294 case clang::Type::ConstantArray:
5295 num_children = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr())->getSize().getLimitedValue();
5298 case clang::Type::Pointer:
5300 const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr());
5301 clang::QualType pointee_type (pointer_type->getPointeeType());
5302 uint32_t num_pointee_children = CompilerType (getASTContext(),pointee_type).GetNumChildren (omit_empty_base_classes);
5303 if (num_pointee_children == 0)
5305 // We have a pointer to a pointee type that claims it has no children.
5306 // We will want to look at
5307 num_children = GetNumPointeeChildren (pointee_type);
5310 num_children = num_pointee_children;
5314 case clang::Type::LValueReference:
5315 case clang::Type::RValueReference:
5317 const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
5318 clang::QualType pointee_type = reference_type->getPointeeType();
5319 uint32_t num_pointee_children = CompilerType (getASTContext(), pointee_type).GetNumChildren (omit_empty_base_classes);
5320 // If this type points to a simple type, then it has 1 child
5321 if (num_pointee_children == 0)
5324 num_children = num_pointee_children;
5329 case clang::Type::Typedef:
5330 num_children = CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumChildren (omit_empty_base_classes);
5333 case clang::Type::Auto:
5334 num_children = CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumChildren (omit_empty_base_classes);
5337 case clang::Type::Elaborated:
5338 num_children = CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumChildren (omit_empty_base_classes);
5341 case clang::Type::Paren:
5342 num_children = CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumChildren (omit_empty_base_classes);
5347 return num_children;
5351 ClangASTContext::GetBuiltinTypeByName (const ConstString &name)
5353 return GetBasicType(GetBasicTypeEnumeration(name));
5357 ClangASTContext::GetBasicTypeEnumeration (lldb::opaque_compiler_type_t type)
5361 clang::QualType qual_type(GetQualType(type));
5362 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5363 if (type_class == clang::Type::Builtin)
5365 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
5367 case clang::BuiltinType::Void: return eBasicTypeVoid;
5368 case clang::BuiltinType::Bool: return eBasicTypeBool;
5369 case clang::BuiltinType::Char_S: return eBasicTypeSignedChar;
5370 case clang::BuiltinType::Char_U: return eBasicTypeUnsignedChar;
5371 case clang::BuiltinType::Char16: return eBasicTypeChar16;
5372 case clang::BuiltinType::Char32: return eBasicTypeChar32;
5373 case clang::BuiltinType::UChar: return eBasicTypeUnsignedChar;
5374 case clang::BuiltinType::SChar: return eBasicTypeSignedChar;
5375 case clang::BuiltinType::WChar_S: return eBasicTypeSignedWChar;
5376 case clang::BuiltinType::WChar_U: return eBasicTypeUnsignedWChar;
5377 case clang::BuiltinType::Short: return eBasicTypeShort;
5378 case clang::BuiltinType::UShort: return eBasicTypeUnsignedShort;
5379 case clang::BuiltinType::Int: return eBasicTypeInt;
5380 case clang::BuiltinType::UInt: return eBasicTypeUnsignedInt;
5381 case clang::BuiltinType::Long: return eBasicTypeLong;
5382 case clang::BuiltinType::ULong: return eBasicTypeUnsignedLong;
5383 case clang::BuiltinType::LongLong: return eBasicTypeLongLong;
5384 case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong;
5385 case clang::BuiltinType::Int128: return eBasicTypeInt128;
5386 case clang::BuiltinType::UInt128: return eBasicTypeUnsignedInt128;
5388 case clang::BuiltinType::Half: return eBasicTypeHalf;
5389 case clang::BuiltinType::Float: return eBasicTypeFloat;
5390 case clang::BuiltinType::Double: return eBasicTypeDouble;
5391 case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble;
5393 case clang::BuiltinType::NullPtr: return eBasicTypeNullPtr;
5394 case clang::BuiltinType::ObjCId: return eBasicTypeObjCID;
5395 case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass;
5396 case clang::BuiltinType::ObjCSel: return eBasicTypeObjCSel;
5398 return eBasicTypeOther;
5402 return eBasicTypeInvalid;
5406 ClangASTContext::ForEachEnumerator (lldb::opaque_compiler_type_t type, std::function <bool (const CompilerType &integer_type, const ConstString &name, const llvm::APSInt &value)> const &callback)
5408 const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type));
5411 const clang::EnumDecl *enum_decl = enum_type->getDecl();
5414 CompilerType integer_type(this, enum_decl->getIntegerType().getAsOpaquePtr());
5416 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
5417 for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
5419 ConstString name(enum_pos->getNameAsString().c_str());
5420 if (!callback (integer_type, name, enum_pos->getInitVal()))
5428 #pragma mark Aggregate Types
5431 ClangASTContext::GetNumFields (lldb::opaque_compiler_type_t type)
5437 clang::QualType qual_type(GetCanonicalQualType(type));
5438 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5441 case clang::Type::Record:
5442 if (GetCompleteType(type))
5444 const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
5447 clang::RecordDecl *record_decl = record_type->getDecl();
5450 uint32_t field_idx = 0;
5451 clang::RecordDecl::field_iterator field, field_end;
5452 for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field)
5460 case clang::Type::Typedef:
5461 count = CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetNumFields();
5464 case clang::Type::Auto:
5465 count = CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetNumFields();
5468 case clang::Type::Elaborated:
5469 count = CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetNumFields();
5472 case clang::Type::Paren:
5473 count = CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetNumFields();
5476 case clang::Type::ObjCObjectPointer:
5477 if (GetCompleteType(type))
5479 const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
5480 if (objc_class_type)
5482 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
5484 if (class_interface_decl)
5485 count = class_interface_decl->ivar_size();
5490 case clang::Type::ObjCObject:
5491 case clang::Type::ObjCInterface:
5492 if (GetCompleteType(type))
5494 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5495 if (objc_class_type)
5497 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
5499 if (class_interface_decl)
5500 count = class_interface_decl->ivar_size();
5511 static lldb::opaque_compiler_type_t
5512 GetObjCFieldAtIndex (clang::ASTContext *ast,
5513 clang::ObjCInterfaceDecl *class_interface_decl,
5516 uint64_t *bit_offset_ptr,
5517 uint32_t *bitfield_bit_size_ptr,
5518 bool *is_bitfield_ptr)
5520 if (class_interface_decl)
5522 if (idx < (class_interface_decl->ivar_size()))
5524 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
5525 uint32_t ivar_idx = 0;
5527 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++ivar_idx)
5529 if (ivar_idx == idx)
5531 const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
5533 clang::QualType ivar_qual_type(ivar_decl->getType());
5535 name.assign(ivar_decl->getNameAsString());
5539 const clang::ASTRecordLayout &interface_layout = ast->getASTObjCInterfaceLayout(class_interface_decl);
5540 *bit_offset_ptr = interface_layout.getFieldOffset (ivar_idx);
5543 const bool is_bitfield = ivar_pos->isBitField();
5545 if (bitfield_bit_size_ptr)
5547 *bitfield_bit_size_ptr = 0;
5549 if (is_bitfield && ast)
5551 clang::Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth();
5552 llvm::APSInt bitfield_apsint;
5553 if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *ast))
5555 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5559 if (is_bitfield_ptr)
5560 *is_bitfield_ptr = is_bitfield;
5562 return ivar_qual_type.getAsOpaquePtr();
5571 ClangASTContext::GetFieldAtIndex (lldb::opaque_compiler_type_t type, size_t idx,
5573 uint64_t *bit_offset_ptr,
5574 uint32_t *bitfield_bit_size_ptr,
5575 bool *is_bitfield_ptr)
5578 return CompilerType();
5580 clang::QualType qual_type(GetCanonicalQualType(type));
5581 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5584 case clang::Type::Record:
5585 if (GetCompleteType(type))
5587 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
5588 const clang::RecordDecl *record_decl = record_type->getDecl();
5589 uint32_t field_idx = 0;
5590 clang::RecordDecl::field_iterator field, field_end;
5591 for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx)
5593 if (idx == field_idx)
5595 // Print the member type if requested
5596 // Print the member name and equal sign
5597 name.assign(field->getNameAsString());
5599 // Figure out the type byte size (field_type_info.first) and
5600 // alignment (field_type_info.second) from the AST context.
5603 const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl);
5604 *bit_offset_ptr = record_layout.getFieldOffset (field_idx);
5607 const bool is_bitfield = field->isBitField();
5609 if (bitfield_bit_size_ptr)
5611 *bitfield_bit_size_ptr = 0;
5615 clang::Expr *bitfield_bit_size_expr = field->getBitWidth();
5616 llvm::APSInt bitfield_apsint;
5617 if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *getASTContext()))
5619 *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue();
5623 if (is_bitfield_ptr)
5624 *is_bitfield_ptr = is_bitfield;
5626 return CompilerType (getASTContext(), field->getType());
5632 case clang::Type::ObjCObjectPointer:
5633 if (GetCompleteType(type))
5635 const clang::ObjCObjectPointerType *objc_class_type = qual_type->getAsObjCInterfacePointerType();
5636 if (objc_class_type)
5638 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterfaceDecl();
5639 return CompilerType (this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
5644 case clang::Type::ObjCObject:
5645 case clang::Type::ObjCInterface:
5646 if (GetCompleteType(type))
5648 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
5649 assert (objc_class_type);
5650 if (objc_class_type)
5652 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
5653 return CompilerType (this, GetObjCFieldAtIndex(getASTContext(), class_interface_decl, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
5659 case clang::Type::Typedef:
5660 return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).
5661 GetFieldAtIndex (idx,
5664 bitfield_bit_size_ptr,
5667 case clang::Type::Auto:
5668 return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).
5669 GetFieldAtIndex (idx,
5672 bitfield_bit_size_ptr,
5675 case clang::Type::Elaborated:
5676 return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).
5677 GetFieldAtIndex (idx,
5680 bitfield_bit_size_ptr,
5683 case clang::Type::Paren:
5684 return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).
5685 GetFieldAtIndex (idx,
5688 bitfield_bit_size_ptr,
5694 return CompilerType();
5698 ClangASTContext::GetNumDirectBaseClasses (lldb::opaque_compiler_type_t type)
5701 clang::QualType qual_type(GetCanonicalQualType(type));
5702 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5705 case clang::Type::Record:
5706 if (GetCompleteType(type))
5708 const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
5709 if (cxx_record_decl)
5710 count = cxx_record_decl->getNumBases();
5714 case clang::Type::ObjCObjectPointer:
5715 count = GetPointeeType(type).GetNumDirectBaseClasses();
5718 case clang::Type::ObjCObject:
5719 if (GetCompleteType(type))
5721 const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
5722 if (objc_class_type)
5724 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
5726 if (class_interface_decl && class_interface_decl->getSuperClass())
5731 case clang::Type::ObjCInterface:
5732 if (GetCompleteType(type))
5734 const clang::ObjCInterfaceType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>();
5735 if (objc_interface_type)
5737 clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface();
5739 if (class_interface_decl && class_interface_decl->getSuperClass())
5746 case clang::Type::Typedef:
5747 count = GetNumDirectBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
5750 case clang::Type::Auto:
5751 count = GetNumDirectBaseClasses(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
5754 case clang::Type::Elaborated:
5755 count = GetNumDirectBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
5758 case clang::Type::Paren:
5759 return GetNumDirectBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
5769 ClangASTContext::GetNumVirtualBaseClasses (lldb::opaque_compiler_type_t type)
5772 clang::QualType qual_type(GetCanonicalQualType(type));
5773 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5776 case clang::Type::Record:
5777 if (GetCompleteType(type))
5779 const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
5780 if (cxx_record_decl)
5781 count = cxx_record_decl->getNumVBases();
5785 case clang::Type::Typedef:
5786 count = GetNumVirtualBaseClasses(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
5789 case clang::Type::Auto:
5790 count = GetNumVirtualBaseClasses(llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr());
5793 case clang::Type::Elaborated:
5794 count = GetNumVirtualBaseClasses(llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr());
5797 case clang::Type::Paren:
5798 count = GetNumVirtualBaseClasses(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr());
5809 ClangASTContext::GetDirectBaseClassAtIndex (lldb::opaque_compiler_type_t type, size_t idx, uint32_t *bit_offset_ptr)
5811 clang::QualType qual_type(GetCanonicalQualType(type));
5812 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5815 case clang::Type::Record:
5816 if (GetCompleteType(type))
5818 const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
5819 if (cxx_record_decl)
5821 uint32_t curr_idx = 0;
5822 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
5823 for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
5824 base_class != base_class_end;
5825 ++base_class, ++curr_idx)
5827 if (curr_idx == idx)
5831 const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl);
5832 const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
5833 if (base_class->isVirtual())
5834 *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
5836 *bit_offset_ptr = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
5838 return CompilerType (this, base_class->getType().getAsOpaquePtr());
5845 case clang::Type::ObjCObjectPointer:
5846 return GetPointeeType(type).GetDirectBaseClassAtIndex(idx, bit_offset_ptr);
5848 case clang::Type::ObjCObject:
5849 if (idx == 0 && GetCompleteType(type))
5851 const clang::ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType();
5852 if (objc_class_type)
5854 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
5856 if (class_interface_decl)
5858 clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
5859 if (superclass_interface_decl)
5862 *bit_offset_ptr = 0;
5863 return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl));
5869 case clang::Type::ObjCInterface:
5870 if (idx == 0 && GetCompleteType(type))
5872 const clang::ObjCObjectType *objc_interface_type = qual_type->getAs<clang::ObjCInterfaceType>();
5873 if (objc_interface_type)
5875 clang::ObjCInterfaceDecl *class_interface_decl = objc_interface_type->getInterface();
5877 if (class_interface_decl)
5879 clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
5880 if (superclass_interface_decl)
5883 *bit_offset_ptr = 0;
5884 return CompilerType (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl));
5892 case clang::Type::Typedef:
5893 return GetDirectBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr);
5895 case clang::Type::Auto:
5896 return GetDirectBaseClassAtIndex (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx, bit_offset_ptr);
5898 case clang::Type::Elaborated:
5899 return GetDirectBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr);
5901 case clang::Type::Paren:
5902 return GetDirectBaseClassAtIndex (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx, bit_offset_ptr);
5907 return CompilerType();
5911 ClangASTContext::GetVirtualBaseClassAtIndex (lldb::opaque_compiler_type_t type,
5913 uint32_t *bit_offset_ptr)
5915 clang::QualType qual_type(GetCanonicalQualType(type));
5916 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5919 case clang::Type::Record:
5920 if (GetCompleteType(type))
5922 const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
5923 if (cxx_record_decl)
5925 uint32_t curr_idx = 0;
5926 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
5927 for (base_class = cxx_record_decl->vbases_begin(), base_class_end = cxx_record_decl->vbases_end();
5928 base_class != base_class_end;
5929 ++base_class, ++curr_idx)
5931 if (curr_idx == idx)
5935 const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(cxx_record_decl);
5936 const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
5937 *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
5940 return CompilerType (this, base_class->getType().getAsOpaquePtr());
5947 case clang::Type::Typedef:
5948 return GetVirtualBaseClassAtIndex (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), idx, bit_offset_ptr);
5950 case clang::Type::Auto:
5951 return GetVirtualBaseClassAtIndex (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), idx, bit_offset_ptr);
5953 case clang::Type::Elaborated:
5954 return GetVirtualBaseClassAtIndex (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), idx, bit_offset_ptr);
5956 case clang::Type::Paren:
5957 return GetVirtualBaseClassAtIndex(llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), idx,
5963 return CompilerType();
5967 // If a pointer to a pointee type (the clang_type arg) says that it has no
5968 // children, then we either need to trust it, or override it and return a
5969 // different result. For example, an "int *" has one child that is an integer,
5970 // but a function pointer doesn't have any children. Likewise if a Record type
5971 // claims it has no children, then there really is nothing to show.
5973 ClangASTContext::GetNumPointeeChildren (clang::QualType type)
5978 clang::QualType qual_type(type.getCanonicalType());
5979 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
5982 case clang::Type::Builtin:
5983 switch (llvm::cast<clang::BuiltinType>(qual_type)->getKind())
5985 case clang::BuiltinType::UnknownAny:
5986 case clang::BuiltinType::Void:
5987 case clang::BuiltinType::NullPtr:
5988 case clang::BuiltinType::OCLEvent:
5989 case clang::BuiltinType::OCLImage1dRO:
5990 case clang::BuiltinType::OCLImage1dWO:
5991 case clang::BuiltinType::OCLImage1dRW:
5992 case clang::BuiltinType::OCLImage1dArrayRO:
5993 case clang::BuiltinType::OCLImage1dArrayWO:
5994 case clang::BuiltinType::OCLImage1dArrayRW:
5995 case clang::BuiltinType::OCLImage1dBufferRO:
5996 case clang::BuiltinType::OCLImage1dBufferWO:
5997 case clang::BuiltinType::OCLImage1dBufferRW:
5998 case clang::BuiltinType::OCLImage2dRO:
5999 case clang::BuiltinType::OCLImage2dWO:
6000 case clang::BuiltinType::OCLImage2dRW:
6001 case clang::BuiltinType::OCLImage2dArrayRO:
6002 case clang::BuiltinType::OCLImage2dArrayWO:
6003 case clang::BuiltinType::OCLImage2dArrayRW:
6004 case clang::BuiltinType::OCLImage3dRO:
6005 case clang::BuiltinType::OCLImage3dWO:
6006 case clang::BuiltinType::OCLImage3dRW:
6007 case clang::BuiltinType::OCLSampler:
6009 case clang::BuiltinType::Bool:
6010 case clang::BuiltinType::Char_U:
6011 case clang::BuiltinType::UChar:
6012 case clang::BuiltinType::WChar_U:
6013 case clang::BuiltinType::Char16:
6014 case clang::BuiltinType::Char32:
6015 case clang::BuiltinType::UShort:
6016 case clang::BuiltinType::UInt:
6017 case clang::BuiltinType::ULong:
6018 case clang::BuiltinType::ULongLong:
6019 case clang::BuiltinType::UInt128:
6020 case clang::BuiltinType::Char_S:
6021 case clang::BuiltinType::SChar:
6022 case clang::BuiltinType::WChar_S:
6023 case clang::BuiltinType::Short:
6024 case clang::BuiltinType::Int:
6025 case clang::BuiltinType::Long:
6026 case clang::BuiltinType::LongLong:
6027 case clang::BuiltinType::Int128:
6028 case clang::BuiltinType::Float:
6029 case clang::BuiltinType::Double:
6030 case clang::BuiltinType::LongDouble:
6031 case clang::BuiltinType::Dependent:
6032 case clang::BuiltinType::Overload:
6033 case clang::BuiltinType::ObjCId:
6034 case clang::BuiltinType::ObjCClass:
6035 case clang::BuiltinType::ObjCSel:
6036 case clang::BuiltinType::BoundMember:
6037 case clang::BuiltinType::Half:
6038 case clang::BuiltinType::ARCUnbridgedCast:
6039 case clang::BuiltinType::PseudoObject:
6040 case clang::BuiltinType::BuiltinFn:
6041 case clang::BuiltinType::OMPArraySection:
6048 case clang::Type::Complex: return 1;
6049 case clang::Type::Pointer: return 1;
6050 case clang::Type::BlockPointer: return 0; // If block pointers don't have debug info, then no children for them
6051 case clang::Type::LValueReference: return 1;
6052 case clang::Type::RValueReference: return 1;
6053 case clang::Type::MemberPointer: return 0;
6054 case clang::Type::ConstantArray: return 0;
6055 case clang::Type::IncompleteArray: return 0;
6056 case clang::Type::VariableArray: return 0;
6057 case clang::Type::DependentSizedArray: return 0;
6058 case clang::Type::DependentSizedExtVector: return 0;
6059 case clang::Type::Vector: return 0;
6060 case clang::Type::ExtVector: return 0;
6061 case clang::Type::FunctionProto: return 0; // When we function pointers, they have no children...
6062 case clang::Type::FunctionNoProto: return 0; // When we function pointers, they have no children...
6063 case clang::Type::UnresolvedUsing: return 0;
6064 case clang::Type::Paren: return GetNumPointeeChildren (llvm::cast<clang::ParenType>(qual_type)->desugar());
6065 case clang::Type::Typedef: return GetNumPointeeChildren (llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType());
6066 case clang::Type::Auto: return GetNumPointeeChildren (llvm::cast<clang::AutoType>(qual_type)->getDeducedType());
6067 case clang::Type::Elaborated: return GetNumPointeeChildren (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType());
6068 case clang::Type::TypeOfExpr: return 0;
6069 case clang::Type::TypeOf: return 0;
6070 case clang::Type::Decltype: return 0;
6071 case clang::Type::Record: return 0;
6072 case clang::Type::Enum: return 1;
6073 case clang::Type::TemplateTypeParm: return 1;
6074 case clang::Type::SubstTemplateTypeParm: return 1;
6075 case clang::Type::TemplateSpecialization: return 1;
6076 case clang::Type::InjectedClassName: return 0;
6077 case clang::Type::DependentName: return 1;
6078 case clang::Type::DependentTemplateSpecialization: return 1;
6079 case clang::Type::ObjCObject: return 0;
6080 case clang::Type::ObjCInterface: return 0;
6081 case clang::Type::ObjCObjectPointer: return 1;
6090 ClangASTContext::GetChildCompilerTypeAtIndex (lldb::opaque_compiler_type_t type,
6091 ExecutionContext *exe_ctx,
6093 bool transparent_pointers,
6094 bool omit_empty_base_classes,
6095 bool ignore_array_bounds,
6096 std::string& child_name,
6097 uint32_t &child_byte_size,
6098 int32_t &child_byte_offset,
6099 uint32_t &child_bitfield_bit_size,
6100 uint32_t &child_bitfield_bit_offset,
6101 bool &child_is_base_class,
6102 bool &child_is_deref_of_parent,
6103 ValueObject *valobj,
6104 uint64_t &language_flags)
6107 return CompilerType();
6109 clang::QualType parent_qual_type(GetCanonicalQualType(type));
6110 const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass();
6111 child_bitfield_bit_size = 0;
6112 child_bitfield_bit_offset = 0;
6113 child_is_base_class = false;
6116 const bool idx_is_valid = idx < GetNumChildren (type, omit_empty_base_classes);
6117 uint32_t bit_offset;
6118 switch (parent_type_class)
6120 case clang::Type::Builtin:
6123 switch (llvm::cast<clang::BuiltinType>(parent_qual_type)->getKind())
6125 case clang::BuiltinType::ObjCId:
6126 case clang::BuiltinType::ObjCClass:
6128 child_byte_size = getASTContext()->getTypeSize(getASTContext()->ObjCBuiltinClassTy) / CHAR_BIT;
6129 return CompilerType (getASTContext(), getASTContext()->ObjCBuiltinClassTy);
6137 case clang::Type::Record:
6138 if (idx_is_valid && GetCompleteType(type))
6140 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(parent_qual_type.getTypePtr());
6141 const clang::RecordDecl *record_decl = record_type->getDecl();
6142 assert(record_decl);
6143 const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl);
6144 uint32_t child_idx = 0;
6146 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6147 if (cxx_record_decl)
6149 // We might have base classes to print out first
6150 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
6151 for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
6152 base_class != base_class_end;
6155 const clang::CXXRecordDecl *base_class_decl = nullptr;
6157 // Skip empty base classes
6158 if (omit_empty_base_classes)
6160 base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
6161 if (ClangASTContext::RecordHasFields(base_class_decl) == false)
6165 if (idx == child_idx)
6167 if (base_class_decl == nullptr)
6168 base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
6171 if (base_class->isVirtual())
6173 bool handled = false;
6177 AddressType addr_type = eAddressTypeInvalid;
6178 lldb::addr_t vtable_ptr_addr = valobj->GetCPPVTableAddress(addr_type);
6180 if (vtable_ptr_addr != LLDB_INVALID_ADDRESS && addr_type == eAddressTypeLoad)
6183 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
6184 Process *process = exe_ctx.GetProcessPtr();
6187 clang::VTableContextBase *vtable_ctx = getASTContext()->getVTableContext();
6190 if (vtable_ctx->isMicrosoft())
6192 clang::MicrosoftVTableContext *msoft_vtable_ctx = static_cast<clang::MicrosoftVTableContext *>(vtable_ctx);
6194 if (vtable_ptr_addr)
6196 const lldb::addr_t vbtable_ptr_addr = vtable_ptr_addr + record_layout.getVBPtrOffset().getQuantity();
6198 const lldb::addr_t vbtable_ptr = process->ReadPointerFromMemory(vbtable_ptr_addr, err);
6199 if (vbtable_ptr != LLDB_INVALID_ADDRESS)
6201 // Get the index into the virtual base table. The index is the index in uint32_t from vbtable_ptr
6202 const unsigned vbtable_index = msoft_vtable_ctx->getVBTableIndex(cxx_record_decl, base_class_decl);
6203 const lldb::addr_t base_offset_addr = vbtable_ptr + vbtable_index * 4;
6204 const uint32_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, 4, UINT32_MAX, err);
6205 if (base_offset != UINT32_MAX)
6208 bit_offset = base_offset * 8;
6215 clang::ItaniumVTableContext *itanium_vtable_ctx = static_cast<clang::ItaniumVTableContext *>(vtable_ctx);
6216 if (vtable_ptr_addr)
6218 const lldb::addr_t vtable_ptr = process->ReadPointerFromMemory(vtable_ptr_addr, err);
6219 if (vtable_ptr != LLDB_INVALID_ADDRESS)
6221 clang::CharUnits base_offset_offset = itanium_vtable_ctx->getVirtualBaseOffsetOffset(cxx_record_decl, base_class_decl);
6222 const lldb::addr_t base_offset_addr = vtable_ptr + base_offset_offset.getQuantity();
6223 const uint32_t base_offset_size = process->GetAddressByteSize();
6224 const uint64_t base_offset = process->ReadUnsignedIntegerFromMemory(base_offset_addr, base_offset_size, UINT32_MAX, err);
6225 if (base_offset < UINT32_MAX)
6228 bit_offset = base_offset * 8;
6239 bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
6242 bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
6244 // Base classes should be a multiple of 8 bits in size
6245 child_byte_offset = bit_offset/8;
6246 CompilerType base_class_clang_type(getASTContext(), base_class->getType());
6247 child_name = base_class_clang_type.GetTypeName().AsCString("");
6248 uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
6250 // Base classes bit sizes should be a multiple of 8 bits in size
6251 assert (base_class_clang_type_bit_size % 8 == 0);
6252 child_byte_size = base_class_clang_type_bit_size / 8;
6253 child_is_base_class = true;
6254 return base_class_clang_type;
6256 // We don't increment the child index in the for loop since we might
6257 // be skipping empty base classes
6261 // Make sure index is in range...
6262 uint32_t field_idx = 0;
6263 clang::RecordDecl::field_iterator field, field_end;
6264 for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx)
6266 if (idx == child_idx)
6268 // Print the member type if requested
6269 // Print the member name and equal sign
6270 child_name.assign(field->getNameAsString().c_str());
6272 // Figure out the type byte size (field_type_info.first) and
6273 // alignment (field_type_info.second) from the AST context.
6274 CompilerType field_clang_type (getASTContext(), field->getType());
6275 assert(field_idx < record_layout.getFieldCount());
6276 child_byte_size = field_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
6277 const uint32_t child_bit_size = child_byte_size * 8;
6279 // Figure out the field offset within the current struct/union/class type
6280 bit_offset = record_layout.getFieldOffset (field_idx);
6281 if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, child_bitfield_bit_size))
6283 child_bitfield_bit_offset = bit_offset % child_bit_size;
6284 const uint32_t child_bit_offset = bit_offset - child_bitfield_bit_offset;
6285 child_byte_offset = child_bit_offset / 8;
6289 child_byte_offset = bit_offset / 8;
6292 return field_clang_type;
6298 case clang::Type::ObjCObject:
6299 case clang::Type::ObjCInterface:
6300 if (idx_is_valid && GetCompleteType(type))
6302 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(parent_qual_type.getTypePtr());
6303 assert (objc_class_type);
6304 if (objc_class_type)
6306 uint32_t child_idx = 0;
6307 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
6309 if (class_interface_decl)
6312 const clang::ASTRecordLayout &interface_layout = getASTContext()->getASTObjCInterfaceLayout(class_interface_decl);
6313 clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
6314 if (superclass_interface_decl)
6316 if (omit_empty_base_classes)
6318 CompilerType base_class_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl));
6319 if (base_class_clang_type.GetNumChildren(omit_empty_base_classes) > 0)
6323 clang::QualType ivar_qual_type(getASTContext()->getObjCInterfaceType(superclass_interface_decl));
6326 child_name.assign(superclass_interface_decl->getNameAsString().c_str());
6328 clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr());
6330 child_byte_size = ivar_type_info.Width / 8;
6331 child_byte_offset = 0;
6332 child_is_base_class = true;
6334 return CompilerType (getASTContext(), ivar_qual_type);
6344 const uint32_t superclass_idx = child_idx;
6346 if (idx < (child_idx + class_interface_decl->ivar_size()))
6348 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
6350 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos)
6352 if (child_idx == idx)
6354 clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
6356 clang::QualType ivar_qual_type(ivar_decl->getType());
6358 child_name.assign(ivar_decl->getNameAsString().c_str());
6360 clang::TypeInfo ivar_type_info = getASTContext()->getTypeInfo(ivar_qual_type.getTypePtr());
6362 child_byte_size = ivar_type_info.Width / 8;
6364 // Figure out the field offset within the current struct/union/class type
6365 // For ObjC objects, we can't trust the bit offset we get from the Clang AST, since
6366 // that doesn't account for the space taken up by unbacked properties, or from
6367 // the changing size of base classes that are newer than this class.
6368 // So if we have a process around that we can ask about this object, do so.
6369 child_byte_offset = LLDB_INVALID_IVAR_OFFSET;
6370 Process *process = nullptr;
6372 process = exe_ctx->GetProcessPtr();
6375 ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime();
6376 if (objc_runtime != nullptr)
6378 CompilerType parent_ast_type (getASTContext(), parent_qual_type);
6379 child_byte_offset = objc_runtime->GetByteOffsetForIvar (parent_ast_type, ivar_decl->getNameAsString().c_str());
6383 // Setting this to UINT32_MAX to make sure we don't compute it twice...
6384 bit_offset = UINT32_MAX;
6386 if (child_byte_offset == static_cast<int32_t>(LLDB_INVALID_IVAR_OFFSET))
6388 bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx);
6389 child_byte_offset = bit_offset / 8;
6392 // Note, the ObjC Ivar Byte offset is just that, it doesn't account for the bit offset
6393 // of a bitfield within its containing object. So regardless of where we get the byte
6394 // offset from, we still need to get the bit offset for bitfields from the layout.
6396 if (ClangASTContext::FieldIsBitfield (getASTContext(), ivar_decl, child_bitfield_bit_size))
6398 if (bit_offset == UINT32_MAX)
6399 bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx);
6401 child_bitfield_bit_offset = bit_offset % 8;
6403 return CompilerType (getASTContext(), ivar_qual_type);
6413 case clang::Type::ObjCObjectPointer:
6416 CompilerType pointee_clang_type (GetPointeeType(type));
6418 if (transparent_pointers && pointee_clang_type.IsAggregateType())
6420 child_is_deref_of_parent = false;
6421 bool tmp_child_is_deref_of_parent = false;
6422 return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
6424 transparent_pointers,
6425 omit_empty_base_classes,
6426 ignore_array_bounds,
6430 child_bitfield_bit_size,
6431 child_bitfield_bit_offset,
6432 child_is_base_class,
6433 tmp_child_is_deref_of_parent,
6439 child_is_deref_of_parent = true;
6440 const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
6443 child_name.assign(1, '*');
6444 child_name += parent_name;
6447 // We have a pointer to an simple type
6448 if (idx == 0 && pointee_clang_type.GetCompleteType())
6450 child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
6451 child_byte_offset = 0;
6452 return pointee_clang_type;
6458 case clang::Type::Vector:
6459 case clang::Type::ExtVector:
6462 const clang::VectorType *array = llvm::cast<clang::VectorType>(parent_qual_type.getTypePtr());
6465 CompilerType element_type (getASTContext(), array->getElementType());
6466 if (element_type.GetCompleteType())
6468 char element_name[64];
6469 ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx));
6470 child_name.assign(element_name);
6471 child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
6472 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6473 return element_type;
6479 case clang::Type::ConstantArray:
6480 case clang::Type::IncompleteArray:
6481 if (ignore_array_bounds || idx_is_valid)
6483 const clang::ArrayType *array = GetQualType(type)->getAsArrayTypeUnsafe();
6486 CompilerType element_type (getASTContext(), array->getElementType());
6487 if (element_type.GetCompleteType())
6489 char element_name[64];
6490 ::snprintf (element_name, sizeof (element_name), "[%" PRIu64 "]", static_cast<uint64_t>(idx));
6491 child_name.assign(element_name);
6492 child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
6493 child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
6494 return element_type;
6501 case clang::Type::Pointer:
6504 CompilerType pointee_clang_type (GetPointeeType(type));
6506 // Don't dereference "void *" pointers
6507 if (pointee_clang_type.IsVoidType())
6508 return CompilerType();
6510 if (transparent_pointers && pointee_clang_type.IsAggregateType ())
6512 child_is_deref_of_parent = false;
6513 bool tmp_child_is_deref_of_parent = false;
6514 return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
6516 transparent_pointers,
6517 omit_empty_base_classes,
6518 ignore_array_bounds,
6522 child_bitfield_bit_size,
6523 child_bitfield_bit_offset,
6524 child_is_base_class,
6525 tmp_child_is_deref_of_parent,
6531 child_is_deref_of_parent = true;
6533 const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
6536 child_name.assign(1, '*');
6537 child_name += parent_name;
6540 // We have a pointer to an simple type
6543 child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
6544 child_byte_offset = 0;
6545 return pointee_clang_type;
6551 case clang::Type::LValueReference:
6552 case clang::Type::RValueReference:
6555 const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(parent_qual_type.getTypePtr());
6556 CompilerType pointee_clang_type (getASTContext(), reference_type->getPointeeType());
6557 if (transparent_pointers && pointee_clang_type.IsAggregateType ())
6559 child_is_deref_of_parent = false;
6560 bool tmp_child_is_deref_of_parent = false;
6561 return pointee_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
6563 transparent_pointers,
6564 omit_empty_base_classes,
6565 ignore_array_bounds,
6569 child_bitfield_bit_size,
6570 child_bitfield_bit_offset,
6571 child_is_base_class,
6572 tmp_child_is_deref_of_parent,
6578 const char *parent_name = valobj ? valobj->GetName().GetCString() : NULL;
6581 child_name.assign(1, '&');
6582 child_name += parent_name;
6585 // We have a pointer to an simple type
6588 child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
6589 child_byte_offset = 0;
6590 return pointee_clang_type;
6596 case clang::Type::Typedef:
6598 CompilerType typedefed_clang_type (getASTContext(), llvm::cast<clang::TypedefType>(parent_qual_type)->getDecl()->getUnderlyingType());
6599 return typedefed_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
6601 transparent_pointers,
6602 omit_empty_base_classes,
6603 ignore_array_bounds,
6607 child_bitfield_bit_size,
6608 child_bitfield_bit_offset,
6609 child_is_base_class,
6610 child_is_deref_of_parent,
6616 case clang::Type::Auto:
6618 CompilerType elaborated_clang_type (getASTContext(), llvm::cast<clang::AutoType>(parent_qual_type)->getDeducedType());
6619 return elaborated_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
6621 transparent_pointers,
6622 omit_empty_base_classes,
6623 ignore_array_bounds,
6627 child_bitfield_bit_size,
6628 child_bitfield_bit_offset,
6629 child_is_base_class,
6630 child_is_deref_of_parent,
6635 case clang::Type::Elaborated:
6637 CompilerType elaborated_clang_type (getASTContext(), llvm::cast<clang::ElaboratedType>(parent_qual_type)->getNamedType());
6638 return elaborated_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
6640 transparent_pointers,
6641 omit_empty_base_classes,
6642 ignore_array_bounds,
6646 child_bitfield_bit_size,
6647 child_bitfield_bit_offset,
6648 child_is_base_class,
6649 child_is_deref_of_parent,
6654 case clang::Type::Paren:
6656 CompilerType paren_clang_type (getASTContext(), llvm::cast<clang::ParenType>(parent_qual_type)->desugar());
6657 return paren_clang_type.GetChildCompilerTypeAtIndex (exe_ctx,
6659 transparent_pointers,
6660 omit_empty_base_classes,
6661 ignore_array_bounds,
6665 child_bitfield_bit_size,
6666 child_bitfield_bit_offset,
6667 child_is_base_class,
6668 child_is_deref_of_parent,
6677 return CompilerType();
6681 GetIndexForRecordBase
6683 const clang::RecordDecl *record_decl,
6684 const clang::CXXBaseSpecifier *base_spec,
6685 bool omit_empty_base_classes
6688 uint32_t child_idx = 0;
6690 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6692 // const char *super_name = record_decl->getNameAsCString();
6693 // const char *base_name = base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString();
6694 // printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name);
6696 if (cxx_record_decl)
6698 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
6699 for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
6700 base_class != base_class_end;
6703 if (omit_empty_base_classes)
6705 if (BaseSpecifierIsEmpty (base_class))
6709 // printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", super_name, base_name,
6711 // base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString());
6714 if (base_class == base_spec)
6725 GetIndexForRecordChild (const clang::RecordDecl *record_decl,
6726 clang::NamedDecl *canonical_decl,
6727 bool omit_empty_base_classes)
6729 uint32_t child_idx = ClangASTContext::GetNumBaseClasses (llvm::dyn_cast<clang::CXXRecordDecl>(record_decl),
6730 omit_empty_base_classes);
6732 clang::RecordDecl::field_iterator field, field_end;
6733 for (field = record_decl->field_begin(), field_end = record_decl->field_end();
6735 ++field, ++child_idx)
6737 if (field->getCanonicalDecl() == canonical_decl)
6744 // Look for a child member (doesn't include base classes, but it does include
6745 // their members) in the type hierarchy. Returns an index path into "clang_type"
6746 // on how to reach the appropriate member.
6765 // If we have a clang type that describes "class C", and we wanted to looked
6768 // With omit_empty_base_classes == false we would get an integer array back with:
6770 // The first index 1 is the child index for "class A" within class C
6771 // The second index 1 is the child index for "m_b" within class A
6773 // With omit_empty_base_classes == true we would get an integer array back with:
6775 // The first index 0 is the child index for "class A" within class C (since class B doesn't have any members it doesn't count)
6776 // The second index 1 is the child index for "m_b" within class A
6779 ClangASTContext::GetIndexOfChildMemberWithName (lldb::opaque_compiler_type_t type, const char *name,
6780 bool omit_empty_base_classes,
6781 std::vector<uint32_t>& child_indexes)
6783 if (type && name && name[0])
6785 clang::QualType qual_type(GetCanonicalQualType(type));
6786 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
6789 case clang::Type::Record:
6790 if (GetCompleteType(type))
6792 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
6793 const clang::RecordDecl *record_decl = record_type->getDecl();
6795 assert(record_decl);
6796 uint32_t child_idx = 0;
6798 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
6800 // Try and find a field that matches NAME
6801 clang::RecordDecl::field_iterator field, field_end;
6802 llvm::StringRef name_sref(name);
6803 for (field = record_decl->field_begin(), field_end = record_decl->field_end();
6805 ++field, ++child_idx)
6807 llvm::StringRef field_name = field->getName();
6808 if (field_name.empty())
6810 CompilerType field_type(getASTContext(),field->getType());
6811 child_indexes.push_back(child_idx);
6812 if (field_type.GetIndexOfChildMemberWithName(name, omit_empty_base_classes, child_indexes))
6813 return child_indexes.size();
6814 child_indexes.pop_back();
6817 else if (field_name.equals (name_sref))
6819 // We have to add on the number of base classes to this index!
6820 child_indexes.push_back (child_idx + ClangASTContext::GetNumBaseClasses (cxx_record_decl, omit_empty_base_classes));
6821 return child_indexes.size();
6825 if (cxx_record_decl)
6827 const clang::RecordDecl *parent_record_decl = cxx_record_decl;
6829 //printf ("parent = %s\n", parent_record_decl->getNameAsCString());
6831 //const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl();
6832 // Didn't find things easily, lets let clang do its thang...
6833 clang::IdentifierInfo & ident_ref = getASTContext()->Idents.get(name_sref);
6834 clang::DeclarationName decl_name(&ident_ref);
6836 clang::CXXBasePaths paths;
6837 if (cxx_record_decl->lookupInBases([decl_name](const clang::CXXBaseSpecifier *specifier, clang::CXXBasePath &path) {
6838 return clang::CXXRecordDecl::FindOrdinaryMember(specifier, path, decl_name);
6842 clang::CXXBasePaths::const_paths_iterator path, path_end = paths.end();
6843 for (path = paths.begin(); path != path_end; ++path)
6845 const size_t num_path_elements = path->size();
6846 for (size_t e=0; e<num_path_elements; ++e)
6848 clang::CXXBasePathElement elem = (*path)[e];
6850 child_idx = GetIndexForRecordBase (parent_record_decl, elem.Base, omit_empty_base_classes);
6851 if (child_idx == UINT32_MAX)
6853 child_indexes.clear();
6858 child_indexes.push_back (child_idx);
6859 parent_record_decl = llvm::cast<clang::RecordDecl>(elem.Base->getType()->getAs<clang::RecordType>()->getDecl());
6862 for (clang::NamedDecl *path_decl : path->Decls)
6864 child_idx = GetIndexForRecordChild (parent_record_decl, path_decl, omit_empty_base_classes);
6865 if (child_idx == UINT32_MAX)
6867 child_indexes.clear();
6872 child_indexes.push_back (child_idx);
6876 return child_indexes.size();
6883 case clang::Type::ObjCObject:
6884 case clang::Type::ObjCInterface:
6885 if (GetCompleteType(type))
6887 llvm::StringRef name_sref(name);
6888 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
6889 assert (objc_class_type);
6890 if (objc_class_type)
6892 uint32_t child_idx = 0;
6893 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
6895 if (class_interface_decl)
6897 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
6898 clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
6900 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx)
6902 const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
6904 if (ivar_decl->getName().equals (name_sref))
6906 if ((!omit_empty_base_classes && superclass_interface_decl) ||
6907 ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true)))
6910 child_indexes.push_back (child_idx);
6911 return child_indexes.size();
6915 if (superclass_interface_decl)
6917 // The super class index is always zero for ObjC classes,
6918 // so we push it onto the child indexes in case we find
6919 // an ivar in our superclass...
6920 child_indexes.push_back (0);
6922 CompilerType superclass_clang_type (getASTContext(), getASTContext()->getObjCInterfaceType(superclass_interface_decl));
6923 if (superclass_clang_type.GetIndexOfChildMemberWithName (name,
6924 omit_empty_base_classes,
6927 // We did find an ivar in a superclass so just
6928 // return the results!
6929 return child_indexes.size();
6932 // We didn't find an ivar matching "name" in our
6933 // superclass, pop the superclass zero index that
6934 // we pushed on above.
6935 child_indexes.pop_back();
6942 case clang::Type::ObjCObjectPointer:
6944 CompilerType objc_object_clang_type (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType());
6945 return objc_object_clang_type.GetIndexOfChildMemberWithName (name,
6946 omit_empty_base_classes,
6952 case clang::Type::ConstantArray:
6954 // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr());
6955 // const uint64_t element_count = array->getSize().getLimitedValue();
6957 // if (idx < element_count)
6959 // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType());
6961 // char element_name[32];
6962 // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx);
6964 // child_name.assign(element_name);
6965 // assert(field_type_info.first % 8 == 0);
6966 // child_byte_size = field_type_info.first / 8;
6967 // child_byte_offset = idx * child_byte_size;
6968 // return array->getElementType().getAsOpaquePtr();
6973 // case clang::Type::MemberPointerType:
6975 // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr());
6976 // clang::QualType pointee_type = mem_ptr_type->getPointeeType();
6978 // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
6980 // return GetIndexOfChildWithName (ast,
6981 // mem_ptr_type->getPointeeType().getAsOpaquePtr(),
6987 case clang::Type::LValueReference:
6988 case clang::Type::RValueReference:
6990 const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
6991 clang::QualType pointee_type(reference_type->getPointeeType());
6992 CompilerType pointee_clang_type (getASTContext(), pointee_type);
6994 if (pointee_clang_type.IsAggregateType ())
6996 return pointee_clang_type.GetIndexOfChildMemberWithName (name,
6997 omit_empty_base_classes,
7003 case clang::Type::Pointer:
7005 CompilerType pointee_clang_type (GetPointeeType(type));
7007 if (pointee_clang_type.IsAggregateType ())
7009 return pointee_clang_type.GetIndexOfChildMemberWithName (name,
7010 omit_empty_base_classes,
7016 case clang::Type::Typedef:
7017 return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildMemberWithName (name,
7018 omit_empty_base_classes,
7021 case clang::Type::Auto:
7022 return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetIndexOfChildMemberWithName (name,
7023 omit_empty_base_classes,
7026 case clang::Type::Elaborated:
7027 return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildMemberWithName (name,
7028 omit_empty_base_classes,
7031 case clang::Type::Paren:
7032 return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildMemberWithName (name,
7033 omit_empty_base_classes,
7044 // Get the index of the child of "clang_type" whose name matches. This function
7045 // doesn't descend into the children, but only looks one level deep and name
7046 // matches can include base class names.
7049 ClangASTContext::GetIndexOfChildWithName (lldb::opaque_compiler_type_t type, const char *name, bool omit_empty_base_classes)
7051 if (type && name && name[0])
7053 clang::QualType qual_type(GetCanonicalQualType(type));
7055 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7059 case clang::Type::Record:
7060 if (GetCompleteType(type))
7062 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
7063 const clang::RecordDecl *record_decl = record_type->getDecl();
7065 assert(record_decl);
7066 uint32_t child_idx = 0;
7068 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
7070 if (cxx_record_decl)
7072 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
7073 for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
7074 base_class != base_class_end;
7077 // Skip empty base classes
7078 clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
7079 if (omit_empty_base_classes && ClangASTContext::RecordHasFields(base_class_decl) == false)
7082 CompilerType base_class_clang_type (getASTContext(), base_class->getType());
7083 std::string base_class_type_name (base_class_clang_type.GetTypeName().AsCString(""));
7084 if (base_class_type_name.compare (name) == 0)
7090 // Try and find a field that matches NAME
7091 clang::RecordDecl::field_iterator field, field_end;
7092 llvm::StringRef name_sref(name);
7093 for (field = record_decl->field_begin(), field_end = record_decl->field_end();
7095 ++field, ++child_idx)
7097 if (field->getName().equals (name_sref))
7104 case clang::Type::ObjCObject:
7105 case clang::Type::ObjCInterface:
7106 if (GetCompleteType(type))
7108 llvm::StringRef name_sref(name);
7109 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
7110 assert (objc_class_type);
7111 if (objc_class_type)
7113 uint32_t child_idx = 0;
7114 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
7116 if (class_interface_decl)
7118 clang::ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end();
7119 clang::ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass();
7121 for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx)
7123 const clang::ObjCIvarDecl* ivar_decl = *ivar_pos;
7125 if (ivar_decl->getName().equals (name_sref))
7127 if ((!omit_empty_base_classes && superclass_interface_decl) ||
7128 ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true)))
7135 if (superclass_interface_decl)
7137 if (superclass_interface_decl->getName().equals (name_sref))
7145 case clang::Type::ObjCObjectPointer:
7147 CompilerType pointee_clang_type (getASTContext(), llvm::cast<clang::ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType());
7148 return pointee_clang_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
7152 case clang::Type::ConstantArray:
7154 // const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr());
7155 // const uint64_t element_count = array->getSize().getLimitedValue();
7157 // if (idx < element_count)
7159 // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType());
7161 // char element_name[32];
7162 // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx);
7164 // child_name.assign(element_name);
7165 // assert(field_type_info.first % 8 == 0);
7166 // child_byte_size = field_type_info.first / 8;
7167 // child_byte_offset = idx * child_byte_size;
7168 // return array->getElementType().getAsOpaquePtr();
7173 // case clang::Type::MemberPointerType:
7175 // MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr());
7176 // clang::QualType pointee_type = mem_ptr_type->getPointeeType();
7178 // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
7180 // return GetIndexOfChildWithName (ast,
7181 // mem_ptr_type->getPointeeType().getAsOpaquePtr(),
7187 case clang::Type::LValueReference:
7188 case clang::Type::RValueReference:
7190 const clang::ReferenceType *reference_type = llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
7191 CompilerType pointee_type (getASTContext(), reference_type->getPointeeType());
7193 if (pointee_type.IsAggregateType ())
7195 return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
7200 case clang::Type::Pointer:
7202 const clang::PointerType *pointer_type = llvm::cast<clang::PointerType>(qual_type.getTypePtr());
7203 CompilerType pointee_type (getASTContext(), pointer_type->getPointeeType());
7205 if (pointee_type.IsAggregateType ())
7207 return pointee_type.GetIndexOfChildWithName (name, omit_empty_base_classes);
7213 // child_name.assign(1, '*');
7214 // child_name += parent_name;
7217 // // We have a pointer to an simple type
7220 // std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type);
7221 // assert(clang_type_info.first % 8 == 0);
7222 // child_byte_size = clang_type_info.first / 8;
7223 // child_byte_offset = 0;
7224 // return pointee_type.getAsOpaquePtr();
7230 case clang::Type::Auto:
7231 return CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).GetIndexOfChildWithName (name, omit_empty_base_classes);
7233 case clang::Type::Elaborated:
7234 return CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).GetIndexOfChildWithName (name, omit_empty_base_classes);
7236 case clang::Type::Paren:
7237 return CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).GetIndexOfChildWithName (name, omit_empty_base_classes);
7239 case clang::Type::Typedef:
7240 return CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType()).GetIndexOfChildWithName (name, omit_empty_base_classes);
7251 ClangASTContext::GetNumTemplateArguments (lldb::opaque_compiler_type_t type)
7256 clang::QualType qual_type (GetCanonicalQualType(type));
7257 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7260 case clang::Type::Record:
7261 if (GetCompleteType(type))
7263 const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
7264 if (cxx_record_decl)
7266 const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl);
7268 return template_decl->getTemplateArgs().size();
7273 case clang::Type::Typedef:
7274 return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetNumTemplateArguments();
7276 case clang::Type::Auto:
7277 return (CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType())).GetNumTemplateArguments();
7279 case clang::Type::Elaborated:
7280 return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetNumTemplateArguments();
7282 case clang::Type::Paren:
7283 return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetNumTemplateArguments();
7293 ClangASTContext::GetTemplateArgument (lldb::opaque_compiler_type_t type, size_t arg_idx, lldb::TemplateArgumentKind &kind)
7296 return CompilerType();
7298 clang::QualType qual_type (GetCanonicalQualType(type));
7299 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
7302 case clang::Type::Record:
7303 if (GetCompleteType(type))
7305 const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
7306 if (cxx_record_decl)
7308 const clang::ClassTemplateSpecializationDecl *template_decl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(cxx_record_decl);
7309 if (template_decl && arg_idx < template_decl->getTemplateArgs().size())
7311 const clang::TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx];
7312 switch (template_arg.getKind())
7314 case clang::TemplateArgument::Null:
7315 kind = eTemplateArgumentKindNull;
7316 return CompilerType();
7318 case clang::TemplateArgument::Type:
7319 kind = eTemplateArgumentKindType;
7320 return CompilerType(getASTContext(), template_arg.getAsType());
7322 case clang::TemplateArgument::Declaration:
7323 kind = eTemplateArgumentKindDeclaration;
7324 return CompilerType();
7326 case clang::TemplateArgument::Integral:
7327 kind = eTemplateArgumentKindIntegral;
7328 return CompilerType(getASTContext(), template_arg.getIntegralType());
7330 case clang::TemplateArgument::Template:
7331 kind = eTemplateArgumentKindTemplate;
7332 return CompilerType();
7334 case clang::TemplateArgument::TemplateExpansion:
7335 kind = eTemplateArgumentKindTemplateExpansion;
7336 return CompilerType();
7338 case clang::TemplateArgument::Expression:
7339 kind = eTemplateArgumentKindExpression;
7340 return CompilerType();
7342 case clang::TemplateArgument::Pack:
7343 kind = eTemplateArgumentKindPack;
7344 return CompilerType();
7347 assert (!"Unhandled clang::TemplateArgument::ArgKind");
7355 case clang::Type::Typedef:
7356 return (CompilerType (getASTContext(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType())).GetTemplateArgument(arg_idx, kind);
7358 case clang::Type::Auto:
7359 return (CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType())).GetTemplateArgument(arg_idx, kind);
7361 case clang::Type::Elaborated:
7362 return (CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType())).GetTemplateArgument(arg_idx, kind);
7364 case clang::Type::Paren:
7365 return (CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar())).GetTemplateArgument(arg_idx, kind);
7370 kind = eTemplateArgumentKindNull;
7371 return CompilerType ();
7375 ClangASTContext::GetTypeForFormatters (void* type)
7378 return ClangUtil::RemoveFastQualifiers(CompilerType(this, type));
7379 return CompilerType();
7383 IsOperator (const char *name, clang::OverloadedOperatorKind &op_kind)
7385 if (name == nullptr || name[0] == '\0')
7388 #define OPERATOR_PREFIX "operator"
7389 #define OPERATOR_PREFIX_LENGTH (sizeof (OPERATOR_PREFIX) - 1)
7391 const char *post_op_name = nullptr;
7393 bool no_space = true;
7395 if (::strncmp(name, OPERATOR_PREFIX, OPERATOR_PREFIX_LENGTH))
7398 post_op_name = name + OPERATOR_PREFIX_LENGTH;
7400 if (post_op_name[0] == ' ')
7406 #undef OPERATOR_PREFIX
7407 #undef OPERATOR_PREFIX_LENGTH
7409 // This is an operator, set the overloaded operator kind to invalid
7410 // in case this is a conversion operator...
7411 op_kind = clang::NUM_OVERLOADED_OPERATORS;
7413 switch (post_op_name[0])
7422 if (strcmp (post_op_name, "new") == 0)
7423 op_kind = clang::OO_New;
7424 else if (strcmp (post_op_name, "new[]") == 0)
7425 op_kind = clang::OO_Array_New;
7431 if (strcmp (post_op_name, "delete") == 0)
7432 op_kind = clang::OO_Delete;
7433 else if (strcmp (post_op_name, "delete[]") == 0)
7434 op_kind = clang::OO_Array_Delete;
7438 if (post_op_name[1] == '\0')
7439 op_kind = clang::OO_Plus;
7440 else if (post_op_name[2] == '\0')
7442 if (post_op_name[1] == '=')
7443 op_kind = clang::OO_PlusEqual;
7444 else if (post_op_name[1] == '+')
7445 op_kind = clang::OO_PlusPlus;
7450 if (post_op_name[1] == '\0')
7451 op_kind = clang::OO_Minus;
7452 else if (post_op_name[2] == '\0')
7454 switch (post_op_name[1])
7456 case '=': op_kind = clang::OO_MinusEqual; break;
7457 case '-': op_kind = clang::OO_MinusMinus; break;
7458 case '>': op_kind = clang::OO_Arrow; break;
7461 else if (post_op_name[3] == '\0')
7463 if (post_op_name[2] == '*')
7464 op_kind = clang::OO_ArrowStar; break;
7469 if (post_op_name[1] == '\0')
7470 op_kind = clang::OO_Star;
7471 else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
7472 op_kind = clang::OO_StarEqual;
7476 if (post_op_name[1] == '\0')
7477 op_kind = clang::OO_Slash;
7478 else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
7479 op_kind = clang::OO_SlashEqual;
7483 if (post_op_name[1] == '\0')
7484 op_kind = clang::OO_Percent;
7485 else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
7486 op_kind = clang::OO_PercentEqual;
7491 if (post_op_name[1] == '\0')
7492 op_kind = clang::OO_Caret;
7493 else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
7494 op_kind = clang::OO_CaretEqual;
7498 if (post_op_name[1] == '\0')
7499 op_kind = clang::OO_Amp;
7500 else if (post_op_name[2] == '\0')
7502 switch (post_op_name[1])
7504 case '=': op_kind = clang::OO_AmpEqual; break;
7505 case '&': op_kind = clang::OO_AmpAmp; break;
7511 if (post_op_name[1] == '\0')
7512 op_kind = clang::OO_Pipe;
7513 else if (post_op_name[2] == '\0')
7515 switch (post_op_name[1])
7517 case '=': op_kind = clang::OO_PipeEqual; break;
7518 case '|': op_kind = clang::OO_PipePipe; break;
7524 if (post_op_name[1] == '\0')
7525 op_kind = clang::OO_Tilde;
7529 if (post_op_name[1] == '\0')
7530 op_kind = clang::OO_Exclaim;
7531 else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
7532 op_kind = clang::OO_ExclaimEqual;
7536 if (post_op_name[1] == '\0')
7537 op_kind = clang::OO_Equal;
7538 else if (post_op_name[1] == '=' && post_op_name[2] == '\0')
7539 op_kind = clang::OO_EqualEqual;
7543 if (post_op_name[1] == '\0')
7544 op_kind = clang::OO_Less;
7545 else if (post_op_name[2] == '\0')
7547 switch (post_op_name[1])
7549 case '<': op_kind = clang::OO_LessLess; break;
7550 case '=': op_kind = clang::OO_LessEqual; break;
7553 else if (post_op_name[3] == '\0')
7555 if (post_op_name[2] == '=')
7556 op_kind = clang::OO_LessLessEqual;
7561 if (post_op_name[1] == '\0')
7562 op_kind = clang::OO_Greater;
7563 else if (post_op_name[2] == '\0')
7565 switch (post_op_name[1])
7567 case '>': op_kind = clang::OO_GreaterGreater; break;
7568 case '=': op_kind = clang::OO_GreaterEqual; break;
7571 else if (post_op_name[1] == '>' &&
7572 post_op_name[2] == '=' &&
7573 post_op_name[3] == '\0')
7575 op_kind = clang::OO_GreaterGreaterEqual;
7580 if (post_op_name[1] == '\0')
7581 op_kind = clang::OO_Comma;
7585 if (post_op_name[1] == ')' && post_op_name[2] == '\0')
7586 op_kind = clang::OO_Call;
7590 if (post_op_name[1] == ']' && post_op_name[2] == '\0')
7591 op_kind = clang::OO_Subscript;
7599 ClangASTContext::GetAsEnumDecl (const CompilerType& type)
7601 const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(ClangUtil::GetCanonicalQualType(type));
7603 return enutype->getDecl();
7608 ClangASTContext::GetAsRecordDecl (const CompilerType& type)
7610 const clang::RecordType *record_type = llvm::dyn_cast<clang::RecordType>(ClangUtil::GetCanonicalQualType(type));
7612 return record_type->getDecl();
7617 ClangASTContext::GetAsTagDecl (const CompilerType& type)
7619 clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type);
7620 if (qual_type.isNull())
7623 return qual_type->getAsTagDecl();
7626 clang::CXXRecordDecl *
7627 ClangASTContext::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t type)
7629 return GetCanonicalQualType(type)->getAsCXXRecordDecl();
7632 clang::ObjCInterfaceDecl *
7633 ClangASTContext::GetAsObjCInterfaceDecl (const CompilerType& type)
7635 const clang::ObjCObjectType *objc_class_type =
7636 llvm::dyn_cast<clang::ObjCObjectType>(ClangUtil::GetCanonicalQualType(type));
7637 if (objc_class_type)
7638 return objc_class_type->getInterface();
7643 ClangASTContext::AddFieldToRecordType (const CompilerType& type, const char *name,
7644 const CompilerType &field_clang_type,
7646 uint32_t bitfield_bit_size)
7648 if (!type.IsValid() || !field_clang_type.IsValid())
7650 ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem());
7653 clang::ASTContext* clang_ast = ast->getASTContext();
7655 clang::FieldDecl *field = nullptr;
7657 clang::Expr *bit_width = nullptr;
7658 if (bitfield_bit_size != 0)
7660 llvm::APInt bitfield_bit_size_apint(clang_ast->getTypeSize(clang_ast->IntTy), bitfield_bit_size);
7661 bit_width = new (*clang_ast)clang::IntegerLiteral (*clang_ast, bitfield_bit_size_apint, clang_ast->IntTy, clang::SourceLocation());
7664 clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type);
7667 field = clang::FieldDecl::Create(*clang_ast, record_decl, clang::SourceLocation(), clang::SourceLocation(),
7668 name ? &clang_ast->Idents.get(name) : nullptr, // Identifier
7669 ClangUtil::GetQualType(field_clang_type), // Field type
7671 bit_width, // BitWidth
7673 clang::ICIS_NoInit); // HasInit
7677 // Determine whether this field corresponds to an anonymous
7679 if (const clang::TagType *TagT = field->getType()->getAs<clang::TagType>()) {
7680 if (clang::RecordDecl *Rec = llvm::dyn_cast<clang::RecordDecl>(TagT->getDecl()))
7681 if (!Rec->getDeclName()) {
7682 Rec->setAnonymousStructOrUnion(true);
7683 field->setImplicit();
7691 field->setAccess (ClangASTContext::ConvertAccessTypeToAccessSpecifier (access));
7693 record_decl->addDecl(field);
7695 #ifdef LLDB_CONFIGURATION_DEBUG
7702 clang::ObjCInterfaceDecl *class_interface_decl = ast->GetAsObjCInterfaceDecl (type);
7704 if (class_interface_decl)
7706 const bool is_synthesized = false;
7708 field_clang_type.GetCompleteType();
7710 field = clang::ObjCIvarDecl::Create(
7711 *clang_ast, class_interface_decl, clang::SourceLocation(), clang::SourceLocation(),
7712 name ? &clang_ast->Idents.get(name) : nullptr, // Identifier
7713 ClangUtil::GetQualType(field_clang_type), // Field type
7714 nullptr, // TypeSourceInfo *
7715 ConvertAccessTypeToObjCIvarAccessControl(access), bit_width, is_synthesized);
7719 class_interface_decl->addDecl(field);
7721 #ifdef LLDB_CONFIGURATION_DEBUG
7731 ClangASTContext::BuildIndirectFields (const CompilerType& type)
7736 ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
7740 clang::RecordDecl *record_decl = ast->GetAsRecordDecl(type);
7745 typedef llvm::SmallVector <clang::IndirectFieldDecl *, 1> IndirectFieldVector;
7747 IndirectFieldVector indirect_fields;
7748 clang::RecordDecl::field_iterator field_pos;
7749 clang::RecordDecl::field_iterator field_end_pos = record_decl->field_end();
7750 clang::RecordDecl::field_iterator last_field_pos = field_end_pos;
7751 for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; last_field_pos = field_pos++)
7753 if (field_pos->isAnonymousStructOrUnion())
7755 clang::QualType field_qual_type = field_pos->getType();
7757 const clang::RecordType *field_record_type = field_qual_type->getAs<clang::RecordType>();
7759 if (!field_record_type)
7762 clang::RecordDecl *field_record_decl = field_record_type->getDecl();
7764 if (!field_record_decl)
7767 for (clang::RecordDecl::decl_iterator di = field_record_decl->decls_begin(), de = field_record_decl->decls_end();
7771 if (clang::FieldDecl *nested_field_decl = llvm::dyn_cast<clang::FieldDecl>(*di))
7773 clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[2];
7774 chain[0] = *field_pos;
7775 chain[1] = nested_field_decl;
7776 clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(),
7778 clang::SourceLocation(),
7779 nested_field_decl->getIdentifier(),
7780 nested_field_decl->getType(),
7783 indirect_field->setImplicit();
7785 indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(),
7786 nested_field_decl->getAccess()));
7788 indirect_fields.push_back(indirect_field);
7790 else if (clang::IndirectFieldDecl *nested_indirect_field_decl = llvm::dyn_cast<clang::IndirectFieldDecl>(*di))
7792 size_t nested_chain_size = nested_indirect_field_decl->getChainingSize();
7793 clang::NamedDecl **chain = new (*ast->getASTContext()) clang::NamedDecl*[nested_chain_size + 1];
7794 chain[0] = *field_pos;
7796 int chain_index = 1;
7797 for (clang::IndirectFieldDecl::chain_iterator nci = nested_indirect_field_decl->chain_begin(),
7798 nce = nested_indirect_field_decl->chain_end();
7802 chain[chain_index] = *nci;
7806 clang::IndirectFieldDecl *indirect_field = clang::IndirectFieldDecl::Create(*ast->getASTContext(),
7808 clang::SourceLocation(),
7809 nested_indirect_field_decl->getIdentifier(),
7810 nested_indirect_field_decl->getType(),
7811 {chain, nested_chain_size + 1});
7813 indirect_field->setImplicit();
7815 indirect_field->setAccess(ClangASTContext::UnifyAccessSpecifiers(field_pos->getAccess(),
7816 nested_indirect_field_decl->getAccess()));
7818 indirect_fields.push_back(indirect_field);
7824 // Check the last field to see if it has an incomplete array type as its
7825 // last member and if it does, the tell the record decl about it
7826 if (last_field_pos != field_end_pos)
7828 if (last_field_pos->getType()->isIncompleteArrayType())
7829 record_decl->hasFlexibleArrayMember();
7832 for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), ife = indirect_fields.end();
7836 record_decl->addDecl(*ifi);
7841 ClangASTContext::SetIsPacked (const CompilerType& type)
7845 ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
7848 clang::RecordDecl *record_decl = GetAsRecordDecl(type);
7853 record_decl->addAttr(clang::PackedAttr::CreateImplicit(*ast->getASTContext()));
7859 ClangASTContext::AddVariableToRecordType (const CompilerType& type, const char *name,
7860 const CompilerType &var_type,
7863 clang::VarDecl *var_decl = nullptr;
7865 if (!type.IsValid() || !var_type.IsValid())
7867 ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
7871 clang::RecordDecl *record_decl = ast->GetAsRecordDecl (type);
7875 clang::VarDecl::Create(*ast->getASTContext(), // ASTContext &
7876 record_decl, // DeclContext *
7877 clang::SourceLocation(), // clang::SourceLocation StartLoc
7878 clang::SourceLocation(), // clang::SourceLocation IdLoc
7879 name ? &ast->getASTContext()->Idents.get(name) : nullptr, // clang::IdentifierInfo *
7880 ClangUtil::GetQualType(var_type), // Variable clang::QualType
7881 nullptr, // TypeSourceInfo *
7882 clang::SC_Static); // StorageClass
7885 var_decl->setAccess(ClangASTContext::ConvertAccessTypeToAccessSpecifier (access));
7886 record_decl->addDecl(var_decl);
7888 #ifdef LLDB_CONFIGURATION_DEBUG
7889 VerifyDecl(var_decl);
7897 clang::CXXMethodDecl *
7898 ClangASTContext::AddMethodToCXXRecordType (lldb::opaque_compiler_type_t type, const char *name,
7899 const CompilerType &method_clang_type,
7900 lldb::AccessType access,
7908 if (!type || !method_clang_type.IsValid() || name == nullptr || name[0] == '\0')
7911 clang::QualType record_qual_type(GetCanonicalQualType(type));
7913 clang::CXXRecordDecl *cxx_record_decl = record_qual_type->getAsCXXRecordDecl();
7915 if (cxx_record_decl == nullptr)
7918 clang::QualType method_qual_type(ClangUtil::GetQualType(method_clang_type));
7920 clang::CXXMethodDecl *cxx_method_decl = nullptr;
7922 clang::DeclarationName decl_name (&getASTContext()->Idents.get(name));
7924 const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType>(method_qual_type.getTypePtr());
7926 if (function_type == nullptr)
7929 const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(function_type));
7931 if (!method_function_prototype)
7934 unsigned int num_params = method_function_prototype->getNumParams();
7936 clang::CXXDestructorDecl *cxx_dtor_decl(nullptr);
7937 clang::CXXConstructorDecl *cxx_ctor_decl(nullptr);
7940 return nullptr; // skip everything artificial
7944 cxx_dtor_decl = clang::CXXDestructorDecl::Create (*getASTContext(),
7946 clang::SourceLocation(),
7947 clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXDestructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()),
7952 cxx_method_decl = cxx_dtor_decl;
7954 else if (decl_name == cxx_record_decl->getDeclName())
7956 cxx_ctor_decl = clang::CXXConstructorDecl::Create (*getASTContext(),
7958 clang::SourceLocation(),
7959 clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConstructorName (getASTContext()->getCanonicalType (record_qual_type)), clang::SourceLocation()),
7961 nullptr, // TypeSourceInfo *
7965 false /*is_constexpr*/);
7966 cxx_method_decl = cxx_ctor_decl;
7970 clang::StorageClass SC = is_static ? clang::SC_Static : clang::SC_None;
7971 clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
7973 if (IsOperator (name, op_kind))
7975 if (op_kind != clang::NUM_OVERLOADED_OPERATORS)
7977 // Check the number of operator parameters. Sometimes we have
7978 // seen bad DWARF that doesn't correctly describe operators and
7979 // if we try to create a method and add it to the class, clang
7980 // will assert and crash, so we need to make sure things are
7982 if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount (op_kind, num_params))
7984 cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(),
7986 clang::SourceLocation(),
7987 clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXOperatorName (op_kind), clang::SourceLocation()),
7989 nullptr, // TypeSourceInfo *
7992 false /*is_constexpr*/,
7993 clang::SourceLocation());
7995 else if (num_params == 0)
7997 // Conversion operators don't take params...
7998 cxx_method_decl = clang::CXXConversionDecl::Create (*getASTContext(),
8000 clang::SourceLocation(),
8001 clang::DeclarationNameInfo (getASTContext()->DeclarationNames.getCXXConversionFunctionName (getASTContext()->getCanonicalType (function_type->getReturnType())), clang::SourceLocation()),
8003 nullptr, // TypeSourceInfo *
8006 false /*is_constexpr*/,
8007 clang::SourceLocation());
8011 if (cxx_method_decl == nullptr)
8013 cxx_method_decl = clang::CXXMethodDecl::Create (*getASTContext(),
8015 clang::SourceLocation(),
8016 clang::DeclarationNameInfo (decl_name, clang::SourceLocation()),
8018 nullptr, // TypeSourceInfo *
8021 false /*is_constexpr*/,
8022 clang::SourceLocation());
8026 clang::AccessSpecifier access_specifier = ClangASTContext::ConvertAccessTypeToAccessSpecifier (access);
8028 cxx_method_decl->setAccess (access_specifier);
8029 cxx_method_decl->setVirtualAsWritten (is_virtual);
8032 cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext()));
8034 // Populate the method decl with parameter decls
8036 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
8038 for (unsigned param_index = 0;
8039 param_index < num_params;
8042 params.push_back (clang::ParmVarDecl::Create (*getASTContext(),
8044 clang::SourceLocation(),
8045 clang::SourceLocation(),
8046 nullptr, // anonymous
8047 method_function_prototype->getParamType(param_index),
8053 cxx_method_decl->setParams (llvm::ArrayRef<clang::ParmVarDecl*>(params));
8055 cxx_record_decl->addDecl (cxx_method_decl);
8057 // Sometimes the debug info will mention a constructor (default/copy/move),
8058 // destructor, or assignment operator (copy/move) but there won't be any
8059 // version of this in the code. So we check if the function was artificially
8060 // generated and if it is trivial and this lets the compiler/backend know
8061 // that it can inline the IR for these when it needs to and we can avoid a
8062 // "missing function" error when running expressions.
8066 if (cxx_ctor_decl &&
8067 ((cxx_ctor_decl->isDefaultConstructor() && cxx_record_decl->hasTrivialDefaultConstructor ()) ||
8068 (cxx_ctor_decl->isCopyConstructor() && cxx_record_decl->hasTrivialCopyConstructor ()) ||
8069 (cxx_ctor_decl->isMoveConstructor() && cxx_record_decl->hasTrivialMoveConstructor ()) ))
8071 cxx_ctor_decl->setDefaulted();
8072 cxx_ctor_decl->setTrivial(true);
8074 else if (cxx_dtor_decl)
8076 if (cxx_record_decl->hasTrivialDestructor())
8078 cxx_dtor_decl->setDefaulted();
8079 cxx_dtor_decl->setTrivial(true);
8082 else if ((cxx_method_decl->isCopyAssignmentOperator() && cxx_record_decl->hasTrivialCopyAssignment()) ||
8083 (cxx_method_decl->isMoveAssignmentOperator() && cxx_record_decl->hasTrivialMoveAssignment()))
8085 cxx_method_decl->setDefaulted();
8086 cxx_method_decl->setTrivial(true);
8090 #ifdef LLDB_CONFIGURATION_DEBUG
8091 VerifyDecl(cxx_method_decl);
8094 // printf ("decl->isPolymorphic() = %i\n", cxx_record_decl->isPolymorphic());
8095 // printf ("decl->isAggregate() = %i\n", cxx_record_decl->isAggregate());
8096 // printf ("decl->isPOD() = %i\n", cxx_record_decl->isPOD());
8097 // printf ("decl->isEmpty() = %i\n", cxx_record_decl->isEmpty());
8098 // printf ("decl->isAbstract() = %i\n", cxx_record_decl->isAbstract());
8099 // printf ("decl->hasTrivialConstructor() = %i\n", cxx_record_decl->hasTrivialConstructor());
8100 // printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor());
8101 // printf ("decl->hasTrivialCopyAssignment() = %i\n", cxx_record_decl->hasTrivialCopyAssignment());
8102 // printf ("decl->hasTrivialDestructor() = %i\n", cxx_record_decl->hasTrivialDestructor());
8103 return cxx_method_decl;
8107 #pragma mark C++ Base Classes
8109 clang::CXXBaseSpecifier *
8110 ClangASTContext::CreateBaseClassSpecifier (lldb::opaque_compiler_type_t type, AccessType access, bool is_virtual, bool base_of_class)
8113 return new clang::CXXBaseSpecifier (clang::SourceRange(),
8116 ClangASTContext::ConvertAccessTypeToAccessSpecifier (access),
8117 getASTContext()->getTrivialTypeSourceInfo (GetQualType(type)),
8118 clang::SourceLocation());
8123 ClangASTContext::DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes, unsigned num_base_classes)
8125 for (unsigned i=0; i<num_base_classes; ++i)
8127 delete base_classes[i];
8128 base_classes[i] = nullptr;
8133 ClangASTContext::SetBaseClassesForClassType (lldb::opaque_compiler_type_t type, clang::CXXBaseSpecifier const * const *base_classes,
8134 unsigned num_base_classes)
8138 clang::CXXRecordDecl *cxx_record_decl = GetAsCXXRecordDecl(type);
8139 if (cxx_record_decl)
8141 cxx_record_decl->setBases(base_classes, num_base_classes);
8149 ClangASTContext::SetObjCSuperClass (const CompilerType& type, const CompilerType &superclass_clang_type)
8151 ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(type.GetTypeSystem());
8154 clang::ASTContext* clang_ast = ast->getASTContext();
8156 if (type && superclass_clang_type.IsValid() && superclass_clang_type.GetTypeSystem() == type.GetTypeSystem())
8158 clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type);
8159 clang::ObjCInterfaceDecl *super_interface_decl = GetAsObjCInterfaceDecl (superclass_clang_type);
8160 if (class_interface_decl && super_interface_decl)
8162 class_interface_decl->setSuperClass(clang_ast->getTrivialTypeSourceInfo(clang_ast->getObjCInterfaceType(super_interface_decl)));
8170 ClangASTContext::AddObjCClassProperty (const CompilerType& type,
8171 const char *property_name,
8172 const CompilerType &property_clang_type,
8173 clang::ObjCIvarDecl *ivar_decl,
8174 const char *property_setter_name,
8175 const char *property_getter_name,
8176 uint32_t property_attributes,
8177 ClangASTMetadata *metadata)
8179 if (!type || !property_clang_type.IsValid() || property_name == nullptr || property_name[0] == '\0')
8181 ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
8184 clang::ASTContext* clang_ast = ast->getASTContext();
8186 clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type);
8188 if (class_interface_decl)
8190 CompilerType property_clang_type_to_access;
8192 if (property_clang_type.IsValid())
8193 property_clang_type_to_access = property_clang_type;
8195 property_clang_type_to_access = CompilerType (clang_ast, ivar_decl->getType());
8197 if (class_interface_decl && property_clang_type_to_access.IsValid())
8199 clang::TypeSourceInfo *prop_type_source;
8201 prop_type_source = clang_ast->getTrivialTypeSourceInfo (ivar_decl->getType());
8203 prop_type_source = clang_ast->getTrivialTypeSourceInfo(ClangUtil::GetQualType(property_clang_type));
8205 clang::ObjCPropertyDecl *property_decl = clang::ObjCPropertyDecl::Create(
8206 *clang_ast, class_interface_decl,
8207 clang::SourceLocation(), // Source Location
8208 &clang_ast->Idents.get(property_name),
8209 clang::SourceLocation(), // Source Location for AT
8210 clang::SourceLocation(), // Source location for (
8211 ivar_decl ? ivar_decl->getType() : ClangUtil::GetQualType(property_clang_type), prop_type_source);
8216 ClangASTContext::SetMetadata(clang_ast, property_decl, *metadata);
8218 class_interface_decl->addDecl (property_decl);
8220 clang::Selector setter_sel, getter_sel;
8222 if (property_setter_name != nullptr)
8224 std::string property_setter_no_colon(property_setter_name, strlen(property_setter_name) - 1);
8225 clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(property_setter_no_colon.c_str());
8226 setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident);
8228 else if (!(property_attributes & DW_APPLE_PROPERTY_readonly))
8230 std::string setter_sel_string("set");
8231 setter_sel_string.push_back(::toupper(property_name[0]));
8232 setter_sel_string.append(&property_name[1]);
8233 clang::IdentifierInfo *setter_ident = &clang_ast->Idents.get(setter_sel_string.c_str());
8234 setter_sel = clang_ast->Selectors.getSelector(1, &setter_ident);
8236 property_decl->setSetterName(setter_sel);
8237 property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter);
8239 if (property_getter_name != nullptr)
8241 clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_getter_name);
8242 getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident);
8246 clang::IdentifierInfo *getter_ident = &clang_ast->Idents.get(property_name);
8247 getter_sel = clang_ast->Selectors.getSelector(0, &getter_ident);
8249 property_decl->setGetterName(getter_sel);
8250 property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter);
8253 property_decl->setPropertyIvarDecl (ivar_decl);
8255 if (property_attributes & DW_APPLE_PROPERTY_readonly)
8256 property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readonly);
8257 if (property_attributes & DW_APPLE_PROPERTY_readwrite)
8258 property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readwrite);
8259 if (property_attributes & DW_APPLE_PROPERTY_assign)
8260 property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_assign);
8261 if (property_attributes & DW_APPLE_PROPERTY_retain)
8262 property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_retain);
8263 if (property_attributes & DW_APPLE_PROPERTY_copy)
8264 property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_copy);
8265 if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
8266 property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_nonatomic);
8267 if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_nullability)
8268 property_decl->setPropertyAttributes(clang::ObjCPropertyDecl::OBJC_PR_nullability);
8269 if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_null_resettable)
8270 property_decl->setPropertyAttributes(clang::ObjCPropertyDecl::OBJC_PR_null_resettable);
8271 if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class)
8272 property_decl->setPropertyAttributes(clang::ObjCPropertyDecl::OBJC_PR_class);
8274 const bool isInstance = (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class) == 0;
8276 if (!getter_sel.isNull() &&
8277 !(isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
8278 : class_interface_decl->lookupClassMethod(getter_sel)))
8280 const bool isVariadic = false;
8281 const bool isSynthesized = false;
8282 const bool isImplicitlyDeclared = true;
8283 const bool isDefined = false;
8284 const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None;
8285 const bool HasRelatedResultType = false;
8287 clang::ObjCMethodDecl *getter = clang::ObjCMethodDecl::Create(
8288 *clang_ast, clang::SourceLocation(), clang::SourceLocation(), getter_sel,
8289 ClangUtil::GetQualType(property_clang_type_to_access), nullptr, class_interface_decl,
8290 isInstance, isVariadic, isSynthesized, isImplicitlyDeclared, isDefined, impControl,
8291 HasRelatedResultType);
8293 if (getter && metadata)
8294 ClangASTContext::SetMetadata(clang_ast, getter, *metadata);
8298 getter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(), llvm::ArrayRef<clang::SourceLocation>());
8300 class_interface_decl->addDecl(getter);
8304 if (!setter_sel.isNull() &&
8305 !(isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
8306 : class_interface_decl->lookupClassMethod(setter_sel)))
8308 clang::QualType result_type = clang_ast->VoidTy;
8309 const bool isVariadic = false;
8310 const bool isSynthesized = false;
8311 const bool isImplicitlyDeclared = true;
8312 const bool isDefined = false;
8313 const clang::ObjCMethodDecl::ImplementationControl impControl = clang::ObjCMethodDecl::None;
8314 const bool HasRelatedResultType = false;
8316 clang::ObjCMethodDecl *setter = clang::ObjCMethodDecl::Create (*clang_ast,
8317 clang::SourceLocation(),
8318 clang::SourceLocation(),
8322 class_interface_decl,
8326 isImplicitlyDeclared,
8329 HasRelatedResultType);
8331 if (setter && metadata)
8332 ClangASTContext::SetMetadata(clang_ast, setter, *metadata);
8334 llvm::SmallVector<clang::ParmVarDecl *, 1> params;
8336 params.push_back(clang::ParmVarDecl::Create(
8337 *clang_ast, setter, clang::SourceLocation(), clang::SourceLocation(),
8338 nullptr, // anonymous
8339 ClangUtil::GetQualType(property_clang_type_to_access), nullptr, clang::SC_Auto, nullptr));
8343 setter->setMethodParams(*clang_ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>());
8345 class_interface_decl->addDecl(setter);
8357 ClangASTContext::IsObjCClassTypeAndHasIVars (const CompilerType& type, bool check_superclass)
8359 clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl (type);
8360 if (class_interface_decl)
8361 return ObjCDeclHasIVars (class_interface_decl, check_superclass);
8366 clang::ObjCMethodDecl *
8367 ClangASTContext::AddMethodToObjCObjectType (const CompilerType& type,
8368 const char *name, // the full symbol name as seen in the symbol table (lldb::opaque_compiler_type_t type, "-[NString stringWithCString:]")
8369 const CompilerType &method_clang_type,
8370 lldb::AccessType access,
8374 if (!type || !method_clang_type.IsValid())
8377 clang::ObjCInterfaceDecl *class_interface_decl = GetAsObjCInterfaceDecl(type);
8379 if (class_interface_decl == nullptr)
8381 ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
8382 if (lldb_ast == nullptr)
8384 clang::ASTContext *ast = lldb_ast->getASTContext();
8386 const char *selector_start = ::strchr (name, ' ');
8387 if (selector_start == nullptr)
8391 llvm::SmallVector<clang::IdentifierInfo *, 12> selector_idents;
8395 //printf ("name = '%s'\n", name);
8397 unsigned num_selectors_with_args = 0;
8398 for (start = selector_start;
8399 start && *start != '\0' && *start != ']';
8402 len = ::strcspn(start, ":]");
8403 bool has_arg = (start[len] == ':');
8405 ++num_selectors_with_args;
8406 selector_idents.push_back (&ast->Idents.get (llvm::StringRef (start, len)));
8412 if (selector_idents.size() == 0)
8415 clang::Selector method_selector = ast->Selectors.getSelector (num_selectors_with_args ? selector_idents.size() : 0,
8416 selector_idents.data());
8418 clang::QualType method_qual_type(ClangUtil::GetQualType(method_clang_type));
8420 // Populate the method decl with parameter decls
8421 const clang::Type *method_type(method_qual_type.getTypePtr());
8423 if (method_type == nullptr)
8426 const clang::FunctionProtoType *method_function_prototype (llvm::dyn_cast<clang::FunctionProtoType>(method_type));
8428 if (!method_function_prototype)
8432 bool is_synthesized = false;
8433 bool is_defined = false;
8434 clang::ObjCMethodDecl::ImplementationControl imp_control = clang::ObjCMethodDecl::None;
8436 const unsigned num_args = method_function_prototype->getNumParams();
8438 if (num_args != num_selectors_with_args)
8439 return nullptr; // some debug information is corrupt. We are not going to deal with it.
8441 clang::ObjCMethodDecl *objc_method_decl = clang::ObjCMethodDecl::Create(
8443 clang::SourceLocation(), // beginLoc,
8444 clang::SourceLocation(), // endLoc,
8445 method_selector, method_function_prototype->getReturnType(),
8446 nullptr, // TypeSourceInfo *ResultTInfo,
8447 ClangASTContext::GetASTContext(ast)->GetDeclContextForType(ClangUtil::GetQualType(type)), name[0] == '-',
8448 is_variadic, is_synthesized,
8449 true, // is_implicitly_declared; we force this to true because we don't have source locations
8450 is_defined, imp_control, false /*has_related_result_type*/);
8452 if (objc_method_decl == nullptr)
8457 llvm::SmallVector<clang::ParmVarDecl *, 12> params;
8459 for (unsigned param_index = 0; param_index < num_args; ++param_index)
8461 params.push_back (clang::ParmVarDecl::Create (*ast,
8463 clang::SourceLocation(),
8464 clang::SourceLocation(),
8465 nullptr, // anonymous
8466 method_function_prototype->getParamType(param_index),
8472 objc_method_decl->setMethodParams(*ast, llvm::ArrayRef<clang::ParmVarDecl*>(params), llvm::ArrayRef<clang::SourceLocation>());
8475 class_interface_decl->addDecl (objc_method_decl);
8477 #ifdef LLDB_CONFIGURATION_DEBUG
8478 VerifyDecl(objc_method_decl);
8481 return objc_method_decl;
8485 ClangASTContext::GetHasExternalStorage (const CompilerType &type)
8487 if (ClangUtil::IsClangType(type))
8490 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(type));
8492 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8495 case clang::Type::Record:
8497 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
8498 if (cxx_record_decl)
8499 return cxx_record_decl->hasExternalLexicalStorage () || cxx_record_decl->hasExternalVisibleStorage();
8503 case clang::Type::Enum:
8505 clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
8507 return enum_decl->hasExternalLexicalStorage () || enum_decl->hasExternalVisibleStorage();
8511 case clang::Type::ObjCObject:
8512 case clang::Type::ObjCInterface:
8514 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8515 assert (objc_class_type);
8516 if (objc_class_type)
8518 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
8520 if (class_interface_decl)
8521 return class_interface_decl->hasExternalLexicalStorage () || class_interface_decl->hasExternalVisibleStorage ();
8526 case clang::Type::Typedef:
8527 return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()));
8529 case clang::Type::Auto:
8530 return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()));
8532 case clang::Type::Elaborated:
8533 return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()));
8535 case clang::Type::Paren:
8536 return GetHasExternalStorage (CompilerType(type.GetTypeSystem(), llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
8546 ClangASTContext::SetHasExternalStorage (lldb::opaque_compiler_type_t type, bool has_extern)
8551 clang::QualType qual_type (GetCanonicalQualType(type));
8553 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
8556 case clang::Type::Record:
8558 clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
8559 if (cxx_record_decl)
8561 cxx_record_decl->setHasExternalLexicalStorage (has_extern);
8562 cxx_record_decl->setHasExternalVisibleStorage (has_extern);
8568 case clang::Type::Enum:
8570 clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
8573 enum_decl->setHasExternalLexicalStorage (has_extern);
8574 enum_decl->setHasExternalVisibleStorage (has_extern);
8580 case clang::Type::ObjCObject:
8581 case clang::Type::ObjCInterface:
8583 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
8584 assert (objc_class_type);
8585 if (objc_class_type)
8587 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
8589 if (class_interface_decl)
8591 class_interface_decl->setHasExternalLexicalStorage (has_extern);
8592 class_interface_decl->setHasExternalVisibleStorage (has_extern);
8599 case clang::Type::Typedef:
8600 return SetHasExternalStorage(llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), has_extern);
8602 case clang::Type::Auto:
8603 return SetHasExternalStorage (llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr(), has_extern);
8605 case clang::Type::Elaborated:
8606 return SetHasExternalStorage (llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), has_extern);
8608 case clang::Type::Paren:
8609 return SetHasExternalStorage (llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr(), has_extern);
8618 #pragma mark TagDecl
8621 ClangASTContext::StartTagDeclarationDefinition (const CompilerType &type)
8623 clang::QualType qual_type(ClangUtil::GetQualType(type));
8624 if (!qual_type.isNull())
8626 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8629 clang::TagDecl *tag_decl = tag_type->getDecl();
8632 tag_decl->startDefinition();
8637 const clang::ObjCObjectType *object_type = qual_type->getAs<clang::ObjCObjectType>();
8640 clang::ObjCInterfaceDecl *interface_decl = object_type->getInterface();
8643 interface_decl->startDefinition();
8652 ClangASTContext::CompleteTagDeclarationDefinition (const CompilerType& type)
8654 clang::QualType qual_type(ClangUtil::GetQualType(type));
8655 if (!qual_type.isNull())
8657 // Make sure we use the same methodology as ClangASTContext::StartTagDeclarationDefinition()
8658 // as to how we start/end the definition. Previously we were calling
8659 const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
8662 clang::TagDecl *tag_decl = tag_type->getDecl();
8665 clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast_or_null<clang::CXXRecordDecl>(tag_decl);
8667 if (cxx_record_decl)
8669 if (!cxx_record_decl->isCompleteDefinition())
8670 cxx_record_decl->completeDefinition();
8671 cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
8672 cxx_record_decl->setHasExternalLexicalStorage (false);
8673 cxx_record_decl->setHasExternalVisibleStorage (false);
8679 const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
8683 clang::EnumDecl *enum_decl = enutype->getDecl();
8687 if (!enum_decl->isCompleteDefinition())
8689 ClangASTContext *lldb_ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
8690 if (lldb_ast == nullptr)
8692 clang::ASTContext *ast = lldb_ast->getASTContext();
8694 /// TODO This really needs to be fixed.
8696 QualType integer_type(enum_decl->getIntegerType());
8697 if (!integer_type.isNull())
8699 unsigned NumPositiveBits = 1;
8700 unsigned NumNegativeBits = 0;
8702 clang::QualType promotion_qual_type;
8703 // If the enum integer type is less than an integer in bit width,
8704 // then we must promote it to an integer size.
8705 if (ast->getTypeSize(enum_decl->getIntegerType()) < ast->getTypeSize(ast->IntTy))
8707 if (enum_decl->getIntegerType()->isSignedIntegerType())
8708 promotion_qual_type = ast->IntTy;
8710 promotion_qual_type = ast->UnsignedIntTy;
8713 promotion_qual_type = enum_decl->getIntegerType();
8715 enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits);
8726 ClangASTContext::AddEnumerationValueToEnumerationType (lldb::opaque_compiler_type_t type,
8727 const CompilerType &enumerator_clang_type,
8728 const Declaration &decl,
8731 uint32_t enum_value_bit_size)
8733 if (type && enumerator_clang_type.IsValid() && name && name[0])
8735 clang::QualType enum_qual_type (GetCanonicalQualType(type));
8737 bool is_signed = false;
8738 enumerator_clang_type.IsIntegerType (is_signed);
8739 const clang::Type *clang_type = enum_qual_type.getTypePtr();
8742 const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
8746 llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed);
8747 enum_llvm_apsint = enum_value;
8748 clang::EnumConstantDecl *enumerator_decl = clang::EnumConstantDecl::Create(
8749 *getASTContext(), enutype->getDecl(), clang::SourceLocation(),
8750 name ? &getASTContext()->Idents.get(name) : nullptr, // Identifier
8751 ClangUtil::GetQualType(enumerator_clang_type), nullptr, enum_llvm_apsint);
8753 if (enumerator_decl)
8755 enutype->getDecl()->addDecl(enumerator_decl);
8757 #ifdef LLDB_CONFIGURATION_DEBUG
8758 VerifyDecl(enumerator_decl);
8770 ClangASTContext::GetEnumerationIntegerType (lldb::opaque_compiler_type_t type)
8772 clang::QualType enum_qual_type (GetCanonicalQualType(type));
8773 const clang::Type *clang_type = enum_qual_type.getTypePtr();
8776 const clang::EnumType *enutype = llvm::dyn_cast<clang::EnumType>(clang_type);
8779 clang::EnumDecl *enum_decl = enutype->getDecl();
8781 return CompilerType (getASTContext(), enum_decl->getIntegerType());
8784 return CompilerType();
8788 ClangASTContext::CreateMemberPointerType (const CompilerType& type, const CompilerType &pointee_type)
8790 if (type && pointee_type.IsValid() && type.GetTypeSystem() == pointee_type.GetTypeSystem())
8792 ClangASTContext *ast = llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
8794 return CompilerType();
8795 return CompilerType(ast->getASTContext(),
8796 ast->getASTContext()->getMemberPointerType(ClangUtil::GetQualType(pointee_type),
8797 ClangUtil::GetQualType(type).getTypePtr()));
8799 return CompilerType();
8804 ClangASTContext::ConvertStringToFloatValue (lldb::opaque_compiler_type_t type, const char *s, uint8_t *dst, size_t dst_size)
8808 clang::QualType qual_type (GetCanonicalQualType(type));
8810 bool is_complex = false;
8811 if (IsFloatingPointType (type, count, is_complex))
8813 // TODO: handle complex and vector types
8817 llvm::StringRef s_sref(s);
8818 llvm::APFloat ap_float(getASTContext()->getFloatTypeSemantics(qual_type), s_sref);
8820 const uint64_t bit_size = getASTContext()->getTypeSize (qual_type);
8821 const uint64_t byte_size = bit_size / 8;
8822 if (dst_size >= byte_size)
8824 Scalar scalar = ap_float.bitcastToAPInt().zextOrTrunc(llvm::NextPowerOf2(byte_size) * 8);
8825 lldb_private::Error get_data_error;
8826 if (scalar.GetAsMemoryData(dst, byte_size, lldb_private::endian::InlHostByteOrder(), get_data_error))
8836 //----------------------------------------------------------------------
8838 //----------------------------------------------------------------------
8839 #define DEPTH_INCREMENT 2
8842 ClangASTContext::DumpValue (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
8844 lldb::Format format,
8845 const lldb_private::DataExtractor &data,
8846 lldb::offset_t data_byte_offset,
8847 size_t data_byte_size,
8848 uint32_t bitfield_bit_size,
8849 uint32_t bitfield_bit_offset,
8858 clang::QualType qual_type(GetQualType(type));
8859 switch (qual_type->getTypeClass())
8861 case clang::Type::Record:
8862 if (GetCompleteType(type))
8864 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
8865 const clang::RecordDecl *record_decl = record_type->getDecl();
8866 assert(record_decl);
8867 uint32_t field_bit_offset = 0;
8868 uint32_t field_byte_offset = 0;
8869 const clang::ASTRecordLayout &record_layout = getASTContext()->getASTRecordLayout(record_decl);
8870 uint32_t child_idx = 0;
8872 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
8873 if (cxx_record_decl)
8875 // We might have base classes to print out first
8876 clang::CXXRecordDecl::base_class_const_iterator base_class, base_class_end;
8877 for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end();
8878 base_class != base_class_end;
8881 const clang::CXXRecordDecl *base_class_decl = llvm::cast<clang::CXXRecordDecl>(base_class->getType()->getAs<clang::RecordType>()->getDecl());
8883 // Skip empty base classes
8884 if (verbose == false && ClangASTContext::RecordHasFields(base_class_decl) == false)
8887 if (base_class->isVirtual())
8888 field_bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8;
8890 field_bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8;
8891 field_byte_offset = field_bit_offset / 8;
8892 assert (field_bit_offset % 8 == 0);
8898 clang::QualType base_class_qual_type = base_class->getType();
8899 std::string base_class_type_name(base_class_qual_type.getAsString());
8901 // Indent and print the base class type name
8902 s->Printf("\n%*s%s ", depth + DEPTH_INCREMENT, "", base_class_type_name.c_str());
8904 clang::TypeInfo base_class_type_info = getASTContext()->getTypeInfo(base_class_qual_type);
8906 // Dump the value of the member
8907 CompilerType base_clang_type(getASTContext(), base_class_qual_type);
8908 base_clang_type.DumpValue (exe_ctx,
8909 s, // Stream to dump to
8910 base_clang_type.GetFormat(), // The format with which to display the member
8911 data, // Data buffer containing all bytes for this type
8912 data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from
8913 base_class_type_info.Width / 8, // Size of this type in bytes
8914 0, // Bitfield bit size
8915 0, // Bitfield bit offset
8916 show_types, // Boolean indicating if we should show the variable types
8917 show_summary, // Boolean indicating if we should show a summary for the current type
8918 verbose, // Verbose output?
8919 depth + DEPTH_INCREMENT); // Scope depth for any types that have children
8924 uint32_t field_idx = 0;
8925 clang::RecordDecl::field_iterator field, field_end;
8926 for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx)
8928 // Print the starting squiggly bracket (if this is the
8929 // first member) or comma (for member 2 and beyond) for
8930 // the struct/union/class member.
8937 s->Printf("\n%*s", depth + DEPTH_INCREMENT, "");
8939 clang::QualType field_type = field->getType();
8940 // Print the member type if requested
8941 // Figure out the type byte size (field_type_info.first) and
8942 // alignment (field_type_info.second) from the AST context.
8943 clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(field_type);
8944 assert(field_idx < record_layout.getFieldCount());
8945 // Figure out the field offset within the current struct/union/class type
8946 field_bit_offset = record_layout.getFieldOffset (field_idx);
8947 field_byte_offset = field_bit_offset / 8;
8948 uint32_t field_bitfield_bit_size = 0;
8949 uint32_t field_bitfield_bit_offset = 0;
8950 if (ClangASTContext::FieldIsBitfield (getASTContext(), *field, field_bitfield_bit_size))
8951 field_bitfield_bit_offset = field_bit_offset % 8;
8955 std::string field_type_name(field_type.getAsString());
8956 if (field_bitfield_bit_size > 0)
8957 s->Printf("(%s:%u) ", field_type_name.c_str(), field_bitfield_bit_size);
8959 s->Printf("(%s) ", field_type_name.c_str());
8961 // Print the member name and equal sign
8962 s->Printf("%s = ", field->getNameAsString().c_str());
8965 // Dump the value of the member
8966 CompilerType field_clang_type (getASTContext(), field_type);
8967 field_clang_type.DumpValue (exe_ctx,
8968 s, // Stream to dump to
8969 field_clang_type.GetFormat(), // The format with which to display the member
8970 data, // Data buffer containing all bytes for this type
8971 data_byte_offset + field_byte_offset,// Offset into "data" where to grab value from
8972 field_type_info.Width / 8, // Size of this type in bytes
8973 field_bitfield_bit_size, // Bitfield bit size
8974 field_bitfield_bit_offset, // Bitfield bit offset
8975 show_types, // Boolean indicating if we should show the variable types
8976 show_summary, // Boolean indicating if we should show a summary for the current type
8977 verbose, // Verbose output?
8978 depth + DEPTH_INCREMENT); // Scope depth for any types that have children
8981 // Indent the trailing squiggly bracket
8983 s->Printf("\n%*s}", depth, "");
8987 case clang::Type::Enum:
8988 if (GetCompleteType(type))
8990 const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr());
8991 const clang::EnumDecl *enum_decl = enutype->getDecl();
8993 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
8994 lldb::offset_t offset = data_byte_offset;
8995 const int64_t enum_value = data.GetMaxU64Bitfield(&offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset);
8996 for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
8998 if (enum_pos->getInitVal() == enum_value)
9000 s->Printf("%s", enum_pos->getNameAsString().c_str());
9004 // If we have gotten here we didn't get find the enumerator in the
9005 // enum decl, so just print the integer.
9006 s->Printf("%" PRIi64, enum_value);
9010 case clang::Type::ConstantArray:
9012 const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(qual_type.getTypePtr());
9013 bool is_array_of_characters = false;
9014 clang::QualType element_qual_type = array->getElementType();
9016 const clang::Type *canonical_type = element_qual_type->getCanonicalTypeInternal().getTypePtr();
9018 is_array_of_characters = canonical_type->isCharType();
9020 const uint64_t element_count = array->getSize().getLimitedValue();
9022 clang::TypeInfo field_type_info = getASTContext()->getTypeInfo(element_qual_type);
9024 uint32_t element_idx = 0;
9025 uint32_t element_offset = 0;
9026 uint64_t element_byte_size = field_type_info.Width / 8;
9027 uint32_t element_stride = element_byte_size;
9029 if (is_array_of_characters)
9032 data.Dump(s, data_byte_offset, lldb::eFormatChar, element_byte_size, element_count, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
9038 CompilerType element_clang_type(getASTContext(), element_qual_type);
9039 lldb::Format element_format = element_clang_type.GetFormat();
9041 for (element_idx = 0; element_idx < element_count; ++element_idx)
9043 // Print the starting squiggly bracket (if this is the
9044 // first member) or comman (for member 2 and beyong) for
9045 // the struct/union/class member.
9046 if (element_idx == 0)
9051 // Indent and print the index
9052 s->Printf("\n%*s[%u] ", depth + DEPTH_INCREMENT, "", element_idx);
9054 // Figure out the field offset within the current struct/union/class type
9055 element_offset = element_idx * element_stride;
9057 // Dump the value of the member
9058 element_clang_type.DumpValue (exe_ctx,
9059 s, // Stream to dump to
9060 element_format, // The format with which to display the element
9061 data, // Data buffer containing all bytes for this type
9062 data_byte_offset + element_offset,// Offset into "data" where to grab value from
9063 element_byte_size, // Size of this type in bytes
9064 0, // Bitfield bit size
9065 0, // Bitfield bit offset
9066 show_types, // Boolean indicating if we should show the variable types
9067 show_summary, // Boolean indicating if we should show a summary for the current type
9068 verbose, // Verbose output?
9069 depth + DEPTH_INCREMENT); // Scope depth for any types that have children
9072 // Indent the trailing squiggly bracket
9073 if (element_idx > 0)
9074 s->Printf("\n%*s}", depth, "");
9079 case clang::Type::Typedef:
9081 clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
9083 CompilerType typedef_clang_type (getASTContext(), typedef_qual_type);
9084 lldb::Format typedef_format = typedef_clang_type.GetFormat();
9085 clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type);
9086 uint64_t typedef_byte_size = typedef_type_info.Width / 8;
9088 return typedef_clang_type.DumpValue (exe_ctx,
9089 s, // Stream to dump to
9090 typedef_format, // The format with which to display the element
9091 data, // Data buffer containing all bytes for this type
9092 data_byte_offset, // Offset into "data" where to grab value from
9093 typedef_byte_size, // Size of this type in bytes
9094 bitfield_bit_size, // Bitfield bit size
9095 bitfield_bit_offset,// Bitfield bit offset
9096 show_types, // Boolean indicating if we should show the variable types
9097 show_summary, // Boolean indicating if we should show a summary for the current type
9098 verbose, // Verbose output?
9099 depth); // Scope depth for any types that have children
9103 case clang::Type::Auto:
9105 clang::QualType elaborated_qual_type = llvm::cast<clang::AutoType>(qual_type)->getDeducedType();
9106 CompilerType elaborated_clang_type (getASTContext(), elaborated_qual_type);
9107 lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
9108 clang::TypeInfo elaborated_type_info = getASTContext()->getTypeInfo(elaborated_qual_type);
9109 uint64_t elaborated_byte_size = elaborated_type_info.Width / 8;
9111 return elaborated_clang_type.DumpValue (exe_ctx,
9112 s, // Stream to dump to
9113 elaborated_format, // The format with which to display the element
9114 data, // Data buffer containing all bytes for this type
9115 data_byte_offset, // Offset into "data" where to grab value from
9116 elaborated_byte_size, // Size of this type in bytes
9117 bitfield_bit_size, // Bitfield bit size
9118 bitfield_bit_offset,// Bitfield bit offset
9119 show_types, // Boolean indicating if we should show the variable types
9120 show_summary, // Boolean indicating if we should show a summary for the current type
9121 verbose, // Verbose output?
9122 depth); // Scope depth for any types that have children
9126 case clang::Type::Elaborated:
9128 clang::QualType elaborated_qual_type = llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType();
9129 CompilerType elaborated_clang_type (getASTContext(), elaborated_qual_type);
9130 lldb::Format elaborated_format = elaborated_clang_type.GetFormat();
9131 clang::TypeInfo elaborated_type_info = getASTContext()->getTypeInfo(elaborated_qual_type);
9132 uint64_t elaborated_byte_size = elaborated_type_info.Width / 8;
9134 return elaborated_clang_type.DumpValue (exe_ctx,
9135 s, // Stream to dump to
9136 elaborated_format, // The format with which to display the element
9137 data, // Data buffer containing all bytes for this type
9138 data_byte_offset, // Offset into "data" where to grab value from
9139 elaborated_byte_size, // Size of this type in bytes
9140 bitfield_bit_size, // Bitfield bit size
9141 bitfield_bit_offset,// Bitfield bit offset
9142 show_types, // Boolean indicating if we should show the variable types
9143 show_summary, // Boolean indicating if we should show a summary for the current type
9144 verbose, // Verbose output?
9145 depth); // Scope depth for any types that have children
9149 case clang::Type::Paren:
9151 clang::QualType desugar_qual_type = llvm::cast<clang::ParenType>(qual_type)->desugar();
9152 CompilerType desugar_clang_type (getASTContext(), desugar_qual_type);
9154 lldb::Format desugar_format = desugar_clang_type.GetFormat();
9155 clang::TypeInfo desugar_type_info = getASTContext()->getTypeInfo(desugar_qual_type);
9156 uint64_t desugar_byte_size = desugar_type_info.Width / 8;
9158 return desugar_clang_type.DumpValue (exe_ctx,
9159 s, // Stream to dump to
9160 desugar_format, // The format with which to display the element
9161 data, // Data buffer containing all bytes for this type
9162 data_byte_offset, // Offset into "data" where to grab value from
9163 desugar_byte_size, // Size of this type in bytes
9164 bitfield_bit_size, // Bitfield bit size
9165 bitfield_bit_offset,// Bitfield bit offset
9166 show_types, // Boolean indicating if we should show the variable types
9167 show_summary, // Boolean indicating if we should show a summary for the current type
9168 verbose, // Verbose output?
9169 depth); // Scope depth for any types that have children
9174 // We are down to a scalar type that we just need to display.
9181 LLDB_INVALID_ADDRESS,
9183 bitfield_bit_offset);
9186 DumpSummary (type, exe_ctx, s, data, data_byte_offset, data_byte_size);
9195 ClangASTContext::DumpTypeValue (lldb::opaque_compiler_type_t type, Stream *s,
9196 lldb::Format format,
9197 const lldb_private::DataExtractor &data,
9198 lldb::offset_t byte_offset,
9200 uint32_t bitfield_bit_size,
9201 uint32_t bitfield_bit_offset,
9202 ExecutionContextScope *exe_scope)
9206 if (IsAggregateType(type))
9212 clang::QualType qual_type(GetQualType(type));
9214 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
9217 case clang::Type::Typedef:
9219 clang::QualType typedef_qual_type = llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
9220 CompilerType typedef_clang_type (getASTContext(), typedef_qual_type);
9221 if (format == eFormatDefault)
9222 format = typedef_clang_type.GetFormat();
9223 clang::TypeInfo typedef_type_info = getASTContext()->getTypeInfo(typedef_qual_type);
9224 uint64_t typedef_byte_size = typedef_type_info.Width / 8;
9226 return typedef_clang_type.DumpTypeValue (s,
9227 format, // The format with which to display the element
9228 data, // Data buffer containing all bytes for this type
9229 byte_offset, // Offset into "data" where to grab value from
9230 typedef_byte_size, // Size of this type in bytes
9231 bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield
9232 bitfield_bit_offset, // Offset in bits of a bitfield value if bitfield_bit_size != 0
9237 case clang::Type::Enum:
9238 // If our format is enum or default, show the enumeration value as
9239 // its enumeration string value, else just display it as requested.
9240 if ((format == eFormatEnum || format == eFormatDefault) && GetCompleteType(type))
9242 const clang::EnumType *enutype = llvm::cast<clang::EnumType>(qual_type.getTypePtr());
9243 const clang::EnumDecl *enum_decl = enutype->getDecl();
9245 clang::EnumDecl::enumerator_iterator enum_pos, enum_end_pos;
9246 const bool is_signed = qual_type->isSignedIntegerOrEnumerationType();
9247 lldb::offset_t offset = byte_offset;
9250 const int64_t enum_svalue = data.GetMaxS64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
9251 for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
9253 if (enum_pos->getInitVal().getSExtValue() == enum_svalue)
9255 s->PutCString (enum_pos->getNameAsString().c_str());
9259 // If we have gotten here we didn't get find the enumerator in the
9260 // enum decl, so just print the integer.
9261 s->Printf("%" PRIi64, enum_svalue);
9265 const uint64_t enum_uvalue = data.GetMaxU64Bitfield (&offset, byte_size, bitfield_bit_size, bitfield_bit_offset);
9266 for (enum_pos = enum_decl->enumerator_begin(), enum_end_pos = enum_decl->enumerator_end(); enum_pos != enum_end_pos; ++enum_pos)
9268 if (enum_pos->getInitVal().getZExtValue() == enum_uvalue)
9270 s->PutCString (enum_pos->getNameAsString().c_str());
9274 // If we have gotten here we didn't get find the enumerator in the
9275 // enum decl, so just print the integer.
9276 s->Printf("%" PRIu64, enum_uvalue);
9280 // format was not enum, just fall through and dump the value as requested....
9284 // We are down to a scalar type that we just need to display.
9286 uint32_t item_count = 1;
9287 // A few formats, we might need to modify our size and count for depending
9288 // on how we are trying to display the value...
9292 case eFormatBoolean:
9294 case eFormatComplex:
9295 case eFormatCString: // NULL terminated C strings
9296 case eFormatDecimal:
9299 case eFormatHexUppercase:
9303 case eFormatUnsigned:
9304 case eFormatPointer:
9305 case eFormatVectorOfChar:
9306 case eFormatVectorOfSInt8:
9307 case eFormatVectorOfUInt8:
9308 case eFormatVectorOfSInt16:
9309 case eFormatVectorOfUInt16:
9310 case eFormatVectorOfSInt32:
9311 case eFormatVectorOfUInt32:
9312 case eFormatVectorOfSInt64:
9313 case eFormatVectorOfUInt64:
9314 case eFormatVectorOfFloat32:
9315 case eFormatVectorOfFloat64:
9316 case eFormatVectorOfUInt128:
9320 case eFormatCharPrintable:
9321 case eFormatCharArray:
9323 case eFormatBytesWithASCII:
9324 item_count = byte_size;
9328 case eFormatUnicode16:
9329 item_count = byte_size / 2;
9333 case eFormatUnicode32:
9334 item_count = byte_size / 4;
9338 return data.Dump (s,
9344 LLDB_INVALID_ADDRESS,
9346 bitfield_bit_offset,
9358 ClangASTContext::DumpSummary (lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
9360 const lldb_private::DataExtractor &data,
9361 lldb::offset_t data_byte_offset,
9362 size_t data_byte_size)
9364 uint32_t length = 0;
9365 if (IsCStringType (type, length))
9369 Process *process = exe_ctx->GetProcessPtr();
9372 lldb::offset_t offset = data_byte_offset;
9373 lldb::addr_t pointer_address = data.GetMaxU64(&offset, data_byte_size);
9374 std::vector<uint8_t> buf;
9376 buf.resize (length);
9380 lldb_private::DataExtractor cstr_data(&buf.front(), buf.size(), process->GetByteOrder(), 4);
9383 size_t total_cstr_len = 0;
9385 while ((bytes_read = process->ReadMemory (pointer_address, &buf.front(), buf.size(), error)) > 0)
9387 const size_t len = strlen((const char *)&buf.front());
9390 if (total_cstr_len == 0)
9391 s->PutCString (" \"");
9392 cstr_data.Dump(s, 0, lldb::eFormatChar, 1, len, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
9393 total_cstr_len += len;
9394 if (len < buf.size())
9396 pointer_address += total_cstr_len;
9398 if (total_cstr_len > 0)
9406 ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type)
9408 StreamFile s (stdout, false);
9409 DumpTypeDescription (type, &s);
9410 ClangASTMetadata *metadata = ClangASTContext::GetMetadata (getASTContext(), type);
9413 metadata->Dump (&s);
9418 ClangASTContext::DumpTypeDescription (lldb::opaque_compiler_type_t type, Stream *s)
9422 clang::QualType qual_type(GetQualType(type));
9424 llvm::SmallVector<char, 1024> buf;
9425 llvm::raw_svector_ostream llvm_ostrm (buf);
9427 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
9430 case clang::Type::ObjCObject:
9431 case clang::Type::ObjCInterface:
9433 GetCompleteType(type);
9435 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type.getTypePtr());
9436 assert (objc_class_type);
9437 if (objc_class_type)
9439 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
9440 if (class_interface_decl)
9442 clang::PrintingPolicy policy = getASTContext()->getPrintingPolicy();
9443 class_interface_decl->print(llvm_ostrm, policy, s->GetIndentLevel());
9449 case clang::Type::Typedef:
9451 const clang::TypedefType *typedef_type = qual_type->getAs<clang::TypedefType>();
9454 const clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
9455 std::string clang_typedef_name (typedef_decl->getQualifiedNameAsString());
9456 if (!clang_typedef_name.empty())
9458 s->PutCString ("typedef ");
9459 s->PutCString (clang_typedef_name.c_str());
9465 case clang::Type::Auto:
9466 CompilerType (getASTContext(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType()).DumpTypeDescription(s);
9469 case clang::Type::Elaborated:
9470 CompilerType (getASTContext(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType()).DumpTypeDescription(s);
9473 case clang::Type::Paren:
9474 CompilerType (getASTContext(), llvm::cast<clang::ParenType>(qual_type)->desugar()).DumpTypeDescription(s);
9477 case clang::Type::Record:
9479 GetCompleteType(type);
9481 const clang::RecordType *record_type = llvm::cast<clang::RecordType>(qual_type.getTypePtr());
9482 const clang::RecordDecl *record_decl = record_type->getDecl();
9483 const clang::CXXRecordDecl *cxx_record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
9485 if (cxx_record_decl)
9486 cxx_record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel());
9488 record_decl->print(llvm_ostrm, getASTContext()->getPrintingPolicy(), s->GetIndentLevel());
9494 const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr());
9497 clang::TagDecl *tag_decl = tag_type->getDecl();
9499 tag_decl->print(llvm_ostrm, 0);
9503 std::string clang_type_name(qual_type.getAsString());
9504 if (!clang_type_name.empty())
9505 s->PutCString (clang_type_name.c_str());
9512 s->Write (buf.data(), buf.size());
9518 ClangASTContext::DumpTypeName (const CompilerType &type)
9520 if (ClangUtil::IsClangType(type))
9522 clang::QualType qual_type(ClangUtil::GetCanonicalQualType(ClangUtil::RemoveFastQualifiers(type)));
9524 const clang::Type::TypeClass type_class = qual_type->getTypeClass();
9527 case clang::Type::Record:
9529 const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
9530 if (cxx_record_decl)
9531 printf("class %s", cxx_record_decl->getName().str().c_str());
9535 case clang::Type::Enum:
9537 clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl();
9540 printf("enum %s", enum_decl->getName().str().c_str());
9545 case clang::Type::ObjCObject:
9546 case clang::Type::ObjCInterface:
9548 const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
9549 if (objc_class_type)
9551 clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface();
9552 // We currently can't complete objective C types through the newly added ASTContext
9553 // because it only supports TagDecl objects right now...
9554 if (class_interface_decl)
9555 printf("@class %s", class_interface_decl->getName().str().c_str());
9561 case clang::Type::Typedef:
9562 printf("typedef %s", llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getName().str().c_str());
9565 case clang::Type::Auto:
9567 return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr()));
9569 case clang::Type::Elaborated:
9570 printf("elaborated ");
9571 return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()));
9573 case clang::Type::Paren:
9575 return DumpTypeName (CompilerType (type.GetTypeSystem(), llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
9578 printf("ClangASTContext::DumpTypeName() type_class = %u", type_class);
9587 clang::ClassTemplateDecl *
9588 ClangASTContext::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
9589 lldb::AccessType access_type,
9590 const char *parent_name,
9592 const ClangASTContext::TemplateParameterInfos &template_param_infos)
9594 if (template_param_infos.IsValid())
9596 std::string template_basename(parent_name);
9597 template_basename.erase (template_basename.find('<'));
9599 return CreateClassTemplateDecl (decl_ctx,
9601 template_basename.c_str(),
9603 template_param_infos);
9609 ClangASTContext::CompleteTagDecl (void *baton, clang::TagDecl *decl)
9611 ClangASTContext *ast = (ClangASTContext *)baton;
9612 SymbolFile *sym_file = ast->GetSymbolFile();
9615 CompilerType clang_type = GetTypeForDecl (decl);
9617 sym_file->CompleteType (clang_type);
9622 ClangASTContext::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
9624 ClangASTContext *ast = (ClangASTContext *)baton;
9625 SymbolFile *sym_file = ast->GetSymbolFile();
9628 CompilerType clang_type = GetTypeForDecl (decl);
9630 sym_file->CompleteType (clang_type);
9635 ClangASTContext::GetDWARFParser()
9637 if (!m_dwarf_ast_parser_ap)
9638 m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this));
9639 return m_dwarf_ast_parser_ap.get();
9644 ClangASTContext::GetPDBParser()
9646 if (!m_pdb_ast_parser_ap)
9647 m_pdb_ast_parser_ap.reset(new PDBASTParser(*this));
9648 return m_pdb_ast_parser_ap.get();
9653 ClangASTContext::LayoutRecordType(void *baton,
9654 const clang::RecordDecl *record_decl,
9656 uint64_t &alignment,
9657 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
9658 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
9659 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
9661 ClangASTContext *ast = (ClangASTContext *)baton;
9662 DWARFASTParserClang *dwarf_ast_parser = (DWARFASTParserClang *)ast->GetDWARFParser();
9663 return dwarf_ast_parser->GetClangASTImporter().LayoutRecordType(record_decl, bit_size, alignment, field_offsets,
9664 base_offsets, vbase_offsets);
9667 //----------------------------------------------------------------------
9668 // CompilerDecl override functions
9669 //----------------------------------------------------------------------
9672 ClangASTContext::DeclGetName (void *opaque_decl)
9676 clang::NamedDecl *nd = llvm::dyn_cast<NamedDecl>((clang::Decl*)opaque_decl);
9678 return ConstString(nd->getDeclName().getAsString());
9680 return ConstString();
9684 ClangASTContext::DeclGetMangledName (void *opaque_decl)
9688 clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>((clang::Decl*)opaque_decl);
9689 if (nd != nullptr && !llvm::isa<clang::ObjCMethodDecl>(nd))
9691 clang::MangleContext *mc = getMangleContext();
9692 if (mc && mc->shouldMangleCXXName(nd))
9694 llvm::SmallVector<char, 1024> buf;
9695 llvm::raw_svector_ostream llvm_ostrm (buf);
9696 if (llvm::isa<clang::CXXConstructorDecl>(nd))
9698 mc->mangleCXXCtor(llvm::dyn_cast<clang::CXXConstructorDecl>(nd), Ctor_Complete, llvm_ostrm);
9700 else if (llvm::isa<clang::CXXDestructorDecl>(nd))
9702 mc->mangleCXXDtor(llvm::dyn_cast<clang::CXXDestructorDecl>(nd), Dtor_Complete, llvm_ostrm);
9706 mc->mangleName(nd, llvm_ostrm);
9709 return ConstString(buf.data(), buf.size());
9713 return ConstString();
9717 ClangASTContext::DeclGetDeclContext (void *opaque_decl)
9720 return CompilerDeclContext(this, ((clang::Decl*)opaque_decl)->getDeclContext());
9722 return CompilerDeclContext();
9726 ClangASTContext::DeclGetFunctionReturnType(void *opaque_decl)
9728 if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl))
9729 return CompilerType(this, func_decl->getReturnType().getAsOpaquePtr());
9730 if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl))
9731 return CompilerType(this, objc_method->getReturnType().getAsOpaquePtr());
9733 return CompilerType();
9737 ClangASTContext::DeclGetFunctionNumArguments(void *opaque_decl)
9739 if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl))
9740 return func_decl->param_size();
9741 if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl))
9742 return objc_method->param_size();
9748 ClangASTContext::DeclGetFunctionArgumentType (void *opaque_decl, size_t idx)
9750 if (clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>((clang::Decl*)opaque_decl))
9752 if (idx < func_decl->param_size())
9754 ParmVarDecl *var_decl = func_decl->getParamDecl(idx);
9756 return CompilerType(this, var_decl->getOriginalType().getAsOpaquePtr());
9759 else if (clang::ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>((clang::Decl*)opaque_decl))
9761 if (idx < objc_method->param_size())
9762 return CompilerType(this, objc_method->parameters()[idx]->getOriginalType().getAsOpaquePtr());
9764 return CompilerType();
9767 //----------------------------------------------------------------------
9768 // CompilerDeclContext functions
9769 //----------------------------------------------------------------------
9771 std::vector<CompilerDecl>
9772 ClangASTContext::DeclContextFindDeclByName(void *opaque_decl_ctx,
9774 const bool ignore_using_decls)
9776 std::vector<CompilerDecl> found_decls;
9777 if (opaque_decl_ctx)
9779 DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx;
9780 std::set<DeclContext *> searched;
9781 std::multimap<DeclContext *, DeclContext *> search_queue;
9782 SymbolFile *symbol_file = GetSymbolFile();
9784 for (clang::DeclContext *decl_context = root_decl_ctx; decl_context != nullptr && found_decls.empty(); decl_context = decl_context->getParent())
9786 search_queue.insert(std::make_pair(decl_context, decl_context));
9788 for (auto it = search_queue.find(decl_context); it != search_queue.end(); it++)
9790 if (!searched.insert(it->second).second)
9792 symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second));
9794 for (clang::Decl *child : it->second->decls())
9796 if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child))
9798 if (ignore_using_decls)
9800 clang::DeclContext *from = ud->getCommonAncestor();
9801 if (searched.find(ud->getNominatedNamespace()) == searched.end())
9802 search_queue.insert(std::make_pair(from, ud->getNominatedNamespace()));
9804 else if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child))
9806 if (ignore_using_decls)
9808 for (clang::UsingShadowDecl *usd : ud->shadows())
9810 clang::Decl *target = usd->getTargetDecl();
9811 if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target))
9813 IdentifierInfo *ii = nd->getIdentifier();
9814 if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr)))
9815 found_decls.push_back(CompilerDecl(this, nd));
9819 else if (clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(child))
9821 IdentifierInfo *ii = nd->getIdentifier();
9822 if (ii != nullptr && ii->getName().equals(name.AsCString(nullptr)))
9823 found_decls.push_back(CompilerDecl(this, nd));
9832 // Look for child_decl_ctx's lookup scope in frame_decl_ctx and its parents,
9833 // and return the number of levels it took to find it, or LLDB_INVALID_DECL_LEVEL
9834 // if not found. If the decl was imported via a using declaration, its name and/or
9835 // type, if set, will be used to check that the decl found in the scope is a match.
9837 // The optional name is required by languages (like C++) to handle using declarations
9847 // // CountDeclLevels returns 0 for 'foo', 1 for 'poo', and
9848 // // LLDB_INVALID_DECL_LEVEL for 'goo'.
9851 // The optional type is useful in the case that there's a specific overload
9852 // that we're looking for that might otherwise be shadowed, like:
9860 // // CountDeclLevels returns 0 for { 'foo', void() },
9861 // // 1 for { 'foo', void(int) }, and
9862 // // LLDB_INVALID_DECL_LEVEL for { 'foo', void(int, int) }.
9865 // NOTE: Because file statics are at the TranslationUnit along with globals, a
9866 // function at file scope will return the same level as a function at global scope.
9867 // Ideally we'd like to treat the file scope as an additional scope just below the
9868 // global scope. More work needs to be done to recognise that, if the decl we're
9869 // trying to look up is static, we should compare its source file with that of the
9870 // current scope and return a lower number for it.
9872 ClangASTContext::CountDeclLevels (clang::DeclContext *frame_decl_ctx,
9873 clang::DeclContext *child_decl_ctx,
9874 ConstString *child_name,
9875 CompilerType *child_type)
9879 std::set<DeclContext *> searched;
9880 std::multimap<DeclContext *, DeclContext *> search_queue;
9881 SymbolFile *symbol_file = GetSymbolFile();
9883 // Get the lookup scope for the decl we're trying to find.
9884 clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent();
9886 // Look for it in our scope's decl context and its parents.
9888 for (clang::DeclContext *decl_ctx = frame_decl_ctx; decl_ctx != nullptr; decl_ctx = decl_ctx->getParent())
9890 if (!decl_ctx->isLookupContext())
9892 if (decl_ctx == parent_decl_ctx)
9895 search_queue.insert(std::make_pair(decl_ctx, decl_ctx));
9896 for (auto it = search_queue.find(decl_ctx); it != search_queue.end(); it++)
9898 if (searched.find(it->second) != searched.end())
9901 // Currently DWARF has one shared translation unit for all Decls at top level, so this
9902 // would erroneously find using statements anywhere. So don't look at the top-level
9903 // translation unit.
9904 // TODO fix this and add a testcase that depends on it.
9906 if (llvm::isa<clang::TranslationUnitDecl>(it->second))
9909 searched.insert(it->second);
9910 symbol_file->ParseDeclsForContext(CompilerDeclContext(this, it->second));
9912 for (clang::Decl *child : it->second->decls())
9914 if (clang::UsingDirectiveDecl *ud = llvm::dyn_cast<clang::UsingDirectiveDecl>(child))
9916 clang::DeclContext *ns = ud->getNominatedNamespace();
9917 if (ns == parent_decl_ctx)
9920 clang::DeclContext *from = ud->getCommonAncestor();
9921 if (searched.find(ns) == searched.end())
9922 search_queue.insert(std::make_pair(from, ns));
9924 else if (child_name)
9926 if (clang::UsingDecl *ud = llvm::dyn_cast<clang::UsingDecl>(child))
9928 for (clang::UsingShadowDecl *usd : ud->shadows())
9930 clang::Decl *target = usd->getTargetDecl();
9931 clang::NamedDecl *nd = llvm::dyn_cast<clang::NamedDecl>(target);
9935 IdentifierInfo *ii = nd->getIdentifier();
9936 if (ii == nullptr || !ii->getName().equals(child_name->AsCString(nullptr)))
9938 // Check types, if one was provided.
9941 CompilerType clang_type = ClangASTContext::GetTypeForDecl(nd);
9942 if (!AreTypesSame(clang_type, *child_type, /*ignore_qualifiers=*/true))
9955 return LLDB_INVALID_DECL_LEVEL;
9959 ClangASTContext::DeclContextIsStructUnionOrClass (void *opaque_decl_ctx)
9961 if (opaque_decl_ctx)
9962 return ((clang::DeclContext *)opaque_decl_ctx)->isRecord();
9968 ClangASTContext::DeclContextGetName (void *opaque_decl_ctx)
9970 if (opaque_decl_ctx)
9972 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9974 return ConstString(named_decl->getName());
9976 return ConstString();
9980 ClangASTContext::DeclContextGetScopeQualifiedName (void *opaque_decl_ctx)
9982 if (opaque_decl_ctx)
9984 clang::NamedDecl *named_decl = llvm::dyn_cast<clang::NamedDecl>((clang::DeclContext *)opaque_decl_ctx);
9986 return ConstString(llvm::StringRef(named_decl->getQualifiedNameAsString()));
9988 return ConstString();
9992 ClangASTContext::DeclContextIsClassMethod (void *opaque_decl_ctx,
9993 lldb::LanguageType *language_ptr,
9994 bool *is_instance_method_ptr,
9995 ConstString *language_object_name_ptr)
9997 if (opaque_decl_ctx)
9999 clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
10000 if (ObjCMethodDecl *objc_method = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx))
10002 if (is_instance_method_ptr)
10003 *is_instance_method_ptr = objc_method->isInstanceMethod();
10005 *language_ptr = eLanguageTypeObjC;
10006 if (language_object_name_ptr)
10007 language_object_name_ptr->SetCString("self");
10010 else if (CXXMethodDecl *cxx_method = llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx))
10012 if (is_instance_method_ptr)
10013 *is_instance_method_ptr = cxx_method->isInstance();
10015 *language_ptr = eLanguageTypeC_plus_plus;
10016 if (language_object_name_ptr)
10017 language_object_name_ptr->SetCString("this");
10020 else if (clang::FunctionDecl *function_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx))
10022 ClangASTMetadata *metadata = GetMetadata (&decl_ctx->getParentASTContext(), function_decl);
10023 if (metadata && metadata->HasObjectPtr())
10025 if (is_instance_method_ptr)
10026 *is_instance_method_ptr = true;
10028 *language_ptr = eLanguageTypeObjC;
10029 if (language_object_name_ptr)
10030 language_object_name_ptr->SetCString (metadata->GetObjectPtrName());
10038 clang::DeclContext *
10039 ClangASTContext::DeclContextGetAsDeclContext (const CompilerDeclContext &dc)
10042 return (clang::DeclContext *)dc.GetOpaqueDeclContext();
10048 ClangASTContext::DeclContextGetAsObjCMethodDecl (const CompilerDeclContext &dc)
10051 return llvm::dyn_cast<clang::ObjCMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext());
10056 ClangASTContext::DeclContextGetAsCXXMethodDecl (const CompilerDeclContext &dc)
10059 return llvm::dyn_cast<clang::CXXMethodDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext());
10063 clang::FunctionDecl *
10064 ClangASTContext::DeclContextGetAsFunctionDecl (const CompilerDeclContext &dc)
10067 return llvm::dyn_cast<clang::FunctionDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext());
10071 clang::NamespaceDecl *
10072 ClangASTContext::DeclContextGetAsNamespaceDecl (const CompilerDeclContext &dc)
10075 return llvm::dyn_cast<clang::NamespaceDecl>((clang::DeclContext *)dc.GetOpaqueDeclContext());
10080 ClangASTContext::DeclContextGetMetaData (const CompilerDeclContext &dc, const void *object)
10082 clang::ASTContext *ast = DeclContextGetClangASTContext (dc);
10084 return ClangASTContext::GetMetadata (ast, object);
10088 clang::ASTContext *
10089 ClangASTContext::DeclContextGetClangASTContext (const CompilerDeclContext &dc)
10091 ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(dc.GetTypeSystem());
10093 return ast->getASTContext();
10097 ClangASTContextForExpressions::ClangASTContextForExpressions (Target &target) :
10098 ClangASTContext (target.GetArchitecture().GetTriple().getTriple().c_str()),
10099 m_target_wp(target.shared_from_this()),
10100 m_persistent_variables (new ClangPersistentVariables)
10105 ClangASTContextForExpressions::GetUserExpression (const char *expr,
10106 const char *expr_prefix,
10107 lldb::LanguageType language,
10108 Expression::ResultType desired_type,
10109 const EvaluateExpressionOptions &options)
10111 TargetSP target_sp = m_target_wp.lock();
10115 return new ClangUserExpression(*target_sp.get(), expr, expr_prefix, language, desired_type, options);
10119 ClangASTContextForExpressions::GetFunctionCaller (const CompilerType &return_type,
10120 const Address& function_address,
10121 const ValueList &arg_value_list,
10124 TargetSP target_sp = m_target_wp.lock();
10128 Process *process = target_sp->GetProcessSP().get();
10132 return new ClangFunctionCaller (*process, return_type, function_address, arg_value_list, name);
10136 ClangASTContextForExpressions::GetUtilityFunction (const char *text,
10139 TargetSP target_sp = m_target_wp.lock();
10143 return new ClangUtilityFunction(*target_sp.get(), text, name);
10146 PersistentExpressionState *
10147 ClangASTContextForExpressions::GetPersistentExpressionState ()
10149 return m_persistent_variables.get();