From: <fwi...@us...> - 2008-11-26 19:43:32
|
Revision: 5643 http://jython.svn.sourceforge.net/jython/?rev=5643&view=rev Author: fwierzbicki Date: 2008-11-26 19:43:27 +0000 (Wed, 26 Nov 2008) Log Message: ----------- Migrated to Python.asdl from CPython 2.6. Modified Paths: -------------- branches/astwrite/Lib/inspect.py branches/astwrite/Lib/test/test_ast.py branches/astwrite/ast/Python.asdl branches/astwrite/ast/asdl_antlr.py branches/astwrite/grammar/Python.g branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java branches/astwrite/src/org/python/antlr/ast/ClassDef.java branches/astwrite/src/org/python/antlr/ast/FunctionDef.java branches/astwrite/src/org/python/antlr/ast/VisitorBase.java branches/astwrite/src/org/python/antlr/ast/VisitorIF.java branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java branches/astwrite/src/org/python/compiler/CodeCompiler.java branches/astwrite/src/org/python/compiler/ScopesCompiler.java Added Paths: ----------- branches/astwrite/src/org/python/antlr/ast/ExceptHandler.java Modified: branches/astwrite/Lib/inspect.py =================================================================== --- branches/astwrite/Lib/inspect.py 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/Lib/inspect.py 2008-11-26 19:43:27 UTC (rev 5643) @@ -315,6 +315,13 @@ return None if not isinstance(doc, types.StringTypes): return None + return cleandoc(doc) + +def cleandoc(doc): + """Clean up indentation from docstrings. + + Any whitespace that can be uniformly removed from the second line + onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: Modified: branches/astwrite/Lib/test/test_ast.py =================================================================== --- branches/astwrite/Lib/test/test_ast.py 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/Lib/test/test_ast.py 2008-11-26 19:43:27 UTC (rev 5643) @@ -250,12 +250,12 @@ [ast.Str('eggs')], [], None, None))) self.assertEqual(src, ast.fix_missing_locations(src)) self.assertEqual(ast.dump(src, include_attributes=True), - "Module(body=[Expr(value=Call(func=Name(id='write', ctx=Load(), " + u"Module(body=[Expr(value=Call(func=Name(id=u'write', ctx=Load(), " "lineno=1, col_offset=0), args=[Str(s='spam', lineno=1, " "col_offset=6)], keywords=[], starargs=None, kwargs=None, " "lineno=1, col_offset=0), lineno=1, col_offset=0), " - "Expr(value=Call(func=Name(id='spam', ctx=Load(), lineno=1, " - "col_offset=0), args=[Str(s='eggs', lineno=1, col_offset=0)], " + "Expr(value=Call(func=Name(id=u'spam', ctx=Load(), lineno=1, " + "col_offset=0), args=[Str(s=u'eggs', lineno=1, col_offset=0)], " "keywords=[], starargs=None, kwargs=None, lineno=1, " "col_offset=0), lineno=1, col_offset=0)])" ) @@ -280,11 +280,11 @@ node = ast.parse("spam(23, 42, eggs='leek')", mode='eval') self.assertEqual(len(list(ast.iter_child_nodes(node.body))), 4) iterator = ast.iter_child_nodes(node.body) - self.assertEqual(next(iterator).id, 'spam') - self.assertEqual(next(iterator).n, 23) - self.assertEqual(next(iterator).n, 42) - self.assertEqual(ast.dump(next(iterator)), - "keyword(arg='eggs', value=Str(s='leek'))" + self.assertEqual(iterator.next().id, 'spam') + self.assertEqual(iterator.next().n, 23) + self.assertEqual(iterator.next().n, 42) + self.assertEqual(ast.dump(iterator.next()), + u"keyword(arg=u'eggs', value=Str(s='leek'))" ) def test_get_docstring(self): Modified: branches/astwrite/ast/Python.asdl =================================================================== --- branches/astwrite/ast/Python.asdl 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/ast/Python.asdl 2008-11-26 19:43:27 UTC (rev 5643) @@ -1,6 +1,6 @@ -- ASDL's five builtin types are identifier, int, string, object, bool -module Python version "$Revision: 53731 $" +module Python version "$Revision: 62047 $" { mod = Module(stmt* body) | Interactive(stmt* body) @@ -10,9 +10,8 @@ | Suite(stmt* body) stmt = FunctionDef(identifier name, arguments args, - stmt* body, expr* decorators) - | ClassDef(identifier name, expr* bases, - stmt* body, expr* decorators) + stmt* body, expr* decorator_list) + | ClassDef(identifier name, expr* bases, stmt* body, expr *decorator_list) | Return(expr? value) | Delete(expr* targets) @@ -29,6 +28,7 @@ | With(expr context_expr, expr? optional_vars, stmt* body) -- 'type' is a bad name + -- changed to 'type' to excepttype for Jython | Raise(expr? excepttype, expr? inst, expr? tback) | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse) | TryFinally(stmt* body, stmt* finalbody) @@ -99,11 +99,9 @@ comprehension = (expr target, expr iter, expr* ifs) -- not sure what to call the first argument for raise and except - -- TODO(jhylton): Figure out if there is a better way to handle - -- lineno and col_offset fields, particularly when - -- ast is exposed to Python. - excepthandler = (expr? excepttype, expr? name, stmt* body, int lineno, - int col_offset) + -- changed to 'type' to excepttype for Jython + excepthandler = ExceptHandler(expr? excepttype, expr? name, stmt* body) + attributes (int lineno, int col_offset) arguments = (expr* args, identifier? vararg, identifier? kwarg, expr* defaults) Modified: branches/astwrite/ast/asdl_antlr.py =================================================================== --- branches/astwrite/ast/asdl_antlr.py 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/ast/asdl_antlr.py 2008-11-26 19:43:27 UTC (rev 5643) @@ -134,7 +134,7 @@ self.visit(type.value, type.name, depth) def visitSum(self, sum, name, depth): - if sum.simple: + if sum.simple and not name == "excepthandler": self.simple_sum(sum, name, depth) else: self.sum_with_constructor(sum, name, depth) @@ -261,7 +261,7 @@ self.emit("}", depth + 1) self.emit("", 0) - if str(name) in ('stmt', 'expr'): + if str(name) in ('stmt', 'expr', 'excepthandler'): # The lineno property self.emit("private int lineno = -1;", depth + 1) self.emit("public int getLineno() {", depth + 1) @@ -290,6 +290,7 @@ self.emit("}", depth + 1) self.emit("", 0) + self.emit("}", depth) self.close() Modified: branches/astwrite/grammar/Python.g =================================================================== --- branches/astwrite/grammar/Python.g 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/grammar/Python.g 2008-11-26 19:43:27 UTC (rev 5643) @@ -102,7 +102,7 @@ import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; import org.python.antlr.ast.Ellipsis; -import org.python.antlr.ast.excepthandlerType; +import org.python.antlr.ast.ExceptHandler; import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; import org.python.antlr.ast.Expression; @@ -918,8 +918,8 @@ //except_clause: 'except' [test [',' test]] except_clause : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite[!$suite.isEmpty() && $suite::continueIllegal] - -> ^(EXCEPT<excepthandlerType>[$EXCEPT, actions.castExpr($t1.tree), actions.castExpr($t2.tree), - actions.castStmts($suite.stypes), $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine()]) + -> ^(EXCEPT<ExceptHandler>[$EXCEPT, actions.castExpr($t1.tree), actions.castExpr($t2.tree), + actions.castStmts($suite.stypes)]) ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT Modified: branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/adapter/ExcepthandlerAdapter.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -3,7 +3,7 @@ import org.python.core.Py; import org.python.core.PyJavaInstance; -import org.python.antlr.ast.excepthandlerType; +import org.python.antlr.ast.ExceptHandler; import org.python.antlr.ast.Num; import java.util.ArrayList; @@ -16,9 +16,9 @@ return o; } if (o instanceof PyJavaInstance) { - o = ((PyJavaInstance)o).__tojava__(excepthandlerType.class); + o = ((PyJavaInstance)o).__tojava__(ExceptHandler.class); } - if (o instanceof excepthandlerType) { + if (o instanceof ExceptHandler) { return o; } @@ -27,9 +27,9 @@ } public Object adaptIter(Object iter) { - List<excepthandlerType> excepthandlers = new ArrayList<excepthandlerType>(); + List<ExceptHandler> excepthandlers = new ArrayList<ExceptHandler>(); for(Object o : (Iterable)iter) { - excepthandlers.add((excepthandlerType)adapt(o)); + excepthandlers.add((ExceptHandler)adapt(o)); } return excepthandlers; } Modified: branches/astwrite/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/ClassDef.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -43,32 +43,34 @@ this.body = AstAdapters.to_stmtList(body); } - private java.util.List<exprType> decorators; - public java.util.List<exprType> getInternalDecorators() { - return decorators; + private java.util.List<exprType> decorator_list; + public java.util.List<exprType> getInternalDecorator_list() { + return decorator_list; } - public Object getDecorators() { - return new ListWrapper(decorators, AstAdapters.exprAdapter); + public Object getDecorator_list() { + return new ListWrapper(decorator_list, AstAdapters.exprAdapter); } - public void setDecorators(Object decorators) { - this.decorators = AstAdapters.to_exprList(decorators); + public void setDecorator_list(Object decorator_list) { + this.decorator_list = AstAdapters.to_exprList(decorator_list); } private final static String[] fields = new String[] {"name", "bases", - "body", "decorators"}; + "body", + "decorator_list"}; public String[] get_fields() { return fields; } public ClassDef() {} - public ClassDef(Object name, Object bases, Object body, Object decorators) { + public ClassDef(Object name, Object bases, Object body, Object + decorator_list) { setName(name); setBases(bases); setBody(body); - setDecorators(decorators); + setDecorator_list(decorator_list); } public ClassDef(Token token, String name, java.util.List<exprType> bases, - java.util.List<stmtType> body, java.util.List<exprType> decorators) { + java.util.List<stmtType> body, java.util.List<exprType> decorator_list) { super(token); this.name = name; this.bases = bases; @@ -85,18 +87,18 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } public ClassDef(Integer ttype, Token token, String name, java.util.List<exprType> bases, java.util.List<stmtType> body, - java.util.List<exprType> decorators) { + java.util.List<exprType> decorator_list) { super(ttype, token); this.name = name; this.bases = bases; @@ -113,17 +115,18 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } public ClassDef(PythonTree tree, String name, java.util.List<exprType> - bases, java.util.List<stmtType> body, java.util.List<exprType> decorators) { + bases, java.util.List<stmtType> body, java.util.List<exprType> + decorator_list) { super(tree); this.name = name; this.bases = bases; @@ -140,11 +143,11 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } @@ -164,8 +167,8 @@ sb.append("body="); sb.append(dumpThis(body)); sb.append(","); - sb.append("decorators="); - sb.append(dumpThis(decorators)); + sb.append("decorator_list="); + sb.append(dumpThis(decorator_list)); sb.append(","); sb.append(")"); return sb.toString(); @@ -188,8 +191,8 @@ t.accept(visitor); } } - if (decorators != null) { - for (PythonTree t : decorators) { + if (decorator_list != null) { + for (PythonTree t : decorator_list) { if (t != null) t.accept(visitor); } Added: branches/astwrite/src/org/python/antlr/ast/ExceptHandler.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/ExceptHandler.java (rev 0) +++ branches/astwrite/src/org/python/antlr/ast/ExceptHandler.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -0,0 +1,166 @@ +// Autogenerated AST node +package org.python.antlr.ast; +import java.util.ArrayList; +import org.python.antlr.PythonTree; +import org.python.antlr.adapter.AstAdapters; +import org.python.antlr.adapter.ListWrapper; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.Token; +import java.io.DataOutputStream; +import java.io.IOException; + +public class ExceptHandler extends excepthandlerType { + private exprType excepttype; + public exprType getInternalExcepttype() { + return excepttype; + } + public Object getExcepttype() { + return excepttype; + } + public void setExcepttype(Object excepttype) { + this.excepttype = AstAdapters.to_expr(excepttype); + } + + private exprType name; + public exprType getInternalName() { + return name; + } + public Object getName() { + return name; + } + public void setName(Object name) { + this.name = AstAdapters.to_expr(name); + } + + private java.util.List<stmtType> body; + public java.util.List<stmtType> getInternalBody() { + return body; + } + public Object getBody() { + return new ListWrapper(body, AstAdapters.stmtAdapter); + } + public void setBody(Object body) { + this.body = AstAdapters.to_stmtList(body); + } + + + private final static String[] fields = new String[] {"excepttype", "name", + "body"}; + public String[] get_fields() { return fields; } + + public ExceptHandler() {} + public ExceptHandler(Object excepttype, Object name, Object body) { + setExcepttype(excepttype); + setName(name); + setBody(body); + } + + public ExceptHandler(Token token, exprType excepttype, exprType name, + java.util.List<stmtType> body) { + super(token); + this.excepttype = excepttype; + addChild(excepttype); + this.name = name; + addChild(name); + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); + } + for(PythonTree t : this.body) { + addChild(t); + } + } + + public ExceptHandler(Integer ttype, Token token, exprType excepttype, + exprType name, java.util.List<stmtType> body) { + super(ttype, token); + this.excepttype = excepttype; + addChild(excepttype); + this.name = name; + addChild(name); + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); + } + for(PythonTree t : this.body) { + addChild(t); + } + } + + public ExceptHandler(PythonTree tree, exprType excepttype, exprType name, + java.util.List<stmtType> body) { + super(tree); + this.excepttype = excepttype; + addChild(excepttype); + this.name = name; + addChild(name); + this.body = body; + if (body == null) { + this.body = new ArrayList<stmtType>(); + } + for(PythonTree t : this.body) { + addChild(t); + } + } + + public String toString() { + return "ExceptHandler"; + } + + public String toStringTree() { + StringBuffer sb = new StringBuffer("ExceptHandler("); + sb.append("excepttype="); + sb.append(dumpThis(excepttype)); + sb.append(","); + sb.append("name="); + sb.append(dumpThis(name)); + sb.append(","); + sb.append("body="); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); + return sb.toString(); + } + + public <R> R accept(VisitorIF<R> visitor) throws Exception { + return visitor.visitExceptHandler(this); + } + + public void traverse(VisitorIF visitor) throws Exception { + if (excepttype != null) + excepttype.accept(visitor); + if (name != null) + name.accept(visitor); + if (body != null) { + for (PythonTree t : body) { + if (t != null) + t.accept(visitor); + } + } + } + + private int lineno = -1; + public int getLineno() { + if (lineno != -1) { + return lineno; + } + return getLine(); + } + + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; + public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } + return getCharPositionInLine(); + } + + public void setCol_offset(int num) { + col_offset = num; + } + +} Modified: branches/astwrite/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/FunctionDef.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -43,33 +43,34 @@ this.body = AstAdapters.to_stmtList(body); } - private java.util.List<exprType> decorators; - public java.util.List<exprType> getInternalDecorators() { - return decorators; + private java.util.List<exprType> decorator_list; + public java.util.List<exprType> getInternalDecorator_list() { + return decorator_list; } - public Object getDecorators() { - return new ListWrapper(decorators, AstAdapters.exprAdapter); + public Object getDecorator_list() { + return new ListWrapper(decorator_list, AstAdapters.exprAdapter); } - public void setDecorators(Object decorators) { - this.decorators = AstAdapters.to_exprList(decorators); + public void setDecorator_list(Object decorator_list) { + this.decorator_list = AstAdapters.to_exprList(decorator_list); } private final static String[] fields = new String[] {"name", "args", - "body", "decorators"}; + "body", + "decorator_list"}; public String[] get_fields() { return fields; } public FunctionDef() {} public FunctionDef(Object name, Object args, Object body, Object - decorators) { + decorator_list) { setName(name); setArgs(args); setBody(body); - setDecorators(decorators); + setDecorator_list(decorator_list); } public FunctionDef(Token token, String name, argumentsType args, - java.util.List<stmtType> body, java.util.List<exprType> decorators) { + java.util.List<stmtType> body, java.util.List<exprType> decorator_list) { super(token); this.name = name; this.args = args; @@ -80,17 +81,18 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } public FunctionDef(Integer ttype, Token token, String name, argumentsType - args, java.util.List<stmtType> body, java.util.List<exprType> decorators) { + args, java.util.List<stmtType> body, java.util.List<exprType> + decorator_list) { super(ttype, token); this.name = name; this.args = args; @@ -101,17 +103,17 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } public FunctionDef(PythonTree tree, String name, argumentsType args, - java.util.List<stmtType> body, java.util.List<exprType> decorators) { + java.util.List<stmtType> body, java.util.List<exprType> decorator_list) { super(tree); this.name = name; this.args = args; @@ -122,11 +124,11 @@ for(PythonTree t : this.body) { addChild(t); } - this.decorators = decorators; - if (decorators == null) { - this.decorators = new ArrayList<exprType>(); + this.decorator_list = decorator_list; + if (decorator_list == null) { + this.decorator_list = new ArrayList<exprType>(); } - for(PythonTree t : this.decorators) { + for(PythonTree t : this.decorator_list) { addChild(t); } } @@ -146,8 +148,8 @@ sb.append("body="); sb.append(dumpThis(body)); sb.append(","); - sb.append("decorators="); - sb.append(dumpThis(decorators)); + sb.append("decorator_list="); + sb.append(dumpThis(decorator_list)); sb.append(","); sb.append(")"); return sb.toString(); @@ -166,8 +168,8 @@ t.accept(visitor); } } - if (decorators != null) { - for (PythonTree t : decorators) { + if (decorator_list != null) { + for (PythonTree t : decorator_list) { if (t != null) t.accept(visitor); } Modified: branches/astwrite/src/org/python/antlr/ast/VisitorBase.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/VisitorBase.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/VisitorBase.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -308,6 +308,12 @@ return ret; } + public R visitExceptHandler(ExceptHandler node) throws Exception { + R ret = unhandled_node(node); + traverse(node); + return ret; + } + abstract protected R unhandled_node(PythonTree node) throws Exception; abstract public void traverse(PythonTree node) throws Exception; } Modified: branches/astwrite/src/org/python/antlr/ast/VisitorIF.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/VisitorIF.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/VisitorIF.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -52,4 +52,5 @@ public R visitSlice(Slice node) throws Exception; public R visitExtSlice(ExtSlice node) throws Exception; public R visitIndex(Index node) throws Exception; + public R visitExceptHandler(ExceptHandler node) throws Exception; } Modified: branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/antlr/ast/excepthandlerType.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -6,177 +6,26 @@ import org.python.antlr.adapter.ListWrapper; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; -import java.io.DataOutputStream; -import java.io.IOException; -public class excepthandlerType extends PythonTree { - private exprType excepttype; - public exprType getInternalExcepttype() { - return excepttype; - } - public Object getExcepttype() { - return excepttype; - } - public void setExcepttype(Object excepttype) { - this.excepttype = AstAdapters.to_expr(excepttype); - } +public abstract class excepthandlerType extends PythonTree { - private exprType name; - public exprType getInternalName() { - return name; - } - public Object getName() { - return name; - } - public void setName(Object name) { - this.name = AstAdapters.to_expr(name); - } + private final static String[] attributes = new String[] {"lineno", + "col_offset"}; + public String[] get_attributes() { return attributes; } - private java.util.List<stmtType> body; - public java.util.List<stmtType> getInternalBody() { - return body; + public excepthandlerType() { } - public Object getBody() { - return new ListWrapper(body, AstAdapters.stmtAdapter); - } - public void setBody(Object body) { - this.body = AstAdapters.to_stmtList(body); - } - private Integer lineno; - public Integer getInternalLineno() { - return lineno; + public excepthandlerType(int ttype, Token token) { + super(ttype, token); } - public Object getLineno() { - return lineno; - } - public void setLineno(Object lineno) { - this.lineno = AstAdapters.to_int(lineno); - } - private Integer col_offset; - public Integer getInternalCol_offset() { - return col_offset; - } - public Object getCol_offset() { - return col_offset; - } - public void setCol_offset(Object col_offset) { - this.col_offset = AstAdapters.to_int(col_offset); - } - - - private final static String[] fields = new String[] {"excepttype", "name", - "body", "lineno", - "col_offset"}; - public String[] get_fields() { return fields; } - - public excepthandlerType() {} - public excepthandlerType(Object excepttype, Object name, Object body, - Object lineno, Object col_offset) { - setExcepttype(excepttype); - setName(name); - setBody(body); - setLineno(lineno); - setCol_offset(col_offset); - } - - public excepthandlerType(Token token, exprType excepttype, exprType name, - java.util.List<stmtType> body, Integer lineno, Integer col_offset) { + public excepthandlerType(Token token) { super(token); - this.excepttype = excepttype; - addChild(excepttype); - this.name = name; - addChild(name); - this.body = body; - if (body == null) { - this.body = new ArrayList<stmtType>(); - } - for(PythonTree t : this.body) { - addChild(t); - } - this.lineno = lineno; - this.col_offset = col_offset; } - public excepthandlerType(Integer ttype, Token token, exprType excepttype, - exprType name, java.util.List<stmtType> body, Integer lineno, Integer - col_offset) { - super(ttype, token); - this.excepttype = excepttype; - addChild(excepttype); - this.name = name; - addChild(name); - this.body = body; - if (body == null) { - this.body = new ArrayList<stmtType>(); - } - for(PythonTree t : this.body) { - addChild(t); - } - this.lineno = lineno; - this.col_offset = col_offset; + public excepthandlerType(PythonTree node) { + super(node); } - public excepthandlerType(PythonTree tree, exprType excepttype, exprType - name, java.util.List<stmtType> body, Integer lineno, Integer col_offset) { - super(tree); - this.excepttype = excepttype; - addChild(excepttype); - this.name = name; - addChild(name); - this.body = body; - if (body == null) { - this.body = new ArrayList<stmtType>(); - } - for(PythonTree t : this.body) { - addChild(t); - } - this.lineno = lineno; - this.col_offset = col_offset; - } - - public String toString() { - return "excepthandler"; - } - - public String toStringTree() { - StringBuffer sb = new StringBuffer("excepthandler("); - sb.append("excepttype="); - sb.append(dumpThis(excepttype)); - sb.append(","); - sb.append("name="); - sb.append(dumpThis(name)); - sb.append(","); - sb.append("body="); - sb.append(dumpThis(body)); - sb.append(","); - sb.append("lineno="); - sb.append(dumpThis(lineno)); - sb.append(","); - sb.append("col_offset="); - sb.append(dumpThis(col_offset)); - sb.append(","); - sb.append(")"); - return sb.toString(); - } - - public <R> R accept(VisitorIF<R> visitor) throws Exception { - traverse(visitor); - return null; - } - - public void traverse(VisitorIF visitor) throws Exception { - if (excepttype != null) - excepttype.accept(visitor); - if (name != null) - name.accept(visitor); - if (body != null) { - for (PythonTree t : body) { - if (t != null) - t.accept(visitor); - } - } - } - } Modified: branches/astwrite/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/astwrite/src/org/python/compiler/CodeCompiler.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/compiler/CodeCompiler.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -27,6 +27,7 @@ import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; import org.python.antlr.ast.Ellipsis; +import org.python.antlr.ast.ExceptHandler; import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; import org.python.antlr.ast.Expression; @@ -419,7 +420,7 @@ } set(new Name(node,node.getInternalName(), expr_contextType.Store)); - doDecorators(node,node.getInternalDecorators(), node.getInternalName()); + doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); return null; } @@ -1124,7 +1125,7 @@ throws Exception { for (int i = 0; i < node.getInternalHandlers().size(); i++) { - excepthandlerType handler = node.getInternalHandlers().get(i); + ExceptHandler handler = (ExceptHandler)node.getInternalHandlers().get(i); //setline(name); Label end_of_self = new Label(); @@ -2024,7 +2025,7 @@ //Assign this new class to the given name set(new Name(node,node.getInternalName(), expr_contextType.Store)); - doDecorators(node,node.getInternalDecorators(), node.getInternalName()); + doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); return null; } Modified: branches/astwrite/src/org/python/compiler/ScopesCompiler.java =================================================================== --- branches/astwrite/src/org/python/compiler/ScopesCompiler.java 2008-11-26 05:19:41 UTC (rev 5642) +++ branches/astwrite/src/org/python/compiler/ScopesCompiler.java 2008-11-26 19:43:27 UTC (rev 5643) @@ -130,7 +130,7 @@ visit(defaults.get(i)); } - List<exprType> decs = node.getInternalDecorators(); + List<exprType> decs = node.getInternalDecorator_list(); for (int i = decs.size() - 1; i >= 0; i--) { visit(decs.get(i)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |