/// <summary>
        /// Retrieves the value of the expression
        /// </summary>
        /// <param name="evalContext">Evaluation context</param>
        /// <param name="checkOnly"></param>
        /// <returns>Evaluated expression value</returns>
        public override ExpressionValue Evaluate(IExpressionEvaluationContext evalContext, bool checkOnly = false)
        {
            // --- Test for operand errors
            var addrValue = StartAddress.Evaluate(evalContext);

            if (addrValue.Type == ExpressionValueType.Error)
            {
                EvaluationError = StartAddress.EvaluationError;
                return(ExpressionValue.Error);
            }
            var length = EndAddress == null ? new ExpressionValue(1) : EndAddress.Evaluate(evalContext);

            if (length.Type == ExpressionValueType.Error)
            {
                EvaluationError = EndAddress?.EvaluationError;
                return(ExpressionValue.Error);
            }

            if (checkOnly)
            {
                return(ExpressionValue.NonEvaluated);
            }

            if (addrValue.Type == ExpressionValueType.ByteArray || length.Type == ExpressionValueType.ByteArray)
            {
                EvaluationError = "Memory address operator cannot be applied on a byte array";
                return(ExpressionValue.Error);
            }

            var addr = addrValue.AsNumber();

            return(new ExpressionValue(evalContext.GetMemorySection((ushort)addr,
                                                                    (ushort)(addr + length.AsNumber() - 1))));
        }
示例#2
0
        /// <summary>
        /// Retrieves the value of the expression
        /// </summary>
        /// <param name="evalContext">Evaluation context</param>
        /// <param name="checkOnly"></param>
        /// <returns>Evaluated expression value</returns>
        public override ExpressionValue Evaluate(IExpressionEvaluationContext evalContext, bool checkOnly = false)
        {
            // --- Test for operand errors
            var addrValue = StartAddress.Evaluate(evalContext);

            if (addrValue.Type == ExpressionValueType.Error)
            {
                EvaluationError = StartAddress.EvaluationError;
                return(ExpressionValue.Error);
            }
            var endValue = EndAddress == null ? new ExpressionValue(1) : EndAddress.Evaluate(evalContext);

            if (endValue.Type == ExpressionValueType.Error)
            {
                EvaluationError = EndAddress?.EvaluationError;
                return(ExpressionValue.Error);
            }

            if (checkOnly)
            {
                return(ExpressionValue.NonEvaluated);
            }

            if (addrValue.Type == ExpressionValueType.ByteArray || endValue.Type == ExpressionValueType.ByteArray)
            {
                EvaluationError = "Memory address operator cannot be applied on a byte array";
                return(ExpressionValue.Error);
            }

            return(new ExpressionValue(evalContext.GetMachineContext().GetMemorySection(addrValue.AsWord(),
                                                                                        endValue.AsWord())));
        }
        /// <summary>
        /// Retrieves the value of the expression
        /// </summary>
        /// <param name="evalContext">Evaluation context</param>
        /// <param name="checkOnly"></param>
        /// <returns>Evaluated expression value</returns>
        public override ExpressionValue Evaluate(IExpressionEvaluationContext evalContext, bool checkOnly = false)
        {
            // --- Test for operand errors
            var startAddr = StartAddress.Evaluate(evalContext);

            if (startAddr.Type == ExpressionValueType.Error)
            {
                EvaluationError = StartAddress.EvaluationError;
                return(ExpressionValue.Error);
            }

            var endAddr = startAddr;

            if (EndAddress != null)
            {
                endAddr = EndAddress.Evaluate(evalContext);
                if (endAddr.Type == ExpressionValueType.Error)
                {
                    EvaluationError = EndAddress?.EvaluationError;
                    return(ExpressionValue.Error);
                }
            }

            if (checkOnly)
            {
                return(ExpressionValue.NonEvaluated);
            }

            if (startAddr.Type == ExpressionValueType.ByteArray || endAddr.Type == ExpressionValueType.ByteArray)
            {
                EvaluationError = "Code reach operator cannot be applied on a byte array";
                return(ExpressionValue.Error);
            }

            return(new ExpressionValue(EvalTouch(evalContext, startAddr.AsWord(), endAddr.AsWord())));
        }