public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings, out IList<ISpecial> specials) { if (cu == null) throw new ArgumentNullException("cu"); if (input == null) throw new ArgumentNullException("input"); if (settings == null) throw new ArgumentNullException("settings"); IParser parser = ParserFactory.CreateParser(settings.IsVisualBasic ? SupportedLanguage.VBNet : SupportedLanguage.CSharp, input); ErrorTrap errorTrap = new ErrorTrap(settings); parser.Errors.SemErr = errorTrap.DefaultCodeError; parser.Errors.SynErr = errorTrap.DefaultCodeError; parser.Errors.Error = errorTrap.DefaultMsgError; parser.Parse(); specials = parser.Lexer.SpecialTracker.CurrentSpecials; if (settings.IsVisualBasic) { PreprocessingDirective.VBToCSharp(specials); } // abort when file has errors if (errorTrap.count > 0) return null; Module m = Converter.Convert(parser.CompilationUnit, settings); if (m != null && cu != null) { cu.Modules.Add(m); if (settings.RemoveRedundantTypeReferences) { cu.Accept(new RemoveRedundantTypeReferencesVisitor()); } } return m; }
public ConvertVisitor(ConverterSettings settings) { this.settings = settings; this.fileName = settings.FileName; this.errors = settings.Errors; this.warnings = settings.Warnings; this.nameComparer = settings.NameComparer; }
public static Expression Convert(NR.Expression expression, ConverterSettings settings) { if (expression == null) throw new ArgumentNullException("expression"); if (settings == null) throw new ArgumentNullException("settings"); return (Expression)expression.AcceptVisitor(new ConvertVisitor(settings), null); }
public static Expression Convert(NR.Expression expression, ConverterSettings settings) { if (expression == null) { throw new ArgumentNullException("expression"); } if (settings == null) { throw new ArgumentNullException("settings"); } return((Expression)expression.AcceptVisitor(new ConvertVisitor(settings), null)); }
public static Module Convert(NR.CompilationUnit cu, ConverterSettings settings) { if (cu == null) throw new ArgumentNullException("cu"); if (settings == null) throw new ArgumentNullException("settings"); if (settings.IsVisualBasic) cu.AcceptVisitor(new VBNetConstructsConvertVisitor { AddDefaultValueInitializerToLocalVariableDeclarations = false }, null); else cu.AcceptVisitor(new CSharpConstructsConvertVisitor(), null); return (Module)cu.AcceptVisitor(new ConvertVisitor(settings), null); }
public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings, out IList <ISpecial> specials) { if (cu == null) { throw new ArgumentNullException("cu"); } if (input == null) { throw new ArgumentNullException("input"); } if (settings == null) { throw new ArgumentNullException("settings"); } IParser parser = ParserFactory.CreateParser(settings.IsVisualBasic ? SupportedLanguage.VBNet : SupportedLanguage.CSharp, input); ErrorTrap errorTrap = new ErrorTrap(settings); parser.Errors.SemErr = errorTrap.DefaultCodeError; parser.Errors.SynErr = errorTrap.DefaultCodeError; parser.Errors.Error = errorTrap.DefaultMsgError; parser.Parse(); specials = parser.Lexer.SpecialTracker.CurrentSpecials; if (settings.IsVisualBasic) { PreprocessingDirective.VBToCSharp(specials); } // abort when file has errors if (errorTrap.count > 0) { return(null); } Module m = Converter.Convert(parser.CompilationUnit, settings); if (m != null && cu != null) { cu.Modules.Add(m); if (settings.RemoveRedundantTypeReferences) { cu.Accept(new RemoveRedundantTypeReferencesVisitor()); } } return(m); }
public override string GenerateCode(AbstractNode node, string indentation) { StringBuilder errorBuilder = new StringBuilder(); ConverterSettings settings = new ConverterSettings("codegeneration.cs"); string output = null; Node booNode = (Node)node.AcceptVisitor(new ConvertVisitor(settings), null); if (settings.Errors.Count > 0) { foreach (CompilerError error in settings.Errors) { errorBuilder.AppendLine(error.ToString()); } } else { if (settings.Warnings.Count > 0) { foreach (CompilerWarning warning in settings.Warnings) { errorBuilder.AppendLine(warning.ToString()); } } booNode.Accept(new RemoveRedundantTypeReferencesVisitor()); using (StringWriter w = new StringWriter()) { BooPrinterVisitor printer = new BooPrinterVisitor(w); int indentCount = 0; foreach (char c in indentation) { if (c == '\t') indentCount += 4; else indentCount += 1; } indentCount /= 4; while (indentCount-- > 0) printer.Indent(); booNode.Accept(printer); output = w.ToString(); } } if (errorBuilder.Length > 0) { MessageService.ShowMessage(errorBuilder.ToString()); } return output; }
public static Module Convert(NR.CompilationUnit cu, ConverterSettings settings) { if (cu == null) { throw new ArgumentNullException("cu"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (settings.IsVisualBasic) { cu.AcceptVisitor(new VBNetConstructsConvertVisitor { AddDefaultValueInitializerToLocalVariableDeclarations = false }, null); } else { cu.AcceptVisitor(new CSharpConstructsConvertVisitor(), null); } return((Module)cu.AcceptVisitor(new ConvertVisitor(settings), null)); }
internal ErrorTrap(ConverterSettings settings) { this.errors = settings.Errors; this.fileName = settings.FileName; }
public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings) { IList <ISpecial> specials; return(ParseModule(cu, input, settings, out specials)); }
public static ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) { ConverterSettings settings = new ConverterSettings(fileName, errors, warnings); settings.SimplifyTypeNames = true; return settings; }
ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) { ConverterSettings settings = new ConverterSettings(fileName, errors, warnings); settings.SimplifyTypeNames = simplifyTypeNames; settings.RemoveRedundantTypeReferences = removeRedundantTypeReferences; return settings; }
public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings) { IList<ISpecial> specials; return ParseModule(cu, input, settings, out specials); }