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%2Fchr%2Frelations%2FCHRConstraint.java;h=ee73477912e3d8ff385f83a29e33562eae8ce0a2;hp=8612fd766ade4410ad9b1706f887e2504e29273b;hb=6d233d1b05176e40f634766537082d2a2ec65fd0;hpb=a2df536f7fc878982c6c960a79ed49f350cddc6f diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java index 8612fd766..ee7347791 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java @@ -34,13 +34,14 @@ import gnu.trove.map.hash.TIntObjectHashMap; public class CHRConstraint extends Symbol implements CHRRelation { public final String name; public final Type[] parameterTypes; + public String[] fieldNames; public boolean implicitlyDeclared; // Analysis - public int firstPriorityAdded; + //public int firstPriorityAdded; public int lastPriorityAdded; - public int firstPriorityRemoved; + //public int firstPriorityRemoved; public int lastPriorityRemoved; // Transient info @@ -56,11 +57,9 @@ public class CHRConstraint extends Symbol implements CHRRelation { public Constant addProcedure; public Constant removeProcedure; - public TIntObjectHashMap indices; + public String nextContainerFieldName; - // Query plans - public int minimumPriority = Integer.MAX_VALUE; - public int nextPriority = Integer.MAX_VALUE; // used in code generation + public TIntObjectHashMap indices; public static class IndexInfo { public final int indexMask; @@ -86,7 +85,7 @@ public class CHRConstraint extends Symbol implements CHRRelation { JavaTypeTranslator jtt = context.javaTypeTranslator; this.parentRuleset = parentRuleset; - this.factClassName = parentRuleset.runtimeRulesetName + "$" + name; + this.factClassName = parentRuleset.runtimeRulesetClassName + "$" + name; TCon factTypeConstructor = Types.con(parentRuleset.runtimeRulesetType.module, parentRuleset.runtimeRulesetType.name + "$" + name); this.factType = Types.apply(factTypeConstructor, TVar.EMPTY_ARRAY); this.factTypeDesc = TypeDesc.forClass(factClassName); @@ -126,6 +125,11 @@ public class CHRConstraint extends Symbol implements CHRRelation { if(context.module != null) // for unit testing context.module.addTypeDescriptor(factTypeConstructor.name, new StandardTypeConstructor(factTypeConstructor, TVar.EMPTY_ARRAY, factTypeDesc)); + + // next container + if(parentRuleset.extensible) { + nextContainerFieldName = CHRCodeGenerationConstants.nextContainerName(name); + } } @Override @@ -161,11 +165,11 @@ public class CHRConstraint extends Symbol implements CHRRelation { Constant accessIndex; if(indexMask == 0) { accessIndex = new CallJava(TVar.EMPTY_ARRAY, Types.PROC, factType, new Type[] {parentRuleset.runtimeRulesetType}, - null, new FieldRef(parentRuleset.runtimeRulesetName, name + "$" + indexName, factTypeDesc), null); + null, new FieldRef(parentRuleset.runtimeRulesetClassName, name + "$" + indexName, factTypeDesc), null); } else { Type[] keyTypes = keyTypeList.toArray(new Type[keyTypeList.size()]); - accessIndex = new JavaMethod(true, parentRuleset.runtimeRulesetName, name + "$" + indexName, Types.PROC, factType, keyTypes); + accessIndex = new JavaMethod(true, parentRuleset.runtimeRulesetClassName, name + "$" + indexName, Types.PROC, factType, keyTypes); } return new IndexInfo( indexMask, @@ -176,13 +180,17 @@ public class CHRConstraint extends Symbol implements CHRRelation { ); } - public IVal fetchFromIndex(CompilationContext context, int boundMask) { + public IndexInfo getOrCreateIndex(CompilationContext context, int boundMask) { IndexInfo indexInfo = indices.get(boundMask); if(indexInfo == null) { indexInfo = createIndexInfo(context, boundMask); indices.put(boundMask, indexInfo); } - return indexInfo.firstFact; + return indexInfo; + } + + public IVal fetchFromIndex(CompilationContext context, int boundMask) { + return getOrCreateIndex(context, boundMask).firstFact; } public Constant nextElement(CompilationContext context, int boundMask) { @@ -191,7 +199,7 @@ public class CHRConstraint extends Symbol implements CHRRelation { indexInfo = createIndexInfo(context, boundMask); indices.put(boundMask, indexInfo); } - return indexInfo.nextFact; + return getOrCreateIndex(context, boundMask).nextFact; } @@ -222,4 +230,9 @@ public class CHRConstraint extends Symbol implements CHRRelation { else return w.apply(location, accessor, fact); } + + @Override + public String[] getFieldNames() { + return fieldNames; + } }