<commit_before>module Language.K3.Codegen.CPP.Simplification (
  simplifyCPP,
) where

import Control.Applicative

import Control.Monad.Identity
import Control.Monad.State

import Language.K3.Codegen.CPP.Representation

type SimplificationS = ()
type SimplificationM = StateT SimplificationS Identity

runSimplificationM :: SimplificationM a -> SimplificationS -> (a, SimplificationS)
runSimplificationM s t = runIdentity $ runStateT s t

simplifyCPP :: [Definition] -> [Definition]
simplifyCPP ds = fst $ runSimplificationM (mapM simplifyCPPDefinition ds) ()

simplifyCPPExpression :: Expression -> SimplificationM Expression
simplifyCPPExpression expr =
  case expr of
    Binary i x y -> Binary i <$> simplifyCPPExpression x <*> simplifyCPPExpression y

    Bind f vs 0 -> simplifyCPPExpression (Call f vs)
    Bind f vs n -> do
      f' <- simplifyCPPExpression f
      vs' <- mapM simplifyCPPExpression vs

      case f' of
        Bind f'' vs'' n' -> return (Bind f'' (vs'' ++ vs') n)
        _ -> return (Bind f' vs' n)

    Call f vs -> do
      f' <- simplifyCPPExpression f
      vs' <- mapM simplifyCPPExpression vs

      case f' of
        Bind f'' vs'' n | n == length vs' -> return (Call f'' (vs'' ++ vs'))<commit_msg>Warning cleanup in CPP.Simplification.<commit_after>module Language.K3.Codegen.CPP.Simplification (
  simplifyCPP,
) where

import Control.Applicative

import Control.Monad.Identity
import Control.Monad.State

import Language.K3.Codegen.CPP.Representation

type SimplificationS = ()
type SimplificationM = StateT SimplificationS Identity

runSimplificationM :: SimplificationM a -> SimplificationS -> (a, SimplificationS)
runSimplificationM s t = runIdentity $ runStateT s t

simplifyCPP :: [Definition] -> [Definition]
simplifyCPP ds = fst $ runSimplificationM (mapM simplifyCPPDefinition ds) ()

simplifyCPPExpression :: Expression -> SimplificationM Expression
simplifyCPPExpression expr =
  case expr of
    Binary i x y -> Binary i <$> simplifyCPPExpression x <*> simplifyCPPExpression y

    Bind f vs 0 -> simplifyCPPExpression (Call f vs)
    Bind f vs n -> do
      f' <- simplifyCPPExpression f
      vs' <- mapM simplifyCPPExpression vs

      case f' of
        Bind f'' vs'' _ -> return (Bind f'' (vs'' ++ vs') n)
        _ -> return (Bind f' vs' n)

    Call f vs -> do
      f' <- simplifyCPPExpression f
      vs' <- mapM simplifyCPPExpression vs

      case f' of
        Bind f'' vs'' n | n == length vs' -> return (Call f'' (vs'' ++ vs'))
{'fraction_non_alphanumeric': 0.10321285140562249, 'fraction_numerical': 0.0024096385542168677, 'mean_word_length': 3.4166666666666665, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2641870', 'n_tokens_mistral': 796, 'n_tokens_neox': 741, 'n_words': 251}