pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1:   // -*- Pike -*-   //   // Master Control Program for Pike.   //   // This file is part of Pike. For copyright information see COPYRIGHT.   // Pike is distributed under GPL, LGPL and MPL. See the file COPYING   // for more information.   // - // $Id: master.pike.in,v 1.476 2010/07/28 22:58:01 mast Exp $ + // $Id$      #pike __REAL_VERSION__   //#pragma strict_types      //! @appears predef::MasterObject   //!   //! Master control program for Pike.   //!   //! @seealso   //! @[predef::master()], @[predef::replace_master()]
pike.git/lib/master.pike.in:2196:   protected class ZERO_TYPE {};      protected object Unicode;      //! Module node representing a single directory.   //!   //! @seealso   //! @[joinnode]   class dirnode   { +  string name; +     string dirname;    object|void compilation_handler;    constant is_resolv_dirnode = 1;    // objectp() is intentionally not used on the module object, to    // allow a module to deny its own existence with `!.    mixed module;    mapping(string:mixed) cache=([]);    mapping(string:array(string)) file_paths = ([]);      #ifdef __NT__
pike.git/lib/master.pike.in:2249:    {    fname = FIX_CASE(fname);    if (has_suffix(fname, ".pmod")) return 3;    if (has_suffix(fname, ".so")) return 2;    if (has_suffix(fname, ".pike")) return 1;       // FIXME: Warn here?    return 0;    }    -  protected void create(string d, object|void h) +  protected void create(string d, object|void h, void|string name)    { -  resolv_debug ("dirnode(%O,%O) created\n",d,h); +  resolv_debug ("dirnode(%O,%O) created with name %O\n", d, h, name);    dirname=d;    compilation_handler=h; -  +  this_program::name = name;    fc[dirname]=this;    array(string) files = sort(master_get_dir(d)||({}));    if (!sizeof(d)) return;    array(string) bases = map(files, base_from_filename);    files = filter(files, bases);    bases = filter(bases, bases);    resolv_debug("dirnode(%O,%O) got %d files.\n",    d, h, sizeof(bases));    if (!sizeof(files)) return;   
pike.git/lib/master.pike.in:2368:    if (dirnode n = fc[fname]) {    // Avoid duplicate dirnodes for the same dirs. This can    // happen if the master is replaced, e.g. with master_76    // in 7.6/modules/__default.pmod.    resolv_debug("dirnode(%O)->ind(%O) => found subdirectory %O, "    "returning old dirnode\n", dirname, index, fname);    return n;    }    resolv_debug("dirnode(%O)->ind(%O) => found subdirectory %O, "    "creating new dirnode\n", dirname, index, fname); -  return fc[fname] = dirnode(fname, compilation_handler); +  return fc[fname] = dirnode(fname, compilation_handler, +  name && (name == "predef::" ? +  index : name + "." + index));    }    resolv_debug("dirnode(%O)->ind(%O) casting (object)%O\n",    dirname, index, fname);    // FIXME: cast_to_program() and cast_to_object()    // have lots of overhead to guess the proper    // filename. This overhead isn't needed in    // our cases, so we could make do with    // low_findprog() and the caches.    mixed ret;    if (ret = catch {
pike.git/lib/master.pike.in:2566:    _cache_full = 0;    }    }       protected int(0..) _sizeof() {    return sizeof(_values());    }       protected string _sprintf(int as)    { -  return as=='O' && sprintf("master()->dirnode(%O:%O)", -  dirname, module && module); +  return as=='O' && (name || sprintf("master()->dirnode(%O:%O)", +  dirname, module && module));    }   }      //! Module node holding possibly multiple directories,   //! and optionally falling back to another level.   //!   //! @seealso   //! @[dirnode]   class joinnode   {    constant is_resolv_joinnode = 1; -  +  +  string name; +     array(object|mapping) joined_modules;    mapping(string:mixed) cache=([]);       object compilation_handler;       // NOTE: Uses the empty mapping as the default fallback    // for simplified code.    joinnode|mapping(mixed:int(0..0)) fallback_module = ([]);       string _sprintf(int as)    { -  return as=='O' && sprintf("master()->joinnode(%O)",joined_modules); +  if (as != 'O') return 0; +  if (name) { +  if (has_value (name, "|")) +  return "joinnode(" + name + ")"; +  else +  return name; // Let's be brief.    } -  +  else +  return sprintf("master()->joinnode(%O)", joined_modules); +  }       protected void create(array(object|mapping) _joined_modules,    object|void _compilation_handler, -  joinnode|void _fallback_module) +  joinnode|void _fallback_module, +  void|string name)    {    joined_modules = _joined_modules;    compilation_handler = _compilation_handler;    fallback_module = _fallback_module || ([]); -  resolv_debug ("joinnode(%O) created\n", joined_modules); +  +  if (name) +  this_program::name = name; +  else { +  mapping(string:int(1..1)) names = ([]); +  foreach (_joined_modules, object|mapping m) { +  if (objectp (m) && stringp (m->name)) +  names[m->name] = 1;    } -  +  if (sizeof (names)) +  this_program::name = sort (indices (names)) * "|"; +  }    -  +  resolv_debug ("joinnode(%O) created with name %O\n", joined_modules, name); +  } +     void add_path(string path)    {    path = combine_path(getcwd(), path);    dirnode node = fc[path] || -  (fc[path] = dirnode(path, compilation_handler)); +  (fc[path] = dirnode(path, compilation_handler, +  name && !has_value (name, "|") && name));    if (sizeof(joined_modules) &&    joined_modules[0] == node) return;    joined_modules = ({ node }) + (joined_modules - ({ node }));    cache = ([]);    }       void rem_path(string path)    {    path = combine_path(getcwd(), path);    joined_modules = filter(joined_modules,
pike.git/lib/master.pike.in:2655:    joined_modules, index, ret);    return (ret);    }    }    }       if (sizeof(res)) {    DEC_RESOLV_MSG_DEPTH();    resolv_debug("joinnode(%O)->ind(%O) => new joinnode, fallback: %O\n",    joined_modules, index, fallback_module[index]); -  return joinnode(res, compilation_handler, fallback_module[index]); +  return joinnode(res, compilation_handler, fallback_module[index], +  name && !has_value (name, "|") && +  (name == "predef::" ? index : name + "." + index));    }       DEC_RESOLV_MSG_DEPTH();    resolv_debug ("joinnode(%O)->ind(%O) => not found. Trying fallback %O\n",    joined_modules, index, fallback_module);    return fallback_module[index];    }       mixed `[](string index)    {
pike.git/lib/master.pike.in:2807:    string tmp = path[21..];    foreach(pike_module_path, string prefix) {    node->add_path(sizeof(tmp)? combine_path(prefix, tmp) : prefix);    }    } else   #endif /* PIKE_MODULE_RELOC */    node->add_path(path);    return node;   }    - program|object findmodule(string fullname, object|void handler) + program|object findmodule(string fullname, object|void handler, +  void|string name)   {    program|object o;       resolv_debug ("findmodule(%O)\n", fullname);    if(!zero_type(o=fc[fullname]) && o != no_value)    {    if (objectp(o) || programp(o) || o != 0) {    resolv_debug ("findmodule(%O) => found %O (cached)\n", fullname, o);    return o;    }    resolv_debug ("findmodule(%O) => not found (cached)\n", fullname);    return UNDEFINED;    }       if(Stat stat=master_file_stat(fakeroot(fullname)))    {    if(stat->isdir)    {    resolv_debug ("findmodule(%O) => new dirnode\n", fullname); -  return fc[fullname] = dirnode(fullname, handler); +  return fc[fullname] = dirnode(fullname, handler, name);    }   #if constant (load_module)    else if (has_suffix (fullname, ".so")) {    o = fc[fullname] = low_cast_to_object(fullname, "/.", handler);    DEC_RESOLV_MSG_DEPTH();    resolv_debug ("findmodule(%O) => got .so object %O\n", fullname, o);    return o;    }   #endif    }
pike.git/lib/master.pike.in:2917:   }   #endif /* 0 */         multiset no_resolv = (<>);      //! Resolver of symbols not located in the program being compiled.   class CompatResolver   {    //! Join node of the root modules for this resolver. -  joinnode root_module = joinnode(({instantiate_static_modules(predef::_static_modules)})); +  joinnode root_module = +  joinnode(({instantiate_static_modules(predef::_static_modules)}), +  0, 0, "predef::");       //! Lookup from handler module to corresponding root_module.    mapping(object:joinnode) handler_root_modules = ([]);       //! The pike system module path, not including any set by the user.    array(string) system_module_path=({});       //! The complete module search path    array(string) pike_module_path=({});   
pike.git/lib/master.pike.in:3099:    {    foreach(m; string n; mixed v)    if(mappingp(v))    m[n]=joinify(v);    return joinnode(({m}));    };    foreach(joins; string n; mixed v) {    if(mappingp(v))    v = joinify(v);    if(res[n]) -  res[n] = joinnode(({res[n], v})); +  res[n] = joinnode(({res[n], v}), 0, 0, n);    else    res[n] = v;    }    return res;    }       //!    mapping get_default_module()    {    resolv_debug ("%O->get_default_module()\n", this);
pike.git/lib/master.pike.in:3164:    }    }       node = joinnode(({ instantiate_static_modules(static_modules),    // Copy relevant stuff from the root module.    @filter(root_module->joined_modules,    lambda(mixed x) {    return objectp(x) && x->is_resolv_dirnode;    }) }),    current_handler, -  root_module->fallback_module); +  root_module->fallback_module, +  "predef::");       // FIXME: Is this needed?    // Kluge to get _static_modules to work at top level.    node->cache->_static_modules = static_modules;       return node;    }       //!    mixed resolv_base(string identifier, string|void current_file,