Commit 1a6cf58b authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[base] Move implicit_cast to macros.h

macros.h already not only defines macros, but also templatized helpers
like {bit_cast} and {arraysize}. Thus {implicit_cast} also belongs
there.

R=tebbi@chromium.org

Bug: v8:7570
Change-Id: Iaea6075dad359d62498453575f22d73ca84e2323
Reviewed-on: https://chromium-review.googlesource.com/1042401
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52991}
parent bc218a2e
......@@ -43,7 +43,6 @@ template <typename T, size_t N>
char (&ArraySizeHelper(const T (&array)[N]))[N];
#endif
// bit_cast<Dest,Source> is a template function that implements the
// equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in
// very low-level functions like the protobuf library and fast math
......@@ -271,6 +270,14 @@ struct Use {
} // namespace base
} // namespace v8
// implicit_cast<A>(x) triggers an implicit cast from {x} to type {A}. This is
// useful in situations where static_cast<A>(x) would do too much.
// Only use this for cheap-to-copy types, or use move semantics explicitly.
template <class A>
V8_INLINE A implicit_cast(A x) {
return x;
}
// Define our own macros for writing 64-bit constants. This is less fragile
// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
// works on compilers that don't have it (like MSVC).
......
......@@ -56,13 +56,6 @@ std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
// implicit_cast<A>(x) triggers an implicit cast from {x} to type {A}. This is
// useful in situations where static_cast<A>(x) would do too much.
template <class A>
A implicit_cast(A x) {
return x;
}
// Helper to determine how to pass values: Pass scalars and arrays by value,
// others by const reference (even if it was a non-const ref before; this is
// disallowed by the style guide anyway).
......
......@@ -7,6 +7,7 @@
#include <functional>
#include "src/base/macros.h"
#include "src/compiler/code-assembler.h"
#include "src/globals.h"
#include "src/objects.h"
......@@ -409,8 +410,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
const G& false_body) {
return UncheckedCast<A>(SelectImpl(
condition,
[&]() -> Node* { return base::implicit_cast<TNode<A>>(true_body()); },
[&]() -> Node* { return base::implicit_cast<TNode<A>>(false_body()); },
[&]() -> Node* { return implicit_cast<TNode<A>>(true_body()); },
[&]() -> Node* { return implicit_cast<TNode<A>>(false_body()); },
MachineRepresentationOf<A>::value));
}
......@@ -2547,11 +2548,11 @@ class ToDirectStringAssembler : public CodeStubAssembler {
const Flags flags_;
};
#define CSA_CHECK(csa, x) \
(csa)->Check( \
[&]() -> compiler::Node* { \
return base::implicit_cast<compiler::SloppyTNode<Word32T>>(x); \
}, \
#define CSA_CHECK(csa, x) \
(csa)->Check( \
[&]() -> compiler::Node* { \
return implicit_cast<compiler::SloppyTNode<Word32T>>(x); \
}, \
#x, __FILE__, __LINE__)
#ifdef DEBUG
......@@ -2584,7 +2585,7 @@ class ToDirectStringAssembler : public CodeStubAssembler {
#define CSA_ASSERT(csa, ...) \
(csa)->Assert( \
[&]() -> compiler::Node* { \
return base::implicit_cast<compiler::SloppyTNode<Word32T>>( \
return implicit_cast<compiler::SloppyTNode<Word32T>>( \
EXPAND(CSA_ASSERT_GET_FIRST(__VA_ARGS__))); \
}, \
EXPAND(CSA_ASSERT_GET_FIRST_STR(__VA_ARGS__)), __FILE__, __LINE__, \
......
......@@ -11,7 +11,7 @@
// Clients of this interface shouldn't depend on lots of compiler internals.
// Do not include anything from src/compiler here!
#include "src/allocation.h"
#include "src/base/template-utils.h"
#include "src/base/macros.h"
#include "src/builtins/builtins.h"
#include "src/code-factory.h"
#include "src/globals.h"
......@@ -608,7 +608,7 @@ class V8_EXPORT_PRIVATE CodeAssembler {
template <class A>
operator SloppyTNode<A>() {
return base::implicit_cast<TNode<A>>(*this);
return implicit_cast<TNode<A>>(*this);
}
Node* node() const { return node_; }
......@@ -949,7 +949,7 @@ class V8_EXPORT_PRIVATE CodeAssembler {
TNode<Object> CallRuntime(Runtime::FunctionId function,
SloppyTNode<Object> context, TArgs... args) {
return CallRuntimeImpl(function, context,
base::implicit_cast<SloppyTNode<Object>>(args)...);
implicit_cast<SloppyTNode<Object>>(args)...);
}
template <class... TArgs>
......@@ -958,8 +958,8 @@ class V8_EXPORT_PRIVATE CodeAssembler {
template <class... TArgs>
TNode<Object> TailCallRuntime(Runtime::FunctionId function,
SloppyTNode<Object> context, TArgs... args) {
return TailCallRuntimeImpl(
function, context, base::implicit_cast<SloppyTNode<Object>>(args)...);
return TailCallRuntimeImpl(function, context,
implicit_cast<SloppyTNode<Object>>(args)...);
}
//
......@@ -970,14 +970,14 @@ class V8_EXPORT_PRIVATE CodeAssembler {
Node* CallStub(Callable const& callable, Node* context, TArgs... args) {
Node* target = HeapConstant(callable.code());
return CallStub(callable.descriptor(), target, context,
base::implicit_cast<Node*>(args)...);
implicit_cast<Node*>(args)...);
}
template <class... TArgs>
Node* CallStub(const CallInterfaceDescriptor& descriptor, Node* target,
Node* context, TArgs... args) {
return CallStubR(descriptor, 1, target, context,
base::implicit_cast<Node*>(args)...);
implicit_cast<Node*>(args)...);
}
template <class... TArgs>
......@@ -998,7 +998,7 @@ class V8_EXPORT_PRIVATE CodeAssembler {
Node* TailCallStub(const CallInterfaceDescriptor& descriptor, Node* target,
Node* context, TArgs... args) {
return TailCallStubImpl(descriptor, target, context,
base::implicit_cast<Node*>(args)...);
implicit_cast<Node*>(args)...);
}
template <class... TArgs>
Node* TailCallStubImpl(const CallInterfaceDescriptor& descriptor,
......
This diff is collapsed.
......@@ -8,6 +8,7 @@
#include <set>
#include <string>
#include "src/base/macros.h"
#include "src/torque/declarations.h"
#include "src/torque/file-visitor.h"
#include "src/torque/global-context.h"
......@@ -43,11 +44,11 @@ class DeclarationVisitor : public FileVisitor {
}
void Visit(DefaultModuleDeclaration* decl) {
decl->SetModule(global_context_.GetDefaultModule());
Visit(base::implicit_cast<ModuleDeclaration*>(decl));
Visit(implicit_cast<ModuleDeclaration*>(decl));
}
void Visit(ExplicitModuleDeclaration* decl) {
decl->SetModule(global_context_.GetModule(decl->name));
Visit(base::implicit_cast<ModuleDeclaration*>(decl));
Visit(implicit_cast<ModuleDeclaration*>(decl));
}
void Visit(IdentifierExpression* expr) {}
......
......@@ -7,6 +7,7 @@
#include <string>
#include "src/base/macros.h"
#include "src/torque/ast.h"
#include "src/torque/file-visitor.h"
#include "src/torque/global-context.h"
......@@ -90,10 +91,10 @@ class ImplementationVisitor : public FileVisitor {
void Visit(ModuleDeclaration* decl);
void Visit(DefaultModuleDeclaration* decl) {
Visit(base::implicit_cast<ModuleDeclaration*>(decl));
Visit(implicit_cast<ModuleDeclaration*>(decl));
}
void Visit(ExplicitModuleDeclaration* decl) {
Visit(base::implicit_cast<ModuleDeclaration*>(decl));
Visit(implicit_cast<ModuleDeclaration*>(decl));
}
void Visit(MacroDeclaration* decl);
void Visit(BuiltinDeclaration* decl);
......
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