(-- * About
-- $about
--
+ --
-- * Internal class file structures
Attribute (..),
FieldType (..),
=> HasSignature a where
type Signature a
-instance HasSignature Field where
- type Signature Field = FieldSignature
+instance HasSignature (Field Direct) where
+ type Signature (Field Direct) = FieldSignature
-instance HasSignature Method where
- type Signature Method = MethodSignature
+instance HasSignature (Method Direct) where
+ type Signature (Method Direct) = MethodSignature
-- | Name and signature pair. Used for methods and fields.
data NameType a = NameType {
-- | Constant pool item
data Constant stage =
CClass (Link stage B.ByteString)
- | CField (Link stage B.ByteString) (Link stage (NameType Field))
- | CMethod (Link stage B.ByteString) (Link stage (NameType Method))
- | CIfaceMethod (Link stage B.ByteString) (Link stage (NameType Method))
+ | CField (Link stage B.ByteString) (Link stage (NameType (Field stage)))
+ | CMethod (Link stage B.ByteString) (Link stage (NameType (Method stage)))
+ | CIfaceMethod (Link stage B.ByteString) (Link stage (NameType (Method stage)))
| CString (Link stage B.ByteString)
| CInteger Word32
| CFloat Float
-- | Generic .class file format
data Class stage = Class {
- magic :: Word32, -- ^ Magic value: 0xCAFEBABE
+ magic :: Word32, -- ^ Magic value: 0xCAFEBABE
minorVersion :: Word16,
majorVersion :: Word16,
- constsPoolSize :: Word16, -- ^ Number of items in constants pool
- constsPool :: Pool stage, -- ^ Constants pool itself
- accessFlags :: AccessFlags stage, -- ^ See @JVM.Types.AccessFlag@
- thisClass :: Link stage B.ByteString, -- ^ Constants pool item index for this class
- superClass :: Link stage B.ByteString, -- ^ --/-- for super class, zero for java.lang.Object
- interfacesCount :: Word16, -- ^ Number of implemented interfaces
- interfaces :: [Link stage B.ByteString], -- ^ Constants pool item indexes for implemented interfaces
- classFieldsCount :: Word16, -- ^ Number of class fileds
- classFields :: [Field stage], -- ^ Class fields
- classMethodsCount :: Word16, -- ^ Number of class methods
- classMethods :: [Method stage], -- ^ Class methods
- classAttributesCount :: Word16, -- ^ Number of class attributes
- classAttributes :: Attributes stage -- ^ Class attributes
+ constsPoolSize :: Word16, -- ^ Number of items in constants pool
+ constsPool :: Pool stage, -- ^ Constants pool itself
+ accessFlags :: AccessFlags stage, -- ^ See @JVM.Types.AccessFlag@
+ thisClass :: Link stage B.ByteString, -- ^ Constants pool item index for this class
+ superClass :: Link stage B.ByteString, -- ^ --/-- for super class, zero for java.lang.Object
+ interfacesCount :: Word16, -- ^ Number of implemented interfaces
+ interfaces :: [Link stage B.ByteString], -- ^ Constants pool item indexes for implemented interfaces
+ classFieldsCount :: Word16, -- ^ Number of class fileds
+ classFields :: [Field stage], -- ^ Class fields
+ classMethodsCount :: Word16, -- ^ Number of class methods
+ classMethods :: [Method stage], -- ^ Class methods
+ classAttributesCount :: Word16, -- ^ Number of class attributes
+ classAttributes :: Attributes stage -- ^ Class attributes
}
deriving instance Eq (Class File)
| BoolType -- ^ Z
| ObjectType String -- ^ L @{class name}@
| Array (Maybe Int) FieldType -- ^ @[{type}@
- deriving (Eq)
+ deriving (Eq, Ord)
instance Show FieldType where
show SignedByte = "byte"
data ReturnSignature =
Returns FieldType
| ReturnsVoid
- deriving (Eq)
+ deriving (Eq, Ord)
instance Show ReturnSignature where
show (Returns t) = show t
-- | Class method argument signature
data MethodSignature =
MethodSignature [ArgumentSignature] ReturnSignature
- deriving (Eq)
+ deriving (Eq, Ord)
instance Show MethodSignature where
show (MethodSignature args ret) = "(" ++ intercalate ", " (map show args) ++ ") returns " ++ show ret
| fieldName f == name = Just f
| otherwise = look fs
-fieldNameType :: Field Direct -> NameType Field
+fieldNameType :: Field Direct -> NameType (Field Direct)
fieldNameType f = NameType (fieldName f) (fieldSignature f)
instance Binary (Field File) where
deriving instance Show (Method File)
deriving instance Show (Method Direct)
-methodNameType :: Method Direct -> NameType Method
+methodNameType :: Method Direct -> NameType (Method Direct)
methodNameType m = NameType (methodName m) (methodSignature m)
lookupMethod :: B.ByteString -> Class Direct -> Maybe (Method Direct)