import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.codegen.references.IVal;
import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
-import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
import org.simantics.scl.compiler.internal.interpreted.IConstant;
import org.simantics.scl.compiler.internal.interpreted.IExpression;
import org.simantics.scl.compiler.internal.interpreted.IIf;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.runtime.tuple.Tuple0;
-import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
-import gnu.trove.set.hash.TIntHashSet;
-
public class EIf extends Expression {
public Expression condition;
public Expression then_;
this.else_ = else_;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- condition.collectRefs(allRefs, refs);
- then_.collectRefs(allRefs, refs);
- if(else_ != null)
- else_.collectRefs(allRefs, refs);
+ @Override
+ protected void updateType() throws MatchException {
+ setType(then_.getType());
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- condition.collectVars(allVars, vars);
- then_.collectVars(allVars, vars);
- if(else_ != null)
- else_.collectVars(allVars, vars);
- }
-
- @Override
- protected void updateType() throws MatchException {
- setType(then_.getType());
- }
-
- @Override
- public IVal toVal(CompilationContext context, CodeWriter w) {
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
IVal conditionVal = condition.toVal(context, w);
CodeWriter joinPoint = w.createBlock(getType());
CodeWriter thenBlock = w.createBlock();
if(else_ != null) {
CodeWriter elseBlock = w.createBlock();
- w.if_(conditionVal, thenBlock.getContinuation(), elseBlock.getContinuation());
+ w.if_(location, conditionVal, thenBlock.getContinuation(), elseBlock.getContinuation());
IVal elseVal = else_.toVal(context, elseBlock);
- elseBlock.jump(joinPoint.getContinuation(), elseVal);
+ elseBlock.jump(location, joinPoint.getContinuation(), elseVal);
}
else {
- w.if_(conditionVal, thenBlock.getContinuation(), joinPoint.getContinuation());
+ w.if_(location, conditionVal, thenBlock.getContinuation(), joinPoint.getContinuation());
}
IVal thenVal = then_.toVal(context, thenBlock);
- thenBlock.jump(joinPoint.getContinuation(), thenVal);
+ thenBlock.jump(location, joinPoint.getContinuation(), thenVal);
w.continueAs(joinPoint);
return w.getParameters()[0];
}
- @Override
- public void collectFreeVariables(THashSet<Variable> vars) {
- condition.collectFreeVariables(vars);
- then_.collectFreeVariables(vars);
- if(else_ != null)
- else_.collectFreeVariables(vars);
- }
-
@Override
public Expression simplify(SimplificationContext context) {
condition = condition.simplify(context);
return this;
}
- @Override
- public Expression decorate(ExpressionDecorator decorator) {
- condition = condition.decorate(decorator);
- then_ = then_.decorate(decorator);
- if(else_ != null)
- else_ = else_.decorate(decorator);
- return decorator.decorate(this);
- }
-
@Override
public boolean isEffectful() {
return condition.isEffectful() || then_.isEffectful() || (else_ != null && else_.isEffectful());
}
-
- @Override
- public void collectEffects(THashSet<Type> effects) {
- condition.collectEffects(effects);
- then_.collectEffects(effects);
- if(else_ != null)
- else_.collectEffects(effects);
- }
@Override
public void setLocationDeep(long loc) {
else_ != null ? else_.toIExpression(target) : new IConstant(Tuple0.INSTANCE));
}
- @Override
- public void forVariables(VariableProcedure procedure) {
- condition.forVariables(procedure);
- then_.forVariables(procedure);
- if(else_ != null)
- else_.forVariables(procedure);
- }
@Override
public Expression accept(ExpressionTransformer transformer) {
return transformer.transform(this);