ISemantic E(EqualExpression x, ISemantic lValue = null, ISemantic rValue = null)
        {
            var l = TryGetValue(lValue ?? E(x.LeftOperand));
            var r = TryGetValue(rValue ?? E(x.RightOperand));

            var isEq = SymbolValueComparer.IsEqual(l, r);

            return(new PrimitiveValue(x.OperatorToken == DTokens.Equal ? isEq : !isEq, x));
        }
Exemplo n.º 2
0
        public override void Set(AbstractSymbolValueProvider vp, ISymbolValue value)
        {
            var oldV = vp[Variable];

            if (oldV is AssociativeArrayValue)
            {
                if (Key != null)
                {
                    var aa = (AssociativeArrayValue)oldV;

                    int itemToReplace = -1;

                    for (int i = 0; i < aa.Elements.Count; i++)
                    {
                        if (SymbolValueComparer.IsEqual(aa.Elements[i].Key, Key))
                        {
                            itemToReplace = i;
                            break;
                        }
                    }

                    // If we haven't found a matching key, add it to the array
                    var newElements = new KeyValuePair <ISymbolValue, ISymbolValue> [aa.Elements.Count + (itemToReplace == -1 ? 1: 0)];
                    aa.Elements.CopyTo(newElements, 0);

                    if (itemToReplace != -1)
                    {
                        newElements[itemToReplace] = new KeyValuePair <ISymbolValue, ISymbolValue>(newElements[itemToReplace].Key, value);
                    }
                    else
                    {
                        newElements[newElements.Length - 1] = new KeyValuePair <ISymbolValue, ISymbolValue>(Key, value);
                    }

                    // Finally, make a new associative array containing the new elements
                    vp[Variable] = new AssociativeArrayValue(aa.RepresentedType as AssocArrayType, newElements);
                }
                else
                {
                    if (vp.ev != null)
                    {
                        vp.ev.EvalError(null, "Key expression must not be null", Key);
                    }
                }
            }
            else
            {
                if (vp.ev != null)
                {
                    vp.ev.EvalError(null, "Type of accessed item must be an associative array", oldV);
                }
            }
        }
Exemplo n.º 3
0
 public virtual bool Equals(ISymbolValue other)
 {
     return(SymbolValueComparer.IsEqual(this, other));
 }