1 28 package org.jruby.parser; 29 30 import org.jruby.ast.AssignableNode; 31 import org.jruby.ast.DAsgnNode; 32 import org.jruby.ast.DVarNode; 33 import org.jruby.ast.Node; 34 import org.jruby.lexer.yacc.ISourcePosition; 35 36 public class BlockStaticScope extends StaticScope { 37 private static final long serialVersionUID = -3882063260379968149L; 38 39 public BlockStaticScope(StaticScope parentScope) { 40 super(parentScope); 41 } 42 43 public StaticScope getLocalScope() { 44 return getEnclosingScope().getLocalScope(); 45 } 46 47 public int isDefined(String name, int depth) { 48 int slot = exists(name); 49 if (slot >= 0) return (depth << 16) | exists(name); 50 51 return getEnclosingScope().isDefined(name, depth + 1); 52 } 53 54 57 public String [] getAllNamesInScope() { 58 String [] variables = getEnclosingScope().getAllNamesInScope(); 59 String [] ourVariables = getVariables(); 60 61 if (ourVariables == null) return variables; 63 64 int newSize = variables.length + ourVariables.length; 66 String [] names = new String [newSize]; 67 68 System.arraycopy(variables, 0, names, 0, variables.length); 69 System.arraycopy(ourVariables, 0, names, variables.length, ourVariables.length); 70 71 return names; 72 } 73 74 protected AssignableNode assign(ISourcePosition position, String name, Node value, 75 StaticScope topScope, int depth) { 76 int slot = exists(name); 77 78 if (slot >= 0) { 79 return new DAsgnNode(position, name, ((depth << 16) | slot), value); 80 } 81 82 return getEnclosingScope().assign(position, name, value, topScope, depth + 1); 83 } 84 85 public AssignableNode addAssign(ISourcePosition position, String name, Node value) { 86 int slot = addVariable(name); 87 88 return new DAsgnNode(position, name, slot, value); 90 } 91 92 public Node declare(ISourcePosition position, String name, int depth) { 93 int slot = exists(name); 94 95 if (slot >= 0) { 96 return new DVarNode(position, ((depth << 16) | slot), name); 97 } 98 99 return getEnclosingScope().declare(position, name, depth + 1); 100 } 101 } 102 | Popular Tags |