public void Compile() { try { m_Engine.Compile(); } catch (VsaException e) { ScriptError scriptError = new ScriptError(this, e.Message); if (e.InnerException is JScriptException) { scriptError = new ScriptError(this, (JScriptException)e.InnerException); } FireOnError(this, scriptError); } }
// // Entry point // private static void Main (string [] args) { if (args.Length < 1) { Usage (); Environment.Exit (0); } MainDriver (args); VsaEngine engine = new VsaEngine (); engine.InitVsaEngine ("mjs:com.mono-project", new MonoEngineSite ()); foreach (string asm in references) { IVsaReferenceItem item = (IVsaReferenceItem) engine.Items.CreateItem (asm, VsaItemType.Reference, VsaItemFlag.None); item.AssemblyName = asm; } string asm_name = String.Empty; foreach (Assembly assembly in assemblies) { asm_name = assembly.GetName ().FullName; IVsaReferenceItem item = (IVsaReferenceItem) engine.Items.CreateItem (asm_name, VsaItemType.Reference, VsaItemFlag.None); item.AssemblyName = asm_name; } foreach (string file in files) { IVsaCodeItem item = (IVsaCodeItem) engine.Items.CreateItem (file, VsaItemType.Code, VsaItemFlag.None); item.SourceText = GetCodeFromFile (file); } engine.SetOption ("debug", want_debugging_support); engine.SetOption ("link_path", link_paths); engine.SetOption ("first_source", first_source); engine.SetOption ("assemblies", assemblies); engine.SetOption ("out", output_file); if (warning_level != -1) engine.SetOption ("WarningLevel", warning_level); engine.Compile (); }
bool Compile(CompilerOptions options) { if (this.fPrintTargets) { Console.WriteLine(Localize("Compiling", options.strOutputFileName)); } VsaEngine engine = new Microsoft.JScript.Vsa.VsaEngine(); if (null == engine) { throw new CmdLineException(CmdLineError.CannotCreateEngine, JScriptCompiler.GetCultureInfo()); } engine.InitVsaEngine("JSC://Microsoft.JScript.Vsa.VsaEngine", new EngineSite(options)); engine.LCID = JScriptCompiler.LCID; engine.GenerateDebugInfo = options.fDebug; engine.SetOption("AutoRef", options.autoRef); engine.SetOption("fast", options.fFast); engine.SetOption("output", options.strOutputFileName); engine.SetOption("PEFileKind", options.PEFileKind); engine.SetOption("print", options.fPrint); engine.SetOption("libpath", options.libpath); if (options.versionInfo != null) { engine.SetOption("version", options.versionInfo); } engine.SetOption("VersionSafe", options.fVersionSafe); engine.SetOption("defines", options.Defines); engine.SetOption("warnaserror", options.fTreatWarningsAsErrors); engine.SetOption("WarningLevel", options.nWarningLevel); if (options.ManagedResources.Count > 0) { engine.SetOption("managedResources", options.ManagedResources.Values); } bool fStdlibAdded = false; bool fWinFormsAdded = false; foreach (string assemblyName in options.ImportFileNames) { this.AddAssemblyReference(engine, assemblyName); string filename = Path.GetFileName(assemblyName); if (String.Compare(filename, "mscorlib.dll", true, CultureInfo.InvariantCulture) == 0) { fStdlibAdded = true; } else if (String.Compare(filename, "System.Windows.Forms.dll", true, CultureInfo.InvariantCulture) == 0) { fWinFormsAdded = true; } } // Only add mscorlib if it hasn't already been added. if (!options.fNoStdlib && !fStdlibAdded) { AddAssemblyReference(engine, "mscorlib.dll"); } // add System.Windows.Forms if target is winexe and it hasn't already been added if ((options.PEFileKind == PEFileKinds.WindowApplication) && !options.fNoStdlib && !fWinFormsAdded) { AddAssemblyReference(engine, "System.Windows.Forms.dll"); } for (int j = 0; j < options.SourceFileNames.Count; j++) { AddSourceFile(engine, (string)options.SourceFileNames[j], options.codepage, options.fForceCodepage); } bool isCompiled = false; try{ isCompiled = engine.Compile(); }catch (VsaException e) { // check for expected errors if (e.ErrorCode == VsaError.AssemblyExpected) { if (e.InnerException != null && e.InnerException is System.BadImageFormatException) { // the reference was not for an assembly CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, e.Message, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); } else if (e.InnerException != null && (e.InnerException is System.IO.FileNotFoundException || e.InnerException is System.IO.FileLoadException)) { // the referenced file not valid CmdLineException cmdLineError = new CmdLineException(CmdLineError.AssemblyNotFound, e.Message, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); } else { CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); } } else if (e.ErrorCode == VsaError.SaveCompiledStateFailed) { CmdLineException cmdLineError = new CmdLineException(CmdLineError.ErrorSavingCompiledState, e.Message, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); } else if (e.ErrorCode == VsaError.AssemblyNameInvalid && e.InnerException != null) { CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidCharacters, e.Message, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); } else { Console.WriteLine(Localize("INTERNAL COMPILER ERROR")); Console.WriteLine(e); } return(false); }catch (Exception e) { Console.WriteLine(Localize("INTERNAL COMPILER ERROR")); Console.WriteLine(e); return(false); } return(isCompiled); }
bool Compile(CompilerOptions options){ if (this.fPrintTargets) Console.WriteLine(Localize("Compiling", options.strOutputFileName)); VsaEngine engine = new Microsoft.JScript.Vsa.VsaEngine(); if (null == engine) throw new CmdLineException(CmdLineError.CannotCreateEngine, JScriptCompiler.GetCultureInfo()); engine.InitVsaEngine("JSC://Microsoft.JScript.Vsa.VsaEngine", new EngineSite(options)); engine.LCID = JScriptCompiler.GetCultureInfo().LCID; engine.GenerateDebugInfo = options.fDebug; engine.SetOption("ReferenceLoaderAPI", "ReflectionOnlyLoadFrom"); engine.SetOption("AutoRef", options.autoRef); engine.SetOption("fast", options.fFast); engine.SetOption("output", options.strOutputFileName); engine.SetOption("PEFileKind", options.PEFileKind); engine.SetOption("PortableExecutableKind", options.PEKindFlags); engine.SetOption("ImageFileMachine", options.PEMachineArchitecture); engine.SetOption("print", options.fPrint); engine.SetOption("libpath", options.libpath); if (options.versionInfo != null) engine.SetOption("version", options.versionInfo); engine.SetOption("VersionSafe", options.fVersionSafe); engine.SetOption("defines", options.Defines); engine.SetOption("warnaserror", options.fTreatWarningsAsErrors); engine.SetOption("WarningLevel", options.nWarningLevel); if (options.ManagedResources.Count > 0) engine.SetOption("managedResources", options.ManagedResources.Values); bool fStdlibAdded = false; bool fWinFormsAdded = false; foreach (string assemblyName in options.ImportFileNames){ AddAssemblyReference(engine, assemblyName); string filename = Path.GetFileName(assemblyName); if (String.Compare(filename, "mscorlib.dll", StringComparison.OrdinalIgnoreCase) == 0) fStdlibAdded = true; else if (String.Compare(filename, "System.Windows.Forms.dll", StringComparison.OrdinalIgnoreCase) == 0) fWinFormsAdded = true; } // Only add mscorlib if it hasn't already been added. if (!options.fNoStdlib && !fStdlibAdded) AddAssemblyReference(engine, "mscorlib.dll"); // add System.Windows.Forms if target is winexe and it hasn't already been added if ((options.PEFileKind == PEFileKinds.WindowApplication) && !options.fNoStdlib && !fWinFormsAdded) AddAssemblyReference(engine, "System.Windows.Forms.dll"); for (int j = 0; j < options.SourceFileNames.Count; j++) AddSourceFile(engine, (string)options.SourceFileNames[j], options.codepage); bool isCompiled = false; try{ isCompiled = engine.Compile(); }catch(VsaException e){ // check for expected errors if (e.ErrorCode == VsaError.AssemblyExpected){ if (e.InnerException != null && e.InnerException is System.BadImageFormatException){ // the reference was not for an assembly CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, e.Message, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); }else if (e.InnerException != null && (e.InnerException is System.IO.FileNotFoundException || e.InnerException is System.IO.FileLoadException)){ // the referenced file not valid CmdLineException cmdLineError = new CmdLineException(CmdLineError.AssemblyNotFound, e.Message, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); }else{ CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); } }else if (e.ErrorCode == VsaError.SaveCompiledStateFailed){ CmdLineException cmdLineError = new CmdLineException(CmdLineError.ErrorSavingCompiledState, e.Message, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); }else if (e.ErrorCode == VsaError.AssemblyNameInvalid && e.InnerException != null){ CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidCharacters, e.Message, JScriptCompiler.GetCultureInfo()); Console.WriteLine(cmdLineError.Message); }else{ Console.WriteLine(Localize("INTERNAL COMPILER ERROR")); Console.WriteLine(e); } return false; }catch(Exception e){ Console.WriteLine(Localize("INTERNAL COMPILER ERROR")); Console.WriteLine(e); return false; }catch{ Console.WriteLine(Localize("INTERNAL COMPILER ERROR")); return false; } return isCompiled; }