public void ConstrainVars(Var v1, Var v2) { Check( ((v1 is ScalarVar) && (v2 is ScalarVar)) || ((v1 is VectorVar) && (v2 is VectorVar)), "Incompatible variable kinds " + v1.ToString() + " and " + v2.ToString()); ConstrainVars(v1.ToString(), v2.ToString()); }
public bool AreVarsEqual(Var x, Var y) { string s = x.ToString(); if (ContainsKey(s)) { return(this[s].Equals(y.ToString())); } else { Add(s, y.ToString()); return(true); } }
public Constraint GetRecursiveVar(Constraint c, Stack <Constraint> visited) { if (!(c is Var)) { return(null); } Var v = c as Var; Constraint[] a = visited.ToArray(); Relation prevRelation = null; for (int i = 0; i < a.Length; ++i) { Constraint tmp = a[i]; if (tmp is Var) { Var v2 = tmp as Var; if (v2.ToString().Equals(v.ToString())) { if (prevRelation == null) { // Recursive variable Trace.Assert(c is VectorVar); return(c); } return(new RecursiveRelation()); } } else if (tmp is Relation) { prevRelation = tmp as Relation; } } return(null); }
public void AddVarConstraint(Var v, Constraint c) { if (c is RecursiveRelation) { return; } AddConstraintToList(c, GetConstraints(v.ToString())); }
public Constraint GetUnifierFor(Var v) { Constraint ret = GetUnifierFor(v.ToString()); if (ret == null) { return(v); } return(ret); }
public bool ContainsVar(Var v) { foreach (Constraint c in this) { if (c.EqualsVar(v.ToString())) { return(true); } } return(false); }
public Constraint ResolveRelationConstraint(Constraint c, Stack <Constraint> visited, Relation parent, VarNameList topVars, VarNameList allVars) { VarNameList nonGenerics = parent.GetNonGenericsForChildren(); if (c is Var) { Var v = c as Var; Constraint u = Resolve(v, visited, parent); if (u is Relation) { Relation r = u as Relation; // Make sure we don't add variables to the non-generics // list which occured in a duplicate. if (!topVars.Contains(v)) { VarNameList subVars = r.GetAllVarNames(); foreach (string s in subVars) { if (allVars.Contains(s)) { nonGenerics.Add(s); } } allVars.AddRange(subVars); } else { Log("duplicate of variable " + v.ToString() + ", with unifier " + r.ToString()); QueueForRenamingOfGenerics(r); } } else if (u is Var) { nonGenerics.Add(u as Var); } topVars.Add(v); return(u); } else { Constraint u = Resolve(c, visited, parent); // non-vars should not resolve to vars Trace.Assert(!(u is Var)); if (u is Relation) { Relation r = u as Relation; VarNameList subVars = r.GetAllVarNames(); foreach (string s in subVars) { if (allVars.Contains(s)) { nonGenerics.Add(s); } } allVars.AddRange(subVars); } return(u); } }
public bool Contains(Var v) { return(base.Contains(v.ToString())); }
public void Add(Var v) { Add(v.ToString()); }