| 20 | } |
| 21 | |
| 22 | Expect<void> Loader::loadType(ComponentValType &Ty) { |
| 23 | // valtype ::= i:<typeidx> => i |
| 24 | // | pvt:<primvaltype> => pvt |
| 25 | |
| 26 | EXPECTED_TRY(int64_t Val, FMgr.readS33().map_error([this](auto E) { |
| 27 | return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Comp_ValueType); |
| 28 | })); |
| 29 | if (Val < 0) { |
| 30 | // PrimValType case. |
| 31 | if (Val < -64) { |
| 32 | // Check for an invalid s33 value larger than 1 byte. |
| 33 | return logLoadError(ErrCode::Value::MalformedValType, |
| 34 | FMgr.getLastOffset(), ASTNodeAttr::Comp_ValueType); |
| 35 | } |
| 36 | AST::Component::PrimValType PVT = static_cast<AST::Component::PrimValType>( |
| 37 | static_cast<uint8_t>(Val & INT64_C(0x7F))); |
| 38 | switch (PVT) { |
| 39 | case AST::Component::PrimValType::Bool: |
| 40 | case AST::Component::PrimValType::S8: |
| 41 | case AST::Component::PrimValType::U8: |
| 42 | case AST::Component::PrimValType::S16: |
| 43 | case AST::Component::PrimValType::U16: |
| 44 | case AST::Component::PrimValType::S32: |
| 45 | case AST::Component::PrimValType::U32: |
| 46 | case AST::Component::PrimValType::S64: |
| 47 | case AST::Component::PrimValType::U64: |
| 48 | case AST::Component::PrimValType::F32: |
| 49 | case AST::Component::PrimValType::F64: |
| 50 | case AST::Component::PrimValType::Char: |
| 51 | case AST::Component::PrimValType::String: |
| 52 | case AST::Component::PrimValType::ErrorContext: |
| 53 | Ty.setCode(static_cast<ComponentTypeCode>(PVT)); |
| 54 | break; |
| 55 | default: |
| 56 | return logLoadError(ErrCode::Value::MalformedValType, |
| 57 | FMgr.getLastOffset(), ASTNodeAttr::Comp_ValueType); |
| 58 | } |
| 59 | } else { |
| 60 | // Type index case. |
| 61 | Ty.setTypeIndex(static_cast<uint32_t>(Val)); |
| 62 | } |
| 63 | return {}; |
| 64 | } |
| 65 | |
| 66 | Expect<void> Loader::loadType(AST::Component::LabelValType &Ty) { |
| 67 | // labelvaltype ::= l:<label'> t:<valtype> |
nothing calls this directly
no test coverage detected