Skip to content

Commit 0a4daff

Browse files
committed
[lldb][NFC] Remove redundant ClangASTContext constructor that takes ArchSpec
ArchSpec has a superset of the information of llvm::Triple but the ClangASTContext just uses the Triple part of it. This deletes the ArchSpec constructor and all the code creating ArchSpecs and instead just uses the llvm::Triple constructor for ClangASTContext.
1 parent a1857e2 commit 0a4daff

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

lldb/include/lldb/Symbol/ClangASTContext.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ class ClangASTContext : public TypeSystem {
5555
bool isA(const void *ClassID) const override { return ClassID == &ID; }
5656
static bool classof(const TypeSystem *ts) { return ts->isA(&ID); }
5757

58-
// Constructors and Destructors
58+
/// Constructs a ClangASTContext with an ASTContext using the given triple.
59+
///
60+
/// \param triple The llvm::Triple used for the ASTContext. The triple defines
61+
/// certain characteristics of the ASTContext and its types
62+
/// (e.g., whether certain primitive types exist or what their
63+
/// signedness is).
5964
explicit ClangASTContext(llvm::Triple triple = llvm::Triple());
60-
explicit ClangASTContext(ArchSpec arch);
6165

6266
/// Constructs a ClangASTContext that uses an existing ASTContext internally.
6367
/// Useful when having an existing ASTContext created by Clang.
@@ -969,7 +973,7 @@ class ClangASTContext : public TypeSystem {
969973

970974
class ClangASTContextForExpressions : public ClangASTContext {
971975
public:
972-
ClangASTContextForExpressions(Target &target, ArchSpec arch);
976+
ClangASTContextForExpressions(Target &target, llvm::Triple triple);
973977

974978
~ClangASTContextForExpressions() override = default;
975979

lldb/source/Symbol/ClangASTContext.cpp

+16-27
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,6 @@ ClangASTContext::ClangASTContext(llvm::Triple target_triple) {
507507
CreateASTContext();
508508
}
509509

510-
ClangASTContext::ClangASTContext(ArchSpec arch) {
511-
SetTargetTriple(arch.GetTriple().str());
512-
// The caller didn't pass an ASTContext so create a new one for this
513-
// ClangASTContext.
514-
CreateASTContext();
515-
}
516-
517510
ClangASTContext::ClangASTContext(ASTContext &existing_ctxt) {
518511
SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str());
519512

@@ -548,29 +541,25 @@ lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language,
548541
if (!arch.IsValid())
549542
return lldb::TypeSystemSP();
550543

551-
ArchSpec fixed_arch = arch;
544+
llvm::Triple triple = arch.GetTriple();
552545
// LLVM wants this to be set to iOS or MacOSX; if we're working on
553546
// a bare-boards type image, change the triple for llvm's benefit.
554-
if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple &&
555-
fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) {
556-
if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm ||
557-
fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
558-
fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64_32 ||
559-
fixed_arch.GetTriple().getArch() == llvm::Triple::thumb) {
560-
fixed_arch.GetTriple().setOS(llvm::Triple::IOS);
547+
if (triple.getVendor() == llvm::Triple::Apple &&
548+
triple.getOS() == llvm::Triple::UnknownOS) {
549+
if (triple.getArch() == llvm::Triple::arm ||
550+
triple.getArch() == llvm::Triple::aarch64 ||
551+
triple.getArch() == llvm::Triple::aarch64_32 ||
552+
triple.getArch() == llvm::Triple::thumb) {
553+
triple.setOS(llvm::Triple::IOS);
561554
} else {
562-
fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX);
555+
triple.setOS(llvm::Triple::MacOSX);
563556
}
564557
}
565558

566-
if (module) {
567-
std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext(fixed_arch));
568-
return ast_sp;
569-
} else if (target && target->IsValid()) {
570-
std::shared_ptr<ClangASTContextForExpressions> ast_sp(
571-
new ClangASTContextForExpressions(*target, fixed_arch));
572-
return ast_sp;
573-
}
559+
if (module)
560+
return std::make_shared<ClangASTContext>(triple);
561+
else if (target && target->IsValid())
562+
return std::make_shared<ClangASTContextForExpressions>(*target, triple);
574563
return lldb::TypeSystemSP();
575564
}
576565

@@ -9255,9 +9244,9 @@ ClangASTContext::DeclContextGetClangASTContext(const CompilerDeclContext &dc) {
92559244
return nullptr;
92569245
}
92579246

9258-
ClangASTContextForExpressions::ClangASTContextForExpressions(Target &target,
9259-
ArchSpec arch)
9260-
: ClangASTContext(arch), m_target_wp(target.shared_from_this()),
9247+
ClangASTContextForExpressions::ClangASTContextForExpressions(
9248+
Target &target, llvm::Triple triple)
9249+
: ClangASTContext(triple), m_target_wp(target.shared_from_this()),
92619250
m_persistent_variables(new ClangPersistentVariables) {
92629251
m_scratch_ast_source_up.reset(new ClangASTSource(
92639252
target.shared_from_this(), target.GetClangASTImporter()));

0 commit comments

Comments
 (0)