/* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** ** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** \* */ // $Id$ package scalac.symtab; import java.util.Map; import java.util.HashMap; import scalac.util.Debug; /** * This class implements a symbol cloner. It automatically determines * the new owner of cloned symbols, clones their type and keeps track * of all cloned symbols. Clone a type means clone all symbol declared * in that type (for example parameters of a MethodType). */ public class SymbolCloner { //######################################################################## // Public Fields /** A table that maps owners of symbols to owners of cloned symbols */ public final Map/* into which cloned symbols are stored */ public final Map/* " + Debug.show(clones.get(symbol)); Symbol clone = symbol.cloneSymbol(getOwnerFor(symbol)); clones.put(symbol, clone); clone.setType(cloneType(symbol.info())); return clone; } /** Clones the given symbols. */ public Symbol[] cloneSymbols(Symbol[] symbols) { if (symbols.length == 0) return Symbol.EMPTY_ARRAY; Symbol[] clones = new Symbol[symbols.length]; for (int i = 0; i < clones.length; i++) clones[i] = cloneSymbol(symbols[i]); return clones; } /** Clones the given type. */ public Type cloneType(Type type) { switch (type) { case PolyType(Symbol[] tparams, Type result): Symbol[] clones = cloneSymbols(tparams); Type clone = Type.PolyType(clones, cloneType(result)); return Type.getSubst(tparams, clones).applyParams(clone); case MethodType(Symbol[] vparams, Type result): return Type.MethodType(cloneSymbols(vparams), cloneType(result)); default: return type; } } //######################################################################## }