Ejemplo n.º 1
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            // all nodes must either be int, frequency or range
            evaluators = ExprNodeUtilityQuery.GetEvaluatorsNoCompile(ChildNodes);
            for (var i = 0; i < ChildNodes.Length; i++) {
                var type = ChildNodes[i].Forge.EvaluationType;
                if (type == typeof(FrequencyParameter) || type == typeof(RangeParameter)) {
                    continue;
                }

                if (!type.IsNumericNonFP()) {
                    throw new ExprValidationException("Frequency operator requires an integer-type parameter");
                }
            }

            return null;
        }
Ejemplo n.º 2
0
        private static ExprNode GetValidatedSubtreeInternal(
            ExprNode exprNode,
            ExprValidationContext validationContext,
            bool isTopLevel)
        {
            ExprNode result = exprNode;
            if (exprNode is ExprLambdaGoesNode) {
                return exprNode;
            }

            for (int i = 0; i < exprNode.ChildNodes.Length; i++) {
                ExprNode childNode = exprNode.ChildNodes[i];
                if (childNode is ExprDeclaredOrLambdaNode node) {
                    if (node.IsValidated) {
                        continue;
                    }
                }

                ExprNode childNodeValidated = GetValidatedSubtreeInternal(childNode, validationContext, false);
                exprNode.SetChildNode(i, childNodeValidated);
            }

            try {
                ExprNode optionalReplacement = exprNode.Validate(validationContext);
                if (optionalReplacement != null) {
                    return GetValidatedSubtreeInternal(optionalReplacement, validationContext, isTopLevel);
                }
            }
            catch (ExprValidationException e) {
                if (exprNode is ExprIdentNode identNode) {
                    try {
                        result = ResolveStaticMethodOrField(identNode, e, validationContext);
                    }
                    catch (ExprValidationException) {
                        var resolutionStream = ResolveAsStreamName(identNode, validationContext);
                        if (resolutionStream.First == false) {
                            throw;
                        }

                        result = resolutionStream.Second;
                    }
                }
                else {
                    throw;
                }
            }

            // For top-level expressions check if we perform audit
            if (isTopLevel) {
                if (validationContext.IsExpressionAudit) {
                    return (ExprNode) ExprNodeProxy.NewInstance(result);
                }
            }
            else {
                if (validationContext.IsExpressionNestedAudit &&
                    !(result is ExprIdentNode) &&
                    !(ExprNodeUtilityQuery.IsConstant(result))) {
                    return (ExprNode) ExprNodeProxy.NewInstance(result);
                }
            }

            return result;
        }