зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1477329 - Avoid static casts for coercing TypeDef nodes. r=jseward
There's no reason to use static_cast, we already have transfer functions on the AstTypeDef node that should be used. --HG-- extra : rebase_source : 07674fd96172143542c4f06c1048c8b5b0e82a90 extra : amend_source : f15851b91133f694ad209ce1feae65c5e1551747
This commit is contained in:
Родитель
46679701af
Коммит
5c37d5f314
|
@ -1334,6 +1334,13 @@ class AstModule : public AstNode
|
||||||
bool append(AstStructType* str) {
|
bool append(AstStructType* str) {
|
||||||
return types_.append(str);
|
return types_.append(str);
|
||||||
}
|
}
|
||||||
|
bool append(AstTypeDef* td) {
|
||||||
|
if (td->isFuncType())
|
||||||
|
return append(&td->asFuncType());
|
||||||
|
if (td->isStructType())
|
||||||
|
return append(&td->asStructType());
|
||||||
|
MOZ_CRASH("Bad type");
|
||||||
|
}
|
||||||
bool append(AstImport* imp) {
|
bool append(AstImport* imp) {
|
||||||
switch (imp->kind()) {
|
switch (imp->kind()) {
|
||||||
case DefinitionKind::Function:
|
case DefinitionKind::Function:
|
||||||
|
|
|
@ -4046,7 +4046,7 @@ ParseModule(const char16_t* text, uintptr_t stackLimit, LifoAlloc& lifo, UniqueC
|
||||||
AstTypeDef* typeDef = ParseTypeDef(c);
|
AstTypeDef* typeDef = ParseTypeDef(c);
|
||||||
if (!typeDef)
|
if (!typeDef)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (!module->append(static_cast<AstFuncType*>(typeDef)))
|
if (!module->append(typeDef))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4729,26 +4729,30 @@ ResolveModule(LifoAlloc& lifo, AstModule* module, UniqueChars* error)
|
||||||
for (size_t i = 0; i < numTypes; i++) {
|
for (size_t i = 0; i < numTypes; i++) {
|
||||||
AstTypeDef* td = module->types()[i];
|
AstTypeDef* td = module->types()[i];
|
||||||
if (td->isFuncType()) {
|
if (td->isFuncType()) {
|
||||||
AstFuncType* funcType = static_cast<AstFuncType*>(td);
|
AstFuncType* funcType = &td->asFuncType();
|
||||||
if (!r.registerFuncTypeName(funcType->name(), i))
|
if (!r.registerFuncTypeName(funcType->name(), i))
|
||||||
return r.fail("duplicate signature");
|
return r.fail("duplicate signature");
|
||||||
} else if (td->isStructType()) {
|
} else if (td->isStructType()) {
|
||||||
AstStructType* structType = static_cast<AstStructType*>(td);
|
AstStructType* structType = &td->asStructType();
|
||||||
if (!r.registerTypeName(structType->name(), i))
|
if (!r.registerTypeName(structType->name(), i))
|
||||||
return r.fail("duplicate type name");
|
return r.fail("duplicate type name");
|
||||||
|
} else {
|
||||||
|
MOZ_CRASH("Bad type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < numTypes; i++) {
|
for (size_t i = 0; i < numTypes; i++) {
|
||||||
AstTypeDef* td = module->types()[i];
|
AstTypeDef* td = module->types()[i];
|
||||||
if (td->isFuncType()) {
|
if (td->isFuncType()) {
|
||||||
AstFuncType* funcType = static_cast<AstFuncType*>(td);
|
AstFuncType* funcType = &td->asFuncType();
|
||||||
if (!ResolveSignature(r, *funcType))
|
if (!ResolveSignature(r, *funcType))
|
||||||
return false;
|
return false;
|
||||||
} else if (td->isStructType()) {
|
} else if (td->isStructType()) {
|
||||||
AstStructType* structType = static_cast<AstStructType*>(td);
|
AstStructType* structType = &td->asStructType();
|
||||||
if (!ResolveStruct(r, *structType))
|
if (!ResolveStruct(r, *structType))
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
MOZ_CRASH("Bad type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5392,7 +5396,7 @@ EncodeTypeSection(Encoder& e, AstModule& module)
|
||||||
|
|
||||||
for (AstTypeDef* td : module.types()) {
|
for (AstTypeDef* td : module.types()) {
|
||||||
if (td->isFuncType()) {
|
if (td->isFuncType()) {
|
||||||
AstFuncType* funcType = static_cast<AstFuncType*>(td);
|
AstFuncType* funcType = &td->asFuncType();
|
||||||
if (!e.writeVarU32(uint32_t(TypeCode::Func)))
|
if (!e.writeVarU32(uint32_t(TypeCode::Func)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -5412,7 +5416,7 @@ EncodeTypeSection(Encoder& e, AstModule& module)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (td->isStructType()) {
|
} else if (td->isStructType()) {
|
||||||
AstStructType* st = static_cast<AstStructType*>(td);
|
AstStructType* st = &td->asStructType();
|
||||||
if (!e.writeVarU32(uint32_t(TypeCode::Struct)))
|
if (!e.writeVarU32(uint32_t(TypeCode::Struct)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -5428,7 +5432,7 @@ EncodeTypeSection(Encoder& e, AstModule& module)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MOZ_CRASH();
|
MOZ_CRASH("Bad type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче