Update of /cvsroot/jython/jython/org/python/parser
In directory usw-pr-cvs1:/tmp/cvs-serv17046
Modified Files:
JJTPythonGrammarState.java Node.java ParseException.java
SimpleNode.java Visitor.java python.jjt
Added Files:
TreeBuilder.java
Log Message:
Implementation of the new AST tree.
--- NEW FILE: TreeBuilder.java ---
package org.python.parser;
import org.python.parser.ast.*;
import org.python.core.PyObject;
public class TreeBuilder implements PythonGrammarTreeConstants {
private JJTPythonGrammarState stack;
CtxVisitor ctx;
public TreeBuilder(JJTPythonGrammarState stack) {
this.stack = stack;
ctx = new CtxVisitor();
}
private stmtType[] makeStmts(int l) {
stmtType[] stmts = new stmtType[l];
for (int i = l-1; i >= 0; i--) {
stmts[i] = (stmtType) stack.popNode();
}
return stmts;
}
private stmtType[] popSuite() {
return ((Suite) popNode()).body;
}
private exprType[] makeExprs() {
if (stack.nodeArity() > 0 && peekNode().getId() == JJTCOMMA)
popNode();
return makeExprs(stack.nodeArity());
}
private exprType[] makeExprs(int l) {
exprType[] exprs = new exprType[l];
for (int i = l-1; i >= 0; i--) {
exprs[i] = makeExpr();
}
return exprs;
}
private exprType makeExpr(SimpleNode node) {
return (exprType) node;
}
private exprType makeExpr() {
return makeExpr((SimpleNode) stack.popNode());
}
private String makeIdentifier() {
return ((Name) stack.popNode()).id;
}
private String[] makeIdentifiers() {
int l = stack.nodeArity();
String[] ids = new String[l];
for (int i = l - 1; i >= 0; i--) {
ids[i] = makeIdentifier();
}
return ids;
}
private aliasType[] makeAliases() {
return makeAliases(stack.nodeArity());
}
private aliasType[] makeAliases(int l) {
aliasType[] aliases = new aliasType[l];
for (int i = l-1; i >= 0; i--) {
aliases[i] = (aliasType) stack.popNode();
}
return aliases;
}
private static SimpleNode[] nodes =
new SimpleNode[PythonGrammarTreeConstants.jjtNodeName.length];
public SimpleNode openNode(int id) {
if (nodes[id] == null)
nodes[id] = new IdentityNode(id);
return nodes[id];
}
public SimpleNode closeNode(SimpleNode n, int arity) throws Exception {
exprType value;
exprType[] exprs;
switch (n.getId()) {
case -1:
System.out.println("Illegal node");
case JJTSINGLE_INPUT:
return new Interactive((stmtType) popNode());
case JJTFILE_INPUT:
return new Module(makeStmts(arity));
case JJTEVAL_INPUT:
return new Expression(makeExpr());
case JJTNAME:
return new Name(n.getImage().toString(), Name.Load);
case JJTNUM:
return new Num((PyObject) n.getImage());
case JJTSTRING:
return new Str(n.getImage().toString());
case JJTSUITE:
stmtType[] stmts = new stmtType[arity];
for (int i = arity-1; i >= 0; i--) {
stmts[i] = (stmtType) popNode();
}
return new Suite(stmts);
case JJTEXPR_STMT:
value = makeExpr();
if (arity > 1) {
exprs = makeExprs(arity-1);
ctx.setStore(exprs);
return new Assign(exprs, value);
} else {
return new Expr(value);
}
case JJTINDEX_OP:
sliceType slice = (sliceType) stack.popNode();
value = makeExpr();
return new Subscript(value, slice, Subscript.Load);
case JJTDOT_OP:
String attr = makeIdentifier();
value = makeExpr();
return new Attribute(value, attr, Attribute.Load);
case JJTDEL_STMT:
exprs = makeExprs(arity);
ctx.setDelete(exprs);
return new Delete(exprs);
case JJTPRINT_STMT:
boolean nl = true;
if (stack.nodeArity() == 0)
return new Print(null, null, true);
if (peekNode().getId() == JJTCOMMA) {
popNode();
nl = false;
}
return new Print(null, makeExprs(), nl);
case JJTPRINTEXT_STMT:
nl = true;
if (peekNode().getId() == JJTCOMMA) {
popNode();
nl = false;
}
exprs = makeExprs(stack.nodeArity()-1);
return new Print(makeExpr(), exprs, nl);
case JJTFOR_STMT:
stmtType[] orelse = null;
if (stack.nodeArity() == 4)
orelse = popSuite();
stmtType[] body = popSuite();
exprType iter = makeExpr();
exprType target = makeExpr();
ctx.setStore(target);
return new For(target, iter, body, orelse);
case JJTWHILE_STMT:
orelse = null;
if (stack.nodeArity() == 3)
orelse = popSuite();
body = popSuite();
exprType test = makeExpr();
return new While(test, body, orelse);
case JJTIF_STMT:
orelse = null;
if (arity % 2 == 1)
orelse = popSuite();
body = popSuite();
test = makeExpr();
If last = new If(test, body, orelse);
for (int i = 0; i < (arity / 2)-1; i++) {
body = popSuite();
test = makeExpr();
last = new If(test, body, new stmtType[] { last });
}
return last;
case JJTPASS_STMT:
return new Pass();
case JJTBREAK_STMT:
return new Break();
case JJTCONTINUE_STMT:
return new Continue();
case JJTFUNCDEF:
body = popSuite();
argumentsType arguments = makeArguments(arity - 2);
String name = makeIdentifier();
return new FunctionDef(name, arguments, body);
case JJTDEFAULTARG:
value = (arity == 1) ? null : makeExpr();
return new DefaultArg(makeExpr(), value);
case JJTEXTRAARGLIST:
return new ExtraArg(makeIdentifier(), JJTEXTRAARGLIST);
case JJTEXTRAKEYWORDLIST:
return new ExtraArg(makeIdentifier(), JJTEXTRAKEYWORDLIST);
/*
case JJTFPLIST:
fpdefType[] list = new fpdefType[arity];
for (int i = arity-1; i >= 0; i--) {
list[i] = popFpdef();
}
return new FpList(list);
*/
case JJTCLASSDEF:
body = popSuite();
exprType[] bases = makeExprs(stack.nodeArity() - 1);
name = makeIdentifier();
return new ClassDef(name, bases, body);
case JJTRETURN_STMT:
value = arity == 1 ? makeExpr() : null;
return new Return(value);
case JJTYIELD_STMT:
return new Yield(makeExpr());
case JJTRAISE_STMT:
exprType tback = arity >= 3 ? makeExpr() : null;
exprType inst = arity >= 2 ? makeExpr() : null;
exprType type = arity >= 1 ? makeExpr() : null;
return new Raise(type, inst, tback);
case JJTGLOBAL_STMT:
return new Global(makeIdentifiers());
case JJTEXEC_STMT:
exprType globals = arity >= 3 ? makeExpr() : null;
exprType locals = arity >= 2 ? makeExpr() : null;
value = makeExpr();
return new Exec(value, locals, globals);
case JJTASSERT_STMT:
exprType msg = arity == 2 ? makeExpr() : null;
test = makeExpr();
return new Assert(test, msg);
case JJTTRYFINALLY_STMT:
orelse = popSuite();
return new TryFinally(popSuite(), orelse);
case JJTTRY_STMT:
orelse = null;
if (peekNode() instanceof Suite) {
arity--;
orelse = popSuite();
}
int l = arity - 1;
excepthandlerType[] handlers = new excepthandlerType[l];
for (int i = l - 1; i >= 0; i--) {
handlers[i] = (excepthandlerType) popNode();
}
return new TryExcept(popSuite(), handlers, orelse);
case JJTEXCEPT_CLAUSE:
body = popSuite();
exprType excname = arity == 3 ? makeExpr() : null;
if (excname != null)
ctx.setStore(excname);
type = arity >= 2 ? makeExpr() : null;
return new excepthandlerType(type, excname, body);
case JJTOR_BOOLEAN:
return new BoolOp(BoolOp.Or, makeExprs());
case JJTAND_BOOLEAN:
return new BoolOp(BoolOp.And, makeExprs());
case JJTCOMPARISION:
l = arity / 2;
exprType[] comparators = new exprType[l];
int[] ops = new int[l];
for (int i = l-1; i >= 0; i--) {
comparators[i] = makeExpr();
SimpleNode op = (SimpleNode) stack.popNode();
switch (op.getId()) {
case JJTLESS_CMP: ops[i] = Compare.Lt; break;
case JJTGREATER_CMP: ops[i] = Compare.Gt; break;
case JJTEQUAL_CMP: ops[i] = Compare.Eq; break;
case JJTGREATER_EQUAL_CMP: ops[i] = Compare.GtE; break;
case JJTLESS_EQUAL_CMP: ops[i] = Compare.LtE; break;
case JJTNOTEQUAL_CMP: ops[i] = Compare.NotEq; break;
case JJTIN_CMP: ops[i] = Compare.In; break;
case JJTNOT_IN_CMP: ops[i] = Compare.NotIn; break;
case JJTIS_NOT_CMP: ops[i] = Compare.IsNot; break;
case JJTIS_CMP: ops[i] = Compare.Is; break;
default:
throw new RuntimeException("Unknown cmp op:" + op.getId());
}
}
return new Compare(makeExpr(), ops, comparators);
case JJTLESS_CMP:
case JJTGREATER_CMP:
case JJTEQUAL_CMP:
case JJTGREATER_EQUAL_CMP:
case JJTLESS_EQUAL_CMP:
case JJTNOTEQUAL_CMP:
case JJTIN_CMP:
case JJTNOT_IN_CMP:
case JJTIS_NOT_CMP:
case JJTIS_CMP:
return n;
case JJTOR_2OP:
return makeBinOp(BinOp.BitOr);
case JJTXOR_2OP:
return makeBinOp(BinOp.BitXor);
case JJTAND_2OP:
return makeBinOp(BinOp.BitAnd);
case JJTLSHIFT_2OP:
return makeBinOp(BinOp.LShift);
case JJTRSHIFT_2OP:
return makeBinOp(BinOp.RShift);
case JJTADD_2OP:
return makeBinOp(BinOp.Add);
case JJTSUB_2OP:
return makeBinOp(BinOp.Sub);
case JJTMUL_2OP:
return makeBinOp(BinOp.Mult);
case JJTDIV_2OP:
return makeBinOp(BinOp.Div);
case JJTMOD_2OP:
return makeBinOp(BinOp.Mod);
case JJTPOW_2OP:
return makeBinOp(BinOp.Pow);
case JJTFLOORDIV_2OP:
return makeBinOp(BinOp.FloorDiv);
case JJTPOS_1OP:
return new UnaryOp(UnaryOp.UAdd, makeExpr());
case JJTNEG_1OP:
return new UnaryOp(UnaryOp.USub, makeExpr());
case JJTINVERT_1OP:
return new UnaryOp(UnaryOp.Invert, makeExpr());
case JJTNOT_1OP:
return new UnaryOp(UnaryOp.Not, makeExpr());
case JJTCALL_OP:
//if (arity == 1)
// return new Call(makeExpr(), null, null, null, null);
exprType starargs = null;
exprType kwargs = null;
l = arity - 1;
if (l > 0 && peekNode().getId() == JJTEXTRAKEYWORDVALUELIST) {
kwargs = ((ExtraArgValue) popNode()).value;
l--;
}
if (l > 0 && peekNode().getId() == JJTEXTRAARGVALUELIST) {
starargs = ((ExtraArgValue) popNode()).value;
l--;
}
int nargs = l;
SimpleNode[] tmparr = new SimpleNode[l];
for (int i = l - 1; i >= 0; i--) {
tmparr[i] = popNode();
if (tmparr[i] instanceof keywordType) {
nargs = i;
}
}
exprType[] args = new exprType[nargs];
for (int i = 0; i < nargs; i++) {
args[i] = makeExpr(tmparr[i]);
}
keywordType[] keywords = new keywordType[l - nargs];
for (int i = nargs; i < l; i++) {
if (!(tmparr[i] instanceof keywordType))
throw new ParseException(
"non-keyword argument following keyword", tmparr[i]);
keywords[i - nargs] = (keywordType) tmparr[i];
}
exprType func = makeExpr();
return new Call(func, args, keywords, starargs, kwargs);
case JJTEXTRAKEYWORDVALUELIST:
return new ExtraArgValue(makeExpr(), JJTEXTRAKEYWORDVALUELIST);
case JJTEXTRAARGVALUELIST:
return new ExtraArgValue(makeExpr(), JJTEXTRAARGVALUELIST);
case JJTKEYWORD:
value = makeExpr();
name = makeIdentifier();
return new keywordType(name, value);
case JJTTUPLE:
return new Tuple(makeExprs(), Tuple.Load);
case JJTLIST:
if (peekNode() instanceof listcompType) {
listcompType[] generators = new listcompType[arity-1];
for (int i = arity-2; i >= 0; i--) {
generators[i] = (listcompType) popNode();
}
return new ListComp(makeExpr(), generators);
}
return new List(makeExprs(), List.Load);
case JJTDICTIONARY:
l = arity / 2;
exprType[] keys = new exprType[l];
exprType[] vals = new exprType[l];
for (int i = l - 1; i >= 0; i--) {
vals[i] = makeExpr();
keys[i] = makeExpr();
}
return new Dict(keys, vals);
case JJTSTR_1OP:
return new Repr(makeExpr());
case JJTSTRJOIN:
String str2 = ((Str) popNode()).s;
String str1 = ((Str) popNode()).s;
return new Str(str1 + str2);
case JJTLAMBDEF:
test = makeExpr();
arguments = makeArguments(arity - 1);
return new Lambda(arguments, test);
case JJTELLIPSES:
return new Ellipsis();
case JJTSLICE:
SimpleNode[] arr = new SimpleNode[arity];
for (int i = arity-1; i >= 0; i--) {
arr[i] = popNode();
}
exprType[] values = new exprType[3];
int k = 0;
for (int j = 0; j < arity; j++) {
if (arr[j].getId() == JJTCOLON)
k++;
else
values[k] = makeExpr(arr[j]);
}
if (k == 0) {
return new Index(values[0]);
} else {
return new Slice(values[0], values[1], values[2]);
}
case JJTSUBSCRIPTLIST:
sliceType[] dims = new sliceType[arity];
for (int i = arity - 1; i >= 0; i--) {
dims[i] = (sliceType) popNode();
}
return new ExtSlice(dims);
case JJTAUG_PLUS:
return makeAugAssign(AugAssign.Add);
case JJTAUG_MINUS:
return makeAugAssign(AugAssign.Sub);
case JJTAUG_MULTIPLY:
return makeAugAssign(AugAssign.Mult);
case JJTAUG_DIVIDE:
return makeAugAssign(AugAssign.Div);
case JJTAUG_MODULO:
return makeAugAssign(AugAssign.Mod);
case JJTAUG_AND:
return makeAugAssign(AugAssign.BitAnd);
case JJTAUG_OR:
return makeAugAssign(AugAssign.BitOr);
case JJTAUG_XOR:
return makeAugAssign(AugAssign.BitXor);
case JJTAUG_LSHIFT:
return makeAugAssign(AugAssign.LShift);
case JJTAUG_RSHIFT:
return makeAugAssign(AugAssign.RShift);
case JJTAUG_POWER:
return makeAugAssign(AugAssign.Pow);
case JJTAUG_FLOORDIVIDE:
return makeAugAssign(AugAssign.FloorDiv);
case JJTLIST_FOR:
exprType[] ifs = new exprType[arity-2];
for (int i = arity-3; i >= 0; i--) {
ifs[i] = makeExpr();
}
iter = makeExpr();
target = makeExpr();
ctx.setStore(target);
return new listcompType(target, iter, ifs);
case JJTIMPORTFROM:
aliasType[] aliases = makeAliases(arity - 1);
String module = makeIdentifier();
return new ImportFrom(module, aliases);
case JJTIMPORT:
return new Import(makeAliases());
case JJTDOTTED_NAME:
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arity; i++) {
if (i > 0)
sb.insert(0, '.');
sb.insert(0, makeIdentifier());
}
return new Name(sb.toString(), Name.Load);
case JJTDOTTED_AS_NAME:
String asname = null;
if (arity > 1)
asname = makeIdentifier();
return new aliasType(makeIdentifier(), asname);
case JJTIMPORT_AS_NAME:
asname = null;
if (arity > 1)
asname = makeIdentifier();
return new aliasType(makeIdentifier(), asname);
case JJTCOMMA:
case JJTCOLON:
return n;
default:
return null;
}
}
private stmtType makeAugAssign(int op) throws Exception {
exprType value = makeExpr();
exprType target = makeExpr();
ctx.setAugStore(target);
return new AugAssign(target, op, value);
}
private void dumpStack() {
int n = stack.nodeArity();
System.out.println("nodeArity:" + n);
if (n > 0) {
System.out.println("peek:" + stack.peekNode());
}
}
SimpleNode peekNode() {
return (SimpleNode) stack.peekNode();
}
SimpleNode popNode() {
return (SimpleNode) stack.popNode();
}
BinOp makeBinOp(int op) {
exprType right = makeExpr();
exprType left = makeExpr();
return new BinOp(left, op, right);
}
argumentsType makeArguments(int l) throws Exception {
String kwarg = null;
String stararg = null;
if (l > 0 && peekNode().getId() == JJTEXTRAKEYWORDLIST) {
kwarg = ((ExtraArg) popNode()).name;
l--;
}
if (l > 0 && peekNode().getId() == JJTEXTRAARGLIST) {
stararg = ((ExtraArg) popNode()).name;
l--;
}
int startofdefaults = l;
exprType fpargs[] = new exprType[l];
exprType defaults[] = new exprType[l];
for (int i = l-1; i >= 0; i--) {
DefaultArg node = (DefaultArg) popNode();
fpargs[i] = node.parameter;
ctx.setStore(fpargs[i]);
defaults[i] = node.value;
if (node.value != null)
startofdefaults = i;
}
//System.out.println("start "+ startofdefaults + " " + l);
exprType[] newdefs = new exprType[l-startofdefaults];
System.arraycopy(defaults, startofdefaults, newdefs, 0, newdefs.length);
return new argumentsType(fpargs, stararg, kwarg, newdefs);
}
}
class DefaultArg extends SimpleNode {
public exprType parameter;
public exprType value;
DefaultArg(exprType parameter, exprType value) {
this.parameter = parameter;
this.value = value;
}
}
class ExtraArg extends SimpleNode {
public String name;
public int id;
ExtraArg(String name, int id) {
this.name = name;
this.id = id;
}
public int getId() {
return id;
}
}
class ExtraArgValue extends SimpleNode {
public exprType value;
public int id;
ExtraArgValue(exprType value, int id) {
this.value = value;
this.id = id;
}
public int getId() {
return id;
}
}
class IdentityNode extends SimpleNode {
public int id;
public Object image;
IdentityNode(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setImage(Object image) {
this.image = image;
}
public Object getImage() {
return image;
}
public String toString() {
return "IdNode[" + PythonGrammarTreeConstants.jjtNodeName[id] + ", " +
image + "]";
}
}
class CtxVisitor extends Visitor {
private int ctx;
public CtxVisitor() { }
public void setStore(SimpleNode node) throws Exception {
this.ctx = expr_contextType.Store;
visit(node);
}
public void setStore(SimpleNode[] nodes) throws Exception {
for (int i = 0; i < nodes.length; i++)
setStore(nodes[i]);
}
public void setDelete(SimpleNode node) throws Exception {
this.ctx = expr_contextType.Del;
visit(node);
}
public void setDelete(SimpleNode[] nodes) throws Exception {
for (int i = 0; i < nodes.length; i++)
setDelete(nodes[i]);
}
public void setAugStore(SimpleNode node) throws Exception {
this.ctx = expr_contextType.AugStore;
visit(node);
}
public Object visitName(Name node) throws Exception {
node.ctx = ctx;
return null;
}
public Object visitAttribute(Attribute node) throws Exception {
node.ctx = ctx;
return null;
}
public Object visitSubscript(Subscript node) throws Exception {
node.ctx = ctx;
return null;
}
public Object visitList(List node) throws Exception {
if (ctx == expr_contextType.AugStore) {
throw new ParseException(
"augmented assign to list not possible", node);
}
node.ctx = ctx;
traverse(node);
return null;
}
public Object visitTuple(Tuple node) throws Exception {
if (ctx == expr_contextType.AugStore) {
throw new ParseException(
"augmented assign to tuple not possible", node);
}
node.ctx = ctx;
traverse(node);
return null;
}
public Object visitCall(Call node) throws Exception {
throw new ParseException("can't assign to function call", node);
}
public Object visitListComp(Call node) throws Exception {
throw new ParseException("can't assign to list comprehension call",
node);
}
public Object unhandled_node(SimpleNode node) throws Exception {
throw new ParseException("can't assign to operator", node);
}
}
Index: JJTPythonGrammarState.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/parser/JJTPythonGrammarState.java,v
retrieving revision 2.2
retrieving revision 2.3
diff -C2 -d -r2.2 -r2.3
*** JJTPythonGrammarState.java 6 Jan 2002 21:19:14 -0000 2.2
--- JJTPythonGrammarState.java 30 May 2002 16:08:02 -0000 2.3
***************
*** 1,123 ****
! /* Generated By:JJTree: Do not edit this line. D:/jython/CVS/org/python/parser\JJTPythonGrammarState.java */
package org.python.parser;
class JJTPythonGrammarState {
! private java.util.Stack nodes;
! private java.util.Stack marks;
! private int sp; // number of nodes on stack
! private int mk; // current mark
! private boolean node_created;
! JJTPythonGrammarState() {
! nodes = new java.util.Stack();
! marks = new java.util.Stack();
! sp = 0;
! mk = 0;
! }
! /* Determines whether the current node was actually closed and
! pushed. This should only be called in the final user action of a
! node scope. */
! boolean nodeCreated() {
! return node_created;
! }
! /* Call this to reinitialize the node stack. It is called
! automatically by the parser's ReInit() method. */
! void reset() {
! nodes.removeAllElements();
! marks.removeAllElements();
! sp = 0;
! mk = 0;
! }
! /* Returns the root node of the AST. It only makes sense to call
! this after a successful parse. */
! Node rootNode() {
! return (Node)nodes.elementAt(0);
! }
! /* Pushes a node on to the stack. */
! void pushNode(Node n) {
! nodes.push(n);
! ++sp;
! }
! /* Returns the node on the top of the stack, and remove it from the
! stack. */
! Node popNode() {
! if (--sp < mk) {
! mk = ((Integer)marks.pop()).intValue();
}
- return (Node)nodes.pop();
- }
! /* Returns the node currently on the top of the stack. */
! Node peekNode() {
! return (Node)nodes.peek();
! }
! /* Returns the number of children on the stack in the current node
! scope. */
! int nodeArity() {
! return sp - mk;
! }
! void clearNodeScope(Node n) {
! while (sp > mk) {
! popNode();
}
- mk = ((Integer)marks.pop()).intValue();
- }
- void openNodeScope(Node n) {
- marks.push(new Integer(mk));
- mk = sp;
- n.jjtOpen();
- }
! /* A definite node is constructed from a specified number of
! children. That number of nodes are popped from the stack and
! made the children of the definite node. Then the definite node
! is pushed on to the stack. */
! void closeNodeScope(Node n, int num) {
! mk = ((Integer)marks.pop()).intValue();
! while (num-- > 0) {
! Node c = popNode();
! c.jjtSetParent(n);
! n.jjtAddChild(c, num);
}
- n.jjtClose();
- pushNode(n);
- node_created = true;
- }
! /* A conditional node is constructed if its condition is true. All
! the nodes that have been pushed since the node was opened are
! made children of the the conditional node, which is then pushed
! on to the stack. If the condition is false the node is not
! constructed and they are left on the stack. */
! void closeNodeScope(Node n, boolean condition) {
! if (condition) {
! int a = nodeArity();
! mk = ((Integer)marks.pop()).intValue();
! while (a-- > 0) {
! Node c = popNode();
! c.jjtSetParent(n);
! n.jjtAddChild(c, a);
! }
! n.jjtClose();
! pushNode(n);
! node_created = true;
! } else {
! mk = ((Integer)marks.pop()).intValue();
! node_created = false;
}
- }
}
--- 1,219 ----
! /* Generated By:JJTree: Do not edit this line. D:/jython/CVS.parser/org/python/parser\JJTPythonGrammarState.java */
!
! // Modified by hand. The two closeNodeScope method have been rewritten
! // completely and is used when building the AST tree bottom-up.
package org.python.parser;
class JJTPythonGrammarState {
! private java.util.Stack nodes;
! private IntStack marks;
! private IntStack lines;
! private IntStack columns;
! private int sp; // number of nodes on stack
! private int mk; // current mark
! private boolean node_created;
! private TreeBuilder builder;
! JJTPythonGrammarState() {
! nodes = new java.util.Stack();
! marks = new IntStack();
! lines = new IntStack();
! columns = new IntStack();
! sp = 0;
! mk = 0;
! builder = new TreeBuilder(this);
! }
! /* Determines whether the current node was actually closed and
! pushed. This should only be called in the final user action of a
! node scope. */
! boolean nodeCreated() {
! return node_created;
! }
! /* Call this to reinitialize the node stack. It is called
! automatically by the parser's ReInit() method. */
! void reset() {
! nodes.removeAllElements();
! marks.removeAllElements();
! sp = 0;
! mk = 0;
! }
! /* Returns the root node of the AST. It only makes sense to call
! this after a successful parse. */
! Node rootNode() {
! return (Node)nodes.elementAt(0);
! }
! /* Pushes a node on to the stack. */
! void pushNode(Node n) {
! nodes.push(n);
! ++sp;
}
! /* Returns the node on the top of the stack, and remove it from the
! stack. */
! Node popNode() {
! if (--sp < mk) {
! mk = marks.pop();
! }
! return (Node)nodes.pop();
! }
! /* Returns the node currently on the top of the stack. */
! Node peekNode() {
! return (Node)nodes.peek();
! }
+ /* Returns the number of children on the stack in the current node
+ scope. */
+ int nodeArity() {
+ return sp - mk;
+ }
! void pushNodePos(int line, int col) {
! lines.push(line);
! columns.push(col);
}
+ void setNodePos() {
+ SimpleNode n = (SimpleNode) peekNode();
+ n.beginLine = lines.pop();
+ n.beginColumn = columns.pop();
+ }
+ void clearNodeScope(Node n) {
+ while (sp > mk) {
+ popNode();
+ }
+ mk = marks.pop();
+ }
!
! void openNodeScope(Node n) {
! marks.push(mk);
! mk = sp;
}
! /* A definite node is constructed from a specified number of
! children. That number of nodes are popped from the stack and
! made the children of the definite node. Then the definite node
! is pushed on to the stack. */
! void closeNodeScope(Node n, int num) throws ParseException {
! SimpleNode sn = (SimpleNode) n;
! mk = marks.pop();
! SimpleNode newNode = null;
! try {
! newNode = builder.closeNode(sn, num);
! } catch (ParseException exc) {
! throw exc;
! } catch (Exception exc) {
! exc.printStackTrace();
! throw new ParseException("Internal error:" + exc);
! }
! if (newNode == null) {
! throw new ParseException("Internal AST builder error");
! }
! pushNode(newNode);
! node_created = true;
! }
!
!
! /* A conditional node is constructed if its condition is true. All
! the nodes that have been pushed since the node was opened are
! made children of the the conditional node, which is then pushed
! on to the stack. If the condition is false the node is not
! constructed and they are left on the stack. */
! void closeNodeScope(Node n, boolean condition) throws ParseException {
! SimpleNode sn = (SimpleNode) n;
! if (condition) {
! SimpleNode newNode = null;
! try {
! newNode = builder.closeNode(sn, nodeArity());
! } catch (ParseException exc) {
! throw exc;
! } catch (Exception exc) {
! exc.printStackTrace();
! throw new ParseException("Internal error:" + exc);
! }
! if (newNode == null) {
! throw new ParseException("Internal AST builder error");
! }
! mk = marks.pop();
! pushNode(newNode);
! node_created = true;
! } else {
! mk = marks.pop();
! node_created = false;
! }
! }
!
! public void dumpTop(String reason) {
! int a = nodeArity();
! System.out.println("dumpTop:" + reason);
! System.out.println("arity:" + a);
! for (int i = 0; i < a; i++) {
! Node n = (Node) nodes.elementAt(nodes.size() - i-1);
! System.out.println(" " + n);
! }
! }
!
! public Node openNode(int id) {
! return builder.openNode(id);
! }
!
! public void dump(String reason) {
! int a = nodeArity();
! System.out.println("dump:" + reason);
! System.out.println(" mk:" + mk + " sp:" + sp);
! for (int i = 0; i < nodes.size(); i++) {
! Node n = (Node) nodes.elementAt(i);
! System.out.println(" " + n);
! }
! for (int i = 0; i < marks.size(); i++) {
! System.out.println(" " + marks.elementAt(i));
! }
! }
! }
!
!
! class IntStack {
! int[] stack;
! int sp = 0;
!
! public IntStack() {
! stack = new int[50];
! }
!
!
! public void removeAllElements() {
! sp = 0;
! }
!
! public int size() {
! return sp;
! }
!
! public int elementAt(int idx) {
! return stack[idx];
! }
!
! public void push(int val) {
! if (sp >= stack.length) {
! int[] newstack = new int[sp*2];
! System.arraycopy(stack, 0, newstack, 0, sp);
! stack = newstack;
! }
! stack[sp++] = val;
! }
!
! public int pop() {
! return stack[--sp];
}
}
Index: Node.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/parser/Node.java,v
retrieving revision 2.1
retrieving revision 2.2
diff -C2 -d -r2.1 -r2.2
*** Node.java 3 Mar 1999 21:42:26 -0000 2.1
--- Node.java 30 May 2002 16:08:02 -0000 2.2
***************
*** 9,34 ****
public interface Node {
- /** This method is called after the node has been made the current
- node. It indicates that child nodes can now be added to it. */
- public void jjtOpen();
-
- /** This method is called after all the child nodes have been
- added. */
- public void jjtClose();
-
- /** This pair of methods are used to inform the node of its
- parent. */
- public void jjtSetParent(Node n);
- public Node jjtGetParent();
-
- /** This method tells the node to add its argument to the node's
- list of children. */
- public void jjtAddChild(Node n, int i);
-
- /** This method returns a child node. The children are numbered
- from zero, left to right. */
- public Node jjtGetChild(int i);
-
- /** Return the number of children the node has. */
- public int jjtGetNumChildren();
}
--- 9,12 ----
public interface Node {
}
+
Index: ParseException.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/parser/ParseException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ParseException.java 29 Jan 1999 15:37:58 -0000 1.3
--- ParseException.java 30 May 2002 16:08:02 -0000 1.4
***************
*** 63,68 ****
t.beginLine = node.beginLine;
t.beginColumn = node.beginColumn;
- t.endLine = node.endLine;
- t.endColumn = node.endColumn;
currentToken = new Token();
--- 63,66 ----
***************
*** 71,76 ****
t.beginLine = node.beginLine;
t.beginColumn = node.beginColumn;
- t.endLine = node.endLine;
- t.endColumn = node.endColumn;
specialConstructor = false;
--- 69,72 ----
Index: SimpleNode.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/parser/SimpleNode.java,v
retrieving revision 2.18
retrieving revision 2.19
diff -C2 -d -r2.18 -r2.19
*** SimpleNode.java 13 Jan 2002 18:23:08 -0000 2.18
--- SimpleNode.java 30 May 2002 16:08:02 -0000 2.19
***************
*** 2,366 ****
package org.python.parser;
! import org.python.core.Py;
! import org.python.core.PyString;
! public class SimpleNode implements Node
! {
! protected Node parent;
! public SimpleNode[] children;
! public int id;
! protected PythonGrammar parser;
! public int endLine, endColumn, beginLine, beginColumn;
! Object info;
! public int aug_tmp1, aug_tmp2, aug_tmp3, aug_tmp4;
- public org.python.compiler.ScopeInfo scope; // for nested scopes
public boolean from_future_checked = false; // from __future__ support
! public SimpleNode(int i) {
! id = i;
! }
!
! public SimpleNode(PythonGrammar p, int i) {
! this(i);
! parser = p;
! }
! public static Node jjtCreate(int id) {
! return new SimpleNode(id);
}
! public static Node jjtCreate(PythonGrammar p, int id) {
! return new SimpleNode(p, id);
}
! public void jjtOpen() {
}
! public void jjtClose() {
}
! public void jjtSetParent(Node n) { parent = n; }
! public Node jjtGetParent() { return parent; }
! public void jjtAddChild(Node n, int i) {
! if (children == null) {
! children = new SimpleNode[i + 1];
! } else if (i >= children.length) {
! SimpleNode c[] = new SimpleNode[i + 1];
! System.arraycopy(children, 0, c, 0, children.length);
! children = c;
! }
! children[i] = (SimpleNode)n;
}
! public Node jjtGetChild(int i) {
! return children[i];
}
! public int jjtGetNumChildren() {
! return (children == null) ? 0 : children.length;
}
! public SimpleNode getChild(int i) {
! return children[i];
}
! public int getNumChildren() {
! return (children == null) ? 0 : children.length;
}
! public Object getInfo() { return info; }
! public void setInfo(Object o) {
! info = o;
! //System.out.println("name: "+info);
}
! public void setString(String s, int quotes) {
! info = parseString(s, quotes, beginLine, beginColumn);
}
! public static String parseString(String s, int quotes,
! int beginLine, int beginColumn) {
! //System.out.println("string: "+s);
! char quoteChar = s.charAt(0);
! int start=0;
! boolean ustring = false;
! if (quoteChar == 'u' || quoteChar == 'U') {
! ustring = true;
! start++;
! }
! quoteChar = s.charAt(start);
! if (quoteChar == 'r' || quoteChar == 'R') {
! return s.substring(quotes+start+1, s.length()-quotes);
} else {
! StringBuffer sb = new StringBuffer(s.length());
! char[] ca = s.toCharArray();
! int n = ca.length-quotes;
! int i=quotes+start;
! int last_i=i;
!
! return PyString.decode_UnicodeEscape(s, i, n, "strict", ustring);
}
}
! public void setInteger(String s, int radix) {
! if (s.endsWith("j") || s.endsWith("J")) {
! setFloat(s);
} else {
! if (s.endsWith("L") || s.endsWith("l")) {
! s = s.substring(0, s.length()-1);
! if (radix == 10) setInfo(s);
! else setInfo(new java.math.BigInteger(s, radix).toString());
! } else {
! int ndigits = s.length();
! int i=0;
! while (i < ndigits && s.charAt(i) == '0') i++;
! if ((ndigits - i) > 11) {
! throw Py.OverflowError("integer literal too large");
! }
! long l = Long.valueOf(s, radix).longValue();
! if (l > 0xffffffffl || (radix == 10 && l > Integer.MAX_VALUE))
! {
! throw Py.OverflowError("integer literal too large");
! }
! setInfo(new Integer((int)l));
}
}
}
! public void setFloat(String s) {
! if (s.endsWith("j") || s.endsWith("J")) {
! setInfo(Double.valueOf(s.substring(0, s.length()-1)));
! id = PythonGrammarTreeConstants.JJTCOMPLEX;
} else {
! setInfo(Double.valueOf(s));
}
}
! /* You can override these two methods in subclasses of SimpleNode to
! customize the way the node appears when the tree is dumped. If
! your output uses more than one line you should override
! toString(String), otherwise overriding toString() is probably all
! you need to do. */
!
! public String toString() {
! return PythonGrammarTreeConstants.jjtNodeName[id]+":"+info+
! " at line "+beginLine;
}
- public String toString(String prefix) { return prefix + toString(); }
! /* Override this method if you want to customize how the node dumps
! out its children. */
! public void dump(String prefix) {
! System.out.println(toString(prefix));
! if (children != null) {
! for (int i = 0; i < children.length; ++i) {
! SimpleNode n = (SimpleNode)children[i];
! if (n != null) {
! n.dump(prefix + " ");
! }
}
}
}
! public Object visit(Visitor visitor) throws Exception {
! switch(id) {
! case PythonGrammarTreeConstants.JJTSINGLE_INPUT:
! return visitor.single_input(this);
! case PythonGrammarTreeConstants.JJTFILE_INPUT:
! return visitor.file_input(this);
! case PythonGrammarTreeConstants.JJTEVAL_INPUT:
! return visitor.eval_input(this);
! case PythonGrammarTreeConstants.JJTFUNCDEF:
! return visitor.funcdef(this);
! case PythonGrammarTreeConstants.JJTVARARGSLIST:
! return visitor.varargslist(this);
! case PythonGrammarTreeConstants.JJTEXTRAARGLIST:
! return visitor.ExtraArgList(this);
! case PythonGrammarTreeConstants.JJTEXTRAKEYWORDLIST:
! return visitor.ExtraKeywordList(this);
! case PythonGrammarTreeConstants.JJTDEFAULTARG:
! return visitor.defaultarg(this);
! case PythonGrammarTreeConstants.JJTFPLIST:
! return visitor.fplist(this);
! case PythonGrammarTreeConstants.JJTEXPR_STMT:
! return visitor.expr_stmt(this);
! case PythonGrammarTreeConstants.JJTPRINT_STMT:
! return visitor.print_stmt(this);
! case PythonGrammarTreeConstants.JJTPRINT_EXT:
! return visitor.print_ext(this);
! case PythonGrammarTreeConstants.JJTDEL_STMT:
! return visitor.del_stmt(this);
! case PythonGrammarTreeConstants.JJTPASS_STMT:
! return visitor.pass_stmt(this);
! case PythonGrammarTreeConstants.JJTBREAK_STMT:
! return visitor.break_stmt(this);
! case PythonGrammarTreeConstants.JJTCONTINUE_STMT:
! return visitor.continue_stmt(this);
! case PythonGrammarTreeConstants.JJTRETURN_STMT:
! return visitor.return_stmt(this);
! case PythonGrammarTreeConstants.JJTRAISE_STMT:
! return visitor.raise_stmt(this);
! case PythonGrammarTreeConstants.JJTIMPORT:
! return visitor.Import(this);
! case PythonGrammarTreeConstants.JJTIMPORTFROM:
! return visitor.ImportFrom(this);
! case PythonGrammarTreeConstants.JJTDOTTED_NAME:
! return visitor.dotted_name(this);
! case PythonGrammarTreeConstants.JJTGLOBAL_STMT:
! return visitor.global_stmt(this);
! case PythonGrammarTreeConstants.JJTEXEC_STMT:
! return visitor.exec_stmt(this);
! case PythonGrammarTreeConstants.JJTASSERT_STMT:
! return visitor.assert_stmt(this);
! case PythonGrammarTreeConstants.JJTIF_STMT:
! return visitor.if_stmt(this);
! case PythonGrammarTreeConstants.JJTWHILE_STMT:
! return visitor.while_stmt(this);
! case PythonGrammarTreeConstants.JJTFOR_STMT:
! return visitor.for_stmt(this);
! case PythonGrammarTreeConstants.JJTTRY_STMT:
! return visitor.try_stmt(this);
! case PythonGrammarTreeConstants.JJTEXCEPT_CLAUSE:
! return visitor.except_clause(this);
! case PythonGrammarTreeConstants.JJTSUITE:
! return visitor.suite(this);
! case PythonGrammarTreeConstants.JJTOR_BOOLEAN:
! return visitor.or_boolean(this);
! case PythonGrammarTreeConstants.JJTAND_BOOLEAN:
! return visitor.and_boolean(this);
! case PythonGrammarTreeConstants.JJTNOT_1OP:
! return visitor.not_1op(this);
! case PythonGrammarTreeConstants.JJTCOMPARISION:
! return visitor.comparision(this);
! case PythonGrammarTreeConstants.JJTLESS_CMP:
! return visitor.less_cmp(this);
! case PythonGrammarTreeConstants.JJTGREATER_CMP:
! return visitor.greater_cmp(this);
! case PythonGrammarTreeConstants.JJTEQUAL_CMP:
! return visitor.equal_cmp(this);
! case PythonGrammarTreeConstants.JJTGREATER_EQUAL_CMP:
! return visitor.greater_equal_cmp(this);
! case PythonGrammarTreeConstants.JJTLESS_EQUAL_CMP:
! return visitor.less_equal_cmp(this);
! case PythonGrammarTreeConstants.JJTNOTEQUAL_CMP:
! return visitor.notequal_cmp(this);
! case PythonGrammarTreeConstants.JJTIN_CMP:
! return visitor.in_cmp(this);
! case PythonGrammarTreeConstants.JJTNOT_IN_CMP:
! return visitor.not_in_cmp(this);
! case PythonGrammarTreeConstants.JJTIS_NOT_CMP:
! return visitor.is_not_cmp(this);
! case PythonGrammarTreeConstants.JJTIS_CMP:
! return visitor.is_cmp(this);
! case PythonGrammarTreeConstants.JJTOR_2OP:
! return visitor.or_2op(this);
! case PythonGrammarTreeConstants.JJTXOR_2OP:
! return visitor.xor_2op(this);
! case PythonGrammarTreeConstants.JJTAND_2OP:
! return visitor.and_2op(this);
! case PythonGrammarTreeConstants.JJTLSHIFT_2OP:
! return visitor.lshift_2op(this);
! case PythonGrammarTreeConstants.JJTRSHIFT_2OP:
! return visitor.rshift_2op(this);
! case PythonGrammarTreeConstants.JJTADD_2OP:
! return visitor.add_2op(this);
! case PythonGrammarTreeConstants.JJTSUB_2OP:
! return visitor.sub_2op(this);
! case PythonGrammarTreeConstants.JJTMUL_2OP:
! return visitor.mul_2op(this);
! case PythonGrammarTreeConstants.JJTDIV_2OP:
! return visitor.div_2op(this);
! case PythonGrammarTreeConstants.JJTFLOORDIV_2OP:
! return visitor.floordiv_2op(this);
! case PythonGrammarTreeConstants.JJTMOD_2OP:
! return visitor.mod_2op(this);
! case PythonGrammarTreeConstants.JJTPOS_1OP:
! return visitor.pos_1op(this);
! case PythonGrammarTreeConstants.JJTNEG_1OP:
! return visitor.neg_1op(this);
! case PythonGrammarTreeConstants.JJTINVERT_1OP:
! return visitor.invert_1op(this);
! case PythonGrammarTreeConstants.JJTPOW_2OP:
! return visitor.pow_2op(this);
! case PythonGrammarTreeConstants.JJTCALL_OP:
! return visitor.Call_Op(this);
! case PythonGrammarTreeConstants.JJTINDEX_OP:
! return visitor.Index_Op(this);
! case PythonGrammarTreeConstants.JJTDOT_OP:
! return visitor.Dot_Op(this);
! case PythonGrammarTreeConstants.JJTTUPLE:
! return visitor.tuple(this);
! case PythonGrammarTreeConstants.JJTLIST:
! return visitor.list(this);
! case PythonGrammarTreeConstants.JJTDICTIONARY:
! return visitor.dictionary(this);
! case PythonGrammarTreeConstants.JJTSTR_1OP:
! return visitor.str_1op(this);
! case PythonGrammarTreeConstants.JJTSTRJOIN:
! return visitor.strjoin(this);
! case PythonGrammarTreeConstants.JJTLAMBDEF:
! return visitor.lambdef(this);
! case PythonGrammarTreeConstants.JJTELLIPSES:
! return visitor.Ellipses(this);
! case PythonGrammarTreeConstants.JJTSLICE:
! return visitor.Slice(this);
! case PythonGrammarTreeConstants.JJTCOLON:
! return visitor.Colon(this);
! case PythonGrammarTreeConstants.JJTCOMMA:
! return visitor.Comma(this);
! case PythonGrammarTreeConstants.JJTCLASSDEF:
! return visitor.classdef(this);
! case PythonGrammarTreeConstants.JJTARGLIST:
! return visitor.arglist(this);
! case PythonGrammarTreeConstants.JJTKEYWORD:
! return visitor.Keyword(this);
! case PythonGrammarTreeConstants.JJTINT:
! return visitor.Int(this);
! case PythonGrammarTreeConstants.JJTFLOAT:
! return visitor.Float(this);
! case PythonGrammarTreeConstants.JJTCOMPLEX:
! return visitor.Complex(this);
! case PythonGrammarTreeConstants.JJTNAME:
! return visitor.Name(this);
! case PythonGrammarTreeConstants.JJTSTRING:
! return visitor.String(this);
! case PythonGrammarTreeConstants.JJTAUG_PLUS:
! return visitor.aug_plus(this);
! case PythonGrammarTreeConstants.JJTAUG_MINUS:
! return visitor.aug_minus(this);
! case PythonGrammarTreeConstants.JJTAUG_MULTIPLY:
! return visitor.aug_multiply(this);
! case PythonGrammarTreeConstants.JJTAUG_DIVIDE:
! return visitor.aug_divide(this);
! case PythonGrammarTreeConstants.JJTAUG_FLOORDIVIDE:
! return visitor.aug_floordivide(this);
! case PythonGrammarTreeConstants.JJTAUG_MODULO:
! return visitor.aug_modulo(this);
! case PythonGrammarTreeConstants.JJTAUG_AND:
! return visitor.aug_and(this);
! case PythonGrammarTreeConstants.JJTAUG_OR:
! return visitor.aug_or(this);
! case PythonGrammarTreeConstants.JJTAUG_XOR:
! return visitor.aug_xor(this);
! case PythonGrammarTreeConstants.JJTAUG_LSHIFT:
! return visitor.aug_lshift(this);
! case PythonGrammarTreeConstants.JJTAUG_RSHIFT:
! return visitor.aug_rshift(this);
! case PythonGrammarTreeConstants.JJTAUG_POWER:
! return visitor.aug_power(this);
! case PythonGrammarTreeConstants.JJTLIST_ITER:
! return visitor.list_iter(this);
! default:
! throw new ParseException("Unexpected node: "+this);
! }
!
}
}
--- 2,192 ----
package org.python.parser;
! import org.python.core.PyObject;
! import org.python.parser.ast.*;
! import java.io.DataOutputStream;
! import java.io.IOException;
! public class SimpleNode implements Node {
! public int beginLine, beginColumn;
public boolean from_future_checked = false; // from __future__ support
! public SimpleNode() { }
! public static Node jjtCreate(PythonGrammar p, int id) {
! return p.jjtree.openNode(id);
}
! public int getId() {
! return -1;
}
! public Object getImage() {
! return null;
}
! public void setImage(Object image) {
}
! /* You can override these two methods in subclasses of SimpleNode to
! customize the way the node appears when the tree is dumped. If
! your output uses more than one line you should override
! toString(String), otherwise overriding toString() is probably all
! you need to do. */
! public String toString() {
! return super.toString() + " at line "+beginLine;
}
+ public String toString(String prefix) { return prefix + toString(); }
! public Object accept(VisitorIF visitor) throws Exception {
! throw new ParseException("Unexpected node: "+this);
}
! public void traverse(VisitorIF visitor) throws Exception {
! throw new ParseException("Unexpected node: "+this);
}
! /* Override this method if you want to customize how the node dumps
! ut its children. */
!
! protected String dumpThis(String s) {
! return s;
}
! protected String dumpThis(Object o) {
! return String.valueOf(o);
}
! protected String dumpThis(Object[] s) {
! StringBuffer sb = new StringBuffer();
! if (s == null) {
! sb.append("null");
! } else {
! sb.append("[");
! for (int i = 0; i < s.length; i++) {
! if (i > 0)
! sb.append(", ");
! sb.append(String.valueOf(s[i]));
! }
! sb.append("]");
! }
!
! return sb.toString();
! }
! protected String dumpThis(int i) {
! return Integer.toString(i);
}
! protected String dumpThis(int i, String[] names) {
! // XXX Verify bounds.
! return names[i];
}
! protected String dumpThis(int[] arr, String[] names) {
! StringBuffer sb = new StringBuffer();
! if (arr == null) {
! sb.append("null");
} else {
! sb.append("[");
! for (int i = 0; i < arr.length; i++) {
! if (i > 0)
! sb.append(", ");
! // XXX Verify bounds.
! sb.append(names[arr[i]]);
! }
! sb.append("]");
}
+ return sb.toString();
}
+ protected String dumpThis(boolean b) {
+ return Boolean.toString(b);
+ }
! public void pickle(DataOutputStream ostream) throws IOException {
! throw new IOException("Pickling not implemented");
! }
!
! protected void pickleThis(String s, DataOutputStream ostream)
! throws IOException
! {
! if (s == null) {
! ostream.writeInt(-1);
} else {
! ostream.writeInt(s.length());
! ostream.writeBytes(s);
! }
! }
! protected void pickleThis(String[] s, DataOutputStream ostream)
! throws IOException
! {
! if (s == null) {
! ostream.writeInt(-1);
! } else {
! ostream.writeInt(s.length);
! for (int i = 0; i < s.length; i++) {
! pickleThis(s[i], ostream);
}
}
}
! protected void pickleThis(SimpleNode o, DataOutputStream ostream)
! throws IOException
! {
! if (o == null) {
! ostream.writeInt(-1);
} else {
! o.pickle(ostream);
}
}
! protected void pickleThis(SimpleNode[] s, DataOutputStream ostream)
! throws IOException
! {
! if (s == null) {
! ostream.writeInt(-1);
! } else {
! ostream.writeInt(s.length);
! for (int i = 0; i < s.length; i++) {
! pickleThis(s[i], ostream);
! }
! }
}
! protected void pickleThis(int i, DataOutputStream ostream)
! throws IOException
! {
! ostream.writeInt(i);
! }
! protected void pickleThis(int[] arr, DataOutputStream ostream)
! throws IOException
! {
! if (arr == null) {
! ostream.writeInt(-1);
! } else {
! ostream.writeInt(arr.length);
! for (int i = 0; i < arr.length; i++) {
! ostream.writeInt(arr[i]);
}
}
}
! protected void pickleThis(boolean b, DataOutputStream ostream)
! throws IOException
! {
! ostream.writeBoolean(b);
}
+ protected void pickleThis(PyObject n, DataOutputStream ostream)
+ throws IOException
+ {
+ String s = n.toString();
+ ostream.writeInt(s.length());
+ ostream.writeBytes(s);
+ }
}
Index: Visitor.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/parser/Visitor.java,v
retrieving revision 2.6
retrieving revision 2.7
diff -C2 -d -r2.6 -r2.7
*** Visitor.java 13 Jan 2002 18:23:08 -0000 2.6
--- Visitor.java 30 May 2002 16:08:02 -0000 2.7
***************
*** 1,380 ****
- // Copyright (c) Corporation for National Research Initiatives
package org.python.parser;
! public class Visitor {
! public Object single_input(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object file_input(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object eval_input(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object funcdef(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object varargslist(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object ExtraArgList(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object ExtraKeywordList(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object defaultarg(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object fplist(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object expr_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object print_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object print_ext(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object del_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object pass_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object break_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object continue_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object return_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object raise_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object Import(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object ImportFrom(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object dotted_name(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object global_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object exec_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object assert_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object if_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object while_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object for_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object try_stmt(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object except_clause(SimpleNode n) throws Exception {
! throw new ParseException("Unhandled Node: "+n);
! }
!
! public Object suite(SimpleNode n...
[truncated message content] |