Commit da49a384 authored by Nico Hartmann's avatar Nico Hartmann Committed by Commit Bot

[torque] Capture owning pointers in std::unique_ptr immediately

In some places objects where allocated on the heap and stored
in a std::unique_ptr later. This CL changes this so that a

The std::unique_ptr<T>(new T(...)) construct is replaced with

std: :unique_ptr takes ownership of new objects immediately.
std: :make_unique<T>(...) where possible.
Change-Id: Icdb4c9e7536d2b437df1a5bb6c3ad94c97e1e4cc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1871916
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64603}
parent bcc0d8f4
......@@ -1163,8 +1163,8 @@ DECLARE_CONTEXTUAL_VARIABLE(CurrentAst, Ast);
template <class T, class... Args>
T* MakeNode(Args... args) {
return CurrentAst::Get().AddNode(std::unique_ptr<T>(
new T(CurrentSourcePosition::Get(), std::move(args)...)));
return CurrentAst::Get().AddNode(
std::make_unique<T>(CurrentSourcePosition::Get(), std::move(args)...));
}
} // namespace torque
......
......@@ -145,7 +145,7 @@ base::Optional<GenericType*> Declarations::TryLookupGenericType(
}
Namespace* Declarations::DeclareNamespace(const std::string& name) {
return Declare(name, std::unique_ptr<Namespace>(new Namespace(name)));
return Declare(name, std::make_unique<Namespace>(name));
}
TypeAlias* Declarations::DeclareType(const Identifier* name, const Type* type) {
......@@ -265,8 +265,8 @@ RuntimeFunction* Declarations::DeclareRuntimeFunction(
void Declarations::DeclareExternConstant(Identifier* name, const Type* type,
std::string value) {
CheckAlreadyDeclared<Value>(name->value, "constant");
ExternConstant* result = new ExternConstant(name, type, value);
Declare(name->value, std::unique_ptr<Declarable>(result));
Declare(name->value, std::unique_ptr<ExternConstant>(
new ExternConstant(name, type, value)));
}
NamespaceConstant* Declarations::DeclareNamespaceConstant(Identifier* name,
......@@ -274,9 +274,10 @@ NamespaceConstant* Declarations::DeclareNamespaceConstant(Identifier* name,
Expression* body) {
CheckAlreadyDeclared<Value>(name->value, "constant");
std::string external_name = GlobalContext::MakeUniqueName(name->value);
NamespaceConstant* result =
new NamespaceConstant(name, std::move(external_name), type, body);
Declare(name->value, std::unique_ptr<Declarable>(result));
std::unique_ptr<NamespaceConstant> namespaceConstant(
new NamespaceConstant(name, std::move(external_name), type, body));
NamespaceConstant* result = namespaceConstant.get();
Declare(name->value, std::move(namespaceConstant));
return result;
}
......
......@@ -426,8 +426,9 @@ class Grammar {
// NewSymbol() allocates a fresh symbol and stores it in the current grammar.
// This is necessary to define helpers that create new symbols.
Symbol* NewSymbol(std::initializer_list<Rule> rules = {}) {
Symbol* result = new Symbol(rules);
generated_symbols_.push_back(std::unique_ptr<Symbol>(result));
auto symbol = std::make_unique<Symbol>(rules);
Symbol* result = symbol.get();
generated_symbols_.push_back(std::move(symbol));
return result;
}
......
......@@ -47,9 +47,10 @@ class TypeOracle : public ContextualClass<TypeOracle> {
ClassFlags flags, const std::string& generates,
ClassDeclaration* decl,
const TypeAlias* alias) {
ClassType* result = new ClassType(parent, CurrentNamespace(), name, flags,
generates, decl, alias);
Get().aggregate_types_.push_back(std::unique_ptr<ClassType>(result));
std::unique_ptr<ClassType> type(new ClassType(
parent, CurrentNamespace(), name, flags, generates, decl, alias));
ClassType* result = type.get();
Get().aggregate_types_.push_back(std::move(type));
return result;
}
......@@ -110,8 +111,9 @@ class TypeOracle : public ContextualClass<TypeOracle> {
static const TopType* GetTopType(std::string reason,
const Type* source_type) {
TopType* result = new TopType(std::move(reason), source_type);
Get().top_types_.push_back(std::unique_ptr<TopType>(result));
std::unique_ptr<TopType> type(new TopType(std::move(reason), source_type));
TopType* result = type.get();
Get().top_types_.push_back(std::move(type));
return result;
}
......
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