Пример #1
0
        public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
        {
            var declaration = node;

            List <StatementSyntax> statements = new List <StatementSyntax>();

            markedNodes.Add(node);

            foreach (var variable in declaration.Declaration.Variables)
            {
                int              index           = _virtualizationContext.DataIndex;
                string           name            = variable.Identifier.Text;
                SyntaxAnnotation indexMarker     = new SyntaxAnnotation("index", index + "");
                SyntaxAnnotation nameMarker      = new SyntaxAnnotation("name", name);
                SyntaxAnnotation variableMarker  = new SyntaxAnnotation("type", "variable");
                SyntaxAnnotation codeIndexMarker = new SyntaxAnnotation("code", "undefined");
                SyntaxAnnotation uniqueMarker    = new SyntaxAnnotation("unique", "" + VirtualizationContext.UniqueId);

                var virtualData = new VirtualData();
                virtualData.Type  = declaration.Declaration.Type.ToString();
                virtualData.Index = index;
                virtualData.Name  = name;
                virtualData.Annotations.Add(indexMarker);
                virtualData.Annotations.Add(nameMarker);
                virtualData.Annotations.Add(variableMarker);
                virtualData.Annotations.Add(codeIndexMarker);
                virtualData.Annotations.Add(uniqueMarker);
                _virtualizationContext.data.Add(virtualData);

                //TODO: split for multiple variables in the same declaration
                var initializer = variable.Initializer;
                if (initializer == null)
                {
                    continue;
                }

                SyntaxNode rightValue;

                rightValue = initializer.DescendantNodes().First();
                ExpressionStatementSyntax newNode;
                if (SyntaxFactoryExtensions.IsBasicType(virtualData.Type))
                {
                    newNode = SyntaxFactoryExtensions.DataVirtualAssignment(rightValue, virtualData.Annotations.ToArray())
                              .WithLeadingTrivia(declaration.GetLeadingTrivia())
                              .WithTrailingTrivia(declaration.GetTrailingTrivia())
                    ;
                }
                else
                {
                    newNode = SyntaxFactoryExtensions.DataVirtualAssignment(virtualData.Type, rightValue, virtualData.Annotations.ToArray())
                              .WithLeadingTrivia(declaration.GetLeadingTrivia())
                              .WithTrailingTrivia(declaration.GetTrailingTrivia())
                    ;
                }

                virtualData.Node      = newNode;
                virtualData.Statement = newNode;
                statements.Add(newNode);
            }

            replacementNodes.Add(new Tuple <LocalDeclarationStatementSyntax, List <StatementSyntax> >(node, statements));

            return(node);
        }