1 32 package org.jruby.ast; 33 34 import java.util.List ; 35 36 import org.jruby.ast.visitor.NodeVisitor; 37 import org.jruby.evaluator.Instruction; 38 import org.jruby.lexer.yacc.ISourcePosition; 39 import org.jruby.runtime.Arity; 40 41 59 public class ArgsNode extends Node { 60 static final long serialVersionUID = 3709437716296564785L; 61 62 private final ListNode arguments; 63 private final ListNode optArgs; 64 private final int restArg; 65 private final BlockArgNode blockArgNode; 66 private final Arity arity; 67 68 79 public ArgsNode(ISourcePosition position, ListNode arguments, ListNode optionalArguments, 80 int restArguments, BlockArgNode blockArgNode) { 81 super(position, NodeTypes.ARGSNODE); 82 83 this.arguments = arguments; 84 this.optArgs = optionalArguments; 85 this.restArg = restArguments; 86 this.blockArgNode = blockArgNode; 87 88 if (getRestArg() == -2) { 89 arity = Arity.optional(); 90 } else if (getOptArgs() != null || getRestArg() >= 0) { 91 arity = Arity.required(getArgsCount()); 92 } else { 93 arity = Arity.createArity(getArgsCount()); 94 } 95 } 96 97 101 public Instruction accept(NodeVisitor iVisitor) { 102 return iVisitor.visitArgsNode(this); 103 } 104 105 108 public ListNode getArgs() { 109 return arguments; 110 } 111 112 public Arity getArity() { 113 return arity; 114 } 115 116 public int getArgsCount() { 117 return arguments == null ? 0 : arguments.size(); 118 } 119 120 124 public ListNode getOptArgs() { 125 return optArgs; 126 } 127 128 132 public int getRestArg() { 133 return restArg; 134 } 135 136 140 public BlockArgNode getBlockArgNode() { 141 return blockArgNode; 142 } 143 144 public List childNodes() { 145 return Node.createList(arguments, optArgs, blockArgNode); 146 } 147 148 } 149 | Popular Tags |