Commit 06412dae authored by Jonas Devlieghere's avatar Jonas Devlieghere
Browse files

[lldb] Use std::make_unique<> (NFC)

Update the rest of lldb to use std::make_unique<>. I used clang-tidy to
automate this, which probably missed cases that are wrapped in ifdefs.
parent b5c24c24
......@@ -369,7 +369,7 @@ BreakpointOptions *BreakpointLocation::GetLocationOptions() {
// potentially expensive and we don't want to do that for the simple case
// where someone is just disabling the location.
if (m_options_up == nullptr)
m_options_up.reset(new BreakpointOptions(false));
m_options_up = std::make_unique<BreakpointOptions>(false);
return m_options_up.get();
}
......
......@@ -154,7 +154,7 @@ BreakpointOptions::BreakpointOptions(const BreakpointOptions &rhs)
m_ignore_count(rhs.m_ignore_count), m_thread_spec_up(),
m_auto_continue(rhs.m_auto_continue), m_set_flags(rhs.m_set_flags) {
if (rhs.m_thread_spec_up != nullptr)
m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
m_condition_text = rhs.m_condition_text;
m_condition_text_hash = rhs.m_condition_text_hash;
}
......@@ -170,7 +170,7 @@ operator=(const BreakpointOptions &rhs) {
m_one_shot = rhs.m_one_shot;
m_ignore_count = rhs.m_ignore_count;
if (rhs.m_thread_spec_up != nullptr)
m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
m_condition_text = rhs.m_condition_text;
m_condition_text_hash = rhs.m_condition_text_hash;
m_auto_continue = rhs.m_auto_continue;
......@@ -223,7 +223,8 @@ void BreakpointOptions::CopyOverSetOptions(const BreakpointOptions &incoming)
}
if (incoming.m_set_flags.Test(eThreadSpec) && incoming.m_thread_spec_up) {
if (!m_thread_spec_up)
m_thread_spec_up.reset(new ThreadSpec(*incoming.m_thread_spec_up));
m_thread_spec_up =
std::make_unique<ThreadSpec>(*incoming.m_thread_spec_up);
else
*m_thread_spec_up = *incoming.m_thread_spec_up;
m_set_flags.Set(eThreadSpec);
......@@ -509,7 +510,7 @@ const ThreadSpec *BreakpointOptions::GetThreadSpecNoCreate() const {
ThreadSpec *BreakpointOptions::GetThreadSpec() {
if (m_thread_spec_up == nullptr) {
m_set_flags.Set(eThreadSpec);
m_thread_spec_up.reset(new ThreadSpec());
m_thread_spec_up = std::make_unique<ThreadSpec>();
}
return m_thread_spec_up.get();
......
......@@ -36,7 +36,7 @@ WatchpointOptions::WatchpointOptions(const WatchpointOptions &rhs)
m_callback_is_synchronous(rhs.m_callback_is_synchronous),
m_thread_spec_up() {
if (rhs.m_thread_spec_up != nullptr)
m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
}
// WatchpointOptions assignment operator
......@@ -46,7 +46,7 @@ operator=(const WatchpointOptions &rhs) {
m_callback_baton_sp = rhs.m_callback_baton_sp;
m_callback_is_synchronous = rhs.m_callback_is_synchronous;
if (rhs.m_thread_spec_up != nullptr)
m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
return *this;
}
......@@ -108,7 +108,7 @@ const ThreadSpec *WatchpointOptions::GetThreadSpecNoCreate() const {
ThreadSpec *WatchpointOptions::GetThreadSpec() {
if (m_thread_spec_up == nullptr)
m_thread_spec_up.reset(new ThreadSpec());
m_thread_spec_up = std::make_unique<ThreadSpec>();
return m_thread_spec_up.get();
}
......
......@@ -4622,8 +4622,8 @@ protected:
// First step, make the specifier.
std::unique_ptr<SymbolContextSpecifier> specifier_up;
if (m_options.m_sym_ctx_specified) {
specifier_up.reset(
new SymbolContextSpecifier(GetDebugger().GetSelectedTarget()));
specifier_up = std::make_unique<SymbolContextSpecifier>(
GetDebugger().GetSelectedTarget());
if (!m_options.m_module_name.empty()) {
specifier_up->AddSpecification(
......
......@@ -1031,8 +1031,8 @@ protected:
std::unique_ptr<RegularExpression> formatter_regex;
if (m_options.m_category_regex.OptionWasSet()) {
category_regex.reset(new RegularExpression(
m_options.m_category_regex.GetCurrentValueAsRef()));
category_regex = std::make_unique<RegularExpression>(
m_options.m_category_regex.GetCurrentValueAsRef());
if (!category_regex->IsValid()) {
result.AppendErrorWithFormat(
"syntax error in category regular expression '%s'",
......@@ -1044,8 +1044,8 @@ protected:
if (argc == 1) {
const char *arg = command.GetArgumentAtIndex(0);
formatter_regex.reset(
new RegularExpression(llvm::StringRef::withNullAsEmpty(arg)));
formatter_regex = std::make_unique<RegularExpression>(
llvm::StringRef::withNullAsEmpty(arg));
if (!formatter_regex->IsValid()) {
result.AppendErrorWithFormat("syntax error in regular expression '%s'",
arg);
......@@ -2092,7 +2092,8 @@ protected:
if (argc == 1) {
const char *arg = command.GetArgumentAtIndex(0);
regex.reset(new RegularExpression(llvm::StringRef::withNullAsEmpty(arg)));
regex = std::make_unique<RegularExpression>(
llvm::StringRef::withNullAsEmpty(arg));
if (!regex->IsValid()) {
result.AppendErrorWithFormat(
"syntax error in category regular expression '%s'", arg);
......
......@@ -253,9 +253,9 @@ IOHandlerEditline::IOHandlerEditline(
m_input_sp && m_input_sp->GetIsRealTerminal();
if (use_editline) {
m_editline_up.reset(new Editline(editline_name, GetInputFILE(),
GetOutputFILE(), GetErrorFILE(),
m_color_prompts));
m_editline_up = std::make_unique<Editline>(editline_name, GetInputFILE(),
GetOutputFILE(), GetErrorFILE(),
m_color_prompts);
m_editline_up->SetIsInputCompleteCallback(IsInputCompleteCallback, this);
m_editline_up->SetAutoCompleteCallback(AutoCompleteCallback, this);
// See if the delegate supports fixing indentation
......
......@@ -3910,7 +3910,7 @@ IOHandlerCursesGUI::IOHandlerCursesGUI(Debugger &debugger)
void IOHandlerCursesGUI::Activate() {
IOHandler::Activate();
if (!m_app_ap) {
m_app_ap.reset(new Application(GetInputFILE(), GetOutputFILE()));
m_app_ap = std::make_unique<Application>(GetInputFILE(), GetOutputFILE());
// This is both a window and a menu delegate
std::shared_ptr<ApplicationDelegate> app_delegate_sp(
......
......@@ -265,11 +265,9 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
builder.setEngineKind(llvm::EngineKind::JIT)
.setErrorStr(&error_string)
.setRelocationModel(triple.isOSBinFormatMachO()
? llvm::Reloc::PIC_
: llvm::Reloc::Static)
.setMCJITMemoryManager(
std::unique_ptr<MemoryManager>(new MemoryManager(*this)))
.setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
: llvm::Reloc::Static)
.setMCJITMemoryManager(std::make_unique<MemoryManager>(*this))
.setOptLevel(llvm::CodeGenOpt::Less);
llvm::StringRef mArch;
......
......@@ -399,7 +399,8 @@ uint32_t Materializer::AddPersistentVariable(
lldb::ExpressionVariableSP &persistent_variable_sp,
PersistentVariableDelegate *delegate, Status &err) {
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
iter->reset(new EntityPersistentVariable(persistent_variable_sp, delegate));
*iter = std::make_unique<EntityPersistentVariable>(persistent_variable_sp,
delegate);
uint32_t ret = AddStructMember(**iter);
(*iter)->SetOffset(ret);
return ret;
......@@ -752,7 +753,7 @@ private:
uint32_t Materializer::AddVariable(lldb::VariableSP &variable_sp, Status &err) {
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
iter->reset(new EntityVariable(variable_sp));
*iter = std::make_unique<EntityVariable>(variable_sp);
uint32_t ret = AddStructMember(**iter);
(*iter)->SetOffset(ret);
return ret;
......@@ -1030,8 +1031,8 @@ uint32_t Materializer::AddResultVariable(const CompilerType &type,
PersistentVariableDelegate *delegate,
Status &err) {
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
iter->reset(new EntityResultVariable(type, is_program_reference,
keep_in_memory, delegate));
*iter = std::make_unique<EntityResultVariable>(type, is_program_reference,
keep_in_memory, delegate);
uint32_t ret = AddStructMember(**iter);
(*iter)->SetOffset(ret);
return ret;
......@@ -1147,7 +1148,7 @@ private:
uint32_t Materializer::AddSymbol(const Symbol &symbol_sp, Status &err) {
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
iter->reset(new EntitySymbol(symbol_sp));
*iter = std::make_unique<EntitySymbol>(symbol_sp);
uint32_t ret = AddStructMember(**iter);
(*iter)->SetOffset(ret);
return ret;
......@@ -1324,7 +1325,7 @@ private:
uint32_t Materializer::AddRegister(const RegisterInfo &register_info,
Status &err) {
EntityVector::iterator iter = m_entities.insert(m_entities.end(), EntityUP());
iter->reset(new EntityRegister(register_info));
*iter = std::make_unique<EntityRegister>(register_info);
uint32_t ret = AddStructMember(**iter);
(*iter)->SetOffset(ret);
return ret;
......
......@@ -209,7 +209,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
// this. For now, we assume we must assume we don't own it.
std::unique_ptr<TCPSocket> tcp_socket;
tcp_socket.reset(new TCPSocket(fd, false, false));
tcp_socket = std::make_unique<TCPSocket>(fd, false, false);
// Try and get a socket option from this file descriptor to see if
// this is a socket and set m_is_socket accordingly.
int resuse;
......
......@@ -798,7 +798,8 @@ void Options::HandleOptionArgumentCompletion(
interpreter.GetDebugger().GetSelectedTarget();
// Search filters require a target...
if (target_sp)
filter_up.reset(new SearchFilterByModule(target_sp, module_spec));
filter_up =
std::make_unique<SearchFilterByModule>(target_sp, module_spec);
}
break;
}
......
......@@ -102,6 +102,5 @@ Status ScriptInterpreter::SetBreakpointCommandCallbackFunction(
std::unique_ptr<ScriptInterpreterLocker>
ScriptInterpreter::AcquireInterpreterLock() {
return std::unique_ptr<ScriptInterpreterLocker>(
new ScriptInterpreterLocker());
return std::make_unique<ScriptInterpreterLocker>();
}
......@@ -331,7 +331,7 @@ ClangExpressionParser::ClangExpressionParser(
}
// 1. Create a new compiler instance.
m_compiler.reset(new CompilerInstance());
m_compiler = std::make_unique<CompilerInstance>();
// When capturing a reproducer, hook up the file collector with clang to
// collector modules and headers.
......@@ -641,12 +641,12 @@ ClangExpressionParser::ClangExpressionParser(
m_compiler->createASTContext();
clang::ASTContext &ast_context = m_compiler->getASTContext();
m_ast_context.reset(new TypeSystemClang(
"Expression ASTContext for '" + m_filename + "'", ast_context));
m_ast_context = std::make_unique<TypeSystemClang>(
"Expression ASTContext for '" + m_filename + "'", ast_context);
std::string module_name("$__lldb_module");
m_llvm_context.reset(new LLVMContext());
m_llvm_context = std::make_unique<LLVMContext>();
m_code_generator.reset(CreateLLVMCodeGen(
m_compiler->getDiagnostics(), module_name,
m_compiler->getHeaderSearchOpts(), m_compiler->getPreprocessorOpts(),
......@@ -1047,11 +1047,11 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
std::unique_ptr<clang::ASTConsumer> Consumer;
if (ast_transformer) {
Consumer.reset(new ASTConsumerForwarder(ast_transformer));
Consumer = std::make_unique<ASTConsumerForwarder>(ast_transformer);
} else if (m_code_generator) {
Consumer.reset(new ASTConsumerForwarder(m_code_generator.get()));
Consumer = std::make_unique<ASTConsumerForwarder>(m_code_generator.get());
} else {
Consumer.reset(new ASTConsumer());
Consumer = std::make_unique<ASTConsumer>();
}
clang::ASTContext &ast_context = m_compiler->getASTContext();
......
......@@ -209,8 +209,8 @@ ClangFunctionCaller::CompileFunction(lldb::ThreadSP thread_to_use_sp,
clang::ASTConsumer *
ClangFunctionCaller::ClangFunctionCallerHelper::ASTTransformer(
clang::ASTConsumer *passthrough) {
m_struct_extractor.reset(new ASTStructExtractor(
passthrough, m_owner.GetWrapperStructName(), m_owner));
m_struct_extractor = std::make_unique<ASTStructExtractor>(
passthrough, m_owner.GetWrapperStructName(), m_owner);
return m_struct_extractor.get();
}
......@@ -187,9 +187,9 @@ ClangModulesDeclVendorImpl::ClangModulesDeclVendorImpl(
m_parser(std::move(parser)) {
// Initialize our TypeSystemClang.
m_ast_context.reset(
new TypeSystemClang("ClangModulesDeclVendor ASTContext",
m_compiler_instance->getASTContext()));
m_ast_context =
std::make_unique<TypeSystemClang>("ClangModulesDeclVendor ASTContext",
m_compiler_instance->getASTContext());
}
void ClangModulesDeclVendorImpl::ReportModuleExportsHelper(
......
......@@ -595,7 +595,7 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
// Parse the expression
//
m_materializer_up.reset(new Materializer());
m_materializer_up = std::make_unique<Materializer>();
ResetDeclMap(exe_ctx, m_result_delegate, keep_result_in_memory);
......@@ -783,7 +783,7 @@ bool ClangUserExpression::Complete(ExecutionContext &exe_ctx,
// Parse the expression
//
m_materializer_up.reset(new Materializer());
m_materializer_up = std::make_unique<Materializer>();
ResetDeclMap(exe_ctx, m_result_delegate, /*keep result in memory*/ true);
......@@ -919,16 +919,16 @@ void ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap(
auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state);
ast_importer = persistent_vars->GetClangASTImporter();
}
m_expr_decl_map_up.reset(
new ClangExpressionDeclMap(keep_result_in_memory, &delegate,
exe_ctx.GetTargetSP(), ast_importer, ctx_obj));
m_expr_decl_map_up = std::make_unique<ClangExpressionDeclMap>(
keep_result_in_memory, &delegate, exe_ctx.GetTargetSP(), ast_importer,
ctx_obj);
}
clang::ASTConsumer *
ClangUserExpression::ClangUserExpressionHelper::ASTTransformer(
clang::ASTConsumer *passthrough) {
m_result_synthesizer_up.reset(
new ASTResultSynthesizer(passthrough, m_top_level, m_target));
m_result_synthesizer_up = std::make_unique<ASTResultSynthesizer>(
passthrough, m_top_level, m_target);
return m_result_synthesizer_up.get();
}
......
......@@ -167,7 +167,7 @@ void ClangUtilityFunction::ClangUtilityFunctionHelper::ResetDeclMap(
auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state);
ast_importer = persistent_vars->GetClangASTImporter();
}
m_expr_decl_map_up.reset(
new ClangExpressionDeclMap(keep_result_in_memory, nullptr,
exe_ctx.GetTargetSP(), ast_importer, nullptr));
m_expr_decl_map_up = std::make_unique<ClangExpressionDeclMap>(
keep_result_in_memory, nullptr, exe_ctx.GetTargetSP(), ast_importer,
nullptr);
}
......@@ -66,9 +66,9 @@ emulateLookupInCtxt(Sema &sema, llvm::StringRef name, DeclContext *ctxt) {
IdentifierInfo &ident = sema.getASTContext().Idents.get(name);
std::unique_ptr<LookupResult> lookup_result;
lookup_result.reset(new LookupResult(sema, DeclarationName(&ident),
SourceLocation(),
Sema::LookupOrdinaryName));
lookup_result = std::make_unique<LookupResult>(sema, DeclarationName(&ident),
SourceLocation(),
Sema::LookupOrdinaryName);
// Usually during parsing we already encountered the scopes we would use. But
// here don't have these scopes so we have to emulate the behavior of the
......
......@@ -1842,7 +1842,7 @@ bool IRForTarget::runOnModule(Module &llvm_module) {
lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
m_module = &llvm_module;
m_target_data.reset(new DataLayout(m_module));
m_target_data = std::make_unique<DataLayout>(m_module);
m_intptr_ty = llvm::Type::getIntNTy(m_module->getContext(),
m_target_data->getPointerSizeInBits());
......
......@@ -159,8 +159,8 @@ EmulateInstructionMIPS::EmulateInstructionMIPS(
target->createMCSubtargetInfo(triple.getTriple(), cpu, features));
assert(m_asm_info.get() && m_subtype_info.get());
m_context.reset(
new llvm::MCContext(m_asm_info.get(), m_reg_info.get(), nullptr));
m_context = std::make_unique<llvm::MCContext>(m_asm_info.get(),
m_reg_info.get(), nullptr);
assert(m_context.get());
m_disasm.reset(target->createMCDisassembler(*m_subtype_info, *m_context));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment