8#ifndef SKSL_SYMBOLTABLE
9#define SKSL_SYMBOLTABLE
18#include <forward_list>
38 : fBuiltin(builtin) {}
42 , fBuiltin(builtin) {}
55 return this->lookup(MakeSymbolKey(
name));
68 return this->lookup(MakeSymbolKey(
name));
76 std::string_view
name,
120 template <
typename T>
122 T* ptr = symbol.get();
131 template <
typename T>
133 T* ptr = symbol.get();
148 template <
typename T>
150 T* ptr = symbol.get();
158 template <
typename T>
160 T* ptr = symbol.get();
173 template <
typename Fn>
174 void foreach(Fn&& fn)
const {
176 [&fn](
const SymbolKey&
key,
const Symbol* symbol) { fn(
key.fName, symbol); });
184 return fSymbols.count();
198 fAtModuleBoundary =
true;
207 std::string_view
fName;
210 bool operator==(
const SymbolKey& that)
const {
return fName == that.fName; }
211 bool operator!=(
const SymbolKey& that)
const {
return fName != that.fName; }
217 static SymbolKey MakeSymbolKey(std::string_view
name) {
221 Symbol* lookup(
const SymbolKey&
key)
const;
224 bool fBuiltin =
false;
225 bool fAtModuleBoundary =
false;
226 std::forward_list<std::string> fOwnedStrings;
void addWithoutOwnership(const Context &context, Symbol *symbol)
T * inject(std::unique_ptr< T > symbol)
const Type * addArrayDimension(const Context &context, const Type *type, int arraySize)
bool isType(std::string_view name) const
T * addOrDie(std::unique_ptr< T > symbol)
void renameSymbol(const Context &context, Symbol *symbol, std::string_view newName)
bool isBuiltinType(std::string_view name) const
const Symbol * find(std::string_view name) const
bool wouldShadowSymbolsFrom(const SymbolTable *other) const
void injectWithoutOwnership(Symbol *symbol)
SymbolTable(SymbolTable *parent, bool builtin)
std::vector< std::unique_ptr< Symbol > > fOwnedSymbols
const std::string * takeOwnershipOfString(std::string n)
void addWithoutOwnershipOrDie(Symbol *symbol)
std::unique_ptr< Expression > instantiateSymbolRef(const Context &context, std::string_view name, Position pos)
SymbolTable(bool builtin)
T * takeOwnershipOfSymbol(std::unique_ptr< T > symbol)
const Symbol * findBuiltinSymbol(std::string_view name) const
T * add(const Context &context, std::unique_ptr< T > symbol)
void moveSymbolTo(SymbolTable *otherTable, Symbol *sym, const Context &context)
std::unique_ptr< SymbolTable > insertNewParent()
Symbol * findMutable(std::string_view name) const
void markModuleBoundary()
std::unique_ptr< Symbol > removeSymbol(const Symbol *symbol)
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
DEF_SWITCHES_START aot vmservice shared library name
bool operator==(C p1, const scoped_nsprotocol< C > &p2)
bool operator!=(C p1, const scoped_nsprotocol< C > &p2)
uint32_t operator()(const SymbolKey &key) const