Example #1
0
        private SymbolicValue this[SymbolicValue arg, IUniqueKey function] {
            get {
                arg = Find(arg);
                SymbolicValue v = (SymbolicValue)this.termMap[arg, function];

                if (v == null)
                {
                    v              = FreshSymbolicValue();
                    this.termMap   = this.termMap.Add(arg, function, v);
                    this.eqTermMap = this.eqTermMap.Add(v, new EGraphTerm(function, arg), null);
                    this.AddEdgeUpdate(arg, function);
                }
                else
                {
                    v = Find(v);
                }
                return(v);
            }

            set {
                arg            = Find(arg);
                value          = Find(value);
                this.termMap   = this.termMap.Add(arg, function, value);
                this.eqTermMap = this.eqTermMap.Add(value, new EGraphTerm(function, arg), null);
                this.AddEdgeUpdate(arg, function);
            }
        }
Example #2
0
 private void AddEliminateEdgeUpdate(SymbolicValue from, IUniqueKey function)
 {
     if (IsOldSymbol(from))
     {
         AddUpdate(new MergeState.EliminateEdgeUpdate(from, function));
     }
 }
Example #3
0
        public ISymValue this[IUniqueKey function, params ISymValue[] args] {
            get {
                if (args.Length == 0)
                {
                    return(this[this.constRoot, function]);
                }
                if (args.Length == 1)
                {
                    return(this[(SymbolicValue)args[0], function]);
                }
                Debug.Assert(false, "EGraph currently only implements unary and nullary function terms");
                return(null);
            }

            set {
                if (args.Length == 0)
                {
                    this[this.constRoot, function] = (SymbolicValue)value;
                    return;
                }
                if (args.Length == 1)
                {
                    this[(SymbolicValue)args[0], function] = (SymbolicValue)value;
                    return;
                }
                Debug.Assert(false, "EGraph currently only implements unary and nullary function terms");
            }
        }
Example #4
0
        private SymbolicValue LookupWithoutManifesting(SymbolicValue arg, IUniqueKey function)
        {
            arg = Find(arg);
            SymbolicValue v = (SymbolicValue)this.termMap[arg, function];

            if (v == null)
            {
                return(v);
            }
            return(Find(v));
        }
Example #5
0
 public ISymValue TryLookup(IUniqueKey function, params ISymValue[] args)
 {
     if (args.Length == 0)
     {
         return(LookupWithoutManifesting(this.constRoot, function));
     }
     if (args.Length == 1)
     {
         return(LookupWithoutManifesting((SymbolicValue)args[0], function));
     }
     Debug.Assert(false, "EGraph currently only implements unary and nullary function terms");
     return(null);
 }
Example #6
0
 public static string Function2String(IUniqueKey function)
 {
     if (function is Variable)
     {
         Variable   v    = (Variable)function;
         Identifier name = v.Name;
         string     nstr = (name == null)?"":name.Name;
         return(String.Format("{0}({1})", nstr, function.UniqueId));
     }
     if (function is Field)
     {
         Field      f    = (Field)function;
         Identifier name = f.Name;
         return((name == null)?"":name.Name);
     }
     return(function.ToString());
 }
Example #7
0
 public void Eliminate(IUniqueKey function, params ISymValue[] args)
 {
     if (args.Length == 0)
     {
         this.termMap = this.termMap.Remove(this.constRoot, function);
         this.AddEliminateEdgeUpdate(this.constRoot, function);
         return;
     }
     if (args.Length == 1)
     {
         SymbolicValue sv = Find(args[0]);
         this.termMap = this.termMap.Remove(sv, function);
         this.AddEliminateEdgeUpdate(sv, function);
         return;
     }
     Debug.Assert(false, "EGraph currently only implements unary and nullary function terms");
 }
Example #8
0
        /// <summary>
        /// Specifies that the collection is to be checked for duplicates using the item's <see cref="IUniqueKey"/> value.
        /// </summary>
        /// <param name="duplicateText">The duplicate text <see cref="LText"/> to be passed for the error message (default is to derive the text from the property itself where possible).</param>
        /// <returns>The <see cref="CollectionRuleItem{TItemEntity}"/> instance to support chaining/fluent.</returns>
        public CollectionRuleItem <TItemEntity> UniqueKeyDuplicateCheck(LText duplicateText = null)
        {
            if (_duplicateCheck)
            {
                throw new InvalidOperationException("A DuplicateCheck or UniqueKeyDuplicateCheck can only be specified once.");
            }

            if (ItemType.GetInterface(typeof(IUniqueKey).Name) == null)
            {
                throw new InvalidOperationException("A CollectionRuleItem ItemType '{_itemType.Name}' must implement 'IUniqueKey' to support UniqueKeyDuplicateCheck.");
            }

            IUniqueKey uk = null;

            try
            {
                uk = (IUniqueKey)Activator.CreateInstance(ItemType);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"A CollectionRuleItem ItemType '{ItemType.Name}' could not be constructed as an IUniqueKey to infer UniqueKeyProperties: {ex.Message}");
            }

            if (!uk.HasUniqueKey || uk.UniqueKeyProperties == null || uk.UniqueKeyProperties.Length == 0)
            {
                throw new InvalidOperationException("A CollectionRule TProperty ItemType '{_itemType.Name}' must define the 'IUniqueKey.UniqueKeyProperties' to support CheckForDuplicates.");
            }

            _duplicateText = duplicateText;
            if (_duplicateText == null && uk.UniqueKeyProperties.Length == 1)
            {
                _duplicateText = new EntityReflectorArgs().GetReflector(ItemType).GetProperty(uk.UniqueKeyProperties[0]).PropertyExpression.Text;
            }

            if (_duplicateText == null)
            {
                _duplicateText = "Unique Key";
            }

            _duplicateCheck = true;

            return(this);
        }
Example #9
0
 public static string PrettyName(IUniqueKey function)
 {
     if (function is Variable)
     {
         Variable   v    = (Variable)function;
         Identifier name = v.Name;
         string     nstr = (name == null)?("temp(" + function.UniqueId.ToString() + ")"):name.Name;
         return(nstr);
     }
     if (function is Field)
     {
         Field      f    = (Field)function;
         Identifier name = f.Name;
         return((name == null)?("field(" + function.UniqueId.ToString() + ")"):name.Name);
     }
     if (function is Method)
     {
         Method     m    = (Method)function;
         Identifier name = m.Name;
         return((name == null)?("method(" + function.UniqueId.ToString() + ")"):name.Name);
     }
     return(function.ToString());
 }
 public int Keys2Count(/*A*/IUniqueKey key1) { 
   IFunctionalMap map2 = (IFunctionalMap)this.map[key1];
     
   if (map2 == null) { return 0; }
   return map2.Count;
 }
 public bool ContainsKey1(/*<A>*/ IUniqueKey key1) {
   return this.map[key1] != null;
 }
    public DoubleFunctionalMap Remove(IUniqueKey key1, IUniqueKey key2) {
      IFunctionalMap t = (IFunctionalMap)this.map[key1];

      if (t == null) { return this; }

      return new DoubleFunctionalMap(this.map.Add(key1, t.Remove(key2)));
    }
 public DoubleFunctionalMap RemoveAll(IUniqueKey key1) {
   return new DoubleFunctionalMap(this.map.Remove(key1));
 }
    public DoubleFunctionalMap Add(IUniqueKey key1, IUniqueKey key2, object value) {
      IFunctionalMap t = (IFunctionalMap)this.map[key1];

      if (t == null) {
        t = FunctionalMap.Empty;
      }

      return new DoubleFunctionalMap(this.map.Add(key1, t.Add(key2, value)));
    }
Example #15
0
 public void Eliminate(IUniqueKey function, params ISymValue[] args) {
   if (args.Length == 0) {
     this.termMap = this.termMap.Remove(this.constRoot, function);
     this.AddEliminateEdgeUpdate(this.constRoot, function);
     return;
   }
   if (args.Length == 1) {
     SymbolicValue sv = Find(args[0]);
     this.termMap = this.termMap.Remove(sv, function);
     this.AddEliminateEdgeUpdate(sv, function);
     return;
   }
   Debug.Assert(false, "EGraph currently only implements unary and nullary function terms");
 }
Example #16
0
 public EliminateEdgeUpdate(SymbolicValue from, IUniqueKey function) {
   this.from = from;
   this.function = function;
 }
Example #17
0
 public ISymValue TryLookup(IUniqueKey function, params ISymValue[] args) 
 {
   if (args.Length == 0) 
   {
     return LookupWithoutManifesting(this.constRoot, function);
   }
   if (args.Length == 1) 
   {
     return LookupWithoutManifesting((SymbolicValue)args[0], function);
   }
   Debug.Assert(false, "EGraph currently only implements unary and nullary function terms");
   return null;
 }
Example #18
0
    private SymbolicValue this[SymbolicValue arg, IUniqueKey function] {
      get {
        arg = Find(arg);
        SymbolicValue v = (SymbolicValue)this.termMap[arg, function];

        if (v == null) {
          v = FreshSymbolicValue();
          this.termMap = this.termMap.Add(arg, function, v);
          this.eqTermMap = this.eqTermMap.Add(v, new EGraphTerm(function, arg), null);
          this.AddEdgeUpdate(arg, function);
        }
        else {
          v = Find(v);
        }
        return v;
      }

      set {
        arg = Find(arg);
        value = Find(value);
        this.termMap = this.termMap.Add(arg, function, value);
        this.eqTermMap = this.eqTermMap.Add(value, new EGraphTerm(function, arg), null);
        this.AddEdgeUpdate(arg, function);
      }
    }
Example #19
0
 public EGraphTerm(IUniqueKey fun, params ISymValue[] args) {
   this.Function = fun;
   this.Args = args;
   this.id = IdGen++;
 }
 public ICollection/*<B>*/ Keys2(/*A*/IUniqueKey key1) {
   IFunctionalMap map2 = (IFunctionalMap)this.map[key1];
     
   if (map2 == null) { return new object[0]; }
   return map2.Keys;
 }
Example #21
0
            private SymbolicValue AddJointEdge(SymbolicValue v1target, SymbolicValue v2target, IUniqueKey function, SymbolicValue resultRoot)
            {
                SymbolicValue rtarget    = (SymbolicValue)Map[v1target, v2target];
                bool          newBinding = false;

                if (rtarget == null)
                {
                    // if we have visited v1target before, then the result graph is not isomorphic to G1
                    if (Map.ContainsKey1(v1target) || IsCommon(v1target) && v1target != v2target)
                    {
                        this.changed = true;
                    }
                    newBinding = true;
                    if (v1target.UniqueId <= lastCommonVariable && v1target == v2target)
                    {
                        rtarget = v1target; // reuse old symbol
                    }
                    else
                    {
                        rtarget = Result.FreshSymbolicValue();
                    }
                    this.Map = this.Map.Add(v1target, v2target, rtarget);
                }
                else
                {
                    // See if info is already present
                    SymbolicValue oldTarget = Result.LookupWithoutManifesting(resultRoot, function);
                    if (oldTarget == rtarget)
                    {
                        // no change, don't record or change anything
                        return(null);
                    }
                }
                Result[resultRoot, function] = rtarget;

                AbstractValue aval1   = G1[v1target];
                AbstractValue aval2   = G2[v2target];
                AbstractValue aresult = G1.elementLattice.Join(aval1, aval2);

                Result[rtarget] = aresult;
                if (!G1.elementLattice.LowerThanOrEqual(aresult, aval1))
                {
                    this.changed = true;
                }

                if (Analyzer.Debug)
                {
                    Console.WriteLine("AddJointEdge: {0} -{1}-> [{2},{3},{4}]",
                                      resultRoot, EGraph.Function2String(function), v1target, v2target, rtarget);
                }
                return((newBinding)?rtarget:null);
            }
Example #22
0
 public EliminateEdgeUpdate(SymbolicValue from, IUniqueKey function)
 {
     this.from     = from;
     this.function = function;
 }
Example #23
0
 public EGraphTerm(IUniqueKey fun, params ISymValue[] args)
 {
     this.Function = fun;
     this.Args     = args;
     this.id       = IdGen++;
 }
Example #24
0
 public static string Function2String(IUniqueKey function) 
 {
   if (function is Variable) 
   {
     Variable v = (Variable)function;
     Identifier name = v.Name;
     string nstr = (name == null)?"":name.Name;
     return String.Format("{0}({1})", nstr, function.UniqueId);
   }
   if (function is Field) 
   {
     Field f = (Field)function;
     Identifier name = f.Name;
     return (name == null)?"":name.Name;
   }
   return function.ToString();
 }
 public bool this[IUniqueKey key] {
   get {
     return this.fimap[key.UniqueId] != null;
   }
 }
Example #26
0
 private void AddEliminateEdgeUpdate(SymbolicValue from, IUniqueKey function) {
   if (IsOldSymbol(from)) {
     AddUpdate(new MergeState.EliminateEdgeUpdate(from, function));
   }
 }
 public IFunctionalSet Add(IUniqueKey key) {
   return new FunctionalSet(this.fimap.Add(key.UniqueId, key, Empty)); // Empty is used as any dummy value here
 }
Example #28
0
    private SymbolicValue LookupWithoutManifesting(SymbolicValue arg, IUniqueKey function) {

      arg = Find(arg);
      SymbolicValue v = (SymbolicValue)this.termMap[arg, function];
      if (v == null) return v;
      return Find(v);
    }
 public object this[IUniqueKey key] {
   get {
     return this.fimap[key.UniqueId];
   }
 }
Example #30
0
    public ISymValue this[IUniqueKey function, params ISymValue[] args] {
      get {
        if (args.Length == 0) {
          return this[this.constRoot, function];
        }
        if (args.Length == 1) {
          return this[(SymbolicValue)args[0], function];
        }
        Debug.Assert(false, "EGraph currently only implements unary and nullary function terms");
        return null;
      }

      set {
        if (args.Length == 0) {
          this[this.constRoot, function] = (SymbolicValue)value;
          return;
        }
        if (args.Length == 1) {
          this[(SymbolicValue)args[0], function] = (SymbolicValue)value;
          return;
        }
        Debug.Assert(false, "EGraph currently only implements unary and nullary function terms");
      }
    }
 public IFunctionalMap Add(IUniqueKey key, object val) {
   return new FunctionalMap(this.fimap.Add(key.UniqueId, key, val));
 }
Example #32
0
      private SymbolicValue AddJointEdge(SymbolicValue v1target, SymbolicValue v2target, IUniqueKey function, SymbolicValue resultRoot) {
        SymbolicValue rtarget = (SymbolicValue)Map[v1target, v2target];
        bool newBinding = false;
        if (rtarget == null) {
          // if we have visited v1target before, then the result graph is not isomorphic to G1
          if (Map.ContainsKey1(v1target) || IsCommon(v1target) && v1target != v2target) { this.changed = true; }
          newBinding = true;
          if (v1target.UniqueId <= lastCommonVariable && v1target == v2target) {
            rtarget = v1target; // reuse old symbol
          }
          else {
            rtarget = Result.FreshSymbolicValue();
          }
          this.Map = this.Map.Add(v1target,v2target,rtarget);
        }
        else {
          // See if info is already present
          SymbolicValue oldTarget = Result.LookupWithoutManifesting(resultRoot, function);
          if (oldTarget == rtarget) {
            // no change, don't record or change anything
            return null;
          }
        }
        Result[resultRoot, function] = rtarget;

        AbstractValue aval1 = G1[v1target];
        AbstractValue aval2 = G2[v2target];
        AbstractValue aresult = G1.elementLattice.Join(aval1, aval2);
        Result[rtarget] = aresult;
        if ( ! G1.elementLattice.LowerThanOrEqual(aresult, aval1)) { this.changed = true; }

        if (Analyzer.Debug) {
          Console.WriteLine("AddJointEdge: {0} -{1}-> [{2},{3},{4}]",
            resultRoot, EGraph.Function2String(function), v1target, v2target, rtarget); 
        }
        return (newBinding)?rtarget:null;
      }
 public IFunctionalMap Remove(IUniqueKey key) {
   return new FunctionalMap(this.fimap.Remove(key.UniqueId));
 }
 public static string PrettyName(IUniqueKey function) {
   if (function is Variable) {
     Variable v = (Variable)function;
     Identifier name = v.Name;
     string nstr = (name == null)?("temp("+function.UniqueId.ToString()+")"):name.Name;
     return nstr;
   }
   if (function is Field) {
     Field f = (Field)function;
     Identifier name = f.Name;
     return (name == null)?("field("+function.UniqueId.ToString()+")"):name.Name;
   }
   if (function is Method) {
     Method m = (Method)function;
     Identifier name = m.Name;
     return (name == null)?("method("+function.UniqueId.ToString()+")"):name.Name;
   }
   return function.ToString();
 }
    public object this[IUniqueKey key1, IUniqueKey key2] {
      get {
        IFunctionalMap t = (IFunctionalMap)this.map[key1];

        if (t == null) {
          return null;
        }

        return t[key2];
      }
    }