/** * Returns the n-th parent scope of this scope. * May return <code>null</code>. * @param n - number of levels above to look. * @return The n-th parent scope or <code>null</code>. */ public DynamicScope getNthParentScope(int n) { DynamicScope scope = this; for (int i = 0; i < n; i++) { if (scope == null) break; scope = scope.getParentScope(); } return scope; }
/** * Returns the n-th parent scope of this scope. * May return <code>null</code>. * @param n - number of levels above to look. * @return The n-th parent scope or <code>null</code>. */ public DynamicScope getNthParentScope(int n) { DynamicScope scope = this; for (int i = 0; i < n; i++) { if (scope == null) break; scope = scope.getParentScope(); } return scope; }
@Deprecated public DynamicScope getNextCapturedScope() { // Used by ruby-debug-ide return getParentScope(); }
@Deprecated public DynamicScope getNextCapturedScope() { // Used by ruby-debug-ide return getParentScope(); }
private static DynamicScope getContainingMethodOrLambdasDynamicScope(DynamicScope dynScope) { // If not in a lambda, check if this was a non-local return for (; dynScope != null; dynScope = dynScope.getParentScope()) { StaticScope staticScope = dynScope.getStaticScope(); IRScope scope = staticScope.getIRScope(); // 1) method 2) root of script 3) lambda 3) closure (define_method) for zsuper if (scope instanceof IRMethod || scope instanceof IRScriptBody || (scope instanceof IRClosure && (dynScope.isLambda() || staticScope.isArgumentScope()))) return dynScope; } return null; }
private static DynamicScope getContainingMethodOrLambdasDynamicScope(DynamicScope dynScope) { // If not in a lambda, check if this was a non-local return for (; dynScope != null; dynScope = dynScope.getParentScope()) { StaticScope staticScope = dynScope.getStaticScope(); IRScope scope = staticScope.getIRScope(); // 1) method 2) root of script 3) lambda 3) closure (define_method) for zsuper if (scope instanceof IRMethod || scope instanceof IRScriptBody || (scope instanceof IRClosure && (dynScope.isLambda() || staticScope.isArgumentScope()))) return dynScope; } return null; }
@JRubyMethod public IRubyObject local_variables(ThreadContext context) { final Ruby runtime = context.runtime; HashSet<String> encounteredLocalVariables = new HashSet<>(); RubyArray allLocalVariables = runtime.newArray(); DynamicScope currentScope = binding.getEvalScope(context.runtime); while (currentScope != null) { for (String name : currentScope.getStaticScope().getVariables()) { if (IdUtil.isLocal(name) && !encounteredLocalVariables.contains(name)) { allLocalVariables.push(runtime.newSymbol(name)); encounteredLocalVariables.add(name); } } currentScope = currentScope.getParentScope(); } return allLocalVariables; }
@JRubyMethod public IRubyObject local_variables(ThreadContext context) { final Ruby runtime = context.runtime; HashSet<String> encounteredLocalVariables = new HashSet<>(); RubyArray allLocalVariables = runtime.newArray(); DynamicScope currentScope = binding.getEvalScope(context.runtime); while (currentScope != null) { for (String name : currentScope.getStaticScope().getVariables()) { if (IdUtil.isLocal(name) && !encounteredLocalVariables.contains(name)) { allLocalVariables.push(runtime.newSymbol(name)); encounteredLocalVariables.add(name); } } currentScope = currentScope.getParentScope(); } return allLocalVariables; }
private static DynamicScope getContainingMethodsDynamicScope(DynamicScope dynScope) { for (; dynScope != null; dynScope = dynScope.getParentScope()) { StaticScope scope = dynScope.getStaticScope(); IRScopeType scopeType = scope.getScopeType(); // We hit a method boundary (actual method or a define_method closure). if (scopeType.isMethodType() || scopeType.isBlock() && scope.isArgumentScope() || scopeType == IRScopeType.SCRIPT_BODY) return dynScope; } return null; }
private static DynamicScope getContainingMethodsDynamicScope(DynamicScope dynScope) { for (; dynScope != null; dynScope = dynScope.getParentScope()) { StaticScope scope = dynScope.getStaticScope(); IRScopeType scopeType = scope.getScopeType(); // We hit a method boundary (actual method or a define_method closure). if (scopeType.isMethodType() || scopeType.isBlock() && scope.isArgumentScope() || scopeType == IRScopeType.SCRIPT_BODY) return dynScope; } return null; }
/** * @param context * @param recv * @return an Array with the names of all local variables. */ @JRubyMethod(name = "local_variables", module = true, visibility = PRIVATE, reads = SCOPE) public static RubyArray local_variables(ThreadContext context, IRubyObject recv) { final Ruby runtime = context.runtime; Set<RubySymbol> encounteredLocalVariables = new HashSet<>(); RubyArray allLocalVariables = runtime.newArray(); DynamicScope currentScope = context.getCurrentScope(); while (currentScope != null) { for (String id: currentScope.getStaticScope().getVariables()) { RubySymbol name = runtime.newSymbol(id); if (name.validLocalVariableName() && !encounteredLocalVariables.contains(name)) { allLocalVariables.push(name); encounteredLocalVariables.add(name); } } currentScope = currentScope.getParentScope(); } return allLocalVariables; }
/** * @param context * @param recv * @return an Array with the names of all local variables. */ @JRubyMethod(name = "local_variables", module = true, visibility = PRIVATE, reads = SCOPE) public static RubyArray local_variables(ThreadContext context, IRubyObject recv) { final Ruby runtime = context.runtime; Set<RubySymbol> encounteredLocalVariables = new HashSet<>(); RubyArray allLocalVariables = runtime.newArray(); DynamicScope currentScope = context.getCurrentScope(); while (currentScope != null) { for (String id: currentScope.getStaticScope().getVariables()) { RubySymbol name = runtime.newSymbol(id); if (name.validLocalVariableName() && !encounteredLocalVariables.contains(name)) { allLocalVariables.push(name); encounteredLocalVariables.add(name); } } currentScope = currentScope.getParentScope(); } return allLocalVariables; }
public static IRubyObject initiateBreak(ThreadContext context, DynamicScope dynScope, IRubyObject breakValue, Block block) throws RuntimeException { // Wrap the return value in an exception object and push it through the break exception // paths so that ensures are run, frames/scopes are popped from runtime stacks, etc. if (inLambda(block.type)) throw new IRWrappedLambdaReturnValue(breakValue); IRScopeType scopeType = ensureScopeIsClosure(context, dynScope); DynamicScope parentScope = dynScope.getParentScope(); if (block.isEscaped()) { throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, breakValue, "unexpected break"); } // Raise a break jump so we can bubble back down the stack to the appropriate place to break from. throw IRBreakJump.create(parentScope, breakValue, scopeType.isEval()); // weirdly evals are impld as closures...yes yes. }
public static IRubyObject initiateBreak(ThreadContext context, DynamicScope dynScope, IRubyObject breakValue, Block block) throws RuntimeException { // Wrap the return value in an exception object and push it through the break exception // paths so that ensures are run, frames/scopes are popped from runtime stacks, etc. if (inLambda(block.type)) throw new IRWrappedLambdaReturnValue(breakValue); IRScopeType scopeType = ensureScopeIsClosure(context, dynScope); DynamicScope parentScope = dynScope.getParentScope(); if (block.isEscaped()) { throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, breakValue, "unexpected break"); } // Raise a break jump so we can bubble back down the stack to the appropriate place to break from. throw IRBreakJump.create(parentScope, breakValue, scopeType.isEval()); // weirdly evals are impld as closures...yes yes. }
case BINDING_EVAL : ds = ds.getParentScope(); break; case NONE: if (scopeType == null || scopeType.isClosureType()) { ds = ds.getParentScope(); } else if (inBindingEval) {
case BINDING_EVAL : ds = ds.getParentScope(); break; case NONE: if (scopeType == null || scopeType.isClosureType()) { ds = ds.getParentScope(); } else if (inBindingEval) {