{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
module Jikka.CPlusPlus.Convert.UseInitialization
( run,
)
where
import Jikka.CPlusPlus.Language.Expr
import Jikka.CPlusPlus.Language.Util
import Jikka.Common.Alpha
import Jikka.Common.Error
runStatement :: Statement -> Statement
runStatement :: Statement -> Statement
runStatement = \case
Declare Type
t VarName
x DeclareRight
init -> case (Type
t, DeclareRight
init) of
(TyVector Type
_, DeclareCopy (Call (VecCtor Type
_) [])) -> Type -> VarName -> DeclareRight -> Statement
Declare Type
t VarName
x DeclareRight
DeclareDefault
(TyVector Type
_, DeclareCopy (Call (VecCtor Type
_) [Expr]
es)) -> Type -> VarName -> DeclareRight -> Statement
Declare Type
t VarName
x ([Expr] -> DeclareRight
DeclareInitialize [Expr]
es)
(Type
TyConvexHullTrick, DeclareCopy (Call Function
ConvexHullTrickCtor [Expr]
es)) -> Type -> VarName -> DeclareRight -> Statement
Declare Type
t VarName
x ([Expr] -> DeclareRight
DeclareInitialize [Expr]
es)
(TySegmentTree Monoid'
_, DeclareCopy (Call (SegmentTreeCtor Monoid'
_) [Expr]
es)) -> Type -> VarName -> DeclareRight -> Statement
Declare Type
t VarName
x ([Expr] -> DeclareRight
DeclareInitialize [Expr]
es)
(Type
_, DeclareRight
_) -> Type -> VarName -> DeclareRight -> Statement
Declare Type
t VarName
x DeclareRight
init
Statement
stmt -> Statement
stmt
runProgram :: Program -> Program
runProgram :: Program -> Program
runProgram = (Expr -> Expr) -> (Statement -> Statement) -> Program -> Program
mapExprStatementProgram Expr -> Expr
forall a. a -> a
id Statement -> Statement
runStatement
run :: (MonadAlpha m, MonadError Error m) => Program -> m Program
run :: Program -> m Program
run Program
prog = String -> m Program -> m Program
forall (m :: * -> *) a. MonadError Error m => String -> m a -> m a
wrapError' String
"Jikka.CPlusPlus.Convert.UseInitialization" (m Program -> m Program) -> m Program -> m Program
forall a b. (a -> b) -> a -> b
$ do
Program -> m Program
forall (m :: * -> *) a. Monad m => a -> m a
return (Program -> m Program) -> Program -> m Program
forall a b. (a -> b) -> a -> b
$ Program -> Program
runProgram Program
prog