Branch: Tag:

2018-02-06

2018-02-06 19:59:55 by Martin Nilsson <nilsson@fastmail.com>

Small refactoring of dirnode/joinnode check

1235:    return 0;   }    + protected bool is_joinnode(mixed o) + { +  return objectp(o) && object_program(o)->is_resolv_joinnode; + } +  + protected bool is_dirnode(mixed o) + { +  return objectp(o) && object_program(o)->is_resolv_dirnode; + } +    //! Find the files in which @[mod] is defined, as they may be hidden away in   //! joinnodes and dirnodes   //!
1251:    return ({ Builtin.program_defined([program]mod) });       array mods; -  if (objectp(mod) && object_program(mod)->is_resolv_joinnode) +  if (is_joinnode(mod))    mods = mod->joined_modules;    else    mods = ({ mod });       foreach (mods;; object mod)    { -  if (objectp(mod) && object_program(mod)->is_resolv_dirnode) +  if (is_dirnode(mod))    files += ({ Builtin.program_defined(object_program(mod->module)) });    else    files += ({ Builtin.program_defined(object_program(mod)) });
1295:    }    if (objectp(obj))    { -  if (object_program(obj)->is_resolv_joinnode) +  if (is_joinnode(obj))    obj = obj->joined_modules[0]; // FIXME: check for multiples -  if (object_program(obj)->is_resolv_dirnode) +  if (is_dirnode(obj))    prog = object_program(obj->module);    else    prog = object_program(obj);
1565:    mixed n = has_value (name, '.') ?    resolv ((name / ".")[..<1] * ".") :    get_root_module(); -  if (objectp (n) && (object_program(n)->is_resolv_dirnode || -  object_program(n)->is_resolv_joinnode)) +  if (is_dirnode(n) || is_joinnode(n))    n->delete_value (p);       fname = dirname (fname);    if ( fname!="" && objectp (n = fc[fname]) ) -  if (object_program(n)->is_resolv_dirnode) // Won't find joinnodes in fc. +  if (is_dirnode(n)) // Won't find joinnodes in fc.    n->delete_value (p);    }   
2428:    path = combine_path(getcwd(), path);    joined_modules = filter(joined_modules,    lambda(dirnode node) { -  return !objectp(node) || -  !object_program(node)->is_resolv_dirnode || +  return !is_dirnode(node) ||    (node->dirname != path);    });    cache = ([]);
2446:    mixed ret;    if (!undefinedp(ret = o[index]))    { -  if (objectp(ret) && -  (object_program(ret)->is_resolv_dirnode || -  object_program(ret)->is_resolv_joinnode)) +  if (is_dirnode(ret) || is_joinnode(ret))    {    // Only join directorynodes (or joinnodes).    res += ({ ret });
2574:    joined_modules = joined_modules[..i - 1] + joined_modules[i + 1..];    i--;    } -  else if (objectp (o) && (object_program(o)->is_resolv_dirnode || -  object_program(o)->is_resolv_joinnode)) +  else if (is_dirnode(o) || is_joinnode(o))    o->delete_value (val);    else if (string name = mappingp (o) && search (o, val))    m_delete (o, name);
2587:    // NB: Index the program instead of the object to avoid issues    // with modules overloading lfun::`->() with stuff that has    // side-effects (here's looking at you Calendar.Events). -  return objectp (other) && -  (object_program(other)->is_resolv_joinnode == 1) && +  return is_joinnode(other) &&    equal (mkmultiset (joined_modules), mkmultiset (other->joined_modules));    }   
3060:    instantiate_static_modules(static_modules),    // Copy relevant stuff from the root module.    @filter(root_module->joined_modules, -  lambda(mixed x) { -  return objectp(x) && -  object_program(x)->is_resolv_dirnode; -  }) }), +  is_dirnode) +  }),    current_handler,    root_module->fallback_module,    "predef::");
5007:    break compare;    }    -  if ((object_program(resolved)->is_resolv_joinnode) && +  if (is_joinnode(resolved) &&    (sizeof(resolved->joined_modules) == 1)) {    ENC_MSG(" compare_resolved: %O is a single element joinnode.\n",    resolved);    resolved = resolved->joined_modules[0];    } -  if (object_program(resolved)->is_resolv_dirnode) { +  if (is_dirnode(resolved)) {    if (resolved->module == what) {    ENC_MSG (" compare_resolved: %O is dirnode module of %O\n", what, resolved);    append = ({'m'});
5033:   #if 0    // This is only safe if the joinnode modules don't conflict,    // and we don't know that. -  if (object_program(resolved)->is_resolv_joinnode) { +  if (is_joinnode(resolved)) {    ENC_MSG (" compare_resolved: searching for %O in joinnode %O\n",    what, resolved);    foreach (resolved->joined_modules, mixed part)
5087:       if (objectp (what)) {    -  if (object_program(what)->is_resolv_dirnode) { +  if (is_dirnode(what)) {    ENC_MSG (" is a dirnode\n");    string name = program_path_to_name (what->dirname);    if (string|array ref = compare_resolved (name, what, resolv (name),
5095:    ENC_RETURN (ref);    }    -  else if (object_program(what)->is_resolv_joinnode) { +  else if (is_joinnode(what)) {    ENC_MSG (" is a joinnode\n");    object modules = Builtin.array_iterator (what->joined_modules);    object|mapping value;    check_dirnode: -  if (modules && objectp (value = modules->value()) && -  object_program(value)->is_resolv_dirnode) { +  if (modules && (value = modules->value()) && is_dirnode(value)) {    string name = program_path_to_name (value->dirname);    modules += 1;    foreach (modules;; value) -  if (!objectp (value) || !object_program(value)->is_resolv_dirnode || +  if (!is_dirnode(value) ||    program_path_to_name (value->dirname) != name)    break check_dirnode;    ENC_MSG (" joinnode has consistent name %O\n", name);
5425:    }    else switch (op) {    case 'm': -  if (objectp (subres) && -  object_program([object]subres)->is_resolv_joinnode) { +  if (is_joinnode(subres)) {    dirnode found;    foreach (([object(joinnode)]subres)->joined_modules,    object|mapping part) -  if (objectp (part) && -  object_program(part)->is_resolv_dirnode && part->module) { +  if (is_dirnode(part) && part->module) {    if (found)    error ("There are ambiguous module objects in %O.\n",    subres);
5441:    if (found) subres = found;    }    -  if (objectp (subres) && -  object_program([object]subres)->is_resolv_dirnode) { +  if (is_dirnode(subres)) {    if (([object]subres)->module) {    subres = ([object]subres)->module;    DEC_MSG (" got dirnode module %O\n", subres);