示例#1
0
// get binding for reading. might return NULL for unbound.
static jl_binding_t *jl_get_binding_(jl_module_t *m, jl_sym_t *var, modstack_t *st)
{
    modstack_t top = { m, st };
    modstack_t *tmp = st;
    while (tmp != NULL) {
        if (tmp->m == m) {
            // import cycle without finding actual location
            return NULL;
        }
        tmp = tmp->prev;
    }
    jl_binding_t *b = (jl_binding_t*)ptrhash_get(&m->bindings, var);
    if (b == HT_NOTFOUND || b->owner == NULL) {
        for(int i=(int)m->usings.len-1; i >= 0; --i) {
            jl_module_t *imp = (jl_module_t*)m->usings.items[i];
            b = (jl_binding_t*)ptrhash_get(&imp->bindings, var);
            if (b != HT_NOTFOUND && b->exportp) {
                b = jl_get_binding_(imp, var, &top);
                if (b == NULL || b->owner == NULL)
                    return NULL;
                // do a full import to prevent the result of this lookup
                // from changing, for example if this var is assigned to
                // later.
                module_import_(m, b->owner, var, 0);
                return b;
            }
        }
        return NULL;
    }
    if (b->owner != m)
        return jl_get_binding_(b->owner, var, &top);
    return b;
}
示例#2
0
文件: module.c 项目: leloulight/julia
// get binding for reading. might return NULL for unbound.
static jl_binding_t *jl_get_binding_(jl_module_t *m, jl_sym_t *var, modstack_t *st)
{
    modstack_t top = { m, st };
    modstack_t *tmp = st;
    while (tmp != NULL) {
        if (tmp->m == m) {
            // import cycle without finding actual location
            return NULL;
        }
        tmp = tmp->prev;
    }
    jl_binding_t *b = (jl_binding_t*)ptrhash_get(&m->bindings, var);
    if (b == HT_NOTFOUND || b->owner == NULL) {
        jl_module_t *owner = NULL;
        for(int i=(int)m->usings.len-1; i >= 0; --i) {
            jl_module_t *imp = (jl_module_t*)m->usings.items[i];
            jl_binding_t *tempb = (jl_binding_t*)ptrhash_get(&imp->bindings, var);
            if (tempb != HT_NOTFOUND && tempb->exportp) {
                tempb = jl_get_binding_(imp, var, &top);
                if (tempb == NULL || tempb->owner == NULL)
                    // couldn't resolve; try next using (see issue #6105)
                    continue;
                if (owner != NULL && tempb->owner != b->owner &&
                    !(tempb->constp && tempb->value && b->constp && b->value == tempb->value)) {
                    jl_printf(JL_STDERR,
                              "WARNING: both %s and %s export \"%s\"; uses of it in module %s must be qualified\n",
                              jl_symbol_name(owner->name),
                              jl_symbol_name(imp->name), jl_symbol_name(var),
                              jl_symbol_name(m->name));
                    // mark this binding resolved, to avoid repeating the warning
                    (void)jl_get_binding_wr(m, var);
                    return NULL;
                }
                owner = imp;
                b = tempb;
            }
        }
        if (owner != NULL) {
            // do a full import to prevent the result of this lookup
            // from changing, for example if this var is assigned to
            // later.
            module_import_(m, b->owner, var, 0);
            return b;
        }
        return NULL;
    }
    if (b->owner != m)
        return jl_get_binding_(b->owner, var, &top);
    return b;
}
示例#3
0
文件: module.c 项目: Wilfred/julia
DLLEXPORT jl_binding_t *jl_get_binding_or_error(jl_module_t *m, jl_sym_t *var)
{
    jl_binding_t *b = jl_get_binding_(m, var, NULL);
    if (b == NULL)
        jl_undefined_var_error(var);
    return b;
}
示例#4
0
文件: module.c 项目: leloulight/julia
JL_DLLEXPORT jl_binding_t *jl_get_binding_or_error(jl_module_t *m, jl_sym_t *var)
{
    jl_binding_t *b = jl_get_binding_(m, var, NULL);
    if (b == NULL)
        jl_undefined_var_error(var);
    if (b->deprecated)
        jl_binding_deprecation_warning(b);
    return b;
}
示例#5
0
文件: module.c 项目: Wilfred/julia
DLLEXPORT jl_binding_t *jl_get_binding(jl_module_t *m, jl_sym_t *var)
{
    return jl_get_binding_(m, var, NULL);
}