MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / validateCanonResourceRep

Method validateCanonResourceRep

lib/validator/component_validator.cpp:1372–1409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1370}
1371
1372Expect<void> Validator::validateCanonResourceRep(
1373 const AST::Component::Canonical &Canon) noexcept {
1374 const uint32_t Idx = Canon.getIndex();
1375 const uint32_t TypeSpaceSize =
1376 CompCtx.getSortIndexSize(AST::Component::Sort::SortType::Type);
1377 // 1. Type index bounds.
1378 if (Idx >= TypeSpaceSize) {
1379 spdlog::error(ErrCode::Value::InvalidIndex);
1380 spdlog::error(
1381 " canon resource.rep: type index {} exceeds type index space size {}"sv,
1382 Idx, TypeSpaceSize);
1383 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1384 return Unexpect(ErrCode::Value::InvalidIndex);
1385 }
1386 // 2. Type must be a resource type.
1387 if (!CompCtx.isResourceType(Idx)) {
1388 spdlog::error(ErrCode::Value::InvalidTypeReference);
1389 spdlog::error(
1390 " canon resource.rep: type index {} does not reference a resource"sv,
1391 Idx);
1392 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1393 return Unexpect(ErrCode::Value::InvalidTypeReference);
1394 }
1395 // 3. Resource must be locally defined.
1396 if (!CompCtx.isLocalResource(Idx)) {
1397 spdlog::error(ErrCode::Value::InvalidTypeReference);
1398 spdlog::error(
1399 " canon resource.rep: type index {} is not locally defined (imported or outer-aliased resources are not allowed)"sv,
1400 Idx);
1401 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1402 return Unexpect(ErrCode::Value::InvalidTypeReference);
1403 }
1404 // 4. Validate canonical options.
1405 EXPECTED_TRY(validateCanonOptions(Canon.getOpCode(), Canon.getOptions()));
1406 // 5. Allocate the resulting core func. Full signature tracking deferred.
1407 CompCtx.addCoreFunc();
1408 return {};
1409}
1410
1411Expect<void> Validator::validateCanonResourceDrop(
1412 const AST::Component::Canonical &Canon) noexcept {

Callers

nothing calls this directly

Calls 11

InfoASTClass · 0.85
UnexpectFunction · 0.85
isLocalResourceMethod · 0.80
getOptionsMethod · 0.80
addCoreFuncMethod · 0.80
errorFunction · 0.50
EXPECTED_TRYFunction · 0.50
getIndexMethod · 0.45
getSortIndexSizeMethod · 0.45
isResourceTypeMethod · 0.45
getOpCodeMethod · 0.45

Tested by

no test coverage detected