Called to begin the resolution of a compilation unit. This will build the import table (and any other data structures) to help resolve types within the compilation unit.
175 auto& importsMap = importsMap_[cu];
178 auto curPkg = cast<UnresolvedType>(cu->package());
193 for(
auto const& imp : cu->imports()) {
194 if(!imp.isOnDemand)
continue;
196 auto subPkg = resolveImport(
static_cast<UnresolvedType const*
>(imp.type));
198 if(!subPkg)
continue;
199 if(!std::holds_alternative<Pkg*>(subPkg.value())) {
200 diag.ReportError(imp.location())
201 <<
"failed to resolve import-on-demand as subpackage is a "
203 << imp.simpleName() <<
"\"";
207 auto pkg = std::get<Pkg*>(subPkg.value());
214 for(
auto& kv : pkg->children) {
215 if(!std::holds_alternative<Decl*>(kv.second))
continue;
216 auto decl = std::get<Decl*>(kv.second);
217 if(importsMap.find(kv.first) != importsMap.end()) {
218 auto imported = importsMap[kv.first];
219 if(std::holds_alternative<Decl*>(imported) &&
220 std::get<Decl*>(imported) == decl)
224 importsMap[kv.first] =
static_cast<Decl*
>(
nullptr);
227 importsMap[kv.first] = Pkg::Child{decl};
232 for(
auto& kv : rootPkg_->children) {
233 if(!std::holds_alternative<Pkg*>(kv.second))
235 if(importsMap.find(kv.first) != importsMap.end())
237 importsMap[kv.first] = Pkg::Child{std::get<Pkg*>(kv.second)};
242 auto curTree = resolveImport(curPkg);
243 assert(curTree &&
"Current package should exist!");
244 assert(std::holds_alternative<Pkg*>(curTree.value()));
245 for(
auto& kv : std::get<Pkg*>(curTree.value())->children)
246 if(std::holds_alternative<Decl*>(kv.second))
247 importsMap[kv.first] = Pkg::Child{std::get<Decl*>(kv.second)};
250 for(
auto const& imp : cu->imports()) {
251 if(imp.isOnDemand)
continue;
253 auto subPkg = resolveImport(
static_cast<UnresolvedType const*
>(imp.type));
254 if(!subPkg)
continue;
255 if(!std::holds_alternative<Decl*>(subPkg.value())) {
256 diag.ReportError(imp.location())
257 <<
"failed to resolve single-type-import as a declaration: \""
258 << imp.simpleName() <<
"\"";
262 auto decl = std::get<Decl*>(subPkg.value());
263 auto cuDecl = cu->bodyAsDecl();
266 if((decl->name() == cuDecl->name()) && (decl != cuDecl)) {
267 diag.ReportError(cu->location()) <<
"single-type-import is the same "
268 "as the class/interface name: "
272 std::pmr::string name{imp.simpleName().data(), alloc};
273 importsMap[name] = decl;
277 importsMap[cu->bodyAsDecl()->name().data()] = cu->mut_bodyAsDecl();
Base class for all declarations.
Represents an unresolved reference type. This means that the underlying reference type is not yet res...