67 lines
1.8 KiB
Haskell
67 lines
1.8 KiB
Haskell
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
{-# LANGUAGE DerivingVia #-}
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
{-# LANGUAGE InstanceSigs #-}
|
|
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
module Language.Java.Classfile.Methods (Methods(..), Method(..), MethodFlag(..)) where
|
|
import Data.Array.IArray (Array)
|
|
import Data.Word (Word16)
|
|
import Language.Java.Classfile.Flags (Flags)
|
|
import Language.Java.Classfile.Extractable (Extractable)
|
|
import Language.Java.Classfile.Flag (FlagMask (..))
|
|
import GHC.Generics ( Generically, Generic, Generically(..) )
|
|
import Language.Java.Classfile.ConstantPool.References (Utf8Reference)
|
|
import Language.Java.Classfile.Attributes (Attributes)
|
|
|
|
-- | Alias for the methods structure from the constant-pool.
|
|
|
|
newtype Methods = Methods (Array Word16 Method)
|
|
deriving stock (Show)
|
|
deriving newtype Extractable
|
|
|
|
-- | A single method record, contains attributes, name and access flags.
|
|
|
|
data Method = Method
|
|
{ flags :: Flags MethodFlag
|
|
, name :: Utf8Reference
|
|
, descriptor :: Utf8Reference
|
|
, attributes :: Attributes
|
|
}
|
|
deriving stock (Show, Generic)
|
|
deriving Extractable via Generically Method
|
|
|
|
-- | Flags for the method, such as abstract, public or static.
|
|
|
|
data MethodFlag
|
|
= Public
|
|
| Private
|
|
| Protected
|
|
| Static
|
|
| Final
|
|
| Synchronized
|
|
| Bridge
|
|
| Varargs
|
|
| Native
|
|
| Abstract
|
|
| Strict
|
|
| Synthetic
|
|
deriving stock (Show, Eq, Ord, Enum, Bounded)
|
|
|
|
instance FlagMask MethodFlag where
|
|
type FlagType MethodFlag = Word16
|
|
|
|
maskOf :: MethodFlag -> FlagType MethodFlag
|
|
maskOf = \case
|
|
Public -> 0x0001
|
|
Private -> 0x0002
|
|
Protected -> 0x0004
|
|
Static -> 0x0008
|
|
Final -> 0x0010
|
|
Synchronized -> 0x0020
|
|
Bridge -> 0x0040
|
|
Varargs -> 0x0080
|
|
Native -> 0x0100
|
|
Abstract -> 0x0400
|
|
Strict -> 0x0800
|
|
Synthetic -> 0x1000
|