Update of /cvsroot/jython/jython/org/python/compiler
In directory usw-pr-cvs1:/tmp/cvs-serv20512
Modified Files:
Code.java CodeCompiler.java
Added Files:
LineNumberTable.java
Log Message:
Added LineNumberTable support. As a result a java stacktrace will show
the correct source linenumber in the $py.class class.
--- NEW FILE ---
// Copyright 2001 Finn Bock
package org.python.compiler;
import java.io.*;
import java.util.*;
public class LineNumberTable extends Attribute {
int attName;
ConstantPool pool;
Vector lines;
public LineNumberTable(ConstantPool pool) throws IOException {
this.pool = pool;
attName = pool.UTF8("LineNumberTable");
lines = new Vector();
}
public void write(DataOutputStream stream) throws IOException {
stream.writeShort(attName);
int n = lines.size();
stream.writeInt(n * 2 + 2);
stream.writeShort(n / 2);
for (int i = 0; i < n; i += 2) {
Short startpc = (Short) lines.elementAt(i);
Short lineno = (Short) lines.elementAt(i+1);
stream.writeShort(startpc.shortValue());
stream.writeShort(lineno.shortValue());
}
}
public void addLine(int startpc, int lineno) {
lines.addElement(new Short((short) startpc));
lines.addElement(new Short((short) lineno));
}
public int length() {
return lines.size() * 2 + 8;
}
}
Index: Code.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/compiler/Code.java,v
retrieving revision 2.2
retrieving revision 2.3
diff -C2 -r2.2 -r2.3
*** Code.java 1999/05/17 19:55:09 2.2
--- Code.java 2001/02/07 09:21:23 2.3
***************
*** 32,35 ****
--- 32,36 ----
int att_name;
Vector labels, exceptions;
+ LineNumberTable linenumbers;
public Label getLabel() {
***************
*** 129,132 ****
--- 130,135 ----
int n = exceptions.size();
int length = bytes.length+12+8*n;;
+ if (linenumbers != null)
+ length += linenumbers.length();
stream.writeShort(att_name);
stream.writeInt(length);
***************
*** 145,149 ****
stream.writeShort(e.exc);
}
! ClassFile.writeAttributes(stream, new Attribute[0]);
}
--- 148,155 ----
stream.writeShort(e.exc);
}
! if (linenumbers != null)
! ClassFile.writeAttributes(stream, new Attribute[] { linenumbers });
! else
! ClassFile.writeAttributes(stream, new Attribute[0]);
}
***************
*** 507,510 ****
--- 513,522 ----
labels[i].setBranch(position, 4);
}
+ }
+
+ public void setline(int line) throws IOException {
+ if (linenumbers == null)
+ linenumbers = new LineNumberTable(pool);
+ linenumbers.addLine(size(), line);
}
}
Index: CodeCompiler.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/compiler/CodeCompiler.java,v
retrieving revision 2.10
retrieving revision 2.11
diff -C2 -r2.10 -r2.11
*** CodeCompiler.java 2000/12/18 21:57:37 2.10
--- CodeCompiler.java 2001/02/07 09:21:23 2.11
***************
*** 76,79 ****
--- 76,80 ----
//System.out.println("line: "+line+", "+code.stack);
if (module.linenumbers) {
+ code.setline(line);
loadFrame();
code.iconst(line);
|