Example #1
0
        public override void PostWalk(GeneratorExpression node)
        {
            Debug.Assert(_scope is ComprehensionScope);
            _scope = _scope.OuterScope;

            base.PostWalk(node);
        }
Example #2
0
 override public void OnGeneratorExpression(GeneratorExpression node)
 {
     Write("(");
     Visit(node.Expression);
     WriteGeneratorExpressionBody(node);
     Write(")");
 }
Example #3
0
        public override bool Walk(GeneratorExpression node)
        {
            EnsureComprehensionScope(node, MakeGeneratorComprehensionScope);
            Debug.Assert(_scope is ComprehensionScope);

            return(base.Walk(node));
        }
Example #4
0
 void WriteGeneratorExpressionBody(GeneratorExpression node)
 {
     WriteKeyword(" for ");
     WriteCommaSeparatedList(node.Declarations);
     WriteKeyword(" in ");
     Visit(node.Iterator);
     Visit(node.Filter);
 }
Example #5
0
 public GeneratorExpressionProcessor(CompilerContext context,
                                     ForeignReferenceCollector collector,
                                     GeneratorExpression node)
 {
     _collector = collector;
     _generator = node;
     Initialize(context);
 }
Example #6
0
 override public void OnGeneratorExpression(GeneratorExpression node)
 {
     ++_closureDepth;
     Visit(node.Iterator);
     Visit(node.Expression);
     Visit(node.Filter);
     --_closureDepth;
 }
Example #7
0
        private static ISet <Namespace> EvaluateGenerator(ExpressionEvaluator ee, Node node)
        {
            GeneratorExpression gen = (GeneratorExpression)node;

            ee.Evaluate(gen.Iterable);

            // TODO: Implement
            return(EmptySet <Namespace> .Instance);
        }
Example #8
0
        public GeneratorExpressionProcessor(CompilerContext context,
                                            ForeignReferenceCollector collector,
                                            GeneratorExpression node)
        {
            _collector = collector;
            _generator = node;
            _skeleton  = My <GeneratorSkeletonBuilder> .Instance.SkeletonFor(node, node.GetAncestor <Method>());

            Initialize(context);
        }
        public async Task <IMember> GetValueFromGeneratorAsync(GeneratorExpression expression, CancellationToken cancellationToken = default)
        {
            var iter = expression.Iterators.OfType <ComprehensionFor>().FirstOrDefault();

            if (iter != null)
            {
                return(await GetValueFromExpressionAsync(iter.List, cancellationToken) ?? UnknownType);
            }
            return(UnknownType);
        }
        public override bool Walk(GeneratorExpression node)
        {
            if (_libraryMode)
            {
                return(false);
            }

            _stack.Enter(SymbolKind.None);
            return(base.Walk(node));
        }
Example #11
0
        public IMember GetValueFromGenerator(GeneratorExpression expression)
        {
            var iter = expression.Iterators.OfType <ComprehensionFor>().FirstOrDefault();

            if (iter != null)
            {
                return(GetValueFromExpression(iter.List) ?? UnknownType);
            }
            return(UnknownType);
        }
        override public void LeaveGeneratorExpression(GeneratorExpression node)
        {
            Expression newExpression = Convert(
                GetConcreteExpressionType(node.Expression),
                node.Expression);

            if (null != newExpression)
            {
                node.Expression = newExpression;
            }
        }
Example #13
0
        override public void LeaveGeneratorExpression(GeneratorExpression node)
        {
            var collector = new ForeignReferenceCollector();

            collector.CurrentType = (IType)AstUtil.GetParentClass(node).Entity;
            node.Accept(collector);

            var processor = new GeneratorExpressionProcessor(Context, collector, node);

            processor.Run();
            ReplaceCurrentNode(processor.CreateEnumerableConstructorInvocation());
        }
        protected override Expression VisitGenerator(GeneratorExpression generator)
        {
            var property = generator.Property;

            if (property.Info.DataType != null &&
                property.Info.DataType.Value.IsStringDbType())
            {
                return(Expression.Call(null, MethodCache.GenerateGuidValue, generator.Entity, Expression.Constant(generator.Property)));
            }

            return(Expression.Call(null, MethodCache.GenerateIdentityValue, _executor, generator.Entity, Expression.Constant(generator.Property)));
        }
 public override void OnGeneratorExpression(GeneratorExpression node)
 {
     if (node.LexicalInfo.Line != resolver.CaretLine)
     {
         return;
     }
     LoggingService.Warn("GeneratorExpression: " + node.EndSourceLocation.Line);
     foreach (Declaration decl in node.Declarations)
     {
         IterationDeclarationFound(decl.Name, decl.Type, node.Iterator, node.LexicalInfo);
     }
     base.OnGeneratorExpression(node);
 }
Example #16
0
        override public void LeaveGeneratorExpression(GeneratorExpression node)
        {
            using (ForeignReferenceCollector collector = new ForeignReferenceCollector())
            {
                collector.CurrentType = (IType)AstUtil.GetParentClass(node).Entity;
                collector.Initialize(_context);
                collector.Visit(node);

                GeneratorExpressionProcessor processor = new GeneratorExpressionProcessor(_context, collector, node);
                processor.Run();
                ReplaceCurrentNode(processor.CreateEnumerableConstructorInvocation());
            }
        }
Example #17
0
        public override void LeaveGeneratorExpression(GeneratorExpression node)
        {
            var collector = new ForeignReferenceCollector {
                CurrentType = TypeContaining(node)
            };

            node.Accept(collector);

            var processor = new GeneratorExpressionProcessor(Context, collector, node);

            processor.Run();

            ReplaceCurrentNode(processor.CreateEnumerableConstructorInvocation());
        }
Example #18
0
        public override void OnGeneratorExpression(GeneratorExpression node)
        {
            ClearResult();
            node.Expression.Accept(this);

            if (resolveResult != null)
            {
                IReturnType enumerable = new GetClassReturnType(projectContent, "System.Collections.Generic.IEnumerable", 1);
                MakeResult(new ConstructedReturnType(enumerable, new IReturnType[] { resolveResult.ResolvedType }));
            }
            else
            {
                MakeResult(new GetClassReturnType(projectContent, "System.Collections.IEnumerable", 0));
            }
        }
        private MSAst.LambdaExpression TransformGenerator(MSAst.LambdaExpression lambda)
        {
            GeneratorExpression generator = (GeneratorExpression)lambda.Body;

            MSAst.Expression body = generator.Body;

            _generatorLabelTarget = generator.Target;

            // $TODO: Detect if the label's type is not typeof(object), and create a new label
            Debug.Assert(_generatorLabelTarget.Type == typeof(object));

            _generatorParams.Add(_frame);

            Dictionary <MSAst.ParameterExpression, object> parameters = new Dictionary <MSAst.ParameterExpression, object>();

            foreach (MSAst.ParameterExpression parameter in lambda.Parameters)
            {
                parameters.Add(parameter, null);
            }

            // Add parameters to the pending list
            _pendingLocals.AddRange(lambda.Parameters);

            // Run 1st tree walk to identify all locals
            LambdaWalker lambdaWalker = new LambdaWalker();

            lambdaWalker.Visit(body);

            // Add all locals to pending list
            _pendingLocals.AddRange(lambdaWalker.Locals);

            // Prepare variables
            LayoutVariablesForGenerator(parameters);

            // Rewrite for generator
            MSAst.Expression generatorBody = TransformToGeneratorBody(body);

            // Get the generator factory lambda
            MSAst.LambdaExpression generatorFactoryLambda = CreateGeneratorFactoryLambda(generatorBody);

            // Create FunctionInfo object
            CreateFunctionInfo(generatorFactoryLambda);

            // Create our own outer generator lambda
            return(CreateOuterGeneratorFactory(lambda.Type));
        }
Example #20
0
        private static ISet <Namespace> EvaluateGenerator(ExpressionEvaluator ee, Node node)
        {
            GeneratorExpression gen = (GeneratorExpression)node;
            var funcBody            = gen.Function.Body;

            // evaluate the body of the generator
            while (funcBody != null)
            {
                ForStatement forStmt = funcBody as ForStatement;
                if (forStmt != null)
                {
                    ee.Evaluate(forStmt.List);
                    funcBody = forStmt.Body;
                    continue;
                }

                IfStatement ifStmt = funcBody as IfStatement;
                if (ifStmt != null)
                {
                    ee.Evaluate(ifStmt.Tests[0].Test);
                    funcBody = ifStmt.Tests[0].Body;
                    continue;
                }

                ExpressionStatement exprStmt = funcBody as ExpressionStatement;
                if (exprStmt != null)
                {
                    YieldExpression yieldExpr = exprStmt.Expression as YieldExpression;
                    if (yieldExpr != null)
                    {
                        ee.Evaluate(yieldExpr.Expression);
                        break;
                    }
                }

                break;
            }

            ee.Evaluate(gen.Iterable);

            return(ee.GlobalScope.GetOrMakeNodeVariable(
                       node,
                       (x) => new GeneratorInfo(new FunctionInfo(ee._unit)).SelfSet));
        }
Example #21
0
 // GeneratorExpression
 public override bool Walk(GeneratorExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
 // GeneratorExpression
 public override bool Walk(GeneratorExpression node) { return false; }
Example #23
0
 public override void LeaveGeneratorExpression(GeneratorExpression node)
 {
     CheckExpressionType(node.Expression);
 }
Example #24
0
 // GeneratorExpression
 public bool Walk(GeneratorExpression node)
 {
     return(Process(node));
 }
Example #25
0
 public override void PostWalk(GeneratorExpression node)
 {
 }
Example #26
0
 // GeneratorExpression
 public override bool Walk(GeneratorExpression node)
 {
     return(false);
 }
 public override void PostWalk(GeneratorExpression node) { }
Example #28
0
 public override void PostWalk(GeneratorExpression node)
 {
     EndScope(false);
     Debug.Assert(_head != null);
     base.PostWalk(node);
 }
 public virtual void PostWalk(GeneratorExpression node) { }
 // GeneratorExpression
 public virtual bool Walk(GeneratorExpression node) { return true; }
Example #31
0
 // GeneratorExpression
 public virtual bool Walk(GeneratorExpression node)
 {
     return(true);
 }
Example #32
0
 public override bool Walk(GeneratorExpression node)
 {
     BeginScope();
     return(base.Walk(node));
 }
Example #33
0
 public virtual void PostWalk(GeneratorExpression node)
 {
 }
Example #34
0
 public void PostWalk(GeneratorExpression node)
 {
     PostProcess(node);
 }
Example #35
0
 // GeneratorExpression
 public override bool Walk(GeneratorExpression node)
 {
     return(Location >= node.StartIndex && Location <= node.EndIndex);
 }