Skip to content

Commit

Permalink
[lldb][NFC] Remove redundant ClangASTContext constructor that takes A…
Browse files Browse the repository at this point in the history
…rchSpec

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.
  • Loading branch information
Teemperor committed Jan 8, 2020
1 parent a1857e2 commit 0a4daff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
10 changes: 7 additions & 3 deletions lldb/include/lldb/Symbol/ClangASTContext.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down
43 changes: 16 additions & 27 deletions lldb/source/Symbol/ClangASTContext.cpp
Expand Up @@ -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());

Expand Down Expand Up @@ -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<ClangASTContext> ast_sp(new ClangASTContext(fixed_arch));
return ast_sp;
} else if (target && target->IsValid()) {
std::shared_ptr<ClangASTContextForExpressions> ast_sp(
new ClangASTContextForExpressions(*target, fixed_arch));
return ast_sp;
}
if (module)
return std::make_shared<ClangASTContext>(triple);
else if (target && target->IsValid())
return std::make_shared<ClangASTContextForExpressions>(*target, triple);
return lldb::TypeSystemSP();
}

Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 0a4daff

Please sign in to comment.