Package org.jruby.ir

Source Code of org.jruby.ir.IRScriptBody

package org.jruby.ir;

import org.jruby.ir.instructions.Instr;
import org.jruby.ir.interpreter.BeginEndInterpreterContext;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;

import java.util.ArrayList;
import java.util.List;

public class IRScriptBody extends IRScope {
    private List<IRClosure> beginBlocks;
    private List<IRClosure> endBlocks;
    private DynamicScope tlbScope;

    public IRScriptBody(IRManager manager, String sourceName, StaticScope staticScope) {
        super(manager, null, sourceName, sourceName, 0, staticScope);
        this.tlbScope = null;
        if (!getManager().isDryRun() && staticScope != null) {
            staticScope.setIRScope(this);
            staticScope.setScopeType(this.getScopeType());
        }
    }

    public DynamicScope getTopLevelBindingScope() {
        return tlbScope;
    }

    public void setTopLevelBindingScope(DynamicScope tlbScope) {
        this.tlbScope = tlbScope;
    }

    @Override
    public InterpreterContext allocateInterpreterContext(Instr[] instructionList) {
        return new BeginEndInterpreterContext(this, instructionList);
    }

    @Override
    public int getNearestModuleReferencingScopeDepth() {
        return 0;
    }

    @Override
    public IRScopeType getScopeType() {
        return IRScopeType.SCRIPT_BODY;
    }

    @Override
    public String toString() {
        return "Script: file: " + getFileName() + super.toString();
    }

    /* Record a begin block -- not all scope implementations can handle them */
    @Override
    public void recordBeginBlock(IRClosure beginBlockClosure) {
        if (beginBlocks == null) beginBlocks = new ArrayList<IRClosure>();
        beginBlockClosure.setBeginEndBlock();
        beginBlocks.add(beginBlockClosure);
    }

    /* Record an end block -- not all scope implementations can handle them */
    @Override
    public void recordEndBlock(IRClosure endBlockClosure) {
        if (endBlocks == null) endBlocks = new ArrayList<IRClosure>();
        endBlockClosure.setBeginEndBlock();
        endBlocks.add(endBlockClosure);
    }

    @Override
    public List<IRClosure> getBeginBlocks() {
        return beginBlocks;
    }

    @Override
    public List<IRClosure> getEndBlocks() {
        return endBlocks;
    }

    @Override
    public boolean isScriptScope() {
        return true;
    }
}
TOP

Related Classes of org.jruby.ir.IRScriptBody

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.