Question

Visitor Pattern in SyntaxEditor for WPF

Posted 2 years ago by Avatar ibrahim
Hi,

Have you implemented AST visitor pattern for C# addon in SyntaxEditor for WPF?

Comments (5)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Ibrahim,

Sorry but not yet. We'll add the request to our TODO list.

Actipro Software Support
Posted 2 years ago by ibrahim
OK. I created my own visitor class with extension Accept methods (four hours of non-stop typing!). Now, I would like to modify the AST and generate C# code from the AST. Is there any built-in capability to do that?

[Modified at 02/12/2012 07:37 PM]
Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Ibrahim,

I'm sorry we don't have any AST-to-code mechanism at this time. I can add a TODO item for that.

Actipro Software Support
Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
By the way, would you mind posting a couple examples of what you added for the visitor pattern to benefit any other customers who are looking to add visitor support until we get it built into the product? It also would give us a clearer picture of what functionality you need for it.

Actipro Software Support
Posted 2 years ago by ibrahim
Here is the code. It works but is not tested thoroughly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ActiproSoftware.Text.Languages.DotNet.Ast.Implementation;
using ActiproSoftware.Text.Parsing;

namespace ActiproVisitor
{
    public class AstVisitorBase
    {
        public virtual void Visit(AccessorBody node) { }
        public virtual void Visit(AccessorDeclaration node) { }
        public virtual void Visit(AddressOfExpression node) { }
        public virtual void Visit(AggregateQueryOperator node) { }
        public virtual void Visit(AnonymousMethodExpression node) { }
        public virtual void Visit(Argument node) { }
        public virtual void Visit(ArrayEraseStatement node) { }
        public virtual void Visit(ArrayReallocateClause node) { }
        public virtual void Visit(ArrayReallocateStatement node) { }
        public virtual void Visit(AssignmentExpression node) { }
        public virtual void Visit(ActiproSoftware.Text.Languages.DotNet.Ast.Implementation.Attribute node) { }
        public virtual void Visit(AttributeArgument node) { }
        public virtual void Visit(AttributeSection node) { }
        public virtual void Visit(BinaryOperatorExpression node) { }
        public virtual void Visit(BlockStatement node) { }
        public virtual void Visit(BreakStatement node) { }
        public virtual void Visit(CastExpression node) { }
        public virtual void Visit(CatchClause node) { }
        public virtual void Visit(CheckedExpression node) { }
        public virtual void Visit(CheckedStatement node) { }
        public virtual void Visit(ClassBody node) { }
        public virtual void Visit(ClassDeclaration node) { }
        public virtual void Visit(CompilationUnit node) { }
        public virtual void Visit(CompilationUnitOption node) { }
        public virtual void Visit(ConditionalExpression node) { }
        public virtual void Visit(ConstructorBody node) { }
        public virtual void Visit(ConstructorDeclaration node) { }
        public virtual void Visit(ContinueStatement node) { }
        public virtual void Visit(DefaultValueExpression node) { }
        public virtual void Visit(DelegateDeclaration node) { }
        public virtual void Visit(DistinctQueryOperator node) { }
        public virtual void Visit(DocumentationComment node) { }
        public virtual void Visit(DoStatement node) { }
        public virtual void Visit(DotNetAstNodeId node) { }
        public virtual void Visit(ElseIfSection node) { }
        public virtual void Visit(EndStatement node) { }
        public virtual void Visit(EnumerationBody node) { }
        public virtual void Visit(EnumerationDeclaration node) { }
        public virtual void Visit(EnumerationMemberDeclaration node) { }
        public virtual void Visit(EventBody node) { }
        public virtual void Visit(EventDeclaration node) { }
        public virtual void Visit(ExitStatement node) { }
        public virtual void Visit(ExpressionStatement node) { }
        public virtual void Visit(ExternalAliasDirective node) { }
        public virtual void Visit(ExternalAliasDirectiveSection node) { }
        public virtual void Visit(FieldDeclaration node) { }
        public virtual void Visit(FixedSizeBufferDeclaration node) { }
        public virtual void Visit(FixedSizeBufferDeclarator node) { }
        public virtual void Visit(FixedStatement node) { }
        public virtual void Visit(ForEachStatement node) { }
        public virtual void Visit(ForStatement node) { }
        public virtual void Visit(FromQueryOperator node) { }
        public virtual void Visit(GoToStatement node) { }
        public virtual void Visit(GroupQueryOperator node) { }
        public virtual void Visit(IfStatement node) { }
        public virtual void Visit(InitializerExpression node) { }
        public virtual void Visit(InstanceExpression node) { }
        public virtual void Visit(InterfaceAccessorDeclaration node) { }
        public virtual void Visit(InterfaceBody node) { }
        public virtual void Visit(InterfaceDeclaration node) { }
        public virtual void Visit(InterfaceEventDeclaration node) { }
        public virtual void Visit(InterfaceMemberDeclaration node) { }
        public virtual void Visit(InterfaceMethodDeclaration node) { }
        public virtual void Visit(InterfacePropertyDeclaration node) { }
        public virtual void Visit(InvocationExpression node) { }
        public virtual void Visit(IsTypeOfExpression node) { }
        public virtual void Visit(JoinQueryOperator node) { }
        public virtual void Visit(LabeledStatement node) { }
        public virtual void Visit(LambdaExpression node) { }
        public virtual void Visit(LetQueryOperator node) { }
        public virtual void Visit(LiteralExpression node) { }
        public virtual void Visit(LocalVariableDeclaration node) { }
        public virtual void Visit(LockStatement node) { }
        public virtual void Visit(MemberAccess node) { }
        public virtual void Visit(MethodBody node) { }
        public virtual void Visit(MethodDeclaration node) { }
        public virtual void Visit(NamespaceBody node) { }
        public virtual void Visit(NamespaceDeclaration node) { }
        public virtual void Visit(ObjectCreationExpression node) { }
        public virtual void Visit(OperatorBody node) { }
        public virtual void Visit(OperatorDeclaration node) { }
        public virtual void Visit(OrderByQueryOperator node) { }
        public virtual void Visit(Ordering node) { }
        public virtual void Visit(ParameterDeclaration node) { }
        public virtual void Visit(ParenthesizedExpression node) { }
        public virtual void Visit(PreprocessorDirective node) { }
        public virtual void Visit(PropertyBody node) { }
        public virtual void Visit(PropertyDeclaration node) { }
        public virtual void Visit(QualifiedName node) { }
        public virtual void Visit(QueryExpression node) { }
        public virtual void Visit(QueryOperator node) { }
        public virtual void Visit(RangeVariableDeclaration node) { }
        public virtual void Visit(RangeVariableDeclarator node) { }
        public virtual void Visit(RegionPreprocessorDirective node) { }
        public virtual void Visit(ReturnStatement node) { }
        public virtual void Visit(ReturnTypeDeclaration node) { }
        public virtual void Visit(SelectQueryOperator node) { }
        public virtual void Visit(SimpleName node) { }
        public virtual void Visit(SizeOfExpression node) { }
        public virtual void Visit(SkipQueryOperator node) { }
        public virtual void Visit(SkipWhileQueryOperator node) { }
        public virtual void Visit(StackAllocationInitializer node) { }
        public virtual void Visit(StopStatement node) { }
        public virtual void Visit(StructureBody node) { }
        public virtual void Visit(StructureDeclaration node) { }
        public virtual void Visit(SwitchSection node) { }
        public virtual void Visit(SwitchStatement node) { }
        public virtual void Visit(TakeQueryOperator node) { }
        public virtual void Visit(TakeWhileQueryOperator node) { }
        public virtual void Visit(ThrowStatement node) { }
        public virtual void Visit(TryCastExpression node) { }
        public virtual void Visit(TryStatement node) { }
        public virtual void Visit(TypeDeclaration node) { }
        public virtual void Visit(TypeMemberDeclaration node) { }
        public virtual void Visit(TypeOfExpression node) { }
        public virtual void Visit(TypeParameter node) { }
        public virtual void Visit(UnaryOperatorExpression node) { }
        public virtual void Visit(UncheckedExpression node) { }
        public virtual void Visit(UncheckedStatement node) { }
        public virtual void Visit(UnsafeStatement node) { }
        public virtual void Visit(UnstructuredErrorHandlerStatement node) { }
        public virtual void Visit(UnstructuredErrorResumeStatement node) { }
        public virtual void Visit(UnstructuredErrorThrowStatement node) { }
        public virtual void Visit(UsingDirective node) { }
        public virtual void Visit(UsingDirectiveSection node) { }
        public virtual void Visit(UsingStatement node) { }
        public virtual void Visit(VariableDeclarationExpression node) { }
        public virtual void Visit(VariableDeclarator node) { }
        public virtual void Visit(WhereQueryOperator node) { }
        public virtual void Visit(WhileStatement node) { }
        public virtual void Visit(WithStatement node) { }
        public virtual void Visit(WithTargetExpression node) { }
        public virtual void Visit(XmlNamespaceExpression node) { }
        public virtual void Visit(YieldStatement node) { }
    }

    public static class AstNodeExtension
    {
        public static void Accept(this AccessorBody node, AstVisitorBase visitor)
        {
            node.Statements.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<Statement> nodes, AstVisitorBase visitor)
        {
            foreach (Statement statement in nodes)
                Accept(statement, visitor);
        }

        private static void Accept(this IList<ParameterDeclaration> nodes, AstVisitorBase visitor)
        {
            foreach (ParameterDeclaration node in nodes)
                Accept(node, visitor);
        }

        public static void Accept(this AccessorDeclaration node, AstVisitorBase visitor)
        {
            node.Parameters.Accept(visitor);
            if (node.Body != null)
                node.Body.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this AddressOfExpression node, AstVisitorBase visitor)
        {
            node.ChildExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this AggregateQueryOperator node, AstVisitorBase visitor)
        {
            node.Declarator.Accept(visitor);
            node.Projection.Accept(visitor);
            node.ChildQueryOperators.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<QueryOperator> nodes, AstVisitorBase visitor)
        {
            foreach (QueryOperator node in nodes)
                Accept(node, visitor);
        }

        public static void Accept(this AnonymousMethodExpression node, AstVisitorBase visitor)
        {
            node.Parameters.Accept(visitor);
            node.Statements.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this Argument node, AstVisitorBase visitor)
        {
            node.Expression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ArrayEraseStatement node, AstVisitorBase visitor)
        {
            node.VariableNames.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<Expression> nodes, AstVisitorBase visitor)
        {
            foreach (Expression node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this ArrayReallocateClause node, AstVisitorBase visitor)
        {
            node.Arguments.Accept(visitor);
            node.VariableName.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ArrayReallocateStatement node, AstVisitorBase visitor)
        {
            node.Clauses.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<ArrayReallocateClause> nodes, AstVisitorBase visitor)
        {
            foreach (ArrayReallocateClause node in nodes)
                Accept(node, visitor);
        }

        public static void Accept(this AssignmentExpression node, AstVisitorBase visitor)
        {
            node.RightExpression.Accept(visitor);
            node.LeftExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ActiproSoftware.Text.Languages.DotNet.Ast.Implementation.Attribute node, AstVisitorBase visitor)
        {
            node.Arguments.Accept(visitor);
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<AttributeArgument> nodes, AstVisitorBase visitor)
        {
            foreach (AttributeArgument node in nodes)
                Accept(node, visitor);
        }

        public static void Accept(this AttributeArgument node, AstVisitorBase visitor)
        {
            node.Expression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this AttributeSection node, AstVisitorBase visitor)
        {
            node.Attributes.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<ActiproSoftware.Text.Languages.DotNet.Ast.Implementation.Attribute> nodes, AstVisitorBase visitor)
        {
            foreach (ActiproSoftware.Text.Languages.DotNet.Ast.Implementation.Attribute node in nodes)
                Accept(node, visitor);
        }

        public static void Accept(this BinaryOperatorExpression node, AstVisitorBase visitor)
        {
            node.LeftExpression.Accept(visitor);
            node.RightExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this BlockStatement node, AstVisitorBase visitor)
        {
            node.ChildStatements.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this BreakStatement node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this CastExpression node, AstVisitorBase visitor)
        {
            node.Type.Accept(visitor);
            node.ChildExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this CatchClause node, AstVisitorBase visitor)
        {
            node.CatchBlock.Accept(visitor);
            node.ConditionExpression.Accept(visitor);

            if (node.VariableDeclarator != null)
                node.VariableDeclarator.Accept(visitor);

            visitor.Visit(node);
        }

        public static void Accept(this CheckedExpression node, AstVisitorBase visitor)
        {
            node.ChildExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this CheckedStatement node, AstVisitorBase visitor)
        {
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ClassBody node, AstVisitorBase visitor)
        {
            AcceptMemberDeclarations(node.Members, visitor);
        }

        private static void AcceptMemberDeclarations(IList<IAstNode> nodes, AstVisitorBase visitor)
        {
            foreach (IAstNode member in nodes)
            {
                AcceptMemberDeclaration(member, visitor);
            }
        }

        private static void AcceptMemberDeclaration(IAstNode member, AstVisitorBase visitor)
        {
            if (member is FieldDeclaration)
                (member as FieldDeclaration).Accept(visitor);
            else if (member is PropertyDeclaration)
                (member as PropertyDeclaration).Accept(visitor);
            else if (member is MethodDeclaration)
                (member as MethodDeclaration).Accept(visitor);
            else if (member is ConstructorDeclaration)
                (member as ConstructorDeclaration).Accept(visitor);
            else if (member is ClassDeclaration)
                (member as ClassDeclaration).Accept(visitor);
            else if (member is EnumerationDeclaration)
                (member as EnumerationDeclaration).Accept(visitor);
            else if (member is EventDeclaration)
                (member as EventDeclaration).Accept(visitor);
            else if (member is DelegateDeclaration)
                (member as DelegateDeclaration).Accept(visitor);
            else if (member is InterfaceDeclaration)
                (member as InterfaceDeclaration).Accept(visitor);
            else if (member is NamespaceDeclaration)
                (member as NamespaceDeclaration).Accept(visitor);
            else if (member is UsingDirectiveSection)
                (member as UsingDirectiveSection).Accept(visitor);
        }

        public static void Accept(this ClassDeclaration node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            node.BaseTypes.Accept(visitor);
            node.TypeParameters.Accept(visitor);
            if (node.Body != null)
                node.Body.Accept(visitor);
        }

        private static void Accept(this IList<TypeParameter> nodes, AstVisitorBase visitor)
        {
            foreach (TypeParameter node in nodes)
                Accept(node, visitor);
        }

        private static void Accept(this IList<QualifiedName> nodes, AstVisitorBase visitor)
        {
            foreach (QualifiedName node in nodes)
                Accept(node, visitor);
        }

        private static void Accept(this IList<AttributeSection> nodes, AstVisitorBase visitor)
        {
            foreach (AttributeSection node in nodes)
                Accept(node, visitor);
        }

        public static void Accept(this CompilationUnit node, AstVisitorBase visitor)
        {
            AcceptMemberDeclarations(node.Members, visitor);
        }

        public static void Accept(this CompilationUnitOption node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this ConditionalExpression node, AstVisitorBase visitor)
        {
            node.ConditionExpression.Accept(visitor);
            if (node.TrueExpression != null)
                node.TrueExpression.Accept(visitor);
            else if (node.FalseExpression != null)
                node.FalseExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ConstructorBody node, AstVisitorBase visitor)
        {
            node.Statements.Accept(visitor);
            visitor.Visit(node);
        }

        private static void VisitTypeMemberCommon(TypeMemberDeclaration node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            node.DocumentationComment.Accept(visitor);
        }

        public static void Accept(this ConstructorDeclaration node, AstVisitorBase visitor)
        {
            VisitTypeMemberCommon(node, visitor);

            if (node.Body != null)
                node.Body.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ContinueStatement node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this DefaultValueExpression node, AstVisitorBase visitor)
        {
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this DelegateDeclaration node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            node.Parameters.Accept(visitor);
            node.ReturnType.Accept(visitor);
            node.TypeParameters.Accept(visitor);
            node.DocumentationComment.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this DistinctQueryOperator node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this DocumentationComment node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this DoStatement node, AstVisitorBase visitor)
        {
            node.ConditionExpression.Accept(visitor);
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this DotNetAstNodeId node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this ElseIfSection node, AstVisitorBase visitor)
        {
            node.ConditionExpression.Accept(visitor);
            node.Statement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this EndStatement node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this EnumerationBody node, AstVisitorBase visitor)
        {
            node.Members.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<EnumerationMemberDeclaration> nodes, AstVisitorBase visitor)
        {
            foreach (EnumerationMemberDeclaration node in nodes)
                Accept(node, visitor);
        }

        public static void Accept(this EnumerationDeclaration node, AstVisitorBase visitor)
        {
            AcceptTypeDeclaration(node, visitor);
            if (node.BaseType != null)
                node.BaseType.Accept(visitor);
            if (node.Body != null)
                node.Body.Accept(visitor);
            visitor.Visit(node);
        }

        private static void AcceptTypeDeclaration(TypeDeclaration node, AstVisitorBase visitor)
        {
            node.Name.Accept(visitor);
            node.DocumentationComment.Accept(visitor);
            node.AttributeSections.Accept(visitor);
        }

        public static void Accept(this EnumerationMemberDeclaration node, AstVisitorBase visitor)
        {
            node.Name.Accept(visitor);
            if (node.Initializer != null)
                node.Initializer.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this EventBody node, AstVisitorBase visitor)
        {
            node.Accessors.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<AccessorDeclaration> nodes, AstVisitorBase visitor)
        {
            foreach (AccessorDeclaration node in nodes)
                Accept(node, visitor);
        }

        public static void Accept(this EventDeclaration node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            node.DocumentationComment.Accept(visitor);
            node.DelegateType.Accept(visitor);
            node.Implements.Accept(visitor);

            if (node.Body != null)
                node.Body.Accept(visitor);

            visitor.Visit(node);
        }

        public static void Accept(this ExitStatement node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this Expression node, AstVisitorBase visitor)
        {
            if (node is AddressOfExpression) (node as AddressOfExpression).Accept(visitor);
            else if (node is AnonymousMethodExpression) (node as AnonymousMethodExpression).Accept(visitor);
            else if (node is AssignmentExpression) (node as AssignmentExpression).Accept(visitor);
            else if (node is BinaryOperatorExpression) (node as BinaryOperatorExpression).Accept(visitor);
            else if (node is CastExpression) (node as CastExpression).Accept(visitor);
            else if (node is CheckedExpression) (node as CheckedExpression).Accept(visitor);
            else if (node is ConditionalExpression) (node as ConditionalExpression).Accept(visitor);
            else if (node is DefaultValueExpression) (node as DefaultValueExpression).Accept(visitor);
            else if (node is InitializerExpression) (node as InitializerExpression).Accept(visitor);
            else if (node is InstanceExpression) (node as InstanceExpression).Accept(visitor);
            else if (node is InvocationExpression) (node as InvocationExpression).Accept(visitor);
            else if (node is LambdaExpression) (node as LambdaExpression).Accept(visitor);
            else if (node is LiteralExpression) (node as LiteralExpression).Accept(visitor);
            else if (node is ObjectCreationExpression) (node as ObjectCreationExpression).Accept(visitor);
            else if (node is ParenthesizedExpression) (node as ParenthesizedExpression).Accept(visitor);
            else if (node is QueryExpression) (node as QueryExpression).Accept(visitor);
            else if (node is SizeOfExpression) (node as SizeOfExpression).Accept(visitor);
            else if (node is TryCastExpression) (node as TryCastExpression).Accept(visitor);
            else if (node is TypeOfExpression) (node as TypeOfExpression).Accept(visitor);
            else if (node is UnaryOperatorExpression) (node as UnaryOperatorExpression).Accept(visitor);
            else if (node is UncheckedExpression) (node as UncheckedExpression).Accept(visitor);
            else if (node is VariableDeclarationExpression) (node as VariableDeclarationExpression).Accept(visitor);
            else if (node is WithTargetExpression) (node as WithTargetExpression).Accept(visitor);
            else if (node is XmlNamespaceExpression) (node as XmlNamespaceExpression).Accept(visitor);
        }

        public static void Accept(this ExpressionStatement node, AstVisitorBase visitor)
        {
            node.Expression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ExternalAliasDirective node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this ExternalAliasDirectiveSection node, AstVisitorBase visitor)
        {
            node.Directives.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<ExternalAliasDirective> nodes, AstVisitorBase visitor)
        {
            foreach (ExternalAliasDirective node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this FieldDeclaration node, AstVisitorBase visitor)
        {
            node.Declarators.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<VariableDeclarator> nodes, AstVisitorBase visitor)
        {
            foreach (VariableDeclarator node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this FixedSizeBufferDeclaration node, AstVisitorBase visitor)
        {
            node.Declarators.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<FixedSizeBufferDeclarator> nodes, AstVisitorBase visitor)
        {
            foreach (FixedSizeBufferDeclarator node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this FixedSizeBufferDeclarator node, AstVisitorBase visitor)
        {
            node.Name.Accept(visitor);
            node.SizeExpression.Accept(visitor);
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this FixedStatement node, AstVisitorBase visitor)
        {
            node.VariableDeclarators.Accept(visitor);
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ForEachStatement node, AstVisitorBase visitor)
        {
            node.EnumerableExpression.Accept(visitor);
            node.ElementExpression.Accept(visitor);
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ForStatement node, AstVisitorBase visitor)
        {
            node.InitializerExpressions.Accept(visitor);
            node.ConditionExpression.Accept(visitor);
            node.IteratorExpressions.Accept(visitor);
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this FromQueryOperator node, AstVisitorBase visitor)
        {
            node.Declarators.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<RangeVariableDeclarator> nodes, AstVisitorBase visitor)
        {
            foreach (RangeVariableDeclarator node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this GoToStatement node, AstVisitorBase visitor)
        {
            node.Label.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this GroupQueryOperator node, AstVisitorBase visitor)
        {
            node.Key.Accept(visitor);
            node.Projection.Accept(visitor);
            node.Source.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this IfStatement node, AstVisitorBase visitor)
        {
            node.ConditionExpression.Accept(visitor);
            node.TrueStatement.Accept(visitor);
            if (node.FalseStatement != null)
                node.FalseStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this InitializerExpression node, AstVisitorBase visitor)
        {
            node.Initializers.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this InstanceExpression node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this InterfaceAccessorDeclaration node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this InterfaceBody node, AstVisitorBase visitor)
        {
            foreach (IAstNode member in node.Members)
            {
                if (member is InterfaceMethodDeclaration)
                    (member as InterfaceMethodDeclaration).Accept(visitor);
                else if (member is InterfaceEventDeclaration)
                    (member as InterfaceEventDeclaration).Accept(visitor);
                else if (member is InterfacePropertyDeclaration)
                    (member as InterfacePropertyDeclaration).Accept(visitor);
            }
        }

        public static void Accept(this InterfaceDeclaration node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            node.DocumentationComment.Accept(visitor);

            if (node.Body != null)
                node.Body.Accept(visitor);

            node.TypeParameters.Accept(visitor);
            node.BaseTypes.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this InterfaceEventDeclaration node, AstVisitorBase visitor)
        {
            node.DocumentationComment.Accept(visitor);
            node.AttributeSections.Accept(visitor);
            node.DelegateType.Accept(visitor);
            if (node.DelegateDeclaration != null)
                node.DelegateDeclaration.Accept(visitor);
            node.Name.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this InterfaceMethodDeclaration node, AstVisitorBase visitor)
        {
            node.DocumentationComment.Accept(visitor);
            node.AttributeSections.Accept(visitor);
            node.ReturnType.Accept(visitor);
            node.Parameters.Accept(visitor);
            node.TypeParameters.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this InterfacePropertyDeclaration node, AstVisitorBase visitor)
        {
            node.DocumentationComment.Accept(visitor);
            node.AttributeSections.Accept(visitor);
            node.Type.Accept(visitor);
            node.Parameters.Accept(visitor);
            node.Accessors.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<InterfaceAccessorDeclaration> nodes, AstVisitorBase visitor)
        {
            foreach (InterfaceAccessorDeclaration node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this InvocationExpression node, AstVisitorBase visitor)
        {
            node.TargetExpression.Accept(visitor);
            node.Arguments.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<Argument> nodes, AstVisitorBase visitor)
        {
            foreach (Argument node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this IsTypeOfExpression node, AstVisitorBase visitor)
        {
            node.ChildExpression.Accept(visitor);
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this JoinQueryOperator node, AstVisitorBase visitor)
        {
            node.ChildJoin.Accept(visitor);
            node.Declarator.Accept(visitor);
            node.LeftKeyExpression.Accept(visitor);
            node.RightKeyExpression.Accept(visitor);
            node.Projection.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this LabeledStatement node, AstVisitorBase visitor)
        {
            node.Label.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this LambdaExpression node, AstVisitorBase visitor)
        {
            if (node.HasParameters)
                node.Parameters.Accept(visitor);
            if (node.HasStatements)
                node.Statements.Accept(visitor);
        }

        public static void Accept(this LetQueryOperator node, AstVisitorBase visitor)
        {
            node.Projection.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this LiteralExpression node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this LocalVariableDeclaration node, AstVisitorBase visitor)
        {
            node.Declarators.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this LockStatement node, AstVisitorBase visitor)
        {
            node.Expression.Accept(visitor);
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this MemberAccess node, AstVisitorBase visitor)
        {
            node.Name.Accept(visitor);
            node.TargetExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this MethodBody node, AstVisitorBase visitor)
        {
            node.Statements.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this MethodDeclaration node, AstVisitorBase visitor)
        {
            VisitTypeMemberCommon(node, visitor);
            node.Parameters.Accept(visitor);
            if (node.ReturnType != null)
                node.ReturnType.Accept(visitor);
            node.Implements.Accept(visitor);
            node.Name.Accept(visitor);
            node.Handles.Accept(visitor);
            node.TypeParameters.Accept(visitor);

            if (node.Body != null)
                node.Body.Accept(visitor);

            visitor.Visit(node);
        }

        public static void Accept(this NamespaceBody node, AstVisitorBase visitor)
        {
            AcceptMemberDeclarations(node.Members, visitor);
            visitor.Visit(node);
        }

        public static void Accept(this NamespaceDeclaration node, AstVisitorBase visitor)
        {
            node.Name.Accept(visitor);

            if (node.Body != null)
                node.Body.Accept(visitor);

            visitor.Visit(node);
        }

        public static void Accept(this ObjectCreationExpression node, AstVisitorBase visitor)
        {
            node.Type.Accept(visitor);
            node.Arguments.Accept(visitor);
            if (node.Initializer != null)
                node.Initializer.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this OperatorBody node, AstVisitorBase visitor)
        {
            node.Statements.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this OperatorDeclaration node, AstVisitorBase visitor)
        {
            VisitTypeMemberCommon(node, visitor);
            node.ReturnType.Accept(visitor);
            node.Parameters.Accept(visitor);

            if (node.Body != null)
                node.Body.Accept(visitor);

            visitor.Visit(node);
        }

        public static void Accept(this OrderByQueryOperator node, AstVisitorBase visitor)
        {
            node.Orderings.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<Ordering> nodes, AstVisitorBase visitor)
        {
            foreach (Ordering node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this Ordering node, AstVisitorBase visitor)
        {
            node.Expression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ParameterDeclaration node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            node.Name.Accept(visitor);
            if (node.Type != null)
                node.Type.Accept(visitor);
            if (node.Initializer != null)
                node.Initializer.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ParenthesizedExpression node, AstVisitorBase visitor)
        {
            node.ChildExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this PreprocessorDirective node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this PropertyBody node, AstVisitorBase visitor)
        {
            node.Accessors.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this PropertyDeclaration node, AstVisitorBase visitor)
        {
            VisitTypeMemberCommon(node, visitor);
            if (node.Initializer != null)
                node.Initializer.Accept(visitor);
            if (node.HasImplements)
                node.Implements.Accept(visitor);
            node.Type.Accept(visitor);
            node.Parameters.Accept(visitor);
            node.Name.Accept(visitor);

            if (node.Body != null)
                node.Body.Accept(visitor);

            visitor.Visit(node);
        }

        public static void Accept(this QualifiedName node, AstVisitorBase visitor)
        {
            node.Identifiers.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<SimpleName> nodes, AstVisitorBase visitor)
        {
            foreach (SimpleName node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this QueryExpression node, AstVisitorBase visitor)
        {
            node.QueryOperators.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this QueryOperator node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this RangeVariableDeclaration node, AstVisitorBase visitor)
        {
            node.Declarators.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this RangeVariableDeclarator node, AstVisitorBase visitor)
        {
            node.Name.Accept(visitor);
            node.Source.Accept(visitor);
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this RegionPreprocessorDirective node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this ReturnStatement node, AstVisitorBase visitor)
        {
            if (node.Expression != null)
                node.Expression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ReturnTypeDeclaration node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this SelectQueryOperator node, AstVisitorBase visitor)
        {
            node.Projection.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this SimpleName node, AstVisitorBase visitor)
        {
            node.TypeArguments.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this SizeOfExpression node, AstVisitorBase visitor)
        {
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this SkipQueryOperator node, AstVisitorBase visitor)
        {
            node.CountExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this SkipWhileQueryOperator node, AstVisitorBase visitor)
        {
            node.ConditionExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this StackAllocationInitializer node, AstVisitorBase visitor)
        {
            node.SizeExpression.Accept(visitor);
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this Statement node, AstVisitorBase visitor)
        {
            if (node is ArrayEraseStatement) (node as ArrayEraseStatement).Accept(visitor);
            else if (node is ArrayReallocateStatement) (node as ArrayReallocateStatement).Accept(visitor);
            else if (node is BlockStatement) (node as BlockStatement).Accept(visitor);
            else if (node is BreakStatement) (node as BreakStatement).Accept(visitor);
            else if (node is CheckedStatement) (node as CheckedStatement).Accept(visitor);
            else if (node is ContinueStatement) (node as ContinueStatement).Accept(visitor);
            else if (node is DoStatement) (node as DoStatement).Accept(visitor);
            else if (node is EndStatement) (node as EndStatement).Accept(visitor);
            else if (node is ExitStatement) (node as ExitStatement).Accept(visitor);
            else if (node is ExpressionStatement) (node as ExpressionStatement).Accept(visitor);
            else if (node is FixedStatement) (node as FixedStatement).Accept(visitor);
            else if (node is ForEachStatement) (node as ForEachStatement).Accept(visitor);
            else if (node is ForStatement) (node as ForStatement).Accept(visitor);
            else if (node is GoToStatement) (node as GoToStatement).Accept(visitor);
            else if (node is IfStatement) (node as IfStatement).Accept(visitor);
            else if (node is LabeledStatement) (node as LabeledStatement).Accept(visitor);
            else if (node is LockStatement) (node as LockStatement).Accept(visitor);
            else if (node is ReturnStatement) (node as ReturnStatement).Accept(visitor);
            else if (node is StopStatement) (node as StopStatement).Accept(visitor);
            else if (node is SwitchStatement) (node as SwitchStatement).Accept(visitor);
            else if (node is ThrowStatement) (node as ThrowStatement).Accept(visitor);
            else if (node is TryStatement) (node as TryStatement).Accept(visitor);
            else if (node is UncheckedStatement) (node as UncheckedStatement).Accept(visitor);
            else if (node is UnsafeStatement) (node as UnsafeStatement).Accept(visitor);
            else if (node is UnstructuredErrorHandlerStatement) (node as UnstructuredErrorHandlerStatement).Accept(visitor);
            else if (node is UnstructuredErrorResumeStatement) (node as UnstructuredErrorResumeStatement).Accept(visitor);
            else if (node is UnstructuredErrorThrowStatement) (node as UnstructuredErrorThrowStatement).Accept(visitor);
            else if (node is UsingStatement) (node as UsingStatement).Accept(visitor);
            else if (node is WhileStatement) (node as WhileStatement).Accept(visitor);
            else if (node is WithStatement) (node as WithStatement).Accept(visitor);
            else if (node is YieldStatement) (node as YieldStatement).Accept(visitor);
        }

        public static void Accept(this StopStatement node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this StructureBody node, AstVisitorBase visitor)
        {
            AcceptMemberDeclarations(node.Members, visitor);
            visitor.Visit(node);
        }

        public static void Accept(this StructureDeclaration node, AstVisitorBase visitor)
        {
            AcceptTypeDeclaration(node, visitor);
            node.BaseTypes.Accept(visitor);
            node.TypeParameters.Accept(visitor);

            if (node.Body != null)
                node.Body.Accept(visitor);

            visitor.Visit(node);
        }

        public static void Accept(this SwitchSection node, AstVisitorBase visitor)
        {
            node.Labels.Accept(visitor);
            node.Statements.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this SwitchStatement node, AstVisitorBase visitor)
        {
            node.Expression.Accept(visitor);
            node.Sections.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<SwitchSection> nodes, AstVisitorBase visitor)
        {
            foreach (SwitchSection node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this TakeQueryOperator node, AstVisitorBase visitor)
        {
            node.CountExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this TakeWhileQueryOperator node, AstVisitorBase visitor)
        {
            node.ConditionExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this ThrowStatement node, AstVisitorBase visitor)
        {
            if (node.Expression != null)
                node.Expression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this TryCastExpression node, AstVisitorBase visitor)
        {
            node.Type.Accept(visitor);
            node.ChildExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this TryStatement node, AstVisitorBase visitor)
        {
            node.TryBlock.Accept(visitor);
            node.CatchClauses.Accept(visitor);

            if (node.FinallyBlock != null)
                node.FinallyBlock.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<CatchClause> nodes, AstVisitorBase visitor)
        {
            foreach (CatchClause node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this TypeMemberDeclaration node, AstVisitorBase visitor)
        {
            AcceptMemberDeclaration(node, visitor);
        }

        public static void Accept(this TypeOfExpression node, AstVisitorBase visitor)
        {
            node.Type.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this TypeParameter node, AstVisitorBase visitor)
        {
            node.AttributeSections.Accept(visitor);
            node.TypeConstraints.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UnaryOperatorExpression node, AstVisitorBase visitor)
        {
            node.ChildExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UncheckedExpression node, AstVisitorBase visitor)
        {
            node.ChildExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UncheckedStatement node, AstVisitorBase visitor)
        {
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UnsafeStatement node, AstVisitorBase visitor)
        {
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UnstructuredErrorHandlerStatement node, AstVisitorBase visitor)
        {
            node.Label.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UnstructuredErrorResumeStatement node, AstVisitorBase visitor)
        {
            node.Label.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UnstructuredErrorThrowStatement node, AstVisitorBase visitor)
        {
            node.Expression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UsingDirective node, AstVisitorBase visitor)
        {
            node.Name.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this UsingDirectiveSection node, AstVisitorBase visitor)
        {
            node.Directives.Accept(visitor);
            visitor.Visit(node);
        }

        private static void Accept(this IList<UsingDirective> nodes, AstVisitorBase visitor)
        {
            foreach (UsingDirective node in nodes)
                node.Accept(visitor);
        }

        public static void Accept(this UsingStatement node, AstVisitorBase visitor)
        {
            node.ResourceAcquisition.Accept(visitor);
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this VariableDeclarationExpression node, AstVisitorBase visitor)
        {
            node.Declarators.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this VariableDeclarator node, AstVisitorBase visitor)
        {
            if (node.Name != null)
                node.Name.Accept(visitor);

            if (node.Type != null)
                node.Type.Accept(visitor);

            if (node.Initializer != null)
                node.Initializer.Accept(visitor);

            visitor.Visit(node);
        }

        public static void Accept(this WhereQueryOperator node, AstVisitorBase visitor)
        {
            node.ConditionExpression.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this WhileStatement node, AstVisitorBase visitor)
        {
            node.ConditionExpression.Accept(visitor);
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this WithStatement node, AstVisitorBase visitor)
        {
            node.Expression.Accept(visitor);
            node.ChildStatement.Accept(visitor);
            visitor.Visit(node);
        }

        public static void Accept(this WithTargetExpression node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this XmlNamespaceExpression node, AstVisitorBase visitor)
        {
            visitor.Visit(node);
        }

        public static void Accept(this YieldStatement node, AstVisitorBase visitor)
        {
            if (node.Expression != null)
                node.Expression.Accept(visitor);
            visitor.Visit(node);
        }
    }
}

Information The latest build of this product (2014.1 build 0601) was released 30 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.