Top Description Inners Fields Constructors Methods
org.python.expose.generate

public abstract Class Exposer

extends Object
implements Opcodes, PyTypes
Class Inheritance
All Implemented Interfaces
org.python.expose.generate.PyTypes, org.objectweb.asm.Opcodes
Known Direct Subclasses
org.python.expose.generate.MethodExposer, org.python.expose.generate.NewExposer, org.python.expose.generate.OverridableNewExposer, org.python.expose.generate.TypeExposer, org.python.expose.generate.DescriptorExposer
Imports
java.util.HashMap, .Map, org.objectweb.asm.ClassVisitor, .ClassWriter, .Label, .MethodVisitor, .Opcodes, .Type, org.python.core.BytecodeLoader

Base class that handles the basics of generating a single class with asm. Subclass to supply the actual functionality of the generated class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
protected ClassVisitor
cv

The current class under construction.

protected Type[]
protected MethodVisitor
mv

The current method under construction or null.

protected static final Map<Type, Type>
PRIMITIVES

Maps from a primitive type to its wrapper

private Type
superType

The super class of the type that will be generated.

protected Type
thisType

The type that will be generated.

Constructor Summary

AccessConstructor and Description
public
Exposer(Class<?>
- the super class of the generated class
superClass
,
String
- the name of the class to generate
generatedName
,
Type... interfacesImplemented)

Method Summary

Modifier and TypeMethod and Description
protected void
call(Type onType, String methodName, Type returnType, Type... args)

Calls the method on onType with the given return type and argument types.

protected void
callConstructor(Type onType, Type... args)

Calls the constructor on onType with the given args.

protected void
callStatic(Type onType, String methodName, Type returnType, Type... args)

Calls the static method on onType with the given return type and argument types.

protected void
endConstructor()

Closes the constructor begun by startConstructor.

protected void
endMethod(int returnCode)

Closes the method under construction.

protected abstract void
generate()

Implemented by subclasses to fill in the actual implementation of the class.

public void
generate(ClassVisitor visitor)

Will call the methods on visitor to generate this class.

protected void
get(String fieldName, Type ofType)

Loads a field on the instance under construction of ofType onto the stack

public String
protected Type
public String
protected void
getStatic(Type onType, String fieldName, Type ofType)

Gets a static field from onType of the given type.

protected void
instantiate(Type ofType)

Instantiates ofType using its no-arg constructor

protected void
instantiate(Type ofType, Exposer.Instantiator inst)

Instantiates ofType with its constructor that takes the types returned by inst.getTypes().

protected Class<?>
load(BytecodeLoader.Loader l)

Generates this Exposer and loads it into the given Loader.

protected String
methodDesc(Type ret, Type... args)

Produces a method descriptor with ret as its return type that takes args.

protected void
startConstructor(Type... args)

Starts building a constructor in the class.

protected void
startMethod(String name, Type ret, Type... args)

Starts building a method in the class being generated.

protected void
superConstructor(Type... args)

Calls the constructor on the super class with the given args.

protected void
toPy(Type inputType)

Turns an object of inputType on the top of the stack into an equivalent Py type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cvback to summary
protected ClassVisitor cv

The current class under construction.

interfacesImplementedback to summary
protected Type[] interfacesImplemented
mvback to summary
protected MethodVisitor mv

The current method under construction or null.

PRIMITIVESback to summary
protected static final Map<Type, Type> PRIMITIVES

Maps from a primitive type to its wrapper

superTypeback to summary
private Type superType

The super class of the type that will be generated.

thisTypeback to summary
protected Type thisType

The type that will be generated.

Constructor Detail

Exposerback to summary
public Exposer(Class<?> superClass, String generatedName, Type... interfacesImplemented)
Parameters
superClass:Class<?>

- the super class of the generated class

generatedName:String

- the name of the class to generate

Method Detail

callback to summary
protected void call(Type onType, String methodName, Type returnType, Type... args)

Calls the method on onType with the given return type and argument types.

callConstructorback to summary
protected void callConstructor(Type onType, Type... args)

Calls the constructor on onType with the given args.

callStaticback to summary
protected void callStatic(Type onType, String methodName, Type returnType, Type... args)

Calls the static method on onType with the given return type and argument types.

endConstructorback to summary
protected void endConstructor()

Closes the constructor begun by startConstructor.

endMethodback to summary
protected void endMethod(int returnCode)

Closes the method under construction.

generateback to summary
protected abstract void generate()

Implemented by subclasses to fill in the actual implementation of the class. cv is set to the ClassVisitor to be used when this is called.

generateback to summary
public void generate(ClassVisitor visitor)

Will call the methods on visitor to generate this class. Only one call to generate may be active at a time on a single instance of Exposer. The ClassVisitor is assumed to have been constructed with COMPUTE_FRAMES.

getback to summary
protected void get(String fieldName, Type ofType)

Loads a field on the instance under construction of ofType onto the stack

getClassNameback to summary
public String getClassName()
getGeneratedTypeback to summary
protected Type getGeneratedType()
getInternalNameback to summary
public String getInternalName()
getStaticback to summary
protected void getStatic(Type onType, String fieldName, Type ofType)

Gets a static field from onType of the given type.

instantiateback to summary
protected void instantiate(Type ofType)

Instantiates ofType using its no-arg constructor

instantiateback to summary
protected void instantiate(Type ofType, Exposer.Instantiator inst)

Instantiates ofType with its constructor that takes the types returned by inst.getTypes(). inst should override pushArgs to put arguments of those types on the stack for the call.

loadback to summary
protected Class<?> load(BytecodeLoader.Loader l)

Generates this Exposer and loads it into the given Loader.

methodDescback to summary
protected String methodDesc(Type ret, Type... args)

Produces a method descriptor with ret as its return type that takes args.

startConstructorback to summary
protected void startConstructor(Type... args)

Starts building a constructor in the class. Must be followed by a call to endConstructor before startConstructor or startMethod may be called.

startMethodback to summary
protected void startMethod(String name, Type ret, Type... args)

Starts building a method in the class being generated. Must be followed by a call to endMethod before startMethod or startConstructor may be called.

superConstructorback to summary
protected void superConstructor(Type... args)

Calls the constructor on the super class with the given args.

toPyback to summary
protected void toPy(Type inputType)

Turns an object of inputType on the top of the stack into an equivalent Py type. Handles primitives, void, and String. If void, the top item on the stack isn't touched.

org.python.expose.generate back to summary

pack-priv Class Exposer.Instantiator

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Type[]

Constructor Summary

AccessConstructor and Description
public
Instantiator(Type... types)

Method Summary

Modifier and TypeMethod and Description
public Type[]
public void
pushArgs()

Push args onto the stack corresponding to the types passed to the constructor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

typesback to summary
private Type[] types

Constructor Detail

Instantiatorback to summary
public Instantiator(Type... types)

Method Detail

getTypesback to summary
public Type[] getTypes()
pushArgsback to summary
public void pushArgs()

Push args onto the stack corresponding to the types passed to the constructor.