import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
import org.simantics.scl.compiler.elaboration.expressions.EVar;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
+import org.simantics.scl.compiler.elaboration.modules.TypeAlias;
import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
+import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
import org.simantics.scl.compiler.environment.AmbiguousNameException;
import org.simantics.scl.compiler.environment.Environment;
import org.simantics.scl.compiler.environment.Environments;
}
TCon con;
try {
- con = Environments.getTypeConstructorName(environment, headType.name);
+ con = Environments.getTypeDescriptorName(environment, headType.name);
} catch (AmbiguousNameException e1) {
errorLog.log(headType.location, e1.getMessage());
return;
errorLog.log(headType.location, "Couldn't resolve " + headType.name);
return;
}
- TypeConstructor tcon = environment.getTypeConstructor(con);
- if(tcon == null) {
+ TypeDescriptor tdesc = environment.getTypeDescriptor(con);
+ if(tdesc == null) {
errorLog.log(headType.location, "Didn't find type constructor for " + headType.name);
return;
}
+ if(tdesc instanceof TypeAlias) {
+ errorLog.log(headType.location, "Cannot derive instance for a type alias.");
+ return;
+ }
+ TypeConstructor tcon = (TypeConstructor)tdesc;
if(tcon.isOpen) {
errorLog.log(headType.location, "Cannot derive instance for open data types.");
return;
for(int i=0;i<l;++i) {
par[i] = "v" + i;
}
- Expression lhs = new EApply(
- new EVar("<+"),
- new EVar("sb"),
- new EApply(new EVar(constructor.name.name), Expressions.vars(par))
- );
- Expression value;
- value = new EApply(new EVar("<<"), new EVar("sb"),
- new ELiteral(new StringConstant(constructor.name.name)));
- for(int i=0;i<l;++i) {
- value = new EApply(new EVar("<<"),
- value,
- new ELiteral(new StringConstant(" "))
- );
- value = new EApply(new EVar("<+"),
- value,
- new EApply(new EVar("Par"), new ELiteral(CONST_10), new EVar("v" + i))
+
+ // <+
+ {
+ Expression lhs = new EApply(
+ new EVar("<+"),
+ new EVar("sb"),
+ new EApply(new EVar(constructor.name.name), Expressions.vars(par))
);
+ Expression value;
+ value = new EApply(new EVar("<<"), new EVar("sb"),
+ new ELiteral(new StringConstant(constructor.name.name)));
+ for(int i=0;i<l;++i) {
+ value = new EApply(new EVar("<<"),
+ value,
+ new ELiteral(new StringConstant(" "))
+ );
+ value = new EApply(new EVar("<+"),
+ value,
+ new EApply(new EVar("Par"), new ELiteral(CONST_10), new EVar("v" + i))
+ );
+ }
+
+ try {
+ DValueAst valueAst = new DValueAst(lhs, value);
+ valueAst.setLocationDeep(der.location);
+ valueDefs.add(valueAst);
+ /*valueDefs.addAnnotation("<+", new DAnnotationAst(new EVar("@private"),
+ Collections.<Expression>emptyList()));*/
+ } catch (NotPatternException e) {
+ errorLog.log(e.getExpression().location, "Not a pattern.");
+ }
}
-
- try {
- DValueAst valueAst = new DValueAst(lhs, value);
- valueAst.setLocationDeep(der.location);
- valueDefs.add(valueAst);
- /*valueDefs.addAnnotation("<+", new DAnnotationAst(new EVar("@private"),
- Collections.<Expression>emptyList()));*/
- } catch (NotPatternException e) {
- errorLog.log(e.getExpression().location, "Not a pattern.");
+
+ // precedence
+ {
+ Expression lhs = new EApply(
+ new EVar("precedence"),
+ new EApply(new EVar(constructor.name.name), Expressions.vars(par))
+ );
+ Expression value;
+ value = new ELiteral(new IntegerConstant(l == 0 ? 0 : 20));
+
+ try {
+ DValueAst valueAst = new DValueAst(lhs, value);
+ valueAst.setLocationDeep(der.location);
+ valueDefs.add(valueAst);
+ } catch (NotPatternException e) {
+ errorLog.log(e.getExpression().location, "Not a pattern.");
+ }
}
}
instancesAst.add(new ProcessedDInstanceAst(instanceAst, valueDefs));