diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 9e8d301fd3f7d1..3cad8414b128bd 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -55,9 +55,13 @@ class ClangASTContext : public TypeSystem { bool isA(const void *ClassID) const override { return ClassID == &ID; } static bool classof(const TypeSystem *ts) { return ts->isA(&ID); } - // Constructors and Destructors + /// Constructs a ClangASTContext with an ASTContext using the given triple. + /// + /// \param triple The llvm::Triple used for the ASTContext. The triple defines + /// certain characteristics of the ASTContext and its types + /// (e.g., whether certain primitive types exist or what their + /// signedness is). explicit ClangASTContext(llvm::Triple triple = llvm::Triple()); - explicit ClangASTContext(ArchSpec arch); /// Constructs a ClangASTContext that uses an existing ASTContext internally. /// Useful when having an existing ASTContext created by Clang. @@ -969,7 +973,7 @@ class ClangASTContext : public TypeSystem { class ClangASTContextForExpressions : public ClangASTContext { public: - ClangASTContextForExpressions(Target &target, ArchSpec arch); + ClangASTContextForExpressions(Target &target, llvm::Triple triple); ~ClangASTContextForExpressions() override = default; diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 314aaa83d4e6c0..c846e410acfa9b 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -507,13 +507,6 @@ ClangASTContext::ClangASTContext(llvm::Triple target_triple) { CreateASTContext(); } -ClangASTContext::ClangASTContext(ArchSpec arch) { - SetTargetTriple(arch.GetTriple().str()); - // The caller didn't pass an ASTContext so create a new one for this - // ClangASTContext. - CreateASTContext(); -} - ClangASTContext::ClangASTContext(ASTContext &existing_ctxt) { SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str()); @@ -548,29 +541,25 @@ lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language, if (!arch.IsValid()) return lldb::TypeSystemSP(); - ArchSpec fixed_arch = arch; + llvm::Triple triple = arch.GetTriple(); // LLVM wants this to be set to iOS or MacOSX; if we're working on // a bare-boards type image, change the triple for llvm's benefit. - if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple && - fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) { - if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm || - fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 || - fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64_32 || - fixed_arch.GetTriple().getArch() == llvm::Triple::thumb) { - fixed_arch.GetTriple().setOS(llvm::Triple::IOS); + if (triple.getVendor() == llvm::Triple::Apple && + triple.getOS() == llvm::Triple::UnknownOS) { + if (triple.getArch() == llvm::Triple::arm || + triple.getArch() == llvm::Triple::aarch64 || + triple.getArch() == llvm::Triple::aarch64_32 || + triple.getArch() == llvm::Triple::thumb) { + triple.setOS(llvm::Triple::IOS); } else { - fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX); + triple.setOS(llvm::Triple::MacOSX); } } - if (module) { - std::shared_ptr ast_sp(new ClangASTContext(fixed_arch)); - return ast_sp; - } else if (target && target->IsValid()) { - std::shared_ptr ast_sp( - new ClangASTContextForExpressions(*target, fixed_arch)); - return ast_sp; - } + if (module) + return std::make_shared(triple); + else if (target && target->IsValid()) + return std::make_shared(*target, triple); return lldb::TypeSystemSP(); } @@ -9255,9 +9244,9 @@ ClangASTContext::DeclContextGetClangASTContext(const CompilerDeclContext &dc) { return nullptr; } -ClangASTContextForExpressions::ClangASTContextForExpressions(Target &target, - ArchSpec arch) - : ClangASTContext(arch), m_target_wp(target.shared_from_this()), +ClangASTContextForExpressions::ClangASTContextForExpressions( + Target &target, llvm::Triple triple) + : ClangASTContext(triple), m_target_wp(target.shared_from_this()), m_persistent_variables(new ClangPersistentVariables) { m_scratch_ast_source_up.reset(new ClangASTSource( target.shared_from_this(), target.GetClangASTImporter()));