Rhino.Optimizer.Codegen.CompileToClassFile C# (CSharp) Method

CompileToClassFile() public method

public CompileToClassFile ( CompilerEnvirons compilerEnv, string mainClassName, ScriptNode scriptOrFn, string encodedSource, bool returnFunction ) : byte[]
compilerEnv Rhino.CompilerEnvirons
mainClassName string
scriptOrFn Rhino.Ast.ScriptNode
encodedSource string
returnFunction bool
return byte[]
		public virtual byte[] CompileToClassFile(CompilerEnvirons compilerEnv, string mainClassName, ScriptNode scriptOrFn, string encodedSource, bool returnFunction)
		{
			this.compilerEnv = compilerEnv;
			Transform(scriptOrFn);
			if (returnFunction)
			{
				scriptOrFn = scriptOrFn.GetFunctionNode(0);
			}
			InitScriptNodesData(scriptOrFn);
			this.mainClassName = mainClassName;
			this.mainClassSignature = ClassFileWriter.ClassNameToSignature(mainClassName);
			try
			{
				return GenerateCode(encodedSource);
			}
			catch (ClassFileWriter.ClassFileFormatException e)
			{
				throw ReportClassFileFormatException(scriptOrFn, e.Message);
			}
		}

Usage Example

Beispiel #1
0
			/// <summary>
			/// Compiles
			/// <code>source</code>
			/// and returns the transformed and optimized
			/// <see cref="Rhino.Ast.ScriptNode">Rhino.Ast.ScriptNode</see>
			/// </summary>
			protected internal virtual ScriptNode Compile(CharSequence source)
			{
				string mainMethodClassName = "Main";
				string scriptClassName = "Main";
				CompilerEnvirons compilerEnv = new CompilerEnvirons();
				compilerEnv.InitFromContext(cx);
				ErrorReporter compilationErrorReporter = compilerEnv.GetErrorReporter();
				Parser p = new Parser(compilerEnv, compilationErrorReporter);
				AstRoot ast = p.Parse(source.ToString(), "<eval>", 1);
				IRFactory irf = new IRFactory(compilerEnv);
				ScriptNode tree = irf.TransformTree(ast);
				Codegen codegen = new Codegen();
				codegen.SetMainMethodClass(mainMethodClassName);
				codegen.CompileToClassFile(compilerEnv, scriptClassName, tree, tree.GetEncodedSource(), false);
				return tree;
			}
All Usage Examples Of Rhino.Optimizer.Codegen::CompileToClassFile