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;
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;
}
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<parameters.length;++i)
+ copy.parameters[i] = copy.parameters[i].replace(context);
+ copy.passive = passive;
+ copy.typeConstraintEvidenceParameters = context.replace(typeConstraintEvidenceParameters);
+ copy.typeParameters = context.replace(typeParameters);
+ copy.fields = context.replace(fields);
+ return copy;
+ }
}
import org.simantics.scl.compiler.elaboration.chr.plan.PreCommitOp;
import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext;
import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint;
+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.TypingContext;
visitor.visit(this);
return b.toString();
}
+
+ public CHRQuery replace(ReplaceContext context) {
+ CHRLiteral[] newLiterals = new CHRLiteral[literals.length];
+ for(int i=0;i<literals.length;++i)
+ newLiterals[i] = literals[i].replace(context);
+ return new CHRQuery(newLiterals);
+ }
}
if(end != null)
end.return_(BooleanConstant.FALSE);
}
-
}
import org.simantics.scl.compiler.elaboration.expressions.EVariable;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
+import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
import gnu.trove.map.hash.THashMap;
public ReplaceContext(TypingContext typingContext) {
this(new THashMap<TVar, Type>(), new THashMap<Variable, Expression>(), typingContext);
}
+
+ public Expression[] replace(Expression[] expressions) {
+ if(expressions == null)
+ return null;
+ Expression[] result = new Expression[expressions.length];
+ for(int i=0;i<expressions.length;++i)
+ result[i] = expressions[i].replace(this);
+ return result;
+ }
+
+ public Type[] replace(Type[] types) {
+ if(types == null)
+ return null;
+ return Types.replace(types, tvarMap);
+ }
+
+ public FieldAssignment[] replace(FieldAssignment[] fields) {
+ if(fields == null)
+ return null;
+ FieldAssignment[] result = new FieldAssignment[fields.length];
+ for(int i=0;i<fields.length;++i)
+ result[i] = fields[i].replace(this);
+ return result;
+ }
}
import java.util.ArrayList;
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.common.names.Names;
import org.simantics.scl.compiler.compilation.CompilationContext;
import org.simantics.scl.compiler.constants.NoRepConstant;
import org.simantics.scl.compiler.elaboration.chr.plan.PlanOp;
import org.simantics.scl.compiler.elaboration.chr.plan.PlanRealizer;
import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext;
+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.TypingContext;
public Expression simplify(SimplificationContext simplificationContext) {
this.expression = expression.simplify(simplificationContext);
query.simplify(simplificationContext);
-
- CompilationContext compilationContext = simplificationContext.getCompilationContext();
- QueryPlanningContext context = new QueryPlanningContext(compilationContext, existentialVariables);
- if(query.createQueryPlan(context, null, -1, null))
- planOps = context.getPlanOps();
return this;
}
@Override
public IVal toVal(CompilationContext context, CodeWriter w) {
+ QueryPlanningContext queryContext = new QueryPlanningContext(context, existentialVariables);
+ if(query.createQueryPlan(queryContext, null, -1, null))
+ planOps = queryContext.getPlanOps();
+
IVal list = w.apply(location, context.getValue(Names.MList_create).getValue(), NoRepConstant.UNIT);
planOps.add(new PlanOp(location) {
@Override
public Expression accept(ExpressionTransformer transformer) {
return transformer.transform(this);
}
+
+ @Override
+ public Expression replace(ReplaceContext context) {
+ Variable[] newExistentialVariables = new Variable[existentialVariables.length];
+ for(int i=0;i<existentialVariables.length;++i) {
+ Variable newVariable = existentialVariables[i].copy();
+ context.varMap.put(existentialVariables[i], new EVariable(newVariable));
+ newExistentialVariables[i] = newVariable;
+ }
+ ECHRSelect copy = new ECHRSelect(expression.replace(context), query.replace(context));
+ copy.existentialVariables = newExistentialVariables;
+ copy.currentRuleset = currentRuleset;
+ copy.planOps = planOps;
+ if(planOps != null) {
+ copy.planOps = new ArrayList<PlanOp>(planOps.size());
+ throw new InternalCompilerError(location, "Copying of ECHRSelect is not supported.");
+ //for(PlanOp op : planOps)
+ // copy.planOps.add(op.replace(context));
+ }
+ return copy;
+ }
}
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;
public void getParameters(TranslationContext translationContext,
ArrayList<Expression> 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) {
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);
}
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) {
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;
this.name = name;
this.value = value;
}
+
+ public FieldAssignment replace(ReplaceContext context) {
+ return new FieldAssignment(name, value == null ? null : value.replace(context));
+ }
}