| Copyright | (c) Christian Gram Kalhauge 2017 |
|---|---|
| License | MIT |
| Maintainer | kalhuage@cs.ucla.edu |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Language.JVM.Constant
Contents
Description
This module contains the Constant type and the ConstantPool. These
are essential for accessing data in the class-file.
- data Constant
- = String !SizedByteString16
- | Integer !Word32
- | Float !Word32
- | Long !Word64
- | Double !Word64
- | ClassRef !ConstantRef
- | StringRef !ConstantRef
- | FieldRef !ConstantRef !ConstantRef
- | MethodRef !ConstantRef !ConstantRef
- | InterfaceMethodRef !ConstantRef !ConstantRef
- | NameAndType !ConstantRef !ConstantRef
- | MethodHandle !Word8 !ConstantRef
- | MethodType !ConstantRef
- | InvokeDynamic !ConstantRef !ConstantRef
- constantSize :: Constant -> Int
- newtype ConstantRef = ConstantRef Word16
- newtype ConstantPool = ConstantPool {}
- lookupConstant :: ConstantRef -> ConstantPool -> Maybe Constant
- lookupText :: ConstantRef -> ConstantPool -> Maybe Text
- lookupClassName :: ConstantRef -> ConstantPool -> Maybe Text
- toListOfConstants :: ConstantPool -> [(ConstantRef, Constant)]
Constant
A constant is a multi word item in the ConstantPool. Each of
the constructors are pretty much self expiatory from the types.
Constructors
constantSize :: Constant -> Int Source #
Some of the Constants take up more space in the constant pool than other.
Notice that String and MethodType is not of size
32, but is still awarded value 1. This is due to an
inconsistency
in JVM.
newtype ConstantRef Source #
A constant is referenced by the ConstantRef data type. It is just a 16 bit word, but wrapped for type safety.
Constructors
| ConstantRef Word16 |
Instances
Constant Pool
The ConstantPool contains all the constants, and is accessible using the
Lookup methods.
newtype ConstantPool Source #
A ConstantPool is just an IntMap. A IntMap is used, because constants are
accessed after their byte-offset. constantSize
Constructors
| ConstantPool | |
Fields | |
Instances
lookupConstant :: ConstantRef -> ConstantPool -> Maybe Constant Source #
Lookup a Constant in the ConstantPool.
lookupText :: ConstantRef -> ConstantPool -> Maybe Text Source #
Lookup a Text in the ConstantPool, returns Nothing if the
reference does not point to something in the ConstantPool, if it points to
something not a String Constant, or if it is
impossible to decode the ByteString as Utf8.
lookupClassName :: ConstantRef -> ConstantPool -> Maybe Text Source #
Lookup a class name in the ConstantPool, returns Nothing otherwise.
toListOfConstants :: ConstantPool -> [(ConstantRef, Constant)] Source #
Return a list of reference-constant pairs.