<commit_before>{-# LANGUAGE TemplateHaskell #-}

module Javelin.Runtime.Structures
where 

import Data.Word (Word8, Word16, Word32, Word64)
import Data.Array.IArray (Array)
import Data.Map.Lazy as Map (fromList, Map, lookup, insert, size)
import Data.Int (Int8, Int16, Int32, Int64)
import Data.Array.IArray (array, bounds, (!), (//))
import Control.Monad.Trans.Except (ExceptT(..))
import Control.Monad.Trans.Class (lift)

import Javelin.ByteCode.Data
import Javelin.Runtime.DescSign
import Data.Either.Utils (maybeToEither)
import Control.Lens (makeLenses, (&), (%~), ix, _1, _2, (^?), (^.))

data Runtime = Runtime { _classPathLayout :: ClassPathLayout,
                         _loadedClasses :: Map.Map ClassId (Either VMError LoadedClass),

                         _classResolving :: Map.Map ClassId ClassRes,

                         _heap :: (Int, Array Int JObject),
                         _threads :: [Thread] }
             deriving (Show, Eq)

data ClassId = ClassId { getInitCL :: ClassLoader,
                         getName :: ClassName }
             deriving (Show, Eq, Ord)

data ClassPartRes = ClassPartResOk
                  | ClassPartResFail VMError
                  deriving (Show, Eq)

data ClassPartReference = ClassPartReference { _partName :: String,
                                               _partDescriptor :: String,
                                               _ownerName :: String }
                        deriving (Show, Eq, Ord)

data PartReference = PartReference { _part :: String,
                                     _descriptor :: String }
                   deriving (Show, Eq, Ord)

data ClassRes = ClassResOk { _resolvedFields  :: Map.Map PartReference ClassPartRes,
                             _resolvedMethods :: Map.Map PartReference ClassPartRes }
              | ClassResFail { resolvingFailure :: VMError }
              deriving (Show, Eq)

data Class = Class {
  classVisibility :: ClassAccess,
  className :: String,
  superName :: String,
  classInterfaces :: [String],
  methodsList :: [Method],
  fieldsList :: [Field]
  }
  deriving (Show, Eq)

data ClassAccess = ClassAccess {
  isClassPublic :: Bool, isClassFinal :: Bool, isClassTreatSuperSpecially :: Bool,
  isClassInterface :: Bool, isClassAbstract :: Bool, isClassSynthetic :: Bool,
  isClassAnnotation :: Bool, isClassEnum :: Bool }
  deriving (Show, Eq)
  
data Method = Method {
  methodAccess :: MethodAccess,
  methodName :: String,
  methodDescriptor :: String }
  deriving (Show, Eq)

data MethodAccess = MethodAccess {
  isMethodPublic :: Bool, isMethodPrivate :: Bool, isMethodProtected :: Bool,
  isMethodStatic :: Bool, isMethodFinal :: Bool, isMethodSynchronized :: Bool,
  isMethodBridge :: Bool, isMethodVarargs :: Bool, isMethodNative :: Bool,
  isMethodAbstract :: Bool, isMethodStrict :: Bool, isMethodSynthetic :: Bool }
  deriving (Show,Eq)

data Field = Field {
  fieldAccess :: FieldAccess,
  fieldName :: String,
  fieldDescriptor :: String }
  deriving (Show, Eq)

data FieldAccess = FieldAccess {
  isFieldPublic :: Bool, isFieldPrivate :: Bool, isFieldProtected :: Bool,<commit_msg>Getting rid of references via constant pool<commit_after>{-# LANGUAGE TemplateHaskell #-}

module Javelin.Runtime.Structures
where 

import Data.Word (Word8, Word16, Word32, Word64)
import Data.Array.IArray (Array)
import Data.Map.Lazy as Map (fromList, Map, lookup, insert, size)
import Data.Int (Int8, Int16, Int32, Int64)
import Data.Array.IArray (array, bounds, (!), (//))
import Control.Monad.Trans.Except (ExceptT(..))
import Control.Monad.Trans.Class (lift)

import Javelin.ByteCode.Data
import Javelin.Runtime.DescSign
import Data.Either.Utils (maybeToEither)
import Control.Lens (makeLenses, (&), (%~), ix, _1, _2, (^?), (^.))

data Runtime = Runtime { _classPathLayout :: ClassPathLayout,
                         _loadedClasses :: Map.Map ClassId (Either VMError LoadedClass),

                         _classResolving :: Map.Map ClassId ClassRes,

                         _heap :: (Int, Array Int JObject),
                         _threads :: [Thread] }
             deriving (Show, Eq)

data ClassId = ClassId { getInitCL :: ClassLoader,
                         getName :: ClassName }
             deriving (Show, Eq, Ord)

data ClassPartRes = ClassPartResOk
                  | ClassPartResFail VMError
                  deriving (Show, Eq)

data ClassPartReference = ClassPartReference { _partName :: String,
                                               _partDescriptor :: String,
                                               _ownerName :: String }
                        deriving (Show, Eq, Ord)

data PartReference = PartReference { _part :: String,
                                     _descriptor :: String }
                   deriving (Show, Eq, Ord)

data ClassRes = ClassResOk { _resolvedFields  :: Map.Map PartReference ClassPartRes,
                             _resolvedMethods :: Map.Map PartReference ClassPartRes }
              | ClassResFail { resolvingFailure :: VMError }
              deriving (Show, Eq)

data Class = Class {
  classVisibility :: ClassAccess,
  className :: String,
  superName :: String,
  sourceFile :: String,
  
  classInterfaces :: [String],
  methodsList :: [Method],
  fieldsList :: [Field]
  } deriving (Show, Eq)

data ClassAccess = ClassAccess {
  isClassPublic :: Bool, isClassFinal :: Bool, isClassTreatSuperSpecially :: Bool,
  isClassInterface :: Bool, isClassAbstract :: Bool, isClassSynthetic :: Bool,
  isClassAnnotation :: Bool, isClassEnum :: Bool
  } deriving (Show, Eq)
  
data Method = Method {
  methodAccess :: MethodAccess,
  methodName :: String,
  methodDescriptor :: String,
  methodParameters :: [MethodParameter2]
--  methodCode :: [String], --todo
--  methodExceptions :: [String], --todo
  } deriving (Show, Eq)

data MethodParameter2 = MethodParameter2 {
  parameterName :: Maybe String,
  isParameterFinal :: Bool,
  isParameterSynthetic :: Bool,
  isParameterMandated :: Bool
  } deriving (Show, Eq)

data MethodAccess = MethodAccess {
  isMethodPublic :: Bool, isMethodPrivate :: Bool, isMethodProtected :: Bool,
  isMethodStatic :: Bool, isMethodFinal :: Bool, isMethodSynchronized :: Bool,
  isMethodBridge :: Bool, isMethodVarargs :: Bool, isMethodNative :: Bool,
  isMethodAbstract :: Bool, isMethodStrict :: Bool, isMethodSynthetic :: Bool
  } deriving (Show,Eq)

data Field = Field {
  fieldAccess :: FieldAccess,
  fieldName :: String,
  fieldDescriptor :: String,
  constantValue :: Maybe ConstantValue
  } deriving (Show, Eq)

data ConstantValue = ConstantLong Word64
                   | ConstantFloat Float
                   | ConstantDouble Double
                   | ConstantInteger Word32
                   | ConstantString String
                   deriving (Show, Eq)

data FieldAccess = FieldAccess {
  isFieldPublic :: Bool, isFieldPrivate :: Bool, isFieldProtected :: Bool,
{'fraction_non_alphanumeric': 0.10164597170083742, 'fraction_numerical': 0.005630955818654346, 'mean_word_length': 2.6286013619696176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4102786', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1845, 'n_words': 528}