Skip to content

Commit

Permalink
[lldb][NFC] Take a llvm::Triple in ClangASTContext constructor
Browse files Browse the repository at this point in the history
This constructor is supposed to take a string representing an llvm::Triple.
We might as well take a llvm::Triple here which saves us all the string
conversions in the call sites and we make this more type safe.
  • Loading branch information
Teemperor committed Jan 7, 2020
1 parent ab1bcda commit d364815
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lldb/include/lldb/Host/HostInfoBase.h
Expand Up @@ -33,11 +33,11 @@ class HostInfoBase {
static void Initialize();
static void Terminate();

/// Gets the host target triple as a const string.
/// Gets the host target triple.
///
/// \return
/// A const string object containing the host target triple.
static llvm::StringRef GetTargetTriple();
/// The host target triple.
static llvm::Triple GetTargetTriple();

enum ArchitectureKind {
eArchKindDefault, // The overall default architecture that applications will
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/ClangASTContext.h
Expand Up @@ -56,7 +56,7 @@ class ClangASTContext : public TypeSystem {
static bool classof(const TypeSystem *ts) { return ts->isA(&ID); }

// Constructors and Destructors
explicit ClangASTContext(llvm::StringRef triple = "");
explicit ClangASTContext(llvm::Triple triple = llvm::Triple());
explicit ClangASTContext(ArchSpec arch);

/// Constructs a ClangASTContext that uses an existing ASTContext internally.
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Host/common/HostInfoBase.cpp
Expand Up @@ -48,7 +48,7 @@ struct HostInfoBaseFields {
}

llvm::once_flag m_host_triple_once;
std::string m_host_triple;
llvm::Triple m_host_triple;

llvm::once_flag m_host_arch_once;
ArchSpec m_host_arch_32;
Expand Down Expand Up @@ -82,10 +82,10 @@ void HostInfoBase::Terminate() {
g_fields = nullptr;
}

llvm::StringRef HostInfoBase::GetTargetTriple() {
llvm::Triple HostInfoBase::GetTargetTriple() {
llvm::call_once(g_fields->m_host_triple_once, []() {
g_fields->m_host_triple =
HostInfo::GetArchitecture().GetTriple().getTriple();
HostInfo::GetArchitecture().GetTriple();
});
return g_fields->m_host_triple;
}
Expand Down
Expand Up @@ -146,9 +146,7 @@ AppleObjCDeclVendor::AppleObjCDeclVendor(ObjCLanguageRuntime &runtime)
m_ast_ctx(runtime.GetProcess()
->GetTarget()
.GetArchitecture()
.GetTriple()
.getTriple()
.c_str()),
.GetTriple()),
m_type_realizer_sp(m_runtime.GetEncodingToType()) {
m_external_source = new AppleObjCExternalASTSource(*this);
llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> external_source_owning_ptr(
Expand Down
Expand Up @@ -26,9 +26,7 @@ AppleObjCTypeEncodingParser::AppleObjCTypeEncodingParser(
m_scratch_ast_ctx_up.reset(new ClangASTContext(runtime.GetProcess()
->GetTarget()
.GetArchitecture()
.GetTriple()
.str()
.c_str()));
.GetTriple()));
}

std::string AppleObjCTypeEncodingParser::ReadStructName(StringLexer &type) {
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Symbol/ClangASTContext.cpp
Expand Up @@ -499,9 +499,9 @@ static void ParseLangArgs(LangOptions &Opts, InputKind IK, const char *triple) {
Opts.NoInlineDefine = !Opt;
}

ClangASTContext::ClangASTContext(llvm::StringRef target_triple) {
if (!target_triple.empty())
SetTargetTriple(target_triple);
ClangASTContext::ClangASTContext(llvm::Triple target_triple) {
if (!target_triple.str().empty())
SetTargetTriple(target_triple.str());
// The caller didn't pass an ASTContext so create a new one for this
// ClangASTContext.
CreateASTContext();
Expand Down
3 changes: 1 addition & 2 deletions lldb/unittests/Symbol/TestClangASTContext.cpp
Expand Up @@ -26,8 +26,7 @@ class TestClangASTContext : public testing::Test {
SubsystemRAII<FileSystem, HostInfo> subsystems;

void SetUp() override {
std::string triple = HostInfo::GetTargetTriple();
m_ast.reset(new ClangASTContext(triple.c_str()));
m_ast.reset(new ClangASTContext(HostInfo::GetTargetTriple()));
}

void TearDown() override { m_ast.reset(); }
Expand Down

0 comments on commit d364815

Please sign in to comment.