35 enum class SymbolKind {
45 std::shared_ptr<Type> m_type;
66 Symbol(SymbolKind kind,
const std::string &name,
const std::shared_ptr<Type> &type,
SymbolTable *symtab,
bool is_defined);
72 void set_is_defined(
bool is_defined);
74 SymbolKind get_kind()
const;
75 const std::string &get_name()
const;
76 std::shared_ptr<Type> get_type()
const;
78 bool is_defined()
const;
81 void set_flag(Flag flag) { m_flags |= unsigned(flag); }
82 void clear_flag(Flag flag) { m_flags &= ~(unsigned(flag)); }
83 bool has_flag(Flag flag)
const {
return (m_flags &
unsigned(flag)) != 0U; }
85 void set_offset(
unsigned offset) { m_offset = offset; }
86 unsigned get_offset()
const {
return m_offset; }
88 void set_vreg(
int vreg) { m_vreg = vreg; }
89 int get_vreg()
const {
return m_vreg; }
96 std::vector<Symbol *> m_symbols;
97 std::map<std::string, unsigned> m_lookup;
104 std::shared_ptr<Type> m_fn_type;
116 bool has_params()
const;
117 void set_has_params(
bool has_params);
122 bool has_symbol_local(
const std::string &name)
const;
123 Symbol *lookup_local(
const std::string &name)
const;
124 Symbol *declare(SymbolKind sym_kind,
const std::string &name,
const std::shared_ptr<Type> &type);
125 Symbol *define(SymbolKind sym_kind,
const std::string &name,
const std::shared_ptr<Type> &type);
131 typedef std::vector<Symbol *>::const_iterator const_iterator;
132 const_iterator cbegin()
const {
return m_symbols.cbegin(); }
133 const_iterator cend()
const {
return m_symbols.cend(); }
137 Symbol *lookup_recursive(
const std::string &name)
const;
141 void set_fn_type(
const std::shared_ptr<Type> &fn_type);
147 std::shared_ptr<Type> get_fn_type()
const;
150 void set_report(
bool en) { m_report = en; }
151 bool add_fields()
const {
return m_add_fields; }
152 void set_add_fields(
bool en) { m_add_fields = en; }
154 bool is_global_scope()
const {
return m_parent ==
nullptr; }
156 bool is_parameter_scope()
const {
return bool(m_fn_type) && m_fn_type->is_function(); }
159 int get_depth()
const;
162 void add_symbol(
Symbol *sym);