[Python-checkins] python/nondist/sandbox/ast asdl_java.py,1.5,1.6

bckfnn@users.sourceforge.net bckfnn@users.sourceforge.net
Thu, 30 May 2002 09:59:58 -0700


Update of /cvsroot/python/python/nondist/sandbox/ast
In directory usw-pr-cvs1:/tmp/cvs-serv1623

Modified Files:
	asdl_java.py 
Log Message:
Added pickle support
Renamed Visitor.



Index: asdl_java.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/ast/asdl_java.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** asdl_java.py	21 Apr 2002 11:24:33 -0000	1.5
--- asdl_java.py	30 May 2002 16:59:56 -0000	1.6
***************
*** 53,58 ****
          self.file = open("%s.java" % name, "wb")
          print >> self.file, "// Autogenerated AST node"
!         print >> self.file, 'package org.python.p2.ast;'
!         print >> self.file, 'import org.python.p2.SimpleNode;'
          print >> self.file
      
--- 53,60 ----
          self.file = open("%s.java" % name, "wb")
          print >> self.file, "// Autogenerated AST node"
!         print >> self.file, 'package org.python.parser.ast;'
!         print >> self.file, 'import org.python.parser.SimpleNode;'
!         print >> self.file, 'import java.io.DataOutputStream;'
!         print >> self.file, 'import java.io.IOException;'
          print >> self.file
      
***************
*** 74,77 ****
--- 76,84 ----
  
  class AnalyzeVisitor(EmitVisitor):
+     index = 0
+     def makeIndex(self):
+         self.index += 1
+         return self.index
+ 
      def visitModule(self, mod):
          self.types = {}
***************
*** 91,98 ****
--- 98,108 ----
                  break
          for t in sum.types:
+             if not sum.simple:
+                 t.index = self.makeIndex()
              self.visit(t, name, depth)
  
      def visitProduct(self, product, name, depth):
          product.simple = 0
+         product.index = self.makeIndex()
          for f in product.fields:
              self.visit(f, depth + 1)
***************
*** 156,160 ****
          self.emit("", depth)
  
!         self.javaMethods(name, "%sType" % name, product.fields, depth+1)
  
          self.emit("}", depth)
--- 166,171 ----
          self.emit("", depth)
  
!         self.javaMethods(product, name, "%sType" % name, product.fields,
!                          depth+1)
  
          self.emit("}", depth)
***************
*** 177,189 ****
          self.emit("", depth)
  
!         self.javaMethods(cons.name, cons.name, cons.fields, depth+1)
  
          self.emit("}", depth)
          self.close()
  
!     def javaMethods(self, clsname, ctorname, fields, depth):
!         # The java ctor
!         self.emit("public %s(%s) {" % (ctorname,
!              ", ".join([self.fieldDef(f) for f in fields])), depth)
          for f in fields:
              self.emit("this.%s = %s;" % (f.name, f.name), depth+1)
--- 188,201 ----
          self.emit("", depth)
  
!         self.javaMethods(cons, cons.name, cons.name, cons.fields, depth+1)
  
          self.emit("}", depth)
          self.close()
  
!     def javaMethods(self, type, clsname, ctorname, fields, depth):
!         # The java ctors
!         fpargs = ", ".join([self.fieldDef(f) for f in fields])
! 
!         self.emit("public %s(%s) {" % (ctorname, fpargs), depth)
          for f in fields:
              self.emit("this.%s = %s;" % (f.name, f.name), depth+1)
***************
*** 191,194 ****
--- 203,216 ----
          self.emit("", 0)
  
+         if fpargs:
+             fpargs += ", "
+         self.emit("public %s(%sSimpleNode parent) {" % (ctorname, fpargs), depth)
+         self.emit("this(%s);" %
+                     ", ".join([str(f.name) for f in fields]), depth+1)
+         self.emit("this.beginLine = parent.beginLine;", depth+1);
+         self.emit("this.beginColumn = parent.beginColumn;", depth+1);
+         self.emit("}", depth)
+         self.emit("", 0)
+ 
          # The toString() method
          self.emit("public String toString() {", depth)
***************
*** 209,214 ****
          self.emit("", 0)
  
          # The accept() method
!         self.emit("public Object accept(Visitor visitor) throws Exception {", depth)
          if clsname == ctorname:
              self.emit('return visitor.visit%s(this);' % clsname, depth+1)
--- 231,244 ----
          self.emit("", 0)
  
+         # The pickle() method
+         self.emit("public void pickle(DataOutputStream ostream) throws IOException {", depth)
+         self.emit("pickleThis(%s, ostream);" % type.index, depth+1);
+         for f in fields:
+             self.emit("pickleThis(this.%s, ostream);" % f.name, depth+1)
+         self.emit("}", depth)
+         self.emit("", 0)
+ 
          # The accept() method
!         self.emit("public Object accept(VisitorIF visitor) throws Exception {", depth)
          if clsname == ctorname:
              self.emit('return visitor.visit%s(this);' % clsname, depth+1)
***************
*** 220,224 ****
  
          # The visitChildren() method
!         self.emit("public void traverse(Visitor visitor) throws Exception {", depth)
          for f in fields:
              if self.bltinnames.has_key(str(f.type)):
--- 250,254 ----
  
          # The visitChildren() method
!         self.emit("public void traverse(VisitorIF visitor) throws Exception {", depth)
          for f in fields:
              if self.bltinnames.has_key(str(f.type)):
***************
*** 270,275 ****
          for dfn in mod.dfns:
              self.visit(dfn)
!         self.open("Visitor")
!         self.emit('public interface Visitor {', 0)
          for ctor in self.ctors:
              self.emit("public Object visit%s(%s node) throws Exception;" % 
--- 300,305 ----
          for dfn in mod.dfns:
              self.visit(dfn)
!         self.open("VisitorIF")
!         self.emit('public interface VisitorIF {', 0)
          for ctor in self.ctors:
              self.emit("public Object visit%s(%s node) throws Exception;" % 
***************
*** 279,283 ****
  
          self.open("VisitorBase")
!         self.emit('public abstract class VisitorBase implements Visitor {', 0)
          for ctor in self.ctors:
              self.emit("public Object visit%s(%s node) throws Exception {" % 
--- 309,313 ----
  
          self.open("VisitorBase")
!         self.emit('public abstract class VisitorBase implements VisitorIF {', 0)
          for ctor in self.ctors:
              self.emit("public Object visit%s(%s node) throws Exception {" %