1 31 package org.jruby.ast; 32 33 import java.util.List ; 34 35 import org.jruby.ast.visitor.NodeVisitor; 36 import org.jruby.evaluator.Instruction; 37 import org.jruby.internal.runtime.methods.EvaluateCallable; 38 import org.jruby.lexer.yacc.ISourcePosition; 39 import org.jruby.parser.StaticScope; 40 import org.jruby.runtime.ICallable; 41 import org.jruby.runtime.NilCallable; 42 43 47 public class IterNode extends Node { 48 static final long serialVersionUID = -9181965000180892184L; 49 50 private final Node varNode; 51 private final Node bodyNode; 52 53 private StaticScope scope; 55 56 private transient ICallable callable; 57 58 public IterNode(ISourcePosition position, Node varNode, StaticScope scope, Node bodyNode) { 59 this(position, varNode, scope, bodyNode, NodeTypes.ITERNODE); 60 } 61 62 public IterNode(ISourcePosition position, Node varNode, StaticScope scope, Node bodyNode, 63 int id) { 64 super(position, id); 65 this.varNode = varNode; 66 this.scope = scope; 67 this.bodyNode = bodyNode; 68 69 if (bodyNode == null && varNode == null) { 71 callable = NilCallable.NIL_CALLABLE; 72 } 73 } 74 75 79 public Instruction accept(NodeVisitor iVisitor) { 80 return iVisitor.visitIterNode(this); 81 } 82 83 public StaticScope getScope() { 84 return scope; 85 } 86 87 91 public Node getBodyNode() { 92 return bodyNode; 93 } 94 95 99 public Node getVarNode() { 100 return varNode; 101 } 102 103 public List childNodes() { 104 return Node.createList(varNode, bodyNode); 105 } 106 107 public ICallable getCallable() { 108 if (callable == null) { 109 callable = new EvaluateCallable(bodyNode, varNode); 110 } 111 112 return callable; 113 } 114 } 115 | Popular Tags |