Title: [693] trunk/jparsetree: mission (nearly) accomplished: down to 6 failures; these are either tiny issues (need to be able to determine post fix if vs prefix if, etc) or difficult to solve related (dasn vs.
Revision
693
Author
murphee
Date
2007-08-19 20:50:55 -0400 (Sun, 19 Aug 2007)

Log Message

mission (nearly) accomplished: down to 6 failures; these are either tiny issues (need to be able to determine post fix if vs prefix if, etc) or difficult to solve related (dasn vs. dasgn_curr in one test case, showing an anonymous splat, etc.). The rest, plus 3 errors, are problems of getting ASTs at runtime.

Modified Paths

Diff

Modified: trunk/jparsetree/lib/jparsetree.rb (692 => 693)


--- trunk/jparsetree/lib/jparsetree.rb	2007-08-19 03:17:44 UTC (rev 692)
+++ trunk/jparsetree/lib/jparsetree.rb	2007-08-20 00:50:55 UTC (rev 693)
@@ -12,8 +12,8 @@
  end
 end
 
+end
 
-
 class ParseTree
 
 
@@ -390,8 +390,8 @@
     tempStack = [:block]
 # tempStack = []
    # p "1"
-    tempStack = @stackElements.pop unless @stackElements.size < 1
-    tempStack ||= []
+#    tempStack = @stackElements.pop unless @stackElements.size < 1
+#    tempStack ||= []
     iVisited.child_nodes.each {|n| 
        visit(n)
        tempStack << JParseTree.filter_nested_arrays(@stackElements.pop)
@@ -474,13 +474,32 @@
   end
   
   def visitCaseNode(iVisited)
-    # puts iVisited.to_s
-     visit(iVisited.case_node)
-     node = @stackElements.pop
+     puts iVisited.to_s
+    
+    # Note: this is the _expression_ that returns the value handled in the when expressions;   
+    visit(iVisited.case_node)
+    
+    node = @stackElements.pop
+    
     @stackElements << []
 
-    iVisited.child_nodes.each{|el| el.accept(self.to_java_object)} 
-
+    
+#     NOTE: the child nodes, for some reason contain
+    if iVisited.child_nodes.size > 1
+      # HACK: for some reason iVisited.child_nodes[1..xxx] won't work
+      # thus, I just filter out the 0th element, which - for some other odd
+      # reason is just a repeat of the case _expression_;  
+      iVisited.child_nodes.each_with_index{|el, idx|
+        if  idx > 0
+         el.accept(self.to_java_object)
+        end
+      } 
+    else
+      if iVisited.child_nodes.size == 1
+        iVisited.child_nodes[0].accept(self.to_java_object)
+      end
+    end
+    
     @stackElements << location([:case, node, *JParseTree.filter_nested_arrays(@stackElements.pop)], iVisited)
     nil
   end
@@ -512,8 +531,6 @@
       klazz = location([:class,clazzname, superclazz, [:scope]], iVisited) 
     end 
     
-#    puts "CLASS #{klazz}"
-    
     if @stackElements == nil
       @sexpr << klazz
     else
@@ -853,7 +870,7 @@
   
   def visitFalseNode(iVisited)
     # puts iVisited.to_s
-    @stackElements << :false
+    @stackElements << [:false]
     nil
   end
   
@@ -1015,7 +1032,11 @@
     if temp == nil
       @stackElements << location([:lasgn, iVisited.name.to_sym], iVisited)
     else
+      if temp == :nil
+        @stackElements << location([:lasgn, iVisited.name.to_sym, [:nil]], iVisited)
+      else 
         @stackElements << location([:lasgn, iVisited.name.to_sym, JParseTree.filter_nested_arrays(temp)], iVisited)
+      end
     end
 
     nil
@@ -1110,10 +1131,10 @@
   end
   
   def visitNewlineNode(iVisited)
-#     puts iVisited.to_s
- #    puts iVisited.next_node.to_s
+    puts iVisited.next_node.to_s
     visit(iVisited.next_node)
-    @stackElements << location([EMAIL PROTECTED], iVisited) # unless @stackElements.size < 1
+    puts "NewLineNode [EMAIL PROTECTED] "
+    @stackElements << location([EMAIL PROTECTED], iVisited) 
 
     nil
   end
@@ -1251,7 +1272,11 @@
       if body == :nil
        @stackElements << location([:resbody, excNodes, [body]], iVisited)
       else
-        @stackElements << location([:resbody, excNodes, JParseTree.filter_nested_arrays(body)], iVisited)
+#        if body.respond_to :size
+          @stackElements << location([:resbody, excNodes, JParseTree.filter_nested_arrays(body)], iVisited) 
+#        else 
+#          @stackElements << location([:resbody, excNodes, body], iVisited)
+#        end
       end
      else
      @stackElements << location([:resbody, excNodes, body, JParseTree.filter_nested_arrays(rescue_node)], iVisited)
@@ -1380,7 +1405,7 @@
   
   def visitTrueNode(iVisited)
     # puts iVisited.to_s
-    @stackElements << :true
+    @stackElements << [:true]
     nil
   end
   
@@ -1394,7 +1419,7 @@
   def visitUntilNode(iVisited)
     # puts iVisited.to_s
     visit(iVisited.condition_node)
-    cond = [EMAIL PROTECTED]
+    cond = @stackElements.pop
     visit(iVisited.body_node)
     body = JParseTree.filter_nested_arrays(@stackElements.pop)
     # TODO: ask about the last element "true"
@@ -1421,8 +1446,6 @@
   end
   
   def visitWhenNode(iVisited)
-    # puts iVisited.to_s
-    puts iVisited.expression_nodes
     visit(iVisited.expression_nodes)
     expr = @stackElements.pop
     if iVisited.body_node
@@ -1431,18 +1454,23 @@
     else
       body = nil   
     end
-    
+
     @stackElements.last << location([:when, JParseTree.filter_nested_arrays(expr), JParseTree.filter_nested_arrays(body) ], iVisited)
-#    puts "WHENODE: [EMAIL PROTECTED]"
+    # Note: for some reason, the Case node doesn't contain it's WhenNodes in a list;
+    # instead, it has a reference to the head of a linked list of WhenNodes + a default _expression_;
+    # No idea why that's the case, but it makes for some nice additional complexity...    
     if iVisited.next_case.class == org.jruby.ast.WhenNode
-      puts iVisited.next_case
+     puts iVisited.next_case
      visitWhenNode(iVisited.next_case) 
     else 
-      visit(iVisited.next_case)
-      tmp = @stackElements.pop
+      if iVisited.next_case
+        visit(iVisited.next_case)
+        tmp = @stackElements.pop       
+      else
+        tmp = nil
+      end
       @stackElements.last << JParseTree.filter_nested_arrays(tmp)
     end 
-   # next_case =  @stackElements.pop unless @stackElements.size < 1
     nil
   end
   
@@ -1493,4 +1521,4 @@
 end #end class
 
 
-end #module
+

Modified: trunk/jparsetree/tests/test_jparsetree_20.rb (692 => 693)


--- trunk/jparsetree/tests/test_jparsetree_20.rb	2007-08-19 03:17:44 UTC (rev 692)
+++ trunk/jparsetree/tests/test_jparsetree_20.rb	2007-08-20 00:50:55 UTC (rev 693)
@@ -6,26 +6,26 @@
   attr_reader :reader
   attr_writer :writer
 
-  def a_method; 1+1; end
+  def a_method(x); x+1; end
   alias an_alias a_method
 
-  def self.bmethod_maker
-    define_method(:bmethod_added) do |x|
-      x + 1
-    end
+  define_method(:bmethod_noargs) do
+    x + 1
   end
-  
-  def self.dmethod_maker
-    define_method :dmethod_added, self.method(:bmethod_maker)
-  end 
-  
-  self.bmethod_maker
-  self.dmethod_maker 
-#  dmethod_maker if RUBY_VERSION < "1.9"
+
+  define_method(:unsplatted) do |x|
+    x + 1
+  end
+
+  define_method :splatted do |*args|
+    y = args.first
+    y + 42
+  end
+
+  define_method :dmethod_added, instance_method(:a_method) if RUBY_VERSION < "1.9"
 end
 
 
-
 include JParseTree
 
 #class TestParseTree < ParseTreeTestCase
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to