Returns the first export in `RequiredIT` missing from the instance at `ProvidedInstIdx`, or whose stored SortType doesn't match the required sort kind. nullopt ⇒ Provided is a sort-kind subtype of RequiredIT. Only the sort kind is compared; deep structural subtype between the required externdesc and the provided export's inferred type is not yet implemented.
| 126 | // required externdesc and the provided export's inferred type is not yet |
| 127 | // implemented. |
| 128 | std::optional<std::string> |
| 129 | findMissingRequiredExport(const ComponentContext &Ctx, uint32_t ProvidedInstIdx, |
| 130 | const AST::Component::InstanceType &RequiredIT) { |
| 131 | const auto &Exports = Ctx.getInstance(ProvidedInstIdx); |
| 132 | for (const auto &Decl : RequiredIT.getDecl()) { |
| 133 | if (!Decl.isExportDecl()) { |
| 134 | continue; |
| 135 | } |
| 136 | const auto &Exp = Decl.getExport(); |
| 137 | auto It = Exports.find(std::string(Exp.getName())); |
| 138 | if (It == Exports.end()) { |
| 139 | return std::string(Exp.getName()); |
| 140 | } |
| 141 | auto RequiredST = descTypeToSortType(Exp.getExternDesc().getDescType()); |
| 142 | if (!RequiredST.has_value()) { |
| 143 | // `(core module)` required-exports can't be compared against |
| 144 | // InstanceExport::ST (component-side only). Skip symmetrically with |
| 145 | // populateInstanceFromType; will be revisited when InstanceExport |
| 146 | // gains a core-sort variant. |
| 147 | spdlog::debug(" findMissingRequiredExport: skipping `(core module)` " |
| 148 | "required-export '{}'"sv, |
| 149 | Exp.getName()); |
| 150 | continue; |
| 151 | } |
| 152 | if (It->second.ST != *RequiredST) { |
| 153 | return std::string(Exp.getName()); |
| 154 | } |
| 155 | } |
| 156 | return std::nullopt; |
| 157 | } |
| 158 | |
| 159 | // Resolve a type index in `Comp`'s own type index space to an InstanceType. |
| 160 | // Returns nullptr when the index does not refer to an inline InstanceType |
no test coverage detected