public override AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst)
        {
            var condition = VisitSyntaxNode(switchStatementAst.Condition);

            var sections = new List <SwitchSection>();

            foreach (var clause in switchStatementAst.Clauses)
            {
                var cond = VisitSyntaxNode(clause.Item1);
                var body = VisitSyntaxNode(clause.Item2);

                var block = new Block(body, new Break());

                var section = new SwitchSection(new[] { cond }, new[] { block });

                sections.Add(section);
            }

            if (switchStatementAst.Default != null)
            {
                var body = VisitSyntaxNode(switchStatementAst.Default) as Block;

                var statements = body.Statements.ToList();
                statements.Add(new Break());

                var section = new SwitchSection(new[] { new IdentifierName("default") }, new[] { new Block(statements) });
                sections.Add(section);
            }


            _currentNode = new SwitchStatement(condition, sections);

            return(AstVisitAction.SkipChildren);
        }
Example #2
0
 // Return Else Clause as a StatementBlockAst
 public static StatementBlockAst GetDefault(this SwitchStatementAst _ast)
 {
     // throw new NotImplementedException("Not implemented at the moment");
     if (_ast.Default != null)
     {
         return(_ast.Default);
     }
     return(null);
 }
        public object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
        {
            var condition = VisitAst(switchStatementAst.Condition);
            var clauses   = switchStatementAst.Clauses.Select(c => Tuple.Create(c.Item1, c.Item2));
            var @default  = VisitAst(switchStatementAst.Default);

            return(new SwitchStatementAst(switchStatementAst.Extent, switchStatementAst.Label, condition, switchStatementAst.Flags,
                                          clauses, @default));
        }
 public virtual StatementAst VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     return(new SwitchStatementAst(
                switchStatementAst.Extent,
                switchStatementAst.Label,
                switchStatementAst.Condition?.Rewrite(this, SyntaxKind.Pipeline),
                switchStatementAst.Flags,
                switchStatementAst.Clauses?.RewriteAllTuples(this, SyntaxKind.Expression, SyntaxKind.StatementBlock),
                switchStatementAst.Default?.Rewrite(this, SyntaxKind.StatementBlock)));
 }
Example #5
0
 public virtual object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     VisitElement(switchStatementAst.Condition);
     foreach (var clause in switchStatementAst.Clauses)
     {
         VisitElement(clause.Item1);
         VisitElement(clause.Item2);
     }
     VisitElement(switchStatementAst.Default);
     return(switchStatementAst);
 }
        public object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
        {
            var newCondition = VisitElement(switchStatementAst.Condition);
            var newClauses   = (from clause in switchStatementAst.Clauses
                                let newClauseTest = VisitElement(clause.Item1)
                                                    let newStatementBlock = VisitElement(clause.Item2)
                                                                            select new Tuple <ExpressionAst, StatementBlockAst>(newClauseTest, newStatementBlock));
            var newDefault = VisitElement(switchStatementAst.Default);

            return(new SwitchStatementAst(switchStatementAst.Extent, switchStatementAst.Label,
                                          newCondition,
                                          switchStatementAst.Flags, newClauses, newDefault));
        }
Example #7
0
        // Return ElseIf Clauses as a list of StatementBlockAst
        public static IEnumerable <StatementBlockAst> GetCases(this SwitchStatementAst _ast)
        {
            if (_ast.Clauses.Count >= 1)
            {
                List <StatementBlockAst> Cases = new List <StatementBlockAst>();
                for (int i = 0; i < _ast.Clauses.Count; i++)
                {
                    Cases.Add(_ast.Clauses[i].Item2);
                }

                return(Cases);
            }
            return(null);
        }
 public static SwitchStatementAst Update(
     this SwitchStatementAst ast,
     string label = null,
     PipelineBaseAst condition = null,
     SwitchFlags?flags         = null,
     IEnumerable <Tuple <ExpressionAst, StatementBlockAst> > clauses = null,
     StatementBlockAst @default = null)
 {
     return(new SwitchStatementAst(
                ast.Extent,
                label ?? ast.Label,
                condition?.Clone() ?? ast.Condition?.Clone(),
                flags ?? ast.Flags,
                clauses?.CloneAll() ?? ast.Clauses?.CloneAll(),
                @default?.Clone() ?? ast.Default?.Clone()));
 }
Example #9
0
            public override object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
            {
                if (switchStatementAst.Label != null)
                {
                    script_.Write(":" + switchStatementAst.Label + " ");
                }

                script_.Write("switch");
                if (switchStatementAst.Flags != SwitchFlags.None)
                {
                    script_.Write(" -" + switchStatementAst.Flags.ToString().ToLower() + " ");
                }

                script_.Write("(");
                VisitElement(switchStatementAst.Condition);
                script_.Write("){");

                foreach (var clause in switchStatementAst.Clauses)
                {
                    VisitElement(clause.Item1);
                    script_.Write("{");
                    VisitElement(clause.Item2);
                    script_.Write("}");
                }

                if (switchStatementAst.Default != null)
                {
                    script_.Write("default{");
                    VisitElement(switchStatementAst.Default);
                    script_.Write("}");
                }
                else
                {
                    VisitElement(switchStatementAst.Default);
                }

                script_.Write("}");
                return(switchStatementAst);
            }
Example #10
0
 public override AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     Console.WriteLine("Visited an SwitchStatementAst.");
     Console.WriteLine("    " + switchStatementAst.ToString().Replace(Environment.NewLine, Environment.NewLine + "    "));
     return(AstVisitAction.Continue);
 }
Example #11
0
 public object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     Console.WriteLine("Visited an SwitchStatementAst.");
     return(switchStatementAst);
 }
 public virtual TResult VisitSwitchStatement(SwitchStatementAst switchStatementAst) => default(TResult);
 public object VisitSwitchStatement(SwitchStatementAst switchStatementAst) => null;
Example #14
0
 /// <summary/>
 public virtual AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst) => DefaultVisit(switchStatementAst);
 public override AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     return(Visit(switchStatementAst));
 }
Example #16
0
 public override AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     throw new NotImplementedException(); //VisitSwitchStatement(switchStatementAst);
 }
Example #17
0
 public override AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     return(AstVisitAction.SkipChildren);
 }
 object ICustomAstVisitor.VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 => ProcessRewriter(VisitSwitchStatement, switchStatementAst);
Example #19
0
 public override AstVisitAction VisitSwitchStatement(SwitchStatementAst ast)
 {
     return(AstVisitAction.Continue);
 }
Example #20
0
 public object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     throw new NotImplementedException();
 }
Example #21
0
 public object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     throw new UnexpectedElementException();
 }
 object ICustomAstVisitor.VisitSwitchStatement(SwitchStatementAst switchStatementAst) => VisitSwitchStatement(switchStatementAst);
 public object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
Example #24
0
 public object VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     return(false);
 }
Example #25
0
 public override AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 {
     // TODO: add switch statement explanation
     AstExplainer(switchStatementAst);
     return(base.VisitSwitchStatement(switchStatementAst));
 }
Example #26
0
 // SwitchStatementAst Extension Methods
 // New Methods Available:
 // - CreateNodeFromAST(NodeDepth, NodePosition, Parent) => Creates a Node
 // - GetChildAst() => retourne only ASTs we are looking for ...
 public static SwitchNode CreateNodeFromAst(this SwitchStatementAst _ast, int _depth, int _position, Node _parent, Tree _tree)
 {
     return(new SwitchNode(_ast, _depth, _position, _parent, _tree));
 }
Example #27
0
 public override AstVisitAction VisitSwitchStatement(SwitchStatementAst ast)
 {
     return(DoNextAction(ast));
 }
Example #28
0
 public override StatementAst VisitSwitchStatement(SwitchStatementAst switchStatementAst)
 => VisitStatement(base.VisitSwitchStatement(switchStatementAst));
Example #29
0
 public override AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst) => VisitAst(switchStatementAst);