fixParent(o, parent);
fixParent(result, parent);
    static public Object cloneToplevel(Object o, Object parent) {	// if it is null, keep it that way	if (o==null) {	    return null;	}	// if we've already cloned <o>, then return the clone	Object alreadyCloned = registry.get(new RegistryWrapper(o));	if (alreadyCloned!=null) {	    return alreadyCloned;	}	// otherwise, we'll get a new cloned result for <o>.  	Object result;	// dispatch on type of <o>...	String typeName = o.getClass().getName();	// local variables require special treatment since their	// references might be shared	if (o instanceof JLocalVariable) {	    result = cloneJLocalVariable((JLocalVariable)o);	}	// immutable types -- don't clone them, either because we	// don't have to or because they might rely on reference	// equality	else if (typeName.startsWith("at.dms.kjc.C") ||		 o instanceof JLiteral ||		 o instanceof JavaStyleComment ||		 o instanceof TokenReference ||		 o instanceof SIRSplitType ||		 o instanceof SIRJoinType ||		 o instanceof String ||		 o instanceof PrintWriter ||		 o instanceof at.dms.compiler.WarningFilter) {	    // don't clone these since they're immutable or shouldn't be copied	    result = o;	} 	// other kjc classes, do deep cloning	else if (CloneGenerator.inTargetClasses(typeName)) {	    // first pass:  output deep cloning for everything in at.dms	    Utils.assert(o instanceof DeepCloneable, "Should declare " + o.getClass() + " to implement DeepCloneable.");	    result = ((DeepCloneable)o).deepClone();	}	// hashtables -- clone along with contents	else if (o instanceof Hashtable) {	    result = cloneHashtable((Hashtable)o, parent);	} 	// arrays -- need to clone children as well	else if (o.getClass().isArray()) {	    // don't clone arrays of certain element types...	    boolean shouldClone;	    Object[] arr = (Object[])o;	    if (arr.length > 0) {		Object elem = arr[0];		// don't clone these array types		if (elem instanceof JavaStyleComment) {		    shouldClone = false;		} else {		    shouldClone = true;		}	    } else {		shouldClone = true;	    }	    // clone array if we decided to	    if (shouldClone) {		result = ((Object[])o).clone();	    } else {		result = o;	    }	    register(o, result);	    if (shouldClone) {		cloneWithinArray((Object[])result, parent);	    }	}	// enumerate the list types to make the java compiler happy	// with calling the .clone() method	else if (o instanceof LinkedList) {	    result = ((LinkedList)o).clone();	    register(o, result);	    cloneWithinList((List)result, parent);	} else if (o instanceof Stack) {	    result = ((Stack)o).clone();	    register(o, result);	    cloneWithinList((List)result, parent);	} else if (o instanceof Vector) {	    result = ((Vector)o).clone();	    register(o, result);	    cloneWithinList((List)result, parent);	}	// unknown types	else {	    Utils.fail("Don't know how to clone field of type " + o.getClass());	    result = o;	}	// try fixing parent	fixParent(o, parent);	// remember result	register(o, result);	return result;    }