/// <summary> /// Initializes a new instance of the <see cref="TestCompilerSettings"/> class. /// </summary> /// <param name="settings">The settings.</param> public CompilerHelperSettings(CompilerHelperSettings settings) { language = settings.language; unsafeCode = settings.unsafeCode; doNotReferenceMscorlib = settings.doNotReferenceMscorlib; codeSource = settings.codeSource; additionalSource = settings.additionalSource; references = new List<string>(settings.references); }
/// <summary> /// Initializes a new instance of the <see cref="TestCompilerSettings"/> class. /// </summary> /// <param name="settings">The settings.</param> public CompilerHelperSettings(CompilerHelperSettings settings) { language = settings.language; unsafeCode = settings.unsafeCode; doNotReferenceMscorlib = settings.doNotReferenceMscorlib; codeSource = settings.codeSource; additionalSource = settings.additionalSource; references = new List <string>(settings.references); }
public bool IsEqual(CompilerHelperSettings other) { if (other == null) { return(false); } if (this.codeSource != other.codeSource) { return(false); } if (this.additionalSource != other.additionalSource) { return(false); } if (this.unsafeCode != other.unsafeCode) { return(false); } if (this.language != other.language) { return(false); } if (this.doNotReferenceMscorlib != other.doNotReferenceMscorlib) { return(false); } if (this.references.Count != other.references.Count) { return(false); } foreach (string file in this.references) { if (!other.references.Contains(file)) { return(false); } } return(true); }
public bool IsEqual(CompilerHelperSettings other) { if (other == null) return false; if (this.codeSource != other.codeSource) return false; if (this.additionalSource != other.additionalSource) return false; if (this.unsafeCode != other.unsafeCode) return false; if (this.language != other.language) return false; if (this.doNotReferenceMscorlib != other.doNotReferenceMscorlib) return false; if (this.references.Count != other.references.Count) return false; foreach (string file in this.references) if (!other.references.Contains(file)) return false; return true; }
private void RunMosaCompiler(CompilerHelperSettings settings, string assemblyFile) { IAssemblyLoader assemblyLoader = new AssemblyLoader(); assemblyLoader.InitializePrivatePaths(settings.References); assemblyLoader.LoadModule(assemblyFile); foreach (string file in settings.References) { assemblyLoader.LoadModule(file); } typeSystem = new TypeSystem(); typeSystem.LoadModules(assemblyLoader.Modules); RunMosaCompiler(); }
private string RunCodeDomCompiler(CompilerHelperSettings settings) { Console.WriteLine("Executing {0} compiler...", settings.Language); CodeDomProvider provider; if (!providerCache.TryGetValue(settings.Language, out provider)) { provider = CodeDomProvider.CreateProvider(settings.Language); if (provider == null) throw new NotSupportedException("The language '" + settings.Language + "' is not supported on this machine."); providerCache.Add(settings.Language, provider); } string filename = Path.Combine(TempDirectory, Path.ChangeExtension(Path.GetRandomFileName(), "dll")); temps.AddFile(filename, false); string[] references = new string[settings.References.Count]; settings.References.CopyTo(references, 0); CompilerResults compileResults; CompilerParameters parameters = new CompilerParameters(references, filename, false); parameters.CompilerOptions = "/optimize-"; if (settings.UnsafeCode) { if (settings.Language == "C#") parameters.CompilerOptions = parameters.CompilerOptions + " /unsafe+"; else throw new NotSupportedException(); } if (settings.DoNotReferenceMscorlib) { if (settings.Language == "C#") parameters.CompilerOptions = parameters.CompilerOptions + " /nostdlib"; else throw new NotSupportedException(); } parameters.GenerateInMemory = false; if (settings.CodeSource != null) { //Console.WriteLine("Code: {0}", settings.CodeSource + settings.AdditionalSource); compileResults = provider.CompileAssemblyFromSource(parameters, settings.CodeSource + settings.AdditionalSource); } else throw new NotSupportedException(); if (compileResults.Errors.HasErrors) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Code compile errors:"); foreach (CompilerError error in compileResults.Errors) { sb.AppendLine(error.ToString()); } throw new Exception(sb.ToString()); } return compileResults.PathToAssembly; }