int IExpressionVisitor <int> .VisitAwait(AwaitExpression expression) { _Writer.Write("await "); WriteChildExpression(expression, expression.Operand); return(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); }
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)); }
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); }
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)); }
public bool Equals(ParameterExpression x, ParameterExpression y) => AwaitExpression.IsAwaiterHolder(x) && AwaitExpression.IsAwaiterHolder(y) ? x?.Type == y?.Type : object.Equals(x, y);
public override bool Walk(AwaitExpression node) { CanComplete = IsActualExpression(node.Expression); CommitByDefault = true; return(base.Walk(node)); }
public virtual void VisitAwaitExpression(AwaitExpression node) { this.Visit(node.get_Expression()); return; }
public override bool Walk(AwaitExpression node) { AddSpan(Tuple.Create("", new Span(node.StartIndex, 5)), Classifications.Keyword); return(base.Walk(node)); }
public virtual void PostWalk(AwaitExpression node) { }
public override bool Walk(AwaitExpression node) { HasSideEffects = true; return(false); }
public override bool Walk(AwaitExpression node) { return(UpdateLineInfo(node, true)); }
public ICodeNode VisitAwaitExpression(AwaitExpression node) { node.Expression = (Expression)Visit(node.Expression); return(node); }
public int GetHashCode(ParameterExpression variable) => AwaitExpression.IsAwaiterHolder(variable) ? variable.Type.GetHashCode() : variable.GetHashCode();
// AndExpression public override bool Walk(AwaitExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
public override void PostWalk(AwaitExpression node) { }
// AndExpression public override bool Walk(AwaitExpression node) { return false; }
public override bool Walk(AwaitExpression node) => Save(node, base.Walk(node), "await");
// AndExpression public override bool Walk(AwaitExpression node) { return(Location >= node.StartIndex && Location <= node.EndIndex); }
void ITreeWalker.Visit(AwaitExpression expression) { Header("Expression/Await"); WriteProperty("Payload", expression.Payload); }
// AwaitExpression public virtual bool Walk(AwaitExpression node) { return(true); }
private static void WriteAwait(CodeTextBuilder code, AwaitExpression expression) { code.Write("await "); WriteExpression(code, expression.Expression); }
public virtual void VisitAwaitExpression(AwaitExpression node) { Visit(node.Expression); }
// AndExpression public override bool Walk(AwaitExpression node) { return(false); }
/// <summary> /// Visits an awaitable expression. /// </summary> public virtual void Visit(AwaitExpression expression) { expression.Payload.Accept(this); }
// AwaitExpression public virtual bool Walk(AwaitExpression node) { return false; }
void ITreeWalker.Visit(AwaitExpression expression) { expression.Validate(this); InsertAwait(() => expression.Payload.Accept(this)); }
public override bool Walk(AwaitExpression node) { SeenAwait = true; return(false); }
/// <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); }