From 4ebc60b24db646dc2c64dd54190b029b8e28d030 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Mon, 31 Jul 2017 18:12:18 +0300 Subject: [PATCH] (refs #7371) Support expression cloning for ECHRSelect Change-Id: Ie4ea77e03eccc3f59b7c0e27e0528527826df9e4 --- .../compiler/elaboration/chr/CHRLiteral.java | 16 ++++++++-- .../compiler/elaboration/chr/CHRQuery.java | 8 +++++ .../elaboration/chr/plan/AccessFactOp.java | 1 - .../elaboration/contexts/ReplaceContext.java | 26 +++++++++++++++ .../elaboration/expressions/ECHRSelect.java | 32 ++++++++++++++++--- .../elaboration/expressions/Expression.java | 10 +++--- .../expressions/records/FieldAssignment.java | 5 +++ 7 files changed, 85 insertions(+), 13 deletions(-) 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 eb0f48b20..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; @@ -36,11 +37,11 @@ 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; } @@ -169,4 +170,15 @@ public class CHRLiteral extends Symbol { visitor.visit(this); return b.toString(); } + + public CHRLiteral replace(ReplaceContext context) { + CHRLiteral copy = new CHRLiteral(location, relation, context.replace(parameters), killAfterMatch, negated); + for(int i=0;i(), new THashMap(), typingContext); } + + public Expression[] replace(Expression[] expressions) { + if(expressions == null) + return null; + Expression[] result = new Expression[expressions.length]; + for(int i=0;i(planOps.size()); + throw new InternalCompilerError(location, "Copying of ECHRSelect is not supported."); + //for(PlanOp op : planOps) + // copy.planOps.add(op.replace(context)); + } + return copy; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java index 427acbd19..3a2f845fe 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/Expression.java @@ -61,10 +61,10 @@ public abstract class Expression extends Symbol implements Typed { try { updateType(); } catch (MatchException e) { - throw new InternalCompilerError(e); + throw new InternalCompilerError(location, e); } if(type == null) - throw new InternalCompilerError(getClass().getSimpleName() + + throw new InternalCompilerError(location, getClass().getSimpleName() + ".updateType couldn't compute its type."); } return type; @@ -242,7 +242,7 @@ public abstract class Expression extends Symbol implements Typed { public void getParameters(TranslationContext translationContext, ArrayList parameters) { - throw new InternalCompilerError("Class " + getClass().getSimpleName() + " does not support getParameters."); + throw new InternalCompilerError(location, "Class " + getClass().getSimpleName() + " does not support getParameters."); } public Expression resolveAsPattern(TranslationContext context) { @@ -252,7 +252,7 @@ public abstract class Expression extends Symbol implements Typed { public Expression checkTypeAsPattern(TypingContext context, Type requiredType) { if(context.isInPattern()) - throw new InternalCompilerError("Already in a pattern."); + throw new InternalCompilerError(location, "Already in a pattern."); context.setInPattern(true); Expression expression = checkType(context, requiredType); context.setInPattern(false); @@ -282,7 +282,7 @@ public abstract class Expression extends Symbol implements Typed { } public Expression replace(ReplaceContext context) { - throw new InternalCompilerError(getClass().getSimpleName() + " does not support replace."); + throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support replace."); } public static Expression[] replace(ReplaceContext context, Expression[] expressions) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/records/FieldAssignment.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/records/FieldAssignment.java index a26cd857b..af84130f8 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/records/FieldAssignment.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/records/FieldAssignment.java @@ -1,5 +1,6 @@ package org.simantics.scl.compiler.elaboration.expressions.records; +import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.internal.parsing.Symbol; @@ -11,4 +12,8 @@ public class FieldAssignment extends Symbol { this.name = name; this.value = value; } + + public FieldAssignment replace(ReplaceContext context) { + return new FieldAssignment(name, value == null ? null : value.replace(context)); + } } -- 2.43.2