import org.simantics.scl.compiler.elaboration.contexts.TypeTranslationContext;
import org.simantics.scl.compiler.elaboration.modules.TypeAlias;
+import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
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.Types;
import org.simantics.scl.compiler.types.kinds.Kind;
import org.simantics.scl.compiler.types.kinds.Kinds;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
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 class TVarAst extends TypeAst {
+ private static final Logger LOGGER = LoggerFactory.getLogger(TVarAst.class);
public final String name;
public TVarAst(String name) {
for(int i=1;i<name.length()-1;++i)
if(name.charAt(i) != ',') {
try {
- con = Environments.getTypeConstructorName(context.getEnvironment(), name.substring(1, name.length()-1));
+ con = Environments.getTypeDescriptorName(context.getEnvironment(), name.substring(1, name.length()-1));
} catch(AmbiguousNameException e) {
context.getErrorLog().log(location, e.getMessage());
return Types.metaVar(Kinds.STAR);
}
else if(Character.isLowerCase(c))
return context.resolveTypeVariable(location, name, expectedKind);
+ else if(c == '?')
+ return context.resolveExistential(location, name, expectedKind);
else {
- TypeAlias alias;
+ TypeDescriptor tdesc;
try {
- alias = Environments.getTypeAlias(context.getEnvironment(), name);
- } catch (AmbiguousNameException e1) {
- context.getErrorLog().log(location, e1.getMessage());
+ tdesc = Environments.getTypeDescriptor(context.getEnvironment(), name);
+ } catch (AmbiguousNameException e) {
+ context.getErrorLog().log(location, e.getMessage());
+ return Types.metaVar(Kinds.STAR);
+ }
+ if(tdesc == null) {
+ context.getErrorLog().log(location, "Didn't find type constructor " + name + ".");
return Types.metaVar(Kinds.STAR);
}
- if(alias != null) {
+ if(tdesc instanceof TypeAlias) {
+ TypeAlias alias = (TypeAlias)tdesc;
if(alias.getArity() > 0) {
context.getErrorLog().log(location, "The alias expects " +
alias.getArity() + " parameters, but none are given.");
}
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);
- }
+ con = tdesc.name;
}
}
if(name.charAt(i) != ',') {
con = context.resolveTypeConstructor(name.substring(1, name.length()-1));
if(con == null) {
- System.err.println("Didn't find type constructor " + name + ".");
+ LOGGER.warn("Didn't find type constructor " + name + ".");
return Types.metaVar(Kinds.STAR);
}
break block;
}
else if(Character.isLowerCase(c))
return context.resolveTypeVariable(name);
+ else if(c == '?')
+ return context.resolveExistential(name);
else {
con = context.resolveTypeConstructor(name);
if(con == null) {
- System.err.println("Didn't find type constructor " + name + ".");
+ LOGGER.warn("Didn't find type constructor " + name + ".");
return Types.metaVar(Kinds.STAR);
}
}
char c = name.charAt(0);
if(Character.isLowerCase(c))
return context.resolveTypeVariable(name);
+ else if(c == '?')
+ return context.resolveExistential(name);
else {
Type con = context.resolveTypeConstructor(name);
if(con == null) {
- System.err.println("Didn't find effect constructor " + name + ".");
+ LOGGER.warn("Didn't find effect constructor " + name + ".");
return Types.metaVar(Kinds.EFFECT);
}
return con;