Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
		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));
				}
			}
		}
Esempio n. 3
0
		public ConvertVisitor(ConverterSettings settings)
		{
			this.settings = settings;
			this.fileName      = settings.FileName;
			this.errors        = settings.Errors;
			this.warnings      = settings.Warnings;
			this.nameComparer  = settings.NameComparer;
		}
 public void TestSuppressWarning()
 {
     CompilerWarningCollection warnings = new CompilerWarningCollection();
     warnings.Adding +=
         delegate(object sender, CompilerWarningEventArgs args) { if (args.Warning.Code == "foo") args.Cancel(); };
     warnings.Add(new CompilerWarning(LexicalInfo.Empty, "foo", "foo"));
     Assert.AreEqual(0, warnings.Count);
     warnings.Add(new CompilerWarning(LexicalInfo.Empty, "bar", "bar"));
     Assert.AreEqual(1, warnings.Count);
 }
		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;
		}
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
        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();
            _warnings.Adding += OnCompilerWarning;

            _references = options.References;
            _parameters = options;

            if (_parameters.Debug && !_parameters.Defines.ContainsKey("DEBUG"))
            {
                _parameters.Defines.Add("DEBUG", null);
            }

            _properties = new Hash();

            var activator = new InstantiatingEnvironment();

            _environment = _parameters.Environment != null
                                ? new CachingEnvironment(new EnvironmentChain(_parameters.Environment, activator))
                                : new CachingEnvironment(activator);
            _environment.InstanceCached += InitializeService;

            // FIXME: temporary hack to make sure the singleton is visible
            // using the My<IReflectionTypeSystemProvider> idiom
            RegisterService <IReflectionTypeSystemProvider>(_references.Provider);
            RegisterService <CompilerParameters>(_parameters);
            RegisterService <CompilerErrorCollection>(_errors);
            RegisterService <CompilerWarningCollection>(_warnings);
            RegisterService <CompileUnit>(_unit);
            RegisterService <CompilerContext>(this);
        }
Esempio n. 8
0
        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;
            _nameResolutionService = new TypeSystem.NameResolutionService(this);
            _traceSwitch           = _parameters.TraceSwitch;
            _properties            = new Hash();
        }
Esempio n. 9
0
 public static ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings)
 {
     ConverterSettings settings = new ConverterSettings(fileName, errors, warnings);
     settings.SimplifyTypeNames = true;
     return settings;
 }
Esempio n. 10
0
        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();
        }
Esempio n. 11
0
		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;
		}
Esempio n. 12
0
		ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings)
		{
			ConverterSettings settings = new ConverterSettings(fileName, errors, warnings);
			settings.SimplifyTypeNames = simplifyTypeNames;
			settings.RemoveRedundantTypeReferences = removeRedundantTypeReferences;
			return settings;
		}
Esempio n. 13
0
		public ConverterSettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings)
			: this(fileName, GetComparer(fileName), errors, warnings)
		{
		}
Esempio n. 14
0
 /// <summary>
 /// Allow a derived class to get access to the warnings that occured during 
 /// compilation
 /// </summary>
 /// <param name="warnings">The warnings.</param>
 protected virtual void HandleWarnings(CompilerWarningCollection warnings)
 {
 }