Exemple #1
0
		public void CompileUnitIsProvidedToTheEnvironment()
		{
			var compileUnit = new CompileUnit();
			ActiveEnvironment.With(
				new CompilerContext(compileUnit).Environment,
				() => Assert.AreSame(compileUnit, My<CompileUnit>.Instance));
		}
Exemple #2
0
		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;
		}
Exemple #3
0
		public static CompilerContext compile_(CompileUnit unit, Assembly[] references)
		{
			BooCompiler compiler = NewCompiler();
			foreach (Assembly reference in references)
				compiler.Parameters.References.Add(reference);
			return compiler.Run(unit);
		}
		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 override Assembly Compile(ViewCompilerInfo info) {
			lock(this) {
				var log = myapp.QorpentApplication.LogManager.GetLog(this.GetType().FullName + ";MvcHandler", this);
				try {
					if (AllInMemory) info.InMemory = true;
					initCompiler(info);
					setupPipeline(compiler, info);
					setupParameters(compiler, info);
					setupSources(compiler, info);
					var cunit = new CompileUnit();
					cunit["sources"] = info.Sources;
					var result = compiler.Run(cunit);
					this.LastResult = result;
					if (result.Errors.Count != 0 && !info.ProcessingTest) {
						throw new Exception(result.Errors.ToString(true));
					}
					if (!info.ProcessingTest) {
						return result.GeneratedAssembly;
					}
					return null;
				}catch(Exception ex) {
					log.Error("",new BrailCompilerException(info,ex),this);
					throw;
				}
			}

        }
		protected override void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem)
		{
			FixExtensionOfExtraProperties(targetItem, ".cs", ".boo");
			FixExtensionOfExtraProperties(targetItem, ".vb", ".boo");
			
			string ext = Path.GetExtension(sourceItem.FileName);
			if (".cs".Equals(ext, StringComparison.OrdinalIgnoreCase) || ".vb".Equals(ext, StringComparison.OrdinalIgnoreCase)) {
				Module module;
				IList<ICSharpCode.NRefactory.ISpecial> specials;
				CompileUnit compileUnit = new CompileUnit();
				using (StringReader r = new StringReader(ParserService.GetParseableFileContent(sourceItem.FileName))) {
					module = Parser.ParseModule(compileUnit, r, ConvertBuffer.ApplySettings(sourceItem.VirtualName, errors, warnings), out specials);
				}
				if (module == null) {
					conversionLog.AppendLine("Could not parse '" + sourceItem.FileName + "', see error list for details.");
					base.ConvertFile(sourceItem, targetItem);
				} else {
					using (StringWriter w = new StringWriter()) {
						BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w);
						printer.OnModule(module);
						printer.Finish();
						
						targetItem.Include = Path.ChangeExtension(targetItem.Include, ".boo");
						File.WriteAllText(targetItem.FileName, w.ToString());
					}
				}
			} else {
				base.ConvertFile(sourceItem, targetItem);
			}
		}
Exemple #7
0
 private static BooCompiler CompilerFor(CompileUnit unit, Assembly[] references)
 {
     BooCompiler compiler = new BooCompiler();
     compiler.Parameters.OutputType = IsApplication(unit) ? CompilerOutputType.ConsoleApplication : CompilerOutputType.Library;
     compiler.Parameters.Pipeline = new Boo.Lang.Compiler.Pipelines.CompileToMemory();
     compiler.Parameters.References.Extend(references);
     return compiler;
 }
Exemple #8
0
		private void RunCompilerStepAfterExpressionResolutionOn(CompileUnit compileUnit, ICompilerStep step)
		{
			var pipeline = new Boo.Lang.Compiler.Pipelines.ResolveExpressions { step };

			var compiler = new Boo.Lang.Compiler.BooCompiler(new CompilerParameters { Pipeline = pipeline });
			var result = compiler.Run(compileUnit);

			if (result.Errors.Count > 0)
				Assert.Fail(result.Errors.ToString(true));
		}
Exemple #9
0
		public CompilerContext Run(CompileUnit compileUnit)
		{
			if (null == compileUnit)
				throw new ArgumentNullException("compileUnit");
			if (null == _parameters.Pipeline)
				throw new InvalidOperationException(Boo.Lang.Resources.StringResources.BooC_CantRunWithoutPipeline);
			
			var context = new CompilerContext(_parameters, compileUnit);
			_parameters.Pipeline.Run(context);
			return context;
		}
Exemple #10
0
		public static Module ParseModule(int tabSize, CompileUnit cu, string readerName, TextReader reader, ParserErrorHandler errorHandler)
		{
			if (Readers.IsEmpty(reader))
			{
				Module emptyModule = new Module(new LexicalInfo(readerName), ModuleNameFrom(readerName));
				cu.Modules.Add(emptyModule);
				return emptyModule;
			}

			Module module = CreateParser(tabSize, readerName, reader, errorHandler).start(cu);
			module.Name = ModuleNameFrom(readerName);
			return module;
		}
Exemple #11
0
 public CompilerContext Run(CompileUnit compileUnit)
 {
     if (null == compileUnit)
     {
         throw new ArgumentNullException("compileUnit");
     }
     if (null == _parameters.Pipeline)
     {
         throw new InvalidOperationException(Boo.Lang.ResourceManager.GetString("BooC.CantRunWithoutPipeline"));
     }
     CompilerContext context = new CompilerContext(_parameters, compileUnit);
     _parameters.Pipeline.Run(context);
     return context;
 }
Exemple #12
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();
        }
        public void TransformerIsAppliedToCompileUnit()
        {
            StubTransformer transformer = new StubTransformer();

            TransformerCompilerStep transformerStep = new TransformerCompilerStep(transformer);

            CompileUnit unit = new CompileUnit();

            BooCompiler compiler = new BooCompiler();
            compiler.Parameters.Pipeline = new CompilerPipeline();
            compiler.Parameters.Pipeline.Insert(0, transformerStep);
            compiler.Run(unit);

            Assert.IsTrue(transformer.CompileUnitVisited);
        }
Exemple #14
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;
        }
Exemple #15
0
        override public object Clone()
        {
            CompileUnit clone = new CompileUnit();

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._isSynthetic       = _isSynthetic;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }
            if (null != _modules)
            {
                clone._modules = _modules.Clone() as ModuleCollection;
                clone._modules.InitializeParent(clone);
            }
            return(clone);
        }
Exemple #16
0
        override public object Clone()
        {
            CompileUnit clone = (CompileUnit)FormatterServices.GetUninitializedObject(typeof(CompileUnit));

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }

            if (null != _modules)
            {
                clone._modules = _modules.Clone() as ModuleCollection;
                clone._modules.InitializeParent(clone);
            }
            return(clone);
        }
Exemple #17
0
		public static Assembly compile(CompileUnit unit, params Assembly[] references)
		{
			CompilerContext result = compile_(unit, references);
			AssertNoErrors(result);
			return result.GeneratedAssembly;
		}
Exemple #18
0
	protected Module  start(
		CompileUnit cu
	) //throws RecognitionException, TokenStreamException
{
		Module module;
		
		IToken  eof = null;
		
			module = new Module();		
			module.LexicalInfo = new LexicalInfo(getFilename(), 1, 1);
			
			cu.Modules.Add(module);
		
		
		try {      // for error handling
			parse_module(module);
			eof = LT(1);
			match(Token.EOF_TYPE);
			if (0==inputState.guessing)
			{
				SetEndSourceLocation(module, eof);
			}
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "start");
				recover(ex,tokenSet_0_);
			}
			else
			{
				throw ex;
			}
		}
		return module;
	}
Exemple #19
0
		public CompileUnitNamespace(CompileUnit unit)
		{
			_nameResolutionService = My<NameResolutionService>.Instance;
			_internalTypeSystemProvider = My<InternalTypeSystemProvider>.Instance;
			_compileUnit = unit;
		}
Exemple #20
0
 private static bool IsApplication(CompileUnit unit)
 {
     foreach (Module m in unit.Modules)
     {
         if (m.Globals.HasStatements) return true;
     }
     return false;
 }
Exemple #21
0
        //throws RecognitionException, TokenStreamException
        protected Module start(
            CompileUnit cu
            )
        {
            Module module;

            module = new Module();
            module.LexicalInfo = new LexicalInfo(getFilename(), 1, 1);

            cu.Modules.Add(module);

            try {      // for error handling
            parse_module(module);
            {
                if ((LA(1)==EOF) && (LA(2)==EOF))
                {
                    match(Token.EOF_TYPE);
                }
                else if ((LA(1)==EOF) && (LA(2)==EOF)) {
                }
                else
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }

            }
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex);
                recover(ex,tokenSet_0_);
            }
            else
            {
                throw ex;
            }
            }
            return module;
        }
Exemple #22
0
		override public object Clone()
		{
		
			CompileUnit clone = new CompileUnit();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			if (null != _modules)
			{
				clone._modules = _modules.Clone() as ModuleCollection;
				clone._modules.InitializeParent(clone);
			}
			return clone;


		}
Exemple #23
0
        public static Module ParseModule(int tabSize, CompileUnit cu, string readerName, TextReader reader, Boo.Lang.Parser.ParserErrorHandler errorHandler)
        {
            WSABooParser parser = CreateParser(tabSize, readerName, reader, errorHandler);

            Module module = parser.start(cu);
            module.Name = Boo.Lang.Parser.BooParser.CreateModuleName(readerName);
            return module;
        }
Exemple #24
0
		public static CompileUnit ParseReader(int tabSize, string readerName, TextReader reader)
		{		
			var cu = new CompileUnit();
			ParseModule(tabSize, cu, readerName, reader, null);
			return cu;
		}
Exemple #25
0
 public static void AssertEquals(string message, CompileUnit expected, CompileUnit actual)
 {
     AssertEqualsByLine(message, ToXmlString(expected), ToXmlString(actual));
 }
		static CompileUnit SyntaxTreeFor(IFile file)
		{
			var compileUnit = new CompileUnit();
			UnityScriptParser.ParseReader(file.OpenText(), "", new CompilerContext(), compileUnit);
			return compileUnit;
		}
Exemple #27
0
 public CompilerContext(CompileUnit unit)
     : this(new CompilerParameters(), unit)
 {
 }
 public void Initialize(CompilerContext context){
     this.root = context.CompileUnit;
 }
Exemple #29
0
		public static CompilerContext compile_(CompileUnit unit, params ICompileUnit[] references)
		{
			return NewCompilerWithReferences(references).Run(unit);
		}
 public static bool IsTainted(CompileUnit cu)
 {
     return cu.ContainsAnnotation(TaintedAnnotation);
 }
 public override void OnCompileUnit(CompileUnit node)
 {
     compileUnitVisited = true;
     base.OnCompileUnit(node);
 }
 public static void Taint(CompileUnit cu)
 {
     cu.set_Item(TaintedAnnotation, TaintedAnnotation);
 }