4 #include <memory_resource>
7 #include <unordered_map>
10 #include "ast/AstNode.h"
11 #include "diagnostics/Diagnostics.h"
12 #include "utils/BumpAllocator.h"
17 class CompilationUnit;
32 using ConstImport = std::variant<ast::
Decl const*,
Pkg const*>;
33 using ConstImportOpt = std::optional<ConstImport>;
38 using Child = std::variant<ast::
Decl*,
Pkg*>;
39 friend class NameResolver;
40 std::string_view name;
41 std::pmr::unordered_map<std::pmr::string, Child> children;
44 Pkg(BumpAllocator& alloc) : name{}, children{alloc} {}
45 Pkg(BumpAllocator& alloc, std::string_view name)
46 : name{name}, children{alloc} {}
55 ConstImportOpt
lookup(std::string_view name, BumpAllocator& alloc)
const {
56 auto it = children.find(std::pmr::string{name, alloc});
57 if(it == children.end())
return std::nullopt;
58 if(
auto* pkg = std::get_if<Pkg*>(&it->second))
return *pkg;
59 return std::get<ast::Decl*>(it->second);
63 std::ostream& print(std::ostream& os,
int indentation = 0)
const;
69 NameResolver(NameResolver
const&) =
delete;
70 NameResolver(NameResolver&&) =
delete;
71 NameResolver& operator=(NameResolver
const&) =
delete;
72 NameResolver& operator=(NameResolver&&) =
delete;
95 populateJavaLangCache();
103 void ResolveType(ast::UnresolvedType* type)
override;
118 ast::CompilationUnit
const* cu, std::string_view name,
119 std::pmr::memory_resource* r = std::pmr::get_default_resource())
const;
154 void dumpImports(ast::CompilationUnit
const* cu)
const;
160 using ChildOpt = std::optional<
Pkg::Child>;
164 void buildSymbolTable();
170 void populateJavaLangCache();
175 ChildOpt resolveImport(ast::UnresolvedType
const* t)
const;
178 BumpAllocator& alloc;
181 ast::LinkingUnit* lu_;
183 ast::CompilationUnit* currentCU_;
185 std::pmr::unordered_map<ast::CompilationUnit
const*,
186 std::pmr::unordered_map<std::pmr::string, Pkg::Child>>
192 ast::ClassDecl* Boolean;
193 ast::ClassDecl* Byte;
194 ast::ClassDecl* Character;
195 ast::ClassDecl* Class;
196 ast::InterfaceDecl* Cloneable;
197 ast::ClassDecl* Integer;
198 ast::ClassDecl* Number;
199 ast::ClassDecl* Object;
200 ast::ClassDecl* Short;
201 ast::ClassDecl* String;
202 ast::ClassDecl* System;
203 ast::InterfaceDecl* Serializable;
206 ast::ClassDecl* arrayPrototype_;