import java.io.IOException; import java.io.FileReader; import java.util.*; import Dep.Absyn.Module; import Dep.Absyn.Import; public class Modules { /** * Load the given modules and all their dependencies. */ public static Map loadModules(String[] ms) throws IOException { Set toLoad = new HashSet(Arrays.asList(ms)); Map loaded = new HashMap(); while (!toLoad.isEmpty()) { String name = removeOne(toLoad); String file = findModule(name); System.err.println("Loading module " + name + " from " + file); Module m = ParseModule.parse(new FileReader(file)); loaded.put(name, m); for (Import i : m.listimport_) { if (!loaded.containsKey(i.ident_)) toLoad.add(i.ident_); } } return loaded; } private static String findModule(String name) { return name + ".dep"; } private static E removeOne(Iterable xs) { Iterator it = xs.iterator(); E x = it.next(); it.remove(); return x; } }