예제 #1
0
        private static void GetPreviousBlock()
        {
            BlockSyntax block = root.DescendantNodes().OfType <BlockSyntax>().Where(n => n.HasAnnotation(currentBlock)).Single();

            block        = block.Parent as BlockSyntax;
            currentBlock = block.GetAnnotations("Block").Single();
        }
예제 #2
0
        static BlockSyntax InjectLastCallFrameStatements(BlockSyntax blockNode)
        {
            var allStatements           = blockNode.Statements;
            List <StatementSyntax> list = new List <StatementSyntax>();

            SyntaxAnnotation currentBlockAnnotation = blockNode.GetAnnotations(Annotations.AnnotationKind).FirstOrDefault();

            if (currentBlockAnnotation != null)
            {
                var buildLastCallFrameExpression = BuildLastCallFrameExpression(currentBlockAnnotation.Data, 0);
                if (buildLastCallFrameExpression != null)
                {
                    list.Add(buildLastCallFrameExpression);
                }
            }

            foreach (var syntaxNode in allStatements)
            {
                SyntaxAnnotation annotation = syntaxNode.GetAnnotations(Annotations.AnnotationKind).FirstOrDefault();

                // the recordValue annotation is added to expressionSyntax nodes, but stacked nodes are
                // wrapped in ExpressionStatementSyntax nodes when added to a stack's BlockSyntax.
                SyntaxAnnotation recordValueAnnotation = null;
                if (syntaxNode is ExpressionStatementSyntax ess)
                {
                    recordValueAnnotation = ess.Expression.GetAnnotations(Annotations.RecordValueKind).FirstOrDefault();
                }

                // if the node is already wrapped in a recordValue(), we're done
                if (annotation == null || recordValueAnnotation != null)
                {
                    list.Add(syntaxNode);
                    continue;
                }

                int recordedValuesCount = syntaxNode.GetAnnotatedNodes(Annotations.RecordValueKind).Count();
                ExpressionStatementSyntax buildLastCallFrameExpression = BuildLastCallFrameExpression(annotation.Data, recordedValuesCount);
                if (buildLastCallFrameExpression != null)
                {
                    list.Add(buildLastCallFrameExpression);
                }
                list.Add(syntaxNode);
            }

            return(blockNode.WithStatements(SyntaxFactory.List(list)));
        }
예제 #3
0
        internal static void ConvertIfToWhile()
        {
            //get current block
            BlockSyntax block = Root.DescendantNodes().OfType <BlockSyntax>().Where(n => n.HasAnnotation(CurrentBlock)).Single();

            if (!(block.Parent is IfStatementSyntax))
            {
                return;
            }

            //get if statement
            IfStatementSyntax ifStatement = block.Parent as IfStatementSyntax;
            //change it to a while
            WhileStatementSyntax whileStatement = SyntaxFactory.WhileStatement(ifStatement.Condition, ifStatement.Statement);

            //do the replacement
            Root = Root.ReplaceNode(ifStatement, whileStatement);

            BlockSyntax prevBlock = GetPreviousBlock();

            CurrentBlock = prevBlock.GetAnnotations("Block").Single();
        }
예제 #4
0
        public static BlockSyntax GetPreviousBlock()
        {
            BlockSyntax block     = Root.DescendantNodes().OfType <BlockSyntax>().Where(n => n.HasAnnotation(CurrentBlock)).Single();
            BlockSyntax prevBlock = null;

            if (block.Parent is ElseClauseSyntax elseStatement)
            {
                //ElseClauseSyntax elseStatement = block.Parent as ElseClauseSyntax;
                IfStatementSyntax ifStatement = elseStatement.Parent as IfStatementSyntax;
                prevBlock = ifStatement.Parent as BlockSyntax;
            }
            else if (block.Parent is IfStatementSyntax ifStatement)
            {
                //IfStatementSyntax ifStatement = block.Parent as IfStatementSyntax;
                prevBlock = ifStatement.Parent as BlockSyntax;
            }
            else if (block.Parent is WhileStatementSyntax whileStatement)
            {
                //IfStatementSyntax ifStatement = block.Parent as IfStatementSyntax;
                prevBlock = whileStatement.Parent as BlockSyntax;
            }
            else
            {
                prevBlock = block.Parent as BlockSyntax;
            }

            if (prevBlock == null)
            {
                //CurrentBlock = null;
                return(block);
            }

            CurrentBlock = prevBlock.GetAnnotations("Block").Single();

            return(prevBlock);
        }
예제 #5
0
 public static void SetBlockAsCurrent(BlockSyntax block)
 {
     CurrentBlock = block.GetAnnotations("Block").Single();
 }