Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void AddVarConstraint(Var v, Constraint c)
        {
            if (c is RecursiveRelation)
            {
                return;
            }

            AddConstraintToList(c, GetConstraints(v.ToString()));
        }
Exemplo n.º 5
0
        public Constraint GetUnifierFor(Var v)
        {
            Constraint ret = GetUnifierFor(v.ToString());

            if (ret == null)
            {
                return(v);
            }
            return(ret);
        }
Exemplo n.º 6
0
 public bool ContainsVar(Var v)
 {
     foreach (Constraint c in this)
     {
         if (c.EqualsVar(v.ToString()))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
 public bool Contains(Var v)
 {
     return(base.Contains(v.ToString()));
 }
Exemplo n.º 9
0
 public void Add(Var v)
 {
     Add(v.ToString());
 }