Exemplo n.º 1
0
        int IExpressionVisitor <int> .VisitAwait(AwaitExpression expression)
        {
            _Writer.Write("await ");
            WriteChildExpression(expression, expression.Operand);

            return(0);
        }
Exemplo n.º 2
0
        public override void OnAwaitExpression(AwaitExpression node)
        {
            var builder     = new BoundSpillSequenceBuilder();
            var replacement = VisitExpression(ref builder, node);

            ReplaceCurrentNode(builder.Update(replacement));
        }
        public void CodeAwaitExpression_ConfigureAwait()
        {
            var expression           = new AwaitExpression(new SnippetExpression("test"));
            var configuredExpression = expression.ConfigureAwait(continueOnCapturedContext: true);

            Assert.Equal(expression, configuredExpression);
            Assert.Equal(true, configuredExpression.Expression.As <MethodInvokeExpression>().Arguments[0].As <LiteralExpression>().Value);
        }
        public void CodeAwaitExpression_ConfigureAwait_NullExpression()
        {
            var expression           = new AwaitExpression();
            var configuredExpression = expression.ConfigureAwait(continueOnCapturedContext: true);

            Assert.Equal(expression, configuredExpression);
            Assert.Null(configuredExpression.Expression);
        }
        public void CSharpCodeGenerator_Await()
        {
            var statement = new AwaitExpression(new VariableReference("awaitable"));
            var generator = new CSharpCodeGenerator();
            var result    = generator.Write(statement);

            Assert.That.StringEquals("await awaitable", result);
        }
        public void CodeAwaitExpression_ConfigureAwait_NullExpression()
        {
            var expression           = new AwaitExpression();
            var configuredExpression = expression.ConfigureAwait(true);

            Assert.AreEqual(expression, configuredExpression);
            Assert.AreEqual(null, configuredExpression.Expression);
        }
Exemplo n.º 7
0
        private Expression VisitAwait(AwaitExpression node)
        {
            var prologue = context.CurrentStatement.PrologueCodeInserter();

            node = (AwaitExpression)base.VisitExtension(node);
            //allocate slot for awaiter
            var awaiterSlot = NewStateSlot(node.NewAwaiterHolder);

            //generate new state and label for it
            var(stateId, transition) = context.NewTransition(stateSwitchTable);
            //convert await expression into TAwaiter.GetResult() expression
            return(node.Reduce(awaiterSlot, stateId, transition.Successful ?? throw new InvalidOperationException(), AsyncMethodEnd, prologue));
        }
Exemplo n.º 8
0
        public virtual AwaitExpression RewriteAwaitExpression(AwaitExpression expression)
        {
            var newExpression = expression.Expression.AcceptRewriter(this);

            if (newExpression != expression.Expression)
            {
                return(new AwaitExpression {
                    Bindings = new BindingCollection(expression.Bindings),
                    Expression = newExpression,
                    Type = expression.Type
                });
            }

            return(expression);
        }
Exemplo n.º 9
0
        public void ShouldReduceAwaitToBlockingCall()
        {
            Task <string> sleepTask = new Task <string>(() =>
            {
                Thread.Sleep(1000);
                return("hey");
            });

            AwaitExpression expression = X.Await(X.Link(sleepTask));

            DateTime before = DateTime.Now;

            Action action = Expression.Lambda <Action>(expression).Compile();

            sleepTask.Start();
            action();

            TimeSpan timeTaken = DateTime.Now - before;

            timeTaken.ShouldBeGreaterThanOrEqualTo(TimeSpan.FromMilliseconds(1000));
        }
Exemplo n.º 10
0
 public bool Equals(ParameterExpression x, ParameterExpression y)
 => AwaitExpression.IsAwaiterHolder(x) && AwaitExpression.IsAwaiterHolder(y) ? x?.Type == y?.Type : object.Equals(x, y);
Exemplo n.º 11
0
 public override bool Walk(AwaitExpression node)
 {
     CanComplete     = IsActualExpression(node.Expression);
     CommitByDefault = true;
     return(base.Walk(node));
 }
Exemplo n.º 12
0
 public virtual void VisitAwaitExpression(AwaitExpression node)
 {
     this.Visit(node.get_Expression());
     return;
 }
Exemplo n.º 13
0
 public override bool Walk(AwaitExpression node)
 {
     AddSpan(Tuple.Create("", new Span(node.StartIndex, 5)), Classifications.Keyword);
     return(base.Walk(node));
 }
Exemplo n.º 14
0
 public virtual void PostWalk(AwaitExpression node)
 {
 }
Exemplo n.º 15
0
 public override bool Walk(AwaitExpression node)
 {
     HasSideEffects = true;
     return(false);
 }
Exemplo n.º 16
0
 public override bool Walk(AwaitExpression node)
 {
     return(UpdateLineInfo(node, true));
 }
Exemplo n.º 17
0
 public ICodeNode VisitAwaitExpression(AwaitExpression node)
 {
     node.Expression = (Expression)Visit(node.Expression);
     return(node);
 }
Exemplo n.º 18
0
 public int GetHashCode(ParameterExpression variable)
 => AwaitExpression.IsAwaiterHolder(variable) ? variable.Type.GetHashCode() : variable.GetHashCode();
Exemplo n.º 19
0
 // AndExpression
 public override bool Walk(AwaitExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
Exemplo n.º 20
0
 public override void PostWalk(AwaitExpression node) { }
Exemplo n.º 21
0
 // AndExpression
 public override bool Walk(AwaitExpression node) { return false; }
Exemplo n.º 22
0
 public override bool Walk(AwaitExpression node) => Save(node, base.Walk(node), "await");
Exemplo n.º 23
0
 // AndExpression
 public override bool Walk(AwaitExpression node)
 {
     return(Location >= node.StartIndex && Location <= node.EndIndex);
 }
Exemplo n.º 24
0
 void ITreeWalker.Visit(AwaitExpression expression)
 {
     Header("Expression/Await");
     WriteProperty("Payload", expression.Payload);
 }
Exemplo n.º 25
0
 // AwaitExpression
 public virtual bool Walk(AwaitExpression node)
 {
     return(true);
 }
Exemplo n.º 26
0
 private static void WriteAwait(CodeTextBuilder code, AwaitExpression expression)
 {
     code.Write("await ");
     WriteExpression(code, expression.Expression);
 }
Exemplo n.º 27
0
 public virtual void PostWalk(AwaitExpression node)
 {
 }
Exemplo n.º 28
0
 public virtual void VisitAwaitExpression(AwaitExpression node)
 {
     Visit(node.Expression);
 }
Exemplo n.º 29
0
 // AndExpression
 public override bool Walk(AwaitExpression node)
 {
     return(false);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Visits an awaitable expression.
 /// </summary>
 public virtual void Visit(AwaitExpression expression)
 {
     expression.Payload.Accept(this);
 }
Exemplo n.º 31
0
 public override void PostWalk(AwaitExpression node)
 {
 }
Exemplo n.º 32
0
 // AwaitExpression
 public virtual bool Walk(AwaitExpression node)
 {
     return false;
 }
Exemplo n.º 33
0
 void ITreeWalker.Visit(AwaitExpression expression)
 {
     expression.Validate(this);
     InsertAwait(() => expression.Payload.Accept(this));
 }
Exemplo n.º 34
0
 public override bool Walk(AwaitExpression node)
 {
     SeenAwait = true;
     return(false);
 }
Exemplo n.º 35
0
        /// <summary>
        ///     <c>
        ///         atom
        ///             : name
        ///             | await_expr
        ///             | yield_expr
        ///             | type_initializer_expr
        ///             | parenthesis_expr
        ///             | list_expr
        ///             | hash_collection
        ///             | CONSTANT
        ///     </c>
        /// </summary>
        internal static Expression ParseAtomExpr(AstNode parent)
        {
            Expression value;

            switch (parent.Peek.Type)
            {
            case Identifier: {
                value = NameExpression.ParseName(parent);
                break;
            }

            case KeywordIf: {
                return(new ConditionalExpression(parent));
            }

            case KeywordWhile: {
                return(new WhileExpression(parent));
            }

                #region Small statements

            case Semicolon:
            case KeywordPass: {
                return(new EmptyExpression(parent));
            }

            case KeywordBreak: {
                return(new BreakExpression(parent));
            }

            case KeywordContinue: {
                return(new ContinueExpression(parent));
            }

            case KeywordReturn: {
                return(new ReturnExpression(parent));
            }

            case KeywordAwait: {
                value = new AwaitExpression(parent);
                break;
            }

            case KeywordYield: {
                value = new YieldExpression(parent);
                break;
            }

                #endregion

            case KeywordModule: {
                return(new ModuleDefinition(parent));
            }

            case KeywordClass: {
                return(new ClassDefinition(parent));
            }

            case KeywordEnum: {
                return(new EnumDefinition(parent));
            }

            case KeywordFn: {
                return(new FunctionDefinition(parent));
            }

            case OpenBrace when parent.Ast.MacroExpectationType != typeof(BlockExpression): {
                value = new BraceCollectionExpression(parent);
                break;
            }

            case Indent:
            case OpenBrace:
            case Colon when parent.Ast.MacroExpectationType == typeof(BlockExpression): {
                value = new BlockExpression(parent);
                break;
            }

            case DoubleOpenBrace: {
                value = new CodeQuoteExpression(parent);
                break;
            }

            case OpenParenthesis: {
                Token start = parent.Token;
                parent.Eat(OpenParenthesis);
                // empty tuple
                if (parent.MaybeEat(CloseParenthesis))
                {
                    return(new TupleExpression(parent, start, parent.Token));
                }

                value = ParseMultiple(parent, parens: true);
                parent.Eat(CloseParenthesis);
                break;
            }

            default: {
                if (Spec.Constants.Contains(parent.Peek.Type))
                {
                    parent.GetNext();
                    // TODO add pre-concatenation of literals
                    value = new ConstantExpression(parent);
                }
                else
                {
                    value = ParseMacroApplication(parent);
                }

                break;
            }
            }

            return(value);
        }