Nice/src/nice/tools/visibility nested.nice,NONE,1.1 impl.nice,1.4,1.5

Daniel Bonniot <[email protected]> Sat, 12 Mar 2005 09:59:06 +0000
Newsgroups gmane.comp.lang.nice.cvs
Message-ID <[email protected]>
Update of /cvsroot/nice/Nice/src/nice/tools/visibility
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2623/src/nice/tools/visibility

Modified Files:
	impl.nice 
Added Files:
	nested.nice 
Log Message:
Moved nested lookup to a separate file.

Made public symbols of the current scope visible in nested mode (although
they are shadowed by private ones, probably not what we want).


--- NEW FILE: nested.nice ---
/**************************************************************************/
/*                                N I C E                                 */
/*             A high-level object-oriented research language             */
/*                        (c) Daniel Bonniot 2005                         */
/*                                                                        */
/*  This program is free software; you can redistribute it and/or modify  */
/*  it under the terms of the GNU General Public License as published by  */
/*  the Free Software Foundation; either version 2 of the License, or     */
/*  (at your option) any later version.                                   */
/*                                                                        */
/**************************************************************************/

package nice.tools.visibility;

/**
   Nested lookup mode.

   In this mode, symbols in the current scope shadow symbols with the same
   name in imported scopes.

   @author Daniel Bonniot ([email protected])
 */

<Sym> get(Scope this, root, key) = this.getScope(root).maybeGet(key) || empty;

<Sym> get(Scope this, key) = this.maybeGet(key) || empty;

private <Sym> ?List<Sym> maybeGet(?Scope<Sym> s, String key) =
  s == null ? null : (s.map[key] || s.publicMap[key] || s.opens[key] || s.parent.maybeGet(key));

<Sym> ?List<Sym> get(List<Scope<Sym>> scopes, String key)
{
  ?List<Sym> res = null;

  for (Scope<Sym> scope : scopes)
    {
      let partial = scope.publicMap[key];
      if (partial != null)
	{
	  if (res == null)
	    res = new LinkedList();
	  notNull(res).addAll(partial);
	}
    }

  return res;
}

private <Sym> ?Scope<Sym> getScope(Scope<Sym> this, String root)
{
  if (this.name.equals(root))
    return this;

  if (parent != null)
    {
      let res = notNull(parent).getScope(root);
      if (res != null)
	return res;
    }

  ?Scope<Sym> s = opens.search(Scope<Sym> s => s.name.equals(root));
  return s;
}

Index: impl.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/nice/tools/visibility/impl.nice,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** impl.nice	12 Mar 2005 02:41:45 -0000	1.4
--- impl.nice	12 Mar 2005 09:59:03 -0000	1.5
***************
*** 19,25 ****
   */
  
- private <Sym> ?List<Sym> maybeGet(?Scope<Sym> s, String key) =
-   s == null ? null : (s.map[key] || s.opens[key] || s.parent.maybeGet(key));
- 
  add(Scope this, key, value, visibility) = map.add(key, value);
  add(Scope this, key, value, familial)
--- 19,22 ----
***************
*** 50,89 ****
  
  addImplicitOpen(Scope this, Scope scope) = opens.add(scope);
- 
- <Sym> get(Scope this, root, key) = this.getScope(root).maybeGet(key) || empty;
- 
- <Sym> get(Scope this, key) = this.maybeGet(key) || empty;
- 
- <Sym> ?List<Sym> get(List<Scope<Sym>> scopes, String key)
- {
-   ?List<Sym> res = null;
- 
-   for (Scope<Sym> scope : scopes)
-     {
-       let partial = scope.publicMap[key];
-       if (partial != null)
- 	{
- 	  if (res == null)
- 	    res = new LinkedList();
- 	  notNull(res).addAll(partial);
- 	}
-     }
- 
-   return res;
- }
- 
- private <Sym> ?Scope<Sym> getScope(Scope<Sym> this, String root)
- {
-   if (this.name.equals(root))
-     return this;
- 
-   if (parent != null)
-     {
-       let res = notNull(parent).getScope(root);
-       if (res != null)
- 	return res;
-     }
- 
-   ?Scope<Sym> s = opens.search(Scope<Sym> s => s.name.equals(root));
-   return s;
- }
--- 47,48 ----



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click