Пример #1
0
		public void CompileUnitIsProvidedToTheEnvironment()
		{
			var compileUnit = new CompileUnit();
			ActiveEnvironment.With(
				new CompilerContext(compileUnit).Environment,
				() => Assert.AreSame(compileUnit, My<CompileUnit>.Instance));
		}
Пример #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;
		}
Пример #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);
		}
Пример #4
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));
				}
			}
		}
Пример #5
0
        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;
				}
			}

        }
Пример #6
0
		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);
			}
		}
Пример #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;
 }
Пример #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));
		}
Пример #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;
		}
Пример #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;
		}
Пример #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;
 }
Пример #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);
        }
Пример #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;
        }
Пример #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);
        }
Пример #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);
        }
Пример #17
0
		public static Assembly compile(CompileUnit unit, params Assembly[] references)
		{
			CompilerContext result = compile_(unit, references);
			AssertNoErrors(result);
			return result.GeneratedAssembly;
		}
Пример #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;
	}
Пример #19
0
		public CompileUnitNamespace(CompileUnit unit)
		{
			_nameResolutionService = My<NameResolutionService>.Instance;
			_internalTypeSystemProvider = My<InternalTypeSystemProvider>.Instance;
			_compileUnit = unit;
		}
Пример #20
0
 private static bool IsApplication(CompileUnit unit)
 {
     foreach (Module m in unit.Modules)
     {
         if (m.Globals.HasStatements) return true;
     }
     return false;
 }
Пример #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;
        }
Пример #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;


		}
Пример #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;
        }
Пример #24
0
		public static CompileUnit ParseReader(int tabSize, string readerName, TextReader reader)
		{		
			var cu = new CompileUnit();
			ParseModule(tabSize, cu, readerName, reader, null);
			return cu;
		}
Пример #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;
		}
Пример #27
0
 public CompilerContext(CompileUnit unit)
     : this(new CompilerParameters(), unit)
 {
 }
 public void Initialize(CompilerContext context){
     this.root = context.CompileUnit;
 }
Пример #29
0
		public static CompilerContext compile_(CompileUnit unit, params ICompileUnit[] references)
		{
			return NewCompilerWithReferences(references).Run(unit);
		}
Пример #30
0
 public static bool IsTainted(CompileUnit cu)
 {
     return cu.ContainsAnnotation(TaintedAnnotation);
 }
 public override void OnCompileUnit(CompileUnit node)
 {
     compileUnitVisited = true;
     base.OnCompileUnit(node);
 }
Пример #32
0
 public static void Taint(CompileUnit cu)
 {
     cu.set_Item(TaintedAnnotation, TaintedAnnotation);
 }