Shallow populate: copy an InstanceType's exportdecls into the instance at InstIdx. InstanceType exportdecls get `IT` resolved in the current scope so alias-export can chase shapes through un-ascribed chains. Precondition: `IT` must be owned by the current ComponentContext scope — nested TypeIndex lookups resolve against that scope.
| 70 | // Precondition: `IT` must be owned by the current ComponentContext scope — |
| 71 | // nested TypeIndex lookups resolve against that scope. |
| 72 | void populateInstanceFromType(ComponentContext &Ctx, uint32_t InstIdx, |
| 73 | const AST::Component::InstanceType &IT) { |
| 74 | for (const auto &Decl : IT.getDecl()) { |
| 75 | if (!Decl.isExportDecl()) { |
| 76 | continue; |
| 77 | } |
| 78 | const auto &Exp = Decl.getExport(); |
| 79 | const auto &ED = Exp.getExternDesc(); |
| 80 | auto ST = descTypeToSortType(ED.getDescType()); |
| 81 | if (!ST.has_value()) { |
| 82 | // The InstanceExport::ST field is component-side only and has no |
| 83 | // variant for `(core module)`. Skip the export rather than crash; |
| 84 | // follow-up: extend InstanceExport to carry a core-sort alternative |
| 85 | // so nested alias lookups through a core-module export can resolve. |
| 86 | spdlog::debug( |
| 87 | " populateInstanceFromType: skipping `(core module)` export " |
| 88 | "'{}'"sv, |
| 89 | Exp.getName()); |
| 90 | continue; |
| 91 | } |
| 92 | const AST::Component::InstanceType *NestedIT = nullptr; |
| 93 | if (ED.getDescType() == |
| 94 | AST::Component::ExternDesc::DescType::InstanceType) { |
| 95 | NestedIT = Ctx.getInstanceType(ED.getTypeIndex()); |
| 96 | // Fallback: when IT is being processed inside a |
| 97 | // componenttype/instancetype scope, nested inline InstanceTypes live |
| 98 | // in IT's own local type-index space rather than the current scope's |
| 99 | // typestate. Walk IT's type-declaring decls to locate the N-th one. |
| 100 | if (NestedIT == nullptr) { |
| 101 | uint32_t TargetIdx = ED.getTypeIndex(); |
| 102 | uint32_t LocalIdx = 0; |
| 103 | for (const auto &LocalDecl : IT.getDecl()) { |
| 104 | if (!LocalDecl.isType()) { |
| 105 | continue; |
| 106 | } |
| 107 | if (LocalIdx == TargetIdx) { |
| 108 | const auto *LocalDT = LocalDecl.getType(); |
| 109 | if (LocalDT != nullptr && LocalDT->isInstanceType()) { |
| 110 | NestedIT = &LocalDT->getInstanceType(); |
| 111 | } |
| 112 | break; |
| 113 | } |
| 114 | LocalIdx++; |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | Ctx.addInstanceExport(InstIdx, Exp.getName(), *ST, NestedIT); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Returns the first export in `RequiredIT` missing from the instance at |
| 123 | // `ProvidedInstIdx`, or whose stored SortType doesn't match the required |
no test coverage detected