public static string CreateBooCode(CompilerErrorCollection errors, CompilerWarningCollection warnings, Module module, IList<ICSharpCode.NRefactory.ISpecial> specials) { using (StringWriter w = new StringWriter()) { foreach (CompilerError error in errors) { w.WriteLine("ERROR: " + error.ToString()); } if (errors.Count > 0) w.WriteLine(); foreach (CompilerWarning warning in warnings) { w.WriteLine("# WARNING: " + warning.ToString()); } if (warnings.Count > 0) w.WriteLine(); BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w); printer.OnModule(module); printer.Finish(); return w.ToString(); } }
public override void Run() { IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; if (window != null && window.ActiveViewContent is IEditable) { CompilerErrorCollection errors = new CompilerErrorCollection(); CompilerWarningCollection warnings = new CompilerWarningCollection(); Module module; IList<ICSharpCode.NRefactory.ISpecial> specials; CompileUnit compileUnit = new CompileUnit(); using (TextReader r = ((IEditable)window.ActiveViewContent).CreateSnapshot().CreateReader()) { string fileName = window.ActiveViewContent.PrimaryFileName; module = Parser.ParseModule(compileUnit, r, ApplySettings(fileName, errors, warnings), out specials); } if (module == null) { StringBuilder errorBuilder = new StringBuilder(); foreach (CompilerError error in errors) { errorBuilder.AppendLine(error.ToString()); } if (warnings.Count > 0) { foreach (CompilerWarning warning in warnings) { errorBuilder.AppendLine(warning.ToString()); } } MessageService.ShowError(errorBuilder.ToString()); } else { FileService.NewFile("Generated.boo", CreateBooCode(errors, warnings, module, specials)); } } }
public ConvertVisitor(ConverterSettings settings) { this.settings = settings; this.fileName = settings.FileName; this.errors = settings.Errors; this.warnings = settings.Warnings; this.nameComparer = settings.NameComparer; }
public ConverterSettings(string fileName, StringComparer nameComparer, CompilerErrorCollection errors, CompilerWarningCollection warnings) { if (fileName == null) throw new ArgumentNullException("fileName"); if (nameComparer == null) throw new ArgumentNullException("nameComparer"); if (errors == null) throw new ArgumentNullException("errors"); if (warnings == null) throw new ArgumentNullException("warnings"); this.errors = errors; this.warnings = warnings; this.fileName = fileName; this.nameComparer = nameComparer; }
public bool GetNode(Expression expression, bool asAttribute, CompilerErrorCollection compileErrors) { _isAttribute = asAttribute; _compileErrors = compileErrors; Visit(expression); if (_node == null) { _compileErrors.Add(CompilerErrorFactory.CustomError(expression.LexicalInfo, "Unrecgonized configuration node syntax")); return false; } return true; }
public static bool ConvertToBoo(string fileName, string ProvidedSource, out string ConvertedSource, out string ErrorMessage) { ConvertedSource = ErrorMessage = ""; CompilerErrorCollection errors = new CompilerErrorCollection(); CompilerWarningCollection warnings = new CompilerWarningCollection(); Module module; IList<ICSharpCode.NRefactory.ISpecial> specials; CompileUnit compileUnit = new CompileUnit(); using (StringReader r = new StringReader(ProvidedSource)) { // modified: removed fileName guessing module = Parser.ParseModule(compileUnit, r, BooHelpers.ApplySettings(fileName, errors, warnings), out specials); } if (module == null) { StringBuilder errorBuilder = new StringBuilder(); foreach (CompilerError error in errors) { errorBuilder.AppendLine(error.ToString()); } if (warnings.Count > 0) { foreach (CompilerWarning warning in warnings) { errorBuilder.AppendLine(warning.ToString()); } } ErrorMessage = errorBuilder.ToString(); return false; } else { ConvertedSource = BooHelpers.CreateBooCode(errors, warnings, module, specials); } return true; }
public static void Print(TextWriter writer, CompilerErrorCollection errors) { Hashtable reported = new Hashtable(); StringBuilder buffer = new StringBuilder(); foreach (CompilerError error in errors) { buffer.Length = 0; buffer.Append(Path.GetFileName(error.LexicalInfo.FileName)); buffer.AppendFormat("({0},{1}): ", error.LexicalInfo.Line, error.LexicalInfo.Column); buffer.AppendFormat("{0}: ", error.Code); buffer.Append(error.Message); string message = buffer.ToString(); if (reported.ContainsKey(message)) continue; reported.Add(message, message); writer.WriteLine(message); } }
public static ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) { ConverterSettings settings = new ConverterSettings(fileName, errors, warnings); settings.SimplifyTypeNames = true; return settings; }
private Assembly CompileAssembly(Node node, string url, CompilerErrorCollection errors) { CompilerContext oldContext = Context; CompilerContext result = Compile(url); _context = oldContext; if (result.Errors.Count > 0) { errors.Add(new CompilerError(node.LexicalInfo, "Failed to add a file reference")); foreach (CompilerError err in result.Errors) { errors.Add(err); } return null; } return result.GeneratedAssembly; }
public bool BuildConfig(Block block, CompilerErrorCollection compileErrors) { return Build(block, false, compileErrors); }
public bool BuildAttributes(Block block, CompilerErrorCollection compileErrors) { return Build(block, true, compileErrors); }
private bool Build(Block block, bool attributesOnly, CompilerErrorCollection compileErrors) { _attributesOnly = attributesOnly; _compileErrors = compileErrors; _configuration = new HashLiteralExpression(); _childContext = new Dictionary<string, object>(); return BuildHashConfiguration(block); }
public CompilerContext(CompilerParameters options, CompileUnit unit) { if (null == options) throw new ArgumentNullException("options"); if (null == unit) throw new ArgumentNullException("unit"); _unit = unit; _errors = new CompilerErrorCollection(); _warnings = new CompilerWarningCollection(); _assemblyReferences = options.References; _parameters = options; if (_parameters.Debug && !_parameters.Defines.ContainsKey("DEBUG")) _parameters.Defines.Add("DEBUG", null); _nameResolutionService = new TypeSystem.NameResolutionService(this); _properties = new Hash(); }
internal ErrorTrap(ConverterSettings settings) { this.errors = settings.Errors; this.fileName = settings.FileName; }
public bool GetNode(Expression expression, CompilerErrorCollection compileErrors) { return GetNode(expression, false, compileErrors); }
bool ConvertFileInternal(string input, string output) { string directory = Path.GetDirectoryName(output); if (directory.Length > 0) { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } } bool isFailed = false; if (!overwriteFiles && File.Exists(output)) { FailFile(ref isFailed, input, "The output file '{0}' already exists.", output); return false; } try { CompilerErrorCollection errors = new CompilerErrorCollection(); CompilerWarningCollection warnings = new CompilerWarningCollection(); Module module; IList<ICSharpCode.NRefactory.Parser.ISpecial> specials; CompileUnit compileUnit = new CompileUnit(); using (StreamReader r = OpenFile(input)) { module = Parser.ParseModule(compileUnit, r, ApplySettings(input, errors, warnings), out specials); } foreach (CompilerError error in errors) { FailFile(ref isFailed, input, error.ToString()); } if (!isFailed && warnings.Count > 0) { Console.WriteLine(input + ":"); foreach (CompilerWarning warning in warnings) { Console.WriteLine(" " + warning.ToString()); } } using (StreamWriter w = new StreamWriter(output, false, Encoding.UTF8)) { foreach (CompilerError error in errors) { w.WriteLine("ERROR: " + error.ToString()); } if (errors.Count > 0) w.WriteLine(); foreach (CompilerWarning warning in warnings) { w.WriteLine("# WARNING: " + warning.ToString()); } if (warnings.Count > 0) w.WriteLine(); BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w); if (module != null) { printer.OnModule(module); } printer.Finish(); } } catch (Exception ex) { FailFile(ref isFailed, input, ex); } return !isFailed; }
ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) { ConverterSettings settings = new ConverterSettings(fileName, errors, warnings); settings.SimplifyTypeNames = simplifyTypeNames; settings.RemoveRedundantTypeReferences = removeRedundantTypeReferences; return settings; }
public ConverterSettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) : this(fileName, GetComparer(fileName), errors, warnings) { }
public CompilationErrorsException(CompilerErrorCollection errors) : base(errors.ToString(true)) { this._errors = errors; }
public BooErrorException(CompilerErrorCollection errors) : base(errors.ToString()){ Errors = errors; }