gnu.jel
Class TypesStack

java.lang.Object
  |
  +--gnu.jel.TypesStack
All Implemented Interfaces:
java.lang.Cloneable

public class TypesStack
extends java.lang.Object
implements java.lang.Cloneable

Organizes stack of types, supports type identification and automatically calculates the maximum occupation. Efficiently supports primitive types identification.


Field Summary
static byte[] baseType
          Translates the type ID into the Java base type ID.
protected  int currWords
           
static char[] primitiveCodes
          Java codes for base types by base ID.
static java.lang.Class[] specialTypes
          Classes of the special types by ID.
protected static byte[] stkoccup
           
static byte[] unwrapType
          Translates the type ID into the Java base type ID.
 
Constructor Summary
TypesStack()
          Constructs a new empty TypesStack.
 
Method Summary
 java.lang.Object clone()
          Makes a clone of this object.
 int getMaxOccupation()
          Used to get a maximum number of Java words needed to store the stack.
static java.lang.Class[] getParameterTypes(java.lang.reflect.Member m)
          Used to get types of formal parameters of a member.
static java.lang.String getSignature(java.lang.Class cls)
          Computes the signature of the given class.
static java.lang.String getSignature(java.lang.reflect.Member m)
          Computes signature of the given member.
static java.lang.Class getType(java.lang.reflect.Member m)
          Used to get return type of a class member.
static boolean isField(java.lang.reflect.Member m)
           
static boolean isIntegral(int id1)
           
static boolean isWidening(java.lang.Class c1, java.lang.Class c2)
          Used to find out if the conversion t1->t2 is widening.
static boolean isWidening(int id1, java.lang.Class c1, int id2, java.lang.Class c2)
          Used to find out if the conversion t1->t2 is widening.
protected static java.lang.Object narrow(java.lang.Number val, int clsID)
           
 java.lang.Class peek()
          Peeks the class on top of the stack without removing it.
 java.lang.Class peek(int i)
          Peeks the class from the body of the stack.
 int peekID()
          Peeks the ID of the class on top of the stack without removing it.
 int peekID(int i)
          Peeks the ID of the class from the body of the stack.
 java.lang.Class pop()
          Pops the top class from the stack.
 void push(java.lang.Class c)
          Pushes a given class into stack.
 void push(java.lang.Class cls, int i)
          Adds a new element to the stack at a given position from top of it.
 void pushID(int id)
          Pushes the class representing the special type into stack.
 void pushID(int id, java.lang.Class c)
          Pushes the class with given typeID into stack.
 void pushID(int id, int i)
          Adds a special type to the stack at a given position from top of it.
 void resetStats()
          Resets maximum stack occupation statistics.
 int size()
          Used to determine the number of elements in this stack.
 void tempExcessWords(int nw)
          Used to adjust maximum stack occupation by a given amount.
static java.lang.String toHistoricalForm(java.lang.String className)
           
static int typeID(java.lang.Class c)
          Identifies the primitive type of the given class.
static int typeIDObject(java.lang.Object o)
          Identify the primitive type corresponding to the given reflection object.
protected static java.lang.Number widen(java.lang.Object o, int clsID)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

specialTypes

public static final java.lang.Class[] specialTypes
Classes of the special types by ID.

The frequently used types (those on which many operations are defined) are identified by an integer number. The advantage is the possibility to have almost completely table driven code generator.

So, the special types are only special in the fact that except of the reference to their class object they are also identified by an integer number.


baseType

public static final byte[] baseType
Translates the type ID into the Java base type ID.

That is all special types which are references are translated into 8.


unwrapType

public static final byte[] unwrapType
Translates the type ID into the Java base type ID.

That is all special types which are references are translated into 8.


primitiveCodes

public static final char[] primitiveCodes
Java codes for base types by base ID.

stkoccup

protected static final byte[] stkoccup

currWords

protected int currWords
Constructor Detail

TypesStack

public TypesStack()
Constructs a new empty TypesStack.
Method Detail

typeID

public static final int typeID(java.lang.Class c)
Identifies the primitive type of the given class.
Parameters:
c - class to identify.
Returns:
id of the corresponding primitive type.

typeIDObject

public static final int typeIDObject(java.lang.Object o)
Identify the primitive type corresponding to the given reflection object.
Parameters:
o - object to identify.
Returns:
id of the corresponding primitive type.

clone

public java.lang.Object clone()
Makes a clone of this object.
Overrides:
clone in class java.lang.Object
Returns:
a clone of this object

peek

public final java.lang.Class peek()
Peeks the class on top of the stack without removing it.
Returns:
class on top of the stack.

peekID

public final int peekID()
Peeks the ID of the class on top of the stack without removing it.
Returns:
ID of the class on top of the stack.

peek

public final java.lang.Class peek(int i)
Peeks the class from the body of the stack.
Parameters:
i - number of the class to peek (0 means the top of the stack)
Returns:
class number i from the top of the stack.

peekID

public final int peekID(int i)
Peeks the ID of the class from the body of the stack.
Parameters:
i - number of the class to peek (0-peek)
Returns:
ID of the class number i from the top of the stack.

pop

public final java.lang.Class pop()
Pops the top class from the stack.
Returns:
class formerly on top of the stack.

pushID

public final void pushID(int id,
                         java.lang.Class c)
Pushes the class with given typeID into stack.

pushID

public final void pushID(int id)
Pushes the class representing the special type into stack.

push

public final void push(java.lang.Class c)
Pushes a given class into stack.

push

public final void push(java.lang.Class cls,
                       int i)
Adds a new element to the stack at a given position from top of it.
Parameters:
cls - class to add
i - position of new element from the top of the stack (0 -- push)

pushID

public final void pushID(int id,
                         int i)
Adds a special type to the stack at a given position from top of it.
Parameters:
id - ID of the class to add
i - position of new element from the top of the stack (0 -- push)

size

public final int size()
Used to determine the number of elements in this stack.
Returns:
the number of elements in this stack.

resetStats

public final void resetStats()
Resets maximum stack occupation statistics.

Should be called when this stack is reused for another method.


tempExcessWords

public final void tempExcessWords(int nw)
Used to adjust maximum stack occupation by a given amount.

This method is called when there were data pushed on top of Java stack bypassing this class.


getMaxOccupation

public final int getMaxOccupation()
Used to get a maximum number of Java words needed to store the stack.
Returns:
number of words.

isWidening

public static boolean isWidening(int id1,
                                 java.lang.Class c1,
                                 int id2,
                                 java.lang.Class c2)
Used to find out if the conversion t1->t2 is widening.
Parameters:
id1 - type ID to convert from
c1 - class to convert from (used if id1==8)
id2 - type ID to convert to
c2 - class to convert to (used if id2==8)
Returns:
true if the given conversion is widening (can be done automatically)

isIntegral

public static boolean isIntegral(int id1)

isWidening

public static boolean isWidening(java.lang.Class c1,
                                 java.lang.Class c2)
Used to find out if the conversion t1->t2 is widening.
Parameters:
c1 - class to convert from (used if id1==8)
c2 - class to convert to (used if id2==8)
Returns:
true if the given conversion is widening (can be done automatically)

widen

protected static java.lang.Number widen(java.lang.Object o,
                                        int clsID)

narrow

protected static java.lang.Object narrow(java.lang.Number val,
                                         int clsID)

getType

public static java.lang.Class getType(java.lang.reflect.Member m)
Used to get return type of a class member.

The type of a Method is its return type, the type of a Constructor is void.

Parameters:
m - member whose type is to be determined
Returns:
type of the member

getParameterTypes

public static java.lang.Class[] getParameterTypes(java.lang.reflect.Member m)
Used to get types of formal parameters of a member.

The reference to the class instance "this" is not counted by this method.

Parameters:
m - member whose formal parameters are to be obtained
Returns:
array of formal parameter types (empty array if none).

getSignature

public static java.lang.String getSignature(java.lang.reflect.Member m)
Computes signature of the given member.
Parameters:
m - the member to compute the sugnature of.
Returns:
the signature.

isField

public static boolean isField(java.lang.reflect.Member m)

getSignature

public static java.lang.String getSignature(java.lang.Class cls)
Computes the signature of the given class.

The signature of the class (Field descriptor) is the string and it's format is described in the paragraph 4.3.2 of the Java VM specification (ISBN 0-201-63451-1).

The same can be done using java.lang.Class.getName() by converting it's result into the "historical form".

This utility method can be used outside of the JEL package it does not involve any JEL specific assumptions and should follow JVM Specification precisely.

Parameters:
cls - is the class to compute the signature of. Can be primitive or array type.
Returns:
the class signature.

toHistoricalForm

public static java.lang.String toHistoricalForm(java.lang.String className)