feat[classfile]: stages the entire file

This commit is contained in:
vegowotenks 2025-08-21 08:54:36 +02:00
parent 500bfa349e
commit f309c5f92c
7 changed files with 117 additions and 57 deletions

View file

@ -6,32 +6,46 @@
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
module Language.Java.Classfile.Methods (Methods(..), Method(..), MethodFlag(..)) where
import Data.Array.IArray (Array)
import Data.Word (Word16)
import Language.Java.Classfile.Flags (Flags, FlagMask (..))
import Language.Java.Classfile.Extractable (Extractable)
import GHC.Generics ( Generically, Generic, Generically(..) )
import Language.Java.Classfile.ConstantPool.References (Utf8Reference)
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)
-- | Alias for the methods structure from the constant-pool.
newtype Methods = Methods (Array Word16 Method)
deriving stock (Show)
deriving newtype (Extractable, PrettySerialize)
newtype Methods stage = Methods (Array Word16 (Method stage))
deriving stock instance (Show (Utf8 stage), Show (Attributes stage)) => Show (Methods stage)
deriving newtype instance (Typeable stage, Extractable (Utf8 stage), Extractable (Attributes stage)) => Extractable (Methods stage)
deriving newtype instance (Typeable stage, PrettySerialize (Utf8 stage), PrettySerialize (Attributes stage)) => PrettySerialize (Methods stage)
-- | A single method record, contains attributes, name and access flags.
data Method = Method
type Method :: Stage -> Type
data Method stage = Method
{ flags :: Flags MethodFlag
, name :: Utf8Reference
, descriptor :: Utf8Reference
, attributes :: Attributes
, name :: Utf8 stage
, descriptor :: Utf8 stage
, attributes :: Attributes stage
}
deriving stock (Show, Generic)
deriving (Extractable, PrettySerialize) via Generically Method
deriving stock (Generic)
deriving stock instance (Show (Utf8 stage), Show (Attributes stage)) => Show (Method stage)
deriving via Generically (Method stage) instance (Extractable (Utf8 stage), Extractable (Attributes stage)) => Extractable (Method stage)
deriving via Generically (Method stage) instance (PrettySerialize (Utf8 stage), PrettySerialize (Attributes stage)) => PrettySerialize (Method stage)
-- | Flags for the method, such as abstract, public or static.