src.org.python.compiler.ClassFile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython Show documentation
Show all versions of jython Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
// Copyright (c) Corporation for National Research Initiatives
package org.python.compiler;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.python.core.imp;
public class ClassFile
{
ClassWriter cw;
int access;
long mtime;
public String name;
String superclass;
String sfilename;
String[] interfaces;
List methodVisitors;
List fieldVisitors;
public static String fixName(String n) {
if (n.indexOf('.') == -1)
return n;
char[] c = n.toCharArray();
for(int i=0; i());
fieldVisitors = Collections.synchronizedList(new ArrayList());
}
public void setSource(String name) {
sfilename = name;
}
public void addInterface(String name) throws IOException {
String[] new_interfaces = new String[interfaces.length+1];
System.arraycopy(interfaces, 0, new_interfaces, 0, interfaces.length);
new_interfaces[interfaces.length] = name;
interfaces = new_interfaces;
}
public Code addMethod(String name, String type, int access)
throws IOException
{
MethodVisitor mv = cw.visitMethod(access, name, type, null, null);
Code pmv = new Code(mv, type, access);
methodVisitors.add(pmv);
return pmv;
}
public void addField(String name, String type, int access)
throws IOException
{
FieldVisitor fv = cw.visitField(access, name, type, null, null);
fieldVisitors.add(fv);
}
public void endFields()
throws IOException
{
for (FieldVisitor fv : fieldVisitors) {
fv.visitEnd();
}
}
public void endMethods()
throws IOException
{
for (int i=0; i