Beispiel #1
0
        public ScopeAnalyzer(ScopeManager scopeManager)
        {
            _scopeManager = scopeManager;
            SyntaxTreeDelegator visitor = new SyntaxTreeDelegator();

            visitor.StatementVisitor  = this;
            visitor.ExpressionVisitor = new GenericExpressionDelegator(this);

            SyntaxTreeDelegator childrenVisitor = new SyntaxTreeDelegator();

            _expressionChildrenVisitor = new ExpressionChildrenVisitor(visitor, null, childrenVisitor);
            _expressionChildrenVisitor.ExtensionChildrenVisitor = new ParseTreeVisitorExtension(
                new ParseTreeChildrenVisitor(visitor, null, childrenVisitor));
            childrenVisitor.ExpressionVisitor = _expressionChildrenVisitor;

            _currentScope = _scopeManager.OuterScope;
        }
        public void Process(FunctionDefinitionNode function)
        {
            SyntaxTreeDelegator syntaxTreeDelegator = new SyntaxTreeDelegator();
            ExpressionDelegator expressionDelegator = new ExpressionDelegator();

            expressionDelegator.UnaryOperationVisitor = this;
            syntaxTreeDelegator.ExpressionVisitor     = expressionDelegator;

            SyntaxTreeDelegator      childrenVisitor          = new SyntaxTreeDelegator();
            StatementChildrenVisitor statementChildrenVisitor =
                new StatementChildrenVisitor(syntaxTreeDelegator, childrenVisitor);
            ExpressionChildrenVisitor expressionChildrenVisitor
                = new ExpressionChildrenVisitor(syntaxTreeDelegator, null, childrenVisitor);

            childrenVisitor.StatementVisitor  = statementChildrenVisitor;
            childrenVisitor.ExpressionVisitor = expressionChildrenVisitor;

            function.Body.VisitStatements(statementChildrenVisitor);
        }
        public ProcessReplacementsVisitorChain(IReplacementSource source, IReplacementListener listener, bool isPostOrder = false)
        {
            ExpressionReplacementsVisitor        = new ProcessExpressionReplacementsVisitor(source, listener);
            StatementReplacementsVisitor         = new ProcessStatementReplacementsVisitor(source, listener);
            TopLevelStatementReplacementsVisitor = new ProcessTopLevelStatementReplacementsVisitor(source, listener);

            ReplacementVisitor = new SyntaxTreeDelegator();
            ReplacementVisitor.ExpressionVisitor = ExpressionReplacementsVisitor;
            ReplacementVisitor.StatementVisitor  = StatementReplacementsVisitor;
            ReplacementVisitor.TopLevelVisitor   = TopLevelStatementReplacementsVisitor;

            ChildrenVisitor           = new SyntaxTreeDelegator();
            ExpressionChildrenVisitor = new ExpressionChildrenVisitor(
                preOrderVisitor: isPostOrder ? null : ReplacementVisitor,
                postOrderVisitor: isPostOrder ? ReplacementVisitor : null,
                childrenVisitor: ChildrenVisitor);
            StatementChildrenVisitor         = new StatementChildrenVisitor(ReplacementVisitor, ChildrenVisitor);
            TopLevelStatementChildrenVisitor = new TopLevelStatementChildrenVisitor(ReplacementVisitor, ChildrenVisitor);

            ChildrenVisitor.ExpressionVisitor = ExpressionChildrenVisitor;
            ChildrenVisitor.StatementVisitor  = StatementChildrenVisitor;
            ChildrenVisitor.TopLevelVisitor   = TopLevelStatementChildrenVisitor;
        }