Example #1
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);
                }
            }
        }
        public ISymbolValue Visit(EqualExpression x)
        {
            var lValue = this.lValue ?? (x.LeftOperand != null ? x.LeftOperand.Accept(this) : null);
            var rValue = this.rValue ?? (x.RightOperand != null ? x.RightOperand.Accept(this) : null);

            this.lValue = null;
            this.rValue = null;

            var l = TryGetValue(lValue);
            var r = TryGetValue(rValue);

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

            return(new PrimitiveValue(x.OperatorToken == DTokens.Equal ? isEq : !isEq, x));
        }
Example #3
0
 public virtual bool Equals(ISymbolValue other)
 {
     return(SymbolValueComparer.IsEqual(this, other));
 }