gnu.jel
Class ClassFile

java.lang.Object
  extended by gnu.jel.ClassFile
All Implemented Interfaces:
Cloneable

public class ClassFile
extends Object
implements Cloneable

This class represents a classfile image in JEL.


Constructor Summary
ClassFile(int modifiers, String name, Class superClass, Class[] interfaces, LocalField[] fields)
          Starts creation of a new class file.
 
Method Summary
 ClassFile clone()
          Makes a clone of this object.
 void code(long op)
          code up to 8 operations.
 void codeB(long op)
           
 void codeLDC(Object o, int primitiveID)
          generates code for code loading constant of primitive type or string.
 void codeM(Member m)
           
 byte[] getImage()
          Finishes class and returns the resulting bytecode.
 int getIndex(Object item, int typeid)
          Used to determine an old CP index or to create a new one for an item.
 void newMethod(LocalMethod m, Class[] vars)
          Starts a new method of this class.
 void noteStk(int s, int a)
          Notes removal of typeID s and subsequent addition of typeID a to Java stack.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFile

public ClassFile(int modifiers,
                 String name,
                 Class superClass,
                 Class[] interfaces,
                 LocalField[] fields)
Starts creation of a new class file.

Sizes of fAccess, fNames and fTypes arrays must be the same.

Parameters:
modifiers - sum of one or more of PUBLIC, FINAL, INTERFACE, ABSTRACT constants of java.lang.reflect.Modifier
name - is the name of new class (must be in Java historical form, i.e. with dots replaced by slashes '/')
superClass - is the superclass of this class
interfaces - array of interfaces this class implements
fields - fields this class will have
Method Detail

clone

public ClassFile clone()
Makes a clone of this object.

This is used in JEL to avoid step-by step creation of service methods of gnu.jel.CompiledExpression (, getType, ...). They are created only once, and then the resulting ClassFile is cloned at the point, when it is ready to accept the code for evaluation method.

Overrides:
clone in class Object
Returns:
a clone of this object

newMethod

public void newMethod(LocalMethod m,
                      Class[] vars)
Starts a new method of this class.

Parameters:
m - method descriptor.
vars - types of local variables by number.

getImage

public byte[] getImage()
Finishes class and returns the resulting bytecode.

Returns:
array of bytes of the resulting *.class file.

noteStk

public void noteStk(int s,
                    int a)
Notes removal of typeID s and subsequent addition of typeID a to Java stack.

If either is negative the corresponding operation (addition/removal) is skipped. This method is needed to allow ClassFile to compute the maximum stack occupation for the generated code. It is responsibility of the user (of this class) to call noteStk() each time the stack is changed from within the code.

Parameters:
s - typeid to be put on stack (-1 if none).
a - typeid to be taken off Java stack (-1 if none).

codeB

public final void codeB(long op)

codeM

public final void codeM(Member m)

code

public final void code(long op)
code up to 8 operations.

Additionally to Java bytecodes this method accepts (and interprets) some more commands. See the implementation.

Parameters:
op - operations to code (least significant bytes coded first).

codeLDC

public final void codeLDC(Object o,
                          int primitiveID)
generates code for code loading constant of primitive type or string.

Parameters:
o - reflection object or String containing the constant
primitiveID - type ID to save lookups.

getIndex

public int getIndex(Object item,
                    int typeid)
Used to determine an old CP index or to create a new one for an item.

Parameters:
item - an item to create or get an index for
typeid - identifies type of argument to avoid linear searches
Returns:
index for an item (negative if it has to be written)


Copyright © 1998-2009 Konstantin L. Metlov All Rights Reserved.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the JEL manual.