protected void Prepare(string source, bool minimizeNames = true, bool expectErrors = false) {
			IProjectContent project = new CSharpProjectContent();
			var parser = new CSharpParser();

			using (var rdr = new StringReader(source)) {
				var pf = new CSharpUnresolvedFile { FileName = "File.cs" };
				var syntaxTree = parser.Parse(rdr, pf.FileName);
				syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
				project = project.AddOrUpdateFiles(pf);
			}
			project = project.AddAssemblyReferences(new[] { Files.Mscorlib });

			_errorReporter = new MockErrorReporter(!expectErrors);

			var compilation = project.CreateCompilation();
			var s = new AttributeStore(compilation, _errorReporter);
			RunAutomaticMetadataAttributeAppliers(s, compilation);
			s.RunAttributeCode();

			Metadata = new MetadataImporter(_errorReporter, compilation, s, new CompilerOptions { MinimizeScript = minimizeNames });

			Metadata.Prepare(compilation.GetAllTypeDefinitions());

			AllErrors = _errorReporter.AllMessages.ToList().AsReadOnly();
			AllErrorTexts = _errorReporter.AllMessages.Select(m => m.FormattedMessage).ToList().AsReadOnly();
			if (expectErrors) {
				Assert.That(AllErrorTexts, Is.Not.Empty, "Compile should have generated errors");
			}
			else {
				Assert.That(AllErrorTexts, Is.Empty, "Compile should not generate errors");
			}

			AllTypes = compilation.MainAssembly.TopLevelTypeDefinitions.SelectMany(SelfAndNested).ToDictionary(t => t.ReflectionName);
		}
        private void InitializeAttributeStore(AttributeStore attributeStore, WindsorContainer container, ICompilation compilation)
        {
            var assemblies = compilation.Assemblies;
            var types      = compilation.GetAllTypeDefinitions().ToList();

            foreach (var applier in container.ResolveAll <IAutomaticMetadataAttributeApplier>())
            {
                foreach (var a in assemblies)
                {
                    applier.Process(a);
                }
                foreach (var t in types)
                {
                    applier.Process(t);
                }
            }
            attributeStore.RunAttributeCode();
        }
		protected Tuple<ICompilation, IOOPEmulator, List<JsType>> Compile(string source, IEnumerable<IAssemblyResource> resources = null, IErrorReporter errorReporter = null) {
			errorReporter = errorReporter ?? new MockErrorReporter(true);
			var sourceFile = new MockSourceFile("file.cs", source);
			var n = new Namer();
			var references = new[] { Files.Mscorlib };
			var compilation = PreparedCompilation.CreateCompilation("x", new[] { sourceFile }, references, null, resources);
			var s = new AttributeStore(compilation.Compilation, errorReporter);
			RunAutomaticMetadataAttributeAppliers(s, compilation.Compilation);
			s.RunAttributeCode();
			var md = new MetadataImporter(errorReporter, compilation.Compilation, s, new CompilerOptions());
			var rtl = new RuntimeLibrary(md, errorReporter, compilation.Compilation, n, s);
			md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
			var compiler = new Compiler(md, n, rtl, errorReporter);
			var compiledTypes = compiler.Compile(compilation).ToList();

			return Tuple.Create(compilation.Compilation, (IOOPEmulator)new OOPEmulator(compilation.Compilation, md, rtl, n, new MockLinker(), s, errorReporter), compiledTypes);

		}
Ejemplo n.º 4
0
        private void Prepare(string source, IRuntimeLibrary runtimeLibrary = null, bool expectErrors = false, bool MinimizeNames = false)
        {
            IProjectContent project = new CSharpProjectContent();
            var             parser  = new CSharpParser();

            using (var rdr = new StringReader(source)) {
                var pf = new CSharpUnresolvedFile()
                {
                    FileName = "File.cs"
                };
                var syntaxTree = parser.Parse(rdr, pf.FileName);
                syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
                project = project.AddOrUpdateFiles(pf);
            }
            project = project.AddAssemblyReferences(new[] { Files.Mscorlib, Files.Web, Files.Knockout });

            _compilation = project.CreateCompilation();

            var options = new CompilerOptions {
                MinimizeScript = MinimizeNames
            };

            _errorReporter = new MockErrorReporter(!expectErrors);
            var s = new AttributeStore(_compilation, _errorReporter);

            s.RunAttributeCode();
            _metadata = new MetadataImporter(_errorReporter, _compilation, s, options);

            _metadata.Prepare(_compilation.GetAllTypeDefinitions());

            _allErrors = _errorReporter.AllMessages.ToList().AsReadOnly();
            if (expectErrors)
            {
                Assert.That(_allErrors, Is.Not.Empty, "Compile should have generated errors");
            }
            else
            {
                Assert.That(_allErrors, Is.Empty, "Compile should not generate errors");
            }

            var rtl = new RuntimeLibrary(_metadata, _errorReporter, _compilation, new Namer(), s);
        }
        protected void Prepare(string source, bool minimizeNames = true, bool expectErrors = false)
        {
            IProjectContent project = new CSharpProjectContent();
            var             parser  = new CSharpParser();

            using (var rdr = new StringReader(source)) {
                var pf = new CSharpUnresolvedFile {
                    FileName = "File.cs"
                };
                var syntaxTree = parser.Parse(rdr, pf.FileName);
                syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
                project = project.AddOrUpdateFiles(pf);
            }
            project = project.AddAssemblyReferences(new[] { Files.Mscorlib });

            _errorReporter = new MockErrorReporter(!expectErrors);

            var compilation = project.CreateCompilation();
            var s           = new AttributeStore(compilation, _errorReporter);

            RunAutomaticMetadataAttributeAppliers(s, compilation);
            s.RunAttributeCode();

            Metadata = new MetadataImporter(_errorReporter, compilation, s, new CompilerOptions {
                MinimizeScript = minimizeNames
            });

            Metadata.Prepare(compilation.GetAllTypeDefinitions());

            AllErrors     = _errorReporter.AllMessages.ToList().AsReadOnly();
            AllErrorTexts = _errorReporter.AllMessages.Select(m => m.FormattedMessage).ToList().AsReadOnly();
            if (expectErrors)
            {
                Assert.That(AllErrorTexts, Is.Not.Empty, "Compile should have generated errors");
            }
            else
            {
                Assert.That(AllErrorTexts, Is.Empty, "Compile should not generate errors");
            }

            AllTypes = compilation.MainAssembly.TopLevelTypeDefinitions.SelectMany(SelfAndNested).ToDictionary(t => t.ReflectionName);
        }
        protected Tuple <ICompilation, IOOPEmulator, List <JsType> > Compile(string source, IEnumerable <IAssemblyResource> resources = null, IErrorReporter errorReporter = null)
        {
            errorReporter = errorReporter ?? new MockErrorReporter(true);
            var sourceFile  = new MockSourceFile("file.cs", source);
            var n           = new Namer();
            var references  = new[] { Files.Mscorlib };
            var compilation = PreparedCompilation.CreateCompilation("x", new[] { sourceFile }, references, null, resources);
            var s           = new AttributeStore(compilation.Compilation, errorReporter);

            RunAutomaticMetadataAttributeAppliers(s, compilation.Compilation);
            s.RunAttributeCode();
            var md  = new MetadataImporter(errorReporter, compilation.Compilation, s, new CompilerOptions());
            var rtl = new RuntimeLibrary(md, errorReporter, compilation.Compilation, n, s);

            md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
            var compiler      = new Compiler(md, n, rtl, errorReporter);
            var compiledTypes = compiler.Compile(compilation).ToList();

            return(Tuple.Create(compilation.Compilation, (IOOPEmulator) new OOPEmulator(compilation.Compilation, md, rtl, n, new MockLinker(), s, errorReporter), compiledTypes));
        }
Ejemplo n.º 7
0
        private Tuple <JsClass, MockErrorReporter> Compile(string source, bool expectErrors = false)
        {
            var sourceFile  = new MockSourceFile("file.cs", source);
            var er          = new MockErrorReporter(!expectErrors);
            var n           = new Namer();
            var references  = new[] { Mscorlib, QUnit };
            var compilation = PreparedCompilation.CreateCompilation("Test", new[] { sourceFile }, references, null);
            var s           = new AttributeStore(compilation.Compilation, er);

            s.RunAttributeCode();
            var md  = new MetadataImporter(er, compilation.Compilation, s, new CompilerOptions());
            var rtl = new RuntimeLibrary(md, er, compilation.Compilation, n, s);

            md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
            var compiler = new Compiler(md, n, rtl, er);

            var result = compiler.Compile(compilation).ToList();

            Assert.That(result, Has.Count.EqualTo(1), "Should compile exactly one type");
            Assert.That(er.AllMessages, Is.Empty, "Compile should not generate errors");

            result = new TestRewriter(er, rtl, s).Rewrite(result).ToList();
            Assert.That(result, Has.Count.EqualTo(1), "Should have one type after rewrite");
            Assert.That(result[0], Is.InstanceOf <JsClass>(), "Compiled type should be a class after rewrite");

            if (expectErrors)
            {
                Assert.That(er.AllMessages, Is.Not.Empty);
            }
            else
            {
                Assert.That(er.AllMessages, Is.Empty);
            }

            return(Tuple.Create((JsClass)result[0], er));
        }
		private void InitializeAttributeStore(AttributeStore attributeStore, WindsorContainer container, ICompilation compilation) {
			var assemblies = compilation.Assemblies;
			var types = compilation.GetAllTypeDefinitions().ToList();
			foreach (var applier in container.ResolveAll<IAutomaticMetadataAttributeApplier>()) {
				foreach (var a in assemblies)
					applier.Process(a);
				foreach (var t in types)
					applier.Process(t);
			}
			attributeStore.RunAttributeCode();
		}
        private void Prepare(string source, IRuntimeLibrary runtimeLibrary = null, bool expectErrors = false, bool MinimizeNames = false)
        {
            IProjectContent project = new CSharpProjectContent();
            var parser = new CSharpParser();

            using (var rdr = new StringReader(source)) {
                var pf = new CSharpUnresolvedFile() { FileName = "File.cs" };
                var syntaxTree = parser.Parse(rdr, pf.FileName);
                syntaxTree.AcceptVisitor(new TypeSystemConvertVisitor(pf));
                project = project.AddOrUpdateFiles(pf);
            }
            project = project.AddAssemblyReferences(new[] { Files.Mscorlib, Files.Web, Files.Knockout });

            _compilation = project.CreateCompilation();

            var options = new CompilerOptions { MinimizeScript = MinimizeNames };
            _errorReporter = new MockErrorReporter(!expectErrors);
            var s = new AttributeStore(_compilation, _errorReporter);
            s.RunAttributeCode();
            _metadata = new MetadataImporter(_errorReporter, _compilation, s, options);

            _metadata.Prepare(_compilation.GetAllTypeDefinitions());

            _allErrors = _errorReporter.AllMessages.ToList().AsReadOnly();
            if (expectErrors) {
                Assert.That(_allErrors, Is.Not.Empty, "Compile should have generated errors");
            }
            else {
                Assert.That(_allErrors, Is.Empty, "Compile should not generate errors");
            }

            var rtl = new RuntimeLibrary(_metadata, _errorReporter, _compilation, new Namer(), s);
        }
Ejemplo n.º 10
0
        private Tuple<JsClass, MockErrorReporter> Compile(string source, bool expectErrors = false)
        {
            var sourceFile = new MockSourceFile("file.cs", source);
            var er = new MockErrorReporter(!expectErrors);
            var n = new Namer();
            var references = new[] { Mscorlib, QUnit };
            var compilation = PreparedCompilation.CreateCompilation("Test", new[] { sourceFile }, references, null);
            var s = new AttributeStore(compilation.Compilation, er);
            s.RunAttributeCode();
            var md = new MetadataImporter(er, compilation.Compilation, s, new CompilerOptions());
            var rtl = new RuntimeLibrary(md, er, compilation.Compilation, n, s);
            md.Prepare(compilation.Compilation.GetAllTypeDefinitions());
            var compiler = new Compiler(md, n, rtl, er);

            var result = compiler.Compile(compilation).ToList();
            Assert.That(result, Has.Count.EqualTo(1), "Should compile exactly one type");
            Assert.That(er.AllMessages, Is.Empty, "Compile should not generate errors");

            result = new TestRewriter(er, rtl, s).Rewrite(result).ToList();
            Assert.That(result, Has.Count.EqualTo(1), "Should have one type after rewrite");
            Assert.That(result[0], Is.InstanceOf<JsClass>(), "Compiled type should be a class after rewrite");

            if (expectErrors) {
                Assert.That(er.AllMessages, Is.Not.Empty);
            }
            else {
                Assert.That(er.AllMessages, Is.Empty);
            }

            return Tuple.Create((JsClass)result[0], er);
        }