rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
meta
stringlengths
141
403
ruby_cref = saved_cref;
ruby.setRubyCRef(saved_cref);
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyObject cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: // return rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: // return rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: RubyObject r = eval(self, node.nd_recv()); RubyObject l = eval(self, node.nd_value()); if (l instanceof RubyString) { // return rb_reg_match(r, l); } else { return l.funcall(ruby.intern("=~"), r); } return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyArray)obj).entry(i).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyObject eqq = ((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = getRubyFrame().getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; ruby.getRubyScope().push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalVars(vars); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.getRubyScope().pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyObject val = recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, rval); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, node.nd_value()); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().getRubyScope().setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby.getRubyClass().setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().getRubyScope().getLocalVars(node.nd_cnt()); case NODE_DVAR: return ruby.getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.getRubyScope().getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getClasses().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); SearchMethodResult smr = ruby.getRubyClass().searchMethod((RubyId)node.nd_mid()); NODE body = smr.getBody(); RubyObject origin = smr.getOrigin(); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby.getRubyClass() && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby.getRubyClass().addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (actMethodScope == SCOPE_MODFUNC) { ruby.getRubyClass().getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby.getRubyClass().funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby.getRubyClass().isSingleton()) { ruby.getRubyClass().getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to undef method"); } ruby.getRubyClass().undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to make alias"); } ruby.getRubyClass().aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self);
return getConstant((NODE)ruby.getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self);
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyObject cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: // return rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: // return rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: RubyObject r = eval(self, node.nd_recv()); RubyObject l = eval(self, node.nd_value()); if (l instanceof RubyString) { // return rb_reg_match(r, l); } else { return l.funcall(ruby.intern("=~"), r); } return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyArray)obj).entry(i).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyObject eqq = ((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = getRubyFrame().getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; ruby.getRubyScope().push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalVars(vars); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.getRubyScope().pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyObject val = recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, rval); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, node.nd_value()); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().getRubyScope().setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby.getRubyClass().setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().getRubyScope().getLocalVars(node.nd_cnt()); case NODE_DVAR: return ruby.getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.getRubyScope().getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getClasses().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); SearchMethodResult smr = ruby.getRubyClass().searchMethod((RubyId)node.nd_mid()); NODE body = smr.getBody(); RubyObject origin = smr.getOrigin(); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby.getRubyClass() && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby.getRubyClass().addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (actMethodScope == SCOPE_MODFUNC) { ruby.getRubyClass().getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby.getRubyClass().funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby.getRubyClass().isSingleton()) { ruby.getRubyClass().getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to undef method"); } ruby.getRubyClass().undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to make alias"); } ruby.getRubyClass().aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0));
if (ruby.getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + ruby.getRubyFrame().getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)ruby.getRubyFrame().getArgs().get(0));
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyObject cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: // return rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: // return rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: RubyObject r = eval(self, node.nd_recv()); RubyObject l = eval(self, node.nd_value()); if (l instanceof RubyString) { // return rb_reg_match(r, l); } else { return l.funcall(ruby.intern("=~"), r); } return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyArray)obj).entry(i).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyObject eqq = ((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = getRubyFrame().getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; ruby.getRubyScope().push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalVars(vars); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.getRubyScope().pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyObject val = recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, rval); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, node.nd_value()); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().getRubyScope().setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby.getRubyClass().setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().getRubyScope().getLocalVars(node.nd_cnt()); case NODE_DVAR: return ruby.getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.getRubyScope().getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getClasses().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); SearchMethodResult smr = ruby.getRubyClass().searchMethod((RubyId)node.nd_mid()); NODE body = smr.getBody(); RubyObject origin = smr.getOrigin(); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby.getRubyClass() && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby.getRubyClass().addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (actMethodScope == SCOPE_MODFUNC) { ruby.getRubyClass().getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby.getRubyClass().funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby.getRubyClass().isSingleton()) { ruby.getRubyClass().getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to undef method"); } ruby.getRubyClass().undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to make alias"); } ruby.getRubyClass().aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
NODE defn = node.nd_defn().copyNodeScope(ruby_cref);
NODE defn = node.nd_defn().copyNodeScope(ruby.getRubyCRef());
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyObject cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: // return rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: // return rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: RubyObject r = eval(self, node.nd_recv()); RubyObject l = eval(self, node.nd_value()); if (l instanceof RubyString) { // return rb_reg_match(r, l); } else { return l.funcall(ruby.intern("=~"), r); } return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyArray)obj).entry(i).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyObject eqq = ((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = getRubyFrame().getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; ruby.getRubyScope().push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalVars(vars); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.getRubyScope().pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyObject val = recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, rval); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, node.nd_value()); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().getRubyScope().setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby.getRubyClass().setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().getRubyScope().getLocalVars(node.nd_cnt()); case NODE_DVAR: return ruby.getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.getRubyScope().getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getClasses().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); SearchMethodResult smr = ruby.getRubyClass().searchMethod((RubyId)node.nd_mid()); NODE body = smr.getBody(); RubyObject origin = smr.getOrigin(); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby.getRubyClass() && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby.getRubyClass().addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (actMethodScope == SCOPE_MODFUNC) { ruby.getRubyClass().getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby.getRubyClass().funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby.getRubyClass().isSingleton()) { ruby.getRubyClass().getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to undef method"); } ruby.getRubyClass().undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to make alias"); } ruby.getRubyClass().aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) {
if (ruby.getSecurityLevel() >= 4 && !recv.isTaint()) {
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyObject cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: // return rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: // return rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: RubyObject r = eval(self, node.nd_recv()); RubyObject l = eval(self, node.nd_value()); if (l instanceof RubyString) { // return rb_reg_match(r, l); } else { return l.funcall(ruby.intern("=~"), r); } return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyArray)obj).entry(i).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyObject eqq = ((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = getRubyFrame().getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; ruby.getRubyScope().push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalVars(vars); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.getRubyScope().pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyObject val = recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, rval); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, node.nd_value()); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().getRubyScope().setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby.getRubyClass().setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().getRubyScope().getLocalVars(node.nd_cnt()); case NODE_DVAR: return ruby.getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.getRubyScope().getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getClasses().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); SearchMethodResult smr = ruby.getRubyClass().searchMethod((RubyId)node.nd_mid()); NODE body = smr.getBody(); RubyObject origin = smr.getOrigin(); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby.getRubyClass() && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby.getRubyClass().addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (actMethodScope == SCOPE_MODFUNC) { ruby.getRubyClass().getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby.getRubyClass().funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby.getRubyClass().isSingleton()) { ruby.getRubyClass().getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to undef method"); } ruby.getRubyClass().undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to make alias"); } ruby.getRubyClass().aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
if (getRuby().getSecurityLevel() >= 4) {
if (ruby.getSecurityLevel() >= 4) {
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyObject cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: // return rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: // return rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: RubyObject r = eval(self, node.nd_recv()); RubyObject l = eval(self, node.nd_value()); if (l instanceof RubyString) { // return rb_reg_match(r, l); } else { return l.funcall(ruby.intern("=~"), r); } return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyArray)obj).entry(i).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyObject eqq = ((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = getRubyFrame().getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; ruby.getRubyScope().push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalVars(vars); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.getRubyScope().pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyObject val = recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, rval); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, node.nd_value()); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().getRubyScope().setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby.getRubyClass().setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().getRubyScope().getLocalVars(node.nd_cnt()); case NODE_DVAR: return ruby.getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.getRubyScope().getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getClasses().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); SearchMethodResult smr = ruby.getRubyClass().searchMethod((RubyId)node.nd_mid()); NODE body = smr.getBody(); RubyObject origin = smr.getOrigin(); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby.getRubyClass() && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby.getRubyClass().addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (actMethodScope == SCOPE_MODFUNC) { ruby.getRubyClass().getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby.getRubyClass().funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby.getRubyClass().isSingleton()) { ruby.getRubyClass().getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to undef method"); } ruby.getRubyClass().undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to make alias"); } ruby.getRubyClass().aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref);
NODE defn = node.nd_defn().copyNodeScope(ruby.getRubyCRef()); defn.nd_rval(ruby.getRubyCRef());
public RubyObject eval(RubyObject self, NODE n) { NODE node = n; RubyObject cond = null; RubyObject[] args = null; RubyObject value = null; RubyObject result = null; RubyModule rubyClass = null; // int state; // RubyOriginalMethods rom = getRuby().getOriginalMethods(); while (true) { if (node == null) { return getRuby().getNil(); } switch (node.nd_type()) { case NODE_BLOCK: while (node.nd_next() != null) { eval(self, node.nd_head()); node = node.nd_next(); } node = node.nd_head(); break; case NODE_POSTEXE: // rb_f_END(); node.nd_set_type(NODE_NIL); /* exec just once */ return getRuby().getNil(); /* begin .. end without clauses */ case NODE_BEGIN: node = node.nd_body(); break; /* nodes for speed-up(default match) */ case NODE_MATCH: // return rb_reg_match2(node.nd_head().nd_lit()); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH2: // return rb_reg_match(eval(node.nd_recv()), eval(node.nd_value())); return getRuby().getNil(); /* nodes for speed-up(literal match) */ case NODE_MATCH3: RubyObject r = eval(self, node.nd_recv()); RubyObject l = eval(self, node.nd_value()); if (l instanceof RubyString) { // return rb_reg_match(r, l); } else { return l.funcall(ruby.intern("=~"), r); } return getRuby().getNil(); /* node for speed-up(top-level loop for -n/-p) */ case NODE_OPT_N: while (true) { try { // while (!rb_gets().isNil() false) { // HACK +++ if (true) { // HACK --- try { eval(self, node.nd_body()); } catch (RedoException rExcptn) { } } break; } catch (NextException nExcptn) { } catch (BreakException bExcptn) { break; } } return getRuby().getNil(); case NODE_SELF: return self; case NODE_NIL: return getRuby().getNil(); case NODE_TRUE: return getRuby().getTrue(); case NODE_FALSE: return getRuby().getFalse(); case NODE_IF: // ruby_sourceline = node.nd_line(); cond = eval(self, node.nd_cond()); if (cond.isTrue()) { node = node.nd_body(); } else { node = node.nd_else(); } break; case NODE_WHEN: while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); }*/ // ruby_sourcefile = tag.nd_file; // ruby_sourceline = tag.nd_line(); if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj = eval(self, tag.nd_head().nd_head()); if (!(obj instanceof RubyArray)) { obj = RubyArray.m_newArray(getRuby(), obj); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { if (((RubyArray)obj).entry(i).isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_CASE: RubyObject obj = eval(self, node.nd_head()); node = node.nd_body(); while (node != null) { NODE tag; if (node.nd_type() != NODE_WHEN) { break; } tag = node.nd_head(); while (tag != null) {/* if (trace_func) { call_trace_func("line", tag->nd_file, nd_line(tag), self, ruby_frame->last_func, ruby_frame->last_class); } ruby_sourcefile = tag->nd_file; ruby_sourceline = nd_line(tag);*/ if (tag.nd_head().nd_type() == NODE_WHEN) { RubyObject obj2 = eval(self, tag.nd_head().nd_head()); if (!(obj2 instanceof RubyArray)) { obj2 = RubyArray.m_newArray(getRuby(), obj2); } for (int i = 0; i < ((RubyArray)obj).length(); i++) { RubyObject eqq = ((RubyArray)obj2).entry(i).funcall(getRuby().intern("==="), obj); if (eqq.isTrue()) { node = node.nd_body(); break; } } tag = tag.nd_next(); continue; } if (eval(self, tag.nd_head()).funcall(getRuby().intern("==="), obj).isTrue()) { node = node.nd_body(); break; } tag = tag.nd_next(); } node = node.nd_next(); } return getRuby().getNil(); case NODE_WHILE: while (eval(self, node.nd_cond()).isTrue()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_UNTIL: while (eval(self, node.nd_cond()).isFalse()) { while (true) { try { eval(self, node.nd_body()); break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { break; } catch (BreakException bExcptn) { return getRuby().getNil(); } } } return getRuby().getNil(); case NODE_BLOCK_PASS: //return block_pass(node); return null; case NODE_ITER: case NODE_FOR: rubyBlock.push(node.nd_var(), node.nd_body(), self); rubyIter.push(Iter.ITER_PRE); while (true) { try { if (node.nd_type() == NODE_ITER) { result = eval(self, node.nd_iter()); } else { // String file = // int line = rubyBlock.flags &= ~RubyBlock.BLOCK_D_SCOPE; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_iter()); endCallArgs(tmpBlock); // = file; // = line; result = recv.getRubyClass().call(recv, ruby.intern("each"), null, 0); } break; } catch (RetryException rExcptn) { } catch (ReturnException rExcptn) { result = rExcptn.getReturnValue(); break; } catch (BreakException bExcptn) { result = ruby.getNil(); break; } } rubyIter.pop(); rubyBlock.pop(); return result; case NODE_BREAK: throw new BreakException(); case NODE_NEXT: throw new NextException(); case NODE_REDO: throw new RedoException(); case NODE_RETRY: throw new RetryException(); case NODE_RESTARGS: result = eval(self, node.nd_head()); if (!(result instanceof RubyArray)) { result = obj = RubyArray.m_newArray(getRuby(), result); } return result; case NODE_YIELD: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); if (node.nd_stts().nd_type() == NODE_RESTARGS && ((RubyArray)result).length() == 1) { result = ((RubyArray)result).entry(0); } } else { result = ruby.getNil(); } return yield0(result, null, null, false); case NODE_RESCUE:/* retry_entry: { volatile VALUE e_info = ruby_errinfo; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); } POP_TAG(); if (state == TAG_RAISE) { NODE * volatile resq = node->nd_resq; ruby_sourceline = nd_line(node); while (resq) { if (handle_rescue(self, resq)) { state = 0; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, resq->nd_body); } POP_TAG(); if (state == TAG_RETRY) { state = 0; ruby_errinfo = Qnil; goto retry_entry; } if (state != TAG_RAISE) { ruby_errinfo = e_info; } break; } resq = resq->nd_head; /* next rescue */ /** } * } * else if (node->nd_else) { /* else clause given *//* if (!state) { /* no exception raised *//* result = rb_eval(self, node->nd_else); } } if (state) JUMP_TAG(state); } break;*/ case NODE_ENSURE:/* PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = eval(node.nd_head()); } POP_TAG(); if (node.nd_ensr()) { VALUE retval = prot_tag->retval; /* save retval *//* VALUE errinfo = ruby_errinfo; rb_eval(self, node->nd_ensr); return_value(retval); ruby_errinfo = errinfo; } if (state) JUMP_TAG(state); break;*/ case NODE_AND: cond = eval(self, node.nd_1st()); if (cond.isFalse()) { return cond; } node = node.nd_2nd(); break; case NODE_OR: cond = eval(self, node.nd_1st()); if (cond.isTrue()) { return cond; } node = node.nd_2nd(); break; case NODE_NOT: return RubyBoolean.m_newBoolean(getRuby(), eval(self, node.nd_1st()).isFalse()); case NODE_DOT2: case NODE_DOT3: result = RubyRange.m_newRange(getRuby(), eval(self, node.nd_beg()), eval(self, node.nd_end()), node.nd_type() == NODE_DOT3); if (node.nd_state() != 0) { return result; } if (node.nd_beg().nd_type() == NODE_LIT && (node.nd_beg().nd_lit() instanceof RubyFixnum) && node.nd_end().nd_type() == NODE_LIT && (node.nd_end().nd_lit() instanceof RubyFixnum)) { node.nd_set_type(NODE_LIT); node.nd_lit(result); } else { node.nd_state(1L); } return result; case NODE_FLIP2: /* like AWK */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { if (eval(self, node.nd_beg()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), eval(self, node.nd_end()).isTrue() ? ruby.getFalse() : ruby.getTrue()); result = ruby.getTrue(); } else { result = ruby.getFalse(); } } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_FLIP3: /* like SED */ /*if (ruby_scope->local_vars == 0) { rb_bug("unexpected local variable"); }*/ if (ruby.getRubyScope().getLocalVars(node.nd_cnt()).isFalse()) { result = eval(self, node.nd_beg()).isTrue() ? ruby.getFalse() : ruby.getTrue(); ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); } else { if (eval(self, node.nd_end()).isTrue()) { ruby.getRubyScope().setLocalVars(node.nd_cnt(), ruby.getFalse()); } result = ruby.getTrue(); } return result; case NODE_RETURN: if (node.nd_stts() != null) { result = eval(self, node.nd_stts()); } else { result = ruby.getNil(); } throw new ReturnException(result); case NODE_ARGSCAT: return ((RubyArray)eval(self, node.nd_head())).m_concat(eval(self, node.nd_body())); case NODE_ARGSPUSH: return ((RubyArray)eval(self, node.nd_head()).m_dup()).push(eval(self, node.nd_body())); case NODE_CALL: // TMP_PROTECT; RubyBlock tmpBlock = beginCallargs(); RubyObject recv = eval(self, node.nd_recv()); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return recv.getRubyClass().call(recv, (RubyId)node.nd_mid(), args, 0); case NODE_FCALL: // TMP_PROTECT; tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); return self.getRubyClass().call(self, (RubyId)node.nd_mid(), args, 1); case NODE_VCALL: return self.getRubyClass().call(self, (RubyId)node.nd_mid(), null, 2); case NODE_SUPER: case NODE_ZSUPER: // TMP_PROTECT; if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled"); } if (node.nd_type() == NODE_ZSUPER) { List argsList = getRubyFrame().getArgs(); args = (RubyObject[])argsList.toArray(new RubyObject[argsList.size()]); } else { tmpBlock = beginCallargs(); args = setupArgs(self, node.nd_args()); endCallArgs(tmpBlock); } rubyIter.push(rubyIter.getIter() != Iter.ITER_NOT ? Iter.ITER_PRE : Iter.ITER_NOT); result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3); rubyIter.pop(); return result; case NODE_SCOPE: NODE saved_cref = null; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; ruby.getRubyScope().push(); if (node.nd_rval() != null) { saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval()); } if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalVars(vars); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } result = eval(self, node.nd_next()); ruby.getRubyScope().pop(); rubyFrame = frame.getTmp(); if (saved_cref != null) { ruby_cref = saved_cref; } return result; case NODE_OP_ASGN1: // TMP_PROTECT; recv = eval(self, node.nd_recv()); NODE rval = node.nd_args().nd_head(); args = setupArgs(self, node.nd_args().nd_next()); ArrayList argsList = new ArrayList(Arrays.asList(args)); argsList.remove(args.length - 1); RubyObject val = recv.funcall(getRuby().intern("[]"), (RubyObject[])argsList.toArray(new RubyObject[argsList.size()])); switch (node.nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, rval); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, rval); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, rval)); } args[args.length - 1] = val; return recv.funcall(getRuby().intern("[]="), args); case NODE_OP_ASGN2: ID id = node.nd_next().nd_vid(); recv = eval(self, node.nd_recv()); val = recv.funcall((RubyId)id, (RubyObject[])null); switch (node.nd_next().nd_mid().intValue()) { case 0: /* OR */ if (val.isTrue()) { return val; } val = eval(self, node.nd_value()); break; case 1: /* AND */ if (val.isFalse()) { return val; } val = eval(self, node.nd_value()); break; default: val = val.funcall((RubyId)node.nd_mid(), eval(self, node.nd_value())); } // HACK +++ val = recv.funcall((RubyId)node.nd_next().nd_aid(), val); // HACK --- return val; case NODE_OP_ASGN_AND: cond = eval(self, node.nd_head()); if (cond.isFalse()) { return cond; } node = node.nd_value(); break; case NODE_OP_ASGN_OR: cond = eval(self, node.nd_head()); if ((node.nd_aid() != null && !self.isInstanceVarDefined((RubyId)node.nd_aid())) || cond.isFalse()) { node = node.nd_value(); break; } return cond; case NODE_MASGN: return massign(self, node, eval(self, node.nd_value()), false); case NODE_LASGN: // if (ruby.ruby_scope.local_vars == null) { // rb_bug("unexpected local variable assignment"); // } result = eval(self, node.nd_value()); getRuby().getRubyScope().setLocalVars(node.nd_cnt(), result); return result; case NODE_DASGN: result = eval(self, node.nd_value()); RubyVarmap.assign(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_DASGN_CURR: result = eval(self, node.nd_value()); RubyVarmap.assignCurrent(ruby, (RubyId)node.nd_vid(), result); return result; case NODE_GASGN: result = eval(self, node.nd_value()); ((RubyGlobalEntry)node.nd_entry()).set(result); return result; case NODE_IASGN: result = eval(self, node.nd_value()); self.setInstanceVar((RubyId)node.nd_vid(), result); return result; case NODE_CDECL: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class/module to define constant"); } result = eval(self, node.nd_value()); ruby.getRubyClass().setConstant((RubyId)node.nd_vid(), result); return result; case NODE_CVDECL: if (ruby_cbase == null) { throw new RubyTypeException("no class/module to define class variable"); } result = eval(self, node.nd_value()); if (ruby_cbase.isSingleton()) { ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().declareClassVar((RubyId)node.nd_vid(), result); return result; } ruby_cbase.declareClassVar((RubyId)node.nd_vid(), result); return result; case NODE_CVASGN: result = eval(self, node.nd_value()); self.getClassVarSingleton().setClassVar((RubyId)node.nd_vid(), result); return result; case NODE_LVAR: //if (getRuby().ruby_scope.local_vars == null) { // rb_bug("unexpected local variable"); // } return (RubyObject)getRuby().getRubyScope().getLocalVars(node.nd_cnt()); case NODE_DVAR: return ruby.getDynamicVars().getRef((RubyId)node.nd_vid()); case NODE_GVAR: return ((RubyGlobalEntry)node.nd_entry()).get(); case NODE_IVAR: return self.getInstanceVar((RubyId)node.nd_vid()); case NODE_CONST: return getConstant((NODE)getRubyFrame().getCbase(), (RubyId)node.nd_vid(), self); case NODE_CVAR: /* normal method */ if (ruby_cbase == null) { return self.getRubyClass().getClassVar((RubyId)node.nd_vid()); } if (!ruby_cbase.isSingleton()) { return ruby_cbase.getClassVar((RubyId)node.nd_vid()); } return ruby_cbase.getInstanceVar("__attached__").getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_CVAR2: /* singleton method */ return self.getClassVarSingleton().getClassVar((RubyId)node.nd_vid()); case NODE_BLOCK_ARG: if (ruby.getRubyScope().getLocalVars() == null) { throw new RuntimeException("BUG: unexpected block argument"); } if (isBlockGiven()) { result = getRuby().getNil(); // Create Proc object ruby.getRubyScope().setLocalVars(node.nd_cnt(), result); return result; } else { return getRuby().getNil(); } case NODE_COLON2: value = eval(self, node.nd_head()); if (value instanceof RubyModule) { return ((RubyModule)value).getConstant((RubyId)node.nd_mid()); } else { return value.funcall((RubyId)node.nd_mid()); } case NODE_COLON3: return getRuby().getClasses().getObjectClass().getConstant((RubyId)node.nd_mid()); case NODE_NTH_REF: // return rom.rb_reg_nth_match(node.nd_nth(), MATCH_DATA); return null; case NODE_BACK_REF: /*switch ((char)node.nd_nth()) { case '&': return rom.rb_reg_last_match(MATCH_DATA); case '`': return rom.rb_reg_match_pre(MATCH_DATA); case '\'': return rom.rb_reg_match_post(MATCH_DATA); case '+': return rom.rb_reg_match_last(MATCH_DATA); default: rom.rb_bug("unexpected back-ref"); }*/ case NODE_HASH: RubyHash hash = RubyHash.m_newHash(ruby); NODE list = node.nd_head(); while(list != null) { RubyObject key = eval(self, list.nd_head()); list = list.nd_next(); if (list == null) { // HACK +++ throw new RubyArgumentException("odd number list for Hash"); // HACK --- } value = eval(self, list.nd_head()); hash.m_aset(key, value); list = list.nd_next(); } return hash; case NODE_ZARRAY: /* zero length list */ return RubyArray.m_newArray(getRuby()); case NODE_ARRAY: ArrayList ary = new ArrayList(node.nd_alen()); for (; node != null ; node = node.nd_next()) { ary.add(eval(self, node.nd_head())); } return RubyArray.m_newArray(getRuby(), ary); case NODE_STR: return ((RubyObject)node.nd_lit()).m_to_s(); case NODE_DSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_DREGX_ONCE:/* NODE list = node.nd_next(); RubyString str = RubyString.m_newString(getRuby(), (RubyObject)node.nd_lit()); RubyString str2; while (list != null) { if (list.nd_head() != null) { switch (list.nd_head().nd_type()) { case NODE_STR: str2 = (RubyString)list.nd_head().nd_lit(); break; case NODE_EVSTR: result = ruby_errinfo; ruby_errinfo = Qnil; ruby_sourceline = nd_line(node); ruby_in_eval++; list.nd_head(compile(list.nd_head().nd_lit(), ruby_sourcefile,ruby_sourceline)); ruby_eval_tree = 0; ruby_in_eval--; if (ruby_nerrs > 0) { compile_error("string expansion"); } if (!NIL_P(result)) ruby_errinfo = result; /* fall through *//* default: str2 = (RubyString)rom.rb_obj_as_string(eval(list.nd_head())); break; } str.append(str2); str.infectObject(str2); } list = list.nd_next(); } switch (node.nd_type()) { case NODE_DREGX: return rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); case NODE_DREGX_ONCE: /* regexp expand once *//* VALUE result = rom.rb_reg_new(str.getString(), str.getString().length(), node.nd_cflag()); node.nd_set_type(NODE_LIT); node.nd_lit(result); return result; case NODE_DXSTR: return rom.rb_funcall(this, '`', 1, str); default: return str; }*/ return null; case NODE_XSTR: return self.funcall(getRuby().intern("`"), (RubyObject)node.nd_lit()); case NODE_LIT: return (RubyObject)node.nd_lit(); case NODE_ATTRSET: if (getRubyFrame().getArgs().size() != 1) { throw new RubyArgumentException("wrong # of arguments(" + rubyFrame.getArgs().size() + "for 1)"); } return self.setInstanceVar((RubyId)node.nd_vid(), (RubyObject)rubyFrame.getArgs().get(0)); case NODE_DEFN: if (node.nd_defn() != null) { int noex; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to add method"); } //if (ruby_class == getRuby().getObjectClass() && node.nd_mid() == init) { // rom.rb_warn("redefining Object#initialize may cause infinite loop"); //} //if (node.nd_mid() == __id__ || node.nd_mid() == __send__) { // rom.rb_warn("redefining `%s' may cause serious problem", ((RubyId)node.nd_mid()).toName()); //} // ruby_class.setFrozen(true); SearchMethodResult smr = ruby.getRubyClass().searchMethod((RubyId)node.nd_mid()); NODE body = smr.getBody(); RubyObject origin = smr.getOrigin(); if (body != null){ // if (ruby_verbose.isTrue() && ruby_class == origin && body.nd_cnt() == 0) { // rom.rb_warning("discarding old %s", ((RubyId)node.nd_mid()).toName()); // } // if (node.nd_noex() != 0) { /* toplevel */ /* should upgrade to rb_warn() if no super was called inside? */ // rom.rb_warning("overriding global function `%s'", ((RubyId)node.nd_mid()).toName()); // } } if (isScope(SCOPE_PRIVATE) || node.nd_mid().equals(ruby.intern("initialize"))) { noex = NOEX_PRIVATE; } else if (isScope(SCOPE_PROTECTED)) { noex = NOEX_PROTECTED; } else if (ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) { noex = node.nd_noex(); } else { noex = NOEX_PUBLIC; } if (body != null && origin == ruby.getRubyClass() && (body.nd_noex() & NOEX_UNDEF) != 0) { noex |= NOEX_UNDEF; } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); ruby.getRubyClass().addMethod((RubyId)node.nd_mid(), defn, noex); // rb_clear_cache_by_id(node.nd_mid()); if (actMethodScope == SCOPE_MODFUNC) { ruby.getRubyClass().getSingletonClass().addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC); ruby.getRubyClass().funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } if (ruby.getRubyClass().isSingleton()) { ruby.getRubyClass().getInstanceVar("__attached__").funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } else { ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); } } return getRuby().getNil(); case NODE_DEFS: if (node.nd_defn() != null) { recv = eval(self, node.nd_recv()); if (getRuby().getSecurityLevel() >= 4 && !recv.isTaint()) { throw new RubySecurityException("Insecure; can't define singleton method"); } /*if (FIXNUM_P(recv) || SYMBOL_P(recv)) { rb_raise(rb_eTypeError, "can't define singleton method \"%s\" for %s", rb_id2name(node.nd_mid()), rb_class2name(CLASS_OF(recv))); }*/ // not needed in jruby if (recv.isFrozen()) { throw new RubyFrozenException("object"); } rubyClass = recv.getSingletonClass(); NODE body = (NODE)rubyClass.getMethods().get((RubyId)node.nd_mid()); if (body != null) { if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("redefining method prohibited"); } /*if (RTEST(ruby_verbose)) { rb_warning("redefine %s", rb_id2name(node.nd_mid())); }*/ } NODE defn = node.nd_defn().copyNodeScope(ruby_cref); defn.nd_rval(ruby_cref); rubyClass.addMethod((RubyId)node.nd_mid(), defn, NOEX_PUBLIC | (body != null ? body.nd_noex() & NOEX_UNDEF : 0)); // rb_clear_cache_by_id(node.nd_mid()); recv.funcall(getRuby().intern("singleton_method_added"), ((RubyId)node.nd_mid()).toSymbol()); } return getRuby().getNil(); case NODE_UNDEF: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to undef method"); } ruby.getRubyClass().undef((RubyId)node.nd_mid()); return getRuby().getNil(); case NODE_ALIAS: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no class to make alias"); } ruby.getRubyClass().aliasMethod((RubyId)node.nd_new(), (RubyId)node.nd_old()); ruby.getRubyClass().funcall(getRuby().intern("method_added"), ((RubyId)node.nd_mid()).toSymbol()); return getRuby().getNil(); case NODE_VALIAS: RubyGlobalEntry.getGlobalEntry((RubyId)node.nd_old()).alias((RubyId)node.nd_new()); return getRuby().getNil(); case NODE_CLASS: RubyModule superClass; if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } if (node.nd_super() != null) { superClass = getSuperClass(self, node.nd_super()); } else { superClass = null; } rubyClass = null; // if ((ruby_class == getRuby().getObjectClass()) && rb_autoload_defined(node.nd_cname())) { // rb_autoload_load(node.nd_cname()); // } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { rubyClass = (RubyClass)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (rubyClass != null) { if (!rubyClass.isClass()) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a class"); } if (superClass != null) { RubyModule tmp = rubyClass.getSuperClass(); if (tmp.isSingleton()) { tmp = tmp.getSuperClass(); } while (tmp.isIncluded()) { tmp = tmp.getSuperClass(); } if (tmp != superClass) { superClass = tmp; //goto override_class; if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); // end goto } } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending class prohibited"); } // rb_clear_cache(); } else { //override_class: if (superClass == null) { superClass = getRuby().getClasses().getObjectClass(); } rubyClass = getRuby().defineClassId((RubyId)node.nd_cname(), (RubyClass)superClass); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), rubyClass); rubyClass.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_MODULE: if (ruby.getRubyClass() == null) { throw new RubyTypeException("no outer class/module"); } RubyModule module = null; if ((ruby.getRubyClass() == getRuby().getClasses().getObjectClass()) && getRuby().isAutoloadDefined((RubyId)node.nd_cname())) { // getRuby().rb_autoload_load(node.nd_cname()); } if (ruby.getRubyClass().isConstantDefined((RubyId)node.nd_cname())) { module = (RubyModule)ruby.getRubyClass().getConstant((RubyId)node.nd_cname()); } if (module != null) { if (!(module instanceof RubyModule)) { throw new RubyTypeException(((RubyId)node.nd_cname()).toName() + " is not a module"); } if (getRuby().getSecurityLevel() >= 4) { throw new RubySecurityException("extending module prohibited"); } } else { module = getRuby().defineModuleId((RubyId)node.nd_cname()); ruby.getRubyClass().setConstant((RubyId)node.nd_cname(), module); module.setClassPath(ruby.getRubyClass(), ((RubyId)node.nd_cname()).toName()); } if (ruby_wrapper != null) { module.getSingletonClass().includeModule(ruby_wrapper); module.includeModule(ruby_wrapper); } return setupModule(module, node.nd_body()); case NODE_SCLASS: rubyClass = (RubyClass)eval(self, node.nd_recv()); if (rubyClass.isSpecialConst()) { throw new RubyTypeException("no virtual class for " + rubyClass.getRubyClass().toName()); } if (getRuby().getSecurityLevel() >= 4 && !rubyClass.isTaint()) { throw new RubySecurityException("Insecure: can't extend object"); } if (rubyClass.getRubyClass().isSingleton()) { // rb_clear_cache(); } rubyClass = rubyClass.getSingletonClass(); if (ruby_wrapper != null) { rubyClass.getSingletonClass().includeModule(ruby_wrapper); rubyClass.includeModule(ruby_wrapper); } return setupModule(rubyClass, node.nd_body()); case NODE_DEFINED: // String buf; // String desc = is_defined(self, node.nd_head(), buf); // // if (desc) { // result = rb_str_new2(desc); // } else { // result = Qnil; // } case NODE_NEWLINE: // ruby_sourcefile = node.nd_file; // ruby_sourceline = node.nd_nth(); // if (trace_func) { // call_trace_func("line", ruby_sourcefile, ruby_sourceline, self, // ruby_frame.last_func(), // ruby_frame.last_class()); // } node = node.nd_next(); break; default: // rom.rb_bug("unknown node type %d", nd_type(node)); } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
public org.jruby.Ruby getRuby() {
public Ruby getRuby() {
public org.jruby.Ruby getRuby() { return ruby; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
public org.jruby.interpreter.RubyBlock getRubyBlock() {
public RubyBlock getRubyBlock() {
public org.jruby.interpreter.RubyBlock getRubyBlock() { return rubyBlock; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
return getRubyFrame().getIter() != Iter.ITER_NOT;
return ruby.getRubyFrame().getIter() != Iter.ITER_NOT;
public boolean isBlockGiven() { return getRubyFrame().getIter() != Iter.ITER_NOT; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
return (getRubyFrame().getPrev() != null) && (getRubyFrame().getPrev().getIter() != Iter.ITER_NOT);
return (ruby.getRubyFrame().getPrev() != null) && (ruby.getRubyFrame().getPrev().getIter() != Iter.ITER_NOT);
public boolean isFBlockGiven() { return (getRubyFrame().getPrev() != null) && (getRubyFrame().getPrev().getIter() != Iter.ITER_NOT); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
public void setRuby(org.jruby.Ruby ruby) {
public void setRuby(Ruby ruby) {
public void setRuby(org.jruby.Ruby ruby) { this.ruby = ruby; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
public void setRubyBlock(org.jruby.interpreter.RubyBlock rubyBlock) {
public void setRubyBlock(RubyBlock rubyBlock) {
public void setRubyBlock(org.jruby.interpreter.RubyBlock rubyBlock) { this.rubyBlock = rubyBlock; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame;
RubyFrame frame = ruby.getRubyFrame(); frame.setTmp(ruby.getRubyFrame()); ruby.setRubyFrame(frame);
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; pushClass(); ruby.setRubyClass(module); getRuby().getRubyScope().push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } PUSH_CREF(module); getRubyFrame().setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby.getRubyClass(), node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().getRubyScope().pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
getRuby().getRubyScope().push();
ruby.getRubyScope().push();
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; pushClass(); ruby.setRubyClass(module); getRuby().getRubyScope().push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } PUSH_CREF(module); getRubyFrame().setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby.getRubyClass(), node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().getRubyScope().pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
getRuby().getRubyScope().setLocalTbl(node.nd_tbl());
ruby.getRubyScope().setLocalTbl(node.nd_tbl());
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; pushClass(); ruby.setRubyClass(module); getRuby().getRubyScope().push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } PUSH_CREF(module); getRubyFrame().setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby.getRubyClass(), node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().getRubyScope().pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null);
ruby.getRubyScope().setLocalVars(null); ruby.getRubyScope().setLocalTbl(null);
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; pushClass(); ruby.setRubyClass(module); getRuby().getRubyScope().push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } PUSH_CREF(module); getRubyFrame().setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby.getRubyClass(), node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().getRubyScope().pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
getRubyFrame().setCbase((VALUE)ruby_cref);
ruby.getRubyFrame().setCbase(ruby.getRubyCRef());
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; pushClass(); ruby.setRubyClass(module); getRuby().getRubyScope().push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } PUSH_CREF(module); getRubyFrame().setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby.getRubyClass(), node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().getRubyScope().pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
getRuby().getRubyScope().pop();
ruby.getRubyScope().pop();
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; pushClass(); ruby.setRubyClass(module); getRuby().getRubyScope().push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } PUSH_CREF(module); getRubyFrame().setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby.getRubyClass(), node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().getRubyScope().pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
rubyFrame = frame.getTmp();
ruby.setRubyFrame(frame.getTmp());
public RubyObject setupModule(RubyModule module, NODE n) { NODE node = n; // String file = ruby_sourcefile; // int line = ruby_sourceline; // TMP_PROTECT; Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame; pushClass(); ruby.setRubyClass(module); getRuby().getRubyScope().push(); RubyVarmap.push(ruby); if (node.nd_tbl() != null) { List tmp = Collections.nCopies(node.nd_tbl()[0].intValue() + 1, ruby.getNil()); ShiftableList vars = new ShiftableList(new ArrayList(tmp)); vars.set(0, (VALUE)node); vars.shift(1); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null); } PUSH_CREF(module); getRubyFrame().setCbase((VALUE)ruby_cref); // PUSH_TAG(PROT_NONE); RubyObject result = null; // if (( state = EXEC_TAG()) == 0 ) { // if (trace_func) { // call_trace_func("class", file, line, ruby_class, // ruby_frame->last_func, ruby_frame->last_class ); // } result = eval(ruby.getRubyClass(), node.nd_next()); // } // POP_TAG(); POP_CREF(); RubyVarmap.pop(ruby); getRuby().getRubyScope().pop(); popClass(); rubyFrame = frame.getTmp();// if (trace_func) {// call_trace_func("end", file, line, 0, ruby_frame->last_func, ruby_frame->last_class );// } // if (state != 0) { // JUMP_TAG(state); // } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
Frame frame = block.frame; frame.setPrev(getRubyFrame()); rubyFrame = frame;
RubyFrame frame = block.frame; frame.setPrev(ruby.getRubyFrame()); ruby.setRubyFrame(frame);
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(getRubyFrame()); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)getRubyFrame().getCbase(); RubyScope oldScope = ruby.getRubyScope(); ruby.setRubyScope(block.scope); rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { ruby.setDynamicVars(new RubyVarmap(null, null, block.dynamicVars)); } else { ruby.setDynamicVars(block.dynamicVars); } ruby.setRubyClass((klass != null) ? klass : block.klass); if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = getRubyFrame().getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.setRubyScope(oldScope); /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
VALUE old_cref = ruby_cref; ruby_cref = (NODE)getRubyFrame().getCbase();
NODE oldCRef = ruby.getRubyCRef(); ruby.setRubyCRef((NODE)ruby.getRubyFrame().getCbase());
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(getRubyFrame()); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)getRubyFrame().getCbase(); RubyScope oldScope = ruby.getRubyScope(); ruby.setRubyScope(block.scope); rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { ruby.setDynamicVars(new RubyVarmap(null, null, block.dynamicVars)); } else { ruby.setDynamicVars(block.dynamicVars); } ruby.setRubyClass((klass != null) ? klass : block.klass); if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = getRubyFrame().getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.setRubyScope(oldScope); /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
rubyFrame = getRubyFrame().getPrev();
ruby.setRubyFrame(ruby.getRubyFrame().getPrev());
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(getRubyFrame()); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)getRubyFrame().getCbase(); RubyScope oldScope = ruby.getRubyScope(); ruby.setRubyScope(block.scope); rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { ruby.setDynamicVars(new RubyVarmap(null, null, block.dynamicVars)); } else { ruby.setDynamicVars(block.dynamicVars); } ruby.setRubyClass((klass != null) ? klass : block.klass); if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = getRubyFrame().getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.setRubyScope(oldScope); /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
ruby_cref = (NODE)old_cref;
ruby.setRubyCRef(oldCRef);
public RubyObject yield0(RubyObject value, RubyObject self, RubyModule klass, boolean acheck) { RubyObject result = ruby.getNil(); if (!(isBlockGiven() || isFBlockGiven()) || (rubyBlock == null)) { throw new RuntimeException("yield called out of block"); } RubyVarmap.push(ruby); pushClass(); RubyBlock block = rubyBlock.getTmp(); Frame frame = block.frame; frame.setPrev(getRubyFrame()); rubyFrame = frame; VALUE old_cref = ruby_cref; ruby_cref = (NODE)getRubyFrame().getCbase(); RubyScope oldScope = ruby.getRubyScope(); ruby.setRubyScope(block.scope); rubyBlock.pop(); if ((block.flags & RubyBlock.BLOCK_D_SCOPE) != 0) { ruby.setDynamicVars(new RubyVarmap(null, null, block.dynamicVars)); } else { ruby.setDynamicVars(block.dynamicVars); } ruby.setRubyClass((klass != null) ? klass : block.klass); if (klass == null) { self = (RubyObject)block.self; } NODE node = block.body; if (block.var != null) { // try { if (block.var == NODE.ONE) { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() != 0) { throw new RubyArgumentException("wrong # of arguments ("+ ((RubyArray)value).length() + " for 0)"); } } else { if (block.var.nd_type() == NODE_MASGN) { massign(self, block.var, value, acheck); } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } assign(self, block.var, value, acheck); } } // } catch () { // goto pop_state; // } } else { if (acheck && value != null && value instanceof RubyArray && ((RubyArray)value).length() == 1) { value = ((RubyArray)value).entry(0); } } rubyIter.push(block.iter); while (true) { try { if (node == null) { result = ruby.getNil(); } else if (node.nd_type() == NODE_CFUNC || node.nd_type() == NODE_IFUNC) { if (value == null) { value = RubyArray.m_newArray(ruby, 0); } result = ((RubyCallbackMethod)node.nd_cfnc()).execute(value, new RubyObject[] {(RubyObject)node.nd_tval(), self}, ruby); } else { result = eval(self, node); } break; } catch (RedoException rExcptn) { } catch (NextException nExcptn) { result = ruby.getNil(); break; } catch (BreakException bExcptn) { break; } catch (ReturnException rExcptn) { break; } } // pop_state: rubyIter.pop(); popClass(); RubyVarmap.pop(ruby); rubyBlock.setTmp(block); rubyFrame = getRubyFrame().getPrev(); ruby_cref = (NODE)old_cref; // if (ruby_scope->flag & SCOPE_DONT_RECYCLE) // scope_dup(old_scope); ruby.setRubyScope(oldScope); /* * if (state) { * if (!block->tag) { * switch (state & TAG_MASK) { * case TAG_BREAK: * case TAG_RETURN: * jump_tag_but_local_jump(state & TAG_MASK); * break; * } * } * JUMP_TAG(state); * } */ return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
public NODE(int type, Object u1, Object u2, Object u3) { nd_set_type(type); this.u1 = u1; this.u2 = u2; this.u3 = u3; }
private NODE() {}
public NODE(int type, Object u1, Object u2, Object u3) { nd_set_type(type); this.u1 = u1; this.u2 = u2; this.u3 = u3; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
public RubyArray push(RubyObject value) {
public RubyArray push(RubyObject[] items) { int length = items.length; if (length == 0) { throw new ArgumentError(getRuby(), "wrong # of arguments(at least 1)"); }
public RubyArray push(RubyObject value) { modify(); list.add(value); infectObject(value); return this; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/0335f0acaf11ca0feb41907f65e7274f8ed49fc3/RubyArray.java/buggy/org/jruby/RubyArray.java
list.add(value); infectObject(value);
boolean taint = false; for (int i = 0; i < length; i++) { taint |= items[i].isTaint(); list.add(items[i]); } setTaint(isTaint() || taint);
public RubyArray push(RubyObject value) { modify(); list.add(value); infectObject(value); return this; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/0335f0acaf11ca0feb41907f65e7274f8ed49fc3/RubyArray.java/buggy/org/jruby/RubyArray.java
vmode = ruby.getInterpreter().getScope_vmode();
vmode = ruby.getInterpreter().getActMethodScope();
public void push(NODE v, NODE b, RubyObject newSelf) { RubyBlock oldBlock = new RubyBlock(var, body, self, frame, scope, klass, iter, vmode, flags, dynamicVars, origThread, prev, ruby); var = v; body = b; self = newSelf; frame = ruby.getInterpreter().getRubyFrame(); klass = ruby.getInterpreter().getRuby_class(); // _block.frame.file = ruby_sourcefile; // _block.frame.line = ruby_sourceline; scope = ruby.rubyScope; prev = oldBlock; iter = ruby.getInterpreter().getRubyIter().getIter(); vmode = ruby.getInterpreter().getScope_vmode(); flags = BLOCK_D_SCOPE; dynamicVars = ruby.getInterpreter().getDynamicVars(); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/658d41dfe4d2bc92a7ecefae9ca04e116d2c290b/RubyBlock.java/buggy/org/jruby/interpreter/RubyBlock.java
public RubyNameException(String msg) { super(msg);
public RubyNameException() {
public RubyNameException(String msg) { super(msg); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/RubyNameException.java/buggy/org/jruby/exceptions/RubyNameException.java
public RubyTypeException(String msg) { super(msg);
public RubyTypeException() {
public RubyTypeException(String msg) { super(msg); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/RubyTypeException.java/buggy/org/jruby/exceptions/RubyTypeException.java
public RubyArgumentException(String msg) { super(msg);
public RubyArgumentException() {
public RubyArgumentException(String msg) { super(msg); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/RubyArgumentException.java/buggy/org/jruby/exceptions/RubyArgumentException.java
public RubySecurityException(String msg) { super(msg);
public RubySecurityException() {
public RubySecurityException(String msg) { super(msg); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/RubySecurityException.java/buggy/org/jruby/exceptions/RubySecurityException.java
public RubyFrozenException(String msg) { super(msg);
public RubyFrozenException() {
public RubyFrozenException(String msg) { super(msg); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/RubyFrozenException.java/buggy/org/jruby/exceptions/RubyFrozenException.java
if (oldMap.get(ruby) != null) { throw new RuntimeException("JRuby - BUG: Need Queue for oldMap in RubyVarmap");
if (oldMap.get(ruby) == null) { oldMap.put(ruby, new RubyStack());
public static void push(Ruby ruby) { // HACK +++ if (oldMap.get(ruby) != null) { throw new RuntimeException("JRuby - BUG: Need Queue for oldMap in RubyVarmap"); } // HACK --- oldMap.put(ruby, ruby.getInterpreter().getDynamicVars()); ruby.getInterpreter().setDynamicVars(null); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/76d3fd1bbcdbd38082a9b8c19c593b06ed915280/RubyVarmap.java/buggy/org/jruby/interpreter/RubyVarmap.java
oldMap.put(ruby, ruby.getInterpreter().getDynamicVars());
((RubyStack)oldMap.get(ruby)).push(ruby.getInterpreter().getDynamicVars());
public static void push(Ruby ruby) { // HACK +++ if (oldMap.get(ruby) != null) { throw new RuntimeException("JRuby - BUG: Need Queue for oldMap in RubyVarmap"); } // HACK --- oldMap.put(ruby, ruby.getInterpreter().getDynamicVars()); ruby.getInterpreter().setDynamicVars(null); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/76d3fd1bbcdbd38082a9b8c19c593b06ed915280/RubyVarmap.java/buggy/org/jruby/interpreter/RubyVarmap.java
ruby.getInterpreter().setDynamicVars((RubyVarmap)oldMap.get(ruby));
ruby.getInterpreter().setDynamicVars((RubyVarmap)((RubyStack)oldMap.get(ruby)).pop());
public static void pop(Ruby ruby) { ruby.getInterpreter().setDynamicVars((RubyVarmap)oldMap.get(ruby)); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/76d3fd1bbcdbd38082a9b8c19c593b06ed915280/RubyVarmap.java/buggy/org/jruby/interpreter/RubyVarmap.java
private void loadThumbail(int index) { PixelsData pxd = images[index].getDefaultPixels(); int sizeX = maxWidth, sizeY = maxHeight; double ratio = (double) pxd.getSizeX()/pxd.getSizeY(); if (ratio < 1) sizeX *= ratio; else if (ratio > 1 && ratio != 0) sizeY *= 1/ratio; OmeroImageService rds = context.getImageService(); BufferedImage thumbPix = null; try { thumbPix = rds.getThumbnail(pxd.getId(), sizeX, sizeY); } catch (Exception e) { e.printStackTrace(); context.getLogger().error(this, "Cannot retrieve thumbnail: "+e.getMessage()); } if (thumbPix == null) thumbPix = Factory.createDefaultThumbnail(sizeX, sizeY); currentThumbnail = new ThumbnailData(images[index].getId(), thumbPix); //thumbs[index] = new ThumbnailData(images[index].getId(), thumbPix); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/464efde90db6bc5095c0a7e5952f51ad0f37ca86/ThumbnailLoader.java/clean/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailLoader.java
this.ruby = ruby;
this.runtime = ruby;
public UnmarshalStream(Ruby ruby, InputStream in) throws IOException { super(in); this.ruby = ruby; in.read(); // Major in.read(); // Minor }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f235ab756f32ea9496f8f880066b46ad95ebb692/UnmarshalStream.java/buggy/org/jruby/runtime/marshal/UnmarshalStream.java
int variableCount = unmarshalInt(); RubyMap variables = new RubyHashMap(variableCount); for (int i = 0; i < variableCount; i++) { RubySymbol name = (RubySymbol) unmarshalObject(); IRubyObject value = unmarshalObject(); variables.put(name.toId(), value); }
private IRubyObject defaultObjectUnmarshal() throws IOException { RubySymbol className = (RubySymbol) unmarshalObject(); int variableCount = unmarshalInt(); RubyMap variables = new RubyHashMap(variableCount); for (int i = 0; i < variableCount; i++) { RubySymbol name = (RubySymbol) unmarshalObject(); IRubyObject value = unmarshalObject(); variables.put(name.toId(), value); } // ... FIXME: handle if class doesn't exist ... RubyClass rubyClass = (RubyClass) ruby.getRubyClass(className.toId()); RubyObject result = new RubyObject(ruby, rubyClass); result.setInstanceVariables(variables); return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f235ab756f32ea9496f8f880066b46ad95ebb692/UnmarshalStream.java/buggy/org/jruby/runtime/marshal/UnmarshalStream.java
RubyClass rubyClass = (RubyClass) ruby.getRubyClass(className.toId()); RubyObject result = new RubyObject(ruby, rubyClass); result.setInstanceVariables(variables);
RubyClass type = (RubyClass) runtime.getRubyClass(className.toId()); IRubyObject result = runtime.getFactory().newObject(type); for (int i = 0, count = unmarshalInt(); i < count; i++) { result.setInstanceVariable(unmarshalObject().toId(), unmarshalObject()); }
private IRubyObject defaultObjectUnmarshal() throws IOException { RubySymbol className = (RubySymbol) unmarshalObject(); int variableCount = unmarshalInt(); RubyMap variables = new RubyHashMap(variableCount); for (int i = 0; i < variableCount; i++) { RubySymbol name = (RubySymbol) unmarshalObject(); IRubyObject value = unmarshalObject(); variables.put(name.toId(), value); } // ... FIXME: handle if class doesn't exist ... RubyClass rubyClass = (RubyClass) ruby.getRubyClass(className.toId()); RubyObject result = new RubyObject(ruby, rubyClass); result.setInstanceVariables(variables); return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f235ab756f32ea9496f8f880066b46ad95ebb692/UnmarshalStream.java/buggy/org/jruby/runtime/marshal/UnmarshalStream.java
return ruby.getNil();
return runtime.getNil();
public IRubyObject unmarshalObject() throws IOException { int type = readUnsignedByte(); switch (type) { case '0' : return ruby.getNil(); case 'T' : return RubyBoolean.newBoolean(ruby, true); case 'F' : return RubyBoolean.newBoolean(ruby, false); case '"' : return RubyString.unmarshalFrom(this); case 'i' : return RubyFixnum.unmarshalFrom(this); case ':' : return RubySymbol.unmarshalFrom(this); case '[' : return RubyArray.unmarshalFrom(this); case '{' : return RubyHash.unmarshalFrom(this); case 'c' : return RubyClass.unmarshalFrom(this); case 'm' : return RubyModule.unmarshalFrom(this); case 'l' : return RubyBignum.unmarshalFrom(this); case 'S' : return RubyStruct.unmarshalFrom(this); case 'o' : return defaultObjectUnmarshal(); case 'u' : return userUnmarshal(); default : Asserts.assertNotReached(); return null; } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f235ab756f32ea9496f8f880066b46ad95ebb692/UnmarshalStream.java/buggy/org/jruby/runtime/marshal/UnmarshalStream.java
return RubyBoolean.newBoolean(ruby, true);
return RubyBoolean.newBoolean(runtime, true);
public IRubyObject unmarshalObject() throws IOException { int type = readUnsignedByte(); switch (type) { case '0' : return ruby.getNil(); case 'T' : return RubyBoolean.newBoolean(ruby, true); case 'F' : return RubyBoolean.newBoolean(ruby, false); case '"' : return RubyString.unmarshalFrom(this); case 'i' : return RubyFixnum.unmarshalFrom(this); case ':' : return RubySymbol.unmarshalFrom(this); case '[' : return RubyArray.unmarshalFrom(this); case '{' : return RubyHash.unmarshalFrom(this); case 'c' : return RubyClass.unmarshalFrom(this); case 'm' : return RubyModule.unmarshalFrom(this); case 'l' : return RubyBignum.unmarshalFrom(this); case 'S' : return RubyStruct.unmarshalFrom(this); case 'o' : return defaultObjectUnmarshal(); case 'u' : return userUnmarshal(); default : Asserts.assertNotReached(); return null; } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f235ab756f32ea9496f8f880066b46ad95ebb692/UnmarshalStream.java/buggy/org/jruby/runtime/marshal/UnmarshalStream.java
return RubyBoolean.newBoolean(ruby, false);
return RubyBoolean.newBoolean(runtime, false);
public IRubyObject unmarshalObject() throws IOException { int type = readUnsignedByte(); switch (type) { case '0' : return ruby.getNil(); case 'T' : return RubyBoolean.newBoolean(ruby, true); case 'F' : return RubyBoolean.newBoolean(ruby, false); case '"' : return RubyString.unmarshalFrom(this); case 'i' : return RubyFixnum.unmarshalFrom(this); case ':' : return RubySymbol.unmarshalFrom(this); case '[' : return RubyArray.unmarshalFrom(this); case '{' : return RubyHash.unmarshalFrom(this); case 'c' : return RubyClass.unmarshalFrom(this); case 'm' : return RubyModule.unmarshalFrom(this); case 'l' : return RubyBignum.unmarshalFrom(this); case 'S' : return RubyStruct.unmarshalFrom(this); case 'o' : return defaultObjectUnmarshal(); case 'u' : return userUnmarshal(); default : Asserts.assertNotReached(); return null; } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f235ab756f32ea9496f8f880066b46ad95ebb692/UnmarshalStream.java/buggy/org/jruby/runtime/marshal/UnmarshalStream.java
RubyModule classInstance = ruby.getRubyModule(className);
RubyModule classInstance = runtime.getRubyModule(className);
private IRubyObject userUnmarshal() throws IOException { String className = ((RubySymbol) unmarshalObject()).toId(); String marshaled = unmarshalString(); RubyModule classInstance = ruby.getRubyModule(className); return classInstance.callMethod( "_load", RubyString.newString(ruby, marshaled)); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f235ab756f32ea9496f8f880066b46ad95ebb692/UnmarshalStream.java/buggy/org/jruby/runtime/marshal/UnmarshalStream.java
RubyString.newString(ruby, marshaled));
RubyString.newString(runtime, marshaled));
private IRubyObject userUnmarshal() throws IOException { String className = ((RubySymbol) unmarshalObject()).toId(); String marshaled = unmarshalString(); RubyModule classInstance = ruby.getRubyModule(className); return classInstance.callMethod( "_load", RubyString.newString(ruby, marshaled)); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f235ab756f32ea9496f8f880066b46ad95ebb692/UnmarshalStream.java/buggy/org/jruby/runtime/marshal/UnmarshalStream.java
if (_context == null) _context = c.cloneContext();
public MacroTemplate(Context c, Template t){ _template = t; _origContext = c; org.webmacro.util.Pool pool = c.getPool(); _context = (pool==null) ? c.cloneContext() : (Context)c.getPool().get(); }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/3ccce61e600cc9a41da5b0c24ff51529ec817bdd/TemplateTool.java/buggy/webmacro/src/org/webmacro/servlet/TemplateTool.java
return RubyArray.newArray(ruby, Arrays.asList(values));
return RubyArray.newArray(ruby, values);
public RubyArray to_a() { return RubyArray.newArray(ruby, Arrays.asList(values)); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/a42a5780d9d19f5b3f27bdc079684319c5596e54/RubyStruct.java/clean/org/jruby/RubyStruct.java
ioClass.defineMethod("close", CallbackFactory.getMethod(RubyIO.class, "close"));
public static RubyClass createIOClass(Ruby ruby) { RubyClass ioClass = ruby.defineClass("IO", ruby.getClasses().getObjectClass()); ioClass.includeModule(ruby.getClasses().getEnumerableModule()); ioClass.defineSingletonMethod("new", CallbackFactory.getOptSingletonMethod(RubyIO.class, "newInstance")); ioClass.defineMethod("initialize", CallbackFactory.getOptMethod(RubyIO.class, "initialize")); ioClass.defineMethod("write", CallbackFactory.getMethod(RubyIO.class, "write", RubyObject.class)); ioClass.defineMethod("<<", CallbackFactory.getMethod(RubyIO.class, "addString", RubyObject.class)); ioClass.defineMethod("gets", CallbackFactory.getOptMethod(RubyIO.class, "gets")); ioClass.defineMethod("lineno", CallbackFactory.getMethod(RubyIO.class, "lineno")); ioClass.defineMethod("lineno=", CallbackFactory.getMethod(RubyIO.class, "lineno_set", RubyFixnum.class)); ioClass.defineMethod("sync", CallbackFactory.getMethod(RubyIO.class, "sync")); ioClass.defineMethod("sync=", CallbackFactory.getMethod(RubyIO.class, "sync_set", RubyBoolean.class)); ruby.defineHookedVariable("$stdin", stdin(ruby, ioClass), null, new StdInSetter()); ruby.defineHookedVariable("$stdout", stdout(ruby, ioClass), null, new StdOutSetter()); return ioClass; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/56a7977143634286f5c14d96df0538899b2fcb1f/RubyIO.java/clean/org/jruby/RubyIO.java
RubyObject sepVal = getRuby().getGlobalEntry("$/").get(); if (args.length > 0) { sepVal = args[0];
RubyString result = internalGets(args); if (!result.isNil()) { getRuby().getParserHelper().setLastline(result);
public RubyString gets(RubyObject[] args) { RubyObject sepVal = getRuby().getGlobalEntry("$/").get(); if (args.length > 0) { sepVal = args[0]; } String separator = sepVal.isNil() ? null : ((RubyString) sepVal).getValue(); if (separator == null) { } else if (separator.length() == 0) { separator = "\n\n"; } try { String newLine = inStream.gets(separator); if (newLine != null) { lineNumber++; RubyString result = RubyString.newString(getRuby(), newLine); result.taint(); getRuby().getParserHelper().setLastline(result); return result; } } catch (IOException ioExcptn) { } return RubyString.nilString(getRuby()); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/56a7977143634286f5c14d96df0538899b2fcb1f/RubyIO.java/clean/org/jruby/RubyIO.java
String separator = sepVal.isNil() ? null : ((RubyString) sepVal).getValue(); if (separator == null) { } else if (separator.length() == 0) { separator = "\n\n"; } try { String newLine = inStream.gets(separator); if (newLine != null) { lineNumber++; RubyString result = RubyString.newString(getRuby(), newLine); result.taint(); getRuby().getParserHelper().setLastline(result); return result; } } catch (IOException ioExcptn) { } return RubyString.nilString(getRuby());
return result;
public RubyString gets(RubyObject[] args) { RubyObject sepVal = getRuby().getGlobalEntry("$/").get(); if (args.length > 0) { sepVal = args[0]; } String separator = sepVal.isNil() ? null : ((RubyString) sepVal).getValue(); if (separator == null) { } else if (separator.length() == 0) { separator = "\n\n"; } try { String newLine = inStream.gets(separator); if (newLine != null) { lineNumber++; RubyString result = RubyString.newString(getRuby(), newLine); result.taint(); getRuby().getParserHelper().setLastline(result); return result; } } catch (IOException ioExcptn) { } return RubyString.nilString(getRuby()); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/56a7977143634286f5c14d96df0538899b2fcb1f/RubyIO.java/clean/org/jruby/RubyIO.java
case 'a' :
protected void setMode(String mode) { if (mode.length() == 0) { throw new RubyArgumentException(getRuby(), "illegal access mode"); } switch (mode.charAt(0)) { case 'r' : readable = true; break; case 'w' : case 'a' : writeable = true; break; default : throw new RubyArgumentException(getRuby(), "illegal access mode " + mode); } if (mode.length() > 1) { int i = mode.charAt(1) == 'b' ? 2 : 1; if (mode.length() > i) { if (mode.charAt(i) == '+') { readable = true; writeable = true; } else { throw new RubyArgumentException(getRuby(), "illegal access mode " + mode); } } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/56a7977143634286f5c14d96df0538899b2fcb1f/RubyIO.java/clean/org/jruby/RubyIO.java
lvtbl.tbl = new ArrayList();
public void top_local_init() { local_push(); List lLocalNames = ruby.getScope().getLocalNames(); int lcnt = lLocalNames != null ? lLocalNames.size() : 0; if (lcnt > 0) { lvtbl.tbl = new ArrayList(); //ruby.getRubyScope().setLocalNames(lvtbl.tbl); //it should be the other way around, don't understand how it works for (int i = 0; i < lcnt; i++) registerLocal((String) lLocalNames.get(i)); } else { lvtbl.tbl = null; } if (ruby.getDynamicVars() != null) { lvtbl.dlev = 1; } else { lvtbl.dlev = 0; } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/2f13ba47385b7584839c7f6f6f1abfee251cbe53/ParserHelper.java/clean/org/jruby/parser/ParserHelper.java
for (int i = 0; i < lcnt; i++) registerLocal((String) lLocalNames.get(i));
/*for (int i = 0; i < lcnt; i++) registerLocal((String) lLocalNames.get(i));*/ lvtbl.tbl = new ArrayList(lLocalNames);
public void top_local_init() { local_push(); List lLocalNames = ruby.getScope().getLocalNames(); int lcnt = lLocalNames != null ? lLocalNames.size() : 0; if (lcnt > 0) { lvtbl.tbl = new ArrayList(); //ruby.getRubyScope().setLocalNames(lvtbl.tbl); //it should be the other way around, don't understand how it works for (int i = 0; i < lcnt; i++) registerLocal((String) lLocalNames.get(i)); } else { lvtbl.tbl = null; } if (ruby.getDynamicVars() != null) { lvtbl.dlev = 1; } else { lvtbl.dlev = 0; } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/2f13ba47385b7584839c7f6f6f1abfee251cbe53/ParserHelper.java/clean/org/jruby/parser/ParserHelper.java
public static Browser createBrowser(Set topNodes) { if (topNodes == null) throw new NullPointerException("No top nodes."); //Create the View. Add each visualization tree to the root display. RootDisplay view = new RootDisplay(); Iterator i = topNodes.iterator(); while (i.hasNext()) view.addChildDisplay((ImageDisplay) i.next()); //Now the Model. In an ideal world the Model wouldn't depend on the //View; however right now the dependence is basically insignificant //(see BrowserModel code) and simplifies matters quite a bit. BrowserModel model = new BrowserModel(view); //Finally the Controller. Call intialize to allow subscription. BrowserControl controller = new BrowserControl(model, view); controller.initialize(); //Fit to go! return model; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/b4992016524102ee0a5c7465d4cc7a94e9ffce2d/BrowserFactory.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/browser/BrowserFactory.java
delegate = (LocalUpdate) applicationContext.getBean("updateService");
delegate = (LocalUpdate) applicationContext.getBean( IUpdate.class.getName());
public void create() { super.create(); delegate = (LocalUpdate) applicationContext.getBean("updateService"); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/f7d8facc0df80871004c721c1920ba34361d4e05/UpdateBean.java/clean/components/ejb/src/ome/ro/ejb/UpdateBean.java
public Node parse(String content, String file) {
public Node parse(Reader content, String file) {
public Node parse(String content, String file) { return parser.parse(file, content); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/02f1a36be6c43bcb5b541cf429a4a8e0a2280750/Ruby.java/buggy/src/org/jruby/Ruby.java
if (value == null) { return new NullJavaObject(runtime); }
public static synchronized JavaObject wrap(Ruby runtime, Object value) { if (value == null) { return new NullJavaObject(runtime); } JavaObject wrapper = runtime.getJavaSupport().getJavaObjectFromCache(value); if (wrapper == null) { if (value.getClass().isArray()) { wrapper = new JavaArray(runtime, value); } else { wrapper = new JavaObject(runtime, value); } runtime.getJavaSupport().putJavaObjectIntoCache(wrapper); } return wrapper; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/206c7b0b7eb0c58d4a00f4aaa94c9013ad204adc/JavaObject.java/buggy/src/org/jruby/javasupport/JavaObject.java
if (value.getClass().isArray()) {
if (value != null && value.getClass().isArray()) {
public static synchronized JavaObject wrap(Ruby runtime, Object value) { if (value == null) { return new NullJavaObject(runtime); } JavaObject wrapper = runtime.getJavaSupport().getJavaObjectFromCache(value); if (wrapper == null) { if (value.getClass().isArray()) { wrapper = new JavaArray(runtime, value); } else { wrapper = new JavaObject(runtime, value); } runtime.getJavaSupport().putJavaObjectIntoCache(wrapper); } return wrapper; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/206c7b0b7eb0c58d4a00f4aaa94c9013ad204adc/JavaObject.java/buggy/src/org/jruby/javasupport/JavaObject.java
setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 10)); repaint();
manager.getView().repaint();
void showImages(List images) { removeAll(); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(Box.createRigidArea(DataManagerUIF.VBOX)); add(componentsPanel); add(Box.createRigidArea(DataManagerUIF.VBOX)); if (images != null && images.size() != 0) { add(buildImagesPanel(images)); setButtonsEnabled(true); } setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 10)); repaint(); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/d70386d4b1bd44d70716a6be05a1c87ff487476d/CreateCategoryImagesPane.java/clean/SRC/org/openmicroscopy/shoola/agents/datamng/editors/category/CreateCategoryImagesPane.java
public static Code create(String lang) {
public static Code create(Ruby runtime, String lang) {
public static Code create(String lang) { if (lang == null) { return NIL; } else if (lang.charAt(0) == 'n' || lang.charAt(0) == 'N') { return NONE; } else if (lang.charAt(0) == 'u' || lang.charAt(0) == 'U') { return UTF8; } else if (lang.charAt(0) == 's' || lang.charAt(0) == 'S') { return SJIS; } return NIL; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/de4c49d21f91fafaad36890ce5108ebf5c0404e8/RubyRegexp.java/buggy/src/org/jruby/RubyRegexp.java
runtime.getErrorHandler().warn("JRuby supports only Unicode regexp.");
public static Code create(String lang) { if (lang == null) { return NIL; } else if (lang.charAt(0) == 'n' || lang.charAt(0) == 'N') { return NONE; } else if (lang.charAt(0) == 'u' || lang.charAt(0) == 'U') { return UTF8; } else if (lang.charAt(0) == 's' || lang.charAt(0) == 'S') { return SJIS; } return NIL; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/de4c49d21f91fafaad36890ce5108ebf5c0404e8/RubyRegexp.java/buggy/src/org/jruby/RubyRegexp.java
regexpClass.defineMethod("to_s", callbackFactory.getMethod(RubyRegexp.class, "to_s"));
public static RubyClass createRegexpClass(Ruby runtime) { RubyClass regexpClass = runtime.defineClass("Regexp", runtime.getClasses().getObjectClass()); CallbackFactory callbackFactory = runtime.callbackFactory(); regexpClass.defineConstant("IGNORECASE", RubyFixnum.newFixnum(runtime, RE_OPTION_IGNORECASE)); regexpClass.defineConstant("EXTENDED", RubyFixnum.newFixnum(runtime, RE_OPTION_EXTENDED)); regexpClass.defineConstant("MULTILINE", RubyFixnum.newFixnum(runtime, RE_OPTION_MULTILINE)); regexpClass.defineMethod("initialize", callbackFactory.getOptMethod(RubyRegexp.class, "initialize")); regexpClass.defineMethod("clone", callbackFactory.getMethod(RubyRegexp.class, "rbClone")); regexpClass.defineMethod("==", callbackFactory.getMethod(RubyRegexp.class, "equal", IRubyObject.class)); regexpClass.defineMethod("===", callbackFactory.getMethod(RubyRegexp.class, "match", IRubyObject.class)); regexpClass.defineMethod("=~", callbackFactory.getMethod(RubyRegexp.class, "match", IRubyObject.class)); regexpClass.defineMethod("~", callbackFactory.getMethod(RubyRegexp.class, "match2")); regexpClass.defineMethod("match", callbackFactory.getMethod(RubyRegexp.class, "match_m", IRubyObject.class)); regexpClass.defineMethod("inspect", callbackFactory.getMethod(RubyRegexp.class, "inspect")); regexpClass.defineMethod("source", callbackFactory.getMethod(RubyRegexp.class, "source")); regexpClass.defineMethod("casefold?", callbackFactory.getMethod(RubyRegexp.class, "casefold")); regexpClass.defineMethod("kcode", callbackFactory.getMethod(RubyRegexp.class, "kcode")); regexpClass.defineSingletonMethod("new", callbackFactory.getOptSingletonMethod(RubyRegexp.class, "newInstance")); regexpClass.defineSingletonMethod("compile", callbackFactory.getOptSingletonMethod(RubyRegexp.class, "newInstance")); regexpClass.defineSingletonMethod("quote", callbackFactory.getSingletonMethod(RubyRegexp.class, "quote", RubyString.class)); regexpClass.defineSingletonMethod("escape", callbackFactory.getSingletonMethod(RubyRegexp.class, "quote", RubyString.class)); regexpClass.defineSingletonMethod("last_match", callbackFactory.getSingletonMethod(RubyRegexp.class, "last_match_s")); return regexpClass; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/de4c49d21f91fafaad36890ce5108ebf5c0404e8/RubyRegexp.java/buggy/src/org/jruby/RubyRegexp.java
public RubyString inspect() { final String regex = pattern.pattern(); final int length = regex.length(); StringBuffer sb = new StringBuffer(length + 2); sb.append('/'); for (int i = 0; i < length; i++) { char c = regex.charAt(i); if (RubyString.isAlnum(c)) { sb.append(c); } else if (c == '/') { sb.append('\\').append(c); } else if (RubyString.isPrint(c)) { sb.append(c); } else if (c == '\n') { sb.append('\\').append('n'); } else if (c == '\r') { sb.append('\\').append('r'); } else if (c == '\t') { sb.append('\\').append('t'); } else if (c == '\f') { sb.append('\\').append('f'); } else if (c == '\u000B') { sb.append('\\').append('v'); } else if (c == '\u0007') { sb.append('\\').append('a'); } else if (c == '\u001B') { sb.append('\\').append('e'); } else { sb.append(new PrintfFormat("\\%.3o").sprintf(c)); } } sb.append('/'); if ((pattern.flags() & Pattern.CASE_INSENSITIVE) > 0) { sb.append('i'); } if ((pattern.flags() & Pattern.DOTALL) > 0) { sb.append('m'); } if ((pattern.flags() & Pattern.COMMENTS) > 0) { sb.append('x'); } return RubyString.newString(getRuntime(), sb.toString()); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/de4c49d21f91fafaad36890ce5108ebf5c0404e8/RubyRegexp.java/buggy/src/org/jruby/RubyRegexp.java
public RubyString inspect() { final String regex = pattern.pattern(); final int length = regex.length(); StringBuffer sb = new StringBuffer(length + 2); sb.append('/'); for (int i = 0; i < length; i++) { char c = regex.charAt(i); if (RubyString.isAlnum(c)) { sb.append(c); } else if (c == '/') { sb.append('\\').append(c); } else if (RubyString.isPrint(c)) { sb.append(c); } else if (c == '\n') { sb.append('\\').append('n'); } else if (c == '\r') { sb.append('\\').append('r'); } else if (c == '\t') { sb.append('\\').append('t'); } else if (c == '\f') { sb.append('\\').append('f'); } else if (c == '\u000B') { sb.append('\\').append('v'); } else if (c == '\u0007') { sb.append('\\').append('a'); } else if (c == '\u001B') { sb.append('\\').append('e'); } else { sb.append(new PrintfFormat("\\%.3o").sprintf(c)); } } sb.append('/'); if ((pattern.flags() & Pattern.CASE_INSENSITIVE) > 0) { sb.append('i'); } if ((pattern.flags() & Pattern.DOTALL) > 0) { sb.append('m'); } if ((pattern.flags() & Pattern.COMMENTS) > 0) { sb.append('x'); } return RubyString.newString(getRuntime(), sb.toString()); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/de4c49d21f91fafaad36890ce5108ebf5c0404e8/RubyRegexp.java/buggy/src/org/jruby/RubyRegexp.java
public String sprintf(int x) throws IllegalArgumentException {
public String sprintf(Object[] o) {
public String sprintf(int x) throws IllegalArgumentException { Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; StringBuffer sb = new StringBuffer(); while (e.hasMoreElements()) { cs = (ConversionSpecification) e.nextElement(); c = cs.getConversionCharacter(); if (c == '\0') { sb.append(cs.getLiteral()); } else if (c == '%') { sb.append("%"); } else { sb.append(cs.internalsprintf(x)); } } return sb.toString(); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/3a923edad7ca292b5c22026d19b698666323e6be/PrintfFormat.java/buggy/src/org/jruby/util/PrintfFormat.java
sb.append(cs.internalsprintf(x));
if (cs.isPositionalSpecification()) { i = cs.getArgumentPosition() - 1; } if (cs.isPositionalFieldWidth()) { int ifw = cs.getArgumentPositionForFieldWidth() - 1; cs.setFieldWidthWithArg(((Number) o[ifw]).intValue()); } else if (cs.isVariableFieldWidth() && !cs.isPositionalSpecification()) { cs.setFieldWidthWithArg(((Number) o[i]).intValue()); i++; } if (cs.isPositionalPrecision()) { int ipr = cs.getArgumentPositionForPrecision() - 1; cs.setPrecisionWithArg(((Number) o[ipr]).intValue()); } else if (cs.isVariablePrecision() && !cs.isPositionalSpecification()) { cs.setPrecisionWithArg(((Number) o[i]).intValue()); i++; } if (o[i] == null) { } else if (o[i] instanceof Byte) { sb.append(cs.internalsprintf(((Byte) o[i]).byteValue())); } else if (o[i] instanceof Short) { sb.append(cs.internalsprintf(((Short) o[i]).shortValue())); } else if (o[i] instanceof Integer) { sb.append(cs.internalsprintf(((Integer) o[i]).intValue())); } else if (o[i] instanceof Long) { sb.append(cs.internalsprintf(((Long) o[i]).longValue())); } else if (o[i] instanceof Float) { sb.append(cs.internalsprintf(((Float) o[i]).floatValue())); } else if (o[i] instanceof Double) { sb.append(cs.internalsprintf(((Double) o[i]).doubleValue())); } else if (o[i] instanceof Character) { sb.append(cs.internalsprintf(((Character) o[i]).charValue())); } else if (o[i] instanceof String) { sb.append(cs.internalsprintf((String) o[i])); } else { sb.append(cs.internalsprintf(o[i])); } i++;
public String sprintf(int x) throws IllegalArgumentException { Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; StringBuffer sb = new StringBuffer(); while (e.hasMoreElements()) { cs = (ConversionSpecification) e.nextElement(); c = cs.getConversionCharacter(); if (c == '\0') { sb.append(cs.getLiteral()); } else if (c == '%') { sb.append("%"); } else { sb.append(cs.internalsprintf(x)); } } return sb.toString(); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/3a923edad7ca292b5c22026d19b698666323e6be/PrintfFormat.java/buggy/src/org/jruby/util/PrintfFormat.java
integerClass.defineMethod( "step", CallbackFactory.getMethod(RubyInteger.class, "step", RubyNumeric.class, RubyNumeric.class));
integerClass.defineMethod("step", CallbackFactory.getMethod(RubyInteger.class, "step", RubyNumeric.class, RubyNumeric.class));
public static RubyClass createIntegerClass(Ruby ruby) { RubyClass integerClass = ruby.defineClass("Integer", ruby.getClasses().getNumericClass()); integerClass.defineMethod("chr", CallbackFactory.getMethod(RubyInteger.class, "chr")); integerClass.defineMethod("integer?", CallbackFactory.getMethod(RubyInteger.class, "int_p")); integerClass.defineMethod("to_i", CallbackFactory.getMethod(RubyInteger.class, "to_i")); integerClass.defineMethod("to_int", CallbackFactory.getMethod(RubyInteger.class, "to_i")); integerClass.defineMethod("ceil", CallbackFactory.getMethod(RubyInteger.class, "to_i")); integerClass.defineMethod("floor", CallbackFactory.getMethod(RubyInteger.class, "to_i")); integerClass.defineMethod("round", CallbackFactory.getMethod(RubyInteger.class, "to_i")); integerClass.defineMethod("truncate", CallbackFactory.getMethod(RubyInteger.class, "to_i")); integerClass.defineMethod("next", CallbackFactory.getMethod(RubyInteger.class, "succ")); integerClass.defineMethod("succ", CallbackFactory.getMethod(RubyInteger.class, "succ")); integerClass.defineMethod("downto", CallbackFactory.getMethod(RubyInteger.class, "downto", RubyNumeric.class)); integerClass.defineMethod( "step", CallbackFactory.getMethod(RubyInteger.class, "step", RubyNumeric.class, RubyNumeric.class)); integerClass.defineMethod("times", CallbackFactory.getMethod(RubyInteger.class, "times")); integerClass.defineMethod("upto", CallbackFactory.getMethod(RubyInteger.class, "upto", RubyNumeric.class)); return integerClass; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/786cea08c1dd2092a02d1254b49fbee371ace5f9/RubyInteger.java/clean/org/jruby/RubyInteger.java
throw new RubyBugException("Couldn't create regexp adapter");
Asserts.assertNotReached("Couldn't create regexp adapter");
public RubyRegexp(Ruby ruby) { super(ruby, ruby.getRubyClass("Regexp")); try { matcher = (IRegexpAdapter) ruby.getRegexpAdapterClass().newInstance(); } catch (Exception ex) { // can't happen if JRuby is invoked via Main class throw new RubyBugException("Couldn't create regexp adapter"); } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/071973606d94103b2d5cb6c793aa1e8809fc7b2a/RubyRegexp.java/buggy/org/jruby/RubyRegexp.java
result.defineAlias("member?", "include?");
public static RubyClass createRangeClass(Ruby runtime) { RubyClass result = runtime.defineClass("Range", runtime.getClasses().getObjectClass()); CallbackFactory callbackFactory = runtime.callbackFactory(RubyRange.class); result.includeModule(runtime.getClasses().getEnumerableModule()); result.defineMethod("==", callbackFactory.getMethod("equal", IRubyObject.class)); result.defineMethod("===", callbackFactory.getMethod("op_eqq", IRubyObject.class)); result.defineMethod("begin", callbackFactory.getMethod("first")); result.defineMethod("each", callbackFactory.getMethod("each")); result.defineMethod("end", callbackFactory.getMethod("last")); result.defineMethod("exclude_end?", callbackFactory.getMethod("exclude_end_p")); result.defineMethod("first", callbackFactory.getMethod("first")); result.defineMethod("initialize", callbackFactory.getOptMethod("initialize")); result.defineMethod("inspect", callbackFactory.getMethod("inspect")); result.defineMethod("last", callbackFactory.getMethod("last")); result.defineMethod("length", callbackFactory.getMethod("length")); result.defineMethod("size", callbackFactory.getMethod("length")); result.defineMethod("to_s", callbackFactory.getMethod("inspect")); result.defineMethod("to_a", callbackFactory.getMethod("to_a")); result.defineMethod("include?", callbackFactory.getMethod("include_p", IRubyObject.class)); return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/c862744512b35172405ba450c8715edf6a11a160/RubyRange.java/buggy/src/org/jruby/RubyRange.java
public IRubyObject upto(IRubyObject str, boolean excl) { RubyString current = this; RubyString end = stringValue(str); while (current.cmp(end) <= 0) { getRuntime().yield(current); if (current.cmp(end) == 0) { break; } current = current.succ(false); if (excl && current.cmp(end) == 0) { break; } if (current.getValue().length() > end.getValue().length()) { break; } } return this;
public IRubyObject upto(IRubyObject str) { return upto(str, false);
public IRubyObject upto(IRubyObject str, boolean excl) { RubyString current = this; RubyString end = stringValue(str); while (current.cmp(end) <= 0) { getRuntime().yield(current); if (current.cmp(end) == 0) { break; } current = current.succ(false); if (excl && current.cmp(end) == 0) { break; } if (current.getValue().length() > end.getValue().length()) { break; } } return this; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/071973606d94103b2d5cb6c793aa1e8809fc7b2a/RubyString.java/buggy/org/jruby/RubyString.java
super(ruby, ruby.getExceptions().getNameError(), msg);
super(ruby, ruby.getExceptions().getRangeError(), msg);
public RangeError(Ruby ruby, String msg) { super(ruby, ruby.getExceptions().getNameError(), msg); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/5c7d9e094aa97d5066c802a80d5e119852f62221/RangeError.java/buggy/org/jruby/exceptions/RangeError.java
registerEditor("java.io.File", "org.apache.xbean.spring.context.impl.FileEditor");
public static void registerCustomEditors() { registerEditor("java.net.URI", "org.apache.xbean.spring.context.impl.URIEditor"); registerEditor("javax.management.ObjectName", "org.apache.xbean.spring.context.impl.ObjectNameEditor"); }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/01e7e2679ccc0cb110ceb63acd118266b38856a2/PropertyEditorHelper.java/buggy/xbean-spring-common/src/main/java/org/apache/xbean/spring/context/impl/PropertyEditorHelper.java
throw new ContextException("Foreach: Cannot evaluate limit");
throw new ContextException("#foreach: Cannot evaluate limit");
public void write(FastWriter out, Context context) throws ContextException, IOException { Object l, limit, from; long loopLimit=-1, loopStart=1, loopIndex=0; l = list; while (l instanceof Macro) l = ((Macro) l).evaluate(context); if (limitExpr != null) { limit = limitExpr; while (limit instanceof Macro) limit = ((Macro) limit).evaluate(context); if (Expression.isNumber(limit)) loopLimit = Expression.numberValue(limit); else throw new ContextException("Foreach: Cannot evaluate limit"); } if (index != null && indexFromExpr != null) { from = indexFromExpr; while (from instanceof Macro) from = ((Macro) from).evaluate(context); if (Expression.isNumber(from)) loopStart = Expression.numberValue(from); else throw new ContextException("Foreach: Cannot evaluate loop start"); } try { if (l instanceof Object[]) { Object[] alist = (Object[]) l; for (int i = 0; i < alist.length; i++) { target.setValue(context, alist[i]); if (index != null) index.setValue(context, new Long(loopIndex + loopStart)); body.write(out, context); ++loopIndex; if (loopLimit > 0 && loopIndex >= loopLimit) break; } } else { Iterator iter; try { iter = PropertyOperator.getIterator(l); } catch (Exception e) { throw new ContextException("The object used as the list of values in a foreach statement must have some way of returning a list type, or be a list type itself. See the documentation for PropertyOperator.getIterator() for more details. No such property was found on the supplied object: " + l + ": ", e); } while(iter.hasNext()) { target.setValue(context, iter.next()); if (index != null) index.setValue(context, new Long(loopIndex + loopStart)); body.write(out, context); ++loopIndex; if (loopLimit > 0 && loopIndex >= loopLimit) break; } } } catch (ContextException e) { String errorText = "Foreach: Unable to set list index"; context.getBroker().getLog("engine").error(errorText); writeWarning(errorText, out); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/3b361f35f3cd9fe5023b969ea9dd1ebdd30219a1/ForeachDirective.java/buggy/webmacro/src/org/webmacro/directive/ForeachDirective.java
throw new ContextException("Foreach: Cannot evaluate loop start");
throw new ContextException("#foreach: Cannot evaluate loop start");
public void write(FastWriter out, Context context) throws ContextException, IOException { Object l, limit, from; long loopLimit=-1, loopStart=1, loopIndex=0; l = list; while (l instanceof Macro) l = ((Macro) l).evaluate(context); if (limitExpr != null) { limit = limitExpr; while (limit instanceof Macro) limit = ((Macro) limit).evaluate(context); if (Expression.isNumber(limit)) loopLimit = Expression.numberValue(limit); else throw new ContextException("Foreach: Cannot evaluate limit"); } if (index != null && indexFromExpr != null) { from = indexFromExpr; while (from instanceof Macro) from = ((Macro) from).evaluate(context); if (Expression.isNumber(from)) loopStart = Expression.numberValue(from); else throw new ContextException("Foreach: Cannot evaluate loop start"); } try { if (l instanceof Object[]) { Object[] alist = (Object[]) l; for (int i = 0; i < alist.length; i++) { target.setValue(context, alist[i]); if (index != null) index.setValue(context, new Long(loopIndex + loopStart)); body.write(out, context); ++loopIndex; if (loopLimit > 0 && loopIndex >= loopLimit) break; } } else { Iterator iter; try { iter = PropertyOperator.getIterator(l); } catch (Exception e) { throw new ContextException("The object used as the list of values in a foreach statement must have some way of returning a list type, or be a list type itself. See the documentation for PropertyOperator.getIterator() for more details. No such property was found on the supplied object: " + l + ": ", e); } while(iter.hasNext()) { target.setValue(context, iter.next()); if (index != null) index.setValue(context, new Long(loopIndex + loopStart)); body.write(out, context); ++loopIndex; if (loopLimit > 0 && loopIndex >= loopLimit) break; } } } catch (ContextException e) { String errorText = "Foreach: Unable to set list index"; context.getBroker().getLog("engine").error(errorText); writeWarning(errorText, out); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/3b361f35f3cd9fe5023b969ea9dd1ebdd30219a1/ForeachDirective.java/buggy/webmacro/src/org/webmacro/directive/ForeachDirective.java
String errorText = "Foreach: Unable to set list index";
String errorText = "#foreach: Unable to set list index";
public void write(FastWriter out, Context context) throws ContextException, IOException { Object l, limit, from; long loopLimit=-1, loopStart=1, loopIndex=0; l = list; while (l instanceof Macro) l = ((Macro) l).evaluate(context); if (limitExpr != null) { limit = limitExpr; while (limit instanceof Macro) limit = ((Macro) limit).evaluate(context); if (Expression.isNumber(limit)) loopLimit = Expression.numberValue(limit); else throw new ContextException("Foreach: Cannot evaluate limit"); } if (index != null && indexFromExpr != null) { from = indexFromExpr; while (from instanceof Macro) from = ((Macro) from).evaluate(context); if (Expression.isNumber(from)) loopStart = Expression.numberValue(from); else throw new ContextException("Foreach: Cannot evaluate loop start"); } try { if (l instanceof Object[]) { Object[] alist = (Object[]) l; for (int i = 0; i < alist.length; i++) { target.setValue(context, alist[i]); if (index != null) index.setValue(context, new Long(loopIndex + loopStart)); body.write(out, context); ++loopIndex; if (loopLimit > 0 && loopIndex >= loopLimit) break; } } else { Iterator iter; try { iter = PropertyOperator.getIterator(l); } catch (Exception e) { throw new ContextException("The object used as the list of values in a foreach statement must have some way of returning a list type, or be a list type itself. See the documentation for PropertyOperator.getIterator() for more details. No such property was found on the supplied object: " + l + ": ", e); } while(iter.hasNext()) { target.setValue(context, iter.next()); if (index != null) index.setValue(context, new Long(loopIndex + loopStart)); body.write(out, context); ++loopIndex; if (loopLimit > 0 && loopIndex >= loopLimit) break; } } } catch (ContextException e) { String errorText = "Foreach: Unable to set list index"; context.getBroker().getLog("engine").error(errorText); writeWarning(errorText, out); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/3b361f35f3cd9fe5023b969ea9dd1ebdd30219a1/ForeachDirective.java/buggy/webmacro/src/org/webmacro/directive/ForeachDirective.java
public Object getArg(int argId, BuildContext bc)
public Object getArg(int argId)
public Object getArg(int argId, BuildContext bc) throws BuildException { if (buildArgs == null) return null; else return buildArgs.getArg(argId, bc); }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/67f3bf2b9347218e8efc5ecece60bb5f03730152/DirectiveBuilder.java/buggy/webmacro/src/org/webmacro/directive/DirectiveBuilder.java
else return buildArgs.getArg(argId, bc);
else return buildArgs.getArg(argId);
public Object getArg(int argId, BuildContext bc) throws BuildException { if (buildArgs == null) return null; else return buildArgs.getArg(argId, bc); }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/67f3bf2b9347218e8efc5ecece60bb5f03730152/DirectiveBuilder.java/buggy/webmacro/src/org/webmacro/directive/DirectiveBuilder.java
kernelModule.defineMethod("send", CallbackFactory.getOptMethod(RubyObject.class, "send", RubyString.class)); kernelModule.defineMethod("__send__", CallbackFactory.getOptMethod(RubyObject.class, "send", RubyString.class));
kernelModule.defineMethod("send", CallbackFactory.getOptMethod(RubyObject.class, "send", RubyObject.class)); kernelModule.defineMethod("__send__", CallbackFactory.getOptMethod(RubyObject.class, "send", RubyObject.class));
public static void createObjectClass(RubyModule kernelModule) { // TODO: convert to CallbackFactory invokes. Callback clone = new ReflectionCallbackMethod(RubyObject.class, "rbClone"); Callback dup = new ReflectionCallbackMethod(RubyObject.class, "dup"); Callback equal = new ReflectionCallbackMethod(RubyObject.class, "equal", RubyObject.class); Callback respond_to = new ReflectionCallbackMethod(RubyObject.class, "respond_to", RubySymbol.class); Callback extend = new ReflectionCallbackMethod(RubyObject.class, "extend", RubyObject[].class, true); Callback freeze = new ReflectionCallbackMethod(RubyObject.class, "freeze"); Callback frozen = new ReflectionCallbackMethod(RubyObject.class, "frozen"); Callback id = new ReflectionCallbackMethod(RubyObject.class, "id"); Callback inspect = new ReflectionCallbackMethod(RubyObject.class, "inspect"); Callback instance_eval = new ReflectionCallbackMethod(RubyObject.class, "instance_eval", RubyObject[].class, true); Callback instance_of = new ReflectionCallbackMethod(RubyObject.class, "instance_of", RubyModule.class); Callback kind_of = new ReflectionCallbackMethod(RubyObject.class, "kind_of", RubyModule.class); Callback method = new ReflectionCallbackMethod(RubyObject.class, "method", RubyObject.class); Callback methods = new ReflectionCallbackMethod(RubyObject.class, "methods"); Callback private_methods = new ReflectionCallbackMethod(RubyObject.class, "private_methods"); Callback protected_methods = new ReflectionCallbackMethod(RubyObject.class, "protected_methods"); Callback taint = new ReflectionCallbackMethod(RubyObject.class, "taint"); Callback tainted = new ReflectionCallbackMethod(RubyObject.class, "tainted"); Callback to_a = new ReflectionCallbackMethod(RubyObject.class, "to_a"); Callback to_s = new ReflectionCallbackMethod(RubyObject.class, "to_s"); Callback type = new ReflectionCallbackMethod(RubyObject.class, "type"); Callback untaint = new ReflectionCallbackMethod(RubyObject.class, "untaint"); kernelModule.defineMethod("=~", CallbackFactory.getFalseMethod()); kernelModule.defineMethod("==", equal); kernelModule.defineMethod("respond_to?", respond_to); kernelModule.defineMethod("class", type); kernelModule.defineMethod("clone", clone); kernelModule.defineMethod("dup", dup); kernelModule.defineMethod("eql?", equal); kernelModule.defineMethod("extend", extend); kernelModule.defineMethod("freeze", freeze); kernelModule.defineMethod("frozen?", frozen); kernelModule.defineMethod("hash", id); kernelModule.defineMethod("id", id); kernelModule.defineMethod("__id__", id); kernelModule.defineMethod("inspect", inspect); kernelModule.defineMethod("instance_eval", instance_eval); kernelModule.defineMethod("instance_of?", instance_of); kernelModule.defineMethod("is_a?", kind_of); kernelModule.defineMethod("kind_of?", kind_of); kernelModule.defineMethod("method", method); kernelModule.defineMethod("methods", methods); kernelModule.defineMethod("private_methods", private_methods); kernelModule.defineMethod("protected_methods", protected_methods); kernelModule.defineMethod("public_methods", methods); kernelModule.defineMethod("nil?", CallbackFactory.getFalseMethod()); kernelModule.defineMethod("send", CallbackFactory.getOptMethod(RubyObject.class, "send", RubyString.class)); kernelModule.defineMethod("__send__", CallbackFactory.getOptMethod(RubyObject.class, "send", RubyString.class)); kernelModule.defineMethod("taint", taint); kernelModule.defineMethod("tainted?", tainted); kernelModule.defineMethod("to_a", to_a); kernelModule.defineMethod("to_s", to_s); kernelModule.defineMethod("type", type); kernelModule.defineMethod("untaint", untaint); kernelModule.defineAlias("===", "=="); kernelModule.defineAlias("equal?", "=="); Ruby ruby = kernelModule.getRuby(); ruby.defineGlobalFunction("method_missing", CallbackFactory.getOptMethod(RubyObject.class, "method_missing", RubyObject.class)); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/d31a76ee29d5978a9bec41e3ac9134cee024bcab/RubyObject.java/buggy/org/jruby/RubyObject.java
if (currType == type || currType.getMethods().keySet().retainAll(type.getMethods().keySet())) {
if (currType == type || currType.getMethods().keySet().containsAll(type.getMethods().keySet())) {
public RubyBoolean kind_of(RubyModule type) { RubyClass currType = getRubyClass(); while (currType != null) { if (currType == type || currType.getMethods().keySet().retainAll(type.getMethods().keySet())) { return getRuby().getTrue(); } currType = currType.getSuperClass(); } return getRuby().getFalse(); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/d31a76ee29d5978a9bec41e3ac9134cee024bcab/RubyObject.java/buggy/org/jruby/RubyObject.java
ruby.getSourceFile() + ":" + ruby.getSourceLine() + " undefined method '" + symbol.toId() + "' for " + type().toName());
ruby.getSourceFile() + ":" + ruby.getSourceLine() + " undefined method '" + symbol.toId() + "' for '" + type().toName() + '\'');
public RubyObject method_missing(RubyObject symbol, RubyObject[] args) { // +++ // IMPLEMENT THIS METHOD // --- Ruby ruby = getRuby(); throw new NameError( ruby, ruby.getSourceFile() + ":" + ruby.getSourceLine() + " undefined method '" + symbol.toId() + "' for " + type().toName()); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/d31a76ee29d5978a9bec41e3ac9134cee024bcab/RubyObject.java/buggy/org/jruby/RubyObject.java
public RubyObject send(RubyString method, RubyObject[] args) {
public RubyObject send(RubyObject method, RubyObject[] args) {
public RubyObject send(RubyString method, RubyObject[] args) { try { getRuby().getIter().push(getRuby().isBlockGiven() ? RubyIter.ITER_PRE : RubyIter.ITER_NOT); return getRubyClass().call(this, method.getValue(), new RubyPointer(args), 1); } finally { getRuby().getIter().pop(); } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/d31a76ee29d5978a9bec41e3ac9134cee024bcab/RubyObject.java/buggy/org/jruby/RubyObject.java
return getRubyClass().call(this, method.getValue(), new RubyPointer(args), 1);
return getRubyClass().call(this, method.toId(), new RubyPointer(args), 1);
public RubyObject send(RubyString method, RubyObject[] args) { try { getRuby().getIter().push(getRuby().isBlockGiven() ? RubyIter.ITER_PRE : RubyIter.ITER_NOT); return getRubyClass().call(this, method.getValue(), new RubyPointer(args), 1); } finally { getRuby().getIter().pop(); } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/d31a76ee29d5978a9bec41e3ac9134cee024bcab/RubyObject.java/buggy/org/jruby/RubyObject.java
public static Callback getFalseMethod() {
public static Callback getFalseMethod(final int arity) {
public static Callback getFalseMethod() { return new Callback() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { return ruby.getFalse(); } }; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/6076c5ab87d25a488469aa1a32f1d2c9c9e470b2/CallbackFactory.java/buggy/org/jruby/runtime/CallbackFactory.java
public int getArity() { return arity; }
public static Callback getFalseMethod() { return new Callback() { public RubyObject execute(RubyObject recv, RubyObject[] args, Ruby ruby) { return ruby.getFalse(); } }; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/6076c5ab87d25a488469aa1a32f1d2c9c9e470b2/CallbackFactory.java/buggy/org/jruby/runtime/CallbackFactory.java
public IRubyObject eval(IRubyObject src, IRubyObject scope, String file, int line) { ThreadContext threadContext = runtime.getCurrentContext(); ISourcePosition savedPosition = threadContext.getPosition(); Iter iter = threadContext.getCurrentFrame().getIter(); if (file == null) { file = threadContext.getSourceFile(); } if (scope.isNil()) { FrameStack frameStack = threadContext.getFrameStack(); if (frameStack.getPrevious() != null) { ((Frame) frameStack.peek()).setIter(frameStack.getPrevious().getIter()); } } threadContext.pushClass(threadContext.getCBase()); IRubyObject result = getRuntime().getNil(); try { INode node = getRuntime().parse(src.toString(), file); result = eval(node); } finally { threadContext.popClass(); if (scope.isNil()) { threadContext.getCurrentFrame().setIter(iter); } threadContext.setPosition(savedPosition); } return result;
public IRubyObject eval(INode n) { return EvaluateVisitor.createVisitor(this).eval(n);
public IRubyObject eval(IRubyObject src, IRubyObject scope, String file, int line) { ThreadContext threadContext = runtime.getCurrentContext(); ISourcePosition savedPosition = threadContext.getPosition(); Iter iter = threadContext.getCurrentFrame().getIter(); if (file == null) { file = threadContext.getSourceFile(); } if (scope.isNil()) { FrameStack frameStack = threadContext.getFrameStack(); if (frameStack.getPrevious() != null) { ((Frame) frameStack.peek()).setIter(frameStack.getPrevious().getIter()); } } threadContext.pushClass(threadContext.getCBase()); IRubyObject result = getRuntime().getNil(); try { INode node = getRuntime().parse(src.toString(), file); result = eval(node); } finally { threadContext.popClass(); if (scope.isNil()) { threadContext.getCurrentFrame().setIter(iter); } threadContext.setPosition(savedPosition); } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/0044a3b88a0afa22dcced1c8213002b0fb16faf4/RubyObject.java/buggy/src/org/jruby/RubyObject.java
public NODE searchMethod(RubyId id) { RubyModule rubyModule = getMethodOrigin(id); if (rubyModule != null) { return (NODE)rubyModule.getMethods().get(id);
public SearchMethodResult searchMethod(RubyId id) { NODE body = (NODE)getMethods().get(id); if (body == null) { if (getSuperClass() != null) { return getSuperClass().searchMethod(id); } else { return new SearchMethodResult(null, null); } } else { return new SearchMethodResult((NODE)getMethods().get(id), this);
public NODE searchMethod(RubyId id) { RubyModule rubyModule = getMethodOrigin(id); if (rubyModule != null) { return (NODE)rubyModule.getMethods().get(id); } return null; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyModule.java/buggy/org/jruby/RubyModule.java
return null;
public NODE searchMethod(RubyId id) { RubyModule rubyModule = getMethodOrigin(id); if (rubyModule != null) { return (NODE)rubyModule.getMethods().get(id); } return null; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyModule.java/buggy/org/jruby/RubyModule.java
RubyModule clone = new RubyClass(getRuby(), null, getSuperClass());
RubyModule clone = new RubyClass(getRuby(), getSuperClass());
public RubyModule getSingletonClassClone() { if (!isSingleton()) { return this; } RubyModule clone = new RubyClass(getRuby(), null, getSuperClass()); clone.setupClone(this); clone.setInstanceVariables(getInstanceVariables().cloneRubyMap()); //clone.setMethods(); // st_foreach(RCLASS(klass)->m_tbl, clone_method, clone->m_tbl); clone.setSingleton(true); return clone; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyModule.java/buggy/org/jruby/RubyModule.java
return getRuntime().newFixnum(hashCode());
return getRuntime().newFixnum(value.hashCode());
public RubyFixnum hash() { return getRuntime().newFixnum(hashCode()); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/4b12521bf34cff2c9841b1dacb1a929f6def5327/RubyBignum.java/clean/src/org/jruby/RubyBignum.java
public abstract RubyNumeric multiplyWith(RubyInteger value);
public RubyNumeric multiplyWith(RubyFixnum value) { return multiplyWith((RubyInteger) value); }
public abstract RubyNumeric multiplyWith(RubyInteger value);
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/01b5828197be55fd807321e9abb8f856ff501ad6/RubyNumeric.java/buggy/src/org/jruby/RubyNumeric.java
System.err.println("laying out datasets");
public void layoutContents() { eventHandler = new DatasetBrowserEventHandler(this); // layout treemaps arrangeDisplay(allDatasets); doLayout(allDatasets); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/5814349a1963bfac97deaeec0ddc26d1fa8710d4/DatasetBrowserCanvas.java/clean/SRC/org/openmicroscopy/shoola/agents/zoombrowser/piccolo/DatasetBrowserCanvas.java
throw new BuildException("Template " + o + " not found: ", ne);
throw new BuildException("#parse: Template " + o + " not found: ", ne);
public Object build(DirectiveBuilder builder, BuildContext bc) throws BuildException { Object o = builder.getArg(PARSE_TEMPLATE, bc); if (o instanceof Macro) { template = (Macro) o; return this; } else try { return bc.getBroker().get("template", o.toString()); } catch (NotFoundException ne) { throw new BuildException("Template " + o + " not found: ", ne); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/3b361f35f3cd9fe5023b969ea9dd1ebdd30219a1/ParseDirective.java/buggy/webmacro/src/org/webmacro/directive/ParseDirective.java
String warning = "Error reading template: " + fname;
String warning = "#parse: Error reading template: " + fname;
public void write(FastWriter out, Context context) throws ContextException, IOException { String fname = template.evaluate(context).toString(); try { Template tmpl = (Template) context.getBroker().get("template", fname); tmpl.write(out,context); } catch (IOException e) { String warning = "Error reading template: " + fname; context.getLog("engine").warning(warning, e); writeWarning(warning, out); } catch (Exception e) { String warning = "Template not found: " + fname; context.getLog("engine").warning(warning,e); writeWarning(warning, out); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/3b361f35f3cd9fe5023b969ea9dd1ebdd30219a1/ParseDirective.java/buggy/webmacro/src/org/webmacro/directive/ParseDirective.java
String warning = "Template not found: " + fname;
String warning = "#parse: Template not found: " + fname;
public void write(FastWriter out, Context context) throws ContextException, IOException { String fname = template.evaluate(context).toString(); try { Template tmpl = (Template) context.getBroker().get("template", fname); tmpl.write(out,context); } catch (IOException e) { String warning = "Error reading template: " + fname; context.getLog("engine").warning(warning, e); writeWarning(warning, out); } catch (Exception e) { String warning = "Template not found: " + fname; context.getLog("engine").warning(warning,e); writeWarning(warning, out); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/3b361f35f3cd9fe5023b969ea9dd1ebdd30219a1/ParseDirective.java/buggy/webmacro/src/org/webmacro/directive/ParseDirective.java
try { return b.get("url", name).toString(); } catch (ResourceException re) { try {
try { return b.get("url", name).toString(); } catch (Exception e) { URL url = null;
protected String getFile(Broker b, String name) throws PropertyException { try { return b.get("url", name).toString(); } catch (ResourceException re) { try { try { // The UrlProvider knows, how to do this, // so let him do the work for us return b.get("url", name).toString(); } catch (NullPointerException npe) { throw npe; } catch (Exception e) { throw makePropertyException("Found by Broker, but could not be retrieved", e); } } catch (NullPointerException npe) { throw makePropertyException("Not found by url provider or broker"); } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from Broker", e); } } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from url provider", e); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/4c6dd1efd26a8cd7e5b5f5ee6a306eb92c3fe2de/IncludeDirective.java/clean/webmacro/src/org/webmacro/directive/IncludeDirective.java
return b.get("url", name).toString();
url = b.getResource(name); if (url == null) throw makePropertyException("Resource not found by URL provider or Broker"); URLConnection conn = url.openConnection(); StringBuffer sb = new StringBuffer (); InputStream in = conn.getInputStream(); String enc = conn.getContentEncoding(); if (enc == null) enc = b.getSetting("TemplateEncoding"); int cnt=0; byte[] buff = new byte[4096]; while ( (cnt = in.read(buff)) > 0) { sb.append (new String (buff, 0, cnt, enc)); } in.close(); return sb.toString();
protected String getFile(Broker b, String name) throws PropertyException { try { return b.get("url", name).toString(); } catch (ResourceException re) { try { try { // The UrlProvider knows, how to do this, // so let him do the work for us return b.get("url", name).toString(); } catch (NullPointerException npe) { throw npe; } catch (Exception e) { throw makePropertyException("Found by Broker, but could not be retrieved", e); } } catch (NullPointerException npe) { throw makePropertyException("Not found by url provider or broker"); } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from Broker", e); } } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from url provider", e); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/4c6dd1efd26a8cd7e5b5f5ee6a306eb92c3fe2de/IncludeDirective.java/clean/webmacro/src/org/webmacro/directive/IncludeDirective.java
catch (NullPointerException npe) { throw npe;
catch (IOException ioe) { throw makePropertyException("Error streaming file from: " + url, ioe);
protected String getFile(Broker b, String name) throws PropertyException { try { return b.get("url", name).toString(); } catch (ResourceException re) { try { try { // The UrlProvider knows, how to do this, // so let him do the work for us return b.get("url", name).toString(); } catch (NullPointerException npe) { throw npe; } catch (Exception e) { throw makePropertyException("Found by Broker, but could not be retrieved", e); } } catch (NullPointerException npe) { throw makePropertyException("Not found by url provider or broker"); } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from Broker", e); } } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from url provider", e); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/4c6dd1efd26a8cd7e5b5f5ee6a306eb92c3fe2de/IncludeDirective.java/clean/webmacro/src/org/webmacro/directive/IncludeDirective.java
catch (Exception e) { throw makePropertyException("Found by Broker, but could not be retrieved", e); } } catch (NullPointerException npe) { throw makePropertyException("Not found by url provider or broker"); } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from Broker", e); } } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from url provider", e); }
}
protected String getFile(Broker b, String name) throws PropertyException { try { return b.get("url", name).toString(); } catch (ResourceException re) { try { try { // The UrlProvider knows, how to do this, // so let him do the work for us return b.get("url", name).toString(); } catch (NullPointerException npe) { throw npe; } catch (Exception e) { throw makePropertyException("Found by Broker, but could not be retrieved", e); } } catch (NullPointerException npe) { throw makePropertyException("Not found by url provider or broker"); } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from Broker", e); } } catch (Exception e) { throw makePropertyException("Unexpected exception while getting from url provider", e); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/4c6dd1efd26a8cd7e5b5f5ee6a306eb92c3fe2de/IncludeDirective.java/clean/webmacro/src/org/webmacro/directive/IncludeDirective.java
if (ChainBuilderAgent.DEBUG)
if (ChainBuilderAgent.DEBUG >3)
public void setSelected(boolean v) { if (ChainBuilderAgent.DEBUG) System.err.println(" setting a link to be selected.."); LinkTarget startTarget = getStartLinkTarget(); LinkTarget endTarget = getEndLinkTarget(); startTarget.setSelected(v); endTarget.setSelected(v); targets.removeAllChildren(); if (v == true) { // set up children bulb.setPaint(Constants.LINK_HIGHLIGHT_COLOR); targets.setVisible(true); int count = points.size(); for (int i = 1; i < count-1; i++) { LinkSelectionTarget t = new LinkSelectionTarget(this,i); targets.addChild(t); Point2D pt = (Point2D) points.get(i); t.setOffset((float)pt.getX()-Constants.LINK_TARGET_HALF_SIZE, (float)pt.getY()-Constants.LINK_TARGET_HALF_SIZE); t.setSelected(v); } } else bulb.setPaint(Constants.DEFAULT_COLOR); repaint(); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/630a53d68f5d29c53d2485557b18599785befb83/Link.java/clean/SRC/org/openmicroscopy/shoola/agents/chainbuilder/piccolo/Link.java
((File) entry.getValue()).mkdirs();
((File) entry.getValue()).getParentFile().mkdirs();
public void execute() throws BuildException { Map fileMap = new HashMap(); FileNameMapper mapper = null; if (mapperElement != null) { mapper = mapperElement.getImplementation(); } else { mapper = new GlobPatternMapper(); mapper.setFrom("*.rb"); mapper.setTo("*.rb.ast.ser"); } SourceFileScanner sfs = new SourceFileScanner(this); for (int i = 0, size = fileSets.size(); i < size; i++) { FileSet fs = (FileSet) fileSets.get(i); DirectoryScanner ds = fs.getDirectoryScanner(project); File dir = fs.getDir(project); String[] files = ds.getIncludedFiles(); files = sfs.restrict(files, dir, destdir, mapper); for (int j = 0; j < files.length; j++) { File src = new File(dir, files[j]); File dest = new File(destdir, mapper.mapFileName(files[j])[0]); fileMap.put(src, dest); } } if (fileMap.size() > 0) { log( "Serializing " + fileMap.size() + " file" + (fileMap.size() == 1 ? "" : "s") + " to " + destdir.getAbsolutePath()); Iterator iter = fileMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); try { ((File) entry.getValue()).mkdirs(); ASTSerializer.serialize((File) entry.getKey(), (File) entry.getValue()); } catch (IOException ioExcpn) { } } } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9e6ae9722245fb5d74254985e21d50a65c7e80c3/JRubySerialize.java/clean/src/org/jruby/util/ant/JRubySerialize.java