| 70 | } |
| 71 | |
| 72 | Expect<void> Loader::loadInstance(AST::Component::Instance &Instance) { |
| 73 | auto ReportError = [this](auto E) { |
| 74 | return logLoadError(E, FMgr.getLastOffset(), ASTNodeAttr::Comp_Instance); |
| 75 | }; |
| 76 | // instance ::= ie:<instanceexpr> |
| 77 | // => (instance ie) |
| 78 | // instanceexpr ::= 0x00 c:<componentidx> arg*:vec(<instantiatearg>) |
| 79 | // => (instantiate c arg*) |
| 80 | // | 0x01 e*:vec(<inlineexport>) |
| 81 | // => e* |
| 82 | |
| 83 | auto LoadInstArg = |
| 84 | [this](AST::Component::InstantiateArg<AST::Component::SortIndex> &Arg) |
| 85 | -> Expect<void> { |
| 86 | // instantiatearg ::= n:<string> si:<sortidx> => (with n si) |
| 87 | EXPECTED_TRY(Arg.getName(), FMgr.readName().map_error([this](auto E) { |
| 88 | return logLoadError(E, FMgr.getLastOffset(), |
| 89 | ASTNodeAttr::Comp_InstanceArg); |
| 90 | })); |
| 91 | return loadSortIndex(Arg.getIndex()).map_error([](auto E) { |
| 92 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_InstanceArg)); |
| 93 | return E; |
| 94 | }); |
| 95 | }; |
| 96 | |
| 97 | auto LoadInlineExp = |
| 98 | [this](AST::Component::InlineExport &Exp) -> Expect<void> { |
| 99 | // inlineexport ::= n:<exportname> si:<sortidx> => (export n si) |
| 100 | EXPECTED_TRY(loadExternName(Exp.getName()).map_error([this](auto E) { |
| 101 | return logLoadError(E, FMgr.getLastOffset(), |
| 102 | ASTNodeAttr::Comp_InlineExport); |
| 103 | })); |
| 104 | return loadSortIndex(Exp.getSortIdx()).map_error([](auto E) { |
| 105 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_InlineExport)); |
| 106 | return E; |
| 107 | }); |
| 108 | }; |
| 109 | |
| 110 | EXPECTED_TRY(uint8_t Flag, FMgr.readByte().map_error(ReportError)); |
| 111 | switch (Flag) { |
| 112 | case 0x00: { |
| 113 | EXPECTED_TRY(uint32_t Idx, FMgr.readU32().map_error(ReportError)); |
| 114 | std::vector<AST::Component::InstantiateArg<AST::Component::SortIndex>> Args; |
| 115 | EXPECTED_TRY(loadVec<AST::Component::Instance>(Args, LoadInstArg)); |
| 116 | Instance.setInstantiateArgs(Idx, std::move(Args)); |
| 117 | return {}; |
| 118 | } |
| 119 | case 0x01: { |
| 120 | std::vector<AST::Component::InlineExport> Exports; |
| 121 | EXPECTED_TRY(loadVec<AST::Component::Instance>(Exports, LoadInlineExp)); |
| 122 | Instance.setInlineExports(std::move(Exports)); |
| 123 | return {}; |
| 124 | } |
| 125 | default: |
| 126 | return logLoadError(ErrCode::Value::MalformedInstance, FMgr.getLastOffset(), |
| 127 | ASTNodeAttr::Comp_Instance); |
| 128 | } |
| 129 | } |
nothing calls this directly
no test coverage detected