1 28 package org.jruby.parser; 29 30 import org.jruby.ast.AssignableNode; 31 import org.jruby.ast.LocalAsgnNode; 32 import org.jruby.ast.LocalVarNode; 33 import org.jruby.ast.Node; 34 import org.jruby.ast.VCallNode; 35 import org.jruby.lexer.yacc.ISourcePosition; 36 37 public class LocalStaticScope extends StaticScope { 38 private static final long serialVersionUID = 2204064248888411628L; 39 40 public LocalStaticScope(StaticScope enclosingScope) { 41 super(enclosingScope); 42 43 addVariable("$~"); 44 addVariable("$_"); 45 } 46 47 public StaticScope getLocalScope() { 48 return this; 49 } 50 51 public int isDefined(String name, int depth) { 52 return (depth << 16) | exists(name); 53 } 54 55 58 public String [] getAllNamesInScope() { 59 String [] variables = getVariables(); 60 61 int localNamesSize = variables.length - 2; 65 66 String [] names = new String [localNamesSize]; 67 System.arraycopy(variables, 2, names, 0, localNamesSize); 68 69 return names; 70 } 71 72 public AssignableNode assign(ISourcePosition position, String name, Node value, 73 StaticScope topScope, int depth) { 74 int slot = exists(name); 75 76 if (slot >= 0) { 79 81 return new LocalAsgnNode(position, name, ((depth << 16) | slot), value); 82 } else if (topScope == this) { 83 slot = addVariable(name); 84 86 return new LocalAsgnNode(position, name, slot , value); 87 } 88 89 return ((BlockStaticScope) topScope).addAssign(position, name, value); 92 } 93 94 public Node declare(ISourcePosition position, String name, int depth) { 95 int slot = exists(name); 96 97 if (slot >= 0) { 98 return new LocalVarNode(position, ((depth << 16) | slot), name); 100 } 101 102 return new VCallNode(position, name); 103 } 104 105 } 106 | Popular Tags |