// get binding for adding a method // like jl_get_binding_wr, but uses existing imports instead of warning // and overwriting. JL_DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_t *var) { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var); jl_binding_t *b = *bp; if (b != HT_NOTFOUND) { if (b->owner != m && b->owner != NULL) { jl_binding_t *b2 = jl_get_binding(b->owner, var); if (b2 == NULL) jl_errorf("invalid method definition: imported function %s.%s does not exist", jl_symbol_name(b->owner->name), jl_symbol_name(var)); // TODO: we might want to require explicitly importing types to add constructors if (!b->imported && (b2->value == NULL || !jl_is_type(b2->value))) { jl_errorf("error in method definition: function %s.%s must be explicitly imported to be extended", jl_symbol_name(b->owner->name), jl_symbol_name(var)); } return b2; } b->owner = m; return b; } b = new_binding(var); b->owner = m; *bp = b; jl_gc_wb_buf(m, b, sizeof(jl_binding_t)); return *bp; }
// get binding for assignment DLLEXPORT jl_binding_t *jl_get_binding_wr(jl_module_t *m, jl_sym_t *var) { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var); jl_binding_t *b; if (*bp != HT_NOTFOUND) { if ((*bp)->owner == NULL) { (*bp)->owner = m; return *bp; } else if ((*bp)->owner != m) { // TODO: change this to an error soon jl_printf(JL_STDERR, "Warning: imported binding for %s overwritten in module %s\n", var->name, m->name->name); } else { return *bp; } } b = new_binding(var); b->owner = m; *bp = b; jl_gc_wb_buf(m, b); return *bp; }
// get binding for adding a method // like jl_get_binding_wr, but uses existing imports instead of warning // and overwriting. DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_t *var) { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var); jl_binding_t *b = *bp; if (b != HT_NOTFOUND) { if (b->owner != m && b->owner != NULL) { jl_binding_t *b2 = jl_get_binding(b->owner, var); if (b2 == NULL) jl_errorf("invalid method definition: imported function %s.%s does not exist", b->owner->name->name, var->name); if (!b->imported && (b2->value==NULL || jl_is_function(b2->value))) { if (b2->value && !jl_is_gf(b2->value)) { jl_errorf("error in method definition: %s.%s cannot be extended", b->owner->name->name, var->name); } else { jl_errorf("error in method definition: function %s.%s must be explicitly imported to be extended", b->owner->name->name, var->name); } } return b2; } b->owner = m; return b; } b = new_binding(var); b->owner = m; *bp = b; jl_gc_wb_buf(m, b); return *bp; }
// NOTE: we use explici since explicit is a C++ keyword static void module_import_(jl_module_t *to, jl_module_t *from, jl_sym_t *s, int explici) { if (to == from) return; jl_binding_t *b = jl_get_binding(from, s); if (b == NULL) { jl_printf(JL_STDERR, "Warning: could not import %s.%s into %s\n", from->name->name, s->name, to->name->name); } else { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&to->bindings, s); jl_binding_t *bto = *bp; if (bto != HT_NOTFOUND) { if (bto == b) { // importing a binding on top of itself. harmless. } else if (bto->owner == b->owner) { // already imported bto->imported = (explici!=0); } else if (bto->owner != to && bto->owner != NULL) { // already imported from somewhere else jl_binding_t *bval = jl_get_binding(to, s); if (bval->constp && bval->value && b->constp && b->value == bval->value) { // equivalent binding bto->imported = (explici!=0); return; } jl_printf(JL_STDERR, "Warning: ignoring conflicting import of %s.%s into %s\n", from->name->name, s->name, to->name->name); } else if (bto->constp || bto->value) { // conflict with name owned by destination module assert(bto->owner == to); if (bto->constp && bto->value && b->constp && b->value == bto->value) { // equivalent binding return; } jl_printf(JL_STDERR, "Warning: import of %s.%s into %s conflicts with an existing identifier; ignored.\n", from->name->name, s->name, to->name->name); } else { bto->owner = b->owner; bto->imported = (explici!=0); } } else { jl_binding_t *nb = new_binding(s); nb->owner = b->owner; nb->imported = (explici!=0); *bp = nb; jl_gc_wb_buf(to, nb); } } }
// get binding for adding a method // like jl_get_binding_wr, but uses existing imports instead of warning // and overwriting. JL_DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_t *var) { if (jl_base_module && m->std_imports && !jl_binding_resolved_p(m,var)) { jl_module_t *opmod = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("Operators")); if (opmod != NULL && jl_defines_or_exports_p(opmod, var)) { jl_printf(JL_STDERR, "WARNING: module %s should explicitly import %s from %s\n", jl_symbol_name(m->name), jl_symbol_name(var), jl_symbol_name(jl_base_module->name)); jl_module_import(m, opmod, var); } } jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var); jl_binding_t *b = *bp; if (b != HT_NOTFOUND) { if (b->owner != m && b->owner != NULL) { jl_binding_t *b2 = jl_get_binding(b->owner, var); if (b2 == NULL) jl_errorf("invalid method definition: imported function %s.%s does not exist", jl_symbol_name(b->owner->name), jl_symbol_name(var)); if (!b->imported && (b2->value==NULL || jl_is_function(b2->value))) { if (b2->value && !jl_is_gf(b2->value)) { jl_errorf("error in method definition: %s.%s cannot be extended", jl_symbol_name(b->owner->name), jl_symbol_name(var)); } else { if (jl_base_module && m->std_imports && b->owner == jl_base_module) { jl_module_t *opmod = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("Operators")); if (opmod != NULL && jl_defines_or_exports_p(opmod, var)) { jl_printf(JL_STDERR, "WARNING: module %s should explicitly import %s from %s\n", jl_symbol_name(m->name), jl_symbol_name(var), jl_symbol_name(b->owner->name)); return b2; } } jl_errorf("error in method definition: function %s.%s must be explicitly imported to be extended", jl_symbol_name(b->owner->name), jl_symbol_name(var)); } } return b2; } b->owner = m; return b; } b = new_binding(var); b->owner = m; *bp = b; jl_gc_wb_buf(m, b); return *bp; }
void jl_module_export(jl_module_t *from, jl_sym_t *s) { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&from->bindings, s); if (*bp == HT_NOTFOUND) { jl_binding_t *b = new_binding(s); // don't yet know who the owner is b->owner = NULL; *bp = b; } assert(*bp != HT_NOTFOUND); (*bp)->exportp = 1; }
void LayoutParser::parseBinding(const TagBindingContainerPtr &binding_container) { static const QStringList actionValues(QString::fromLatin1( "insert,shift,backspace,space,cycle,layout_menu,sym,return,commit," "decimal_separator,plus_minus_toggle,switch,on_off_toggle,compose," "left,up,right,down,close,tab,dead,left-layout,right-layout,command" ).split(',')); Q_ASSERT(actionValues.count() == Key::NumActions); const QXmlStreamAttributes attributes(m_xml.attributes()); const TagBinding::Action action(enumValue("action", actionValues, TagBinding::Insert)); const QString label(attributes.value(QLatin1String("label")).toString()); const QString secondary_label(attributes.value(QLatin1String("secondary_label")).toString()); const QString accents(attributes.value(QLatin1String("accents")).toString()); const QString accented_labels(attributes.value(QLatin1String("accented_labels")).toString()); const QString cycleset(attributes.value(QLatin1String("cycleset")).toString()); const QString sequence(attributes.value(QLatin1String("sequence")).toString()); const QString icon(attributes.value(QLatin1String("icon")).toString()); const bool dead(boolValue(attributes.value(QLatin1String("dead")), false)); const bool quick_pick(boolValue(attributes.value(QLatin1String("quick_pick")), false)); const bool rtl(boolValue(attributes.value(QLatin1String("rtl")), false)); const bool enlarge(boolValue(attributes.value(QLatin1String("enlarge")), false)); TagBindingPtr new_binding(new TagBinding(action, label, secondary_label, accents, accented_labels, cycleset, sequence, icon, dead, quick_pick, rtl, enlarge)); binding_container->setBinding(new_binding); while (m_xml.readNextStartElement()) { const QStringRef name(m_xml.name()); if (name == QLatin1String("modifiers")) { parseModifiers(new_binding); } else { error(QString::fromLatin1("Expected '<modifiers>', but got '<%1>'.").arg(name.toString())); } } }
// get binding for adding a method // like jl_get_binding_wr, but uses existing imports instead of warning // and overwriting. jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_t *var) { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var); jl_binding_t *b = *bp; if (b != HT_NOTFOUND) { if (b->owner != m && b->owner != NULL) { jl_binding_t *b2 = jl_get_binding(b->owner, var); if (b2 == NULL) jl_errorf("invalid method definition: imported function %s.%s does not exist", b->owner->name->name, var->name); if (!b->imported) jl_errorf("error in method definition: function %s.%s must be explicitly imported to be extended", b->owner->name->name, var->name); return b2; } b->owner = m; return b; } b = new_binding(var); b->owner = m; *bp = b; return *bp; }
// get binding for assignment JL_DLLEXPORT jl_binding_t *jl_get_binding_wr(jl_module_t *m, jl_sym_t *var, int error) { jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var); jl_binding_t *b = *bp; if (b != HT_NOTFOUND) { if (b->owner != m) { if (b->owner == NULL) { b->owner = m; } else if (error) { jl_errorf("cannot assign variable %s.%s from module %s", jl_symbol_name(b->owner->name), jl_symbol_name(var), jl_symbol_name(m->name)); } } return *bp; } b = new_binding(var); b->owner = m; *bp = b; jl_gc_wb_buf(m, b, sizeof(jl_binding_t)); return *bp; }