Java 类org.mozilla.javascript.IRFactory 实例源码

项目:rhino-android    文件:Bug782363Test.java   
/**
 * Compiles {@code source} and returns the transformed and optimized
 * {@link ScriptNode}
 */
protected ScriptNode compile(CharSequence source) {
    final String mainMethodClassName = "Main";
    final String scriptClassName = "Main";

    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(cx);
    Parser p = new Parser(compilerEnv);
    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;
}
项目:rhino-android    文件:Bug708801Test.java   
/**
 * Compiles {@code source} and returns the transformed and optimized
 * {@link ScriptNode}
 */
protected ScriptNode compile(CharSequence source) {
    final String mainMethodClassName = "Main";
    final 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;
}
项目:code404    文件:Bug708801Test.java   
/**
 * Compiles {@code source} and returns the transformed and optimized
 * {@link ScriptNode}
 */
protected ScriptNode compile(CharSequence source) {
    final String mainMethodClassName = "Main";
    final 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;
}
项目:rhino-jscover    文件:Bug708801Test.java   
/**
 * Compiles {@code source} and returns the transformed and optimized
 * {@link ScriptNode}
 */
protected ScriptNode compile(CharSequence source) {
    final String mainMethodClassName = "Main";
    final 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;
}
项目:Rhino-Prov-Mod    文件:Bug708801Test.java   
/**
 * Compiles {@code source} and returns the transformed and optimized
 * {@link ScriptNode}
 */
protected ScriptNode compile(CharSequence source) {
    final String mainMethodClassName = "Main";
    final 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;
}
项目:birt    文件:CubeQueryUtil.java   
/**
 * 
 * @param expr
 * @param objectName
 * @return
 */
private static String getReferencedScriptObject( String expr,
        String objectName )
{
    if ( expr == null )
        return null;
    try
    {
        Context cx = Context.enter( );
        CompilerEnvirons ce = new CompilerEnvirons( );
        Parser p = new Parser( ce, cx.getErrorReporter( ) );
        AstRoot tree = p.parse( expr, null, 0 );
        IRFactory ir = new IRFactory( ce );
        ScriptNode script = ir.transformTree( tree );
        return getScriptObjectName( script, objectName );
    }
    finally
    {
        Context.exit( );
    }
}
项目:birt    文件:OlapExpressionCompiler.java   
/**
 * 
 * @param expr
 * @param objectName
 * @return
 */
public static String getReferencedScriptObject( String expr,
        String objectName )
{
    if ( expr == null )
        return null;
    try
    {
        Context cx = Context.enter( );
        CompilerEnvirons ce = new CompilerEnvirons( );
        Parser p = new Parser( ce, cx.getErrorReporter( ) );
        AstRoot tree = p.parse( expr, null, 0 );
        Node root = new IRFactory( ce).transformTree(tree);

        return getScriptObjectName( root, objectName );
    }
    catch( Exception ex )
    {
        return null;
    }
    finally
    {
        Context.exit( );
    }
}
项目:birt    文件:OlapExpressionCompiler.java   
/**
 * 
 * @param expr
 * @param bindings
 * @param onlyFromDirectReferenceExpr
 * @return
 * @throws DataException
 */
private static Set getReferencedDimLevel( IScriptExpression expr,
        List bindings, boolean onlyFromDirectReferenceExpr )
        throws DataException
{
    if ( expr == null || expr.getText( ) == null || expr.getText( ).length( ) == 0 || BaseExpression.constantId.equals( expr.getScriptId( ) ) )
        return new HashSet( );
    try
    {
        Set result = new HashSet( );
        Context cx = Context.enter( );
        CompilerEnvirons ce = new CompilerEnvirons( );
        Parser p = new Parser( ce, cx.getErrorReporter( ) );
        AstRoot tree = p.parse( expr.getText( ), null, 0 );
        Node root = new IRFactory( ce).transformTree(tree);

        populateDimLevels( null,
                root,
                result,
                bindings,
                onlyFromDirectReferenceExpr );
        return result;
    }
    finally
    {
        Context.exit( );
    }
}
项目:birt    文件:AbstractExpressionCompiler.java   
/**
 * parse the expression to script tree
 * 
 * @param expression
 * @param cx
 * @return
 * @throws DataException
 */
protected ScriptNode parse( String expression, Context cx )
        throws DataException
{
    if ( expression == null )
        throw new DataException( ResourceConstants.EXPRESSION_CANNOT_BE_NULL_OR_BLANK );

    CompilerEnvirons compilerEnv = getCompilerEnv( cx );
    Parser p = new Parser( compilerEnv, cx.getErrorReporter( ) );
    AstRoot root = p.parse( expression, null, 0 );
    IRFactory ir = new IRFactory(compilerEnv );
    ScriptNode script = ir.transformTree(root);
    return script;
}
项目:birt    文件:ExpressionParserUtility.java   
/**
 * parse the expression into a script tree
 * 
 * @param expression
 * @param cx
 * @return
 */
private ScriptNode parse( String expression, Context cx )
{
    CompilerEnvirons compilerEnv = new CompilerEnvirons( );
    Parser p = new Parser( compilerEnv, cx.getErrorReporter( ) );
    AstRoot root = p.parse( expression, null, 0 );
    IRFactory ir = new IRFactory(compilerEnv);
    return ir.transformTree(root);
}
项目:birt    文件:OlapExpressionCompiler.java   
/**
 * 
 * @param expr
 * @param objectName
 * @return
 */
public static Set<String> getReferencedMeasure( String expr )
{
    if ( expr == null )
        return Collections.emptySet( );
    try
    {
        Set<String> result = new LinkedHashSet<String>( );
        Context cx = Context.enter( );
        CompilerEnvirons ce = new CompilerEnvirons( );
        Parser p = new Parser( ce, cx.getErrorReporter( ) );
        AstRoot tree = p.parse( expr, null, 0 );
        IRFactory ir = new IRFactory( ce );
        ScriptNode script = ir.transformTree( tree );
        getScriptObjectName( script, "measure", result ); //$NON-NLS-1$

        return result;
    }
    catch( Exception e )
    {
        return Collections.emptySet( );
    }
    finally
    {
        Context.exit( );
    }
}
项目:birt    文件:OlapExpressionCompiler.java   
/**
 * 
 * @param expr
 * @param bindings
 * @param onlyFromDirectReferenceExpr
 * @return
 * @throws DataException
 */
public static Set<IDimLevel> getReferencedDimLevel( String expr )
        throws CoreException
{
    if ( expr == null  )
        return new HashSet<IDimLevel>( );
    try
    {
        Set<IDimLevel> result = new HashSet<IDimLevel>( );
        Context cx = Context.enter( );
        CompilerEnvirons ce = new CompilerEnvirons( );
        Parser p = new Parser( ce, cx.getErrorReporter( ) );
        AstRoot tree = p.parse( expr, null, 0 );
        IRFactory ir = new IRFactory( ce );
        ScriptNode script = ir.transformTree( tree );
        populateDimLevels( null, script, result );
        return result;
    }
    catch( Exception e )
    {
        return Collections.emptySet( );
    }
    finally
    {
        Context.exit( );
    }
}
项目:birt    文件:ExpressionUtility.java   
/**
 * whether the expression is column reference
 * @param expression
 * @return
 */
public static boolean isColumnExpression( String expression, boolean mode )
{
    boolean isColumn = false;
    if ( expression == null || expression.trim( ).length( ) == 0 )
        return isColumn;
    if ( getCompiledExpCacheMap( mode ).containsKey( expression ) )
    {
        return ( (Boolean)  getCompiledExpCacheMap( mode ).get( expression ) ).booleanValue( );
    }
    Context context = Context.enter( );
    ScriptNode tree;
    try
    {
        CompilerEnvirons m_compilerEnv = new CompilerEnvirons( );
        m_compilerEnv.initFromContext( context );
        Parser p = new Parser( m_compilerEnv, context.getErrorReporter( ) );
        AstRoot root = p.parse( expression, null, 0 );
        IRFactory ir = new IRFactory( m_compilerEnv );
        tree = ir.transformTree( root );
    }
    catch ( Exception e )
    {
        getCompiledExpCacheMap( mode ).put( expression,
                Boolean.valueOf( false ) );
        return false;
    }
    finally
    {
        Context.exit( );
    }

    if ( tree.getFirstChild( ) == tree.getLastChild( ) )
    {
        // A single expression
        if ( tree.getFirstChild( ).getType( ) != Token.EXPR_RESULT
                && tree.getFirstChild( ).getType( ) != Token.EXPR_VOID
                && tree.getFirstChild( ).getType( ) != Token.BLOCK )
        {
            isColumn = false;
        }
        Node exprNode = tree.getFirstChild( );
        Node child = exprNode.getFirstChild( );
        assert ( child != null );
        if ( child.getType( ) == Token.GETELEM
                || child.getType( ) == Token.GETPROP )
            isColumn = getDirectColRefExpr( child, mode );
        else
            isColumn = false;
    }
    else
    {
        isColumn = false;
    }
    getCompiledExpCacheMap( mode ).put( expression,
            Boolean.valueOf( isColumn ) );
    return isColumn;
}
项目:birt    文件:ExpressionUtility.java   
/**
 * whether the expression is column reference
 * @param expression
 * @return
 */
public static boolean isColumnExpression( String expression, boolean mode )
{
    boolean isColumn = false;
    if ( expression == null || expression.trim( ).length( ) == 0 )
        return isColumn;
    if ( getCompiledExpCacheMap( mode ).containsKey( expression ) )
    {
        return ( (Boolean)  getCompiledExpCacheMap( mode ).get( expression ) ).booleanValue( );
    }
    Context context = Context.enter( );
    ScriptNode tree;
    try
    {
        CompilerEnvirons m_compilerEnv = new CompilerEnvirons( );
        m_compilerEnv.initFromContext( context );
        Parser p = new Parser( m_compilerEnv, context.getErrorReporter( ) );
        AstRoot root = p.parse( expression, null, 0 );
        IRFactory ir = new IRFactory( m_compilerEnv );
        tree = ir.transformTree( root );
    }
    catch ( Exception e )
    {
        getCompiledExpCacheMap( mode ).put( expression,
                Boolean.valueOf( false ) );
        return false;
    }
    finally
    {
        Context.exit( );
    }

    if ( tree.getFirstChild( ) == tree.getLastChild( ) )
    {
        // A single expression
        if ( tree.getFirstChild( ).getType( ) != Token.EXPR_RESULT
                && tree.getFirstChild( ).getType( ) != Token.EXPR_VOID
                && tree.getFirstChild( ).getType( ) != Token.BLOCK )
        {
            isColumn = false;
        }
        Node exprNode = tree.getFirstChild( );
        Node child = exprNode.getFirstChild( );
        assert ( child != null );
        if ( child.getType( ) == Token.GETELEM
                || child.getType( ) == Token.GETPROP )
            isColumn = getDirectColRefExpr( child, mode );
        else
            isColumn = false;
    }
    else
    {
        isColumn = false;
    }
    getCompiledExpCacheMap( mode ).put( expression,
            Boolean.valueOf( isColumn ) );
    return isColumn;
}
项目:birt    文件:ExpressionUtility.java   
/**
 * whether the expression is column reference
 * 
 * @param expression
 * @return
 */
public static boolean isColumnExpression( String expression )
{
    boolean isColumn = false;
    if ( expression == null || expression.trim( ).length( ) == 0 )
        return isColumn;
    if ( compiledExprCache.containsKey( expression ) )
        return ( (Boolean) compiledExprCache.get( expression ) ).booleanValue( );
    Context context = Context.enter( );
    ScriptNode tree;
    try
    {
        CompilerEnvirons m_compilerEnv = new CompilerEnvirons( );
        m_compilerEnv.initFromContext( context );
        Parser p = new Parser( m_compilerEnv, context.getErrorReporter( ) );
        AstRoot root = p.parse( expression, null, 0 );
        IRFactory ir = new IRFactory( m_compilerEnv );
        tree = ir.transformTree( root );
    }
    catch ( Exception e )
    {
        compiledExprCache.put( expression, Boolean.valueOf( false ) );
        return false;
    }
    finally
    {
        Context.exit( );
    }

    if ( tree.getFirstChild( ) == tree.getLastChild( ) )
    {
        // A single expression
        if ( tree.getFirstChild( ).getType( ) != Token.EXPR_RESULT
                && tree.getFirstChild( ).getType( ) != Token.EXPR_VOID
                && tree.getFirstChild( ).getType( ) != Token.BLOCK )
        {
            isColumn = false;
        }
        Node exprNode = tree.getFirstChild( );
        Node child = exprNode.getFirstChild( );
        assert ( child != null );
        if ( child.getType( ) == Token.GETELEM
                || child.getType( ) == Token.GETPROP )
            isColumn = getDirectColRefExpr( child );
        else
            isColumn = false;
    }
    else
    {
        isColumn = false;
    }

    compiledExprCache.put( expression, Boolean.valueOf( isColumn ) );
    return isColumn;
}