X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fchr%2FCHRLiteral.java;h=e0921dc106fa67f50944ef6ebd9c14c3080972bf;hb=624ab61bd302e999952f792e619a691e027ff1d2;hp=f44609e6c1b13552b9311025f2872c740a10978c;hpb=2542bc1ae2bbddedb6e82e46fa8eb9838a63aea7;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java index f44609e6c..e0921dc10 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java @@ -5,6 +5,7 @@ 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; @@ -12,7 +13,6 @@ 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.VariableProcedure; 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; @@ -24,7 +24,6 @@ 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.THashSet; import gnu.trove.set.hash.TIntHashSet; public class CHRLiteral extends Symbol { @@ -38,15 +37,20 @@ public class CHRLiteral extends Symbol { public boolean negated; public boolean passive = true; - public CHRLiteral(long location, CHRRelation relation, Expression[] parameters, boolean remove, boolean negated) { + public CHRLiteral(long location, CHRRelation relation, Expression[] parameters, boolean killAfterMatch, boolean negated) { this.location = location; this.relation = relation; this.parameters = parameters; - this.killAfterMatch = remove; + 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 allRefs, TIntHashSet refs) { - for(Expression parameter : parameters) - parameter.collectRefs(allRefs, refs); - if(typeConstraintEvidenceParameters != null) - for(Expression parameter : typeConstraintEvidenceParameters) - parameter.collectRefs(allRefs, refs); - } - public void checkType(TypingContext context) { if(relation == SpecialCHRRelation.EXECUTE) { if(parameters.length != 1) @@ -123,6 +119,11 @@ public class CHRLiteral extends Symbol { parameters[0] = parameters[0].checkIgnoredType(context); typeConstraintEvidenceParameters = Expression.EMPTY_ARRAY; } + else if(relation == SpecialCHRRelation.ASSIGN) { + parameters[1] = parameters[1].inferType(context); + parameters[0] = parameters[0].checkTypeAsPattern(context, parameters[1].getType()); + typeConstraintEvidenceParameters = Expression.EMPTY_ARRAY; + } else { TVar[] typeVariables = relation.getTypeVariables(); typeParameters = typeVariables.length == 0 ? Type.EMPTY_ARRAY : new Type[typeVariables.length]; @@ -147,22 +148,6 @@ public class CHRLiteral extends Symbol { parameter.collectVars(allVars, vars); } - public void forVariables(VariableProcedure procedure) { - for(Expression parameter : parameters) - parameter.forVariables(procedure); - if(typeConstraintEvidenceParameters != null) - for(Expression parameter : typeConstraintEvidenceParameters) - parameter.forVariables(procedure); - } - - public void collectFreeVariables(THashSet vars) { - for(Expression parameter : parameters) - parameter.collectFreeVariables(vars); - if(typeConstraintEvidenceParameters != null) - for(Expression parameter : typeConstraintEvidenceParameters) - parameter.collectFreeVariables(vars); - } - public void setLocationDeep(long loc) { if(location == Locations.NO_LOCATION) { this.location = loc; @@ -186,9 +171,14 @@ public class CHRLiteral extends Symbol { return b.toString(); } - public void collectQueryEffects(THashSet effects) { - } - - public void collectEnforceEffects(THashSet effects) { + public CHRLiteral replace(ReplaceContext context) { + CHRLiteral copy = new CHRLiteral(location, relation, context.replace(parameters), killAfterMatch, negated); + for(int i=0;i