Ejemplo n.º 1
0
/// Returns true if the specified scope or any non-shadowed non-global subscopes contain an exported
/// variable.
static int local_scope_exports(env_node_t *n) {
    if (n == global_env) return 0;

    if (n->exportv) return 1;

    if (n->new_scope) return 0;

    return local_scope_exports(n->next);
}
Ejemplo n.º 2
0
void env_push(bool new_scope) {
    env_node_t *node = new env_node_t;
    node->next = top;
    node->new_scope = new_scope;

    if (new_scope) {
        if (local_scope_exports(top)) mark_changed_exported();
    }
    top = node;
}
Ejemplo n.º 3
0
void env_pop()
{
    if (&top->env != global)
    {
        int i;
        int locale_changed = 0;

        env_node_t *killme = top;

        for (i=0; locale_variable[i]; i++)
        {
            var_table_t::iterator result =  killme->env.find(locale_variable[i]);
            if (result != killme->env.end())
            {
                locale_changed = 1;
                break;
            }
        }

        if (killme->new_scope)
        {
            if (killme->exportv || local_scope_exports(killme->next))
                mark_changed_exported();
        }

        top = top->next;

        var_table_t::iterator iter;
        for (iter = killme->env.begin(); iter != killme->env.end(); ++iter)
        {
            const var_entry_t &entry = iter->second;
            if (entry.exportv)
            {
                mark_changed_exported();
                break;
            }
        }

        delete killme;

        if (locale_changed)
            handle_locale();

    }
    else
    {
        debug(0,
              _(L"Tried to pop empty environment stack."));
        sanity_lose();
    }
}