From: <fwi...@us...> - 2008-12-03 04:38:08
|
Revision: 5679 http://jython.svn.sourceforge.net/jython/?rev=5679&view=rev Author: fwierzbicki Date: 2008-12-03 04:38:04 +0000 (Wed, 03 Dec 2008) Log Message: ----------- Enough to get a slightly modified Python 2.5 test_ast.py to pass. Modified Paths: -------------- branches/astwrite/Lib/test/test_ast.py branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java branches/astwrite/src/org/python/antlr/adapter/CmpopAdapter.java branches/astwrite/src/org/python/antlr/adapter/IdentifierAdapter.java branches/astwrite/src/org/python/core/AstList.java Added Paths: ----------- branches/astwrite/src/org/python/antlr/ast/FloorDiv.java branches/astwrite/src/org/python/antlr/ast/NotIn.java branches/astwrite/src/org/python/antlr/ast/Or.java branches/astwrite/src/org/python/antlr/ast/Param.java branches/astwrite/src/org/python/antlr/ast/USub.java Modified: branches/astwrite/Lib/test/test_ast.py =================================================================== --- branches/astwrite/Lib/test/test_ast.py 2008-12-02 22:23:33 UTC (rev 5678) +++ branches/astwrite/Lib/test/test_ast.py 2008-12-03 04:38:04 UTC (rev 5679) @@ -2,27 +2,12 @@ import sys,os, itertools import ast -def get_class_name(t): - result = t.__class__.__name__ - if os.name.startswith('java'): - if result in ("expr_contextType", - "boolopType", - "unaryopType", - "cmpopType", - "operatorType"): - result = t.name() - else: - result = result.split(".")[-1] - if result.endswith("Type"): - result = result[:-4] - return result - def to_tuple(t): if t is None or isinstance(t, (basestring, int, long, complex)): return t elif hasattr(t, '__iter__'): return [to_tuple(e) for e in t] - result = [get_class_name(t)] + result = [t.__class__.__name__] if hasattr(t, 'lineno') and hasattr(t, 'col_offset'): result.append((t.lineno, t.col_offset)) if not hasattr(t, '_fields') or t._fields is None: @@ -186,11 +171,11 @@ ('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]), ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), ('Module', [('Raise', (1, 0), ('Name', (1, 6), 'Exception', ('Load',)), ('Str', (1, 17), 'string'), None)]), -('Module', [('TryExcept', (1, 0), [('Pass', (2, 2))], [('excepthandler', (3, 0), ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))], 3, 0)], [])]), +('Module', [('TryExcept', (1, 0), [('Pass', (2, 2))], [('ExceptHandler', (3, 0), ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [])]), ('Module', [('TryFinally', (1, 0), [('Pass', (2, 2))], [('Pass', (4, 2))])]), ('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]), -('Module', [('Import', (1, 0), [('alias', 'sys', None)])]), -('Module', [('ImportFrom', (1, 0), 'sys', [('alias', 'v', None)], 0)]), +('Module', [('Import', (1, 0), [('aliasType', 'sys', None)])]), +('Module', [('ImportFrom', (1, 0), 'sys', [('aliasType', 'v', None)], 0)]), ('Module', [('Exec', (1, 0), ('Str', (1, 5), 'v'), None, None)]), ('Module', [('Global', (1, 0), ['v'])]), ('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]), @@ -210,7 +195,7 @@ ('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), ('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), ('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Num', (1, 4), 2), ('Num', (1, 8), 3)])), -('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2), 1), ('Num', (1, 4), 2)], [('keyword', 'c', ('Num', (1, 8), 3))], ('Name', (1, 11), 'd', ('Load',)), ('Name', (1, 15), 'e', ('Load',)))), +('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2), 1), ('Num', (1, 4), 2)], [('keywordType', 'c', ('Num', (1, 8), 3))], ('Name', (1, 11), 'd', ('Load',)), ('Name', (1, 15), 'e', ('Load',)))), ('Expression', ('Repr', (1, 0), ('Name', (1, 1), 'v', ('Load',)))), ('Expression', ('Num', (1, 0), 10L)), ('Expression', ('Str', (1, 0), 'string')), Modified: branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java 2008-12-02 22:23:33 UTC (rev 5678) +++ branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -142,6 +142,10 @@ return Py.None; } + public static PyObject op2py(cmpopType o) { + return cmpopAdapter.ast2py(o); + } + public static PyObject op2py(unaryopType o) { switch (o) { case Invert: Modified: branches/astwrite/src/org/python/antlr/adapter/CmpopAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/CmpopAdapter.java 2008-12-02 22:23:33 UTC (rev 5678) +++ branches/astwrite/src/org/python/antlr/adapter/CmpopAdapter.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -5,6 +5,16 @@ import org.python.core.PyJavaInstance; import org.python.antlr.ast.cmpopType; +import org.python.antlr.ast.Eq; +import org.python.antlr.ast.NotEq; +import org.python.antlr.ast.Lt; +import org.python.antlr.ast.LtE; +import org.python.antlr.ast.Gt; +import org.python.antlr.ast.GtE; +import org.python.antlr.ast.Is; +import org.python.antlr.ast.IsNot; +import org.python.antlr.ast.In; +import org.python.antlr.ast.NotIn; import java.util.ArrayList; import java.util.List; @@ -21,7 +31,29 @@ } public PyObject ast2py(Object o) { - return (PyObject)o; + switch ((cmpopType)o) { + case Eq: + return new Eq(); + case NotEq: + return new NotEq(); + case Lt: + return new Lt(); + case LtE: + return new LtE(); + case Gt: + return new Gt(); + case GtE: + return new GtE(); + case Is: + return new Is(); + case IsNot: + return new IsNot(); + case In: + return new In(); + case NotIn: + return new NotIn(); + } + return Py.None; } public List iter2ast(PyObject iter) { Modified: branches/astwrite/src/org/python/antlr/adapter/IdentifierAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/IdentifierAdapter.java 2008-12-02 22:23:33 UTC (rev 5678) +++ branches/astwrite/src/org/python/antlr/adapter/IdentifierAdapter.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -3,6 +3,7 @@ import org.python.core.Py; import org.python.core.PyJavaInstance; import org.python.core.PyObject; +import org.python.core.PyString; import org.python.antlr.ast.Num; @@ -16,7 +17,7 @@ } public PyObject ast2py(Object o) { - return (PyObject)o; + return new PyString(o.toString()); } public List iter2ast(PyObject iter) { Added: branches/astwrite/src/org/python/antlr/ast/FloorDiv.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/FloorDiv.java (rev 0) +++ branches/astwrite/src/org/python/antlr/ast/FloorDiv.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -0,0 +1,18 @@ +// Autogenerated AST node +package org.python.antlr.ast; + +import org.python.antlr.AST; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.expose.ExposedType; + +@ExposedType(name = "_ast.FloorDiv", base = PyObject.class) +public class FloorDiv extends AST { + public static final PyType TYPE = PyType.fromClass(FloorDiv.class); + public int asIndex() { + return asIndex(null); + } + public int asIndex(PyObject error) { + return 12; + } +} Added: branches/astwrite/src/org/python/antlr/ast/NotIn.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/NotIn.java (rev 0) +++ branches/astwrite/src/org/python/antlr/ast/NotIn.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -0,0 +1,18 @@ +// Autogenerated AST node +package org.python.antlr.ast; + +import org.python.antlr.AST; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.expose.ExposedType; + +@ExposedType(name = "_ast.NotIn", base = PyObject.class) +public class NotIn extends AST { + public static final PyType TYPE = PyType.fromClass(NotIn.class); + public int asIndex() { + return asIndex(null); + } + public int asIndex(PyObject error) { + return 10; + } +} Added: branches/astwrite/src/org/python/antlr/ast/Or.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Or.java (rev 0) +++ branches/astwrite/src/org/python/antlr/ast/Or.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -0,0 +1,18 @@ +// Autogenerated AST node +package org.python.antlr.ast; + +import org.python.antlr.AST; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.expose.ExposedType; + +@ExposedType(name = "_ast.Or", base = PyObject.class) +public class Or extends AST { + public static final PyType TYPE = PyType.fromClass(Or.class); + public int asIndex() { + return asIndex(null); + } + public int asIndex(PyObject error) { + return 2; + } +} Added: branches/astwrite/src/org/python/antlr/ast/Param.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/Param.java (rev 0) +++ branches/astwrite/src/org/python/antlr/ast/Param.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -0,0 +1,18 @@ +// Autogenerated AST node +package org.python.antlr.ast; + +import org.python.antlr.AST; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.expose.ExposedType; + +@ExposedType(name = "_ast.Param", base = PyObject.class) +public class Param extends AST { + public static final PyType TYPE = PyType.fromClass(Param.class); + public int asIndex() { + return asIndex(null); + } + public int asIndex(PyObject error) { + return 6; + } +} Added: branches/astwrite/src/org/python/antlr/ast/USub.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/USub.java (rev 0) +++ branches/astwrite/src/org/python/antlr/ast/USub.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -0,0 +1,18 @@ +// Autogenerated AST node +package org.python.antlr.ast; + +import org.python.antlr.AST; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.expose.ExposedType; + +@ExposedType(name = "_ast.USub", base = PyObject.class) +public class USub extends AST { + public static final PyType TYPE = PyType.fromClass(USub.class); + public int asIndex() { + return asIndex(null); + } + public int asIndex(PyObject error) { + return 4; + } +} Modified: branches/astwrite/src/org/python/core/AstList.java =================================================================== --- branches/astwrite/src/org/python/core/AstList.java 2008-12-02 22:23:33 UTC (rev 5678) +++ branches/astwrite/src/org/python/core/AstList.java 2008-12-03 04:38:04 UTC (rev 5679) @@ -515,7 +515,10 @@ } public PyObject pyget(int index) { - return (PyObject)data.get(index); + if (adapter == null) { + return (PyObject)data.get(index); + } + return adapter.ast2py(data.get(index)); } public PyObject pyset(int index, PyObject element) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |