package org.simantics.scl.compiler.elaboration.chr; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint; import org.simantics.scl.compiler.elaboration.chr.relations.ExternalCHRRelation; import org.simantics.scl.compiler.elaboration.chr.relations.SpecialCHRRelation; import org.simantics.scl.compiler.elaboration.chr.relations.UnresolvedCHRRelation; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext.ExistentialFrame; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.expressions.ERecord; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor; import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.parsing.Symbol; import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; import gnu.trove.set.hash.TIntHashSet; public class CHRLiteral extends Symbol { public CHRRelation relation; public Type[] typeParameters; public Expression[] parameters; public FieldAssignment[] fields; // optional public Expression[] typeConstraintEvidenceParameters; public boolean killAfterMatch; public boolean negated; public boolean passive = true; public CHRLiteral(long location, CHRRelation relation, Expression[] parameters, boolean killAfterMatch, boolean negated) { this.location = location; this.relation = relation; this.parameters = parameters; this.killAfterMatch = killAfterMatch; this.negated = negated; } public void resolve(TranslationContext context) { if(relation == SpecialCHRRelation.ASSIGN) { parameters[1] = parameters[1].resolve(context); parameters[0] = parameters[0].resolveAsPattern(context); return; } if(parameters != null) { for(int i=0;i allVars, TIntHashSet vars) { for(Expression parameter : parameters) parameter.collectVars(allVars, vars); if(typeConstraintEvidenceParameters != null) for(Expression parameter : typeConstraintEvidenceParameters) parameter.collectVars(allVars, vars); } public void setLocationDeep(long loc) { if(location == Locations.NO_LOCATION) { this.location = loc; for(Expression parameter : parameters) parameter.setLocationDeep(loc); } } public void simplify(SimplificationContext context) { for(int i=0;i