16#include <unordered_map>
29template<
typename SymbolT>
30struct SymbolMap : unordered_map<string, pair<SourceLocation, SymbolT *>> {
31 pair<SymbolT *, bool>
emplace(SymbolT *sym)
33 auto [it, success] = this->try_emplace(sym->identifier,
34 pair<SourceLocation, SymbolT *>(sym->loc, sym));
35 return pair<SymbolT *, bool>(it->second.second, success);
38 pair<SymbolT *, bool>
emplace(
const string &
id, SymbolT *sym)
40 auto [it, success] = this->try_emplace(
id, pair<SourceLocation, SymbolT *>(sym->loc, sym));
41 return pair<SymbolT *, bool>(it->second.second, success);
46 auto [it, success] = this->try_emplace(
id, pair<SourceLocation, SymbolT *>(loc, sym));
47 return pair<SymbolT *, bool>(it->second.second, success);
53 return this->find(k)->second.second;
66 unordered_map<string, SymbolScope *>
scopes;
87 optional<SourceLocation>
poi;
114 optional<SourceLocation>
loc = nullopt)
const;
116 template<
typename ArgOrParamList>
119 ArgOrParamList params,
121 optional<SourceLocation>
loc = nullopt)
const;
125 optional<SourceLocation>
loc = nullopt)
const;
130 optional<SourceLocation>
loc = nullopt)
const;
string to_string(const char *str)
Represents a specific position within a source file or included sub-file.
pair< SymbolT *, bool > emplace(const string &id, SymbolT *sym, SourceLocation loc)
pair< SymbolT *, bool > emplace(SymbolT *sym)
SymbolT * operator[](const string &k)
pair< SymbolT *, bool > emplace(const string &id, SymbolT *sym)
SymbolScope * child_scope(int n)
unordered_map< string, SymbolScope * > scopes
vector< SymbolVariable * > non_static_variables_in_declaration_order() const
SymbolVariable * lookup_variable(const SymbolTable &table, ast::IdQualified id) const
enum bsl::SymbolScope::Type type
SymbolScope(ast::LocalScope decl)
vector< std::pair< ast::FuncForwardDecl, SymbolFunction * > > function_prototypes
bool function_emplace(SymbolFunction *fn, bool builtin=false)
SymbolMap< SymbolFunction > functions
SymbolScope(SymbolScope *parent, Token tok, const string &id, Type type)
optional< SourceLocation > poi
SymbolScope(SymbolScope *parent, ast::Id id, Type type)
SymbolFunction * as_function()
bool variable_emplace(string id, SymbolVariable *var)
SymbolFunction * parent_function()
SymbolMap< SymbolVariable > variables
SymbolFunction * lookup_function_base(const SymbolTable &table, ast::IdQualified id) const
SymbolMap< SymbolClass > classes
const SymbolScope * root_scope() const
Result< SymbolFunction * > lookup_function(const SymbolTable &table, ast::IdQualified id, optional< SourceLocation > loc=nullopt) const
SymbolClass * lookup_class_base(const SymbolTable &table, ast::IdQualified id) const
Result< SymbolClass * > lookup_class(const SymbolTable &table, ast::IdQualified id, optional< SourceLocation > loc=nullopt) const
SymbolScope(SymbolScope *parent, ast::LocalScope decl)
std::pair< ast::FuncForwardDecl, SymbolFunction * > lookup_function_forward_decl(ast::FuncDecl decl) const