//
// Created by pgess on 3/15/15.
//

#include "attachments.h"
#include "ast.h"

void xreate::SymbolAttachments::put(xreate::Symbol const &symbol, unsigned int key, void *data) {
    symbol.scope->attachments.__data[key].emplace(symbol.identifier, data);
}

void *xreate::SymbolAttachments::get(xreate::Symbol const &symbol, unsigned int key, void *def) {
    if (symbol.scope->attachments.__data[key].count(symbol.identifier))
        return symbol.scope->attachments.__data[key].at(symbol.identifier);

    return def;
}

bool
xreate::SymbolAttachments::exists(const Symbol& symbol, unsigned int key)
{
    return symbol.scope->attachments.__data.count(key) && symbol.scope->attachments.__data.at(key).count(symbol.identifier);
}
