for(TransformationRule rule : module.getRules())
for(Query[] queries : rule.sections.values())
for(Query query : queries)
- query.collectRefs(allRefs, refs);
+ query.collectRefs(allRefs, refs);
}
@Override
}
}
- public void collectRefs(TObjectIntHashMap<Object> 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)
literal.resolve(context);
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- for(CHRLiteral literal : literals)
- literal.collectRefs(allRefs, refs);
- }
-
public void checkType(TypingContext context) {
for(CHRLiteral literal : literals)
literal.checkType(context);
existentialVariables = context.popExistentialFrame();
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- head.collectRefs(allRefs, refs);
- body.collectRefs(allRefs, refs);
- }
-
public void checkType(TypingContext context) {
for(Variable variable : existentialVariables)
variable.setType(Types.metaVar(Kinds.STAR));
}*/
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- for(IncludeStatement include : includes)
- include.value.collectRefs(allRefs, refs);
- for(CHRRule rule : rules)
- rule.collectRefs(allRefs, refs);
- }
-
public void checkType(TypingContext context) {
for(IncludeStatement include : includes)
include.value = include.value.checkType(context, include.ruleset.runtimeRulesetType);
right = right.checkType(context, left.getType());
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- left.collectRefs(allRefs, refs);
- right.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
left.collectVars(allVars, vars);
guard = guard.checkIgnoredType(context);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- guard.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
guard.collectVars(allVars, vars);
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
-import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
import org.simantics.scl.compiler.internal.parsing.Symbol;
import org.simantics.scl.compiler.types.Type;
public abstract void collectFreeVariables(THashSet<Variable> vars);
public abstract void collectEffects(THashSet<Type> effects);
public abstract void checkType(TypingContext context);
- public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void resolve(TranslationContext context);
public abstract void accept(EquationVisitor visitor);
throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectFreeVariables.");
}
- @Override
- final public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectRefs.");
- }
-
@Override
final public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
return lhs;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- value.collectRefs(allRefs, refs);
- }
-
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
value.collectVars(allVars, vars);
super(loc);
this.expression = expression;
}
-
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- expression.collectRefs(allRefs, refs);
- }
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
this.activeCount = alternatives.length;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
return parameters;
}
-
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- function.collectRefs(allRefs, refs);
- for(Expression parameter : parameters)
- parameter.collectRefs(allRefs, refs);
- }
-
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
function.collectVars(allVars, vars);
for(Expression parameter : parameters)
return parameter;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- expression.collectRefs(allRefs, refs);
+ public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
+ expression.collectVars(allVars, vars);
}
-
- public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
- expression.collectVars(allVars, vars);
- }
- @Override
- protected void updateType() throws MatchException {
- setType(Types.instantiate(expression.getType(), parameter));
- }
-
- @Override
- public IVal toVal(CompilationContext context, CodeWriter w) {
+ @Override
+ protected void updateType() throws MatchException {
+ setType(Types.instantiate(expression.getType(), parameter));
+ }
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
IVal val = expression.toVal(context, w);
return val.createSpecialization(parameter);
}
return pattern;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- pattern.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
this.value = value;
this.in = in;
}
-
- @Override
- public void collectRefs(final TObjectIntHashMap<Object> allRefs, final TIntHashSet refs) {
- value.collectRefs(allRefs, refs);
- in.collectRefs(allRefs, refs);
- }
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
this.in = in;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- ruleset.collectRefs(allRefs, refs);
- in.collectRefs(allRefs, refs);
- }
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
ruleset.collectVars(allVars, vars);
in.collectVars(allVars, vars);
}
+
@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<Variable> vars) {
ruleset.collectFreeVariables(vars);
in.collectFreeVariables(vars);
}
+
@Override
public Expression resolve(TranslationContext context) {
if(context.currentRuleset != null) {
public ECHRRulesetConstructor(CHRRuleset ruleset) {
this.ruleset = ruleset;
}
-
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- ruleset.collectRefs(allRefs, refs);
- }
+
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
ruleset.collectVars(allVars, vars);
}
+
@Override
protected void updateType() throws MatchException {
throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given.");
}
+
@Override
public IVal toVal(CompilationContext context, CodeWriter w) {
return ruleset.generateCode(w);
}
+
@Override
public void collectFreeVariables(THashSet<Variable> vars) {
ruleset.collectFreeVariables(vars);
}
+
@Override
public Expression resolve(TranslationContext context) {
context.pushFrame();
this.query = query;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- query.collectRefs(allRefs, refs);
- expression.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
query.collectVars(allVars, vars);
import gnu.trove.set.hash.TIntHashSet;
public class EConstant extends Expression {
- SCLValue value;
+ public SCLValue value;
Type[] typeParameters;
public EConstant(SCLValue value, Type ... typeParameters) {
return this;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- int id = allRefs.get(value);
- if(id >= 0)
- refs.add(id);
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
- public void toString(StringBuilder b, TypeUnparsingContext tuc) {
- Name name = value.getName();
- if(name.module.equals("Builtin") || name.module.equals("Prelude"))
- b.append(name.name);
- else
- b.append(name);
+ public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+ Name name = value.getName();
+ if(name.module.equals("Builtin") || name.module.equals("Prelude"))
+ b.append(name.name);
+ else
+ b.append(name);
/*for(Type type : typeParameters) {
b.append(" <");
b.append(type.toString(tuc));
return query;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- query.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
return transformer.transform(this);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- for(Equation equation : equations)
- equation.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
for(Equation equation : equations)
setType(type);
}
- public EError() {
+ public EError() {
}
public EError(long loc) {
this(loc, Types.metaVar(Kinds.STAR));
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
- @Override
- protected void updateType() throws MatchException {
- setType(Types.metaVar(Kinds.STAR));
- }
-
- @Override
- public IVal toVal(CompilationContext context, CodeWriter w) {
+ @Override
+ protected void updateType() throws MatchException {
+ setType(Types.metaVar(Kinds.STAR));
+ }
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
throw new UnsupportedOperationException();
}
return value;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
-
- public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+ public void toString(StringBuilder b, TypeUnparsingContext tuc) {
b.append(value);
}
- @Override
- protected void updateType() throws MatchException {
- throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
- }
-
- @Override
- public IVal toVal(CompilationContext context, CodeWriter w) {
- ModuleWriter mw = w.getModuleWriter();
- return mw.getExternalConstant(value, getType());
+ @Override
+ protected void updateType() throws MatchException {
+ throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
+ }
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
+ ModuleWriter mw = w.getModuleWriter();
+ return mw.getExternalConstant(value, getType());
}
@Override
((EFieldAccess)parent).lastAccessor = false;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- parent.collectRefs(allRefs, refs);
- accessor.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
super(loc);
this.constraint = constraint;
}
-
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- }
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
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
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- condition.collectVars(allVars, vars);
+ @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
+ protected void updateType() throws MatchException {
+ setType(then_.getType());
+ }
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
IVal conditionVal = condition.toVal(context, w);
CodeWriter joinPoint = w.createBlock(getType());
CodeWriter thenBlock = w.createBlock();
this.value = value;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
this(loc, new Case(new Expression[] {pat}, exp));
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
for(Case case_ : cases)
- case_.collectRefs(allRefs, refs);
- }
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Case case_ : cases)
case_.collectVars(allVars, vars);
- }
+ }
- public Expression decomposeMatching() {
- Expression[] patterns = cases[0].patterns;
+ public Expression decomposeMatching() {
+ Expression[] patterns = cases[0].patterns;
int arity = patterns.length;
// Simple cases
this.value = value;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- value.collectRefs(allRefs, refs);
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
+ value.collectVars(allVars, vars);
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
-
- @Override
- protected void updateType() throws MatchException {
- setType(Types.forAll(parameters, value.getType()));
- }
- @Override
+ @Override
+ protected void updateType() throws MatchException {
+ setType(Types.forAll(parameters, value.getType()));
+ }
+
+ @Override
public IVal toVal(CompilationContext context, CodeWriter w) {
return lambdaToVal(context, w);
}
this.assignments = assignments;
this.in = in;
}
-
- @Override
- public void collectRefs(final TObjectIntHashMap<Object> allRefs, final TIntHashSet refs) {
- for(Assignment assign : assignments)
- assign.value.collectRefs(allRefs, refs);
- in.collectRefs(allRefs, refs);
- }
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
this.qualifier = qualifier;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- head.collectRefs(allRefs, refs);
- qualifier.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
public Expression[] getComponents() {
return components;
}
-
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- for(Expression component : components)
- component.collectRefs(allRefs, refs);
- }
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
return value;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
}
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- }
-
- public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+ public void toString(StringBuilder b, TypeUnparsingContext tuc) {
b.append(value);
}
-
- @Override
- protected void updateType() throws MatchException {
- setType(value.getType());
- }
- @Override
- public IVal toVal(CompilationContext context, CodeWriter w) {
+ @Override
+ protected void updateType() throws MatchException {
+ setType(value.getType());
+ }
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
return value;
}
this.cases = cases;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
for(Expression s : scrutinee)
- s.collectRefs(allRefs, refs);
- for(Case case_ : cases)
- case_.collectRefs(allRefs, refs);
- }
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- for(Expression s : scrutinee)
s.collectVars(allVars, vars);
- for(Case case_ : cases)
+ for(Case case_ : cases)
case_.collectVars(allVars, vars);
- }
-
- @Override
- protected void updateType() {
- setType(cases[0].value.getType());
- }
+ }
+
+ @Override
+ protected void updateType() {
+ setType(cases[0].value.getType());
+ }
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
+ ArrayList<Row> rows = new ArrayList<Row>(cases.length);
+ for(Case case_ : cases)
+ rows.add(new Row(case_.patterns, case_.value));
+
+ IVal[] scrutineeVals = new IVal[scrutinee.length];
+ for(int i=0;i<scrutinee.length;++i)
+ scrutineeVals[i] = scrutinee[i].toVal(context, w);
- @Override
- public IVal toVal(CompilationContext context, CodeWriter w) {
- ArrayList<Row> rows = new ArrayList<Row>(cases.length);
- for(Case case_ : cases)
- rows.add(new Row(case_.patterns, case_.value));
-
- IVal[] scrutineeVals = new IVal[scrutinee.length];
- for(int i=0;i<scrutinee.length;++i)
- scrutineeVals[i] = scrutinee[i].toVal(context, w);
-
- CodeWriter joinPoint = w.createBlock(getType());
- CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function
- PatternMatchingCompiler.split(w, context, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);
- failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
- w.continueAs(joinPoint);
- return w.getParameters()[0];
+ CodeWriter joinPoint = w.createBlock(getType());
+ CodeWriter failurePoint = w.createBlock(); // TODO generate only one failurePoint per function
+ PatternMatchingCompiler.split(w, context, scrutineeVals, joinPoint.getContinuation(), failurePoint.getContinuation(), rows);
+ failurePoint.throw_(location, Throw.MatchingException, "Matching failure at: " + toString());
+ w.continueAs(joinPoint);
+ return w.getParameters()[0];
}
@Override
this.value = value;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
}
in.collectFreeVariables(vars);
}
-
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- for(DatalogRule rule : rules) {
- for(Expression parameter : rule.headParameters)
- parameter.collectRefs(allRefs, refs);
- rule.body.collectRefs(allRefs, refs);
- }
- in.collectRefs(allRefs, refs);
- }
-
+
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
}
in.collectVars(allVars, vars);
}
-
+
@Override
public void collectEffects(THashSet<Type> effects) {
throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectEffects.");
this.query = query;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- expression.collectRefs(allRefs, refs);
- query.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
this.effect = effect;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- value.collectRefs(allRefs, refs);
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
+ value.collectVars(allVars, vars);
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
- public Expression decomposeMatching() {
+ public Expression decomposeMatching() {
value = value.decomposeMatching();
return this;
}
this.in = in;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- value.collectRefs(allRefs, refs);
- in.collectRefs(allRefs, refs);
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
+ value.collectVars(allVars, vars);
+ in.collectVars(allVars, vars);
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- in.collectVars(allVars, vars);
- }
@Override
protected void updateType() throws MatchException {
setType(in.getType());
}
-
- @Override
- public IVal toVal(CompilationContext context, CodeWriter w) {
- IVal valueVal = value.toVal(context, w);
- if(variable != null)
- variable.setVal(valueVal);
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
+ IVal valueVal = value.toVal(context, w);
+ if(variable != null)
+ variable.setVal(valueVal);
return in.toVal(context, w);
}
this.seed = seed;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- {
- int ref = allRefs.get(TRANSFORMATION_RULES_TYPECHECKED);
- if(ref >= 0)
- refs.add(ref);
- }
- seed.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
this.type = type;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- value.collectRefs(allRefs, refs);
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
+ value.collectVars(allVars, vars);
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- value.collectVars(allVars, vars);
- }
- @Override
- protected void updateType() throws MatchException {
- setType(type);
- }
+ @Override
+ protected void updateType() throws MatchException {
+ setType(type);
+ }
@Override
public void collectFreeVariables(THashSet<Variable> vars) {
this.variable = variable;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars,
+ TIntHashSet vars) {
+ int id = allVars.get(variable);
+ if(id >= 0)
+ vars.add(id);
}
-
- @Override
- public void collectVars(TObjectIntHashMap<Variable> allVars,
- TIntHashSet vars) {
- int id = allVars.get(variable);
- if(id >= 0)
- vars.add(id);
- }
- public void toString(StringBuilder b, TypeUnparsingContext tuc) {
+ public void toString(StringBuilder b, TypeUnparsingContext tuc) {
b.append(variable == null ? "???" : variable.toString());
}
this.pattern = pattern;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- expression.collectRefs(allRefs, refs);
- pattern.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
expression.collectVars(allVars, vars);
this.variables = variables;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- query.collectRefs(allRefs, refs);
- action.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs;
import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.visitors.CollectRefsVisitor;
import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
import org.simantics.scl.compiler.elaboration.query.QAtom;
import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
expression = new ESimpleLet(location, null, expression, new ELiteral(NoRepConstant.PUNIT));
return expression;
}
-
- /**
- * Checks the type of the expression against the given type. Adds type
- * applications and lambdas if needed.
- */
- public final Expression checkType(TypingContext context, Type requiredType) {
- //System.out.println("checkType: " + this + " :: " + requiredType);
- if(!context.isInPattern()) {
- requiredType = Types.canonical(requiredType);
- if(requiredType instanceof TForAll) {
+
+ /**
+ * Checks the type of the expression against the given type. Adds type
+ * applications and lambdas if needed.
+ */
+ public final Expression checkType(TypingContext context, Type requiredType) {
+ //System.out.println("checkType: " + this + " :: " + requiredType);
+ if(!context.isInPattern()) {
+ requiredType = Types.canonical(requiredType);
+ if(requiredType instanceof TForAll) {
TForAll forAll = (TForAll)requiredType;
TVar var = forAll.var;
TVar newVar = Types.var(var.getKind());
requiredType = Types.canonical(forAll.type).replace(var, newVar);
return new ELambdaType(new TVar[] {newVar}, checkType(context, requiredType));
}
- while(requiredType instanceof TFun) {
+ while(requiredType instanceof TFun) {
TFun fun = (TFun)requiredType;
if(fun.domain instanceof TPred) { // No need to canonicalize
ArrayList<Variable> constraints = new ArrayList<Variable>(2);
context.pushEffectUpperBound(location, fun.effect);
Expression expr = checkType(context, fun.range);
context.popEffectUpperBound();
-
+
// Wrap
Variable var = new Variable("punit", Types.PUNIT);
return new ESimpleLambda(location, var, fun.effect, expr);
else
break;
}
- }
- return checkBasicType(context, requiredType);
- }
+ }
+ return checkBasicType(context, requiredType);
+ }
+
+ public final void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ accept(new CollectRefsVisitor(allRefs, refs));
+ }
- public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
- public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
+ public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
- public void forVariableUses(VariableProcedure procedure) {
+ public final void forVariableUses(VariableProcedure procedure) {
accept(new ForVariablesUsesVisitor(procedure));
}
this.expressions = expressions;
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- for(GuardedExpression expression : expressions) {
- for(Expression guard : expression.guards)
- guard.collectRefs(allRefs, refs);
- expression.value.collectRefs(allRefs, refs);
- }
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
fieldName.collectFreeVariables(vars);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- fieldName.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
this.accessSeparator = accessSeparator;
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- }
-
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
}
pattern.checkTypeAsPattern(context, value.getType());
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- value.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
pattern.checkTypeAsPattern(context, componentType);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- value.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
condition.checkType(context, Types.BOOLEAN);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- condition.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
public abstract class ListQualifier extends Symbol {
public abstract void checkType(TypingContext context);
- public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void collectFreeVariables(THashSet<Variable> vars);
/**
a.checkType(context);
b.checkType(context);
}
-
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- a.collectRefs(allRefs, refs);
- b.collectRefs(allRefs, refs);
- }
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
}
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- left.collectRefs(allRefs, refs);
- transformer.collectRefs(allRefs, refs);
- if(by != null)
- by.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
--- /dev/null
+package org.simantics.scl.compiler.elaboration.expressions.visitors;
+
+import org.simantics.scl.compiler.elaboration.expressions.EConstant;
+import org.simantics.scl.compiler.elaboration.expressions.ETransformation;
+import org.simantics.scl.compiler.elaboration.expressions.StandardExpressionVisitor;
+import org.simantics.scl.compiler.elaboration.query.QAtom;
+import org.simantics.scl.compiler.elaboration.relations.CompositeRelation;
+import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
+
+import gnu.trove.map.hash.TObjectIntHashMap;
+import gnu.trove.set.hash.TIntHashSet;
+
+public class CollectRefsVisitor extends StandardExpressionVisitor {
+ private final TObjectIntHashMap<Object> allRefs;
+ private final TIntHashSet refs;
+
+ public CollectRefsVisitor(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ this.allRefs = allRefs;
+ this.refs = refs;
+ }
+
+ @Override
+ public void visit(ETransformation expression) {
+ {
+ int ref = allRefs.get(ETransformation.TRANSFORMATION_RULES_TYPECHECKED);
+ if(ref >= 0)
+ refs.add(ref);
+ }
+ super.visit(expression);
+ }
+
+ @Override
+ public void visit(EConstant expression) {
+ int id = allRefs.get(expression.value);
+ if(id >= 0)
+ refs.add(id);
+ }
+
+ @Override
+ public void visit(QAtom query) {
+ collectRelationRefs(query.relation);
+ super.visit(query);
+ }
+
+ private void collectRelationRefs(SCLRelation relation) {
+ if(relation instanceof CompositeRelation) {
+ for(SCLRelation subrelation : ((CompositeRelation) relation).getSubrelations())
+ collectRelationRefs(subrelation);
+ }
+ else {
+ int id = allRefs.get(relation);
+ if(id >= 0)
+ refs.add(id);
+ }
+ }
+}
query.checkType(context);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- for(Query query : queries)
- query.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
for(Query query : queries)
query.checkType(context);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- query.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
}
}
- private static void collectRefs(SCLRelation relation, TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- if(relation instanceof CompositeRelation) {
- for(SCLRelation subrelation : ((CompositeRelation) relation).getSubrelations())
- collectRefs(subrelation, allRefs, refs);
- }
- else {
- int id = allRefs.get(relation);
- if(id >= 0)
- refs.add(id);
- }
- }
-
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- collectRefs(relation, allRefs, refs);
- for(Expression parameter : parameters)
- parameter.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
elseQuery.collectFreeVariables(vars);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- condition.collectRefs(allRefs, refs);
- thenQuery.collectRefs(allRefs, refs);
- elseQuery.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
condition.collectVars(allVars, vars);
parameter.collectFreeVariables(vars);
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- for(Expression parameter : parameters)
- parameter.collectRefs(allRefs, refs);
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {
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.visitors.CollectRefsVisitor;
import org.simantics.scl.compiler.elaboration.expressions.visitors.ForVariablesUsesVisitor;
import org.simantics.scl.compiler.elaboration.query.compilation.ConstraintCollectionContext;
import org.simantics.scl.compiler.elaboration.query.compilation.DerivateException;
public static final Query[] EMPTY_ARRAY = new Query[0];
public abstract void collectFreeVariables(THashSet<Variable> vars);
- public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void checkType(TypingContext context);
public void forVariables(VariableProcedure procedure) {
accept(new ForVariablesUsesVisitor(procedure));
}
+ public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ accept(new CollectRefsVisitor(allRefs, refs));
+ }
}
throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectConstraints.");
}
- @Override
- public void collectRefs(TObjectIntHashMap<Object> allRefs,
- TIntHashSet refs) {
- throw new InternalCompilerError(location, getClass().getSimpleName() + " does not support collectRefs.");
- }
-
@Override
public void collectVars(TObjectIntHashMap<Variable> allVars,
TIntHashSet vars) {