コード例 #1
0
        public IExpressionNode Visit(SuperAnonymFunctionSyntaxNode arrowAnonymFunNode)
        {
            var outputTypeFunDefinition = arrowAnonymFunNode.OutputType.FunTypeSpecification;

            if (outputTypeFunDefinition == null)
            {
                throw new ImpossibleException("Fun definition expected");
            }
            string[] argNames = null;
            if (outputTypeFunDefinition.Inputs.Length == 1)
            {
                argNames = new[] { "it" }
            }
            ;
            else
            {
                argNames = new string[outputTypeFunDefinition.Inputs.Length];
                for (int i = 0; i < outputTypeFunDefinition.Inputs.Length; i++)
                {
                    argNames[i] = $"it{i + 1}";
                }
            }

            //Prepare local variable scope
            //Capture all outerscope variables
            var localVariables = new VariableDictionary(_variables.GetAllSources());

            var arguments = new VariableSource[argNames.Length];

            for (var i = 0; i < argNames.Length; i++)
            {
                var arg    = argNames[i];
                var type   = outputTypeFunDefinition.Inputs[i];
                var source = VariableSource.CreateWithoutStrictTypeLabel(arg, type, false);
                //collect argument
                arguments[i] = source;
                //add argument to local scope
                //if argument with it* name already exist - replace it
                localVariables.AddOrReplace(source);
            }

            var body = arrowAnonymFunNode.Body;

            return(BuildAnonymousFunction(arrowAnonymFunNode.Interval, body, localVariables, arguments));
        }