Пример #1
0
    public StatementAst _VisitStatement(StatementAst statementAst)
    {
        //Console.WriteLine("Visiting statement type {0}", statementAst.GetType().FullName);
        var @switch = new Dictionary <Type, Func <StatementAst, StatementAst> > {
            { typeof(BlockStatementAst), (s) => { return((StatementAst)VisitBlockStatement(s as BlockStatementAst)); } },
            { typeof(BreakStatementAst), (s) => { return((StatementAst)VisitBreakStatement(s as BreakStatementAst)); } },
            { typeof(CommandAst), (s) => { return((StatementAst)VisitCommand(s as CommandAst)); } },
            { typeof(CommandExpressionAst), (s) => { return((StatementAst)VisitCommandExpression(s as CommandExpressionAst)); } },
            { typeof(ContinueStatementAst), (s) => { return((StatementAst)VisitContinueStatement(s as ContinueStatementAst)); } },
            { typeof(DataStatementAst), (s) => { return((StatementAst)VisitDataStatement(s as DataStatementAst)); } },
            { typeof(ExitStatementAst), (s) => { return((StatementAst)VisitExitStatement(s as ExitStatementAst)); } },
            { typeof(FunctionDefinitionAst), (s) => { return((StatementAst)VisitFunctionDefinition(s as FunctionDefinitionAst)); } },
            { typeof(IfStatementAst), (s) => { return((StatementAst)VisitIfStatement(s as IfStatementAst)); } },
            //LabeledStatementAst
            //LoopStatementAst
            { typeof(DoUntilStatementAst), (s) => { return((StatementAst)VisitDoUntilStatement(s as DoUntilStatementAst)); } },
            { typeof(DoWhileStatementAst), (s) => { return((StatementAst)VisitDoWhileStatement(s as DoWhileStatementAst)); } },
            { typeof(ForEachStatementAst), (s) => { return((StatementAst)VisitForEachStatement(s as ForEachStatementAst)); } },
            { typeof(ForStatementAst), (s) => { return((StatementAst)VisitForStatement(s as ForStatementAst)); } },
            { typeof(WhileStatementAst), (s) => { return((StatementAst)VisitWhileStatement(s as WhileStatementAst)); } },
            { typeof(SwitchStatementAst), (s) => { return((StatementAst)VisitSwitchStatement(s as SwitchStatementAst)); } },
            //PipelineBaseAst
            { typeof(AssignmentStatementAst), (s) => { return((StatementAst)VisitAssignmentStatement(s as AssignmentStatementAst)); } },
            { typeof(ErrorStatementAst), (s) => { return((StatementAst)VisitErrorStatement(s as ErrorStatementAst)); } },
            { typeof(PipelineAst), (s) => { return((StatementAst)VisitPipeline(s as PipelineAst)); } },
            { typeof(ReturnStatementAst), (s) => { return((StatementAst)VisitReturnStatement(s as ReturnStatementAst)); } },
            { typeof(ThrowStatementAst), (s) => { return((StatementAst)VisitThrowStatement(s as ThrowStatementAst)); } },
            { typeof(TrapStatementAst), (s) => { return((StatementAst)VisitTrap(s as TrapStatementAst)); } },
            { typeof(TryStatementAst), (s) => { return((StatementAst)VisitTryStatement(s as TryStatementAst)); } }
        };

        return(@switch[statementAst.GetType()](statementAst));
    }
        /*
         * stmt ->
         *    expr_stmt
         | decl_stmt
         | if_stmt
         | while_stmt
         | return_stmt
         | block_stmt
         | empty_stmt
         |
         | break_stmt | continue_stmt
         */
        public virtual bool ProcessStatement(StatementAst statement)
        {
            Guard.Against.Null(statement, nameof(statement));

            if (statement is BreakStatementAst breakStatement)
            {
                ProcessBreakStatement(breakStatement);
            }
            else if (statement is ContinueStatementAst continueStatement)
            {
                ProcessContinueStatement(continueStatement);
            }
            else if (statement is ExpressionStatementAst expressionStatement)
            {
                ProcessExpressionStatement(expressionStatement);
            }
            else if (statement is DeclarationStatementAst declarationStatement)
            {
                ProcessDeclarationStatement(declarationStatement);
            }
            else if (statement is IfStatementAst ifStatement)
            {
                return(ProcessIfStatement(ifStatement));
            }
            else if (statement is WhileStatementAst whileStatement)
            {
                ProcessWhileStatement(whileStatement);
            }
            else if (statement is ReturnStatementAst returnStatement)
            {
                ProcessReturnStatement(returnStatement);
                return(true);
            }
            else if (statement is BlockStatementAst blockStatement)
            {
                return(ProcessBlockStatement(blockStatement));
            }
            else if (statement is EmptyStatementAst emptyStatement)
            {
                ProcessEmptyStatement(emptyStatement);
            }
            else
            {
                throw new ArgumentException($"Unknown statement type: {statement.GetType()}",
                                            nameof(statement));
            }

            return(false);
        }
Пример #3
0
 private CommandExpressionAst CreateLoggingExpression(StatementAst source)
 {
     return(CommandExpression(CreateLoggingExpressionImpl(CreateEvaluation(source), source.Extent, source.GetType())));
 }