Exemplo n.º 1
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);
            }
        }