public void declareLocals(StaticScope scope, Label start, Label end) { // declare locals for Java debugging purposes String[] variables = scope.getVariables(); for (int i = 0; i < variables.length; i++) { method.local(baseVariableIndex + i, variables[i], IRubyObject.class); } }
public void declareLocals(StaticScope scope, Label start, Label end) { // declare locals for Java debugging purposes String[] variables = scope.getVariables(); for (int i = 0; i < variables.length; i++) { method.local(baseVariableIndex + i, variables[i], IRubyObject.class); } }
/** * Get all visible variables that we can see from this scope that have been assigned * (e.g. seen so far) * * @return a list of all names (sans $~ and $_ which are special names) */ public String[] getAllNamesInScope() { String[] names = getVariables(); if (isBlockOrEval) { String[] ourVariables = names; String[] variables = enclosingScope.getAllNamesInScope(); // we know variables cannot be null since this IRStaticScope always returns a non-null array names = new String[variables.length + ourVariables.length]; System.arraycopy(variables, 0, names, 0, variables.length); System.arraycopy(ourVariables, 0, names, variables.length, ourVariables.length); } return names; }
/** * Get all visible variables that we can see from this scope that have been assigned * (e.g. seen so far) * * @return a list of all names (sans $~ and $_ which are special names) */ public String[] getAllNamesInScope() { String[] names = getVariables(); if (isBlockOrEval) { String[] ourVariables = names; String[] variables = enclosingScope.getAllNamesInScope(); // we know variables cannot be null since this IRStaticScope always returns a non-null array names = new String[variables.length + ourVariables.length]; System.arraycopy(variables, 0, names, 0, variables.length); System.arraycopy(ourVariables, 0, names, variables.length, ourVariables.length); } return names; }
@SuppressWarnings("deprecation") static String encodeScope(StaticScope scope) { StringBuilder namesBuilder = new StringBuilder(scope.getType().name()); // 0 namesBuilder.append(','); // 1 boolean first = true; for (String name : scope.getVariables()) { if (!first) namesBuilder.append(';'); first = false; namesBuilder.append(name); } namesBuilder.append(',').append(scope.getSignature().encode()); // 2 namesBuilder.append(',').append(scope.getScopeType()); // 3 return namesBuilder.toString(); }
@SuppressWarnings("deprecation") static String encodeScope(StaticScope scope) { StringBuilder namesBuilder = new StringBuilder(scope.getType().name()); // 0 namesBuilder.append(','); // 1 boolean first = true; for (String name : scope.getVariables()) { if (!first) namesBuilder.append(';'); first = false; namesBuilder.append(name); } namesBuilder.append(',').append(scope.getSignature().encode()); // 2 namesBuilder.append(',').append(scope.getScopeType()); // 3 return namesBuilder.toString(); }
public static String encodeScope(StaticScope scope) { StringBuilder namesBuilder = new StringBuilder(scope.getType().name()); namesBuilder.append(','); boolean first = true; for (String name : scope.getVariables()) { if (!first) namesBuilder.append(';'); first = false; namesBuilder.append(name); } namesBuilder .append(',') .append(scope.getRequiredArgs()) .append(',') .append(scope.getOptionalArgs()) .append(',') .append(scope.getRestArg()); return namesBuilder.toString(); }
public static String encodeScope(StaticScope scope) { StringBuilder namesBuilder = new StringBuilder(scope.getType().name()); namesBuilder.append(','); boolean first = true; for (String name : scope.getVariables()) { if (!first) namesBuilder.append(';'); first = false; namesBuilder.append(name); } namesBuilder .append(',') .append(scope.getRequiredArgs()) .append(',') .append(scope.getOptionalArgs()) .append(',') .append(scope.getRestArg()); return namesBuilder.toString(); }
String names[] = staticScope.getVariables(); for (int i = 0; i < size-1; i++) { buf.append(names[i]).append("=");
String names[] = staticScope.getVariables(); for (int i = 0; i < size-1; i++) { buf.append(names[i]).append("=");
String names[] = staticScope.getVariables(); for (int i = 0; i < size-1; i++) { buf.append(names[i]).append("=");
private String getVarNameFromScopeTree(IRScope scope, int depth, int offset) { if (depth == 0) { return scope.getStaticScope().getVariables()[offset]; } return getVarNameFromScopeTree(scope.getLexicalParent(), depth - 1, offset); }
private String getVarNameFromScopeTree(IRScope scope, int depth, int offset) { if (depth == 0) { return scope.getStaticScope().getVariables()[offset]; } return getVarNameFromScopeTree(scope.getLexicalParent(), depth - 1, offset); }
@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; }
/** * @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; }
private static void persistStaticScope(IRWriterEncoder file, StaticScope staticScope) { file.encode(staticScope.getType()); file.encode(staticScope.getVariables()); file.encode(staticScope.getFirstKeywordIndex()); file.encode(staticScope.getSignature()); } }
private static void persistStaticScope(IRWriterEncoder file, StaticScope staticScope) { file.encode(staticScope.getType()); file.encode(staticScope.getVariables()); file.encode(staticScope.getFirstKeywordIndex()); file.encode(staticScope.getSignature()); } }
StaticScope newScope = getRuntime().getStaticScopeFactory().newBlockScope(oldScope.getEnclosingScope(), oldScope.getVariables()); newScope.setPreviousCRefScope(oldScope.getPreviousCRefScope()); newScope.setModule(oldScope.getModule());