public IEnumerable <StatementSyntax> GetFinalization() { yield return(SF.IfStatement(SF.BinaryExpression(SyntaxKind.GreaterThanExpression, SF.IdentifierName(outputIndex), SH.Literal(0)), SF.ExpressionStatement(SF.IdentifierName(outputParameter).Dot("Write").Invoke(SF.IdentifierName(outputBuffer), SH.Literal(0), SF.IdentifierName(outputIndex))))); yield return(SF.ReturnStatement()); }
public IEnumerable <StatementSyntax> GetYields(IEnumerable <ExpressionSyntax> yields, int numYields) { if (numYields == 0) { yield break; } if (numYields > BufferSize) { throw new NotImplementedException(); } yield return(SF.IfStatement(SF.BinaryExpression(SyntaxKind.GreaterThanExpression, SF.IdentifierName(outputIndex), SH.Literal(BufferSize - numYields)), SF.Block( SF.ExpressionStatement(SF.IdentifierName(outputParameter).Dot("Write").Invoke(SF.IdentifierName(outputBuffer), SH.Literal(0), SF.IdentifierName(outputIndex))), SH.Assignment(SF.IdentifierName(outputIndex), SH.Literal(0))))); int index = 0; foreach (var yieldSyntax in yields) { yield return(SH.Assignment(SF.ElementAccessExpression(SF.IdentifierName(outputBuffer), SF.BracketedArgumentList(SF.SingletonSeparatedList(SF.Argument( SF.BinaryExpression(SyntaxKind.AddExpression, SF.IdentifierName(outputIndex), SH.Literal(index)))))), yieldSyntax)); ++index; } yield return(SH.Assignment(SF.IdentifierName(outputIndex), SH.Literal(numYields), SyntaxKind.AddAssignmentExpression)); }
public static ExpressionStatementSyntax Assignment(ExpressionSyntax left, ExpressionSyntax right, SyntaxKind kind = SyntaxKind.SimpleAssignmentExpression) { return(SF.ExpressionStatement(SF.AssignmentExpression(kind, left, right))); }
private void AddExpression(ExpressionSyntax expression) => this.expressions.Add( SF.ExpressionStatement(expression));