package org.simantics.scl.compiler.internal.parsing.types; import org.simantics.scl.compiler.elaboration.contexts.TypeTranslationContext; import org.simantics.scl.compiler.elaboration.modules.TypeAlias; import org.simantics.scl.compiler.environment.AmbiguousNameException; import org.simantics.scl.compiler.environment.Environments; import org.simantics.scl.compiler.internal.types.TypeElaborationContext; import org.simantics.scl.compiler.types.TCon; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.kinds.Kind; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; import gnu.trove.set.hash.TIntHashSet; /** * This class represents an abstract syntax tree node for a type variable. * The only property of a type variable is its name. */ public class TVarAst extends TypeAst { public final String name; public TVarAst(String name) { this.name = name; } @Override public void toString(StringBuilder b) { b.append(name); } @Override public Type toType(TypeTranslationContext context, Kind expectedKind) { char c = name.charAt(0); TCon con; block: { if(c == '(') { for(int i=1;i 0) { context.getErrorLog().log(location, "The alias expects " + alias.getArity() + " parameters, but none are given."); return Types.metaVar(Kinds.metaVar()); } return alias.body; } try { con = Environments.getTypeConstructorName(context.getEnvironment(), name); } catch(AmbiguousNameException e) { context.getErrorLog().log(location, e.getMessage()); return Types.metaVar(Kinds.STAR); } if(con == null) { context.getErrorLog().log(location, "Didn't find type constructor " + name + "."); return Types.metaVar(Kinds.STAR); } } } Kind providedKind = context.getKind(con); context.unify(location, providedKind, expectedKind); return con; } @Override public Type toType(TypeElaborationContext context) { char c = name.charAt(0); Type con; block: { if(c == '(') { for(int i=1;i typeNameMap, TIntHashSet set) { if(typeNameMap.containsKey(name)) set.add(typeNameMap.get(name)); } }