From: <fwi...@us...> - 2008-11-25 04:24:42
|
Revision: 5636 http://jython.svn.sourceforge.net/jython/?rev=5636&view=rev Author: fwierzbicki Date: 2008-11-25 04:24:40 +0000 (Tue, 25 Nov 2008) Log Message: ----------- Creating an adapter package under antlr for obj->ast conversions. Modified Paths: -------------- branches/astwrite/ast/asdl_antlr.py Added Paths: ----------- branches/astwrite/src/org/python/antlr/adapter/ branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java Removed Paths: ------------- branches/astwrite/src/org/python/antlr/AstAdapters.java branches/astwrite/src/org/python/antlr/AstObjectAdapter.java branches/astwrite/src/org/python/antlr/ListWrapper.java branches/astwrite/src/org/python/antlr/StmtListAdapter.java Modified: branches/astwrite/ast/asdl_antlr.py =================================================================== --- branches/astwrite/ast/asdl_antlr.py 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/ast/asdl_antlr.py 2008-11-25 04:24:40 UTC (rev 5636) @@ -57,9 +57,9 @@ print >> self.file, 'package org.python.antlr.ast;' if refersToPythonTree: print >> self.file, 'import java.util.ArrayList;' - print >> self.file, 'import org.python.antlr.AstAdapters;' print >> self.file, 'import org.python.antlr.PythonTree;' - print >> self.file, 'import org.python.antlr.ListWrapper;' + print >> self.file, 'import org.python.antlr.adapter.AstAdapters;' + print >> self.file, 'import org.python.antlr.adapter.ListWrapper;' print >> self.file, 'import org.antlr.runtime.CommonToken;' print >> self.file, 'import org.antlr.runtime.Token;' if useDataOutput: Deleted: branches/astwrite/src/org/python/antlr/AstAdapters.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstAdapters.java 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/src/org/python/antlr/AstAdapters.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -1,156 +0,0 @@ -package org.python.antlr; - -import org.python.antlr.ast.*; -import org.python.core.*; - -/** - * AstAdapter turns Python and Java objects into ast nodes. - */ -public class AstAdapters { - - public static java.util.List<aliasType> to_aliasList(Object o) { - return null; - } - - public static java.util.List<cmpopType> to_cmpopList(Object o) { - return null; - } - - public static java.util.List<comprehensionType> to_comprehensionList(Object o) { - return null; - } - - public static java.util.List<excepthandlerType> to_excepthandlerList(Object o) { - return null; - } - - public static java.util.List<exprType> to_exprList(Object o) { - return null; - } - - public static java.util.List<String> to_identifierList(Object o) { - return null; - } - - public static java.util.List<keywordType> to_keywordList(Object o) { - return null; - } - - public static java.util.List<sliceType> to_sliceList(Object o) { - return null; - } - - public static java.util.List<stmtType> to_stmtList(Object o) { - return null; - } - - public static exprType to_expr(Object o) { - if (o == null || o instanceof exprType) { - return (exprType)o; - } else if (o instanceof Integer) { - return new Num(new PyInteger((Integer)o)); - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); - } - - public static int to_int(Object o) { - if (o == null || o instanceof Integer) { - return (Integer)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to int node"); - } - - public static String to_identifier(Object o) { - if (o == null || o instanceof String) { - return (String)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); - } - - public static expr_contextType to_expr_context(Object o) { - if (o == null || o instanceof expr_contextType) { - return (expr_contextType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr_context node"); - } - - public static sliceType to_slice(Object o) { - if (o == null || o instanceof sliceType) { - return (sliceType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); - } - - public static stmtType to_stmt(Object o) { - if (o instanceof PyJavaInstance) { - o = ((PyJavaInstance)o).__tojava__(stmtType.class); - } - if (o == null || o instanceof stmtType) { - return (stmtType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to stmt node"); - } - - public static String to_string(Object o) { - if (o == null || o instanceof String) { - return (String)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to string node"); - } - - public static operatorType to_operator(Object o) { - if (o == null || o instanceof operatorType) { - return (operatorType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to operator node"); - } - - public static boolopType to_boolop(Object o) { - if (o == null || o instanceof boolopType) { - return (boolopType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to boolop node"); - } - - public static argumentsType to_arguments(Object o) { - if (o == null || o instanceof argumentsType) { - return (argumentsType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arguments node"); - } - - public static Object to_object(Object o) { - if (o == null || o instanceof Object) { - return (Object)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to object node"); - } - - public static Boolean to_bool(Object o) { - if (o == null || o instanceof Boolean) { - return (Boolean)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to Boolean node"); - } - - public static unaryopType to_unaryop(Object o) { - if (o == null || o instanceof unaryopType) { - return (unaryopType)o; - } - //FIXME: investigate the right exception - throw Py.TypeError("Can't convert " + o.getClass().getName() + " to unaryop node"); - } - -} Deleted: branches/astwrite/src/org/python/antlr/AstObjectAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/AstObjectAdapter.java 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/src/org/python/antlr/AstObjectAdapter.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -1,5 +0,0 @@ -package org.python.antlr; - -public interface AstObjectAdapter { - public Object adapt(Object o); -} Deleted: branches/astwrite/src/org/python/antlr/ListWrapper.java =================================================================== --- branches/astwrite/src/org/python/antlr/ListWrapper.java 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/src/org/python/antlr/ListWrapper.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -1,219 +0,0 @@ -package org.python.antlr; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.python.core.PyObject; - -public class ListWrapper implements List { - - private List list; - private AstObjectAdapter adapter; - - public ListWrapper(List list) { - this.list = list; - } - - public ListWrapper(List list, AstObjectAdapter adapter) { - this.adapter = adapter; - this.list = list; - } - - public boolean containsAll(Collection c) { - return containsAll(c); - } - - public boolean removeAll(Collection c) { - return list.removeAll(c); - } - - public boolean retainAll(Collection c) { - return list.retainAll(c); - } - - public boolean add(Object e) { - return list.add(e); - } - - public void add(int index, Object e) { - list.add(index, e); - } - - public boolean addAll(Collection c) { - return list.addAll(c); - } - - public boolean addAll(int index, Collection c) { - return list.addAll(index, c); - } - - public void clear() { - list.clear(); - } - - public boolean contains(Object elem) { - return list.contains(elem); - } - - public Object get(int index) { - return list.get(index); - } - - public int indexOf(Object elem) { - return list.indexOf(elem); - } - - public boolean isEmpty() { - return list.isEmpty(); - } - - public int lastIndexOf(Object elem) { - return list.lastIndexOf(elem); - } - - public Object remove(int index) { - return list.remove(index); - } - - public boolean remove(Object o) { - return list.remove(o); - } - - public Object set(int index, Object element) { - return list.set(index, element); - } - - public int size() { - return list.size(); - } - - public Object[] toArray() { - return list.toArray(); - } - - public Object[] toArray(Object[] a) { - return list.toArray(a); - } - - public Iterator iterator() { - return list.iterator(); - } - - public ListIterator listIterator() { - return list.listIterator(); - } - - public ListIterator listIterator(int index) { - return list.listIterator(index); - } - - public List subList(int fromIndex, int toIndex) { - return list.subList(fromIndex, toIndex); - } - - public ListWrapper __add__(Object o) { - List newList = new ArrayList(); - newList.addAll(list); - newList.add(o); - return new ListWrapper(newList); - } - - public void __iadd__(PyObject o) { - extend(o); - } - - public int __len__() { - return list.size(); - } - - public boolean __contains__(Object o) { - return list.contains(o); - } - - public PyObject __imul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject __iter__() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject __mul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject __radd__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject __rmul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void append(PyObject o) { - list.add(adapter.adapt(o)); - } - - public int count(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void del(int i) { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void delRange(int start, int stop, int step) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void extend(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public int index(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public int index(PyObject o, int start) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public int index(PyObject o, int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void insert(int index, PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject pop() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public PyObject pop(int n) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void remove(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void reverse() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void sort(PyObject compare) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void sort() { - throw new UnsupportedOperationException("Not supported yet."); - } - - public void sort(PyObject cmp, PyObject key, PyObject reverse) { - throw new UnsupportedOperationException("Not supported yet."); - } - -} Deleted: branches/astwrite/src/org/python/antlr/StmtListAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/StmtListAdapter.java 2008-11-25 04:19:42 UTC (rev 5635) +++ branches/astwrite/src/org/python/antlr/StmtListAdapter.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -1,22 +0,0 @@ -package org.python.antlr; - -import org.python.antlr.ast.stmtType; - -import java.util.ArrayList; -import java.util.List; - -public class StmtListAdapter implements AstObjectAdapter { - public Object adaptList(Object list) { - List<stmtType> s = new ArrayList<stmtType>(); - if (list instanceof List) { - for (Object o : (List)list) { - s.add(AstAdapters.to_stmt(o)); - } - } - return s; - } - - public Object adapt(Object o) { - return AstAdapters.to_stmt(o); - } -} Copied: branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java (from rev 5634, branches/astwrite/src/org/python/antlr/AstAdapters.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/AstAdapters.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -0,0 +1,156 @@ +package org.python.antlr.adapter; + +import org.python.antlr.ast.*; +import org.python.core.*; + +/** + * AstAdapter turns Python and Java objects into ast nodes. + */ +public class AstAdapters { + + public static java.util.List<aliasType> to_aliasList(Object o) { + return null; + } + + public static java.util.List<cmpopType> to_cmpopList(Object o) { + return null; + } + + public static java.util.List<comprehensionType> to_comprehensionList(Object o) { + return null; + } + + public static java.util.List<excepthandlerType> to_excepthandlerList(Object o) { + return null; + } + + public static java.util.List<exprType> to_exprList(Object o) { + return null; + } + + public static java.util.List<String> to_identifierList(Object o) { + return null; + } + + public static java.util.List<keywordType> to_keywordList(Object o) { + return null; + } + + public static java.util.List<sliceType> to_sliceList(Object o) { + return null; + } + + public static java.util.List<stmtType> to_stmtList(Object o) { + return null; + } + + public static exprType to_expr(Object o) { + if (o == null || o instanceof exprType) { + return (exprType)o; + } else if (o instanceof Integer) { + return new Num(new PyInteger((Integer)o)); + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr node"); + } + + public static int to_int(Object o) { + if (o == null || o instanceof Integer) { + return (Integer)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to int node"); + } + + public static String to_identifier(Object o) { + if (o == null || o instanceof String) { + return (String)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to identifier node"); + } + + public static expr_contextType to_expr_context(Object o) { + if (o == null || o instanceof expr_contextType) { + return (expr_contextType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to expr_context node"); + } + + public static sliceType to_slice(Object o) { + if (o == null || o instanceof sliceType) { + return (sliceType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to slice node"); + } + + public static stmtType to_stmt(Object o) { + if (o instanceof PyJavaInstance) { + o = ((PyJavaInstance)o).__tojava__(stmtType.class); + } + if (o == null || o instanceof stmtType) { + return (stmtType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to stmt node"); + } + + public static String to_string(Object o) { + if (o == null || o instanceof String) { + return (String)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to string node"); + } + + public static operatorType to_operator(Object o) { + if (o == null || o instanceof operatorType) { + return (operatorType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to operator node"); + } + + public static boolopType to_boolop(Object o) { + if (o == null || o instanceof boolopType) { + return (boolopType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to boolop node"); + } + + public static argumentsType to_arguments(Object o) { + if (o == null || o instanceof argumentsType) { + return (argumentsType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to arguments node"); + } + + public static Object to_object(Object o) { + if (o == null || o instanceof Object) { + return (Object)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to object node"); + } + + public static Boolean to_bool(Object o) { + if (o == null || o instanceof Boolean) { + return (Boolean)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to Boolean node"); + } + + public static unaryopType to_unaryop(Object o) { + if (o == null || o instanceof unaryopType) { + return (unaryopType)o; + } + //FIXME: investigate the right exception + throw Py.TypeError("Can't convert " + o.getClass().getName() + " to unaryop node"); + } + +} Copied: branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java (from rev 5634, branches/astwrite/src/org/python/antlr/AstObjectAdapter.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/AstObjectAdapter.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -0,0 +1,5 @@ +package org.python.antlr.adapter; + +public interface AstObjectAdapter { + public Object adapt(Object o); +} Copied: branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java (from rev 5634, branches/astwrite/src/org/python/antlr/ListWrapper.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -0,0 +1,219 @@ +package org.python.antlr.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import org.python.core.PyObject; + +public class ListWrapper implements List { + + private List list; + private AstObjectAdapter adapter; + + public ListWrapper(List list) { + this.list = list; + } + + public ListWrapper(List list, AstObjectAdapter adapter) { + this.adapter = adapter; + this.list = list; + } + + public boolean containsAll(Collection c) { + return containsAll(c); + } + + public boolean removeAll(Collection c) { + return list.removeAll(c); + } + + public boolean retainAll(Collection c) { + return list.retainAll(c); + } + + public boolean add(Object e) { + return list.add(e); + } + + public void add(int index, Object e) { + list.add(index, e); + } + + public boolean addAll(Collection c) { + return list.addAll(c); + } + + public boolean addAll(int index, Collection c) { + return list.addAll(index, c); + } + + public void clear() { + list.clear(); + } + + public boolean contains(Object elem) { + return list.contains(elem); + } + + public Object get(int index) { + return list.get(index); + } + + public int indexOf(Object elem) { + return list.indexOf(elem); + } + + public boolean isEmpty() { + return list.isEmpty(); + } + + public int lastIndexOf(Object elem) { + return list.lastIndexOf(elem); + } + + public Object remove(int index) { + return list.remove(index); + } + + public boolean remove(Object o) { + return list.remove(o); + } + + public Object set(int index, Object element) { + return list.set(index, element); + } + + public int size() { + return list.size(); + } + + public Object[] toArray() { + return list.toArray(); + } + + public Object[] toArray(Object[] a) { + return list.toArray(a); + } + + public Iterator iterator() { + return list.iterator(); + } + + public ListIterator listIterator() { + return list.listIterator(); + } + + public ListIterator listIterator(int index) { + return list.listIterator(index); + } + + public List subList(int fromIndex, int toIndex) { + return list.subList(fromIndex, toIndex); + } + + public ListWrapper __add__(Object o) { + List newList = new ArrayList(); + newList.addAll(list); + newList.add(o); + return new ListWrapper(newList); + } + + public void __iadd__(PyObject o) { + extend(o); + } + + public int __len__() { + return list.size(); + } + + public boolean __contains__(Object o) { + return list.contains(o); + } + + public PyObject __imul__(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject __iter__() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject __mul__(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject __radd__(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject __rmul__(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void append(PyObject o) { + list.add(adapter.adapt(o)); + } + + public int count(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void del(int i) { + throw new UnsupportedOperationException("Not supported yet."); + } + + protected void delRange(int start, int stop, int step) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void extend(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int index(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int index(PyObject o, int start) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int index(PyObject o, int start, int stop) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void insert(int index, PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject pop() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public PyObject pop(int n) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void remove(PyObject o) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void reverse() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void sort(PyObject compare) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void sort() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void sort(PyObject cmp, PyObject key, PyObject reverse) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} Copied: branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java (from rev 5634, branches/astwrite/src/org/python/antlr/StmtListAdapter.java) =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java (rev 0) +++ branches/astwrite/src/org/python/antlr/adapter/StmtListAdapter.java 2008-11-25 04:24:40 UTC (rev 5636) @@ -0,0 +1,22 @@ +package org.python.antlr.adapter; + +import org.python.antlr.ast.stmtType; + +import java.util.ArrayList; +import java.util.List; + +public class StmtListAdapter implements AstObjectAdapter { + public Object adaptList(Object list) { + List<stmtType> s = new ArrayList<stmtType>(); + if (list instanceof List) { + for (Object o : (List)list) { + s.add(AstAdapters.to_stmt(o)); + } + } + return s; + } + + public Object adapt(Object o) { + return AstAdapters.to_stmt(o); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |