X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FECHRRuleset.java;h=9a8aa78b929199b8e6aad3b4db405d4e9e2e2b15;hp=b2d3b2235567808963b8644fa71ce2863518d80a;hb=862c09c9608329f326404342d12da61792eece2c;hpb=593a8f75d9dbc363234002dc500c346afbeba040 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java index b2d3b2235..9a8aa78b9 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRuleset.java @@ -1,117 +1,117 @@ -package org.simantics.scl.compiler.elaboration.expressions; - -import org.simantics.scl.compiler.elaboration.chr.CHRRuleset; -import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; -import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; -import org.simantics.scl.compiler.elaboration.contexts.TypingContext; -import org.simantics.scl.compiler.environment.Environment; -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.IExpression; -import org.simantics.scl.compiler.top.ExpressionInterpretationContext; -import org.simantics.scl.compiler.types.Type; -import org.simantics.scl.compiler.types.exceptions.MatchException; - -import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; -import gnu.trove.set.hash.TIntHashSet; - -public class ECHRRuleset extends Expression { - CHRRuleset ruleset; - Expression in; - - public ECHRRuleset(CHRRuleset ruleset, Expression in) { - this.ruleset = ruleset; - this.in = in; - } - - @Override - public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { - ruleset.collectRefs(allRefs, refs); - in.collectRefs(allRefs, refs); - } - @Override - public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { - ruleset.collectVars(allVars, vars); - in.collectVars(allVars, vars); - } - @Override - public void forVariables(VariableProcedure procedure) { - ruleset.forVariables(procedure); - in.forVariables(procedure); - } - @Override - protected void updateType() throws MatchException { - setType(in.getType()); - } - @Override - public IVal toVal(Environment env, CodeWriter w) { - ruleset.generateCode(w); - return in.toVal(env, w); - } - @Override - public void collectFreeVariables(THashSet vars) { - ruleset.collectFreeVariables(vars); - in.collectFreeVariables(vars); - } - @Override - public Expression resolve(TranslationContext context) { - context.pushFrame(); - context.pushCHRConstraintFrame(); - ruleset.resolve(context); - in = in.resolve(context); - context.popCHRConstraintFrame(ruleset.constraints); - context.popFrame(); - return this; - } - @Override - public void setLocationDeep(long loc) { - if(location == Locations.NO_LOCATION) { - this.location = loc; - ruleset.setLocationDeep(loc); - in.setLocationDeep(loc); - } - } - @Override - public Expression decorate(ExpressionDecorator decorator) { - in = in.decorate(decorator); - return this; - } - @Override - public void collectEffects(THashSet effects) { - ruleset.collectEffects(effects); - in.collectEffects(effects); - } - @Override - public void accept(ExpressionVisitor visitor) { - visitor.visit(this); - } - - @Override - public Expression inferType(TypingContext context) { - ruleset.checkType(context); - in = in.inferType(context); - return this; - } - - @Override - public Expression simplify(SimplificationContext context) { - ruleset.simplify(context); - ruleset.compile(context); - in = in.simplify(context); - return this; - } - - @Override - public Expression accept(ExpressionTransformer transformer) { - return transformer.transform(this); - } - - @Override - public IExpression toIExpression(ExpressionInterpretationContext context) { - throw new UnsupportedOperationException(); - } - -} +package org.simantics.scl.compiler.elaboration.expressions; + +import org.simantics.scl.compiler.compilation.CompilationContext; +import org.simantics.scl.compiler.elaboration.chr.CHRRuleset; +import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; +import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; +import org.simantics.scl.compiler.elaboration.contexts.TypingContext; +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.IExpression; +import org.simantics.scl.compiler.top.ExpressionInterpretationContext; +import org.simantics.scl.compiler.types.Type; +import org.simantics.scl.compiler.types.exceptions.MatchException; + +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.set.hash.THashSet; +import gnu.trove.set.hash.TIntHashSet; + +public class ECHRRuleset extends Expression { + CHRRuleset ruleset; + Expression in; + + public ECHRRuleset(CHRRuleset ruleset, Expression in) { + this.ruleset = ruleset; + this.in = in; + } + + @Override + public void collectRefs(TObjectIntHashMap allRefs, TIntHashSet refs) { + ruleset.collectRefs(allRefs, refs); + in.collectRefs(allRefs, refs); + } + @Override + public void collectVars(TObjectIntHashMap allVars, TIntHashSet vars) { + ruleset.collectVars(allVars, vars); + in.collectVars(allVars, vars); + } + @Override + public void forVariables(VariableProcedure procedure) { + ruleset.forVariables(procedure); + in.forVariables(procedure); + } + @Override + protected void updateType() throws MatchException { + setType(in.getType()); + } + @Override + public IVal toVal(CompilationContext context, CodeWriter w) { + ruleset.generateCode(w); + return in.toVal(context, w); + } + @Override + public void collectFreeVariables(THashSet vars) { + ruleset.collectFreeVariables(vars); + in.collectFreeVariables(vars); + } + @Override + public Expression resolve(TranslationContext context) { + context.pushFrame(); + context.pushCHRConstraintFrame(); + ruleset.resolve(context); + in = in.resolve(context); + context.popCHRConstraintFrame(ruleset.constraints); + context.popFrame(); + return this; + } + @Override + public void setLocationDeep(long loc) { + if(location == Locations.NO_LOCATION) { + this.location = loc; + ruleset.setLocationDeep(loc); + in.setLocationDeep(loc); + } + } + @Override + public Expression decorate(ExpressionDecorator decorator) { + in = in.decorate(decorator); + return this; + } + @Override + public void collectEffects(THashSet effects) { + ruleset.collectEffects(effects); + in.collectEffects(effects); + } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } + + @Override + public Expression inferType(TypingContext context) { + ruleset.checkType(context); + in = in.inferType(context); + return this; + } + + @Override + public Expression simplify(SimplificationContext context) { + ruleset.simplify(context); + ruleset.compile(context); + in = in.simplify(context); + return this; + } + + @Override + public Expression accept(ExpressionTransformer transformer) { + return transformer.transform(this); + } + + @Override + public IExpression toIExpression(ExpressionInterpretationContext context) { + throw new UnsupportedOperationException(); + } + +}