Skip to content

Commit af87f23

Browse files
authored
Use const modifier when dealing with types (#3064)
Since they make the code clearer and more self-documenting.
1 parent a18d30f commit af87f23

22 files changed

+50
-50
lines changed

src/asmjs/asm_v_wasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ std::string getSig(Type results, Type params) {
104104
assert(!results.isMulti());
105105
std::string sig;
106106
sig += getSig(results);
107-
for (auto& param : params) {
107+
for (const auto& param : params) {
108108
sig += getSig(param);
109109
}
110110
return sig;

src/binaryen-c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ uint32_t BinaryenTypeArity(BinaryenType t) { return Type(t).size(); }
152152
void BinaryenTypeExpand(BinaryenType t, BinaryenType* buf) {
153153
Type types(t);
154154
size_t i = 0;
155-
for (auto& type : types) {
155+
for (const auto& type : types) {
156156
buf[i++] = type.getID();
157157
}
158158
}

src/passes/Asyncify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ struct AsyncifyLocals : public WalkerPass<PostWalker<AsyncifyLocals>> {
13061306
}
13071307
auto localType = func->getLocalType(i);
13081308
SmallVector<Expression*, 1> loads;
1309-
for (auto& type : localType) {
1309+
for (const auto& type : localType) {
13101310
auto size = type.getByteSize();
13111311
assert(size % STACK_ALIGN == 0);
13121312
// TODO: higher alignment?
@@ -1350,7 +1350,7 @@ struct AsyncifyLocals : public WalkerPass<PostWalker<AsyncifyLocals>> {
13501350
}
13511351
auto localType = func->getLocalType(i);
13521352
size_t j = 0;
1353-
for (auto& type : localType) {
1353+
for (const auto& type : localType) {
13541354
auto size = type.getByteSize();
13551355
Expression* localGet = builder->makeLocalGet(i, localType);
13561356
if (localType.size() > 1) {

src/passes/FuncCastEmulation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ struct FuncCastEmulation : public Pass {
197197
Builder builder(*module);
198198
std::vector<Expression*> callOperands;
199199
Index i = 0;
200-
for (auto& param : func->sig.params) {
200+
for (const auto& param : func->sig.params) {
201201
callOperands.push_back(
202202
fromABI(builder.makeLocalGet(i++, Type::i64), param, module));
203203
}

src/passes/I64ToI32Lowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
272272
visitGenericCall<CallIndirect>(
273273
curr, [&](std::vector<Expression*>& args, Type results) {
274274
std::vector<Type> params;
275-
for (auto& param : curr->sig.params) {
275+
for (const auto& param : curr->sig.params) {
276276
if (param == Type::i64) {
277277
params.push_back(Type::i32);
278278
params.push_back(Type::i32);

src/passes/LegalizeJSInterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ struct LegalizeJSInterface : public Pass {
183183
std::map<Name, Name> illegalImportsToLegal;
184184

185185
template<typename T> bool isIllegal(T* t) {
186-
for (auto& param : t->sig.params) {
186+
for (const auto& param : t->sig.params) {
187187
if (param == Type::i64) {
188188
return true;
189189
}
@@ -223,7 +223,7 @@ struct LegalizeJSInterface : public Pass {
223223
call->type = func->sig.results;
224224

225225
std::vector<Type> legalParams;
226-
for (auto& param : func->sig.params) {
226+
for (const auto& param : func->sig.params) {
227227
if (param == Type::i64) {
228228
call->operands.push_back(I64Utilities::recreateI64(
229229
builder, legalParams.size(), legalParams.size() + 1));
@@ -278,7 +278,7 @@ struct LegalizeJSInterface : public Pass {
278278

279279
std::vector<Type> params;
280280
Index i = 0;
281-
for (auto& param : im->sig.params) {
281+
for (const auto& param : im->sig.params) {
282282
if (param == Type::i64) {
283283
call->operands.push_back(I64Utilities::getI64Low(builder, i));
284284
call->operands.push_back(I64Utilities::getI64High(builder, i));

src/passes/Print.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static std::ostream& operator<<(std::ostream& o, const SExprType& localType) {
6969
if (type.isMulti()) {
7070
o << '(';
7171
auto sep = "";
72-
for (auto& t : type) {
72+
for (const auto& t : type) {
7373
o << sep << t;
7474
sep = " ";
7575
}
@@ -92,7 +92,7 @@ std::ostream& operator<<(std::ostream& os, SigName sigName) {
9292
os << "none";
9393
} else {
9494
auto sep = "";
95-
for (auto& t : type) {
95+
for (const auto& t : type) {
9696
os << sep << t;
9797
sep = "_";
9898
}
@@ -2170,7 +2170,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
21702170
}
21712171
if (curr->sig.params.size() > 0) {
21722172
Index i = 0;
2173-
for (auto& param : curr->sig.params) {
2173+
for (const auto& param : curr->sig.params) {
21742174
o << maybeSpace;
21752175
o << '(';
21762176
printMinor(o, "param ");

src/shell-interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
169169
trap("callIndirect: bad # of arguments");
170170
}
171171
size_t i = 0;
172-
for (auto& param : func->sig.params) {
172+
for (const auto& param : func->sig.params) {
173173
if (!Type::isSubType(arguments[i++].type, param)) {
174174
trap("callIndirect: bad argument type");
175175
}

src/tools/execution-results.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct ExecutionResults {
144144
instance.callFunction(ex->value, arguments);
145145
}
146146
// call the method
147-
for (auto& param : func->sig.params) {
147+
for (const auto& param : func->sig.params) {
148148
// zeros in arguments TODO: more?
149149
arguments.push_back(Literal::makeSingleZero(param));
150150
}

src/tools/fuzzing.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class TranslateToFuzzReader {
308308
Type getSubType(Type type) {
309309
if (type.isMulti()) {
310310
std::vector<Type> types;
311-
for (auto& t : type) {
311+
for (const auto& t : type) {
312312
types.push_back(getSubType(t));
313313
}
314314
return Type(types);
@@ -770,7 +770,7 @@ class TranslateToFuzzReader {
770770
std::vector<Expression*> invocations;
771771
while (oneIn(2) && !finishedInput) {
772772
std::vector<Expression*> args;
773-
for (auto& type : func->sig.params) {
773+
for (const auto& type : func->sig.params) {
774774
args.push_back(makeConst(type));
775775
}
776776
Expression* invoke =
@@ -1166,7 +1166,7 @@ class TranslateToFuzzReader {
11661166
}
11671167
// we found one!
11681168
std::vector<Expression*> args;
1169-
for (auto& argType : target->sig.params) {
1169+
for (const auto& argType : target->sig.params) {
11701170
args.push_back(make(argType));
11711171
}
11721172
return builder.makeCall(target->name, args, type, isReturn);
@@ -1210,7 +1210,7 @@ class TranslateToFuzzReader {
12101210
target = make(Type::i32);
12111211
}
12121212
std::vector<Expression*> args;
1213-
for (auto& type : targetFn->sig.params) {
1213+
for (const auto& type : targetFn->sig.params) {
12141214
args.push_back(make(type));
12151215
}
12161216
return builder.makeCallIndirect(target, args, targetFn->sig, isReturn);
@@ -1267,7 +1267,7 @@ class TranslateToFuzzReader {
12671267
assert(wasm.features.hasMultivalue());
12681268
assert(type.isMulti());
12691269
std::vector<Expression*> elements;
1270-
for (auto& t : type) {
1270+
for (const auto& t : type) {
12711271
elements.push_back(make(t));
12721272
}
12731273
return builder.makeTupleMake(std::move(elements));
@@ -1281,7 +1281,7 @@ class TranslateToFuzzReader {
12811281
// Find indices from which we can extract `type`
12821282
std::vector<size_t> extractIndices;
12831283
size_t i = 0;
1284-
for (auto& t : tupleType) {
1284+
for (const auto& t : tupleType) {
12851285
if (t == type) {
12861286
extractIndices.push_back(i);
12871287
}
@@ -1767,7 +1767,7 @@ class TranslateToFuzzReader {
17671767
}
17681768
if (type.isMulti()) {
17691769
std::vector<Expression*> operands;
1770-
for (auto& t : type) {
1770+
for (const auto& t : type) {
17711771
operands.push_back(makeConst(t));
17721772
}
17731773
return builder.makeTupleMake(std::move(operands));

0 commit comments

Comments
 (0)