21 auto newTable = std::make_unique<SymbolTable>(
fParent, fBuiltin);
28 return symbol && symbol->
is<
Type>();
42 return this->
find(name);
53 bool foundShadow =
false;
55 self->fSymbols.foreach([&](
const SymbolKey&
key,
const Symbol* symbol) {
60 if (other->fSymbols.find(
key) !=
nullptr) {
68Symbol* SymbolTable::lookup(
const SymbolKey&
key)
const {
95 if (fSymbols.removeIfExists(MakeSymbolKey(symbol->
name()))) {
99 if (symbol == owned.get()) {
100 return std::move(owned);
110 if (std::unique_ptr<Symbol> ownedSymbol = this->
removeSymbol(sym)) {
111 otherTable->
add(context, std::move(ownedSymbol));
118 fOwnedStrings.push_front(std::move(str));
120 return &fOwnedStrings.front();
126 "symbol '" + std::string(symbol->
name()) +
"' was already defined");
132 SK_ABORT(
"symbol '%.*s' was already defined",
133 (
int)symbol->
name().size(), symbol->
name().data());
138 if (symbol->
name().empty()) {
143 auto key = MakeSymbolKey(symbol->
name());
146 if (symbol->
is<FunctionDeclaration>()) {
148 Symbol* existingSymbol = this->lookup(
key);
149 if (existingSymbol && existingSymbol->is<FunctionDeclaration>()) {
151 FunctionDeclaration* existingDecl = &existingSymbol->as<FunctionDeclaration>();
152 symbol->
as<FunctionDeclaration>().setNextOverload(existingDecl);
153 fSymbols[
key] = symbol;
165 return symbol ==
nullptr;
169 auto key = MakeSymbolKey(symbol->
name());
170 fSymbols[
key] = symbol;
176 if (arraySize == 0) {
185 std::string arrayName =
type->getArrayName(arraySize);
186 if (
const Symbol* existingType = this->
find(arrayName)) {
187 return &existingType->as<
Type>();
195 std::string_view
name,
197 if (
const Symbol* symbol = this->
find(name)) {
#define SK_ABORT(message,...)
void swap(sk_sp< T > &a, sk_sp< T > &b)
void error(Position position, std::string_view msg)
FunctionDeclaration * mutableNextOverload() const
Position position() const
void addWithoutOwnership(const Context &context, Symbol *symbol)
const Type * addArrayDimension(const Context &context, const Type *type, int arraySize)
bool isType(std::string_view name) const
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)
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)
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()
std::unique_ptr< Symbol > removeSymbol(const Symbol *symbol)
std::string_view name() const
void setName(std::string_view newName)
std::unique_ptr< Expression > instantiate(const Context &context, Position pos) const
static std::unique_ptr< Type > MakeArrayType(const Context &context, std::string_view name, const Type &componentType, int columns)
DEF_SWITCHES_START aot vmservice shared library name