From 76506bbb731ca10119bbe37cf7718d327d5d2ff4 Mon Sep 17 00:00:00 2001 From: paltherr Date: Thu, 26 Feb 2004 16:42:42 +0000 Subject: - Added ClosureHistory.java --- config/list/compiler.lst | 1 + sources/scalac/symtab/ClosureHistory.java | 73 +++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 sources/scalac/symtab/ClosureHistory.java diff --git a/config/list/compiler.lst b/config/list/compiler.lst index 65c2710ebf..ebbad6cd93 100644 --- a/config/list/compiler.lst +++ b/config/list/compiler.lst @@ -87,6 +87,7 @@ symtab/classfile/SymblParser.java symtab/classfile/Pickle.java symtab/classfile/UnPickle.java +symtab/ClosureHistory.java symtab/Definitions.java symtab/EntryTags.java symtab/Kinds.java diff --git a/sources/scalac/symtab/ClosureHistory.java b/sources/scalac/symtab/ClosureHistory.java new file mode 100644 index 0000000000..8825fb3e20 --- /dev/null +++ b/sources/scalac/symtab/ClosureHistory.java @@ -0,0 +1,73 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package scalac.symtab; + +import java.util.Iterator; +import java.util.TreeMap; + +import scalac.Global; +import scalac.framework.History; +import scalac.util.Debug; + +/** This class implements a closure history. */ +public class ClosureHistory extends History { + + //######################################################################## + // Protected Methods + + /** Transforms given closure into closure at next phase. */ + protected Object transformValue(Object owner, Object value){ + Type[] closure = (Type[])value; + for (int i = 0; i < closure.length; i++) { + Symbol symbol = closure[i].symbol(); + // !!! symbol.nextInfoHasChanged() would be better + if (symbol.info() != symbol.nextInfo()) + return super.transformValue(owner, closure); + } + return closure; + } + + /** Computes the closure at current phase. */ + protected Object computeValue(Object owner) { + Symbol clasz = (Symbol)owner; + TreeMap parents = new TreeMap(SymbolComparator.instance); + addParents(parents, clasz.info()); + Type[] closure = new Type[1 + parents.size()]; + Iterator types = parents.values().iterator(); + closure[0] = clasz.type(); + for (int i = 1; i < closure.length; i++) + closure[i] = (Type)types.next(); + return closure; + } + + //######################################################################## + // Private Functions + + /** Adds all parents of given type to given parent table. */ + private static void addParents(TreeMap/**/ table, Type type) { + switch (type) { + case ErrorType: + return; + case TypeRef(_, Symbol symbol, _): + Type.Map map = Type.getThisTypeMap(symbol, type); + Type[] closure = symbol.closure(); + for (int i = 0; i < closure.length; i++) + table.put(closure[i].symbol(), map.apply(closure[i])); + return; + case CompoundType(Type[] parents, _): + for (int i = 0; i < parents.length; i++) + addParents(table, parents[i]); + return; + default: + throw Debug.abort("illegal case", type); + } + } + + //######################################################################## +} -- cgit v1.2.3