Resolve a type index in `Comp`'s own type index space to an InstanceType. Returns nullptr when the index does not refer to an inline InstanceType definition — callers treat nullptr as "no required shape" and fall back to inferred exports. TypeBound imports and outer-alias type imports currently fall through to nullptr; a more complete resolver would walk the alias chain to recover the underlying I
| 163 | // currently fall through to nullptr; a more complete resolver would walk |
| 164 | // the alias chain to recover the underlying InstanceType. |
| 165 | const AST::Component::InstanceType * |
| 166 | resolveChildInstanceType(const AST::Component::Component &Comp, |
| 167 | uint32_t TypeIdx) { |
| 168 | uint32_t CurrentIdx = 0; |
| 169 | for (const auto &Sec : Comp.getSections()) { |
| 170 | if (std::holds_alternative<AST::Component::TypeSection>(Sec)) { |
| 171 | const auto &TSec = std::get<AST::Component::TypeSection>(Sec); |
| 172 | for (const auto &DT : TSec.getContent()) { |
| 173 | if (CurrentIdx == TypeIdx) { |
| 174 | if (DT.isInstanceType()) { |
| 175 | return &DT.getInstanceType(); |
| 176 | } |
| 177 | return nullptr; |
| 178 | } |
| 179 | CurrentIdx++; |
| 180 | } |
| 181 | } else if (std::holds_alternative<AST::Component::ImportSection>(Sec)) { |
| 182 | const auto &ISec = std::get<AST::Component::ImportSection>(Sec); |
| 183 | for (const auto &Import : ISec.getContent()) { |
| 184 | if (Import.getDesc().getDescType() == |
| 185 | AST::Component::ExternDesc::DescType::TypeBound) { |
| 186 | if (CurrentIdx == TypeIdx) { |
| 187 | return nullptr; |
| 188 | } |
| 189 | CurrentIdx++; |
| 190 | } |
| 191 | } |
| 192 | } else if (std::holds_alternative<AST::Component::AliasSection>(Sec)) { |
| 193 | const auto &ASec = std::get<AST::Component::AliasSection>(Sec); |
| 194 | for (const auto &Alias : ASec.getContent()) { |
| 195 | if (!Alias.getSort().isCore() && |
| 196 | Alias.getSort().getSortType() == |
| 197 | AST::Component::Sort::SortType::Type) { |
| 198 | if (CurrentIdx == TypeIdx) { |
| 199 | return nullptr; |
| 200 | } |
| 201 | CurrentIdx++; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | return nullptr; |
| 207 | } |
| 208 | |
| 209 | // Validate that a name may appear at an export position: reject the |
| 210 | // `relative-url=` prefix (not part of the extern-name grammar) and any |
no test coverage detected