Exemplo n.º 1
0
        protected virtual IEnumerable <string> GetFunctionDeclarationLines(FunctionDeclaration fun)
        {
            var assignedTo = new HashSet <Variable>(
                fun.Statements.OfType <Assignment>().Select(a => a.Variable));

            var isMain = fun is MainFunctionDeclaration;

            yield return(isMain
                ? $"{Main} {FunctionWrapStart}"
                : $"{FunctionPrefix} {fun.FunctionName}({P}{VariableTypeIndicator}{IntType}){FunctionTypeIndicator}{IntType} {FunctionWrapStart}");

            foreach (var statement in fun.Statements)
            {
                if (isMain && statement is Return)
                {
                    continue;
                }

                yield return($"{IndentSpaces}{GetStatement(statement, assignedTo)}");
            }
            if (!string.IsNullOrEmpty(FunctionWrapEnd))
            {
                yield return(FunctionWrapEnd);
            }
        }
Exemplo n.º 2
0
        protected virtual IEnumerable <string> GetFunctionDeclarationLines(FunctionDeclaration fun)
        {
            var assignedTo = new HashSet <Variable>(
                fun.Statements.OfType <Assignment>().Select(a => a.Variable));

            yield return((fun is MainFunctionDeclaration)
                ? $"{FunctionPrefix}{IntType} {Main} {{"
                : $"{FunctionPrefix}{IntType} {fun.FunctionName}({ConstIntType} {P}) {{");

            foreach (var statement in fun.Statements)
            {
                yield return($"    {GetStatement(statement, assignedTo)}");
            }

            yield return("}");
        }
Exemplo n.º 3
0
        protected override IEnumerable <string> GetFunctionDeclarationLines(FunctionDeclaration fun)
        {
            var assignedTo = new HashSet <Variable>(
                fun.Statements.OfType <Assignment>().Select(a => a.Variable));

            var isMain = fun is MainFunctionDeclaration;

            yield return(isMain
                ? $"{Main} {FunctionWrapStart}"
                : $"{fun.FunctionName} :: {IntType} -> {IntType}\n{fun.FunctionName} {P} {FunctionWrapStart}");

            foreach (var statement in fun.Statements)
            {
                if (isMain && statement is Return)
                {
                    continue;
                }

                yield return($"{IndentSpaces}{GetStatement(statement, assignedTo)}");
            }
        }