Commit d16b45eb authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[base] Remove pre-c++11 restrictions of macros

Before the existence of "= delete", we were enforcing that the
DISALLOW_* macros were used in the private: section of classes only.
This is not needed any more, hence remove the comment on the macros.

Also, introduce macros for making types move-only, and use them
instead of our special macro in wasm.

R=bmeurer@chromium.org
CC=titzer@chromium.org

Change-Id: Iceba456fb0a32ae67defe16e35b865db8c8da500
Reviewed-on: https://chromium-review.googlesource.com/577687Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46773}
parent 57b9a3b1
...@@ -102,28 +102,34 @@ V8_INLINE Dest bit_cast(Source const& source) { ...@@ -102,28 +102,34 @@ V8_INLINE Dest bit_cast(Source const& source) {
return dest; return dest;
} }
// Explicitly declare the assignment operator as deleted.
#define DISALLOW_ASSIGN(TypeName) TypeName& operator=(const TypeName&) = delete;
// Put this in the private: declarations for a class to be unassignable. // Explicitly declare the copy constructor and assignment operator as deleted.
#define DISALLOW_ASSIGN(TypeName) void operator=(const TypeName&)
// A macro to disallow the evil copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \ TypeName(const TypeName&) = delete; \
void operator=(const TypeName&) = delete DISALLOW_ASSIGN(TypeName)
// A macro to disallow all the implicit constructors, namely the // Explicitly declare all implicit constructors as deleted, namely the
// default constructor, copy constructor and operator= functions. // default constructor, copy constructor and operator= functions.
// // This is especially useful for classes containing only static methods.
// This should be used in the private: declarations for a class
// that wants to prevent anyone from instantiating it. This is
// especially useful for classes containing only static methods.
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
TypeName() = delete; \ TypeName() = delete; \
DISALLOW_COPY_AND_ASSIGN(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName)
// Disallow copying a type, but provide default construction, move construction
// and move assignment. Especially useful for move-only structs.
#define MOVE_ONLY_WITH_DEFAULT_CONSTRUCTORS(TypeName) \
TypeName() = default; \
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(TypeName)
// Disallow copying a type, and only provide move construction and move
// assignment. Especially useful for move-only structs.
#define MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(TypeName) \
TypeName(TypeName&&) = default; \
TypeName& operator=(TypeName&&) = default; \
DISALLOW_COPY_AND_ASSIGN(TypeName)
// A macro to disallow the dynamic allocation. // A macro to disallow the dynamic allocation.
// This should be used in the private: declarations for a class // This should be used in the private: declarations for a class
// Declaring operator new and delete as deleted is not spec compliant. // Declaring operator new and delete as deleted is not spec compliant.
......
...@@ -94,6 +94,8 @@ class InterpreterHandle; ...@@ -94,6 +94,8 @@ class InterpreterHandle;
InterpreterHandle* GetInterpreterHandle(WasmDebugInfo* debug_info); InterpreterHandle* GetInterpreterHandle(WasmDebugInfo* debug_info);
class InterpreterHandle { class InterpreterHandle {
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(InterpreterHandle);
WasmInstance instance_; WasmInstance instance_;
WasmInterpreter interpreter_; WasmInterpreter interpreter_;
Isolate* isolate_; Isolate* isolate_;
......
...@@ -34,15 +34,6 @@ class CallDescriptor; ...@@ -34,15 +34,6 @@ class CallDescriptor;
namespace wasm { namespace wasm {
class ErrorThrower; class ErrorThrower;
// Use this in the private section to mark a struct move-only.
#define WASM_MOVE_ONLY_STRUCT(name) \
public: \
name() = default; \
name(name&&) = default; \
\
private: \
DISALLOW_COPY_AND_ASSIGN(name)
enum WasmExternalKind { enum WasmExternalKind {
kExternalFunction = 0, kExternalFunction = 0,
kExternalTable = 1, kExternalTable = 1,
...@@ -143,6 +134,8 @@ struct WasmDataSegment { ...@@ -143,6 +134,8 @@ struct WasmDataSegment {
// Static representation of a wasm indirect call table. // Static representation of a wasm indirect call table.
struct WasmIndirectFunctionTable { struct WasmIndirectFunctionTable {
MOVE_ONLY_WITH_DEFAULT_CONSTRUCTORS(WasmIndirectFunctionTable);
uint32_t min_size = 0; // minimum table size. uint32_t min_size = 0; // minimum table size.
uint32_t max_size = 0; // maximum table size. uint32_t max_size = 0; // maximum table size.
bool has_max = false; // true if there is a maximum size. bool has_max = false; // true if there is a maximum size.
...@@ -151,22 +144,18 @@ struct WasmIndirectFunctionTable { ...@@ -151,22 +144,18 @@ struct WasmIndirectFunctionTable {
bool imported = false; // true if imported. bool imported = false; // true if imported.
bool exported = false; // true if exported. bool exported = false; // true if exported.
SignatureMap map; // canonicalizing map for sig indexes. SignatureMap map; // canonicalizing map for sig indexes.
private:
WASM_MOVE_ONLY_STRUCT(WasmIndirectFunctionTable);
}; };
// Static representation of how to initialize a table. // Static representation of how to initialize a table.
struct WasmTableInit { struct WasmTableInit {
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmTableInit);
WasmTableInit(uint32_t table_index, WasmInitExpr offset) WasmTableInit(uint32_t table_index, WasmInitExpr offset)
: table_index(table_index), offset(offset) {} : table_index(table_index), offset(offset) {}
uint32_t table_index; uint32_t table_index;
WasmInitExpr offset; WasmInitExpr offset;
std::vector<uint32_t> entries; std::vector<uint32_t> entries;
private:
WASM_MOVE_ONLY_STRUCT(WasmTableInit);
}; };
// Static representation of a wasm import. // Static representation of a wasm import.
...@@ -190,6 +179,8 @@ struct ModuleWireBytes; ...@@ -190,6 +179,8 @@ struct ModuleWireBytes;
// Static representation of a module. // Static representation of a module.
struct V8_EXPORT_PRIVATE WasmModule { struct V8_EXPORT_PRIVATE WasmModule {
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmModule);
static const uint32_t kPageSize = 0x10000; // Page size, 64kb. static const uint32_t kPageSize = 0x10000; // Page size, 64kb.
static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb
...@@ -228,14 +219,14 @@ struct V8_EXPORT_PRIVATE WasmModule { ...@@ -228,14 +219,14 @@ struct V8_EXPORT_PRIVATE WasmModule {
private: private:
// TODO(kschimpf) - Encapsulate more fields. // TODO(kschimpf) - Encapsulate more fields.
ModuleOrigin origin_ = kWasmOrigin; // origin of the module ModuleOrigin origin_ = kWasmOrigin; // origin of the module
DISALLOW_COPY_AND_ASSIGN(WasmModule);
}; };
typedef Managed<WasmModule> WasmModuleWrapper; typedef Managed<WasmModule> WasmModuleWrapper;
// An instantiated wasm module, including memory, function table, etc. // An instantiated wasm module, including memory, function table, etc.
struct WasmInstance { struct WasmInstance {
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmInstance);
const WasmModule* module; // static representation of the module. const WasmModule* module; // static representation of the module.
// -- Heap allocated -------------------------------------------------------- // -- Heap allocated --------------------------------------------------------
Handle<Context> context; // JavaScript native context. Handle<Context> context; // JavaScript native context.
...@@ -271,9 +262,6 @@ struct WasmInstance { ...@@ -271,9 +262,6 @@ struct WasmInstance {
code = handle(*code, isolate); code = handle(*code, isolate);
} }
} }
private:
WASM_MOVE_ONLY_STRUCT(WasmInstance);
}; };
// Interface to the storage (wire bytes) of a wasm module. // Interface to the storage (wire bytes) of a wasm module.
...@@ -336,6 +324,8 @@ struct V8_EXPORT_PRIVATE ModuleWireBytes { ...@@ -336,6 +324,8 @@ struct V8_EXPORT_PRIVATE ModuleWireBytes {
// Interface provided to the decoder/graph builder which contains only // Interface provided to the decoder/graph builder which contains only
// minimal information about the globals, functions, and function tables. // minimal information about the globals, functions, and function tables.
struct V8_EXPORT_PRIVATE ModuleEnv { struct V8_EXPORT_PRIVATE ModuleEnv {
MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(ModuleEnv);
ModuleEnv(const WasmModule* module, WasmInstance* instance) ModuleEnv(const WasmModule* module, WasmInstance* instance)
: module(module), : module(module),
instance(instance), instance(instance),
...@@ -392,9 +382,6 @@ struct V8_EXPORT_PRIVATE ModuleEnv { ...@@ -392,9 +382,6 @@ struct V8_EXPORT_PRIVATE ModuleEnv {
DCHECK_NOT_NULL(instance); DCHECK_NOT_NULL(instance);
return instance->function_code[index]; return instance->function_code[index];
} }
private:
WASM_MOVE_ONLY_STRUCT(ModuleEnv);
}; };
// A ModuleEnv together with ModuleWireBytes. // A ModuleEnv together with ModuleWireBytes.
...@@ -573,8 +560,6 @@ void ValidateOrphanedInstance(Isolate* isolate, ...@@ -573,8 +560,6 @@ void ValidateOrphanedInstance(Isolate* isolate,
Handle<WasmInstanceObject> instance); Handle<WasmInstanceObject> instance);
} // namespace testing } // namespace testing
#undef WASM_MOVE_ONLY_STRUCT
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
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