示例#1
0
        private static void ThrowIfSomeVariablesNotExistsInTheList(this VariableDictionary resultVariables, IEnumerable <string> list)
        {
            var unknownVariables = resultVariables.GetAllUsages()
                                   .Where(u => !list.Contains(u.Source.Name)).ToList();

            if (unknownVariables.Any())
            {
                throw ErrorFactory.UnknownVariables(unknownVariables.SelectMany(u => u.Usages));
            }
        }
示例#2
0
        private IExpressionNode BuildAnonymousFunction(Interval interval, ISyntaxNode body,
                                                       VariableDictionary localVariables, VariableSource[] arguments)
        {
            var sources         = localVariables.GetAllSources().ToArray();
            var originVariables = new string[sources.Length];

            for (int i = 0; i < originVariables.Length; i++)
            {
                originVariables[i] = sources[i].Name;
            }

            var expr = BuildExpression(body, _functions, localVariables, _typeInferenceResults, _typesConverter);

            //New variables are new closured
            var closured = localVariables.GetAllUsages()
                           .Where(s => !originVariables.Contains(s.Source.Name))
                           .ToList();

            if (closured.Any(c => Helper.DoesItLooksLikeSuperAnonymousVariable(c.Source.Name)))
            {
                throw FunParseException.ErrorStubToDo("Unexpected it* variable");
            }

            //Add closured vars to outer-scope dictionary
            foreach (var newVar in closured)
            {
                _variables.TryAdd(newVar); //add full usage info to allow analyze outer errors
            }
            var fun = ConcreteUserFunction.Create(
                isRecursive: false,
                name: "anonymous",
                variables: arguments,
                isReturnTypeStrictlyTyped: false,
                expression: expr);

            return(new FunVariableExpressionNode(fun, interval));
        }