|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--com.svincent.util.BaseObject
|
+--com.svincent.smalljava.SmallType
The SmallJava API uses two internal representations for types. The first, which is used by most of the APIs for succinctness, is a slightly modified syntax of standard JVM type descriptors.
The syntax for fields is as follows (This table, of course, looks much nicer in an HTML form):
| production | syntax | description |
|---|---|---|
| FieldType | BaseType|ComplexType|ArrayType | A basic field |
| BaseType | B | signed byte (byte) |
| C | character (char) | |
| D | double precision (double) | |
| F | single precision (float) | |
| I | integer (int) | |
| J | long integer (long) | |
| S | short integer (short) | |
| Z | boolean value (boolean) | |
| VerboseType | Lbyte; | signed byte (byte) |
| Lchar; | character (char) | |
| Ldouble; | double precision (double) | |
| Lfloat; | single precision (float) | |
| Lint; | integer (int) | |
| Llong; | long integer (long) | |
| Lshort; | short integer (short) | |
| Lboolean; | boolean value (boolean) | |
| LclassName; | boolean value (boolean) | |
| ArrayType | [FieldType | Array of type |
The syntax for fields is as follows (Again, this table looks much nicer in an HTML form):
| production | syntax | description |
|---|---|---|
| MethodType | (FieldType*)ReturnDescriptor | Method type |
| ReturnType | FieldType | standard field type |
| V | void (no return) |
The following are some examples of field type specifiers, and their equivalent Java types.
I int
[I int[]
Ljava.lang.String; java.lang.String
[[I int[][]
[Z boolean[]
Lint; int
[Lint; int[]
[Ljava.lang.String; java.lang.String[]
The following are some examples of method type specifiers, and their equivalent Java types.
()V void foo ()
(I)I int foo (int)
(II)I int foo (int, int)
(Ljava.lang.String)V void foo (java.lang.String)
([Lint;)V void foo (int[])
([I[[I)Z boolean foo (int[], int[][])
An alternative to using these type descriptors is to use the SmallType API to build them for you. An example of this follows.
{
// --- Make a field type
// --- make a type using a combination of static methods & static
// - instances.
SmallType myType =
SmallType.array (SmallType.array (SmallType.Int));
// --- print as java (outputs "int[][]")
myType.writeAsJava (Util.out);
// --- print as type descriptor (outputs "[[I")
myType.writeDescriptor (Util.out);
// --- Make a method type
SmallType.MethodType methodType =
new SmallType.MethodType (myType,
new SmallType[] {SmallType.Int});
// --- print as java (outputs "(int)->int[][]")
methodType.writeAsJava (Util.out);
// --- print as type descriptor (outputs "(I)[[I")
methodType.writeDescriptor (Util.out);
}
| Inner Class Summary | |
static class |
SmallType.ArrayType
A type which represents an array type. |
static class |
SmallType.MethodType
Represents a type for a method. |
static class |
SmallType.ObjectType
An instance of a class. |
protected static class |
SmallType.PrimitiveType
Reprsents a primitive type, such as int or boolean. |
| Field Summary | |
static SmallType |
Boolean
A boolean value: true or false. |
static SmallType |
Byte
A signed byte value. |
static SmallType |
Char
An unsigned Unicode character. |
static boolean |
debug
Debug flag for the parsing algorithm. |
static SmallType |
Double
A double-precision IEEE 754 float |
static SmallType[] |
EmptyArray
A constant empty array of SmallTypes. |
static SmallType |
Float
A single-precision IEEE 754 float |
static SmallType |
Int
A signed integer |
static SmallType |
Long
A signed long integer |
static SmallType |
Short
A signed short integer. |
static SmallType |
Void
The Void type: only allowed as the return type of methods. |
| Constructor Summary | |
SmallType()
|
|
| Method Summary | |
protected void |
addAdd(ClassFileWriter out)
make an appropriately typed ADD operator (IADD, FADD, etc) |
protected void |
addArrayNew(ClassFileWriter out)
make an appropriately typed NEWARRAY instruction |
protected void |
addArrayStore(ClassFileWriter out)
make an appropriately typed ASTORE operator (IASTORE, AASTORE, etc) |
protected void |
addCmp(ClassFileWriter out)
make an appropriately typed CMP operator (ISUB, LCMP, etc) |
protected void |
addLoad(ClassFileWriter out,
int index)
make an appropriately typed LOAD operator (ILOAD, ALOAD, etc) |
protected void |
addReturn(ClassFileWriter out)
make an appropriately typed RETURN operator (IRETURN, LRETURN, etc) |
protected void |
addStore(ClassFileWriter out,
int index)
make an appropriately typed STORE operator (ISTORE, ASTORE, etc) |
protected void |
addSub(ClassFileWriter out)
make an appropriately typed SUB operator (ISUB, FSUB, etc) |
static SmallType.ArrayType |
array(SmallType t)
Make a new array of the given type. |
java.lang.String |
descriptorToString()
Returns this type's type descriptor as a String. |
boolean |
isPrimitive()
Returns 'true' if this type is a primitive type, such as 'int'. |
static void |
main(java.lang.String[] args)
A non-exhaustive test of the field and method descriptor parsing mechanism. |
static SmallType |
parseFieldDescriptor(java.lang.String desc)
Parse the given field descriptor into a SmallType. |
static SmallType.MethodType |
parseMethodDescriptor(java.lang.String desc)
Parses a method descriptor into a SmallType.MethodType structure. |
java.lang.String |
tag()
Returns a short description of this object, suitable for printing. |
static void |
testField(java.io.PrintWriter out,
java.lang.String fieldDesc)
Test method for testing the parsing of field descriptors |
static void |
testMethod(java.io.PrintWriter out,
java.lang.String methodDesc)
Test method for testing the parsing of method descriptors |
abstract void |
writeAsJava(java.io.PrintWriter out)
Write this type out as Java code, if possible. |
abstract void |
writeDescriptor(java.io.PrintWriter out)
Write this type's type descriptor to the given PrintWriter. |
| Methods inherited from class com.svincent.util.BaseObject |
dump,
dump,
dumpToString |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
public static final boolean debug
public static final SmallType[] EmptyArray
public static final SmallType Void
public static final SmallType Boolean
public static final SmallType Byte
public static final SmallType Char
public static final SmallType Short
public static final SmallType Int
public static final SmallType Long
public static final SmallType Float
public static final SmallType Double
| Constructor Detail |
public SmallType()
| Method Detail |
public boolean isPrimitive()
public java.lang.String tag()
public java.lang.String descriptorToString()
writeDescriptor(java.io.PrintWriter)public abstract void writeAsJava(java.io.PrintWriter out)
public abstract void writeDescriptor(java.io.PrintWriter out)
protected void addLoad(ClassFileWriter out,
int index)
protected void addStore(ClassFileWriter out,
int index)
protected void addArrayStore(ClassFileWriter out)
protected void addReturn(ClassFileWriter out)
protected void addAdd(ClassFileWriter out)
protected void addSub(ClassFileWriter out)
protected void addCmp(ClassFileWriter out)
protected void addArrayNew(ClassFileWriter out)
public static SmallType.ArrayType array(SmallType t)
public static SmallType parseFieldDescriptor(java.lang.String desc)
throws InvalidDescriptorException
Parse the given field descriptor into a SmallType. Will not work on method descriptors. Reasonably efficient implementation.
Meaningful exceptions are thrown, including integer positions, if an error is found.
public static SmallType.MethodType parseMethodDescriptor(java.lang.String desc)
throws InvalidDescriptorException
Parses a method descriptor into a SmallType.MethodType structure.
Will, of course, not work on fields (as they cannot be represented with MethodTypes). Reasonably efficient implementation.
Meaningful exceptions are thrown, including integer positions, if an error is found.
public static void main(java.lang.String[] args)
public static void testField(java.io.PrintWriter out,
java.lang.String fieldDesc)
public static void testMethod(java.io.PrintWriter out,
java.lang.String methodDesc)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
This is documentation for Moksa Prolog, which can be found at http://www.svincent.com/moksa/
Copyright © 1999 Shawn P. Vincent.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.