/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This file is part of SimpleC. * * See the file "SimpleC-LICENSE" for Copyright information and * * the terms and conditions for copying, distribution and * * modification of SimpleC. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ package org.sablecc.simplec; import java.util.*; class Lam extends Type { LinkedList args = new LinkedList(); Variable ret = new Variable(new Ref()); void unify(Type t) { Lam lam = (Lam) t; LinkedList list1 = (args.size() > lam.args.size()) ? args : lam.args; LinkedList list2 = (args.size() > lam.args.size()) ? lam.args : args; ListIterator i2 = list2.listIterator(); for(ListIterator i1 = list1.listIterator(); i1.hasNext(); ) { Variable v1 = ((Variable) i1.next()).ecr(); if(i2.hasNext()) { Variable v2 = ((Variable) i2.next()).ecr(); if(v1 != v2) { v1.join(v2); } } else { i2.add(v1); i2.next(); } } Variable ret1 = ret.ecr(); Variable ret2 = lam.ret.ecr(); if(ret1 != ret2) { ret1.join(ret2); } } public String toString() { StringBuffer s = new StringBuffer(); s.append("lam("); boolean comma = false; for(Iterator i = args.iterator(); i.hasNext();) { Variable v = (Variable) i.next(); if(comma) { s.append(","); } else { comma = true; } if(v.ecr().type == Bottom.instance) { s.append("bottom"); } else { s.append("T" + v.ecr().number); } } s.append("):"); if(ret.ecr().type == Bottom.instance) { s.append("bottom"); } else { s.append("T" + ret.ecr().number); } return s.toString(); } }