[java2python] r181 committed - Acounts for local names in addition to method names.

1 view
Skip to first unread message

java2...@googlecode.com

unread,
Oct 16, 2011, 9:09:27 PM10/16/11
to java2pyth...@googlegroups.com
Revision: 181
Author: troy.melhase
Date: Sun Oct 16 18:08:14 2011
Log: Acounts for local names in addition to method names.
http://code.google.com/p/java2python/source/detail?r=181

Added:
/trunk/test/Class12.java
Deleted:
/trunk/test/ReallyQuickTest.java
Modified:
/trunk/java2python/compiler/template.py
/trunk/java2python/compiler/visitor.py
/trunk/java2python/config/default.py
/trunk/test/Class7.java

=======================================
--- /dev/null
+++ /trunk/test/Class12.java Sun Oct 16 18:08:14 2011
@@ -0,0 +1,12 @@
+class Class12 {
+ private int c = 12;
+
+ private void x() {
+ System.out.println('x');
+ }
+
+ public static void main(String[] args) {
+ Class12 c = new Class12();
+ c.x();
+ }
+}
=======================================
--- /trunk/test/ReallyQuickTest.java Thu Aug 12 11:20:01 2010
+++ /dev/null
@@ -1,7 +0,0 @@
-class ReallyQuickTest {
- public void method() {
- Fu.Bar.Baz a, b, c;
- Eggs z = new Eggs(44, 33);
- }
-
-}
=======================================
--- /trunk/java2python/compiler/template.py Sat Oct 15 15:17:26 2011
+++ /trunk/java2python/compiler/template.py Sun Oct 16 18:08:14 2011
@@ -92,7 +92,9 @@

def altIdent(self, name):
""" Returns an alternate identifier for the one given. """
+ #print '## looking for name:', name, 'parent count:', [(type(x),
type(x.parent)) for x in self.parents()]
for klass in self.parents(lambda v:v.isClass):
+ #print '#### looking inside', klass.name, klass.variables
if name in klass.variables:
try:
method = self.parents(lambda v:v.isMethod).next()
@@ -100,7 +102,10 @@
return name
if name in [p['name'] for p in method.parameters]:
return name
+ if name in method.variables:
+ return name
return ('cls' if method.isStatic else 'self') + '.' + name
+ #print
return name

def configHandler(self, part, suffix='Handler', default=None):
=======================================
--- /trunk/java2python/compiler/visitor.py Thu Aug 12 11:20:01 2010
+++ /trunk/java2python/compiler/visitor.py Sun Oct 16 18:08:14 2011
@@ -384,13 +384,15 @@
tokens.BLOCK_SCOPE,
tokens.CASE,
tokens.DEFAULT,
- tokens.FOR_EACH
+ tokens.FOR_EACH,
+ tokens.METHOD_CALL,
+ tokens.ARGUMENT_LIST,
)

def acceptExpr(self, node, memo):
""" Creates a new expression. """
# this works but isn't precise
- if node.parentType in self.goodExprParents:
+ if node.parentType in self.goodExprParents:
return self.factory.expr(parent=self)

def acceptFor(self, node, memo):
@@ -519,7 +521,7 @@
def acceptReturn(self, node, memo):
""" Creates a new return expression. """
# again, this works but isn't as precise as it should be
- if node.parentType in self.goodReturnParents:
+ if node.parentType: # in self.goodReturnParents:
expr = self.factory.expr(left='return', parent=self)
if node.children:
expr.fs, expr.right = FS.lsr, self.factory.expr(parent=expr)
@@ -681,7 +683,7 @@
""" Accept and process a dotted expression. """
expr = self.factory.expr
self.fs = FS.l + '.' + FS.r
- self.left, self.right = visitors = expr(), expr()
+ self.left, self.right = visitors = expr(parent=self), expr()
self.zipWalk(node.children, visitors, memo)

def acceptExpr(self, node, memo):
=======================================
--- /trunk/java2python/config/default.py Sat Oct 15 15:17:26 2011
+++ /trunk/java2python/config/default.py Sun Oct 16 18:08:14 2011
@@ -149,6 +149,7 @@
(r'([\w.]+)\.size\(\)', r'len(\1)'),
(r'(\w+)\.get\((.*?)\)', r'\1[\2]'),
(r'(\s)(\S*?)(\.toString\(\))', r'\1\2.__str__()'),
+ (r'(\s)def toString', r'\1def __str__'),
(r'(\s)(\S*?)(\.toLowerCase\(\))', r'\1\2.lower()'),
(r'(\s)(\S*?)(\.length\(\))', r'\1len(\2)'),
(r'(.*?)IndexOutOfBoundsException\((.*?)\)', r'\1IndexError(\2)'),
=======================================
--- /trunk/test/Class7.java Sun Oct 16 16:26:06 2011
+++ /trunk/test/Class7.java Sun Oct 16 18:08:14 2011
@@ -21,9 +21,9 @@
System.out.println(a);
System.out.println(b);

- Class7 d = new Class7();
- d.x();
- d.y();
- d.z(3);
+ Class7 c = new Class7();
+ c.x();
+ c.y();
+ c.z(3);
}
}

Reply all
Reply to author
Forward
0 new messages