@Override public RubyNode visitBlockArgNode(org.jruby.ast.BlockArgNode node) { final SourceSection sourceSection = translate(node.getPosition()); final RubyNode readNode = new ReadBlockNode(context, sourceSection, NilPlaceholder.INSTANCE); final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName()); return WriteLocalVariableNodeFactory.create(context, sourceSection, slot, readNode); }
private void blockArgNode(BlockArgNode node) { sb.append(" ").append(node.getName()); }
@JRubyMethod(name = "parameters", compat = CompatVersion.RUBY1_9) public IRubyObject parameters(ThreadContext context) { Ruby runtime = context.getRuntime(); RubyArray parms = RubyArray.newEmptyArray(runtime); ArgsNode args; if (!(this.getBlock().getBody() instanceof Interpreted19Block)) { return parms; } // argument names are easily accessible from interpreter RubyArray elem = RubyArray.newEmptyArray(runtime); args = ((Interpreted19Block) this.getBlock().getBody()).getArgs(); // required parameters List<Node> children = new ArrayList(); if (args.getPreCount() > 0) children.addAll(args.getPre().childNodes()); if (args.getPostCount() > 0) children.addAll(args.getPost().childNodes()); Iterator iter = children.iterator(); while (iter.hasNext()) { Node node = (Node) iter.next(); elem = RubyArray.newEmptyArray(runtime); elem.add(RubySymbol.newSymbol(runtime, this.isLambda() ? "req" : "opt")); if (node instanceof ArgumentNode) { elem.add(RubySymbol.newSymbol(runtime, ((ArgumentNode) node).getName())); } parms.add(elem); } // optional parameters if (args.getOptArgs() != null) { children = args.getOptArgs().childNodes(); if (!children.isEmpty()) { iter = children.iterator(); while (iter.hasNext()) { Node node = (Node) iter.next(); elem = RubyArray.newEmptyArray(runtime); elem.add(RubySymbol.newSymbol(runtime, "opt")); if (node instanceof OptArgNode) { elem.add(RubySymbol.newSymbol(runtime, ((OptArgNode) node).getName())); } parms.add(elem); } } } ArgumentNode rest = args.getRestArgNode(); if (rest != null) { elem = RubyArray.newEmptyArray(runtime); elem.add(RubySymbol.newSymbol(runtime, "rest")); elem.add(RubySymbol.newSymbol(runtime, rest.getName())); parms.add(elem); } BlockArgNode blockArg = args.getBlock(); if (blockArg != null) { elem = RubyArray.newEmptyArray(runtime); elem.add(RubySymbol.newSymbol(runtime, "block")); elem.add(RubySymbol.newSymbol(runtime, blockArg.getName())); parms.add(elem); } return parms; }