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

Method validateCanonResourceNew

lib/validator/component_validator.cpp:1333–1370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1331}
1332
1333Expect<void> Validator::validateCanonResourceNew(
1334 const AST::Component::Canonical &Canon) noexcept {
1335 const uint32_t Idx = Canon.getIndex();
1336 const uint32_t TypeSpaceSize =
1337 CompCtx.getSortIndexSize(AST::Component::Sort::SortType::Type);
1338 // 1. Type index bounds.
1339 if (Idx >= TypeSpaceSize) {
1340 spdlog::error(ErrCode::Value::InvalidIndex);
1341 spdlog::error(
1342 " canon resource.new: type index {} exceeds type index space size {}"sv,
1343 Idx, TypeSpaceSize);
1344 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1345 return Unexpect(ErrCode::Value::InvalidIndex);
1346 }
1347 // 2. Type must be a resource type.
1348 if (!CompCtx.isResourceType(Idx)) {
1349 spdlog::error(ErrCode::Value::InvalidTypeReference);
1350 spdlog::error(
1351 " canon resource.new: type index {} does not reference a resource"sv,
1352 Idx);
1353 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1354 return Unexpect(ErrCode::Value::InvalidTypeReference);
1355 }
1356 // 3. Resource must be locally defined.
1357 if (!CompCtx.isLocalResource(Idx)) {
1358 spdlog::error(ErrCode::Value::InvalidTypeReference);
1359 spdlog::error(
1360 " canon resource.new: type index {} is not locally defined (imported or outer-aliased resources are not allowed)"sv,
1361 Idx);
1362 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical));
1363 return Unexpect(ErrCode::Value::InvalidTypeReference);
1364 }
1365 // 4. Validate canonical options.
1366 EXPECTED_TRY(validateCanonOptions(Canon.getOpCode(), Canon.getOptions()));
1367 // 5. Allocate the resulting core func. Full signature tracking deferred.
1368 CompCtx.addCoreFunc();
1369 return {};
1370}
1371
1372Expect<void> Validator::validateCanonResourceRep(
1373 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