Exemplo n.º 1
0
        /// <summary>
        /// Renders a single SwitchStatement with the given indentation
        /// </summary>
        /// <returns>The VHDL lines in the statement.</returns>
        /// <param name="method">The method the statement belongs to.</param>
        /// <param name="s">The statement to render.</param>
        /// <param name="indentation">The indentation to use.</param>
        private IEnumerable <string> RenderStatement(AST.Method method, AST.SwitchStatement s, int indentation)
        {
            var indent = new string(' ', indentation);

            indentation += 4;

            var indent2 = new string(' ', indentation);

            indentation += 4;

            yield return($"{indent}switch({RenderExpression(s.SwitchExpression)}) {{");

            var hasOthers = false;

            foreach (var c in s.Cases)
            {
                if (c.Item1.Length == 1 && c.Item1.First() is EmptyExpression)
                {
                    hasOthers = true;
                    yield return($"{indent2}default:");
                }
                else
                {
                    foreach (var cs in c.Item1.Select(x => RenderExpression(x)))
                    {
                        yield return($"{indent2}case {cs}:");
                    }
                }

                foreach (var ss in c.Item2.SelectMany(x => RenderStatement(method, x, indentation)))
                {
                    yield return(ss);
                }

                yield return($"{indent2}break;");
            }

            if (!hasOthers)
            {
                yield return($"{indent2}default:");
            }

            yield return($"{indent}}}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders a single SwitchStatement with the given indentation
        /// </summary>
        /// <returns>The VHDL lines in the statement.</returns>
        /// <param name="method">The method the statement belongs to.</param>
        /// <param name="s">The statement to render.</param>
        /// <param name="indentation">The indentation to use.</param>
        private IEnumerable <string> RenderStatement(AST.Method method, AST.SwitchStatement s, int indentation)
        {
            var indent = new string(' ', indentation);

            indentation += 4;
            var indent2 = new string(' ', indentation);

            indentation += 4;

            yield return($"{indent}case {RenderExpression(s.SwitchExpression)} is");

            var others = new Statement[0];

            foreach (var c in s.Cases)
            {
                if (c.Item1.Length == 1 && c.Item1.First() is EmptyExpression)
                {
                    others = c.Item2;
                    continue;
                }
                else
                {
                    yield return(indent2 + "when " + string.Join(" | ", c.Item1.Select(x => RenderExpression(x))) + " =>");
                }

                foreach (var ss in c.Item2.SelectMany(x => RenderStatement(method, x, indentation)))
                {
                    yield return(ss);
                }
            }

            yield return($"{indent2}when others =>");

            foreach (var ss in others.SelectMany(x => RenderStatement(method, x, indentation)))
            {
                yield return(ss);
            }

            yield return($"{indent}end case;");
        }