1 package org.simantics.scl.compiler.internal.elaboration.subsumption2;
3 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
4 import org.simantics.scl.compiler.internal.types.effects.EffectIdMap;
5 import org.simantics.scl.compiler.types.TMetaVar;
6 import org.simantics.scl.compiler.types.exceptions.UnificationException;
7 import org.simantics.scl.compiler.types.util.Polarity;
9 public class SubsumptionGraph {
10 public static final int REMOVED = Integer.MAX_VALUE-1;
12 public static class LowerBoundSource {
13 public final long location;
14 public final int lower;
15 public final LowerBoundSource next;
16 public LowerBoundSource(long location, int lower, LowerBoundSource next) {
17 this.location = location;
23 public static abstract class Node {
24 int lowerBound = EffectIdMap.MIN;
25 int upperBound = EffectIdMap.MAX;
27 LowerBoundSource lowerBoundSource;
29 public void addLowerBoundSource(long location, int lower) {
30 lowerBoundSource = new LowerBoundSource(location, lower, lowerBoundSource);
34 public static class VarNode extends Node {
40 public VarNode(TMetaVar origin) {
44 public Polarity getPolarity() {
45 return origin.getPolarity();
48 public void replaceBy(VarNode replacement) {
50 origin.setRef(replacement.origin);
51 } catch(UnificationException e) {
52 throw new InternalCompilerError(e);
56 for(Sub cur=upper;cur!=null;cur=cur.aNext) {
61 last.aNext = replacement.upper;
62 if(last.aNext != null)
63 last.aNext.aPrev = last;
64 replacement.upper = upper;
68 for(Sub cur=lower;cur!=null;cur=cur.bNext) {
73 last.bNext = replacement.lower;
74 if(last.bNext != null)
75 last.bNext.bPrev = last;
76 replacement.lower = lower;
80 PartOfUnion last = null;
81 for(PartOfUnion cur=partOf;cur!=null;cur=cur.bNext) {
86 last.aNext = replacement.partOf;
87 if(last.aNext != null)
88 last.aNext.bPrev = last;
89 replacement.partOf = partOf;
95 public void removeConstantNode(EffectIdMap effectIds, int constValue) {
97 origin.setRef(effectIds.toType(constValue));
98 } catch (UnificationException e) {
99 throw new InternalCompilerError(e);
101 for(Sub cur=lower;cur!=null;cur=cur.bNext)
103 for(Sub cur=upper;cur!=null;cur=cur.aNext)
105 for(PartOfUnion cur=partOf;cur!=null;cur=cur.aNext) {
107 cur.b.constPart |= constValue;
113 public static class UnionNode extends Node {
118 public UnionNode(long location, int constPart) {
119 this.location = location;
120 this.constPart = constPart;
121 this.lowerBound = constPart;
124 public void remove() {
125 for(Sub cur=lower;cur!=null;cur=cur.bNext)
127 for(PartOfUnion cur=parts;cur!=null;cur=cur.bNext)
133 public static class Sub {
141 public Sub(VarNode a, Node b) {
156 public void detachA() {
165 public void detachB() {
174 public void remove() {
180 public static class PartOfUnion {
188 public PartOfUnion(VarNode a, UnionNode b) {
203 public void detachA() {
212 public void detachB() {
221 public void remove() {