Commit 0cabc6a0 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Reland "[utils] Make BitField final"

This is a reland of 658ff200

Original change's description:
> [utils] Make BitField final
> 
> We have hundreds of classes that derive from {BitField} without adding
> any functionality. This CL switches all such occurrences to 'using'
> declarations instead.
> 
> Before:
>   class MyBitField : public BitField<int, 6, 4, MyEnum> {};
> After:
>   using MyBitField = BitField<int, 6, 4, MyEnum>;
> 
> This might reduce compilation time by reducing the number of existing
> classes.
> 
> The old pattern is forbidden now by making {BitField} final.
> 
> R=yangguo@chromium.org
> 
> Bug: v8:9396, v8:7629
> Change-Id: I8a8364707e8eae0bb522af2459c160e3293eecbb
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1722565
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#62956}

Bug: v8:9396, v8:7629
Change-Id: Ic68541af9d1e8d0340691970922f282b24a9767f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1724379Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62959}
parent 753a07db
This diff is collapsed.
......@@ -243,25 +243,21 @@ class Variable final : public ZoneObject {
bit_field_ = MaybeAssignedFlagField::update(bit_field_, kMaybeAssigned);
}
class VariableModeField : public BitField16<VariableMode, 0, 3> {};
class VariableKindField
: public BitField16<VariableKind, VariableModeField::kNext, 3> {};
class LocationField
: public BitField16<VariableLocation, VariableKindField::kNext, 3> {};
class ForceContextAllocationField
: public BitField16<bool, LocationField::kNext, 1> {};
class IsUsedField
: public BitField16<bool, ForceContextAllocationField::kNext, 1> {};
class InitializationFlagField
: public BitField16<InitializationFlag, IsUsedField::kNext, 1> {};
class ForceHoleInitializationField
: public BitField16<bool, InitializationFlagField::kNext, 1> {};
class MaybeAssignedFlagField
: public BitField16<MaybeAssignedFlag,
ForceHoleInitializationField::kNext, 1> {};
class RequiresBrandCheckField
: public BitField16<RequiresBrandCheckFlag, MaybeAssignedFlagField::kNext,
1> {};
using VariableModeField = BitField16<VariableMode, 0, 3>;
using VariableKindField =
BitField16<VariableKind, VariableModeField::kNext, 3>;
using LocationField =
BitField16<VariableLocation, VariableKindField::kNext, 3>;
using ForceContextAllocationField = BitField16<bool, LocationField::kNext, 1>;
using IsUsedField = BitField16<bool, ForceContextAllocationField::kNext, 1>;
using InitializationFlagField =
BitField16<InitializationFlag, IsUsedField::kNext, 1>;
using ForceHoleInitializationField =
BitField16<bool, InitializationFlagField::kNext, 1>;
using MaybeAssignedFlagField =
BitField16<MaybeAssignedFlag, ForceHoleInitializationField::kNext, 1>;
using RequiresBrandCheckField =
BitField16<RequiresBrandCheckFlag, MaybeAssignedFlagField::kNext, 1>;
Variable** next() { return &next_; }
friend List;
friend base::ThreadedListTraits<Variable>;
......
......@@ -782,10 +782,10 @@ class ArrayConcatVisitor {
storage_ = isolate_->global_handles()->Create(storage);
}
class FastElementsField : public BitField<bool, 0, 1> {};
class ExceedsLimitField : public BitField<bool, 1, 1> {};
class IsFixedArrayField : public BitField<bool, 2, 1> {};
class HasSimpleElementsField : public BitField<bool, 3, 1> {};
using FastElementsField = BitField<bool, 0, 1>;
using ExceedsLimitField = BitField<bool, 1, 1>;
using IsFixedArrayField = BitField<bool, 2, 1>;
using HasSimpleElementsField = BitField<bool, 3, 1>;
bool fast_elements() const { return FastElementsField::decode(bit_field_); }
void set_fast_elements(bool fast) {
......
......@@ -129,8 +129,8 @@ class V8_EXPORT_PRIVATE HandlerTable {
static const int kReturnEntrySize = 2;
// Encoding of the {handler} field.
class HandlerPredictionField : public BitField<CatchPrediction, 0, 3> {};
class HandlerOffsetField : public BitField<int, 3, 29> {};
using HandlerPredictionField = BitField<CatchPrediction, 0, 3>;
using HandlerOffsetField = BitField<int, 3, 29>;
};
} // namespace internal
......
......@@ -342,8 +342,8 @@ class Displacement {
private:
int data_;
class TypeField : public BitField<Type, 0, 2> {};
class NextField : public BitField<int, 2, 32 - 2> {};
using TypeField = BitField<Type, 0, 2>;
using NextField = BitField<int, 2, 32 - 2>;
void init(Label* L, Type type);
};
......
......@@ -27,8 +27,8 @@ namespace internal {
namespace {
// Each byte is encoded as MoreBit | ValueBits.
class MoreBit : public BitField8<bool, 7, 1> {};
class ValueBits : public BitField8<unsigned, 0, 7> {};
using MoreBit = BitField8<bool, 7, 1>;
using ValueBits = BitField8<unsigned, 0, 7>;
// Helper: Add the offsets from 'other' to 'value'. Also set is_statement.
void AddAndSetEntry(PositionTableEntry& value, // NOLINT(runtime/references)
......
......@@ -92,16 +92,18 @@ bool PerThreadAssertScope<kType, kAllow>::IsAllowed() {
return current_data == nullptr || current_data->Get(kType);
}
template <PerIsolateAssertType kType, bool kAllow>
class PerIsolateAssertScope<kType, kAllow>::DataBit
: public BitField<bool, kType, 1> {};
namespace {
template <PerIsolateAssertType kType>
using DataBit = BitField<bool, kType, 1>;
}
template <PerIsolateAssertType kType, bool kAllow>
PerIsolateAssertScope<kType, kAllow>::PerIsolateAssertScope(Isolate* isolate)
: isolate_(isolate), old_data_(isolate->per_isolate_assert_data()) {
DCHECK_NOT_NULL(isolate);
STATIC_ASSERT(kType < 32);
isolate_->set_per_isolate_assert_data(DataBit::update(old_data_, kAllow));
isolate_->set_per_isolate_assert_data(
DataBit<kType>::update(old_data_, kAllow));
}
template <PerIsolateAssertType kType, bool kAllow>
......@@ -112,7 +114,7 @@ PerIsolateAssertScope<kType, kAllow>::~PerIsolateAssertScope() {
// static
template <PerIsolateAssertType kType, bool kAllow>
bool PerIsolateAssertScope<kType, kAllow>::IsAllowed(Isolate* isolate) {
return DataBit::decode(isolate->per_isolate_assert_data());
return DataBit<kType>::decode(isolate->per_isolate_assert_data());
}
// -----------------------------------------------------------------------------
......
......@@ -81,8 +81,6 @@ class PerIsolateAssertScope {
static bool IsAllowed(Isolate* isolate);
private:
class DataBit;
Isolate* isolate_;
uint32_t old_data_;
......
......@@ -130,7 +130,7 @@ class V8_EXPORT_PRIVATE InstructionOperand {
inline uint64_t GetCanonicalizedValue() const;
class KindField : public BitField64<Kind, 0, 3> {};
using KindField = BitField64<Kind, 0, 3>;
uint64_t value_;
};
......@@ -331,20 +331,20 @@ class UnallocatedOperand final : public InstructionOperand {
STATIC_ASSERT(KindField::kSize == 3);
class VirtualRegisterField : public BitField64<uint32_t, 3, 32> {};
using VirtualRegisterField = BitField64<uint32_t, 3, 32>;
// BitFields for all unallocated operands.
class BasicPolicyField : public BitField64<BasicPolicy, 35, 1> {};
using BasicPolicyField = BitField64<BasicPolicy, 35, 1>;
// BitFields specific to BasicPolicy::FIXED_SLOT.
class FixedSlotIndexField : public BitField64<int, 36, 28> {};
using FixedSlotIndexField = BitField64<int, 36, 28>;
// BitFields specific to BasicPolicy::EXTENDED_POLICY.
class ExtendedPolicyField : public BitField64<ExtendedPolicy, 36, 3> {};
class LifetimeField : public BitField64<Lifetime, 39, 1> {};
class HasSecondaryStorageField : public BitField64<bool, 40, 1> {};
class FixedRegisterField : public BitField64<int, 41, 6> {};
class SecondaryStorageField : public BitField64<int, 47, 3> {};
using ExtendedPolicyField = BitField64<ExtendedPolicy, 36, 3>;
using LifetimeField = BitField64<Lifetime, 39, 1>;
using HasSecondaryStorageField = BitField64<bool, 40, 1>;
using FixedRegisterField = BitField64<int, 41, 6>;
using SecondaryStorageField = BitField64<int, 47, 3>;
private:
explicit UnallocatedOperand(int virtual_register)
......@@ -373,7 +373,7 @@ class ConstantOperand : public InstructionOperand {
INSTRUCTION_OPERAND_CASTS(ConstantOperand, CONSTANT)
STATIC_ASSERT(KindField::kSize == 3);
class VirtualRegisterField : public BitField64<uint32_t, 3, 32> {};
using VirtualRegisterField = BitField64<uint32_t, 3, 32>;
};
class ImmediateOperand : public InstructionOperand {
......@@ -406,8 +406,8 @@ class ImmediateOperand : public InstructionOperand {
INSTRUCTION_OPERAND_CASTS(ImmediateOperand, IMMEDIATE)
STATIC_ASSERT(KindField::kSize == 3);
class TypeField : public BitField64<ImmediateType, 3, 1> {};
class ValueField : public BitField64<int32_t, 32, 32> {};
using TypeField = BitField64<ImmediateType, 3, 1>;
using ValueField = BitField64<int32_t, 32, 32>;
};
class LocationOperand : public InstructionOperand {
......@@ -509,9 +509,9 @@ class LocationOperand : public InstructionOperand {
}
STATIC_ASSERT(KindField::kSize == 3);
class LocationKindField : public BitField64<LocationKind, 3, 2> {};
class RepresentationField : public BitField64<MachineRepresentation, 5, 8> {};
class IndexField : public BitField64<int32_t, 35, 29> {};
using LocationKindField = BitField64<LocationKind, 3, 2>;
using RepresentationField = BitField64<MachineRepresentation, 5, 8>;
using IndexField = BitField64<int32_t, 35, 29>;
};
class V8_EXPORT_PRIVATE ExplicitOperand
......
......@@ -144,8 +144,8 @@ class LinkageLocation {
private:
enum LocationType { REGISTER, STACK_SLOT };
class TypeField : public BitField<LocationType, 0, 1> {};
class LocationField : public BitField<int32_t, TypeField::kNext, 31> {};
using TypeField = BitField<LocationType, 0, 1>;
using LocationField = BitField<int32_t, TypeField::kNext, 31>;
static constexpr int32_t ANY_REGISTER = -1;
static constexpr int32_t MAX_STACK_SLOT = 32767;
......
......@@ -580,10 +580,9 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> {
// This stores three flags (independent, partially_dependent and
// in_young_list) and a State.
class NodeState : public BitField8<State, 0, 3> {};
class IsInYoungList : public BitField8<bool, NodeState::kNext, 1> {};
class NodeWeaknessType
: public BitField8<WeaknessType, IsInYoungList::kNext, 2> {};
using NodeState = BitField8<State, 0, 3>;
using IsInYoungList = BitField8<bool, NodeState::kNext, 1>;
using NodeWeaknessType = BitField8<WeaknessType, IsInYoungList::kNext, 2>;
// Handle specific callback - might be a weak reference in disguise.
WeakCallbackInfo<void>::Callback weak_callback_;
......@@ -650,9 +649,9 @@ class GlobalHandles::TracedNode final
}
protected:
class NodeState : public BitField8<State, 0, 2> {};
class IsInYoungList : public BitField8<bool, NodeState::kNext, 1> {};
class IsRoot : public BitField8<bool, IsInYoungList::kNext, 1> {};
using NodeState = BitField8<State, 0, 2>;
using IsInYoungList = BitField8<bool, NodeState::kNext, 1>;
using IsRoot = BitField8<bool, IsInYoungList::kNext, 1>;
void ClearImplFields() {
set_root(true);
......
......@@ -411,8 +411,8 @@ class V8_EXPORT_PRIVATE TypedSlots {
void Merge(TypedSlots* other);
protected:
class OffsetField : public BitField<int, 0, 29> {};
class TypeField : public BitField<SlotType, 29, 3> {};
using OffsetField = BitField<int, 0, 29>;
using TypeField = BitField<SlotType, 29, 3>;
struct TypedSlot {
uint32_t type_and_offset;
};
......
......@@ -47,65 +47,60 @@ class LoadHandler final : public DataHandler {
kNonExistent,
kModuleExport
};
class KindBits : public BitField<Kind, 0, 4> {};
using KindBits = BitField<Kind, 0, 4>;
// Defines whether access rights check should be done on receiver object.
// Applicable to named property kinds only when loading value from prototype
// chain. Ignored when loading from holder.
class DoAccessCheckOnReceiverBits
: public BitField<bool, KindBits::kNext, 1> {};
using DoAccessCheckOnReceiverBits = BitField<bool, KindBits::kNext, 1>;
// Defines whether a lookup should be done on receiver object before
// proceeding to the prototype chain. Applicable to named property kinds only
// when loading value from prototype chain. Ignored when loading from holder.
class LookupOnReceiverBits
: public BitField<bool, DoAccessCheckOnReceiverBits::kNext, 1> {};
using LookupOnReceiverBits =
BitField<bool, DoAccessCheckOnReceiverBits::kNext, 1>;
//
// Encoding when KindBits contains kForConstants.
//
// Index of a value entry in the descriptor array.
class DescriptorBits : public BitField<unsigned, LookupOnReceiverBits::kNext,
kDescriptorIndexBitCount> {};
using DescriptorBits =
BitField<unsigned, LookupOnReceiverBits::kNext, kDescriptorIndexBitCount>;
// Make sure we don't overflow the smi.
STATIC_ASSERT(DescriptorBits::kNext <= kSmiValueSize);
//
// Encoding when KindBits contains kField.
//
class IsInobjectBits : public BitField<bool, LookupOnReceiverBits::kNext, 1> {
};
class IsDoubleBits : public BitField<bool, IsInobjectBits::kNext, 1> {};
using IsInobjectBits = BitField<bool, LookupOnReceiverBits::kNext, 1>;
using IsDoubleBits = BitField<bool, IsInobjectBits::kNext, 1>;
// +1 here is to cover all possible JSObject header sizes.
class FieldIndexBits : public BitField<unsigned, IsDoubleBits::kNext,
kDescriptorIndexBitCount + 1> {};
using FieldIndexBits =
BitField<unsigned, IsDoubleBits::kNext, kDescriptorIndexBitCount + 1>;
// Make sure we don't overflow the smi.
STATIC_ASSERT(FieldIndexBits::kNext <= kSmiValueSize);
//
// Encoding when KindBits contains kElement or kIndexedString.
//
class AllowOutOfBoundsBits
: public BitField<bool, LookupOnReceiverBits::kNext, 1> {};
using AllowOutOfBoundsBits = BitField<bool, LookupOnReceiverBits::kNext, 1>;
//
// Encoding when KindBits contains kElement.
//
class IsJsArrayBits : public BitField<bool, AllowOutOfBoundsBits::kNext, 1> {
};
class ConvertHoleBits : public BitField<bool, IsJsArrayBits::kNext, 1> {};
class ElementsKindBits
: public BitField<ElementsKind, ConvertHoleBits::kNext, 8> {};
using IsJsArrayBits = BitField<bool, AllowOutOfBoundsBits::kNext, 1>;
using ConvertHoleBits = BitField<bool, IsJsArrayBits::kNext, 1>;
using ElementsKindBits = BitField<ElementsKind, ConvertHoleBits::kNext, 8>;
// Make sure we don't overflow the smi.
STATIC_ASSERT(ElementsKindBits::kNext <= kSmiValueSize);
//
// Encoding when KindBits contains kModuleExport.
//
class ExportsIndexBits
: public BitField<unsigned, LookupOnReceiverBits::kNext,
kSmiValueSize - LookupOnReceiverBits::kNext> {};
using ExportsIndexBits =
BitField<unsigned, LookupOnReceiverBits::kNext,
kSmiValueSize - LookupOnReceiverBits::kNext>;
// Decodes kind from Smi-handler.
static inline Kind GetHandlerKind(Smi smi_handler);
......@@ -206,28 +201,27 @@ class StoreHandler final : public DataHandler {
kProxy,
kKindsNumber // Keep last
};
class KindBits : public BitField<Kind, 0, 4> {};
using KindBits = BitField<Kind, 0, 4>;
enum FieldRepresentation { kSmi, kDouble, kHeapObject, kTagged };
// Applicable to kGlobalProxy, kProxy kinds.
// Defines whether access rights check should be done on receiver object.
class DoAccessCheckOnReceiverBits
: public BitField<bool, KindBits::kNext, 1> {};
using DoAccessCheckOnReceiverBits = BitField<bool, KindBits::kNext, 1>;
// Defines whether a lookup should be done on receiver object before
// proceeding to the prototype chain. Applicable to named property kinds only
// when storing through prototype chain. Ignored when storing to holder.
class LookupOnReceiverBits
: public BitField<bool, DoAccessCheckOnReceiverBits::kNext, 1> {};
using LookupOnReceiverBits =
BitField<bool, DoAccessCheckOnReceiverBits::kNext, 1>;
// Applicable to kField, kTransitionToField and kTransitionToConstant
// kinds.
// Index of a value entry in the descriptor array.
class DescriptorBits : public BitField<unsigned, LookupOnReceiverBits::kNext,
kDescriptorIndexBitCount> {};
using DescriptorBits =
BitField<unsigned, LookupOnReceiverBits::kNext, kDescriptorIndexBitCount>;
//
// Encoding when KindBits contains kTransitionToConstant.
//
......@@ -238,13 +232,12 @@ class StoreHandler final : public DataHandler {
//
// Encoding when KindBits contains kField or kTransitionToField.
//
class IsInobjectBits : public BitField<bool, DescriptorBits::kNext, 1> {};
class FieldRepresentationBits
: public BitField<FieldRepresentation, IsInobjectBits::kNext, 2> {};
using IsInobjectBits = BitField<bool, DescriptorBits::kNext, 1>;
using FieldRepresentationBits =
BitField<FieldRepresentation, IsInobjectBits::kNext, 2>;
// +1 here is to cover all possible JSObject header sizes.
class FieldIndexBits
: public BitField<unsigned, FieldRepresentationBits::kNext,
kDescriptorIndexBitCount + 1> {};
using FieldIndexBits = BitField<unsigned, FieldRepresentationBits::kNext,
kDescriptorIndexBitCount + 1>;
// Make sure we don't overflow the smi.
STATIC_ASSERT(FieldIndexBits::kNext <= kSmiValueSize);
......
......@@ -18,8 +18,8 @@ namespace interpreter {
class CreateArrayLiteralFlags {
public:
class FlagsBits : public BitField8<int, 0, 5> {};
class FastCloneSupportedBit : public BitField8<bool, FlagsBits::kNext, 1> {};
using FlagsBits = BitField8<int, 0, 5>;
using FastCloneSupportedBit = BitField8<bool, FlagsBits::kNext, 1>;
static uint8_t Encode(bool use_fast_shallow_clone, int runtime_flags);
......@@ -29,8 +29,8 @@ class CreateArrayLiteralFlags {
class CreateObjectLiteralFlags {
public:
class FlagsBits : public BitField8<int, 0, 5> {};
class FastCloneSupportedBit : public BitField8<bool, FlagsBits::kNext, 1> {};
using FlagsBits = BitField8<int, 0, 5>;
using FastCloneSupportedBit = BitField8<bool, FlagsBits::kNext, 1>;
static uint8_t Encode(int runtime_flags, bool fast_clone_supported);
......@@ -40,8 +40,8 @@ class CreateObjectLiteralFlags {
class CreateClosureFlags {
public:
class PretenuredBit : public BitField8<bool, 0, 1> {};
class FastNewClosureBit : public BitField8<bool, PretenuredBit::kNext, 1> {};
using PretenuredBit = BitField8<bool, 0, 1>;
using FastNewClosureBit = BitField8<bool, PretenuredBit::kNext, 1>;
static uint8_t Encode(bool pretenure, bool is_function_scope,
bool might_always_opt);
......@@ -80,9 +80,8 @@ class TestTypeOfFlags {
class StoreLookupSlotFlags {
public:
class LanguageModeBit : public BitField8<LanguageMode, 0, 1> {};
class LookupHoistingModeBit
: public BitField8<bool, LanguageModeBit::kNext, 1> {};
using LanguageModeBit = BitField8<LanguageMode, 0, 1>;
using LookupHoistingModeBit = BitField8<bool, LanguageModeBit::kNext, 1>;
STATIC_ASSERT(LanguageModeSize <= LanguageModeBit::kNumValues);
static uint8_t Encode(LanguageMode language_mode,
......
......@@ -66,14 +66,14 @@ class AllocationSite : public Struct {
bool IsNested();
// transition_info bitfields, for constructed array transition info.
class ElementsKindBits : public BitField<ElementsKind, 0, 5> {};
class DoNotInlineBit : public BitField<bool, 5, 1> {};
using ElementsKindBits = BitField<ElementsKind, 0, 5>;
using DoNotInlineBit = BitField<bool, 5, 1>;
// Unused bits 6-30.
// Bitfields for pretenure_data
class MementoFoundCountBits : public BitField<int, 0, 26> {};
class PretenureDecisionBits : public BitField<PretenureDecision, 26, 3> {};
class DeoptDependentCodeBit : public BitField<bool, 29, 1> {};
using MementoFoundCountBits = BitField<int, 0, 26>;
using PretenureDecisionBits = BitField<PretenureDecision, 26, 3>;
using DeoptDependentCodeBit = BitField<bool, 29, 1>;
STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue);
// Increments the mementos found counter and returns true when the first
......
......@@ -57,8 +57,8 @@ class BigIntBase : public HeapObject {
// able to read the length concurrently, the getters and setters are atomic.
static const int kLengthFieldBits = 30;
STATIC_ASSERT(kMaxLength <= ((1 << kLengthFieldBits) - 1));
class SignBits : public BitField<bool, 0, 1> {};
class LengthBits : public BitField<int, SignBits::kNext, kLengthFieldBits> {};
using SignBits = BitField<bool, 0, 1>;
using LengthBits = BitField<int, SignBits::kNext, kLengthFieldBits>;
STATIC_ASSERT(LengthBits::kNext <= 32);
// Layout description.
......
......@@ -706,8 +706,8 @@ class DependentCode : public WeakFixedArray {
inline int flags();
inline void set_flags(int flags);
class GroupField : public BitField<int, 0, 3> {};
class CountField : public BitField<int, 3, 27> {};
using GroupField = BitField<int, 0, 3>;
using CountField = BitField<int, 3, 27>;
STATIC_ASSERT(kGroupCount <= GroupField::kMax + 1);
OBJECT_CONSTRUCTORS(DependentCode, WeakFixedArray);
......
......@@ -107,17 +107,16 @@ class FieldIndex final {
(kDescriptorIndexBitCount + 1 + kTaggedSizeLog2);
// Index from beginning of object.
class OffsetBits : public BitField64<int, 0, kOffsetBitsSize> {};
class IsInObjectBits : public BitField64<bool, OffsetBits::kNext, 1> {};
class EncodingBits : public BitField64<Encoding, IsInObjectBits::kNext, 2> {};
using OffsetBits = BitField64<int, 0, kOffsetBitsSize>;
using IsInObjectBits = BitField64<bool, OffsetBits::kNext, 1>;
using EncodingBits = BitField64<Encoding, IsInObjectBits::kNext, 2>;
// Number of inobject properties.
class InObjectPropertyBits
: public BitField64<int, EncodingBits::kNext, kDescriptorIndexBitCount> {
};
using InObjectPropertyBits =
BitField64<int, EncodingBits::kNext, kDescriptorIndexBitCount>;
// Offset of first inobject property from beginning of object.
class FirstInobjectPropertyOffsetBits
: public BitField64<int, InObjectPropertyBits::kNext,
kFirstInobjectPropertyOffsetBitCount> {};
using FirstInobjectPropertyOffsetBits =
BitField64<int, InObjectPropertyBits::kNext,
kFirstInobjectPropertyOffsetBitCount>;
STATIC_ASSERT(FirstInobjectPropertyOffsetBits::kNext <= 64);
uint64_t bit_field_;
......
......@@ -79,7 +79,7 @@ class JSPromise : public JSObject {
static const int kStatusBits = 2;
static const int kHasHandlerBit = 2;
static const int kHandledHintBit = 3;
class AsyncTaskIdField : public BitField<int, kHandledHintBit + 1, 22> {};
using AsyncTaskIdField = BitField<int, kHandledHintBit + 1, 22>;
static const int kStatusShift = 0;
static const int kStatusMask = 0x3;
......
......@@ -67,7 +67,7 @@ class JSFinalizationGroup : public JSObject {
TORQUE_GENERATED_JSFINALIZATION_GROUP_FIELDS)
// Bitfields in flags.
class ScheduledForCleanupField : public BitField<bool, 0, 1> {};
using ScheduledForCleanupField = BitField<bool, 0, 1>;
OBJECT_CONSTRUCTORS(JSFinalizationGroup, JSObject);
};
......
......@@ -99,12 +99,11 @@ class Name : public TorqueGeneratedName<Name, HeapObject> {
STATIC_ASSERT(kArrayIndexLengthBits > 0);
STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
class ArrayIndexValueBits
: public BitField<unsigned int, kNofHashBitFields, kArrayIndexValueBits> {
}; // NOLINT
class ArrayIndexLengthBits
: public BitField<unsigned int, kNofHashBitFields + kArrayIndexValueBits,
kArrayIndexLengthBits> {}; // NOLINT
using ArrayIndexValueBits =
BitField<unsigned int, kNofHashBitFields, kArrayIndexValueBits>;
using ArrayIndexLengthBits =
BitField<unsigned int, kNofHashBitFields + kArrayIndexValueBits,
kArrayIndexLengthBits>;
// Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
// could use a mask to test if the length of string is less than or equal to
......
......@@ -61,10 +61,10 @@ class PropertyArray : public HeapObject {
using BodyDescriptor = FlexibleBodyDescriptor<kHeaderSize>;
static const int kLengthFieldSize = 10;
class LengthField : public BitField<int, 0, kLengthFieldSize> {};
using LengthField = BitField<int, 0, kLengthFieldSize>;
static const int kMaxLength = LengthField::kMax;
class HashField : public BitField<int, kLengthFieldSize,
kSmiValueSize - kLengthFieldSize - 1> {};
using HashField =
BitField<int, kLengthFieldSize, kSmiValueSize - kLengthFieldSize - 1>;
static const int kNoHashSentinel = 0;
......
......@@ -310,13 +310,11 @@ class PropertyDetails {
// Bit fields in value_ (type, shift, size). Must be public so the
// constants can be embedded in generated code.
class KindField : public BitField<PropertyKind, 0, 1> {};
class LocationField : public BitField<PropertyLocation, KindField::kNext, 1> {
};
class ConstnessField
: public BitField<PropertyConstness, LocationField::kNext, 1> {};
class AttributesField
: public BitField<PropertyAttributes, ConstnessField::kNext, 3> {};
using KindField = BitField<PropertyKind, 0, 1>;
using LocationField = BitField<PropertyLocation, KindField::kNext, 1>;
using ConstnessField = BitField<PropertyConstness, LocationField::kNext, 1>;
using AttributesField =
BitField<PropertyAttributes, ConstnessField::kNext, 3>;
static const int kAttributesReadOnlyMask =
(READ_ONLY << AttributesField::kShift);
static const int kAttributesDontDeleteMask =
......@@ -325,20 +323,17 @@ class PropertyDetails {
(DONT_ENUM << AttributesField::kShift);
// Bit fields for normalized objects.
class PropertyCellTypeField
: public BitField<PropertyCellType, AttributesField::kNext, 2> {};
class DictionaryStorageField
: public BitField<uint32_t, PropertyCellTypeField::kNext, 23> {};
using PropertyCellTypeField =
BitField<PropertyCellType, AttributesField::kNext, 2>;
using DictionaryStorageField =
BitField<uint32_t, PropertyCellTypeField::kNext, 23>;
// Bit fields for fast objects.
class RepresentationField
: public BitField<uint32_t, AttributesField::kNext, 3> {};
class DescriptorPointer
: public BitField<uint32_t, RepresentationField::kNext,
kDescriptorIndexBitCount> {}; // NOLINT
class FieldIndexField : public BitField<uint32_t, DescriptorPointer::kNext,
kDescriptorIndexBitCount> {
}; // NOLINT
using RepresentationField = BitField<uint32_t, AttributesField::kNext, 3>;
using DescriptorPointer =
BitField<uint32_t, RepresentationField::kNext, kDescriptorIndexBitCount>;
using FieldIndexField =
BitField<uint32_t, DescriptorPointer::kNext, kDescriptorIndexBitCount>;
// All bits for both fast and slow objects must fit in a smi.
STATIC_ASSERT(DictionaryStorageField::kNext <= 31);
......
......@@ -224,39 +224,32 @@ class ScopeInfo : public FixedArray {
enum VariableAllocationInfo { NONE, STACK, CONTEXT, UNUSED };
// Properties of scopes.
class ScopeTypeField : public BitField<ScopeType, 0, 4> {};
class CallsSloppyEvalField : public BitField<bool, ScopeTypeField::kNext, 1> {
};
using ScopeTypeField = BitField<ScopeType, 0, 4>;
using CallsSloppyEvalField = BitField<bool, ScopeTypeField::kNext, 1>;
STATIC_ASSERT(LanguageModeSize == 2);
class LanguageModeField
: public BitField<LanguageMode, CallsSloppyEvalField::kNext, 1> {};
class DeclarationScopeField
: public BitField<bool, LanguageModeField::kNext, 1> {};
class ReceiverVariableField
: public BitField<VariableAllocationInfo, DeclarationScopeField::kNext,
2> {};
class HasClassBrandField
: public BitField<bool, ReceiverVariableField::kNext, 1> {};
class HasNewTargetField
: public BitField<bool, HasClassBrandField::kNext, 1> {};
class FunctionVariableField
: public BitField<VariableAllocationInfo, HasNewTargetField::kNext, 2> {};
using LanguageModeField =
BitField<LanguageMode, CallsSloppyEvalField::kNext, 1>;
using DeclarationScopeField = BitField<bool, LanguageModeField::kNext, 1>;
using ReceiverVariableField =
BitField<VariableAllocationInfo, DeclarationScopeField::kNext, 2>;
using HasClassBrandField = BitField<bool, ReceiverVariableField::kNext, 1>;
using HasNewTargetField = BitField<bool, HasClassBrandField::kNext, 1>;
using FunctionVariableField =
BitField<VariableAllocationInfo, HasNewTargetField::kNext, 2>;
// TODO(cbruni): Combine with function variable field when only storing the
// function name.
class HasInferredFunctionNameField
: public BitField<bool, FunctionVariableField::kNext, 1> {};
class IsAsmModuleField
: public BitField<bool, HasInferredFunctionNameField::kNext, 1> {};
class HasSimpleParametersField
: public BitField<bool, IsAsmModuleField::kNext, 1> {};
class FunctionKindField
: public BitField<FunctionKind, HasSimpleParametersField::kNext, 5> {};
class HasOuterScopeInfoField
: public BitField<bool, FunctionKindField::kNext, 1> {};
class IsDebugEvaluateScopeField
: public BitField<bool, HasOuterScopeInfoField::kNext, 1> {};
class ForceContextAllocationField
: public BitField<bool, IsDebugEvaluateScopeField::kNext, 1> {};
using HasInferredFunctionNameField =
BitField<bool, FunctionVariableField::kNext, 1>;
using IsAsmModuleField =
BitField<bool, HasInferredFunctionNameField::kNext, 1>;
using HasSimpleParametersField = BitField<bool, IsAsmModuleField::kNext, 1>;
using FunctionKindField =
BitField<FunctionKind, HasSimpleParametersField::kNext, 5>;
using HasOuterScopeInfoField = BitField<bool, FunctionKindField::kNext, 1>;
using IsDebugEvaluateScopeField =
BitField<bool, HasOuterScopeInfoField::kNext, 1>;
using ForceContextAllocationField =
BitField<bool, IsDebugEvaluateScopeField::kNext, 1>;
STATIC_ASSERT(kLastFunctionKind <= FunctionKindField::kMax);
......@@ -323,14 +316,13 @@ class ScopeInfo : public FixedArray {
static const int kPositionInfoEntries = 2;
// Properties of variables.
class VariableModeField : public BitField<VariableMode, 0, 3> {};
class InitFlagField : public BitField<InitializationFlag, 3, 1> {};
class MaybeAssignedFlagField : public BitField<MaybeAssignedFlag, 4, 1> {};
class RequiresBrandCheckField
: public BitField<RequiresBrandCheckFlag, MaybeAssignedFlagField::kNext,
1> {};
class ParameterNumberField
: public BitField<uint32_t, RequiresBrandCheckField::kNext, 16> {};
using VariableModeField = BitField<VariableMode, 0, 3>;
using InitFlagField = BitField<InitializationFlag, 3, 1>;
using MaybeAssignedFlagField = BitField<MaybeAssignedFlag, 4, 1>;
using RequiresBrandCheckField =
BitField<RequiresBrandCheckFlag, MaybeAssignedFlagField::kNext, 1>;
using ParameterNumberField =
BitField<uint32_t, RequiresBrandCheckField::kNext, 16>;
friend class ScopeIterator;
friend std::ostream& operator<<(std::ostream& os,
......
......@@ -227,9 +227,8 @@ class ObjectTemplateInfo : public TemplateInfo {
inline ObjectTemplateInfo GetParent(Isolate* isolate);
private:
class IsImmutablePrototype : public BitField<bool, 0, 1> {};
class EmbedderFieldCount
: public BitField<int, IsImmutablePrototype::kNext, 29> {};
using IsImmutablePrototype = BitField<bool, 0, 1>;
using EmbedderFieldCount = BitField<int, IsImmutablePrototype::kNext, 29>;
OBJECT_CONSTRUCTORS(ObjectTemplateInfo, TemplateInfo);
};
......
......@@ -21,22 +21,21 @@ namespace internal {
namespace {
class ScopeCallsSloppyEvalField : public BitField8<bool, 0, 1> {};
class InnerScopeCallsEvalField
: public BitField8<bool, ScopeCallsSloppyEvalField::kNext, 1> {};
class VariableMaybeAssignedField : public BitField8<bool, 0, 1> {};
class VariableContextAllocatedField
: public BitField8<bool, VariableMaybeAssignedField::kNext, 1> {};
class HasDataField : public BitField<bool, 0, 1> {};
class LengthEqualsParametersField
: public BitField<bool, HasDataField::kNext, 1> {};
class NumberOfParametersField
: public BitField<uint16_t, LengthEqualsParametersField::kNext, 16> {};
class LanguageField : public BitField8<LanguageMode, 0, 1> {};
class UsesSuperField : public BitField8<bool, LanguageField::kNext, 1> {};
using ScopeCallsSloppyEvalField = BitField8<bool, 0, 1>;
using InnerScopeCallsEvalField =
BitField8<bool, ScopeCallsSloppyEvalField::kNext, 1>;
using VariableMaybeAssignedField = BitField8<bool, 0, 1>;
using VariableContextAllocatedField =
BitField8<bool, VariableMaybeAssignedField::kNext, 1>;
using HasDataField = BitField<bool, 0, 1>;
using LengthEqualsParametersField = BitField<bool, HasDataField::kNext, 1>;
using NumberOfParametersField =
BitField<uint16_t, LengthEqualsParametersField::kNext, 16>;
using LanguageField = BitField8<LanguageMode, 0, 1>;
using UsesSuperField = BitField8<bool, LanguageField::kNext, 1>;
STATIC_ASSERT(LanguageModeSize <= LanguageField::kNumValues);
} // namespace
......
......@@ -215,8 +215,8 @@ class V8_EXPORT_PRIVATE Token {
return name_[token];
}
class IsKeywordBits : public BitField8<bool, 0, 1> {};
class IsPropertyNameBits : public BitField8<bool, IsKeywordBits::kNext, 1> {};
using IsKeywordBits = BitField8<bool, 0, 1>;
using IsPropertyNameBits = BitField8<bool, IsKeywordBits::kNext, 1>;
// Predicates
static bool IsKeyword(Value token) {
......
......@@ -82,8 +82,8 @@ class HeapGraphEdge {
V8_INLINE HeapSnapshot* snapshot() const;
int from_index() const { return FromIndexField::decode(bit_field_); }
class TypeField : public BitField<Type, 0, 3> {};
class FromIndexField : public BitField<int, 3, 29> {};
using TypeField = BitField<Type, 0, 3>;
using FromIndexField = BitField<int, 3, 29>;
uint32_t bit_field_;
HeapEntry* to_entry_;
union {
......
......@@ -769,11 +769,11 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
//---------------------------------------------------------------------------
// Constants used by interface to runtime functions.
class AllocateDoubleAlignFlag : public BitField<bool, 0, 1> {};
using AllocateDoubleAlignFlag = BitField<bool, 0, 1>;
class AllowLargeObjectAllocationFlag : public BitField<bool, 1, 1> {};
using AllowLargeObjectAllocationFlag = BitField<bool, 1, 1>;
class DeclareGlobalsEvalFlag : public BitField<bool, 0, 1> {};
using DeclareGlobalsEvalFlag = BitField<bool, 0, 1>;
// A set of bits returned by Runtime_GetOptimizationStatus.
// These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
......
......@@ -154,12 +154,11 @@ class SerializerReference {
}
private:
class SpaceBits : public BitField<SnapshotSpace, 0, kSpaceTagSize> {};
class ChunkIndexBits
: public BitField<uint32_t, SpaceBits::kNext, 32 - kSpaceTagSize> {};
class SpecialValueTypeBits
: public BitField<SpecialValueType, SpaceBits::kNext,
32 - kSpaceTagSize> {};
using SpaceBits = BitField<SnapshotSpace, 0, kSpaceTagSize>;
using ChunkIndexBits =
BitField<uint32_t, SpaceBits::kNext, 32 - kSpaceTagSize>;
using SpecialValueTypeBits =
BitField<SpecialValueType, SpaceBits::kNext, 32 - kSpaceTagSize>;
// We use two fields to store a reference.
// In case of a normal back reference, the bitfield_ stores the space and
......
......@@ -34,8 +34,8 @@ class ExternalReferenceEncoder {
uint32_t index() const { return Index::decode(value_); }
private:
class Index : public BitField<uint32_t, 0, 31> {};
class IsFromAPI : public BitField<bool, 31, 1> {};
using Index = BitField<uint32_t, 0, 31>;
using IsFromAPI = BitField<bool, 31, 1>;
uint32_t value_;
};
......@@ -328,8 +328,8 @@ class SerializedData {
uint32_t GetMagicNumber() const { return GetHeaderValue(kMagicNumberOffset); }
class ChunkSizeBits : public BitField<uint32_t, 0, 31> {};
class IsLastChunkBits : public BitField<bool, 31, 1> {};
using ChunkSizeBits = BitField<uint32_t, 0, 31>;
using IsLastChunkBits = BitField<bool, 31, 1>;
static constexpr uint32_t kMagicNumberOffset = 0;
static constexpr uint32_t kMagicNumber =
......
......@@ -51,8 +51,8 @@ class Predicate {
bool value() const { return ValueField::decode(bit_field_); }
private:
class CodePointField : public v8::internal::BitField<uchar, 0, 21> {};
class ValueField : public v8::internal::BitField<bool, 21, 1> {};
using CodePointField = v8::internal::BitField<uchar, 0, 21>;
using ValueField = v8::internal::BitField<bool, 21, 1>;
uint32_t bit_field_;
};
......
......@@ -302,9 +302,12 @@ T SaturateSub(T a, T b) {
// ----------------------------------------------------------------------------
// BitField is a help template for encoding and decode bitfield with
// unsigned content.
// Instantiate them via 'using', which is cheaper than deriving a new class:
// using MyBitField = BitField<int, 4, 2, MyEnum>;
// The BitField class is final to enforce this style over derivation.
template <class T, int shift, int size, class U = uint32_t>
class BitField {
class BitField final {
public:
STATIC_ASSERT(std::is_unsigned<U>::value);
STATIC_ASSERT(shift < 8 * sizeof(U)); // Otherwise shifts by {shift} are UB.
......
......@@ -524,9 +524,9 @@ class CompilationStateImpl {
//////////////////////////////////////////////////////////////////////////////
// Encoding of fields in the {compilation_progress_} vector.
class RequiredBaselineTierField : public BitField8<ExecutionTier, 0, 2> {};
class RequiredTopTierField : public BitField8<ExecutionTier, 2, 2> {};
class ReachedTierField : public BitField8<ExecutionTier, 4, 2> {};
using RequiredBaselineTierField = BitField8<ExecutionTier, 0, 2>;
using RequiredTopTierField = BitField8<ExecutionTier, 2, 2>;
using ReachedTierField = BitField8<ExecutionTier, 4, 2>;
};
CompilationStateImpl* Impl(CompilationState* compilation_state) {
......
......@@ -311,7 +311,7 @@ TEST(DecodeWordFromWord32) {
CodeAssemblerTester asm_tester(isolate);
CodeStubAssembler m(asm_tester.state());
class TestBitField : public BitField<unsigned, 3, 3> {};
using TestBitField = BitField<unsigned, 3, 3>;
m.Return(m.SmiTag(
m.Signed(m.DecodeWordFromWord32<TestBitField>(m.Int32Constant(0x2F)))));
FunctionTester ft(asm_tester.GenerateCode());
......
......@@ -312,11 +312,10 @@ TEST(ExponentNumberStr) {
CHECK_EQ(1e-106, StringToDouble(".000001e-100", NO_FLAGS));
}
class OneBit1: public BitField<uint32_t, 0, 1> {};
class OneBit2: public BitField<uint32_t, 7, 1> {};
class EightBit1: public BitField<uint32_t, 0, 8> {};
class EightBit2: public BitField<uint32_t, 13, 8> {};
using OneBit1 = BitField<uint32_t, 0, 1>;
using OneBit2 = BitField<uint32_t, 7, 1>;
using EightBit1 = BitField<uint32_t, 0, 8>;
using EightBit2 = BitField<uint32_t, 13, 8>;
TEST(BitField) {
uint32_t x;
......@@ -351,9 +350,8 @@ TEST(BitField) {
CHECK(!EightBit2::is_valid(256));
}
class UpperBits: public BitField64<int, 61, 3> {};
class MiddleBits: public BitField64<int, 31, 2> {};
using UpperBits = BitField64<int, 61, 3>;
using MiddleBits = BitField64<int, 31, 2>;
TEST(BitField64) {
uint64_t x;
......
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