[Nice-commit] Nice/src/bossa/syntax GlobalVarScope.java,NONE,1.1 VarScope.java,1.17,1.18 Node.java,1
Brought to you by:
bonniot
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv16598/src/bossa/syntax Modified Files: VarScope.java Node.java MethodBodyDefinition.java JavaClasses.java Added Files: GlobalVarScope.java Log Message: Lazy loading of Java classes and methods. This avoids loading huge hierarchy recursively, which improves compilation speed and reduces ambiguities. --- NEW FILE: GlobalVarScope.java --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2003 */ /* */ /* 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 bossa.syntax; /** The global scope of symbols. @author Daniel Bonniot (bo...@us...) */ public class GlobalVarScope extends VarScope { GlobalVarScope() { super(null); } /** * The lookup method to call when you need to get a VarSymbol * from its name * * @param i the identifier to lookup * @return the symbols if some were found, null otherwise */ public java.util.List lookup(LocatedString i) { // If there is any method by that name waiting, load it. JavaClasses.nameRequired(i.toString()); return super.lookup(i); } } Index: VarScope.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/VarScope.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** VarScope.java 18 Apr 2003 14:50:20 -0000 1.17 --- VarScope.java 28 Nov 2003 14:01:29 -0000 1.18 *************** *** 22,26 **** @author Daniel Bonniot (d.b...@ma...) */ ! public final class VarScope { public VarScope(VarScope outer) --- 22,26 ---- @author Daniel Bonniot (d.b...@ma...) */ ! public class VarScope { public VarScope(VarScope outer) Index: Node.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Node.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** Node.java 22 Jul 2003 16:55:31 -0000 1.57 --- Node.java 28 Nov 2003 14:01:29 -0000 1.58 *************** *** 182,187 **** */ ! private static VarScope globalScope; ! public static final VarScope getGlobalScope() { return globalScope; --- 182,187 ---- */ ! private static GlobalVarScope globalScope; ! public static final GlobalVarScope getGlobalScope() { return globalScope; *************** *** 201,205 **** { JavaClasses.compilation = module.compilation(); ! globalScope = new VarScope(null); globalTypeScope = new GlobalTypeScope(); } --- 201,205 ---- { JavaClasses.compilation = module.compilation(); ! globalScope = new GlobalVarScope(); globalTypeScope = new GlobalTypeScope(); } Index: MethodBodyDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodBodyDefinition.java,v retrieving revision 1.144 retrieving revision 1.145 diff -C2 -d -r1.144 -r1.145 *** MethodBodyDefinition.java 24 Nov 2003 14:47:50 -0000 1.144 --- MethodBodyDefinition.java 28 Nov 2003 14:01:29 -0000 1.145 *************** *** 126,132 **** Returns the symbol of the method this declaration belongs to. */ ! private VarSymbol findSymbol(VarScope scope) { - List symbols = scope.lookup(name); if(symbols.size() == 0) return null; --- 126,131 ---- Returns the symbol of the method this declaration belongs to. */ ! private VarSymbol findSymbol(List symbols) { if(symbols.size() == 0) return null; *************** *** 290,300 **** Pattern.resolve(typeScope, getGlobalScope(), formals); } ! void lateBuildScope() { Pattern.resolveValues(formals); ! VarSymbol s = findSymbol(scope); if(s==null) --- 289,304 ---- Pattern.resolve(typeScope, getGlobalScope(), formals); + + symbols = scope.lookup(name); } ! ! private List symbols; ! void lateBuildScope() { Pattern.resolveValues(formals); ! VarSymbol s = findSymbol(symbols); ! symbols = null; if(s==null) Index: JavaClasses.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/JavaClasses.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** JavaClasses.java 23 Nov 2003 16:25:17 -0000 1.40 --- JavaClasses.java 28 Nov 2003 14:01:30 -0000 1.41 *************** *** 211,214 **** --- 211,215 ---- { retyped = new HashMap(); + knownMethods = new HashMap(); } *************** *** 358,390 **** continue; ! if (m.isConstructor()) ! { ! JavaMethod res = JavaMethod.make(m, true); ! ! if (res != null) ! { ! TypeConstructors.addConstructor(tc, res); ! retyped.put(m, res); ! } ! else if(Debug.javaTypes) ! Debug.println("Constructor " + m + " ignored"); ! } ! else ! { ! /* We don't need to put static methods in the global scope. ! They can and must be accessed by specifying the class ! explicitely, like in Java. ! */ ! if (m.getStaticFlag()) ! continue; ! ! Method base = baseMethod(classType, m); ! if (base != null) ! continue; ! ! if (Debug.javaTypes) ! Debug.println("Loaded native method " + m); ! addSymbol(m, JavaMethod.make(m, false)); ! } } } --- 359,363 ---- continue; ! fetch(m, tc, classType); } } *************** *** 399,402 **** --- 372,449 ---- " has an invalid bytecode format"); } + } + + private static void fetch(Method m, TypeConstructor tc, ClassType classType) + { + if (m.isConstructor()) + { + JavaMethod res = JavaMethod.make(m, true); + + if (res != null) + { + TypeConstructors.addConstructor(tc, res); + retyped.put(m, res); + } + else if(Debug.javaTypes) + Debug.println("Constructor " + m + " ignored"); + } + else + { + /* We don't need to put static methods in the global scope. + They can and must be accessed by specifying the class + explicitely, like in Java. + */ + if (m.getStaticFlag()) + return; + + Method base = baseMethod(classType, m); + if (base != null) + return; + + registerMethod(m); + } + } + + private static Map knownMethods; + + /** Remember that we know a method of this name, so that we can load it + lazily, if that name is searched. + */ + private static void registerMethod(Method m) + { + List methods = (List) knownMethods.get(m.getName()); + if (methods == null) + { + methods = new ArrayList(); + knownMethods.put(m.getName(), methods); + } + methods.add(m); + } + + /** Called when the given name is going to be needed. */ + static void nameRequired(String name) + { + List methods = (List) knownMethods.get(name); + if (methods == null) + return; + knownMethods.remove(name); + + for (Iterator i = methods.iterator(); i.hasNext();) + { + Method m = (Method) i.next(); + loadMethod(m); + } + } + + /** Actually load the method. */ + private static void loadMethod(Method m) + { + if (Debug.javaTypes) + Debug.println("Loaded native method " + m); + + if (retyped.get(m) != null) + return; + + addSymbol(m, JavaMethod.make(m, false)); } |