public string Expand() { var statements = _statement.Statements.GetStatementsFromCollection(_statementFactory, _options); var initStatement = _statementFactory.GetStatement(_statement.InitStatement, _options).Expand(); var incrementStatement = _statementFactory.GetStatement(_statement.IncrementStatement, _options).Expand(); var testExpression = _expressionFactory.GetExpression(_statement.TestExpression, _options).Evaluate(); return($"for ({initStatement}; {testExpression}; {incrementStatement} {{{statements}{Environment.NewLine}}}"); }
public static string GetStatementsFromCollection(this CodeStatementCollection statementCollection, IStatementFactory statementFactory, CodeGeneratorOptions options) { if (statementCollection.Count <= 0) return string.Empty; return statementCollection .OfType<CodeStatement>() .Select(statement => { var statementLines = statementFactory.GetStatement(statement, options); return statementLines.Expand(); }) .Aggregate((previous, current) => $"{previous}{Environment.NewLine}{current}"); }
public string Expand(CodeNamespace codeNamespace, CodeGeneratorOptions options) { var name = codeNamespace.Name; var comments = codeNamespace.Comments .OfType <CodeCommentStatement>() .Select(statement => _statementFactory.GetStatement(statement, options).Expand()) .ToList(); var commentsExpression = string.Empty; if (comments.Any()) { commentsExpression = string.Join(Environment.NewLine, comments); } var imports = codeNamespace.Imports .OfType <CodeNamespaceImport>() .Select(import => $"import {import.Namespace};") .ToList(); var importsExpression = string.Empty; if (imports.Any()) { importsExpression = $"{string.Join(Environment.NewLine, imports)}"; } var types = codeNamespace.Types .OfType <CodeTypeDeclaration>() .Select(declaration => { declaration.UserData["AddExportKeyword"] = !string.IsNullOrWhiteSpace(codeNamespace.Name); return($"{Environment.NewLine}{_memberFactory.GetMember(declaration, options).Expand()}"); }) .ToList(); var typesExpression = string.Empty; if (types.Any()) { typesExpression = $"{string.Join(Environment.NewLine, types)}"; } if (string.IsNullOrWhiteSpace(name)) { return($"{importsExpression}{commentsExpression}{Environment.NewLine}{typesExpression}{Environment.NewLine}"); } return($"{importsExpression}{commentsExpression}{Environment.NewLine}module {name}{{{typesExpression}{Environment.NewLine}}}"); }
public static string GetStatementsFromCollection(this CodeStatementCollection statementCollection, IStatementFactory statementFactory, CodeGeneratorOptions options) { if (statementCollection.Count <= 0) { return(string.Empty); } return(statementCollection .OfType <CodeStatement>() .Select(statement => { var statementLines = statementFactory.GetStatement(statement, options); return statementLines.Expand(); }) .Aggregate((previous, current) => $"{previous}{Environment.NewLine}{current}")); }
public void GenerateCodeFromStatement(CodeStatement codeStatement, TextWriter textWriter, CodeGeneratorOptions options) { var statement = _statementFactory.GetStatement(codeStatement, options); textWriter.Write(statement.Expand()); }
public string Expand() { var statement = _statementFactory.GetStatement(_statement.Statement, _options).Expand(); return($"{_statement.Label}:{Environment.NewLine}{statement};"); }