Skip to content

Commit d24427d

Browse files
authored
Code style improvements (#1868)
* Use modern T p = v; notation to initialize class fields * Use modern X() = default; notation for empty class constructors
1 parent 45714b5 commit d24427d

23 files changed

+108
-102
lines changed

src/cfg/Relooper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ static wasm::Expression* HandleFollowupMultiples(wasm::Expression* Ret, Shape* P
9999

100100
// Branch
101101

102-
Branch::Branch(wasm::Expression* ConditionInit, wasm::Expression* CodeInit) : Ancestor(nullptr), Condition(ConditionInit), Code(CodeInit) {}
102+
Branch::Branch(wasm::Expression* ConditionInit, wasm::Expression* CodeInit) : Condition(ConditionInit), Code(CodeInit) {}
103103

104-
Branch::Branch(std::vector<wasm::Index>&& ValuesInit, wasm::Expression* CodeInit) : Ancestor(nullptr), Condition(nullptr), Code(CodeInit) {
104+
Branch::Branch(std::vector<wasm::Index>&& ValuesInit, wasm::Expression* CodeInit) : Condition(nullptr), Code(CodeInit) {
105105
if (ValuesInit.size() > 0) {
106106
SwitchValues = wasm::make_unique<std::vector<wasm::Index>>(ValuesInit);
107107
}
@@ -124,7 +124,7 @@ wasm::Expression* Branch::Render(RelooperBuilder& Builder, Block* Target, bool S
124124

125125
// Block
126126

127-
Block::Block(wasm::Expression* CodeInit, wasm::Expression* SwitchConditionInit) : Parent(nullptr), Id(-1), Code(CodeInit), SwitchCondition(SwitchConditionInit), IsCheckedMultipleEntry(false) {}
127+
Block::Block(wasm::Expression* CodeInit, wasm::Expression* SwitchConditionInit) : Code(CodeInit), SwitchCondition(SwitchConditionInit), IsCheckedMultipleEntry(false) {}
128128

129129
Block::~Block() {
130130
for (auto& iter : ProcessedBranchesOut) {

src/cfg/Relooper.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct Branch {
8282
Break = 1,
8383
Continue = 2
8484
};
85-
Shape* Ancestor; // If not NULL, this shape is the relevant one for purposes of getting to the target block. We break or continue on it
85+
Shape* Ancestor = nullptr; // If not NULL, this shape is the relevant one for purposes of getting to the target block. We break or continue on it
8686
Branch::FlowType Type; // If Ancestor is not NULL, this says whether to break or continue
8787

8888
// A branch either has a condition expression if the block ends in ifs, or if the block ends in a switch, then a list of indexes, which
@@ -151,7 +151,7 @@ struct InsertOrderedSet
151151

152152
size_t count(const T& val) const { return Map.count(val); }
153153

154-
InsertOrderedSet() {}
154+
InsertOrderedSet() = default;
155155
InsertOrderedSet(const InsertOrderedSet& other) {
156156
*this = other;
157157
}
@@ -214,7 +214,7 @@ struct InsertOrderedMap
214214
bool empty() const { return Map.empty(); }
215215
size_t count(const Key& k) const { return Map.count(k); }
216216

217-
InsertOrderedMap() {}
217+
InsertOrderedMap() = default;
218218
InsertOrderedMap(InsertOrderedMap& other) {
219219
abort(); // TODO, watch out for iterators
220220
}
@@ -245,8 +245,8 @@ struct Block {
245245
BlockSet BranchesIn;
246246
BlockBranchMap ProcessedBranchesOut;
247247
BlockSet ProcessedBranchesIn;
248-
Shape* Parent; // The shape we are directly inside
249-
int Id; // A unique identifier, defined when added to relooper
248+
Shape* Parent = nullptr; // The shape we are directly inside
249+
int Id = -1; // A unique identifier, defined when added to relooper
250250
wasm::Expression* Code; // The code in this block. This can be arbitrary wasm code, including internal control flow, it should just not branch to the outside
251251
wasm::Expression* SwitchCondition; // If nullptr, then this block ends in ifs (or nothing). otherwise, this block ends in a switch, done on this condition
252252
bool IsCheckedMultipleEntry; // If true, we are a multiple entry, so reaching us requires setting the label variable
@@ -296,8 +296,8 @@ struct MultipleShape;
296296
struct LoopShape;
297297

298298
struct Shape {
299-
int Id; // A unique identifier. Used to identify loops, labels are Lx where x is the Id. Defined when added to relooper
300-
Shape* Next; // The shape that will appear in the code right after this one
299+
int Id = -1; // A unique identifier. Used to identify loops, labels are Lx where x is the Id. Defined when added to relooper
300+
Shape* Next = nullptr; // The shape that will appear in the code right after this one
301301
Shape* Natural; // The shape that control flow gets to naturally (if there is Next, then this is Next)
302302

303303
enum ShapeType {
@@ -307,7 +307,7 @@ struct Shape {
307307
};
308308
ShapeType Type;
309309

310-
Shape(ShapeType TypeInit) : Id(-1), Next(NULL), Type(TypeInit) {}
310+
Shape(ShapeType TypeInit) : Type(TypeInit) {}
311311
virtual ~Shape() = default;
312312

313313
virtual wasm::Expression* Render(RelooperBuilder& Builder, bool InLoop) = 0;
@@ -318,9 +318,9 @@ struct Shape {
318318
};
319319

320320
struct SimpleShape : public Shape {
321-
Block* Inner;
321+
Block* Inner = nullptr;
322322

323-
SimpleShape() : Shape(Simple), Inner(NULL) {}
323+
SimpleShape() : Shape(Simple) {}
324324
wasm::Expression* Render(RelooperBuilder& Builder, bool InLoop) override;
325325
};
326326

@@ -335,11 +335,11 @@ struct MultipleShape : public Shape {
335335
};
336336

337337
struct LoopShape : public Shape {
338-
Shape* Inner;
338+
Shape* Inner = nullptr;
339339

340340
BlockSet Entries; // we must visit at least one of these
341341

342-
LoopShape() : Shape(Loop), Inner(NULL) {}
342+
LoopShape() : Shape(Loop) {}
343343
wasm::Expression* Render(RelooperBuilder& Builder, bool InLoop) override;
344344
};
345345

src/emscripten-optimizer/istring.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
namespace cashew {
3636

3737
struct IString {
38-
const char *str;
38+
const char *str = nullptr;
3939

4040
static size_t hash_c(const char *str) { // see http://www.cse.yorku.ca/~oz/hash.html
4141
unsigned int hash = 5381;
@@ -59,7 +59,7 @@ struct IString {
5959
}
6060
};
6161

62-
IString() : str(nullptr) {}
62+
IString() = default;
6363
IString(const char *s, bool reuse=true) { // if reuse=true, then input is assumed to remain alive; not copied
6464
assert(s);
6565
set(s, reuse);
@@ -178,7 +178,7 @@ namespace cashew {
178178
class IStringSet : public std::unordered_set<IString> {
179179
std::vector<char> data;
180180
public:
181-
IStringSet() {}
181+
IStringSet() = default;
182182
IStringSet(const char *init) { // comma-delimited list
183183
int size = strlen(init) + 1;
184184
data.resize(size);

src/emscripten-optimizer/optimizer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ AsmType detectType(cashew::Ref node, AsmData *asmData=nullptr, bool inVarDef=fal
5959

6060
struct AsmData {
6161
struct Local {
62-
Local() {}
62+
Local() = default;
6363
Local(AsmType type, bool param) : type(type), param(param) {}
6464
AsmType type;
6565
bool param; // false if a var
@@ -92,7 +92,7 @@ struct AsmData {
9292
return isLocal(name) && !locals[name].param;
9393
}
9494

95-
AsmData() {} // if you want to fill in the data yourself
95+
AsmData() = default; // if you want to fill in the data yourself
9696
AsmData(cashew::Ref f); // if you want to read data from f, and modify it as you go (parallel to denormalize)
9797

9898
void denormalize();

src/emscripten-optimizer/parser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,8 @@ class Parser {
910910

911911
// Debugging
912912

913-
char *allSource;
914-
int allSize;
913+
char *allSource = nullptr;
914+
int allSize = 0;
915915

916916
static void dump(const char *where, char* curr) {
917917
/*
@@ -938,7 +938,7 @@ class Parser {
938938

939939
public:
940940

941-
Parser() : allSource(nullptr), allSize(0) {
941+
Parser() {
942942
expressionPartsStack.resize(1);
943943
}
944944

src/emscripten-optimizer/simple_ast.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void dump(const char *str, Ref node, bool pretty) {
188188
// Traversals
189189

190190
struct TraverseInfo {
191-
TraverseInfo() {}
191+
TraverseInfo() = default;
192192
TraverseInfo(Ref node, ArrayStorage* arr) : node(node), arr(arr), index(0) {}
193193
Ref node;
194194
ArrayStorage* arr;
@@ -199,10 +199,11 @@ template<class T, int init>
199199
struct StackedStack { // a stack, on the stack
200200
T stackStorage[init];
201201
T* storage;
202-
int used, available; // used amount, available amount
203-
bool alloced;
202+
int used = 0;
203+
int available = init; // used amount, available amount
204+
bool alloced = false;
204205

205-
StackedStack() : used(0), available(init), alloced(false) {
206+
StackedStack() {
206207
storage = stackStorage;
207208
}
208209
~StackedStack() {

src/emscripten-optimizer/simple_ast.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct Value {
112112
AssignName_ = 7
113113
};
114114

115-
Type type;
115+
Type type = Null;
116116

117117
typedef std::unordered_map<IString, Ref> ObjectStorage;
118118

@@ -131,14 +131,14 @@ struct Value {
131131
};
132132

133133
// constructors all copy their input
134-
Value() : type(Null), num(0) {}
135-
explicit Value(const char *s) : type(Null) {
134+
Value() {}
135+
explicit Value(const char *s) {
136136
setString(s);
137137
}
138-
explicit Value(double n) : type(Null) {
138+
explicit Value(double n) {
139139
setNumber(n);
140140
}
141-
explicit Value(ArrayStorage &a) : type(Null) {
141+
explicit Value(ArrayStorage &a) {
142142
setArray();
143143
*arr = a;
144144
}
@@ -544,15 +544,16 @@ void traverseFunctions(Ref ast, std::function<void (Ref)> visit);
544544
struct JSPrinter {
545545
bool pretty, finalize;
546546

547-
char *buffer;
548-
size_t size, used;
547+
char *buffer = nullptr;
548+
size_t size = 0;
549+
size_t used = 0;
549550

550-
int indent;
551-
bool possibleSpace; // add a space to separate identifiers
551+
int indent = 0;
552+
bool possibleSpace = false; // add a space to separate identifiers
552553

553554
Ref ast;
554555

555-
JSPrinter(bool pretty_, bool finalize_, Ref ast_) : pretty(pretty_), finalize(finalize_), buffer(0), size(0), used(0), indent(0), possibleSpace(false), ast(ast_) {}
556+
JSPrinter(bool pretty_, bool finalize_, Ref ast_) : pretty(pretty_), finalize(finalize_), ast(ast_) {}
556557

557558
~JSPrinter() {
558559
free(buffer);

src/ir/branch-utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ struct BranchSeeker : public PostWalker<BranchSeeker> {
149149
Name target;
150150
bool named = true;
151151

152-
Index found;
152+
Index found = 0;
153153
Type valueType;
154154

155-
BranchSeeker(Name target) : target(target), found(0) {}
155+
BranchSeeker(Name target) : target(target) {}
156156

157157
void noteFound(Expression* value) {
158158
found++;

src/ir/count.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace wasm {
2222
struct GetLocalCounter : public PostWalker<GetLocalCounter> {
2323
std::vector<Index> num;
2424

25-
GetLocalCounter() {}
25+
GetLocalCounter() = default;
2626
GetLocalCounter(Function* func) {
2727
analyze(func, func->body);
2828
}

src/pass.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct PassRegistry {
4949
struct PassInfo {
5050
std::string description;
5151
Creator create;
52-
PassInfo() {}
52+
PassInfo() = default;
5353
PassInfo(std::string description, Creator create) : description(description), create(create) {}
5454
};
5555
std::map<std::string, PassInfo> passInfos;
@@ -253,8 +253,8 @@ class Pass {
253253
std::string name;
254254

255255
protected:
256-
Pass() {}
257-
Pass(Pass &) {}
256+
Pass() = default;
257+
Pass(Pass &) = default;
258258
Pass &operator=(const Pass&) = delete;
259259
};
260260

0 commit comments

Comments
 (0)