Codegen (rhino 1.7.7.2 API)
Date: 2017-09-27

org.mozilla.javascript.optimizer

## Class Codegen

- java.lang.Object
- - org.mozilla.javascript.optimizer.Codegen

- All Implemented Interfaces:
    Evaluator

      public class Codegen
      extends java.lang.Object
      implements Evaluator

  This class generates code for a given IR tree.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Codegen()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `captureStackInfo(RhinoException ex)` Capture stack information from the given exception.
    `java.lang.Object` | `compile(CompilerEnvirons compilerEnv, ScriptNode tree, java.lang.String encodedSource, boolean returnFunction)` Compile the script or function from intermediate representation tree into an executable form.
    `byte[]` | `compileToClassFile(CompilerEnvirons compilerEnv, java.lang.String mainClassName, ScriptNode scriptOrFn, java.lang.String encodedSource, boolean returnFunction)`
    `Function` | `createFunctionObject(Context cx, Scriptable scope, java.lang.Object bytecode, java.lang.Object staticSecurityDomain)` Create a function object.
    `Script` | `createScriptObject(java.lang.Object bytecode, java.lang.Object staticSecurityDomain)` Create a script object.
    `java.lang.String` | `getPatchedStack(RhinoException ex, java.lang.String nativeStackTrace)` Given a native stack trace, patch it with script-specific source and line information
    `java.util.List<java.lang.String>` | `getScriptStack(RhinoException ex)` Get the script stack for the given exception
    `java.lang.String` | `getSourcePositionFromStack(Context cx, int[] linep)` Get the source position information by examining the stack.
    `void` | `setEvalScriptFlag(Script script)` Mark the given script to indicate it was created by a call to eval() or to a Function constructor.
    `void` | `setMainMethodClass(java.lang.String className)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Codegen

          public Codegen()

  - ### Method Detail

    - #### captureStackInfo

          public void captureStackInfo(RhinoException ex)

      Description copied from interface: `Evaluator`
      Capture stack information from the given exception.
      Specified by:
        `captureStackInfo` in interface `Evaluator`
      Parameters:
        `ex` - an exception thrown during execution

    - #### getSourcePositionFromStack

          public java.lang.String getSourcePositionFromStack(Context cx,
                                                             int[] linep)

      Description copied from interface: `Evaluator`
      Get the source position information by examining the stack.
      Specified by:
        `getSourcePositionFromStack` in interface `Evaluator`
      Parameters:
        `cx` - Context
        `linep` - Array object of length >= 1; getSourcePositionFromStack will assign the line number to linep[0].
      Returns:
        the name of the file or other source container

    - #### getPatchedStack

          public java.lang.String getPatchedStack(RhinoException ex,
                                                  java.lang.String nativeStackTrace)

      Description copied from interface: `Evaluator`
      Given a native stack trace, patch it with script-specific source and line information
      Specified by:
        `getPatchedStack` in interface `Evaluator`
      Parameters:
        `ex` - exception
        `nativeStackTrace` - the native stack trace
      Returns:
        patched stack trace

    - #### getScriptStack

          public java.util.List<java.lang.String> getScriptStack(RhinoException ex)

      Description copied from interface: `Evaluator`
      Get the script stack for the given exception
      Specified by:
        `getScriptStack` in interface `Evaluator`
      Parameters:
        `ex` - exception from execution
      Returns:
        list of strings for the stack trace

    - #### setEvalScriptFlag

          public void setEvalScriptFlag(Script script)

      Description copied from interface: `Evaluator`
      Mark the given script to indicate it was created by a call to eval() or to a Function constructor.
      Specified by:
        `setEvalScriptFlag` in interface `Evaluator`
      Parameters:
        `script` - script to mark as from eval

    - #### compile

          public java.lang.Object compile(CompilerEnvirons compilerEnv,
                                          ScriptNode tree,
                                          java.lang.String encodedSource,
                                          boolean returnFunction)

      Description copied from interface: `Evaluator`
      Compile the script or function from intermediate representation tree into an executable form.
      Specified by:
        `compile` in interface `Evaluator`
      Parameters:
        `compilerEnv` - Compiler environment
        `tree` - parse tree
        `encodedSource` - encoding of the source code for decompilation
        `returnFunction` - if true, compiling a function
      Returns:
        an opaque object that can be passed to either createFunctionObject or createScriptObject, depending on the value of returnFunction

    - #### createScriptObject

          public Script createScriptObject(java.lang.Object bytecode,
                                           java.lang.Object staticSecurityDomain)

      Description copied from interface: `Evaluator`
      Create a script object.
      Specified by:
        `createScriptObject` in interface `Evaluator`
      Parameters:
        `bytecode` - opaque object returned by compile
        `staticSecurityDomain` - security domain
      Returns:
        Script object that can be evaluated

    - #### createFunctionObject

          public Function createFunctionObject(Context cx,
                                               Scriptable scope,
                                               java.lang.Object bytecode,
                                               java.lang.Object staticSecurityDomain)

      Description copied from interface: `Evaluator`
      Create a function object.
      Specified by:
        `createFunctionObject` in interface `Evaluator`
      Parameters:
        `cx` - Current context
        `scope` - scope of the function
        `bytecode` - opaque object returned by compile
        `staticSecurityDomain` - security domain
      Returns:
        Function object that can be called

    - #### compileToClassFile

          public byte[] compileToClassFile(CompilerEnvirons compilerEnv,
                                           java.lang.String mainClassName,
                                           ScriptNode scriptOrFn,
                                           java.lang.String encodedSource,
                                           boolean returnFunction)

    - #### setMainMethodClass

          public void setMainMethodClass(java.lang.String className)