Skip to content

Commit

Permalink
[cleanup] Replace simple typedefs by using
Browse files Browse the repository at this point in the history
This replaces all typedefs that define types and not functions by the
equivalent "using" declaration.

This was done mostly automatically using this command:
ag -l '\btypedef\b' src test | xargs -L1 \
     perl -i -p0e 's/typedef ([^*;{}]+) (\w+);/using \2 = \1;/sg'

Patchset 2 then adds some manual changes for typedefs for pointer types,
where the regular expression did not match.

[email protected]
[email protected], [email protected]

Bug: v8:9183
Change-Id: I6f6ee28d1793b7ac34a58f980b94babc21874b78
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1631409
Commit-Queue: Clemens Hammacher <[email protected]>
Reviewed-by: Michael Starzinger <[email protected]>
Cr-Commit-Position: refs/heads/master@{#61849}
  • Loading branch information
backes authored and Commit Bot committed May 27, 2019
1 parent 0ec82d5 commit a335f2a
Show file tree
Hide file tree
Showing 180 changed files with 622 additions and 721 deletions.
8 changes: 4 additions & 4 deletions src/api/api-arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class CustomArguments : public CustomArgumentsBase {
class PropertyCallbackArguments
: public CustomArguments<PropertyCallbackInfo<Value> > {
public:
typedef PropertyCallbackInfo<Value> T;
typedef CustomArguments<T> Super;
using T = PropertyCallbackInfo<Value>;
using Super = CustomArguments<T>;
static const int kArgsLength = T::kArgsLength;
static const int kThisIndex = T::kThisIndex;
static const int kHolderIndex = T::kHolderIndex;
Expand Down Expand Up @@ -150,8 +150,8 @@ class PropertyCallbackArguments
class FunctionCallbackArguments
: public CustomArguments<FunctionCallbackInfo<Value> > {
public:
typedef FunctionCallbackInfo<Value> T;
typedef CustomArguments<T> Super;
using T = FunctionCallbackInfo<Value>;
using Super = CustomArguments<T>;
static const int kArgsLength = T::kArgsLength;
static const int kHolderIndex = T::kHolderIndex;
static const int kDataIndex = T::kDataIndex;
Expand Down
4 changes: 2 additions & 2 deletions src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5290,7 +5290,7 @@ void v8::String::VerifyExternalStringResourceBase(

String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
i::DisallowHeapAllocation no_allocation;
typedef internal::Internals I;
using I = internal::Internals;
i::String str = *Utils::OpenHandle(this);

if (str.IsThinString()) {
Expand All @@ -5307,7 +5307,7 @@ String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
String::Encoding* encoding_out) const {
i::DisallowHeapAllocation no_allocation;
typedef internal::Internals I;
using I = internal::Internals;
ExternalStringResourceBase* resource = nullptr;
i::String str = *Utils::OpenHandle(this);

Expand Down
6 changes: 2 additions & 4 deletions src/arm/constants-arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ inline Condition NegateCondition(Condition cond) {
// representing instructions from usual 32 bit values.
// Instruction objects are pointers to 32bit values, and provide methods to
// access the various ISA fields.
typedef int32_t Instr;

using Instr = int32_t;

// Opcodes for Data-processing instructions (instructions with a type 0 and 1)
// as defined in section A3.4
Expand Down Expand Up @@ -263,8 +262,7 @@ enum SRegisterField {
};

// Status register field mask (or'ed SRegisterField enum values).
typedef uint32_t SRegisterFieldMask;

using SRegisterFieldMask = uint32_t;

// Memory operand addressing mode.
enum AddrMode {
Expand Down
10 changes: 5 additions & 5 deletions src/arm/register-arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ enum SwVfpRegisterCode {
// This way, we make sure no registers in the list ever overlap. However, a list
// may represent multiple different sets of registers,
// e.g. [d0 s2 s3] <=> [s0 s1 d1].
typedef uint64_t VfpRegList;
using VfpRegList = uint64_t;

// Single word VFP register.
class SwVfpRegister : public RegisterBase<SwVfpRegister, kSwVfpAfterLast> {
Expand Down Expand Up @@ -179,7 +179,7 @@ ASSERT_TRIVIALLY_COPYABLE(SwVfpRegister);
static_assert(sizeof(SwVfpRegister) == sizeof(int),
"SwVfpRegister can efficiently be passed by value");

typedef SwVfpRegister FloatRegister;
using FloatRegister = SwVfpRegister;

enum DoubleRegisterCode {
#define REGISTER_CODE(R) kDoubleCode_##R,
Expand Down Expand Up @@ -217,7 +217,7 @@ ASSERT_TRIVIALLY_COPYABLE(DwVfpRegister);
static_assert(sizeof(DwVfpRegister) == sizeof(int),
"DwVfpRegister can efficiently be passed by value");

typedef DwVfpRegister DoubleRegister;
using DoubleRegister = DwVfpRegister;

// Double word VFP register d0-15.
class LowDwVfpRegister
Expand Down Expand Up @@ -272,9 +272,9 @@ class QwNeonRegister : public RegisterBase<QwNeonRegister, kSimd128AfterLast> {
explicit constexpr QwNeonRegister(int code) : RegisterBase(code) {}
};

typedef QwNeonRegister QuadRegister;
using QuadRegister = QwNeonRegister;

typedef QwNeonRegister Simd128Register;
using Simd128Register = QwNeonRegister;

enum CRegisterCode {
#define REGISTER_CODE(R) kCCode_##R,
Expand Down
2 changes: 1 addition & 1 deletion src/arm64/assembler-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ void Assembler::DeleteUnresolvedBranchInfoForLabelTraverse(Label* label) {
int max_reachable_pc =
static_cast<int>(InstructionOffset(link) +
Instruction::ImmBranchRange(link->BranchType()));
typedef std::multimap<int, FarBranchInfo>::iterator unresolved_info_it;
using unresolved_info_it = std::multimap<int, FarBranchInfo>::iterator;
std::pair<unresolved_info_it, unresolved_info_it> range;
range = unresolved_branches_.equal_range(max_reachable_pc);
unresolved_info_it it;
Expand Down
2 changes: 1 addition & 1 deletion src/arm64/assembler-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class ConstPool {
void EmitGuard();
void EmitEntries();

typedef std::map<uint64_t, int> SharedEntryMap;
using SharedEntryMap = std::map<uint64_t, int>;
// Adds a shared entry to entries_, using 'entry_map' to determine whether we
// already track this entry. Returns true if this is the first time we add
// this entry, false otherwise.
Expand Down
2 changes: 1 addition & 1 deletion src/arm64/constants-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const unsigned kFloat16ExponentBias = 15;
// TODO(sigurds): Choose best value.
constexpr int kRootRegisterBias = 256;

typedef uint16_t float16;
using float16 = uint16_t;

#define INSTRUCTION_FIELDS_LIST(V_) \
/* Register fields */ \
Expand Down
2 changes: 1 addition & 1 deletion src/arm64/instructions-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct AssemblerOptions;

// ISA constants. --------------------------------------------------------------

typedef uint32_t Instr;
using Instr = uint32_t;

#if defined(V8_OS_WIN)
extern "C" {
Expand Down
6 changes: 3 additions & 3 deletions src/arm64/register-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ V8_EXPORT_PRIVATE bool AreConsecutive(const VRegister& reg1,
const VRegister& reg3 = NoVReg,
const VRegister& reg4 = NoVReg);

typedef VRegister FloatRegister;
typedef VRegister DoubleRegister;
typedef VRegister Simd128Register;
using FloatRegister = VRegister;
using DoubleRegister = VRegister;
using Simd128Register = VRegister;

// -----------------------------------------------------------------------------
// Lists of registers.
Expand Down
8 changes: 4 additions & 4 deletions src/arm64/simulator-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace internal {
#define CYAN "36"
#define WHITE "37"

typedef char const * const TEXT_COLOUR;
using TEXT_COLOUR = char const* const;
TEXT_COLOUR clr_normal = FLAG_log_colour ? COLOUR(NORMAL) : "";
TEXT_COLOUR clr_flag_name = FLAG_log_colour ? COLOUR_BOLD(WHITE) : "";
TEXT_COLOUR clr_flag_value = FLAG_log_colour ? COLOUR(NORMAL) : "";
Expand Down Expand Up @@ -874,7 +874,7 @@ void Simulator::AddSubWithCarry(Instruction* instr) {

template <typename T>
T Simulator::ShiftOperand(T value, Shift shift_type, unsigned amount) {
typedef typename std::make_unsigned<T>::type unsignedT;
using unsignedT = typename std::make_unsigned<T>::type;

if (amount == 0) {
return value;
Expand Down Expand Up @@ -2388,7 +2388,7 @@ void Simulator::DataProcessing2Source(Instruction* instr) {
}
case UDIV_w:
case UDIV_x: {
typedef typename std::make_unsigned<T>::type unsignedT;
using unsignedT = typename std::make_unsigned<T>::type;
unsignedT rn = static_cast<unsignedT>(reg<T>(instr->Rn()));
unsignedT rm = static_cast<unsignedT>(reg<T>(instr->Rm()));
if (rm == 0) {
Expand Down Expand Up @@ -2493,7 +2493,7 @@ void Simulator::VisitDataProcessing3Source(Instruction* instr) {

template <typename T>
void Simulator::BitfieldHelper(Instruction* instr) {
typedef typename std::make_unsigned<T>::type unsignedT;
using unsignedT = typename std::make_unsigned<T>::type;
T reg_size = sizeof(T) * 8;
T R = instr->ImmR();
T S = instr->ImmS();
Expand Down
4 changes: 2 additions & 2 deletions src/arm64/simulator-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ class SimRegisterBase {
void NotifyRegisterWrite() { written_since_last_log_ = true; }
};

typedef SimRegisterBase<kXRegSize> SimRegister; // r0-r31
typedef SimRegisterBase<kQRegSize> SimVRegister; // v0-v31
using SimRegister = SimRegisterBase<kXRegSize>; // r0-r31
using SimVRegister = SimRegisterBase<kQRegSize>; // v0-v31

// Representation of a vector register, with typed getters and setters for lanes
// and additional information to represent lane state.
Expand Down
2 changes: 1 addition & 1 deletion src/asmjs/asm-scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Utf16CharacterStream;
// (for performance).
class V8_EXPORT_PRIVATE AsmJsScanner {
public:
typedef int32_t token_t;
using token_t = int32_t;

explicit AsmJsScanner(Utf16CharacterStream* stream);

Expand Down
2 changes: 1 addition & 1 deletion src/asmjs/asm-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AsmOverloadedFunctionType;

class AsmValueType {
public:
typedef uint32_t bitset_t;
using bitset_t = uint32_t;

enum : uint32_t {
#define DEFINE_TAG(CamelName, string_name, number, parent_types) \
Expand Down
8 changes: 4 additions & 4 deletions src/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class DoExpression final : public Expression {

class Declaration : public AstNode {
public:
typedef base::ThreadedList<Declaration> List;
using List = base::ThreadedList<Declaration>;

Variable* var() const { return var_; }
void set_var(Variable* var) { var_ = var; }
Expand Down Expand Up @@ -1300,7 +1300,7 @@ class ObjectLiteralProperty final : public LiteralProperty {
// for minimizing the work when constructing it at runtime.
class ObjectLiteral final : public AggregateLiteral {
public:
typedef ObjectLiteralProperty Property;
using Property = ObjectLiteralProperty;

Handle<ObjectBoilerplateDescription> boilerplate_description() const {
DCHECK(!boilerplate_description_.is_null());
Expand Down Expand Up @@ -2459,7 +2459,7 @@ class ClassLiteralProperty final : public LiteralProperty {

class InitializeClassMembersStatement final : public Statement {
public:
typedef ClassLiteralProperty Property;
using Property = ClassLiteralProperty;

ZonePtrList<Property>* fields() const { return fields_; }

Expand All @@ -2474,7 +2474,7 @@ class InitializeClassMembersStatement final : public Statement {

class ClassLiteral final : public Expression {
public:
typedef ClassLiteralProperty Property;
using Property = ClassLiteralProperty;

ClassScope* scope() const { return scope_; }
Variable* class_variable() const { return class_variable_; }
Expand Down
12 changes: 6 additions & 6 deletions src/ast/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ class ModuleDescriptor : public ZoneObject {
bool operator()(const AstRawString* lhs, const AstRawString* rhs) const;
};

typedef ZoneMap<const AstRawString*, ModuleRequest, AstRawStringComparer>
ModuleRequestMap;
typedef ZoneMultimap<const AstRawString*, Entry*, AstRawStringComparer>
RegularExportMap;
typedef ZoneMap<const AstRawString*, Entry*, AstRawStringComparer>
RegularImportMap;
using ModuleRequestMap =
ZoneMap<const AstRawString*, ModuleRequest, AstRawStringComparer>;
using RegularExportMap =
ZoneMultimap<const AstRawString*, Entry*, AstRawStringComparer>;
using RegularImportMap =
ZoneMap<const AstRawString*, Entry*, AstRawStringComparer>;

// Module requests.
const ModuleRequestMap& module_requests() const { return module_requests_; }
Expand Down
4 changes: 2 additions & 2 deletions src/ast/scopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Statement;
class StringSet;
class VariableProxy;

typedef base::ThreadedList<VariableProxy, VariableProxy::UnresolvedNext>
UnresolvedList;
using UnresolvedList =
base::ThreadedList<VariableProxy, VariableProxy::UnresolvedNext>;

// A hash map to support fast variable declaration and lookup.
class VariableMap : public ZoneHashMap {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Variable final : public ZoneObject {
: kNeedsInitialization;
}

typedef base::ThreadedList<Variable> List;
using List = base::ThreadedList<Variable>;

private:
Scope* scope_;
Expand Down
6 changes: 3 additions & 3 deletions src/base/compiler-specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "include/v8config.h"

// Annotate a typedef or function indicating it's ok if it's not used.
// Use like:
// typedef Foo Bar ALLOW_UNUSED_TYPE;
// Annotate a using ALLOW_UNUSED_TYPE = or function indicating it's ok if it's
// not used. Use like:
// using Bar = Foo;
#if V8_HAS_ATTRIBUTE_UNUSED
#define ALLOW_UNUSED_TYPE __attribute__((unused))
#else
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/arm/builtins-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,7 @@ void Builtins::Generate_CallApiCallback(MacroAssembler* masm) {

DCHECK(!AreAliased(api_function_address, argc, call_data, holder, scratch));

typedef FunctionCallbackArguments FCA;
using FCA = FunctionCallbackArguments;

STATIC_ASSERT(FCA::kArgsLength == 6);
STATIC_ASSERT(FCA::kNewTargetIndex == 5);
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/arm64/builtins-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3530,7 +3530,7 @@ void Builtins::Generate_CallApiCallback(MacroAssembler* masm) {

DCHECK(!AreAliased(api_function_address, argc, call_data, holder, scratch));

typedef FunctionCallbackArguments FCA;
using FCA = FunctionCallbackArguments;

STATIC_ASSERT(FCA::kArgsLength == 6);
STATIC_ASSERT(FCA::kNewTargetIndex == 5);
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/builtins-arguments-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace v8 {
namespace internal {

typedef compiler::Node Node;
using Node = compiler::Node;

std::tuple<Node*, Node*, Node*>
ArgumentsBuiltinsAssembler::AllocateArgumentsObject(Node* map,
Expand Down
6 changes: 3 additions & 3 deletions src/builtins/builtins-arguments-gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
namespace v8 {
namespace internal {

typedef compiler::Node Node;
typedef compiler::CodeAssemblerState CodeAssemblerState;
typedef compiler::CodeAssemblerLabel CodeAssemblerLabel;
using Node = compiler::Node;
using CodeAssemblerState = compiler::CodeAssemblerState;
using CodeAssemblerLabel = compiler::CodeAssemblerLabel;

class ArgumentsBuiltinsAssembler
: public CodeStubAssembler,
Expand Down
6 changes: 3 additions & 3 deletions src/builtins/builtins-array-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ void ArrayBuiltinsAssembler::GenerateConstructor(

void ArrayBuiltinsAssembler::GenerateArrayNoArgumentConstructor(
ElementsKind kind, AllocationSiteOverrideMode mode) {
typedef ArrayNoArgumentConstructorDescriptor Descriptor;
using Descriptor = ArrayNoArgumentConstructorDescriptor;
Node* native_context = LoadObjectField(Parameter(Descriptor::kFunction),
JSFunction::kContextOffset);
bool track_allocation_site =
Expand All @@ -2224,7 +2224,7 @@ void ArrayBuiltinsAssembler::GenerateArrayNoArgumentConstructor(

void ArrayBuiltinsAssembler::GenerateArraySingleArgumentConstructor(
ElementsKind kind, AllocationSiteOverrideMode mode) {
typedef ArraySingleArgumentConstructorDescriptor Descriptor;
using Descriptor = ArraySingleArgumentConstructorDescriptor;
Node* context = Parameter(Descriptor::kContext);
Node* function = Parameter(Descriptor::kFunction);
Node* native_context = LoadObjectField(function, JSFunction::kContextOffset);
Expand Down Expand Up @@ -2318,7 +2318,7 @@ GENERATE_ARRAY_CTOR(SingleArgument, HoleyDouble, HOLEY_DOUBLE_ELEMENTS,
#undef GENERATE_ARRAY_CTOR

TF_BUILTIN(InternalArrayNoArgumentConstructor_Packed, ArrayBuiltinsAssembler) {
typedef ArrayNoArgumentConstructorDescriptor Descriptor;
using Descriptor = ArrayNoArgumentConstructorDescriptor;
TNode<Map> array_map =
CAST(LoadObjectField(Parameter(Descriptor::kFunction),
JSFunction::kPrototypeOrInitialMapOffset));
Expand Down
11 changes: 5 additions & 6 deletions src/builtins/builtins-array-gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
public:
explicit ArrayBuiltinsAssembler(compiler::CodeAssemblerState* state);

typedef std::function<void(ArrayBuiltinsAssembler* masm)>
BuiltinResultGenerator;
using BuiltinResultGenerator =
std::function<void(ArrayBuiltinsAssembler* masm)>;

typedef std::function<Node*(ArrayBuiltinsAssembler* masm, Node* k_value,
Node* k)>
CallResultProcessor;
using CallResultProcessor = std::function<Node*(ArrayBuiltinsAssembler* masm,
Node* k_value, Node* k)>;

typedef std::function<void(ArrayBuiltinsAssembler* masm)> PostLoopAction;
using PostLoopAction = std::function<void(ArrayBuiltinsAssembler* masm)>;

void FindResultGenerator();

Expand Down
Loading

0 comments on commit a335f2a

Please sign in to comment.