Exemplo n.º 1
0
 public NormalSubstituter(Substitution subst, Substitution forold)
     : base()
 {
     Contract.Requires(subst != null);
     this.always = subst;
     this.forold = forold;
 }
Exemplo n.º 2
0
        private void Ask(LinkedList<Expression> goals, KnowledgeBase context, Substitution theta, ProverCache cache, VariableRenamer renamer, 
            bool askOne, HashSet<Substitution> results, HashSet<Fact> alreadyAsking)
        {
            if (goals.Count == 0)
                results.Add(theta);
            else
            {
                Expression literal = goals.First.Value;
                goals.RemoveFirst();
                Expression qPrime = Substituter.Substitute(literal, theta);

                var fact = qPrime as Fact;
                if (fact != null && fact.RelationName == GameContainer.Parser.TokDistinct)
                    AskDistinct(fact, goals, context, theta, cache, renamer, askOne, results, alreadyAsking);
                else
                {
                    var negation = qPrime as Negation;
                    if (negation != null)
                        AskNot(negation, goals, context, theta, cache, renamer, askOne, results, alreadyAsking);
                    else
                    {
                        var disjunction = qPrime as Disjunction;
                        if (disjunction != null)
                            AskOr(disjunction, goals, context, theta, cache, renamer, askOne, results, alreadyAsking);
                        else
                        {
                            var sentence = (Fact) qPrime;
                            AskSentence(sentence, goals, context, theta, cache, renamer, askOne, results, alreadyAsking);
                        }
                    }
                }

                goals.AddFirst(literal);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Hide data in buffer
        /// </summary>
        /// <param name="buffer">Buffer in which data is to be hidden</param>
        /// <param name="bufferLen">Length of buffer</param>
        protected virtual unsafe int HideData(byte *buffer, int bufferLen)
        {
            int offset = 0;

            while ((offset + 8) < bufferLen)
            {
                iter++;

                int next = this._message.NextByte();
                if (next == -1)
                {
                    this._processing = ProcessingType.Done;
                    ///No more data to hide
                    break;
                }
                byte data = (byte)next;

                ///Get 8 bytes of cover message and
                ///hide a byte of data in it
                for (int i = 0; i < 8; i++)
                {
                    byte cover = buffer[offset];

                    ///Right shift the data to get next byte and AND with 1 = 00000001
                    Substitution.LsbSubstitute(ref cover, (byte)(((data >> i) & 0x1)));

                    buffer[offset] = cover;
                    offset++;
                }
            }

            return(offset);
        }
Exemplo n.º 4
0
 public NormalSubstituter(Substitution subst)
     : base()
 {
     Contract.Requires(subst != null);
     this.always = subst;
     this.forold = Substituter.SubstitutionFromHashtable(new Dictionary <Variable, Expr>());
 }
Exemplo n.º 5
0
 public CodeCopier(Dictionary<Variable, Expr> substMap, Dictionary<Variable, Expr> oldSubstMap)
 {
     Contract.Requires(oldSubstMap != null);
       Contract.Requires(substMap != null);
       Subst = Substituter.SubstitutionFromHashtable(substMap);
       OldSubst = Substituter.SubstitutionFromHashtable(oldSubstMap);
 }
Exemplo n.º 6
0
        // ----------------------------- Substitutions for Cmd -------------------------------

        /// <summary>
        /// Apply a substitution to a command.  Any variables not in domain(subst)
        /// is not changed.  The substitutions apply within the "old", but the "old"
        /// expression remains.
        /// </summary>
        public static Cmd Apply(Substitution subst, Cmd cmd)
        {
            Contract.Requires(subst != null);
            Contract.Requires(cmd != null);
            Contract.Ensures(Contract.Result <Cmd>() != null);
            return((Cmd) new NormalSubstituter(subst).Visit(cmd));
        }
Exemplo n.º 7
0
        // ----------------------------- Substitutions for CmdSeq -------------------------------

        /// <summary>
        /// Apply a substitution to a command sequence.  Any variables not in domain(subst)
        /// is not changed.  The substitutions apply within the "old", but the "old"
        /// expression remains.
        /// </summary>
        public static List <Cmd> Apply(Substitution subst, List <Cmd> cmdSeq)
        {
            Contract.Requires(subst != null);
            Contract.Requires(cmdSeq != null);
            Contract.Ensures(Contract.Result <Cmd>() != null);
            return(new NormalSubstituter(subst).VisitCmdSeq(cmdSeq));
        }
Exemplo n.º 8
0
 /**
  * Creates an identical substitution.
  *
  * @return A new, identical substitution.
  */
 public Substitution Copy()
 {
     var copy = new Substitution();
     foreach (var kv in _contents)
     copy._contents[kv.Key] = kv.Value;
     return copy;
 }
Exemplo n.º 9
0
        // ----------------------------- Substitutions for Expr -------------------------------

        /// <summary>
        /// Apply a substitution to an expression.  Any variables not in domain(subst)
        /// is not changed.  The substitutions apply within the "old", but the "old"
        /// expression remains.
        /// </summary>
        public static Expr Apply(Substitution subst, Expr expr)
        {
            Contract.Requires(subst != null);
            Contract.Requires(expr != null);
            Contract.Ensures(Contract.Result <Expr>() != null);
            return((Expr) new NormalSubstituter(subst).Visit(expr));
        }
Exemplo n.º 10
0
        public static void SubstituteIncarnationInInstantiationSources(Cmd cmd, Substitution incarnationSubst)
        {
            QKeyValue iter = null;

            if (cmd is AssignCmd assignCmd)
            {
                iter = assignCmd.Attributes;
            }
            else if (cmd is PredicateCmd predicateCmd)
            {
                iter = predicateCmd.Attributes;
            }
            while (iter != null)
            {
                if (iter.Key == "inst_add")
                {
                    var label    = iter.Params[0] as string;
                    var instance = iter.Params[1] as Expr;
                    if (label != null && instance != null)
                    {
                        instance = Substituter.Apply(incarnationSubst, instance);
                        iter.ClearParams();
                        iter.AddParams(new List <object> {
                            label, instance
                        });
                    }
                }
                iter = iter.Next;
            }
        }
            private void TryElimination(IEnumerable <Variable> extraDefinedVariables)
            {
                bool Defined(Variable v) => varToExpr.ContainsKey(v) || extraDefinedVariables.Contains(v);

                bool changed;

                do
                {
                    changed = false;
                    var remainingAssignments = new List <Assignment>();
                    foreach (var assignment in assignments)
                    {
                        if (!Defined(assignment.Var) &&
                            VariableCollector.Collect(assignment.Expr).Intersect(AllIntroducedVariables).All(Defined))
                        {
                            varToExpr[assignment.Var] = SubstitutionHelper.Apply(varToExpr, assignment.Expr);
                            changed = true;
                        }
                        else
                        {
                            remainingAssignments.Add(assignment);
                        }
                    }

                    Substitution sub = Substituter.SubstitutionFromDictionary(varToExpr);
                    foreach (var assignment in remainingAssignments)
                    {
                        assignment.Expr = Substituter.Apply(sub, assignment.Expr);
                    }

                    assignments = remainingAssignments;
                    assumes     = SubstitutionHelper.Apply(sub, assumes).ToList();
                } while (changed);
            }
Exemplo n.º 12
0
        public IResMemberTerm Substitute(Substitution subst)
        {
            var obj = _obj.Substitute(subst);
            var memberSpec = _memberSpec.Substitute(subst);

            var objType = obj.Type;
            var dataType = objType;
            if (objType is ResFreqQualType)
            {
                dataType = ((ResFreqQualType)objType).Type;
            }
            if (dataType is Spark.Resolve.ResDummyTypeArg)
            {
                var typeArg = (Spark.Resolve.ResDummyTypeArg)dataType;
                if(typeArg.ConcreteType != null )
                    dataType = typeArg.ConcreteType;
            }
            if (dataType is ResErrorTerm)
            {
            }
            else if (dataType is IResContainerRef)
            {
                var containerRef = (IResContainerRef)dataType;
                memberSpec = containerRef.FindMember(memberSpec).EffectiveSpec;
            }

            return new ResMemberBind(
                _range,
                obj,
                memberSpec);
        }
Exemplo n.º 13
0
        private List <Cmd> InlineYieldLoopInvariants(List <CallCmd> yieldInvariants)
        {
            var inlinedYieldInvariants = new List <Cmd>();

            foreach (var callCmd in yieldInvariants)
            {
                var yieldInvariant = civlTypeChecker.procToYieldInvariant[callCmd.Proc];
                if (layerNum == yieldInvariant.LayerNum)
                {
                    Dictionary <Variable, Expr> map = callCmd.Proc.InParams.Zip(callCmd.Ins)
                                                      .ToDictionary(x => x.Item1, x => x.Item2);
                    Substitution subst = Substituter.SubstitutionFromDictionary(map);
                    foreach (Requires req in callCmd.Proc.Requires)
                    {
                        var newExpr = Substituter.Apply(subst, req.Condition);
                        if (req.Free)
                        {
                            inlinedYieldInvariants.Add(new AssumeCmd(req.tok, newExpr, req.Attributes));
                        }
                        else
                        {
                            inlinedYieldInvariants.Add(new AssertCmd(req.tok, newExpr, req.Attributes));
                        }
                    }
                }
            }

            return(inlinedYieldInvariants);
        }
Exemplo n.º 14
0
        public static Substitution Unify(Fact x, Fact y)
        {
            Substitution theta = new Substitution();
            bool isGood = UnifyTerm(x.ToTerm(), y.ToTerm(), theta);

            return isGood ? theta : null;
        }
Exemplo n.º 15
0
        public IFormula visit(ExistentialFormula f)
        {
            if (f.f is Or)
            {
                var c  = f.f as Or;
                var i1 = c.f1.ffreeVariables.Contains(f.var);
                var i2 = c.f2.ffreeVariables.Contains(f.var);

                if (i1 && i2)
                {
                    var newVar = srs.getFreshVariable(f.var);
                    var ns     = new Substitution(f.var, new Variable(newVar));
                    return(new Or(
                               new ExistentialFormula(f.var, c.f1, f.attributes, f.triggers).visit(this),
                               new ExistentialFormula(newVar, c.f2.substitute(ns), f.attributes, from ts in f.triggers select from t in ts select t.substitute(ns)).visit(
                                   this)
                               ));
                }
                else if (i1)
                {
                    return(new Or(new ExistentialFormula(f.var, c.f1, f.attributes, f.triggers).visit(this), c.f2.visit(this)));
                }
                else if (i2)
                {
                    return(new Or(c.f1.visit(this), new ExistentialFormula(f.var, c.f2, f.attributes, f.triggers).visit(this)));
                }
                else
                {
                    return(c.visit(this));
                }
            }
            else if (f.f is And)
            {
                var c  = f.f as And;
                var i1 = c.f1.ffreeVariables.Contains(f.var);
                var i2 = c.f2.ffreeVariables.Contains(f.var);

                if (i1 && i2)
                {
                    return(new ExistentialFormula(f.var, f.f.visit(this), f.attributes, f.triggers));
                }
                else if (i1)
                {
                    return(new And(new ExistentialFormula(f.var, c.f1, f.attributes, f.triggers).visit(this), c.f2.visit(this)));
                }
                else if (i2)
                {
                    return(new And(c.f1.visit(this), new ExistentialFormula(f.var, c.f2, f.attributes, f.triggers).visit(this)));
                }
                else
                {
                    return(c.visit(this));
                }
            }
            else
            {
                return(new ExistentialFormula(f.var, f.f.visit(this), f.attributes, f.triggers));
            }
        }
Exemplo n.º 16
0
        public void GetDisplayName_WithoutSubstitutedUser()
        {
            Substitution substitution = Substitution.NewObject();

            substitution.SubstitutedUser = null;

            Assert.That(substitution.DisplayName, Is.EqualTo("?"));
        }
Exemplo n.º 17
0
        public void Initialize()
        {
            Substitution substitution = Substitution.NewObject();

            Assert.That(substitution.IsEnabled, Is.True);
            Assert.That(substitution.BeginDate, Is.Null);
            Assert.That(substitution.EndDate, Is.Null);
        }
Exemplo n.º 18
0
        public void Clone_AnySubstitution_ClonedSubstitution(string s)
        {
            var sub   = new Substitution(s);
            var clone = sub.Clone();

            Assert.That(!ReferenceEquals(sub, clone));
            Assert.That(sub.Equals(clone));
        }
Exemplo n.º 19
0
 public static int ReplaceFirst(Matcher m,Substitution substitution,TextWriter _out)
 {
     try {
         return ReplaceFirst(m,substitution,Wrap(_out));
     } catch(WriteException e) {
         throw e.reason;
     }
 }
Exemplo n.º 20
0
 public ReplacingOldSubstituter(Substitution always, Substitution forold)
     : base()
 {
     Contract.Requires(forold != null);
     Contract.Requires(always != null);
     this.always = always;
     this.forold = forold;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Apply a substitution to a command replacing "old" expressions.
 /// Outside "old" expressions, the substitution "always" is applied; any variable not in
 /// domain(always) is not changed.  Inside "old" expressions, apply map "oldExpr" to
 /// variables in domain(oldExpr), apply map "always" to variables in
 /// domain(always)-domain(oldExpr), and leave variable unchanged otherwise.
 /// </summary>
 public static Cmd ApplyReplacingOldExprs(Substitution always, Substitution forold, Cmd cmd)
 {
     Contract.Requires(cmd != null);
     Contract.Requires(forold != null);
     Contract.Requires(always != null);
     Contract.Ensures(Contract.Result <Cmd>() != null);
     return((Cmd) new ReplacingOldSubstituter(always, forold).Visit(cmd));
 }
 public override IResExp Substitute(Substitution subst)
 {
     return new ResAttributeFetch(
         this.Range,
         this.Type.Substitute(subst),
         _obj.Substitute(subst),
         _attribute.Substitute(subst));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Apply a substitution to a command sequence replacing "old" expressions.
 /// Outside "old" expressions, the substitution "always" is applied; any variable not in
 /// domain(always) is not changed.  Inside "old" expressions, apply map "forOld" to
 /// variables in domain(forOld), apply map "always" to variables in
 /// domain(always)-domain(forOld), and leave variable unchanged otherwise.
 /// </summary>
 public static List <Cmd> ApplyReplacingOldExprs(Substitution always, Substitution forOld, List <Cmd> cmdSeq)
 {
     Contract.Requires(always != null);
     Contract.Requires(forOld != null);
     Contract.Requires(cmdSeq != null);
     Contract.Ensures(Contract.Result <Cmd>() != null);
     return(new ReplacingOldSubstituter(always, forOld).VisitCmdSeq(cmdSeq));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Apply a substitution to a command.
 /// Outside "old" expressions, the substitution "always" is applied; any variable not in
 /// domain(always) is not changed.  Inside "old" expressions, apply map "forOld" to
 /// variables in domain(forOld), apply map "always" to variables in
 /// domain(always)-domain(forOld), and leave variable unchanged otherwise.
 /// </summary>
 public static Cmd Apply(Substitution always, Substitution forOld, Cmd cmd)
 {
     Contract.Requires(always != null);
     Contract.Requires(forOld != null);
     Contract.Requires(cmd != null);
     Contract.Ensures(Contract.Result <Cmd>() != null);
     return((Cmd) new NormalSubstituter(always, forOld).Visit(cmd));
 }
Exemplo n.º 25
0
        public ActionResult DeleteConfirmed(string id)
        {
            Substitution substitution = db.Substitutions.Find(id);

            db.Substitutions.Remove(substitution);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 26
0
        public async Task AddSubstitution(Substitution sub)
        {
            sub.Player = await _context.Players.FirstAsync(p => p.Id == sub.PlayerId);

            await _context.Substitutions.AddAsync(sub);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 27
0
 public static Expr FunctionCallReresolvingApply(Substitution always, Substitution forOld, Expr expr, Program program)
 {
     Contract.Requires(always != null);
     Contract.Requires(forOld != null);
     Contract.Requires(expr != null);
     Contract.Ensures(Contract.Result <Expr>() != null);
     return((Expr) new FunctionCallReresolvingNormalSubstituter(program, always, forOld).Visit(expr));
 }
Exemplo n.º 28
0
 public override IResExp Substitute(Substitution subst)
 {
     return new ResMethodApp(
         this.Range,
         this.Type.Substitute(subst),
         _method.Substitute<IResMethodRef>(subst),
         from a in _args select a.Substitute(subst));
 }
Exemplo n.º 29
0
        public void Test_SelfCompare_Diferent()
        {
            var c   = Condition.Parse("[x] != Self");
            var s   = new Substitution("[x]/Agatha");
            var res = c.Evaluate(_kb, Name.SELF_SYMBOL, new[] { new SubstitutionSet(s) });

            Assert.IsFalse(res);
        }
Exemplo n.º 30
0
 /// <summary>
 /// Apply a substitution to an expression replacing "old" expressions.
 /// Outside "old" expressions, the substitution "always" is applied; any variable not in
 /// domain(always) is not changed.  Inside "old" expressions, apply map "forOld" to
 /// variables in domain(forOld), apply map "always" to variables in
 /// domain(always)-domain(forOld), and leave variable unchanged otherwise.
 /// </summary>
 public static Expr ApplyReplacingOldExprs(Substitution always, Substitution forold, Expr expr)
 {
     Contract.Requires(expr != null);
     Contract.Requires(forold != null);
     Contract.Requires(always != null);
     Contract.Ensures(Contract.Result <Expr>() != null);
     return((Expr) new ReplacingOldSubstituter(always, forold).Visit(expr));
 }
Exemplo n.º 31
0
        public override Expr VisitNAryExpr(NAryExpr node)
        {
            if (!(node.Fun is FunctionCall))
            {
                return(base.VisitNAryExpr(node));
            }

            var FC = node.Fun as FunctionCall;

            // Can't inline SMTLIBv2 functions
            if (QKeyValue.FindStringAttribute(FC.Func.Attributes, "bvbuiltin") != null)
            {
                return(base.VisitNAryExpr(node));
            }

            if (Condition(FC.Func))
            {
                if (FC.Func.Body == null)
                {
                    throw new InvalidOperationException("Can't inline a function without a body");
                }

                // Compute mapping
                var varToExprMap = new Dictionary <Variable, Expr>();
                foreach (var parameterArgumentPair in FC.Func.InParams.Zip(node.Args))
                {
                    varToExprMap.Add(parameterArgumentPair.Item1, parameterArgumentPair.Item2);
                }

                // Using Closure :)
                Substitution sub = delegate(Variable v)
                {
                    try
                    {
                        return(varToExprMap[v]);
                    }
                    catch (KeyNotFoundException)
                    {
                        // The substituter seems to expect null being
                        // returned if we don't want to change the variable
                        return(null);
                    }
                };

                // Return the Function expression with variables substituted for function arguments.
                // This is basically inling
                ++InlineCounter;

                var result = Substituter.Apply(sub, FC.Func.Body);

                // Make sure we visit the result because it may itself contain function calls
                return((Expr)base.Visit(result));
            }
            else
            {
                return(base.VisitNAryExpr(node));
            }
        }
Exemplo n.º 32
0
        public void GetDisplayName_WithSubstitutedUser()
        {
            User         user         = TestHelper.CreateUser("user", "Firstname", "Lastname", "Title", null, null);
            Substitution substitution = Substitution.NewObject();

            substitution.SubstitutedUser = user;

            Assert.That(substitution.DisplayName, Is.EqualTo("Lastname Firstname, Title"));
        }
Exemplo n.º 33
0
        public IResTypeExp Substitute(Substitution subst)
        {
            var memberTerm = this.MemberTerm.Substitute(subst);

            return(new ResTypeSlotRef(
                       this.Range,
                       (ResTypeSlotDecl)memberTerm.Decl,
                       memberTerm));
        }
Exemplo n.º 34
0
        public IResConceptClassRef Substitute(Substitution subst)
        {
            var memberTerm = this.MemberTerm.Substitute(subst);

            return(new ResConceptClassRef(
                       this.Range,
                       (ResConceptClassDecl)memberTerm.Decl,
                       memberTerm));
        }
Exemplo n.º 35
0
        public IResMethodRef Substitute(Substitution subst)
        {
            var memberTerm = MemberTerm.Substitute(subst);

            return(new ResMethodRef(
                       Range,
                       (ResMethodDecl)memberTerm.Decl,
                       memberTerm));
        }
        public void Substitution_ValidVariableAndValidValue_NewSubstitution(string var, string val)
        {
            var sub = new Substitution(var, val);
            Assert.That(sub.Variable.ToString() == var);
            Assert.That(sub.Value.ToString() == val);

            var sub2 = new Substitution(Name.BuildName(var), Name.BuildName(val));
            Assert.That(sub2.Equals(sub));
        }
Exemplo n.º 37
0
        public Type Infer(Environment env)
        {
            var subst = new Substitution();
            var ret   = Infer(env, subst);

            ret.Perform(subst);
            env.Perform(subst);
            return(ret);
        }
        private Term ApplySubstitution(Substitution newSubstitution, Term substituteTerm)
        {
            var substitutionFrame = new Frame(_termDatabase);

            substitutionFrame.RootTerms.Add(substituteTerm);
            substitutionFrame.Substitutions.Add(newSubstitution);
            substitutionFrame.Rewrite(int.MaxValue);
            return(substitutionFrame.RootTerms.Single());
        }
Exemplo n.º 39
0
        public IResGenericRef Substitute(Substitution subst)
        {
            var memberTerm = this.MemberTerm.Substitute(subst);

            return(new ResGenericRef(
                       this.Range,
                       (ResGenericDecl)memberTerm.Decl,
                       memberTerm));
        }
 protected override IEnumerable<SubstitutionSet> CheckActivation(IQueryable db, Name perspective, IEnumerable<SubstitutionSet> constraints)
 {
     foreach (var result in m_other.Retrive(db, perspective, constraints))
     {
         var sub = new Substitution(m_variable, result.Item1);
         if (result.Item2.AddSubstitution(sub))
             yield return result.Item2;
     }
 }
 public ResGlobalMemberTerm(
     SourceRange range,
     ILazy<IResModuleDecl> module,
     IResMemberDecl decl)
 {
     _range = range;
     _module = module;
     _decl = decl;
     _subst = new Substitution();
 }
Exemplo n.º 42
0
        private static TermFunction SubstituteFunction(TermFunction function, Substitution theta)
        {
            if (!function.HasVariables)
                return function;

            var body = new List<Term>();
            for (int i = 0; i < function.Arity; i++)
                body.Add(SubstituteTerm(function.GetTerm(i), theta));

            return new TermFunction(function.FunctionName, body.ToArray());
        }
Exemplo n.º 43
0
 public override string GetState(Newtonsoft.Json.Linq.JObject jobject)
 {
     var result = Response;
     Substitution s = new Substitution();
     Dictionary<string, string> pairs = new Dictionary<string, string>();
     pairs["PropertyName"] = PropertyName;
     pairs["PropertyValue"] = GetValue(jobject, PropertyName);
     pairs["PropertyHasValue"] = (jobject[PropertyName] != null).ToString().ToLower();
     result = s.Substitute(result, pairs);
     return result;
 }
Exemplo n.º 44
0
 public static int ReplaceFirst(Matcher m,Substitution substitution,TextBuffer dest)
 {
     int c=0;
     if(m.Find()) {
         if(m.Start>0) m.Group(Matcher.PREFIX,dest);
         substitution.AppendSubstitution(m,dest);
         c++;
         m.SetTarget(m,Matcher.SUFFIX);
     }
     m.Group(Matcher.TARGET,dest);
     return c;
 }
Exemplo n.º 45
0
        public Substitution Compose(Substitution thetaPrime)
        {
            var result = new Substitution();

            foreach (var kv in _contents)
            result._contents[kv.Key] = kv.Value;

            foreach (var kv in thetaPrime._contents)
            result._contents[kv.Key] = kv.Value;

            return result;
        }
Exemplo n.º 46
0
        private static Fact SubstituteDistinct(Fact distinct, Substitution theta)
        {
            if (distinct is GroundFact)
                return distinct;

            Term arg1 = SubstituteTerm(distinct.GetTerm(0), theta);
            Term arg2 = SubstituteTerm(distinct.GetTerm(1), theta);

            return arg1.HasVariables || arg2.HasVariables
                ? new VariableFact(false, distinct.RelationName, arg1, arg2)
                : (Fact) new GroundFact(distinct.RelationName, arg1, arg2);
        }
Exemplo n.º 47
0
        private static bool UnifyVariable(TermVariable var, Term x, Substitution theta)
        {
            if (theta.Contains(var))
                return UnifyTerm(theta[var], x, theta);

            TermVariable termVariable = x as TermVariable;
            if ((termVariable != null) && theta.Contains(termVariable))
                return UnifyTerm(var, theta[termVariable], theta);

            theta[var] = x;
            return true;
        }
            public void AddSubstitution(Substitution s)
            {
                Constraint c;
                bool needsBuild = !m_constraints.TryGetValue(s.Variable, out c);

                if (s.Value.IsVariable)
                {
                    Constraint c2;
                    if (m_constraints.TryGetValue(s.Value, out c2))
                    {
                        if (needsBuild)
                        {
                            m_constraints[s.Variable] = c2;
                            c2.EquivalentVariables.Add(s.Variable);
                        }
                        else if (!Object.ReferenceEquals(c, c2))
                        {
                            c2.UnionWith(c);
                            foreach (var v in c2.EquivalentVariables)
                                m_constraints[v] = c2;
                        }
                    }
                    else
                    {
                        if (needsBuild)
                        {
                            c = new Constraint();
                            m_constraints[s.Variable] = c;
                            c.EquivalentVariables.Add(s.Variable);
                        }

                        m_constraints[s.Value] = c;
                        c.EquivalentVariables.Add(s.Value);
                    }
                }
                else
                {
                    if (needsBuild)
                    {
                        c = new Constraint();
                        m_constraints[s.Variable] = c;
                        c.EquivalentVariables.Add(s.Variable);
                    }

                    c.Value = s.Value;
                }

                m_substitutions.Add(s);
                m_hashIsDirty = true;
            }
Exemplo n.º 49
0
 public static int Replace(Matcher m,Substitution substitution,TextBuffer dest)
 {
     bool firstPass=true;
     int c=0;
     while(m.Find()) {
         if(m.End==0 && !firstPass) continue;  //allow to Replace at "^"
         if(m.Start>0) m.Group(Matcher.PREFIX,dest);
         substitution.AppendSubstitution(m,dest);
         c++;
         m.SetTarget(m,Matcher.SUFFIX);
         firstPass=false;
     }
     m.Group(Matcher.TARGET,dest);
     return c;
 }
Exemplo n.º 50
0
 void Start()
 {
     levelNameSubstitution = DynamicTextManager.instance.Substitute("#{hoveredLevelName}", () => hovered == null ? "" : hovered.levelName);
     levelStatusSubstitution = DynamicTextManager.instance.Substitute("#{hoveredLevelStatus}", () => {
         if (hovered == null) {
             return "";
         }
         if (hovered.level.Completed()) {
             return "completed";
         }
         if (hovered.level.Unlocked()) {
             return "unlocked";
         }
         return "locked";
     });
 }
Exemplo n.º 51
0
        public GenericFactory(Type genericTypeDescription, Subsistence subsistence, object serviceKey, ConstructorInfo constructor, Substitution substitution)
            : base(genericTypeDescription, serviceKey, substitution)
        {
            Subsistence = subsistence;
            Constructor = constructor;

            _dependencyFactories = new Dictionary<Type, IDependencyFactory>();

            ConstructorInfo[] allConstructors = Type.GetConstructors();
            for (int i = 0; i < allConstructors.Length; i++)
                if (allConstructors[i] == constructor)
                {
                    _constructorIndex = i;
                    break;
                }
        }
Exemplo n.º 52
0
        private static Expression SubstituteLiteral(Expression literal, Substitution theta)
        {
            var negation = literal as Negation;
            if (negation != null)
                return SubstituteNot(negation, theta);

            var disjunction = literal as Disjunction;
            if (disjunction != null)
                return SubstituteOr(disjunction, theta);

            var fact = (Fact) literal;

            return fact.RelationName == GameContainer.Parser.TokDistinct
                ? SubstituteDistinct(fact, theta)
                : SubstituteSentence(fact, theta);
        }
Exemplo n.º 53
0
        public ResMemberBind(
            SourceRange range,
            IResExp obj,
            IResMemberSpec memberSpec)
        {
            _range = range;
            _obj = obj;
            _memberSpec = memberSpec;

            _subst = new Substitution( memberSpec.Container.MemberTerm.Subst );
            // \todo: Need to ensure "obj" is clone-able...
            // \todo: Need to iteratively re-subst...
            _subst.Insert(
                memberSpec.Container.ThisParameter,
                (r) => obj);
        }
Exemplo n.º 54
0
        public TransientFactory(Type type, object serviceKey, ConstructorInfo constructorInfo, Substitution substitution)
            : base(type, serviceKey, substitution)
        {
            _constructorData = new ConstructorData(constructorInfo);

            PropertyInfo[] propertyInfos = type.GetProperties()
                .Where(x => x.SetMethod != null && x.SetMethod.IsPublic && x.GetCustomAttribute<InjectableAttribute>() != null)
                .ToArray();

            _propertiesData = new PropertyData[propertyInfos.Length];
            for (int i = 0; i < _propertiesData.Length; i++)
                _propertiesData[i] = new PropertyData(propertyInfos[i]);

            FieldInfo[] fieldInfos = type.GetFields()
                .Where(x => x.IsPublic && x.GetCustomAttribute<InjectableAttribute>() != null)
                .ToArray();

            _fieldsData = new FieldData[fieldInfos.Length];
            for (int i = 0; i < _fieldsData.Length; i++)
                _fieldsData[i] = new FieldData(fieldInfos[i]);
        }
Exemplo n.º 55
0
        private static bool UnifyTerm(Term x, Term y, Substitution theta)
        {
            if (x.Equals(y))
                return true;

            if (x is TermVariable)
            {
                if (!UnifyVariable((TermVariable)x, y, theta))
                    return false;
            }
            else if (y is TermVariable)
            {
                if (!UnifyVariable((TermVariable)y, x, theta))
                    return false;
            }
            else if ((x is TermFunction) && (y is TermFunction))
            {
                var xFunction = (TermFunction)x;
                var yFunction = (TermFunction)y;

                if (xFunction.FunctionName != yFunction.FunctionName)
                    return false;

                for (int i = 0; i < xFunction.Arity; i++)
                {
                    if (!UnifyTerm(xFunction.GetTerm(i), yFunction.GetTerm(i), theta))
                        return false;
                }
            }
            else
            {
                return false;
            }

            return true;
        }
Exemplo n.º 56
0
 public IResMemberSpec Substitute(Substitution subst)
 {
     return new ResMemberSpec(
         _range,
         _container.Substitute<IResContainerRef>(subst),
         _decl);
 }
Exemplo n.º 57
0
 public ReplacingOldSubstituter(Substitution always, Substitution forold)
   : base() {
   Contract.Requires(forold != null);
   Contract.Requires(always != null);
   this.always = always;
   this.forold = forold;
 }
Exemplo n.º 58
0
 public FunctionCallReresolvingNormalSubstituter(Program program, Substitution always, Substitution forold)
   : base(always, forold)
 {
   Program = program;
 }
Exemplo n.º 59
0
 public NormalSubstituter(Substitution subst, Substitution forold)
     : base()
 {
     Contract.Requires(subst != null);
     this.always = subst;
     this.forold = forold;
 }
Exemplo n.º 60
0
 public NormalSubstituter(Substitution subst)
   : base() {
   Contract.Requires(subst != null);
   this.always = subst;
   this.forold = Substituter.SubstitutionFromHashtable(new Dictionary<Variable, Expr>());
 }