78 lines
2.6 KiB
Haskell
78 lines
2.6 KiB
Haskell
-- | Fields array of a class.
|
|
|
|
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
{-# LANGUAGE DerivingVia #-}
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
{-# LANGUAGE InstanceSigs #-}
|
|
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE StandaloneKindSignatures #-}
|
|
{-# LANGUAGE DataKinds #-}
|
|
{-# LANGUAGE StandaloneDeriving #-}
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
{-# LANGUAGE UndecidableInstances #-}
|
|
module Language.Java.Classfile.Fields (Fields(..)) where
|
|
import Data.Array.IArray (Array)
|
|
import Data.Word (Word16)
|
|
import Language.Java.Classfile.Extractable (Extractable)
|
|
import GHC.Generics ( Generically, Generic, Generically(..) )
|
|
import Language.Java.Classfile.Flags (Flags, FlagMask (..))
|
|
import Language.Java.Classfile.ConstantPool.References (Utf8)
|
|
import Language.Java.Classfile.Attributes (Attributes)
|
|
import Pretty.Serialize (PrettySerialize)
|
|
import Language.Java.Classfile.Stage (Stage)
|
|
import Data.Kind (Type)
|
|
import Data.Typeable (Typeable)
|
|
|
|
-- | Word16-Array of Fields.
|
|
|
|
type Fields :: Stage -> Type
|
|
newtype Fields stage = Fields (Array Word16 (Field stage))
|
|
|
|
deriving stock instance (Show (Field stage)) => Show (Fields stage)
|
|
deriving newtype instance (Typeable stage, Extractable (Utf8 stage), Extractable (Attributes stage)) => Extractable (Fields stage)
|
|
deriving newtype instance (Typeable stage, PrettySerialize (Utf8 stage), PrettySerialize (Attributes stage)) => PrettySerialize (Fields stage)
|
|
|
|
-- | All the access flags a field can have
|
|
|
|
data FieldFlag
|
|
= Public
|
|
| Private
|
|
| Protected
|
|
| Static
|
|
| Final
|
|
| Volatile
|
|
| Transient
|
|
| Synthetic
|
|
| Enumeration -- original "Enum"
|
|
deriving stock (Show, Eq, Ord, Enum, Bounded, Generic)
|
|
deriving PrettySerialize via Generically FieldFlag
|
|
|
|
instance FlagMask FieldFlag where
|
|
type FlagType FieldFlag = Word16
|
|
maskOf :: FieldFlag -> FlagType FieldFlag
|
|
maskOf = \case
|
|
Public -> 0x0001
|
|
Private -> 0x0002
|
|
Protected -> 0x0004
|
|
Static -> 0x0008
|
|
Final -> 0x0010
|
|
Volatile -> 0x0040
|
|
Transient -> 0x0080
|
|
Synthetic -> 0x1000
|
|
Enumeration -> 0x4000
|
|
|
|
-- | A singular field of a class.
|
|
|
|
type Field :: Stage -> Type
|
|
data Field stage = Field
|
|
{ flags :: Flags FieldFlag
|
|
, name :: Utf8 stage
|
|
, descriptor :: Utf8 stage
|
|
, attribute :: Attributes stage
|
|
}
|
|
deriving stock (Generic)
|
|
|
|
deriving stock instance (Show (Utf8 stage), Show (Attributes stage)) => Show (Field stage)
|
|
deriving via Generically (Field stage) instance (Extractable (Utf8 stage), Extractable (Attributes stage)) => Extractable (Field stage)
|
|
deriving via Generically (Field stage) instance (PrettySerialize (Utf8 stage), PrettySerialize (Attributes stage)) => PrettySerialize (Field stage)
|