X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fderiving%2FShowDeriver.java;h=40c3605e779dc86ac402a4fb80016e3d8298ddff;hb=refs%2Fchanges%2F34%2F3134%2F2;hp=e06a117e9cb20b4ecfc6ee03ed93a6f0a06eda09;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/deriving/ShowDeriver.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/deriving/ShowDeriver.java index e06a117e9..40c3605e7 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/deriving/ShowDeriver.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/deriving/ShowDeriver.java @@ -10,7 +10,9 @@ import org.simantics.scl.compiler.elaboration.expressions.EApply; 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; @@ -46,7 +48,7 @@ class ShowDeriver implements InstanceDeriver { } 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; @@ -55,11 +57,16 @@ class ShowDeriver implements InstanceDeriver { 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; @@ -74,33 +81,55 @@ class ShowDeriver implements InstanceDeriver { for(int i=0;iemptyList()));*/ + } 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.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));