rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
meta
stringlengths
141
403
public void nd_head(NODE n) { u1 = n; }
public NODE nd_head() { return (NODE)u1; }
public void nd_head(NODE n) { u1 = n; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
this.value = value;
this.value = value;
private RubyId(Ruby ruby, int value) { super(); this.ruby = ruby; this.value = value; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/0a7181933af700ea8025a4197f3a5ebcc08333c3/RubyId.java/buggy/org/jruby/RubyId.java
public void nd_end(NODE n) { u2 = n; }
public NODE nd_end() { return (NODE)u2; }
public void nd_end(NODE n) { u2 = n; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
public void nd_cnt(int i) { u3 = new Integer(i); }
public int nd_cnt() { return u3 == null ? 0 : ((Integer)u3).intValue(); }
public void nd_cnt(int i) { u3 = new Integer(i); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
public RubyString(Ruby ruby, String str) { this(ruby, ruby.getClasses().getStringClass(), str);
public RubyString(Ruby ruby) { this(ruby, null);
public RubyString(Ruby ruby, String str) { this(ruby, ruby.getClasses().getStringClass(), str); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/071973606d94103b2d5cb6c793aa1e8809fc7b2a/RubyString.java/buggy/org/jruby/RubyString.java
public void nd_iter(NODE n) { u3 = n; }
public NODE nd_iter() { return (NODE)u3; }
public void nd_iter(NODE n) { u3 = n; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
public void nd_nth(int i) { u2 = new Integer(i); }
public int nd_nth() { return u2 == null ? 0 : ((Integer)u2).intValue(); }
public void nd_nth(int i) { u2 = new Integer(i); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
public void nd_cflag(RubyId id) { u2 = id; }
public RubyId nd_cflag() { return (RubyId)u2; }
public void nd_cflag(RubyId id) { u2 = id; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
public static void print(int indent, Object o, Set visited) { if (o == null) return; if (visited.contains(o)) { indent(indent); System.out.println("(...@" + Integer.toHexString(o.hashCode()) + "...)"); } else if (o instanceof NODE) ((NODE)o).print(indent, visited); else { indent(indent); System.out.println(o); }
public void print(int indent, Set visited) { visited.add(this); indent(indent); System.out.println(this); print(indent + 1, u1, visited); print(indent + 1, u2, visited); print(indent + 1, u3, visited);
public static void print(int indent, Object o, Set visited) { if (o == null) return; if (visited.contains(o)) { indent(indent); System.out.println("(...@" + Integer.toHexString(o.hashCode()) + "...)"); } else if (o instanceof NODE) ((NODE)o).print(indent, visited); else { indent(indent); System.out.println(o); } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
public void nd_aid(RubyId id) { u3 = id; }
public RubyId nd_aid() { return (RubyId)u3; }
public void nd_aid(RubyId id) { u3 = id; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
public void nd_noex(int i) { u1 = new Integer(i); }
public int nd_noex() { return u1 == null ? 0 : ((Integer)u1).intValue(); }
public void nd_noex(int i) { u1 = new Integer(i); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/9a05f18f2b6207bf93455d756436fe8f0002b542/NODE.java/buggy/org/jruby/original/NODE.java
assertEquals(1, favorites.size());
assertEquals(2, favorites.size());
public void testFavs() throws Exception { FavoriteService fs = (FavoriteService) getBean("favoriteService"); Map favorites = fs.getFavorites(); assertNotNull(favorites); assertEquals(1, favorites.size()); assertEquals("Grey Goose", favorites.get("Dan")); }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/4a3dda22527dffb579d2266a490a4bf02b280c4f/FavoriteUsingSpringTest.java/buggy/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/FavoriteUsingSpringTest.java
Object object = favorites.get("IndecisiveDan"); System.out.println(object.getClass()); assertTrue(object instanceof List); List l = (List) object; assertEquals(2, l.size());
public void testFavs() throws Exception { FavoriteService fs = (FavoriteService) getBean("favoriteService"); Map favorites = fs.getFavorites(); assertNotNull(favorites); assertEquals(1, favorites.size()); assertEquals("Grey Goose", favorites.get("Dan")); }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/4a3dda22527dffb579d2266a490a4bf02b280c4f/FavoriteUsingSpringTest.java/buggy/xbean-spring-v1/src/test/java/org/apache/xbean/spring/context/FavoriteUsingSpringTest.java
context.registerTool("testTool", new TestTool());
public static void main(String arg[]) { Log.traceExceptions(true); Log.setLevel(Log.ALL); Log.setTarget(System.err); if (arg.length != 0) { System.out.println("Enabling log types"); Log.enableTypes(arg); } // Build a context WebMacro wm = null; Context context = null; try { wm = new WM(); context = new Context(null); Object names[] = { "prop" }; context.setProperty(names, "Example property"); } catch (Exception e) { e.printStackTrace(); } try { context.put("helloworld", "Hello World"); context.put("hello", "Hello"); context.put("file", "include.txt"); TestObject[] fruits = { new TestObject("apple",false), new TestObject("lemon",true), new TestObject("pear",false), new TestObject("orange",true), new TestObject("watermelon",false), new TestObject("peach",false), new TestObject("lime",true) }; SelectList sl = new SelectList(fruits, 3); context.put("sl-fruits", sl); context.put("fruits", fruits); context.put("flipper", new TestObject("flip",false)); context.registerTool("testTool", new TestTool()); System.out.println("- - - - - - - - - - - - - - - - - - - -"); System.out.println("Context contains: helloWorld, hello, file, TestObject[] fruits, SelectList sl(fruits, 3), TestObject flipper"); System.out.println("- - - - - - - - - - - - - - - - - - - -"); Template t1 = new StreamTemplate(wm.getBroker(), new InputStreamReader(System.in)); t1.parse(); Writer w = new OutputStreamWriter(System.out); System.out.println("*** RESULT ***"); t1.write(w,context); w.close(); System.out.println("*** DONE ***"); //System.out.println(result); } catch (Exception e) { e.printStackTrace(); } }
52513 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52513/df66bff2e7e90a14ae25f0c5642fd5199b077ad4/StreamTemplate.java/clean/webmacro/src/org/webmacro/engine/StreamTemplate.java
private void addRow(GridBagLayout gridbag, GridBagConstraints c, JPanel main, int index, DataObject data) { //The image has not been created. if (data instanceof ImageSummary) { main.add(new JLabel("The selected image hasn't been classified")); return; } JCheckBox box = new JCheckBox(); box.setSelected(true); String name = ""; if (data instanceof CategoryGroupData) { CategoryGroupData cg = (CategoryGroupData) data; name += cg.getName()+">"; List l = cg.getCategories(); if (l.size() == 1) { final CategoryData category = (CategoryData) l.get(0); name += category.getName(); box.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { setSelectedCategory(category); } }); } } else if (data instanceof CategoryData) { //i.e. the Category is orphan, shouldn't happen final CategoryData category = (CategoryData) data; name += category.getName(); box.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { setSelectedCategory(category); } }); } //init JLabel JLabel label = new JLabel(name); c.gridx = 0; c.gridy = index; gridbag.setConstraints(box, c); main.add(box); c.gridx = 1; gridbag.setConstraints(label, c); main.add(label); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/bf090ceeb0aed127b45849a8e8313a6788dd0e4d/RemoveWin.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clsf/RemoveWin.java
main.add(new JLabel("The selected image hasn't been classified"));
main.add(new JLabel(UNCLASSIFIED_TEXT));
private void addRow(GridBagLayout gridbag, GridBagConstraints c, JPanel main, int index, DataObject data) { //The image has not been created. if (data instanceof ImageSummary) { main.add(new JLabel("The selected image hasn't been classified")); return; } JCheckBox box = new JCheckBox(); box.setSelected(true); String name = ""; if (data instanceof CategoryGroupData) { CategoryGroupData cg = (CategoryGroupData) data; name += cg.getName()+">"; List l = cg.getCategories(); if (l.size() == 1) { final CategoryData category = (CategoryData) l.get(0); name += category.getName(); box.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { setSelectedCategory(category); } }); } } else if (data instanceof CategoryData) { //i.e. the Category is orphan, shouldn't happen final CategoryData category = (CategoryData) data; name += category.getName(); box.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { setSelectedCategory(category); } }); } //init JLabel JLabel label = new JLabel(name); c.gridx = 0; c.gridy = index; gridbag.setConstraints(box, c); main.add(box); c.gridx = 1; gridbag.setConstraints(label, c); main.add(label); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/bf090ceeb0aed127b45849a8e8313a6788dd0e4d/RemoveWin.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clsf/RemoveWin.java
cst.weightx = 0.5; cst.fill = GridBagConstraints.HORIZONTAL;
protected JComponent getClassifPanel() { JPanel main = new JPanel(); main.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); GridBagLayout gridbag = new GridBagLayout(); main.setLayout(gridbag); GridBagConstraints cst = new GridBagConstraints(); cst.ipadx = ClassifierWin.H_SPACE; cst.weightx = 0.5; cst.fill = GridBagConstraints.HORIZONTAL; cst.anchor = GridBagConstraints.EAST; Iterator i = availablePaths.iterator(); int index = 0; while (i.hasNext()) addRow(gridbag, cst, main, index, (DataObject) i.next()); return new JScrollPane(main); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/bf090ceeb0aed127b45849a8e8313a6788dd0e4d/RemoveWin.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clsf/RemoveWin.java
return new JScrollPane(main);
return new JScrollPane(UIUtilities.buildComponentPanel(main));
protected JComponent getClassifPanel() { JPanel main = new JPanel(); main.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); GridBagLayout gridbag = new GridBagLayout(); main.setLayout(gridbag); GridBagConstraints cst = new GridBagConstraints(); cst.ipadx = ClassifierWin.H_SPACE; cst.weightx = 0.5; cst.fill = GridBagConstraints.HORIZONTAL; cst.anchor = GridBagConstraints.EAST; Iterator i = availablePaths.iterator(); int index = 0; while (i.hasNext()) addRow(gridbag, cst, main, index, (DataObject) i.next()); return new JScrollPane(main); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/bf090ceeb0aed127b45849a8e8313a6788dd0e4d/RemoveWin.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clsf/RemoveWin.java
buildGUI();
ClassifierWin(Set availablePaths) { super(); if (availablePaths == null) throw new IllegalArgumentException("no paths"); setModal(true); setTitle("Classification"); //AttachWindow Listener addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { setClosed(); } }); buildGUI(); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/423006aa061b61c5fd6f0a1b95754e8a9a2c0fef/ClassifierWin.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clsf/ClassifierWin.java
private void buildGUI()
protected void buildGUI()
private void buildGUI() { IconManager icons = IconManager.getInstance(); TitlePanel tp = new TitlePanel("Classification", getWinTitle(), getWinNote(), icons.getIcon(IconManager.CATEGORY_BIG)); //Set layout and add components setLayout(new BorderLayout(0, 0)); add(tp, BorderLayout.NORTH); add(getClassifPanel(), BorderLayout.CENTER); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/423006aa061b61c5fd6f0a1b95754e8a9a2c0fef/ClassifierWin.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clsf/ClassifierWin.java
setLayout(new BorderLayout(0, 0)); add(tp, BorderLayout.NORTH); add(getClassifPanel(), BorderLayout.CENTER);
Container c = getContentPane(); c.setLayout(new BorderLayout(0, 0)); c.add(tp, BorderLayout.NORTH); c.add(getClassifPanel(), BorderLayout.CENTER);
private void buildGUI() { IconManager icons = IconManager.getInstance(); TitlePanel tp = new TitlePanel("Classification", getWinTitle(), getWinNote(), icons.getIcon(IconManager.CATEGORY_BIG)); //Set layout and add components setLayout(new BorderLayout(0, 0)); add(tp, BorderLayout.NORTH); add(getClassifPanel(), BorderLayout.CENTER); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/423006aa061b61c5fd6f0a1b95754e8a9a2c0fef/ClassifierWin.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clsf/ClassifierWin.java
firePropertyChange(SELECTED_CATEGORY_PROPERTY, oldValue, category);
firePropertyChange(SELECTED_CATEGORY_PROPERTY, oldValue, selected_category);
void setSelectedCategory(CategoryData category) { Object oldValue = selected_category; selected_category = category; firePropertyChange(SELECTED_CATEGORY_PROPERTY, oldValue, category); setClosed(); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/423006aa061b61c5fd6f0a1b95754e8a9a2c0fef/ClassifierWin.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clsf/ClassifierWin.java
try { ctx.getBeanFactory(); } catch (IllegalStateException ise) { ctx.refresh(); }
public static OmeroContext getInstance(String beanFactoryName) { OmeroContext ctx = (OmeroContext) ContextSingletonBeanFactoryLocator.getInstance() .useBeanFactory(beanFactoryName).getFactory(); return ctx; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/1da0af68c9386b826d75c04230a939952932997b/OmeroContext.java/buggy/components/common/src/ome/system/OmeroContext.java
public static OmeroContext getClientContext( Properties props )
public static OmeroContext getClientContext()
public static OmeroContext getClientContext( Properties props ) { if ( props == null ) throw new ApiUsageException( "Properties argument may not be null." ); Properties copy = new Properties( props ); ConstructorArgumentValues ctorArg = new ConstructorArgumentValues(); ctorArg.addGenericArgumentValue( copy ); BeanDefinition definition = new RootBeanDefinition(Properties.class, ctorArg, null); StaticApplicationContext staticContext = new StaticApplicationContext(); staticContext.registerBeanDefinition( "properties", definition ); staticContext.refresh(); OmeroContext ctx = new Locator( ).lookup( CLIENT_CONTEXT ); ctx.setParent( staticContext ); ctx.refresh(); return ctx; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/1da0af68c9386b826d75c04230a939952932997b/OmeroContext.java/buggy/components/common/src/ome/system/OmeroContext.java
if ( props == null ) throw new ApiUsageException( "Properties argument may not be null." ); Properties copy = new Properties( props ); ConstructorArgumentValues ctorArg = new ConstructorArgumentValues(); ctorArg.addGenericArgumentValue( copy ); BeanDefinition definition = new RootBeanDefinition(Properties.class, ctorArg, null); StaticApplicationContext staticContext = new StaticApplicationContext(); staticContext.registerBeanDefinition( "properties", definition ); staticContext.refresh(); OmeroContext ctx = new Locator( ).lookup( CLIENT_CONTEXT ); ctx.setParent( staticContext ); ctx.refresh(); return ctx;
synchronized (mutex) { if (_client == null) _client = getInstance(CLIENT_CONTEXT); return _client; }
public static OmeroContext getClientContext( Properties props ) { if ( props == null ) throw new ApiUsageException( "Properties argument may not be null." ); Properties copy = new Properties( props ); ConstructorArgumentValues ctorArg = new ConstructorArgumentValues(); ctorArg.addGenericArgumentValue( copy ); BeanDefinition definition = new RootBeanDefinition(Properties.class, ctorArg, null); StaticApplicationContext staticContext = new StaticApplicationContext(); staticContext.registerBeanDefinition( "properties", definition ); staticContext.refresh(); OmeroContext ctx = new Locator( ).lookup( CLIENT_CONTEXT ); ctx.setParent( staticContext ); ctx.refresh(); return ctx; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/1da0af68c9386b826d75c04230a939952932997b/OmeroContext.java/buggy/components/common/src/ome/system/OmeroContext.java
threadClass.defineMethod("run", callbackFactory.getMethod(ThreadClass.class, "run"));
public static RubyClass createThreadClass(Ruby ruby) { RubyClass threadClass = ruby.defineClass("Thread", ruby.getClasses().getObjectClass()); CallbackFactory callbackFactory = ruby.callbackFactory(); threadClass.defineMethod("[]", callbackFactory.getMethod(ThreadClass.class, "aref", IRubyObject.class)); threadClass.defineMethod("[]=", callbackFactory.getMethod(ThreadClass.class, "aset", IRubyObject.class, IRubyObject.class)); threadClass.defineMethod("abort_on_exception", callbackFactory.getMethod(ThreadClass.class, "abort_on_exception", IRubyObject.class)); threadClass.defineMethod("abort_on_exception=", callbackFactory.getMethod(ThreadClass.class, "abort_on_exception_set", IRubyObject.class, IRubyObject.class)); threadClass.defineMethod("alive?", callbackFactory.getMethod(ThreadClass.class, "is_alive")); threadClass.defineMethod("join", callbackFactory.getMethod(ThreadClass.class, "join")); threadClass.defineMethod("key?", callbackFactory.getMethod(ThreadClass.class, "has_key", IRubyObject.class)); threadClass.defineMethod("priority", callbackFactory.getMethod(ThreadClass.class, "priority")); threadClass.defineMethod("priority=", callbackFactory.getMethod(ThreadClass.class, "priority_set", IRubyObject.class)); threadClass.defineMethod("raise", callbackFactory.getMethod(ThreadClass.class, "raise", IRubyObject.class)); threadClass.defineMethod("status", callbackFactory.getMethod(ThreadClass.class, "status")); threadClass.defineSingletonMethod("current", callbackFactory.getSingletonMethod(ThreadClass.class, "current")); threadClass.defineSingletonMethod("fork", callbackFactory.getOptSingletonMethod(ThreadClass.class, "newInstance")); threadClass.defineSingletonMethod("new", callbackFactory.getOptSingletonMethod(ThreadClass.class, "newInstance")); threadClass.defineSingletonMethod("list", callbackFactory.getSingletonMethod(ThreadClass.class, "list")); threadClass.defineSingletonMethod("pass", callbackFactory.getSingletonMethod(ThreadClass.class, "pass")); threadClass.defineSingletonMethod("start", callbackFactory.getOptSingletonMethod(ThreadClass.class, "start")); threadClass.defineSingletonMethod("critical=", callbackFactory.getSingletonMethod(ThreadClass.class, "critical_set", RubyBoolean.class)); ThreadClass currentThread = new ThreadClass(ruby, threadClass); currentThread.jvmThread = Thread.currentThread(); ruby.getThreadService().setMainThread(currentThread); return threadClass; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/fe758a7c8ed9be7b679b8aef938333d27e876035/ThreadClass.java/buggy/src/org/jruby/ThreadClass.java
return new ReflectionCallbackMethod(type, method, false, true);
return new ReflectionCallbackMethod(type, method, new Class[0], false, true, 0);
public static Callback getSingletonMethod(Class type, String method) { return new ReflectionCallbackMethod(type, method, false, true); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/6076c5ab87d25a488469aa1a32f1d2c9c9e470b2/CallbackFactory.java/buggy/org/jruby/runtime/CallbackFactory.java
RubyException newException = new RubyException(ruby, excptnClass); newException.setInstanceVar("mesg", RubyString.m_newString(ruby, msg)); return newException; }
RubyException newException = new RubyException(ruby, excptnClass); newException.setInstanceVar("mesg", RubyString.m_newString(ruby, msg)); return newException; }
public static RubyException newException(Ruby ruby, RubyClass excptnClass, String msg) { RubyException newException = new RubyException(ruby, excptnClass); newException.setInstanceVar("mesg", RubyString.m_newString(ruby, msg)); return newException; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/0a7181933af700ea8025a4197f3a5ebcc08333c3/RubyException.java/buggy/org/jruby/RubyException.java
public IRubyObject callMethod(String name, IRubyObject arg) { return callMethod(name, new IRubyObject[] { arg });
public IRubyObject callMethod(String name, IRubyObject[] args) { return getMetaClass().call(this, name, args, CallType.FUNCTIONAL);
public IRubyObject callMethod(String name, IRubyObject arg) { return callMethod(name, new IRubyObject[] { arg }); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/0044a3b88a0afa22dcced1c8213002b0fb16faf4/RubyObject.java/buggy/src/org/jruby/RubyObject.java
block.setBlockObject(newProc);
newProc.block.setBlockObject(newProc);
public static RubyProc newProc(IRuby runtime, boolean isLambda) { ThreadContext tc = runtime.getCurrentContext(); if (!tc.isBlockGiven() && !tc.isFBlockGiven()) { throw runtime.newArgumentError("tried to create Proc object without a block"); } if (isLambda && !tc.isBlockGiven()) { // TODO: warn "tried to create Proc object without a block" } Block block = (Block) tc.getCurrentBlock(); if (!isLambda && block.getBlockObject() instanceof RubyProc) { return (RubyProc) block.getBlockObject(); } RubyProc newProc = new RubyProc(runtime, runtime.getClass("Proc")); newProc.block = block.cloneBlock(); newProc.wrapper = tc.getWrapper(); newProc.block.isLambda = isLambda; block.setBlockObject(newProc); return newProc; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/048e5b9179a657d1e786630b4cb43ae2bfdfbe4a/RubyProc.java/buggy/src/org/jruby/RubyProc.java
public static RubyString newString(Ruby ruby, String str) { return new RubyString(ruby, str);
public RubyString newString(String s) { RubyClass type = getInternalClass(); while (type.isIncluded() || type.isSingleton()) { type = type.getSuperClass(); } return new RubyString(getRuntime(), type, s);
public static RubyString newString(Ruby ruby, String str) { return new RubyString(ruby, str); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/071973606d94103b2d5cb6c793aa1e8809fc7b2a/RubyString.java/buggy/org/jruby/RubyString.java
timeClass.defineMethod("hash", CallbackFactory.getMethod(RubyTime.class, "hash"));
public static RubyClass createTimeClass(Ruby ruby) { RubyClass timeClass = ruby.defineClass("Time", ruby.getClasses().getObjectClass()); timeClass.includeModule(ruby.getClasses().getComparableModule()); timeClass.defineSingletonMethod("at", CallbackFactory.getOptSingletonMethod(RubyTime.class, "new_at")); timeClass.defineSingletonMethod("new", CallbackFactory.getSingletonMethod(RubyTime.class, "s_new")); timeClass.defineSingletonMethod("now", CallbackFactory.getSingletonMethod(RubyTime.class, "s_new")); timeClass.defineSingletonMethod("local", CallbackFactory.getOptSingletonMethod(RubyTime.class, "new_local")); timeClass.defineSingletonMethod("mktime", CallbackFactory.getOptSingletonMethod(RubyTime.class, "new_local")); timeClass.defineSingletonMethod("gm", CallbackFactory.getOptSingletonMethod(RubyTime.class, "new_utc")); timeClass.defineSingletonMethod("utc", CallbackFactory.getOptSingletonMethod(RubyTime.class, "new_utc")); timeClass.defineMethod("<=>", CallbackFactory.getMethod(RubyTime.class, "op_cmp", RubyObject.class)); timeClass.defineMethod("-", CallbackFactory.getMethod(RubyTime.class, "op_minus", RubyObject.class)); timeClass.defineMethod("+", CallbackFactory.getMethod(RubyTime.class, "op_plus", RubyObject.class)); timeClass.defineMethod("sec", CallbackFactory.getMethod(RubyTime.class, "sec")); timeClass.defineMethod("min", CallbackFactory.getMethod(RubyTime.class, "min")); timeClass.defineMethod("hour", CallbackFactory.getMethod(RubyTime.class, "hour")); timeClass.defineMethod("day", CallbackFactory.getMethod(RubyTime.class, "mday")); timeClass.defineMethod("mday", CallbackFactory.getMethod(RubyTime.class, "mday")); timeClass.defineMethod("mon", CallbackFactory.getMethod(RubyTime.class, "month")); timeClass.defineMethod("month", CallbackFactory.getMethod(RubyTime.class, "month")); timeClass.defineMethod("year", CallbackFactory.getMethod(RubyTime.class, "year")); timeClass.defineMethod("wday", CallbackFactory.getMethod(RubyTime.class, "wday")); timeClass.defineMethod("yday", CallbackFactory.getMethod(RubyTime.class, "yday")); timeClass.defineMethod("isdst", CallbackFactory.getMethod(RubyTime.class, "isdst")); timeClass.defineMethod("zone", CallbackFactory.getMethod(RubyTime.class, "zone")); timeClass.defineMethod("to_a", CallbackFactory.getMethod(RubyTime.class, "to_a")); timeClass.defineMethod("to_f", CallbackFactory.getMethod(RubyTime.class, "to_f")); timeClass.defineMethod("asctime", CallbackFactory.getMethod(RubyTime.class, "asctime")); timeClass.defineMethod("ctime", CallbackFactory.getMethod(RubyTime.class, "asctime")); timeClass.defineMethod("to_s", CallbackFactory.getMethod(RubyTime.class, "to_s")); timeClass.defineMethod("inspect", CallbackFactory.getMethod(RubyTime.class, "to_s")); timeClass.defineMethod("strftime", CallbackFactory.getMethod(RubyTime.class, "strftime", RubyObject.class)); timeClass.defineMethod("tv_usec", CallbackFactory.getMethod(RubyTime.class, "usec")); timeClass.defineMethod("usec", CallbackFactory.getMethod(RubyTime.class, "usec")); timeClass.defineMethod("tv_sec", CallbackFactory.getMethod(RubyTime.class, "to_i")); timeClass.defineMethod("to_i", CallbackFactory.getMethod(RubyTime.class, "to_i")); timeClass.defineMethod("gmtime", CallbackFactory.getMethod(RubyTime.class, "gmtime")); timeClass.defineMethod("utc", CallbackFactory.getMethod(RubyTime.class, "gmtime")); timeClass.defineMethod("gmt?", CallbackFactory.getMethod(RubyTime.class, "gmt")); timeClass.defineMethod("gmtime?", CallbackFactory.getMethod(RubyTime.class, "gmt")); timeClass.defineMethod("utc?", CallbackFactory.getMethod(RubyTime.class, "gmt")); timeClass.defineMethod("localtime", CallbackFactory.getMethod(RubyTime.class, "localtime")); return timeClass; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/7f0907240b4b4a4379424377e971ed0ca23f1dcb/RubyTime.java/clean/org/jruby/RubyTime.java
value = calendar.get(Calendar.WEEK_OF_YEAR);
calendar.setFirstDayOfWeek(Calendar.MONDAY); case FORMAT_WEEK_YEAR_S: value = calendar.get(Calendar.WEEK_OF_YEAR) - 1;
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { calendar.setTime(date); Iterator iter = compiledPattern.iterator(); while (iter.hasNext()) { Token token = (Token) iter.next(); switch (token.getFormat()) { case FORMAT_STRING: toAppendTo.append(token.getData()); break; case FORMAT_WEEK_LONG: toAppendTo.append(formatSymbols.getWeekdays()[calendar.get(Calendar.DAY_OF_WEEK)]); break; case FORMAT_WEEK_SHORT: toAppendTo.append(formatSymbols.getShortWeekdays()[calendar.get(Calendar.DAY_OF_WEEK)]); break; case FORMAT_MONTH_LONG: toAppendTo.append(formatSymbols.getMonths()[calendar.get(Calendar.MONTH)]); break; case FORMAT_MONTH_SHORT: toAppendTo.append(formatSymbols.getShortMonths()[calendar.get(Calendar.MONTH)]); break; case FORMAT_DAY: int value = calendar.get(Calendar.DAY_OF_MONTH); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_HOUR: value = calendar.get(Calendar.HOUR_OF_DAY); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_HOUR_M: value = calendar.get(Calendar.HOUR); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_DAY_YEAR: value = calendar.get(Calendar.DAY_OF_YEAR); if (value < 10) { toAppendTo.append("00"); } else if (value < 100) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_MINUTES: value = calendar.get(Calendar.MINUTE); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_MONTH: value = calendar.get(Calendar.MONTH) + 1; if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_MERIDIAN: if (calendar.get(Calendar.AM_PM) == Calendar.AM) { toAppendTo.append("AM"); } else { toAppendTo.append("PM"); } break; case FORMAT_SECONDS: value = calendar.get(Calendar.SECOND); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_WEEK_YEAR_M: value = calendar.get(Calendar.WEEK_OF_YEAR); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_WEEK_YEAR_S: value = calendar.get(Calendar.WEEK_OF_YEAR); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_DAY_WEEK: value = calendar.get(Calendar.DAY_OF_WEEK) - 1; toAppendTo.append(value); break; case FORMAT_YEAR_LONG: value = calendar.get(Calendar.YEAR); if (value < 10) { toAppendTo.append("000"); } else if (value < 100) { toAppendTo.append("00"); } else if (value < 1000) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_YEAR_SHORT: value = calendar.get(Calendar.YEAR) % 100; if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_ZONE_OFF: value = calendar.getTimeZone().getOffset(calendar.getTimeInMillis()); if (value < 0) { toAppendTo.append('+'); } else { toAppendTo.append('-'); } value = Math.abs(value); if (value / 3600000 < 10) { toAppendTo.append('0'); } toAppendTo.append(value / 3600000); value = value % 3600000 / 60000; if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_ZONE_ID: toAppendTo.append(calendar.getTimeZone().getDisplayName(calendar.get(Calendar.DST_OFFSET) != 0, TimeZone.SHORT)); break; } } return toAppendTo; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/76f879af69439b7f26a34059cedc0978624b042d/RubyDateFormat.java/buggy/src/org/jruby/util/RubyDateFormat.java
break; case FORMAT_WEEK_YEAR_S: value = calendar.get(Calendar.WEEK_OF_YEAR); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value);
calendar.setFirstDayOfWeek(Calendar.SUNDAY);
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { calendar.setTime(date); Iterator iter = compiledPattern.iterator(); while (iter.hasNext()) { Token token = (Token) iter.next(); switch (token.getFormat()) { case FORMAT_STRING: toAppendTo.append(token.getData()); break; case FORMAT_WEEK_LONG: toAppendTo.append(formatSymbols.getWeekdays()[calendar.get(Calendar.DAY_OF_WEEK)]); break; case FORMAT_WEEK_SHORT: toAppendTo.append(formatSymbols.getShortWeekdays()[calendar.get(Calendar.DAY_OF_WEEK)]); break; case FORMAT_MONTH_LONG: toAppendTo.append(formatSymbols.getMonths()[calendar.get(Calendar.MONTH)]); break; case FORMAT_MONTH_SHORT: toAppendTo.append(formatSymbols.getShortMonths()[calendar.get(Calendar.MONTH)]); break; case FORMAT_DAY: int value = calendar.get(Calendar.DAY_OF_MONTH); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_HOUR: value = calendar.get(Calendar.HOUR_OF_DAY); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_HOUR_M: value = calendar.get(Calendar.HOUR); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_DAY_YEAR: value = calendar.get(Calendar.DAY_OF_YEAR); if (value < 10) { toAppendTo.append("00"); } else if (value < 100) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_MINUTES: value = calendar.get(Calendar.MINUTE); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_MONTH: value = calendar.get(Calendar.MONTH) + 1; if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_MERIDIAN: if (calendar.get(Calendar.AM_PM) == Calendar.AM) { toAppendTo.append("AM"); } else { toAppendTo.append("PM"); } break; case FORMAT_SECONDS: value = calendar.get(Calendar.SECOND); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_WEEK_YEAR_M: value = calendar.get(Calendar.WEEK_OF_YEAR); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_WEEK_YEAR_S: value = calendar.get(Calendar.WEEK_OF_YEAR); if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_DAY_WEEK: value = calendar.get(Calendar.DAY_OF_WEEK) - 1; toAppendTo.append(value); break; case FORMAT_YEAR_LONG: value = calendar.get(Calendar.YEAR); if (value < 10) { toAppendTo.append("000"); } else if (value < 100) { toAppendTo.append("00"); } else if (value < 1000) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_YEAR_SHORT: value = calendar.get(Calendar.YEAR) % 100; if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_ZONE_OFF: value = calendar.getTimeZone().getOffset(calendar.getTimeInMillis()); if (value < 0) { toAppendTo.append('+'); } else { toAppendTo.append('-'); } value = Math.abs(value); if (value / 3600000 < 10) { toAppendTo.append('0'); } toAppendTo.append(value / 3600000); value = value % 3600000 / 60000; if (value < 10) { toAppendTo.append('0'); } toAppendTo.append(value); break; case FORMAT_ZONE_ID: toAppendTo.append(calendar.getTimeZone().getDisplayName(calendar.get(Calendar.DST_OFFSET) != 0, TimeZone.SHORT)); break; } } return toAppendTo; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/76f879af69439b7f26a34059cedc0978624b042d/RubyDateFormat.java/buggy/src/org/jruby/util/RubyDateFormat.java
return new RubyJavaObject(ruby, ruby.getRubyClass("JavaObject"), object);
return new RubyJavaObject(ruby, RubyJavaObject.getRubyClass(ruby, javaClass), object);
public static RubyObject convertJavaToRuby(Ruby ruby, Object object, Class javaClass) { if (object == null) { return ruby.getNil(); } if (javaClass == Boolean.TYPE || javaClass == Boolean.class) { return RubyBoolean.m_newBoolean(ruby, ((Boolean)object).booleanValue()); } if (javaClass == Integer.TYPE || javaClass == Integer.class || javaClass == Long.TYPE || javaClass == Long.class) { return RubyFixnum.m_newFixnum(ruby, ((Number)object).intValue()); } if (javaClass == Float.TYPE || javaClass == Float.class || javaClass == Double.TYPE || javaClass == Double.class) { return RubyFloat.m_newFloat(ruby, ((Number)object).doubleValue()); } if (javaClass == String.class) { return RubyString.m_newString(ruby, object.toString()); } return new RubyJavaObject(ruby, ruby.getRubyClass("JavaObject"), object); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/8e00ad1c7ae96f50ae0bd521483380788f891b7b/JavaUtil.java/clean/org/jruby/javasupport/JavaUtil.java
public RubyJavaObject(Ruby ruby, RubyModule rubyClass, Object value) { super(ruby, rubyClass); this.value = value;
public RubyJavaObject(Ruby ruby, RubyModule rubyClass) { this(ruby, rubyClass, null);
public RubyJavaObject(Ruby ruby, RubyModule rubyClass, Object value) { super(ruby, rubyClass); this.value = value; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/086abcd7e5107a6e6813ecb64810deff5780af95/RubyJavaObject.java/buggy/org/jruby/RubyJavaObject.java
new XmlMetadataGenerator(this, metaInfDir, destFile), new DocumentationGenerator(this, destFile), new XsdGenerator(this, destFile)
new XmlMetadataGenerator(metaInfDir, destFile), new DocumentationGenerator(destFile), new XsdGenerator(destFile)
public void execute() throws BuildException { if (namespace == null) { throw new BuildException("'namespace' must be specified"); } if (srcDir == null) { throw new BuildException("'srcDir' must be specified"); } if (destFile == null) { throw new BuildException("'destFile' must be specified"); } if (propertyEditorPaths != null) { List editorSearchPath = new LinkedList(Arrays.asList(PropertyEditorManager.getEditorSearchPath())); StringTokenizer paths = new StringTokenizer(propertyEditorPaths, " ,"); editorSearchPath.addAll(Collections.list(paths)); PropertyEditorManager.setEditorSearchPath((String[]) editorSearchPath.toArray(new String[editorSearchPath.size()])); } ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { String[] excludedClasses = null; if (this.excludedClasses != null) { excludedClasses = this.excludedClasses.split(" *, *"); } MappingLoader mappingLoader = new QdoxMappingLoader(namespace, getFiles(srcDir), excludedClasses); GeneratorPlugin[] plugins = new GeneratorPlugin[]{ new XmlMetadataGenerator(this, metaInfDir, destFile), new DocumentationGenerator(this, destFile), new XsdGenerator(this, destFile) }; // load the mappings Set namespaces = mappingLoader.loadNamespaces(); if (namespaces.isEmpty()) { System.out.println("Warning: no namespaces found!"); } // generate the files for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) { NamespaceMapping namespaceMapping = (NamespaceMapping) iterator.next(); for (int i = 0; i < plugins.length; i++) { GeneratorPlugin plugin = plugins[i]; plugin.generate(namespaceMapping); } } log("...done."); } catch (Exception e) { throw new BuildException(e); } finally { Thread.currentThread().setContextClassLoader(oldCL); } }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/82f8c1592f773a8e10d7a95ab3c2405dc29d8a3e/MappingGeneratorTask.java/clean/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/MappingGeneratorTask.java
plugin.setLog(this);
public void execute() throws BuildException { if (namespace == null) { throw new BuildException("'namespace' must be specified"); } if (srcDir == null) { throw new BuildException("'srcDir' must be specified"); } if (destFile == null) { throw new BuildException("'destFile' must be specified"); } if (propertyEditorPaths != null) { List editorSearchPath = new LinkedList(Arrays.asList(PropertyEditorManager.getEditorSearchPath())); StringTokenizer paths = new StringTokenizer(propertyEditorPaths, " ,"); editorSearchPath.addAll(Collections.list(paths)); PropertyEditorManager.setEditorSearchPath((String[]) editorSearchPath.toArray(new String[editorSearchPath.size()])); } ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { String[] excludedClasses = null; if (this.excludedClasses != null) { excludedClasses = this.excludedClasses.split(" *, *"); } MappingLoader mappingLoader = new QdoxMappingLoader(namespace, getFiles(srcDir), excludedClasses); GeneratorPlugin[] plugins = new GeneratorPlugin[]{ new XmlMetadataGenerator(this, metaInfDir, destFile), new DocumentationGenerator(this, destFile), new XsdGenerator(this, destFile) }; // load the mappings Set namespaces = mappingLoader.loadNamespaces(); if (namespaces.isEmpty()) { System.out.println("Warning: no namespaces found!"); } // generate the files for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) { NamespaceMapping namespaceMapping = (NamespaceMapping) iterator.next(); for (int i = 0; i < plugins.length; i++) { GeneratorPlugin plugin = plugins[i]; plugin.generate(namespaceMapping); } } log("...done."); } catch (Exception e) { throw new BuildException(e); } finally { Thread.currentThread().setContextClassLoader(oldCL); } }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/82f8c1592f773a8e10d7a95ab3c2405dc29d8a3e/MappingGeneratorTask.java/clean/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/MappingGeneratorTask.java
public XmlMetadataGenerator(LogFacade log, String metaInfDir, File schema) {
public XmlMetadataGenerator(String metaInfDir, File schema) {
public XmlMetadataGenerator(LogFacade log, String metaInfDir, File schema) { this.metaInfDir = metaInfDir; this.log = log; this.schema = schema; }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/82f8c1592f773a8e10d7a95ab3c2405dc29d8a3e/XmlMetadataGenerator.java/buggy/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
this.log = log;
public XmlMetadataGenerator(LogFacade log, String metaInfDir, File schema) { this.metaInfDir = metaInfDir; this.log = log; this.schema = schema; }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/82f8c1592f773a8e10d7a95ab3c2405dc29d8a3e/XmlMetadataGenerator.java/buggy/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
public DocumentationGenerator(LogFacade log, File destFile) {
public DocumentationGenerator(File destFile) {
public DocumentationGenerator(LogFacade log, File destFile) { this.destFile = destFile; this.log = log; }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/82f8c1592f773a8e10d7a95ab3c2405dc29d8a3e/DocumentationGenerator.java/buggy/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/DocumentationGenerator.java
this.log = log;
public DocumentationGenerator(LogFacade log, File destFile) { this.destFile = destFile; this.log = log; }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/82f8c1592f773a8e10d7a95ab3c2405dc29d8a3e/DocumentationGenerator.java/buggy/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/DocumentationGenerator.java
public XsdGenerator(LogFacade log, File destFile) {
public XsdGenerator(File destFile) {
public XsdGenerator(LogFacade log, File destFile) { this.destFile = destFile; this.log = log; }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/82f8c1592f773a8e10d7a95ab3c2405dc29d8a3e/XsdGenerator.java/buggy/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
this.log = log;
public XsdGenerator(LogFacade log, File destFile) { this.destFile = destFile; this.log = log; }
52533 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52533/82f8c1592f773a8e10d7a95ab3c2405dc29d8a3e/XsdGenerator.java/buggy/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java
public Frame() {
public Frame(Ruby ruby) { this.ruby = ruby;
public Frame() { }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f1e2c45b99e6f9a2be3f15f5fd7ad91c7e086a2c/Frame.java/buggy/org/jruby/interpreter/Frame.java
Frame oldFrame = new Frame(self, args, lastFunc, lastClass, cbase, prev,
Frame oldFrame = new Frame(ruby, self, args, lastFunc, lastClass, cbase, prev,
public void push() { Frame oldFrame = new Frame(self, args, lastFunc, lastClass, cbase, prev, tmp, file, line, iter, flags); prev = oldFrame; tmp = null; // file = null // line = // iter = // cbase = cbase; args = null; flags = FRAME_ALLOCA; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f1e2c45b99e6f9a2be3f15f5fd7ad91c7e086a2c/Frame.java/buggy/org/jruby/interpreter/Frame.java
args = null; flags = FRAME_ALLOCA;
iter = ruby.getInterpreter().getRubyIter().getIter(); args = null; flags = FRAME_ALLOCA;
public void push() { Frame oldFrame = new Frame(self, args, lastFunc, lastClass, cbase, prev, tmp, file, line, iter, flags); prev = oldFrame; tmp = null; // file = null // line = // iter = // cbase = cbase; args = null; flags = FRAME_ALLOCA; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/f1e2c45b99e6f9a2be3f15f5fd7ad91c7e086a2c/Frame.java/buggy/org/jruby/interpreter/Frame.java
recalculatePanNodes();
public void cameraResized(Rectangle2D cameraBounds) { // OK, so the hotspots will be the margins *unless* for some reason // someone was stupid enough to set the margins larger than the // bounds, in which case we'll do nothing because someone was stupid // enough to pull off that kind of nonsense. Heavens to Betsy. if(cameraBounds == null || cameraBounds.getWidth() <= edgeDistance*2 || cameraBounds.getHeight() <= edgeDistance*2) { invalidRegion = true; return; } else invalidRegion = false; this.cameraBounds = cameraBounds; recalculatePanNodes(); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/f82d914fe97ef0c74bef944bf12ae4961776c814/BrowserCamera.java/clean/SRC/org/openmicroscopy/shoola/agents/browser/ui/BrowserCamera.java
recalculatePanNodes();
public void setActiveRegion(Rectangle2D region) { if(region != null) { activeRegion = region; recalculatePanNodes(); } else { region = new Rectangle2D.Double(0,0,0,0); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/f82d914fe97ef0c74bef944bf12ae4961776c814/BrowserCamera.java/clean/SRC/org/openmicroscopy/shoola/agents/browser/ui/BrowserCamera.java
if (parentModel.getState() == HiViewer.LOADING_THUMBNAILS) {
if (parentModel.getState() == HiViewer.READY) {
public void stateChanged(ChangeEvent ce) { Object source = ce.getSource(); if (source instanceof HiViewer) { HiViewer parentModel = model.getParentModel(); if (parentModel.getState() == HiViewer.LOADING_THUMBNAILS) { parentModel.getBrowser().addPropertyChangeListener( Browser.SELECTED_DISPLAY_PROPERTY, this); } } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/0c7517f5d0ece413452f58f3f0a071be2ccbee2e/ClipBoardControl.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clipboard/ClipBoardControl.java
view.initListener();
public void stateChanged(ChangeEvent ce) { Object source = ce.getSource(); if (source instanceof HiViewer) { HiViewer parentModel = model.getParentModel(); if (parentModel.getState() == HiViewer.LOADING_THUMBNAILS) { parentModel.getBrowser().addPropertyChangeListener( Browser.SELECTED_DISPLAY_PROPERTY, this); } } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/0c7517f5d0ece413452f58f3f0a071be2ccbee2e/ClipBoardControl.java/buggy/SRC/org/openmicroscopy/shoola/agents/hiviewer/clipboard/ClipBoardControl.java
for (int i = 0, count = unmarshalInt(); i < count; i++) { result.setInstanceVariable(unmarshalObject().asSymbol(), unmarshalObject(proc)); }
defaultInstanceVarsUnmarshal(result, proc);
private IRubyObject defaultObjectUnmarshal(IRubyObject proc) throws IOException { RubySymbol className = (RubySymbol) unmarshalObject(); // ... FIXME: handle if class doesn't exist ... RubyClass type = (RubyClass) runtime.getClassFromPath(className.asSymbol()); assert type != null : "type shouldn't be null."; IRubyObject result = new RubyObject(runtime, type); registerLinkTarget(result); for (int i = 0, count = unmarshalInt(); i < count; i++) { result.setInstanceVariable(unmarshalObject().asSymbol(), unmarshalObject(proc)); } return result; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/d70012034b8795a6917f9e3b903281a59f12d372/UnmarshalStream.java/clean/src/org/jruby/runtime/marshal/UnmarshalStream.java
throw getRuntime().newArgumentError("dump format error(" + type + ")");
throw getRuntime().newArgumentError("dump format error(" + (char)type + ")");
private IRubyObject unmarshalObjectDirectly(int type, IRubyObject proc) throws IOException { IRubyObject rubyObj = null; switch (type) { case '0' : rubyObj = runtime.getNil(); break; case 'T' : rubyObj = runtime.getTrue(); break; case 'F' : rubyObj = runtime.getFalse(); break; case '"' : rubyObj = RubyString.unmarshalFrom(this); break; case 'i' : rubyObj = RubyFixnum.unmarshalFrom(this); break; case 'f' : rubyObj = RubyFloat.unmarshalFrom(this); break; case ':' : rubyObj = RubySymbol.unmarshalFrom(this); break; case '[' : rubyObj = RubyArray.unmarshalFrom(this); break; case '{' : rubyObj = RubyHash.unmarshalFrom(this); break; case 'c' : rubyObj = RubyClass.unmarshalFrom(this); break; case 'm' : rubyObj = RubyModule.unmarshalFrom(this); break; case 'l' : rubyObj = RubyBignum.unmarshalFrom(this); break; case 'S' : rubyObj = RubyStruct.unmarshalFrom(this); break; case 'o' : rubyObj = defaultObjectUnmarshal(proc); break; case 'u' : rubyObj = userUnmarshal(); break; case 'U' : rubyObj = userNewUnmarshal(); break; default : throw getRuntime().newArgumentError("dump format error(" + type + ")"); } if (proc != null) { proc.callMethod("call", new IRubyObject[] {rubyObj}); } return rubyObj; }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/d70012034b8795a6917f9e3b903281a59f12d372/UnmarshalStream.java/clean/src/org/jruby/runtime/marshal/UnmarshalStream.java
public String[] countFields(){ return (String[]) options.get(FIELDS);
public PojoOptions countFields(String[] fields) { options.put(FIELDS,fields); return this;
public String[] countFields(){ return (String[]) options.get(FIELDS); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/0b36a8e77f5bacb7e122d76ffce01866205b09d7/PojoOptions.java/buggy/components/common/src/ome/util/builders/PojoOptions.java
if ( l == null ) return;
public void addCounts(String field, Long id, Integer count) { int idx = Arrays.binarySearch(fields,field); if (idx < 0) return; if (count == null) return; Map<Long, IObject> l = lookup[idx]; IObject obj = l.get(id); if (obj == null) return; if (obj.getDetails() == null) obj.setDetails(new Details()); Map counts; if (obj.getDetails().getCounts() == null) { counts = new HashMap(); obj.getDetails().setCounts(counts); } else { counts = obj.getDetails().getCounts(); } Integer previous = (Integer) counts.get(field); if ( previous != null) { counts.put(field,new Integer(count.intValue()+previous.intValue())); } else { counts.put(field,count); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/0b36a8e77f5bacb7e122d76ffce01866205b09d7/CountCollector.java/buggy/components/server/src/ome/services/util/CountCollector.java
public PojoOptions(Map map){ if (null != map){ copy(map); } else { copy(new PojoOptions().map()); }
public PojoOptions(){ this.noLeaves().countsForUser() .countFields(new String[]{ Dataset.ANNOTATIONS, Image.ANNOTATIONS, Image.CATEGORYLINKS});
public PojoOptions(Map map){ if (null != map){ copy(map); } else { copy(new PojoOptions().map()); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/0b36a8e77f5bacb7e122d76ffce01866205b09d7/PojoOptions.java/buggy/components/common/src/ome/util/builders/PojoOptions.java
Iterator d = img.iterateOverDatasetLinks();
Iterator d = img.linkedDatasetIterator();
public static Set invertPDI(Set imagesAll) { Set cleared = new HashSet(); Set hierarchies = new HashSet(); Iterator i = imagesAll.iterator(); while (i.hasNext()) { Image img = (Image) i.next(); Iterator d = img.iterateOverDatasetLinks(); if ( ! d.hasNext() ) { hierarchies.add(img); } else { while (d.hasNext()) { Dataset ds = (Dataset) d.next(); if ( ! cleared.contains( ds )) { ds.clearImageLinks(); cleared.add( ds ); } ds.linkImage( img ); Iterator p = ds.iterateOverProjectLinks(); if ( ! p.hasNext() ) { hierarchies.add( ds ); } else { while (p.hasNext()) { Project prj = (Project) p.next(); if ( ! cleared.contains( p )) { prj.clearDatasetLinks(); cleared.add( prj ); } prj.linkDataset( ds ); hierarchies.add(prj); } } } } } return hierarchies; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/7b5c704279f82fa929138305f70f2f5e6b462c69/HierarchyTransformations.java/buggy/components/server/src/ome/tools/HierarchyTransformations.java
Iterator p = ds.iterateOverProjectLinks();
Iterator p = ds.linkedProjectIterator();
public static Set invertPDI(Set imagesAll) { Set cleared = new HashSet(); Set hierarchies = new HashSet(); Iterator i = imagesAll.iterator(); while (i.hasNext()) { Image img = (Image) i.next(); Iterator d = img.iterateOverDatasetLinks(); if ( ! d.hasNext() ) { hierarchies.add(img); } else { while (d.hasNext()) { Dataset ds = (Dataset) d.next(); if ( ! cleared.contains( ds )) { ds.clearImageLinks(); cleared.add( ds ); } ds.linkImage( img ); Iterator p = ds.iterateOverProjectLinks(); if ( ! p.hasNext() ) { hierarchies.add( ds ); } else { while (p.hasNext()) { Project prj = (Project) p.next(); if ( ! cleared.contains( p )) { prj.clearDatasetLinks(); cleared.add( prj ); } prj.linkDataset( ds ); hierarchies.add(prj); } } } } } return hierarchies; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/7b5c704279f82fa929138305f70f2f5e6b462c69/HierarchyTransformations.java/buggy/components/server/src/ome/tools/HierarchyTransformations.java
Iterator c = img.iterateOverCategoryLinks();
Iterator c = img.linkedCategoryIterator();
public static Set invertCGCI(Set imagesAll) { Set cleared = new HashSet(); Set hierarchies = new HashSet(); Iterator i = imagesAll.iterator(); while (i.hasNext()) { Image img = (Image) i.next(); Iterator c = img.iterateOverCategoryLinks(); if ( ! c.hasNext() ) { hierarchies.add(img); } else { while (c.hasNext()) { Category ca = (Category) c.next(); if ( ! cleared.contains( ca )) { ca.clearImageLinks(); cleared.add( ca ); } ca.linkImage( img ); Iterator g = ca.iterateOverCategoryGroupLinks(); if ( ! g.hasNext() ) { hierarchies.add(ca); } else { while (g.hasNext()){ CategoryGroup cg = (CategoryGroup) g.next(); if ( ! cleared.contains( cg )) { cg.clearCategoryLinks(); cleared.add( cg ); } cg.linkCategory( ca ); hierarchies.add( cg ); } } } } } return hierarchies; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/7b5c704279f82fa929138305f70f2f5e6b462c69/HierarchyTransformations.java/buggy/components/server/src/ome/tools/HierarchyTransformations.java
Iterator g = ca.iterateOverCategoryGroupLinks();
Iterator g = ca.linkedCategoryGroupIterator();
public static Set invertCGCI(Set imagesAll) { Set cleared = new HashSet(); Set hierarchies = new HashSet(); Iterator i = imagesAll.iterator(); while (i.hasNext()) { Image img = (Image) i.next(); Iterator c = img.iterateOverCategoryLinks(); if ( ! c.hasNext() ) { hierarchies.add(img); } else { while (c.hasNext()) { Category ca = (Category) c.next(); if ( ! cleared.contains( ca )) { ca.clearImageLinks(); cleared.add( ca ); } ca.linkImage( img ); Iterator g = ca.iterateOverCategoryGroupLinks(); if ( ! g.hasNext() ) { hierarchies.add(ca); } else { while (g.hasNext()){ CategoryGroup cg = (CategoryGroup) g.next(); if ( ! cleared.contains( cg )) { cg.clearCategoryLinks(); cleared.add( cg ); } cg.linkCategory( ca ); hierarchies.add( cg ); } } } } } return hierarchies; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/7b5c704279f82fa929138305f70f2f5e6b462c69/HierarchyTransformations.java/buggy/components/server/src/ome/tools/HierarchyTransformations.java
JUnitXMLHelper.validate(new File(PATH_TO_TEST_OUTPUT, htmlFiles[i]));
JUnitXMLHelper.readXmlFile(new File(PATH_TO_TEST_OUTPUT, htmlFiles[i]), true);
public void testHTMLReportValidity() throws Exception { // Serialize the current coverage data to disk ProjectData.saveGlobalProjectData(); String dataFileName = CoverageDataFileHandler.getDefaultDataFile().getAbsolutePath(); // Then we need to generate the HTML report String[] args = new String[] { "--format", "html", "--datafile", dataFileName, "--destination", PATH_TO_TEST_OUTPUT.getAbsolutePath(), PATH_TO_SOURCES.getAbsolutePath(), PATH_TO_SOURCES_2.getAbsolutePath() }; net.sourceforge.cobertura.reporting.Main.main(args); // Get all files from report directory String htmlFiles[] = PATH_TO_TEST_OUTPUT.list(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".html"); } }); Arrays.sort(htmlFiles); assertTrue(htmlFiles.length >= 5); // Assert that all required files are there String[] requiredFiles = { "index.html", "help.html", "frame-packages.html", "frame-summary.html", "frame-sourcefiles.html" }; for (int i = 0; i < requiredFiles.length; i++) { if (!containsFile(htmlFiles, requiredFiles[i])) { fail("File " + requiredFiles[i] + " not found among report files"); } } // Validate selected files String previousPrefix = "NONE"; for (int i = 0; i < htmlFiles.length; i++) { // Validate file if has prefix different than previous one, or is required file if (containsFile(requiredFiles, htmlFiles[i]) || !htmlFiles[i].startsWith(previousPrefix)) { JUnitXMLHelper.validate(new File(PATH_TO_TEST_OUTPUT, htmlFiles[i])); } if (htmlFiles[i].length() > 7) { previousPrefix = htmlFiles[i].substring(0, 7); } else { previousPrefix = htmlFiles[i]; } } // Mark that test was successful so report will be deleted testSuccessful = true; }
50197 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50197/9a1f242cd64dfc68f804c44562c72e3200447563/HTMLReportTest.java/clean/cobertura/test/net/sourceforge/cobertura/reporting/html/HTMLReportTest.java
Coverage coverage = CoverageUnmarshaller.parse(coverageData);
CoverageReport coverage = new CoverageReport(coverageData);
public static void main(String[] args) throws Exception { long startTime = System.currentTimeMillis(); LongOpt[] longOpts = new LongOpt[4]; longOpts[0] = new LongOpt("format", LongOpt.REQUIRED_ARGUMENT, null, 'f'); longOpts[1] = new LongOpt("instrumentation", LongOpt.REQUIRED_ARGUMENT, null, 'i'); longOpts[2] = new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null, 'o'); longOpts[3] = new LongOpt("source", LongOpt.REQUIRED_ARGUMENT, null, 's'); Getopt g = new Getopt(Main.class.getName(), args, ":f:i:o:s:", longOpts); int c; while ((c = g.getopt()) != -1) { switch (c) { case 'f': format = new String(g.getOptarg()); if (!format.equalsIgnoreCase("html") && !format.equalsIgnoreCase("xml")) { throw new Exception("Error: format \"" + format + "\" must be either html or xml"); } break; case 'i': serializationFile = new File(g.getOptarg()); if (!serializationFile.exists()) { throw new Exception("Error: serialization file " + serializationFile + " does not exist"); } if (serializationFile.isDirectory()) { throw new Exception("Error: serialization file " + serializationFile + " cannot be a directory"); } break; case 'o': outputDir = new File(g.getOptarg()); if (outputDir.exists() && outputDir.isFile()) { throw new Exception("Error: destination directory " + outputDir + " already exists and is a file"); } outputDir.mkdirs(); break; case 's': sourceDir = new File(g.getOptarg()); if (!sourceDir.exists()) { throw new Exception("Error: source directory " + sourceDir + " does not exist"); } if (sourceDir.isFile()) { throw new Exception("Error: source directory " + sourceDir + " should be a directory, not a file"); } break; } } if (logger.isDebugEnabled()) { logger.debug("format is " + format); logger.debug("serializationFile is " + serializationFile.getAbsolutePath()); logger.debug("outputDir is " + outputDir.getAbsolutePath()); logger.debug("sourceDir is " + sourceDir.getAbsolutePath()); } InputStream is = null; ObjectInputStream objects = null; try { is = new FileInputStream(serializationFile); objects = new ObjectInputStream(is); Map coverageData = (Map)objects.readObject(); Coverage coverage = CoverageUnmarshaller.parse(coverageData); if (format.equalsIgnoreCase("xml")) { new XMLReport(coverage, outputDir, sourceDir); } else if (format.equalsIgnoreCase("html")) { new HTMLReport(coverage, outputDir, sourceDir); } } finally { if (is != null) is.close(); if (objects != null) objects.close(); } long stopTime = System.currentTimeMillis(); System.out .println("Reporting time: " + (stopTime - startTime) + "ms"); }
50197 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50197/100512ee483a0d8eebc3eb78a5d8913b7b64ddb6/Main.java/buggy/cobertura/src/net/sourceforge/cobertura/reporting/Main.java
if (isSessionBoundToThread())
Session session = nullOrSessionBoundToThread(); if (session != null)
private void closeSession() throws Exception { if (isSessionBoundToThread()) { debug("Session bound to thread. Closing."); Session session = sessionBoundToThread(); try { session.connection().commit(); sessionBoundToThread().close(); } finally { resetThreadSession(); } } else { debug("No session bound to thread. Can't close."); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
Session session = sessionBoundToThread();
private void closeSession() throws Exception { if (isSessionBoundToThread()) { debug("Session bound to thread. Closing."); Session session = sessionBoundToThread(); try { session.connection().commit(); sessionBoundToThread().close(); } finally { resetThreadSession(); } } else { debug("No session bound to thread. Can't close."); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
sessionBoundToThread().close();
session.close();
private void closeSession() throws Exception { if (isSessionBoundToThread()) { debug("Session bound to thread. Closing."); Session session = sessionBoundToThread(); try { session.connection().commit(); sessionBoundToThread().close(); } finally { resetThreadSession(); } } else { debug("No session bound to thread. Can't close."); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
if (isSessionBoundToThread() && sessionBoundToThread().isConnected())
Session session = nullOrSessionBoundToThread(); if ( session != null && session.isConnected())
private void disconnectSession() throws HibernateException { if (isSessionBoundToThread() && sessionBoundToThread().isConnected()) { debug("Session bound to thread. Disconnecting."); sessionBoundToThread().disconnect(); } else { debug("No session bound to thread. Can't disconnect."); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
sessionBoundToThread().disconnect();
session.disconnect();
private void disconnectSession() throws HibernateException { if (isSessionBoundToThread() && sessionBoundToThread().isConnected()) { debug("Session bound to thread. Disconnecting."); sessionBoundToThread().disconnect(); } else { debug("No session bound to thread. Can't disconnect."); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
private void disconnectSession() throws HibernateException { if (isSessionBoundToThread() && sessionBoundToThread().isConnected()) { debug("Session bound to thread. Disconnecting."); sessionBoundToThread().disconnect(); } else { debug("No session bound to thread. Can't disconnect."); } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
newOrRestoredSession(invocation);
status = newOrRestoredSession(invocation); status.session.setFlushMode( FlushMode.MANUAL );
private Object doStateful(MethodInvocation invocation) throws Throwable { Object result = null; try { newOrRestoredSession(invocation); result = invocation.proceed(); return result; } catch (Throwable e) { e.printStackTrace(); throw e; } finally { try { if (isCloseSession(invocation)) { closeSession(); } else { disconnectSession(); } } catch (Exception e) { debug("Error while closing/disconnecting session."); } finally { resetThreadSession(); // Everything successfully turned off. Decrement. if (sessions.containsKey(invocation.getThis())) { sessions.get(invocation.getThis()).calls--; } } } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
disconnectSession();
if (status != null ) { status.session.setFlushMode( FlushMode.MANUAL ); disconnectSession(); }
private Object doStateful(MethodInvocation invocation) throws Throwable { Object result = null; try { newOrRestoredSession(invocation); result = invocation.proceed(); return result; } catch (Throwable e) { e.printStackTrace(); throw e; } finally { try { if (isCloseSession(invocation)) { closeSession(); } else { disconnectSession(); } } catch (Exception e) { debug("Error while closing/disconnecting session."); } finally { resetThreadSession(); // Everything successfully turned off. Decrement. if (sessions.containsKey(invocation.getThis())) { sessions.get(invocation.getThis()).calls--; } } } }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
Session currentSession = acquireBindAndConfigureSession();
Session currentSession = acquireAndBindSession();
private SessionStatus newOrRestoredSession(MethodInvocation invocation) throws HibernateException { SessionStatus status = sessions.get(invocation.getThis()); Session previousSession = ! isSessionBoundToThread() ? null : sessionBoundToThread(); // a session is currently running. // something has gone wrong (e.g. with cleanup) abort! if ( previousSession != null ) { String msg = "Dirty Hibernate Session " + sessionBoundToThread() + " found in Thread " + Thread.currentThread(); sessionBoundToThread().close(); resetThreadSession(); throw new InternalException(msg); } // we may or may not be in a session, but if we haven't yet bound // it to This, then we need to. else if (status == null || !status.session.isOpen()) { Session currentSession = acquireBindAndConfigureSession(); status = new SessionStatus( currentSession ); sessions.put(invocation.getThis(), status); } // the session bound to This is already currently being called. abort! else if (status.calls > 1) { throw new InternalException( "Hibernate session is not re-entrant.\n" + "Either you have two threads operating on the same " + "stateful object (don't do this)\n or you have a " + "recursive call (recurse on the unwrapped object). "); } // all is fine. else { debug("Binding and reconnecting session."); bindSession(status.session); reconnectSession(status.session); } // It's ready to be used. Increment. status.calls++; return status; }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/abb75611ecbe8038586bfc5b8903fe7fb0b36a3e/SessionHandler.java/clean/components/server/src/ome/tools/hibernate/SessionHandler.java
assertEquals(":[-1,-1]:[0,0]: A message (NameError)\n", err.toString());
public void testPrintErrorShouldOnlyPrintErrorMessageWhenBacktraceIsNil() { ByteArrayOutputStream err = new ByteArrayOutputStream(); IRuby ruby = Ruby.newInstance(System.in, System.out, new PrintStream(err), false); RubyException exception = new RubyException(ruby, ruby.getClass("NameError"), "A message"); ruby.printError(exception); assertEquals(":[-1,-1]:[0,0]: A message (NameError)\n", err.toString()); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/af07dd9e2d788cd1a5151ea8833909422495f7c4/TestRuby.java/buggy/test/org/jruby/test/TestRuby.java
super(name); }
super(name); }
public TestRubyBase(String name) { super(name); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/774c5d3d592dfd020e3a8f961b73f629c4c55cf0/TestRubyBase.java/buggy/org/jruby/test/TestRubyBase.java
super(ruby, rubyClass); }
super(ruby, rubyClass); }
public RubyException(Ruby ruby, RubyClass rubyClass) { super(ruby, rubyClass); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/0a7181933af700ea8025a4197f3a5ebcc08333c3/RubyException.java/buggy/org/jruby/RubyException.java
pipeIn = new PipedInputStream(); in = new BufferedReader(new InputStreamReader(pipeIn));
pipeIn = new PipedInputStream(); in = new BufferedReader(new InputStreamReader(pipeIn));
protected String eval(String script) { pipeIn = new PipedInputStream(); in = new BufferedReader(new InputStreamReader(pipeIn)); String output = null; StringBuffer result = new StringBuffer(); try { out = new PrintStream(new PipedOutputStream(pipeIn), true); // ruby.getRuntime().setOutputStream(out); // ruby.getRuntime().setErrorStream(out); RubyIO lStream = new RubyIO(ruby); lStream.initIO(null, out, null); ruby.setGlobalVar("$stdout", lStream); ruby.setGlobalVar("$>", lStream); lStream = (RubyIO) ruby.getGlobalVar("$stderr"); lStream.initIO(null,out,null); ruby.setGlobalVar("$stderr", lStream); new EvalThread("test", script).start(); while ((output = in.readLine()) != null) { result.append(output); } } catch (Exception ex) { throw new RuntimeException(ex.getMessage()); } return result.toString(); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/774c5d3d592dfd020e3a8f961b73f629c4c55cf0/TestRubyBase.java/buggy/org/jruby/test/TestRubyBase.java
String output = null; StringBuffer result = new StringBuffer(); try { out = new PrintStream(new PipedOutputStream(pipeIn), true); RubyIO lStream = new RubyIO(ruby); lStream.initIO(null, out, null); ruby.setGlobalVar("$stdout", lStream); ruby.setGlobalVar("$>", lStream); lStream = (RubyIO) ruby.getGlobalVar("$stderr"); lStream.initIO(null,out,null); ruby.setGlobalVar("$stderr", lStream); new EvalThread("test", script).start(); while ((output = in.readLine()) != null) { result.append(output); } } catch (Exception ex) { throw new RuntimeException(ex.getMessage()); } return result.toString(); }
String output = null; StringBuffer result = new StringBuffer(); try { out = new PrintStream(new PipedOutputStream(pipeIn), true); RubyIO lStream = new RubyIO(ruby); lStream.initIO(null, out, null); ruby.setGlobalVar("$stdout", lStream); ruby.setGlobalVar("$>", lStream); lStream = (RubyIO) ruby.getGlobalVar("$stderr"); lStream.initIO(null, out, null); ruby.setGlobalVar("$stderr", lStream); new EvalThread("test", script).start(); while ((output = in.readLine()) != null) { result.append(output); } } catch (Exception ex) { throw new RuntimeException(ex.getMessage()); } return result.toString(); }
protected String eval(String script) { pipeIn = new PipedInputStream(); in = new BufferedReader(new InputStreamReader(pipeIn)); String output = null; StringBuffer result = new StringBuffer(); try { out = new PrintStream(new PipedOutputStream(pipeIn), true); // ruby.getRuntime().setOutputStream(out); // ruby.getRuntime().setErrorStream(out); RubyIO lStream = new RubyIO(ruby); lStream.initIO(null, out, null); ruby.setGlobalVar("$stdout", lStream); ruby.setGlobalVar("$>", lStream); lStream = (RubyIO) ruby.getGlobalVar("$stderr"); lStream.initIO(null,out,null); ruby.setGlobalVar("$stderr", lStream); new EvalThread("test", script).start(); while ((output = in.readLine()) != null) { result.append(output); } } catch (Exception ex) { throw new RuntimeException(ex.getMessage()); } return result.toString(); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/774c5d3d592dfd020e3a8f961b73f629c4c55cf0/TestRubyBase.java/buggy/org/jruby/test/TestRubyBase.java
public RubyClass(Ruby ruby, RubyModule rubyClass, RubyModule superClass) { super(ruby, rubyClass, superClass);
public RubyClass(Ruby ruby) { this(ruby, null);
public RubyClass(Ruby ruby, RubyModule rubyClass, RubyModule superClass) { super(ruby, rubyClass, superClass); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyClass.java/buggy/org/jruby/RubyClass.java
connectMenu.remove(item);
public void initialize() { if (Spark.isMac()) { roomListener = new DockRoomListener(); SparkManager.getChatManager().addChatRoomListener(roomListener); // Remove the About Menu Item from the help menu MainWindow mainWindow = SparkManager.getMainWindow(); JMenu helpMenu = mainWindow.getMenuByName("Help"); Component[] menuComponents = helpMenu.getMenuComponents(); Component prev = null; for (int i = 0; i < menuComponents.length; i++) { Component current = menuComponents[i]; if (current instanceof JMenuItem) { JMenuItem item = (JMenuItem) current; if ("About".equals(item.getText())) { helpMenu.remove(item); // We want to remove the seperator if (prev != null && (prev instanceof JSeparator)) { helpMenu.remove(prev); } } } prev = current; } JMenu connectMenu = mainWindow.getMenuByName("Spark"); connectMenu.setText("Connect"); menuComponents = connectMenu.getMenuComponents(); JSeparator lastSeperator = null; for (int i = 0; i < menuComponents.length; i++) { Component current = menuComponents[i]; if (current instanceof JMenuItem) { JMenuItem item = (JMenuItem) current; if ("Preferences".equals(item.getText())) { //connectMenu.remove(item); } else if ("Log Out".equals(item.getText())) { connectMenu.remove(item); } } else if (current instanceof JSeparator) { lastSeperator = (JSeparator) current; } } if (lastSeperator != null) { connectMenu.remove(lastSeperator); } // register an application listener to show the about box Application application = Application.getApplication(); // application.setEnabledPreferencesMenu(true); // application.addPreferencesMenuItem(); application.addApplicationListener(new ApplicationAdapter() { public void handlePreferences(ApplicationEvent applicationEvent) { SparkManager.getPreferenceManager().showPreferences(); } public void handleReOpenApplication(ApplicationEvent event) { MainWindow mainWindow = SparkManager.getMainWindow(); if (!mainWindow.isVisible()) { mainWindow.setState(Frame.NORMAL); mainWindow.setVisible(true); } } public void handleQuit(ApplicationEvent applicationEvent) { System.exit(0); } }); new AppleStatusMenu().display(); } }
52006 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52006/25c0f6db5fc8e92ad52f6a354c86118d3658649b/ApplePlugin.java/clean/src/plugins/apple/src/com/jivesoftware/spark/plugin/apple/ApplePlugin.java
application.setEnabledPreferencesMenu(true); application.addPreferencesMenuItem();
public void initialize() { if (Spark.isMac()) { roomListener = new DockRoomListener(); SparkManager.getChatManager().addChatRoomListener(roomListener); // Remove the About Menu Item from the help menu MainWindow mainWindow = SparkManager.getMainWindow(); JMenu helpMenu = mainWindow.getMenuByName("Help"); Component[] menuComponents = helpMenu.getMenuComponents(); Component prev = null; for (int i = 0; i < menuComponents.length; i++) { Component current = menuComponents[i]; if (current instanceof JMenuItem) { JMenuItem item = (JMenuItem) current; if ("About".equals(item.getText())) { helpMenu.remove(item); // We want to remove the seperator if (prev != null && (prev instanceof JSeparator)) { helpMenu.remove(prev); } } } prev = current; } JMenu connectMenu = mainWindow.getMenuByName("Spark"); connectMenu.setText("Connect"); menuComponents = connectMenu.getMenuComponents(); JSeparator lastSeperator = null; for (int i = 0; i < menuComponents.length; i++) { Component current = menuComponents[i]; if (current instanceof JMenuItem) { JMenuItem item = (JMenuItem) current; if ("Preferences".equals(item.getText())) { //connectMenu.remove(item); } else if ("Log Out".equals(item.getText())) { connectMenu.remove(item); } } else if (current instanceof JSeparator) { lastSeperator = (JSeparator) current; } } if (lastSeperator != null) { connectMenu.remove(lastSeperator); } // register an application listener to show the about box Application application = Application.getApplication(); // application.setEnabledPreferencesMenu(true); // application.addPreferencesMenuItem(); application.addApplicationListener(new ApplicationAdapter() { public void handlePreferences(ApplicationEvent applicationEvent) { SparkManager.getPreferenceManager().showPreferences(); } public void handleReOpenApplication(ApplicationEvent event) { MainWindow mainWindow = SparkManager.getMainWindow(); if (!mainWindow.isVisible()) { mainWindow.setState(Frame.NORMAL); mainWindow.setVisible(true); } } public void handleQuit(ApplicationEvent applicationEvent) { System.exit(0); } }); new AppleStatusMenu().display(); } }
52006 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/52006/25c0f6db5fc8e92ad52f6a354c86118d3658649b/ApplePlugin.java/clean/src/plugins/apple/src/com/jivesoftware/spark/plugin/apple/ApplePlugin.java
if (f1.exists() != f2.exists() && f1.isFile() != f2.isFile() && f1.isDirectory() != f2.isDirectory())
if (f1.exists() != f2.exists() || f1.isFile() != f2.isFile() || f1.isDirectory() != f2.isDirectory())
public static boolean contentsEqual(File f1, File f2, boolean ignoreWhitespace) throws IOException { if (f1 == f2) return true; if (f1 == null && f2 == null) return true; if (f1 == null || f2 == null) return false; if (f1.exists() != f2.exists() && f1.isFile() != f2.isFile() && f1.isDirectory() != f2.isDirectory()) return false; if (!f1.exists()) return true; if (f1.isDirectory()) { final File[] files1 = f1.listFiles(); for (final File file1 : files1) { final File file2 = new File(f2, file1.getName()); if (!contentsEqual(file1, file2, ignoreWhitespace)) return false; } // TODO same quantity of files return true; } else { Reader r1 = null; Reader r2 = null; try { r1 = new FileReader(f1); r2 = new FileReader(f2); if (!IOUtils.contentsEqual(r1, r2, ignoreWhitespace)) return false; } finally { try { if (r1 != null) r1.close(); } catch (IOException ignored) { } try { if (r2 != null) r2.close(); } catch (IOException ignored) { } } return true; } }
53231 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/53231/b4e947c77517c73db921d02a7471df7db67e53da/FileUtils.java/clean/branches/lexi-19102006/codemodel/codemodel/src/test/java/com/sun/codemodel/tests/util/FileUtils.java
parent.buildGroupList();
parent.buildCategoryList(group);
public void actionPerformed(ActionEvent arg0) { saveButton.setEnabled(false); cancelButton.setEnabled(false); control.newCategory(group,nameField.getText(), descriptionArea.getText()); parent.buildGroupList(); setVisible(false); dispose(); }
54698 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/54698/6b6fb3d79e056966af9613826e3acb47d46b3abe/CategoryEditUI.java/clean/SRC/org/openmicroscopy/shoola/agents/classifier/CategoryEditUI.java
singletonClass.setParentModule((RubyModule) receiver);
singletonClass.setParentModule(runtime.getRubyClass());
public void visitSClassNode(SClassNode iVisited) { IRubyObject receiver = eval(iVisited.getReceiverNode()); RubyClass singletonClass; if (receiver.isNil()) { singletonClass = runtime.getClasses().getNilClass(); } else if (receiver == runtime.getTrue()) { singletonClass = runtime.getClasses().getTrueClass(); } else if (receiver == runtime.getFalse()) { singletonClass = runtime.getClasses().getFalseClass(); } else { if (runtime.getSafeLevel() >= 4 && !receiver.isTaint()) { throw new SecurityError(runtime, "Insecure: can't extend object."); } if (receiver.getMetaClass() instanceof MetaClass) { RubyModule.clearMethodCache(runtime); } singletonClass = receiver.getSingletonClass(); singletonClass.setParentModule((RubyModule) receiver); } if (threadContext.getWrapper() != null) { singletonClass.extendObject(threadContext.getWrapper()); singletonClass.includeModule(threadContext.getWrapper()); } evalClassDefinitionBody(iVisited.getBodyNode(), singletonClass); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/d5b4eb9cfd95f0bc424c7969a5ac09a0d9423a66/EvaluateVisitor.java/buggy/src/org/jruby/evaluator/EvaluateVisitor.java
public RubyArray newArray(IRubyObject object) { return RubyArray.newArray(this, object);
public RubyArray newArray() { return RubyArray.newArray(this);
public RubyArray newArray(IRubyObject object) { return RubyArray.newArray(this, object); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/02f1a36be6c43bcb5b541cf429a4a8e0a2280750/Ruby.java/buggy/src/org/jruby/Ruby.java
NODE orig = searchMethod(oldId); RubyModule origin = getMethodOrigin(oldId);
SearchMethodResult smr = searchMethod(oldId); NODE orig = smr.getBody(); RubyModule origin = smr.getOrigin();
public void aliasMethod(RubyId newId, RubyId oldId) { testFrozen(); if (oldId == newId) { return; } if (this == getRuby().getClasses().getObjectClass()) { getRuby().secure(4); } NODE orig = searchMethod(oldId); RubyModule origin = getMethodOrigin(oldId); if (orig == null || orig.nd_body() == null) { if (isModule()) { orig = getRuby().getClasses().getObjectClass().searchMethod(oldId); origin = getRuby().getClasses().getObjectClass().getMethodOrigin(oldId); } } if (orig == null || orig.nd_body() == null) { // print_undef( klass, def ); } NODE body = orig.nd_body(); orig.nd_cnt(orig.nd_cnt() + 1); if (body.nd_type() == NODE_FBODY) { /* was alias */ oldId = (RubyId)body.nd_mid(); origin = (RubyModule)body.nd_orig(); body = body.nd_head(); } getMethods().put(newId, NODE.newMethod(NODE.newFBody(body, oldId, origin), orig.nd_noex())); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyModule.java/buggy/org/jruby/RubyModule.java
orig = getRuby().getClasses().getObjectClass().searchMethod(oldId); origin = getRuby().getClasses().getObjectClass().getMethodOrigin(oldId);
smr = getRuby().getClasses().getObjectClass().searchMethod(oldId); orig = smr.getBody(); origin = smr.getOrigin();
public void aliasMethod(RubyId newId, RubyId oldId) { testFrozen(); if (oldId == newId) { return; } if (this == getRuby().getClasses().getObjectClass()) { getRuby().secure(4); } NODE orig = searchMethod(oldId); RubyModule origin = getMethodOrigin(oldId); if (orig == null || orig.nd_body() == null) { if (isModule()) { orig = getRuby().getClasses().getObjectClass().searchMethod(oldId); origin = getRuby().getClasses().getObjectClass().getMethodOrigin(oldId); } } if (orig == null || orig.nd_body() == null) { // print_undef( klass, def ); } NODE body = orig.nd_body(); orig.nd_cnt(orig.nd_cnt() + 1); if (body.nd_type() == NODE_FBODY) { /* was alias */ oldId = (RubyId)body.nd_mid(); origin = (RubyModule)body.nd_orig(); body = body.nd_head(); } getMethods().put(newId, NODE.newMethod(NODE.newFBody(body, oldId, origin), orig.nd_noex())); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyModule.java/buggy/org/jruby/RubyModule.java
public static RubyBignum newBignum(Ruby ruby, BigInteger value) { return new RubyBignum(ruby, value);
public static RubyBignum newBignum(Ruby ruby, long value) { return newBignum(ruby, BigInteger.valueOf(value));
public static RubyBignum newBignum(Ruby ruby, BigInteger value) { return new RubyBignum(ruby, value); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/071973606d94103b2d5cb6c793aa1e8809fc7b2a/RubyBignum.java/buggy/org/jruby/RubyBignum.java
public RubyObject call(RubyObject recv, RubyId id, RubyObject[] args, int scope) {
public RubyObject call(RubyObject recv, RubyId mid, RubyObject[] args, int scope) { MethodCacheEntry ent = MethodCacheEntry.getEntry(getRuby(), this, mid); RubyModule klass = this; RubyId id = mid; int noex; NODE body; if (ent != null) { if (ent.getMethod() == null) { throw new RuntimeException("Undefined"); } klass = ent.getOrigin(); id = ent.getMid0(); noex = ent.getNoex(); body = ent.getMethod(); } else { GetMethodBodyResult gmbr = getMethodBody(id, 0); klass = gmbr.getKlass(); id = gmbr.getId(); noex = gmbr.getNoex(); body = gmbr.getBody(); if (body == null) { if (scope == 3) { throw new RubyNameException("super: no superclass method '" + mid.toName() + "'"); } throw new RuntimeException("Undefined"); } }
public RubyObject call(RubyObject recv, RubyId id, RubyObject[] args, int scope) { // ... NODE body = getMethodBody(id, scope); return call0(recv, id, args, body, false); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyModule.java/buggy/org/jruby/RubyModule.java
NODE body = getMethodBody(id, scope); return call0(recv, id, args, body, false);
return klass.call0(recv, id, args, body, false);
public RubyObject call(RubyObject recv, RubyId id, RubyObject[] args, int scope) { // ... NODE body = getMethodBody(id, scope); return call0(recv, id, args, body, false); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyModule.java/buggy/org/jruby/RubyModule.java
throw runtime.newNameError("superclass method '" + frame.getLastFunc() + "' must be enabled by enableSuper().");
String name = frame.getLastFunc(); throw runtime.newNameError("superclass method '" + name + "' must be enabled by enableSuper().", name);
public IRubyObject callSuper(IRubyObject[] args) { Frame frame = getCurrentFrame(); if (frame.getLastClass() == null) { throw runtime.newNameError("superclass method '" + frame.getLastFunc() + "' must be enabled by enableSuper()."); } setNoBlockIfNoBlock(); try { RubyClass superClass = frame.getLastClass().getSuperClass(); // Modules do not directly inherit Object so we have hacks like this if (superClass == null) { // TODO cnutter: I believe modules, the only ones here to have no superclasses, should have Module as their superclass superClass = runtime.getClass("Module"); } return frame.getSelf().callMethod(this, superClass, frame.getLastFunc(), args, CallType.SUPER); } finally { clearNoBlock(); } }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/1278c5bb3507a052d150d814f15453542ae41aed/ThreadContext.java/buggy/src/org/jruby/runtime/ThreadContext.java
NODE body = searchMethod(id);
NODE body = searchMethod(id).getBody();
public void undef(RubyId id) { if (this == getRuby().getClasses().getObjectClass()) { getRuby().secure(4); } if (getRuby().getSecurityLevel() >= 4 && !isTaint()) { throw new SecurityException("Insecure: can't undef"); } testFrozen(); if (id == getRuby().intern("__id__") || id == getRuby().intern("__send__")) { /*rb_warn("undefining `%s' may cause serious problem", rb_id2name( id ) );*/ } NODE body = searchMethod(id); if (body == null || body.nd_body() == null) { String s0 = " class"; RubyModule c = this; if (c.isSingleton()) { RubyObject obj = getInstanceVar("__attached__"); if (obj instanceof RubyModule) { c = (RubyModule)obj; s0 = ""; } } else if (c.isModule()) { s0 = " module"; } throw new RubyNameException("undefined method " + id.toName() + " for" + s0 + " '" + c.toName() + "'"); } addMethod(id, null, NOEX_PUBLIC); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/03950522a75c28f406bd4cb011cb1916a662366d/RubyModule.java/buggy/org/jruby/RubyModule.java
ruby_cref = ruby_cref.nd_next();
ruby.setRubyCRef(ruby.getRubyCRef().nd_next());
private void POP_CREF() { ruby_cref = ruby_cref.nd_next(); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
ruby_cref = new NODE(NODE_CREF, c, null, ruby_cref);
ruby.setRubyCRef(new NODE(NODE.NODE_CREF, c, null, ruby.getRubyCRef()));
private void PUSH_CREF(Object c) { ruby_cref = new NODE(NODE_CREF, c, null, ruby_cref); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
ruby.setRubyClass(ruby.getClasses().getObjectClass()); ruby_cbase = null;
public RubyInterpreter(Ruby ruby) { this.ruby = ruby; ruby.setRubyClass(ruby.getClasses().getObjectClass()); ruby_cbase = null; rubyBlock = new RubyBlock(ruby); }
50661 /local/tlutelli/issta_data/temp/all_java5context/java/2006_temp/2006/50661/cf644c556d410c47305ebeba5728efa25f7756dc/RubyInterpreter.java/clean/org/jruby/interpreter/RubyInterpreter.java
if (getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + rubyFrame.getLastFunc().toName() + "' disabled");
if (ruby.getRubyFrame().getLastClass() == null) { throw new RubyNameException("superclass method '" + ruby.getRubyFrame().getLastFunc().toName() + "' disabled");
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
List argsList = getRubyFrame().getArgs();
List argsList = ruby.getRubyFrame().getArgs();
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
result = getRubyFrame().getLastClass().getSuperClass().call(rubyFrame.getSelf(), rubyFrame.getLastFunc(), args, 3);
result = ruby.getRubyFrame().getLastClass().getSuperClass().call( ruby.getRubyFrame().getSelf(), ruby.getRubyFrame().getLastFunc(), args, 3);
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
Frame frame = getRubyFrame(); frame.setTmp(getRubyFrame()); rubyFrame = frame;
RubyFrame frame = ruby.getRubyFrame(); frame.setTmp(ruby.getRubyFrame()); ruby.setRubyFrame(frame);
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
saved_cref = ruby_cref; ruby_cref = (NODE)node.nd_rval(); getRubyFrame().setCbase(node.nd_rval());
saved_cref = ruby.getRubyCRef(); ruby.setRubyCRef((NODE)node.nd_rval()); ruby.getRubyFrame().setCbase(node.nd_rval());
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
getRuby().getRubyScope().setLocalVars(vars); getRuby().getRubyScope().setLocalTbl(node.nd_tbl()); } else { getRuby().getRubyScope().setLocalVars(null); getRuby().getRubyScope().setLocalTbl(null);
ruby.getRubyScope().setLocalVars(vars); ruby.getRubyScope().setLocalTbl(node.nd_tbl()); } else { ruby.getRubyScope().setLocalVars(null); ruby.getRubyScope().setLocalTbl(null);
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
rubyFrame = frame.getTmp();
ruby.setRubyFrame(frame.getTmp());
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