Nice/src/bossa/syntax tools.nice,1.109,1.110 retypedMethod.nice,1.11,1.12 new.nice,1.11,1.12 methodbody.nice,1.16,1.17 methodDeclaration.nice,1.8,1.9 javaMethod.nice,1.12,1.13 javaFieldAccess.nice,1.8,1.9 ident.nice,1.3,1.4 alternative.nice,1.12,1.13

Daniel Bonniot <[email protected]> Fri, 01 Apr 2005 00:09:26 +0000
Newsgroups gmane.comp.lang.nice.cvs
Message-ID <[email protected]>
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21519/src/bossa/syntax

Modified Files:
	tools.nice retypedMethod.nice new.nice methodbody.nice 
	methodDeclaration.nice javaMethod.nice javaFieldAccess.nice 
	ident.nice alternative.nice 
Log Message:
Lazily load only those retypings that might be used in the program, based on
the set of identifiers used in the program.


Index: methodDeclaration.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodDeclaration.nice,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** methodDeclaration.nice	30 Mar 2005 11:43:02 -0000	1.8
--- methodDeclaration.nice	1 Apr 2005 00:09:23 -0000	1.9
***************
*** 244,247 ****
--- 244,249 ----
    }
  
+   boolean hasFullName(String name) = this.getFullName().equals(name);
+ 
    public boolean specializesMethods()
    {
***************
*** 317,321 ****
  }
  
! let char methodListSeparator = ';';
  
  /** Whether typechecking is currently happening in the global context */
--- 319,323 ----
  }
  
! let char methodListSeparator = '\n';
  
  /** Whether typechecking is currently happening in the global context */

Index: retypedMethod.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/retypedMethod.nice,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** retypedMethod.nice	30 Mar 2005 08:02:08 -0000	1.11
--- retypedMethod.nice	1 Apr 2005 00:09:23 -0000	1.12
***************
*** 31,35 ****
      // We put this here, since we need 'module' to be computed
      // since it is used to open the imported packages.
!     this.findReflectMethod();
  
      super;
--- 31,78 ----
      // We put this here, since we need 'module' to be computed
      // since it is used to open the imported packages.
!     if (this.needed())
!       this.findReflectMethod();
! 
!     super;
!   }
! 
!   private boolean needed()
!   {
!     // We only load the method eagerly if the retyping is being compiled
!     // from source.
!     // Otherwise, we do it lazily if the method name is actually used in the
!     // program.
!     if (! this.inInterfaceFile()
! 	// The nice name can differ from the original one, and both can be used
! 	// to refer to this method
! 	|| usedIdentifiers.contains(methodName)
! 	|| usedIdentifiers.contains(this.getName().toString()))
!       return true;
! 
!     if (methodName.equals("<init>"))
!       {
! 	// Since the package is compiled, we know className is qualified.
! 
! 	let shortName = unqualifyName(className.toString());
! 
! 	if (usedIdentifiers.contains(className.toString())
! 	    || usedIdentifiers.contains(shortName))
! 	  return true;
!       }
! 
!     return false;
!   }
! 
!   doResolve()
!   {
!     if (ignoredRetyping)
!       return;
! 
!     if (reflectMethod == null)
!       // lazy loading, we are not needed
!       {
! 	this.setIgnoredRetyping(this, "This method is not used");
! 	return;
!       }
  
      super;
***************
*** 46,49 ****
--- 89,94 ----
    isIgnored() = ignoredRetyping;
  
+   hasFullName(String name) = ! ignoredRetyping && super;
+ 
    private ?gnu.bytecode.Type type(LocatedString s)
    {
***************
*** 131,134 ****
--- 176,182 ----
        }
  
+     if (bossa.util.Debug.javaTypes)
+       bossa.util.Debug.println("Loaded retyped method " + this);
+ 
      // use the following, or the Type.flushTypeChanges() in SpecialTypes
      //reflectMethod.arg_types = javaArgType;
***************
*** 224,227 ****
--- 272,284 ----
      return res + ")";
    }
+ 
+   toString()
+   {
+     // For debugging only
+     if (this.getType() == null)
+       return "retyped method "className"."methodName;
+     else
+       return super;
+   }
  }
  

Index: javaMethod.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/javaMethod.nice,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** javaMethod.nice	30 Mar 2005 12:42:34 -0000	1.12
--- javaMethod.nice	1 Apr 2005 00:09:23 -0000	1.13
***************
*** 34,38 ****
    getFullName()
    {
!     return "JAVA:" + name + ':' + this.getType();
    }
  
--- 34,40 ----
    getFullName()
    {
!     return "JAVA:" + name + ':' +
!       this.getReflectMethod().getDeclaringClass().getName() + '.' +
!       this.getReflectMethod().getSignature();
    }
  
***************
*** 115,118 ****
--- 117,126 ----
  void registerMethod(gnu.bytecode.Method m)
  {
+   if (usedIdentifiers.contains(m.getName()))
+     {
+       addJavaSymbol(m, makeJavaMethod(m, false));
+       return;
+     }
+ 
    ?List<gnu.bytecode.Method> methods = knownMethods.get(m.getName());
    if (methods == null)
***************
*** 122,125 ****
--- 130,140 ----
  }
  
+ let HashSet<String> usedIdentifiers = new HashSet();
+ 
+ void registerUsedIdentifier(String ident)
+ {
+   usedIdentifiers.add(ident);
+ }
+ 
  /** Utility function for analyse.nice */
  
***************
*** 339,342 ****
--- 354,358 ----
    retyped.clear();
    knownMethods.clear();
+   usedIdentifiers.clear();
    javaObjectConstructor = null;
  }

Index: tools.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v
retrieving revision 1.109
retrieving revision 1.110
diff -C2 -d -r1.109 -r1.110
*** tools.nice	26 Mar 2005 00:48:09 -0000	1.109
--- tools.nice	1 Apr 2005 00:09:22 -0000	1.110
***************
*** 156,159 ****
--- 156,168 ----
    printStackTraceWithSourceInfo(t);
  
+ String unqualifyName(String qualified)
+ {
+   int end = qualified.lastIndexOf('.');
+   if (end == -1)
+     return qualified;
+   else
+     return qualified.substring(end + 1);
+ }
+ 
  /****************************************************************
   * Temporary: this should be solved when AST classes are written 

Index: new.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/new.nice,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** new.nice	17 Jan 2005 18:26:18 -0000	1.11
--- new.nice	1 Apr 2005 00:09:23 -0000	1.12
***************
*** 23,26 ****
--- 23,31 ----
    private final TypeIdent ti;
  
+     {
+       // Used to decide which constructor retypings need to be loaded.
+       registerUsedIdentifier(ti.getName().toString());
+     }
+ 
    /** Can be null if the class instantiated is Object. */
    ?mlsub.typing.TypeConstructor tc = null;

Index: alternative.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/alternative.nice,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** alternative.nice	25 Mar 2005 16:39:59 -0000	1.12
--- alternative.nice	1 Apr 2005 00:09:23 -0000	1.13
***************
*** 445,449 ****
  
        MethodDeclaration md = notNull(sym.getMethodDeclaration());
!       if (md.getFullName().equals(fullName))
          {
            cast(md).registerForDispatch();
--- 445,449 ----
  
        MethodDeclaration md = notNull(sym.getMethodDeclaration());
!       if (md.hasFullName(fullName))
          {
            cast(md).registerForDispatch();

Index: javaFieldAccess.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/javaFieldAccess.nice,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** javaFieldAccess.nice	25 Mar 2005 16:40:00 -0000	1.8
--- javaFieldAccess.nice	1 Apr 2005 00:09:23 -0000	1.9
***************
*** 39,42 ****
--- 39,46 ----
      super;
  
+     if (this.inInterfaceFile() &&
+ 	! usedIdentifiers.contains(this.getName().toString()))
+       return;
+ 
      // We put this here, since we need 'module' to be computed
      // since it is used to open the imported packages.
***************
*** 141,144 ****
--- 145,151 ----
  ?MethodDeclaration makeJavaFieldAccess(gnu.bytecode.Field f)
  {
+   if (! usedIdentifiers.contains(f.getName()))
+     return null;
+ 
    try {
      mlsub.typing.Monotype[?] params;

Index: ident.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ident.nice,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ident.nice	14 Jan 2005 16:41:27 -0000	1.3
--- ident.nice	1 Apr 2005 00:09:23 -0000	1.4
***************
*** 23,26 ****
--- 23,30 ----
    final LocatedString ident;
  
+     {
+       registerUsedIdentifier(ident.toString());
+     }
+ 
    private boolean infix = false;
    /** Resolve to a ClassExp or a PackageExp if ident is not known. */

Index: methodbody.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodbody.nice,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** methodbody.nice	25 Mar 2005 16:40:00 -0000	1.16
--- methodbody.nice	1 Apr 2005 00:09:23 -0000	1.17
***************
*** 21,24 ****
--- 21,28 ----
  public class MethodBodyDefinition extends MethodImplementation
  {
+     {
+       registerUsedIdentifier(name.toString());
+     }
+ 
    ?Collection<LocatedString> binders; // Null if type parameters are not bound
  



-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/Info/Sentarus/hamr30