private static IEnumerable <UnifiedCase> CreateWhenAndDefault(
            XElement node)
        {
            Contract.Requires(node != null);
            if (node.Name() == "nil")
            {
                yield break;
            }

            if (node.Name() != "when")
            {
                yield return(UnifiedCase.CreateDefault(CreateSmartBlock(node)));
            }
            else
            {
                var first     = node.FirstElement();
                var caseConds = first.Elements()
                                .Select(CreateExpresion)
                                .ToList();
                int i;
                for (i = 0; i < caseConds.Count - 1; i++)
                {
                    yield return(UnifiedCase.Create(caseConds[i]));
                }
                yield return
                    (UnifiedCase.Create(
                         caseConds[i],
                         CreateSmartBlock(node.LastElement())));
            }
        }
예제 #2
0
        private static UnifiedCase CreateCaseOrDefault(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "labeled_statement");
            Contract.Requires(node.FirstElement().Name != "IDENTIFIER");

            /*
             * labeled_statement
             * : IDENTIFIER ':' statement
             | 'case' constant_expression ':' statement
             | 'default' ':' statement
             */

            switch (node.FirstElement().Value)
            {
            case "case":
                return
                    (UnifiedCase.Create(
                         CreateConstantExpression(node.NthElement(1)),
                         UnifiedBlock.Create(
                             CreateStatement(node.NthElement(3)))));

            case "default":
                return
                    (UnifiedCase.CreateDefault(
                         UnifiedBlock.Create(
                             CreateStatement(node.NthElement(2)))));

            default:
                throw new InvalidOperationException();
            }
        }
        private static IEnumerable <UnifiedExpression> CreateSwitchStatement(SwitchStatement statement)
        {
            var cases =
                statement.CodeList.Cast <SwitchCaseBase>().Select(
                    sc =>
                    UnifiedCase.Create(
                        CreatePhrase(sc.CaseLabel), CreateStatementCollection(sc.Statements)))
                .ToSet();

            cases.Add(UnifiedCase.CreateDefault(CreateStatementCollection(statement.ElseCase.Statements)));
            yield return(UnifiedSwitch.Create(CreatePhrase(statement.Expression), cases));
        }
예제 #4
0
 public UnifiedElement VisitGotoDefaultStatement(
     GotoDefaultStatement gotoDefaultStatement, object data)
 {
     return(UnifiedGoto.Create(UnifiedCase.CreateDefault()));
 }