{-# LANGUAGE PostfixOperators #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Redundant return" #-}

-- | Implementations defined here are valid for any language renderer.
module Drasil.GOOL.LanguageRenderer.LanguagePolymorphic (fileFromData,
  multiBody, block, multiBlock, listInnerType, obj, negateOp, csc, sec, 
  cot, equalOp, notEqualOp, greaterOp, greaterEqualOp, lessOp, lessEqualOp, 
  plusOp, minusOp, multOp, divideOp, moduloOp, var, staticVar, objVar,
  classVarCheckStatic, arrayElem, local, litChar, litDouble, litInt, litString, 
  valueOf, arg, argsList, call, funcAppMixedArgs, selfFuncAppMixedArgs, 
  newObjMixedArgs, lambda, objAccess, objMethodCall, func, get, set, listAdd, 
  listAppend, listAccess, listSet, getFunc, setFunc, 
  listAppendFunc, stmt, loopStmt, emptyStmt, assign, subAssign, increment,
  objDecNew, print, closeFile, returnStmt, valStmt, comment, throw, ifCond,
  tryCatch, construct, param, method, getMethod, setMethod, initStmts,
  function, docFuncRepr, docFunc, buildClass, implementingClass, docClass,
  commentedClass, modFromData, fileDoc, docMod, OptionalSpace(..),
  defaultOptSpace, smartAdd, smartSub
) where

import Utils.Drasil (indent)

import Drasil.GOOL.CodeType (CodeType(..), ClassName)
import Drasil.GOOL.InterfaceCommon (Label, Library, MSBody, MSBlock, VSFunction,
  VSType, SVariable, SValue, MSStatement, MSParameter, SMethod, NamedArgs,
  MixedCall, MixedCtorCall, BodySym(Body), bodyStatements, oneLiner,
  BlockSym(Block), TypeSym(Type), TypeElim(getType, getTypeString),
  VariableSym(Variable), VisibilitySym(..), VariableElim(variableName,
  variableType), ValueSym(Value, valueType), NumericExpression((#+), (#-), (#/),
  sin, cos, tan), Comparison(..), funcApp, StatementSym(multi),
  AssignStatement((&++)), (&=), IOStatement(printStr, printStrLn, printFile,
  printFileStr, printFileStrLn), ifNoElse, ScopeSym(Scope), convType)
import qualified Drasil.GOOL.InterfaceCommon as IC (TypeSym(int, double, char,
  string, listType, arrayType, listInnerType, funcType, void), VariableSym(var),
  Literal(litInt, litFloat, litDouble, litString), VariableValue(valueOf),
  List(listSize, listAccess), StatementSym(valStmt), DeclStatement(varDecDef),
  IOStatement(print), ControlStatement(returnStmt, for, forEach), ParameterSym(param),
  List(intToIndex), ScopeSym(local))
import Drasil.GOOL.InterfaceGOOL (SFile, FSModule, SClass, Initializers,
  CSStateVar, FileSym(File), ModuleSym(Module), newObj, objMethodCallNoParams,
  ($.), PermanenceSym(..), convTypeOO)
import qualified Drasil.GOOL.InterfaceGOOL as IG (OOVariableSym(objVarSelf),
  OOMethodSym(method), OOFunctionSym(func))
import Drasil.GOOL.RendererClassesCommon (CommonRenderSym, RenderType(..),
  InternalVarElim(variableBind), RenderValue(valFromData),
  RenderFunction(funcFromData), FunctionElim(functionType),
  RenderStatement(stmtFromData), StatementElim(statementTerm),
  MethodTypeSym(mType), RenderParam(paramFromData), RenderMethod(commentedFunc),
  BlockCommentSym(..))
import qualified Drasil.GOOL.RendererClassesCommon as S (RenderValue(call),
  InternalListFunc (listAddFunc, listAppendFunc, listAccessFunc, listSetFunc),
  RenderStatement(stmt), InternalIOStmt(..))
import qualified Drasil.GOOL.RendererClassesCommon as RC (BodyElim(..),
  BlockElim(..), InternalVarElim(variable), ValueElim(value, valueInt),
  FunctionElim(..), StatementElim(statement), BlockCommentElim(..))
import Drasil.GOOL.RendererClassesOO (OORenderSym, RenderFile(commentedMod),
  OORenderMethod(intMethod), RenderClass(inherit, implements),
  RenderMod(updateModuleDoc))
import qualified Drasil.GOOL.RendererClassesOO as S (RenderFile(fileFromData),
  InternalGetSet(getFunc, setFunc), OORenderMethod(intFunc),
  RenderClass(intClass, commentedClass))
import qualified Drasil.GOOL.RendererClassesOO as RC (ClassElim(..),
  ModuleElim(..))
import Drasil.GOOL.AST (Binding(..), Terminator(..), isSource, ScopeTag(Local),
  ScopeData, sd)
import Drasil.GOOL.Helpers (doubleQuotedText, vibcat, emptyIfEmpty, toCode, 
  toState, onStateValue, on2StateValues, onStateList, getInnerType, getNestDegree,
  on2StateWrapped)
import Drasil.GOOL.LanguageRenderer (dot, ifLabel, elseLabel, access, addExt, 
  FuncDocRenderer, ClassDocRenderer, ModuleDocRenderer, getterName, setterName, 
  valueList, namedArgList)
import qualified Drasil.GOOL.LanguageRenderer as R (file, block, assign, 
  addAssign, subAssign, return', comment, getTerm, var, objVar, arg, func, 
  objAccess, commentedItem)
import Drasil.GOOL.LanguageRenderer.Constructors (mkStmt, mkStmtNoEnd, 
  mkStateVal, mkVal, mkStateVar, mkVar, mkStaticVar, VSOp, unOpPrec, 
  compEqualPrec, compPrec, addPrec, multPrec)
import Drasil.GOOL.State (FS, CS, MS, lensFStoGS, lensMStoVS, lensCStoFS, 
  currMain, currFileType, addFile, setMainMod, setModuleName, getModuleName,
  addParameter, getParameters, useVarName)

import Prelude hiding (print,sin,cos,tan,(<>))
import Data.Maybe (fromMaybe, maybeToList)
import Control.Monad.State (modify)
import Control.Lens ((^.), over)
import Control.Lens.Zoom (zoom)
import Text.PrettyPrint.HughesPJ (Doc, text, empty, render, (<>), (<+>), ($+$),
  parens, brackets, integer, vcat, comma, isEmpty, space)
import qualified Text.PrettyPrint.HughesPJ as D (char, double)

-- Bodies --

multiBody :: (CommonRenderSym r, Monad r) => [MSBody r] -> MS (r Doc)
multiBody :: forall (r :: * -> *).
(CommonRenderSym r, Monad r) =>
[MSBody r] -> MS (r Doc)
multiBody [MSBody r]
bs = ([Doc] -> r Doc)
-> [State MethodState Doc] -> State MethodState (r Doc)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc) -> ([Doc] -> Doc) -> [Doc] -> r Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
vibcat) ([State MethodState Doc] -> State MethodState (r Doc))
-> [State MethodState Doc] -> State MethodState (r Doc)
forall a b. (a -> b) -> a -> b
$ (MSBody r -> State MethodState Doc)
-> [MSBody r] -> [State MethodState Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((r (Body r) -> Doc) -> MSBody r -> State MethodState Doc
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body) [MSBody r]
bs

-- Blocks --

block :: (CommonRenderSym r, Monad r) => [MSStatement r] -> MS (r Doc)
block :: forall (r :: * -> *).
(CommonRenderSym r, Monad r) =>
[MSStatement r] -> MS (r Doc)
block [MSStatement r]
sts = ([r (Statement r)] -> r Doc)
-> [MSStatement r] -> State MethodState (r Doc)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc)
-> ([r (Statement r)] -> Doc) -> [r (Statement r)] -> r Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
R.block ([Doc] -> Doc)
-> ([r (Statement r)] -> [Doc]) -> [r (Statement r)] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r (Statement r) -> Doc) -> [r (Statement r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement) ((MSStatement r -> MSStatement r)
-> [MSStatement r] -> [MSStatement r]
forall a b. (a -> b) -> [a] -> [b]
map MSStatement r -> MSStatement r
forall (r :: * -> *).
RenderStatement r =>
MSStatement r -> MSStatement r
S.stmt [MSStatement r]
sts)

multiBlock :: (CommonRenderSym r, Monad r) => [MSBlock r] -> MS (r Doc)
multiBlock :: forall (r :: * -> *).
(CommonRenderSym r, Monad r) =>
[MSBlock r] -> MS (r Doc)
multiBlock [MSBlock r]
bs = ([Doc] -> r Doc)
-> [State MethodState Doc] -> State MethodState (r Doc)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc) -> ([Doc] -> Doc) -> [Doc] -> r Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
vibcat) ([State MethodState Doc] -> State MethodState (r Doc))
-> [State MethodState Doc] -> State MethodState (r Doc)
forall a b. (a -> b) -> a -> b
$ (MSBlock r -> State MethodState Doc)
-> [MSBlock r] -> [State MethodState Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((r (Block r) -> Doc) -> MSBlock r -> State MethodState Doc
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Block r) -> Doc
forall (r :: * -> *). BlockElim r => r (Block r) -> Doc
RC.block) [MSBlock r]
bs

-- Types --

listInnerType :: (OORenderSym r) => VSType r -> VSType r
listInnerType :: forall (r :: * -> *). OORenderSym r => VSType r -> VSType r
listInnerType VSType r
t = VSType r
t VSType r -> (r (Type r) -> VSType r) -> VSType r
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (CodeType -> VSType r
forall (r :: * -> *). OOTypeSym r => CodeType -> VSType r
convTypeOO (CodeType -> VSType r)
-> (r (Type r) -> CodeType) -> r (Type r) -> VSType r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeType -> CodeType
getInnerType (CodeType -> CodeType)
-> (r (Type r) -> CodeType) -> r (Type r) -> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Type r) -> CodeType
forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType)

obj :: (CommonRenderSym r) => ClassName -> VSType r
obj :: forall (r :: * -> *). CommonRenderSym r => ClassName -> VSType r
obj ClassName
n = CodeType
-> ClassName -> Doc -> StateT ValueState Identity (r (Type r))
forall (r :: * -> *).
RenderType r =>
CodeType -> ClassName -> Doc -> VSType r
typeFromData (ClassName -> CodeType
Object ClassName
n) ClassName
n (ClassName -> Doc
text ClassName
n)

-- Unary Operators --

negateOp :: (Monad r) => VSOp r
negateOp :: forall (r :: * -> *). Monad r => VSOp r
negateOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
unOpPrec ClassName
"-"

csc :: (CommonRenderSym r) => SValue r -> SValue r
csc :: forall (r :: * -> *). CommonRenderSym r => SValue r -> SValue r
csc SValue r
v = VSType r -> SValue r
forall (r :: * -> *). CommonRenderSym r => VSType r -> SValue r
valOfOne ((r (Value r) -> r (Type r)) -> SValue r -> VSType r
forall a b.
(a -> b)
-> StateT ValueState Identity a -> StateT ValueState Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v) SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#/ SValue r -> SValue r
forall (r :: * -> *). NumericExpression r => SValue r -> SValue r
sin SValue r
v

sec :: (CommonRenderSym r) => SValue r -> SValue r
sec :: forall (r :: * -> *). CommonRenderSym r => SValue r -> SValue r
sec SValue r
v = VSType r -> SValue r
forall (r :: * -> *). CommonRenderSym r => VSType r -> SValue r
valOfOne ((r (Value r) -> r (Type r)) -> SValue r -> VSType r
forall a b.
(a -> b)
-> StateT ValueState Identity a -> StateT ValueState Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v) SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#/ SValue r -> SValue r
forall (r :: * -> *). NumericExpression r => SValue r -> SValue r
cos SValue r
v

cot :: (CommonRenderSym r) => SValue r -> SValue r
cot :: forall (r :: * -> *). CommonRenderSym r => SValue r -> SValue r
cot SValue r
v = VSType r -> SValue r
forall (r :: * -> *). CommonRenderSym r => VSType r -> SValue r
valOfOne ((r (Value r) -> r (Type r)) -> SValue r -> VSType r
forall a b.
(a -> b)
-> StateT ValueState Identity a -> StateT ValueState Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v) SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#/ SValue r -> SValue r
forall (r :: * -> *). NumericExpression r => SValue r -> SValue r
tan SValue r
v

valOfOne :: (CommonRenderSym r) => VSType r -> SValue r
valOfOne :: forall (r :: * -> *). CommonRenderSym r => VSType r -> SValue r
valOfOne VSType r
t = VSType r
t VSType r
-> (r (Type r) -> StateT ValueState Identity (r (Value r)))
-> StateT ValueState Identity (r (Value r))
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (CodeType -> StateT ValueState Identity (r (Value r))
forall {r :: * -> *}. Literal r => CodeType -> VS (r (Value r))
getVal (CodeType -> StateT ValueState Identity (r (Value r)))
-> (r (Type r) -> CodeType)
-> r (Type r)
-> StateT ValueState Identity (r (Value r))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Type r) -> CodeType
forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType)
  where getVal :: CodeType -> VS (r (Value r))
getVal CodeType
Float = Float -> VS (r (Value r))
forall (r :: * -> *). Literal r => Float -> SValue r
IC.litFloat Float
1.0
        getVal CodeType
_ = Double -> VS (r (Value r))
forall (r :: * -> *). Literal r => Double -> SValue r
IC.litDouble Double
1.0

-- Binary Operators --

smartAdd :: (CommonRenderSym r) => SValue r -> SValue r -> SValue r
smartAdd :: forall (r :: * -> *).
CommonRenderSym r =>
SValue r -> SValue r -> SValue r
smartAdd SValue r
v1 SValue r
v2 = do
  r (Value r)
v1' <- SValue r
v1
  r (Value r)
v2' <- SValue r
v2
  case (r (Value r) -> Maybe Integer
forall (r :: * -> *). ValueElim r => r (Value r) -> Maybe Integer
RC.valueInt r (Value r)
v1', r (Value r) -> Maybe Integer
forall (r :: * -> *). ValueElim r => r (Value r) -> Maybe Integer
RC.valueInt r (Value r)
v2') of
    (Just Integer
i1, Just Integer
i2) -> Integer -> SValue r
forall (r :: * -> *). CommonRenderSym r => Integer -> SValue r
litInt (Integer
i1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
i2)
    (Maybe Integer, Maybe Integer)
_                  -> SValue r
v1 SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#+ SValue r
v2

smartSub :: (CommonRenderSym r) => SValue r -> SValue r -> SValue r
smartSub :: forall (r :: * -> *).
CommonRenderSym r =>
SValue r -> SValue r -> SValue r
smartSub SValue r
v1 SValue r
v2 = do
  r (Value r)
v1' <- SValue r
v1
  r (Value r)
v2' <- SValue r
v2
  case (r (Value r) -> Maybe Integer
forall (r :: * -> *). ValueElim r => r (Value r) -> Maybe Integer
RC.valueInt r (Value r)
v1', r (Value r) -> Maybe Integer
forall (r :: * -> *). ValueElim r => r (Value r) -> Maybe Integer
RC.valueInt r (Value r)
v2') of
    (Just Integer
i1, Just Integer
i2) -> Integer -> SValue r
forall (r :: * -> *). CommonRenderSym r => Integer -> SValue r
litInt (Integer
i1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
i2)
    (Maybe Integer, Maybe Integer)
_                  -> SValue r
v1 SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#- SValue r
v2

equalOp :: (Monad r) => VSOp r
equalOp :: forall (r :: * -> *). Monad r => VSOp r
equalOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
compEqualPrec ClassName
"=="

notEqualOp :: (Monad r) => VSOp r
notEqualOp :: forall (r :: * -> *). Monad r => VSOp r
notEqualOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
compEqualPrec ClassName
"!="

greaterOp :: (Monad r) => VSOp r
greaterOp :: forall (r :: * -> *). Monad r => VSOp r
greaterOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
compPrec ClassName
">"

greaterEqualOp :: (Monad r) => VSOp r
greaterEqualOp :: forall (r :: * -> *). Monad r => VSOp r
greaterEqualOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
compPrec ClassName
">="

lessOp :: (Monad r) => VSOp r
lessOp :: forall (r :: * -> *). Monad r => VSOp r
lessOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
compPrec ClassName
"<"

lessEqualOp :: (Monad r) => VSOp r
lessEqualOp :: forall (r :: * -> *). Monad r => VSOp r
lessEqualOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
compPrec ClassName
"<="

plusOp :: (Monad r) => VSOp r
plusOp :: forall (r :: * -> *). Monad r => VSOp r
plusOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
addPrec ClassName
"+"

minusOp :: (Monad r) => VSOp r
minusOp :: forall (r :: * -> *). Monad r => VSOp r
minusOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
addPrec ClassName
"-"

multOp :: (Monad r) => VSOp r
multOp :: forall (r :: * -> *). Monad r => VSOp r
multOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
multPrec ClassName
"*"

divideOp :: (Monad r) => VSOp r
divideOp :: forall (r :: * -> *). Monad r => VSOp r
divideOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
multPrec ClassName
"/"

moduloOp :: (Monad r) => VSOp r
moduloOp :: forall (r :: * -> *). Monad r => VSOp r
moduloOp = ClassName -> VSOp r
forall (r :: * -> *). Monad r => ClassName -> VSOp r
multPrec ClassName
"%"

-- Variables --

var :: (CommonRenderSym r) => Label -> VSType r -> SVariable r
var :: forall (r :: * -> *).
CommonRenderSym r =>
ClassName -> VSType r -> SVariable r
var ClassName
n VSType r
t = ClassName
-> VSType r -> Doc -> StateT ValueState Identity (r (Variable r))
forall (r :: * -> *).
CommonRenderSym r =>
ClassName -> VSType r -> Doc -> SVariable r
mkStateVar ClassName
n VSType r
t (ClassName -> Doc
R.var ClassName
n)

staticVar :: (CommonRenderSym r) => Label -> VSType r -> SVariable r
staticVar :: forall (r :: * -> *).
CommonRenderSym r =>
ClassName -> VSType r -> SVariable r
staticVar ClassName
n VSType r
t = ClassName
-> VSType r -> Doc -> StateT ValueState Identity (r (Variable r))
forall (r :: * -> *).
CommonRenderSym r =>
ClassName -> VSType r -> Doc -> SVariable r
mkStaticVar ClassName
n VSType r
t (ClassName -> Doc
R.var ClassName
n)

-- | To be used in classVar implementations. Throws an error if the variable is 
-- not static since classVar is for accessing static variables from a class
classVarCheckStatic :: (CommonRenderSym r) => r (Variable r) -> r (Variable r)
classVarCheckStatic :: forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Variable r)
classVarCheckStatic r (Variable r)
v = Binding -> r (Variable r)
classVarCS (r (Variable r) -> Binding
forall (r :: * -> *).
InternalVarElim r =>
r (Variable r) -> Binding
variableBind r (Variable r)
v)
  where classVarCS :: Binding -> r (Variable r)
classVarCS Binding
Dynamic = ClassName -> r (Variable r)
forall a. HasCallStack => ClassName -> a
error
          ClassName
"classVar can only be used to access static variables"
        classVarCS Binding
Static = r (Variable r)
v

objVar :: (CommonRenderSym r) => SVariable r -> SVariable r -> SVariable r
objVar :: forall (r :: * -> *).
CommonRenderSym r =>
SVariable r -> SVariable r -> SVariable r
objVar SVariable r
o' SVariable r
v' = do
  r (Variable r)
o <- SVariable r
o'
  r (Variable r)
v <- SVariable r
v'
  let objVar' :: Binding -> SVariable r
objVar' Binding
Static = ClassName -> SVariable r
forall a. HasCallStack => ClassName -> a
error 
        ClassName
"Cannot access static variables through an object, use classVar instead"
      objVar' Binding
Dynamic = ClassName -> r (Type r) -> Doc -> SVariable r
forall (r :: * -> *).
CommonRenderSym r =>
ClassName -> r (Type r) -> Doc -> SVariable r
mkVar (r (Variable r) -> ClassName
forall (r :: * -> *). VariableElim r => r (Variable r) -> ClassName
variableName r (Variable r)
o ClassName -> ClassName -> ClassName
`access` r (Variable r) -> ClassName
forall (r :: * -> *). VariableElim r => r (Variable r) -> ClassName
variableName r (Variable r)
v) 
        (r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v) (Doc -> Doc -> Doc
R.objVar (r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
o) (r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v))
  Binding -> SVariable r
objVar' (r (Variable r) -> Binding
forall (r :: * -> *).
InternalVarElim r =>
r (Variable r) -> Binding
variableBind r (Variable r)
v)

arrayElem :: (OORenderSym r) => SValue r -> SVariable r -> SVariable r
arrayElem :: forall (r :: * -> *).
OORenderSym r =>
SValue r -> SVariable r -> SVariable r
arrayElem SValue r
i' SVariable r
v' = do
  r (Value r)
i <- SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.intToIndex SValue r
i'
  r (Variable r)
v <- SVariable r
v'
  let vName :: ClassName
vName = r (Variable r) -> ClassName
forall (r :: * -> *). VariableElim r => r (Variable r) -> ClassName
variableName r (Variable r)
v ClassName -> ClassName -> ClassName
forall a. [a] -> [a] -> [a]
++ ClassName
"[" ClassName -> ClassName -> ClassName
forall a. [a] -> [a] -> [a]
++ Doc -> ClassName
render (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
i) ClassName -> ClassName -> ClassName
forall a. [a] -> [a] -> [a]
++ ClassName
"]"
      vType :: VSType r
vType = VSType r -> VSType r
forall (r :: * -> *). OORenderSym r => VSType r -> VSType r
listInnerType (VSType r -> VSType r) -> VSType r -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Type r) -> VSType r
forall a. a -> StateT ValueState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (r (Type r) -> VSType r) -> r (Type r) -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v
      vRender :: Doc
vRender = r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v Doc -> Doc -> Doc
<> Doc -> Doc
brackets (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
i)
  ClassName -> VSType r -> Doc -> SVariable r
forall (r :: * -> *).
CommonRenderSym r =>
ClassName -> VSType r -> Doc -> SVariable r
mkStateVar ClassName
vName VSType r
vType Doc
vRender

-- Scope --
local :: (Monad r) => r ScopeData
local :: forall (r :: * -> *). Monad r => r ScopeData
local = ScopeData -> r ScopeData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (ScopeData -> r ScopeData) -> ScopeData -> r ScopeData
forall a b. (a -> b) -> a -> b
$ ScopeTag -> ScopeData
sd ScopeTag
Local

-- Values --

litChar :: (CommonRenderSym r) => (Doc -> Doc) -> Char -> SValue r
litChar :: forall (r :: * -> *).
CommonRenderSym r =>
(Doc -> Doc) -> Char -> SValue r
litChar Doc -> Doc
f Char
c = VSType r -> Doc -> StateT ValueState Identity (r (Value r))
forall (r :: * -> *).
CommonRenderSym r =>
VSType r -> Doc -> SValue r
mkStateVal VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.char (Doc -> Doc
f (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ if Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n' then ClassName -> Doc
text ClassName
"\\n" else Char -> Doc
D.char Char
c)

litDouble :: (CommonRenderSym r) => Double -> SValue r
litDouble :: forall (r :: * -> *). CommonRenderSym r => Double -> SValue r
litDouble Double
d = VSType r -> Doc -> StateT ValueState Identity (r (Value r))
forall (r :: * -> *).
CommonRenderSym r =>
VSType r -> Doc -> SValue r
mkStateVal VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.double (Double -> Doc
D.double Double
d)

litInt :: (CommonRenderSym r) => Integer -> SValue r
litInt :: forall (r :: * -> *). CommonRenderSym r => Integer -> SValue r
litInt Integer
i = Maybe Int
-> Maybe Integer
-> VSType r
-> Doc
-> StateT ValueState Identity (r (Value r))
forall (r :: * -> *).
RenderValue r =>
Maybe Int -> Maybe Integer -> VSType r -> Doc -> SValue r
valFromData Maybe Int
forall a. Maybe a
Nothing (Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
i) VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.int (Integer -> Doc
integer Integer
i)

litString :: (CommonRenderSym r) => String -> SValue r
litString :: forall (r :: * -> *). CommonRenderSym r => ClassName -> SValue r
litString ClassName
s = VSType r -> Doc -> StateT ValueState Identity (r (Value r))
forall (r :: * -> *).
CommonRenderSym r =>
VSType r -> Doc -> SValue r
mkStateVal VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.string (ClassName -> Doc
doubleQuotedText ClassName
s)

valueOf :: (CommonRenderSym r) => SVariable r -> SValue r
valueOf :: forall (r :: * -> *). CommonRenderSym r => SVariable r -> SValue r
valueOf SVariable r
v' = do 
  r (Variable r)
v <- SVariable r
v'
  r (Type r) -> Doc -> SValue r
forall (r :: * -> *).
CommonRenderSym r =>
r (Type r) -> Doc -> SValue r
mkVal (r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v) (r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v)

arg :: (CommonRenderSym r) => SValue r -> SValue r -> SValue r
arg :: forall (r :: * -> *).
CommonRenderSym r =>
SValue r -> SValue r -> SValue r
arg SValue r
n' SValue r
args' = do 
  r (Value r)
n <- SValue r
n'
  r (Value r)
args <- SValue r
args'
  r (Type r)
s <- VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.string
  r (Type r) -> Doc -> SValue r
forall (r :: * -> *).
CommonRenderSym r =>
r (Type r) -> Doc -> SValue r
mkVal r (Type r)
s (r (Value r) -> r (Value r) -> Doc
forall (r :: * -> *).
CommonRenderSym r =>
r (Value r) -> r (Value r) -> Doc
R.arg r (Value r)
n r (Value r)
args)

argsList :: (CommonRenderSym r) => String -> SValue r
argsList :: forall (r :: * -> *). CommonRenderSym r => ClassName -> SValue r
argsList ClassName
l = VSType r -> Doc -> StateT ValueState Identity (r (Value r))
forall (r :: * -> *).
CommonRenderSym r =>
VSType r -> Doc -> SValue r
mkStateVal (VSType r -> VSType r
forall (r :: * -> *). TypeSym r => VSType r -> VSType r
IC.arrayType VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.string) (ClassName -> Doc
text ClassName
l)

-- | First parameter is separator between name and value for named arguments, 
-- rest similar to call from RendererClasses
call :: (CommonRenderSym r) => Doc -> Maybe Library -> Maybe Doc -> MixedCall r
call :: forall (r :: * -> *).
CommonRenderSym r =>
Doc -> Maybe ClassName -> Maybe Doc -> MixedCall r
call Doc
sep Maybe ClassName
lib Maybe Doc
o ClassName
n VSType r
t [SValue r]
pas NamedArgs r
nas = do
  [r (Value r)]
pargs <- [SValue r] -> StateT ValueState Identity [r (Value r)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [SValue r]
pas
  [r (Variable r)]
nms <- ((StateT ValueState Identity (r (Variable r)), SValue r)
 -> StateT ValueState Identity (r (Variable r)))
-> NamedArgs r -> StateT ValueState Identity [r (Variable r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (StateT ValueState Identity (r (Variable r)), SValue r)
-> StateT ValueState Identity (r (Variable r))
forall a b. (a, b) -> a
fst NamedArgs r
nas
  [r (Value r)]
nargs <- ((StateT ValueState Identity (r (Variable r)), SValue r)
 -> SValue r)
-> NamedArgs r -> StateT ValueState Identity [r (Value r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (StateT ValueState Identity (r (Variable r)), SValue r) -> SValue r
forall a b. (a, b) -> b
snd NamedArgs r
nas
  let libDoc :: Doc
libDoc = Doc -> (ClassName -> Doc) -> Maybe ClassName -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ClassName -> Doc
text ClassName
n) (ClassName -> Doc
text (ClassName -> Doc) -> (ClassName -> ClassName) -> ClassName -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClassName -> ClassName -> ClassName
`access` ClassName
n)) Maybe ClassName
lib
      obDoc :: Doc
obDoc = Doc -> Maybe Doc -> Doc
forall a. a -> Maybe a -> a
fromMaybe Doc
empty Maybe Doc
o
  VSType r -> Doc -> SValue r
forall (r :: * -> *).
CommonRenderSym r =>
VSType r -> Doc -> SValue r
mkStateVal VSType r
t (Doc -> SValue r) -> Doc -> SValue r
forall a b. (a -> b) -> a -> b
$ Doc
obDoc Doc -> Doc -> Doc
<> Doc
libDoc Doc -> Doc -> Doc
<> Doc -> Doc
parens ([r (Value r)] -> Doc
forall (r :: * -> *). CommonRenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
pargs Doc -> Doc -> Doc
<> 
    (if [SValue r] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SValue r]
pas Bool -> Bool -> Bool
|| NamedArgs r -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null NamedArgs r
nas then Doc
empty else Doc
comma) Doc -> Doc -> Doc
<+> Doc -> [(r (Variable r), r (Value r))] -> Doc
forall (r :: * -> *).
CommonRenderSym r =>
Doc -> [(r (Variable r), r (Value r))] -> Doc
namedArgList Doc
sep 
    ([r (Variable r)]
-> [r (Value r)] -> [(r (Variable r), r (Value r))]
forall a b. [a] -> [b] -> [(a, b)]
zip [r (Variable r)]
nms [r (Value r)]
nargs))

funcAppMixedArgs :: (CommonRenderSym r) => MixedCall r
funcAppMixedArgs :: forall (r :: * -> *). CommonRenderSym r => MixedCall r
funcAppMixedArgs = Maybe ClassName
-> Maybe Doc
-> ClassName
-> StateT ValueState Identity (r (Type r))
-> [StateT ValueState Identity (r (Value r))]
-> [(StateT ValueState Identity (r (Variable r)),
     StateT ValueState Identity (r (Value r)))]
-> StateT ValueState Identity (r (Value r))
forall (r :: * -> *).
RenderValue r =>
Maybe ClassName -> Maybe Doc -> MixedCall r
S.call Maybe ClassName
forall a. Maybe a
Nothing Maybe Doc
forall a. Maybe a
Nothing

selfFuncAppMixedArgs :: (CommonRenderSym r) => Doc -> SVariable r -> MixedCall r
selfFuncAppMixedArgs :: forall (r :: * -> *).
CommonRenderSym r =>
Doc -> SVariable r -> MixedCall r
selfFuncAppMixedArgs Doc
d SVariable r
slf ClassName
n VSType r
t [SValue r]
vs NamedArgs r
ns = do
  r (Variable r)
s <- SVariable r
slf 
  Maybe ClassName -> Maybe Doc -> MixedCall r
forall (r :: * -> *).
RenderValue r =>
Maybe ClassName -> Maybe Doc -> MixedCall r
S.call Maybe ClassName
forall a. Maybe a
Nothing (Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
s Doc -> Doc -> Doc
<> Doc
d) ClassName
n VSType r
t [SValue r]
vs NamedArgs r
ns

newObjMixedArgs :: (CommonRenderSym r) => String -> MixedCtorCall r
newObjMixedArgs :: forall (r :: * -> *). CommonRenderSym r => MixedCall r
newObjMixedArgs ClassName
s VSType r
tp [SValue r]
vs NamedArgs r
ns = do
  r (Type r)
t <- VSType r
tp 
  Maybe ClassName -> Maybe Doc -> MixedCall r
forall (r :: * -> *).
RenderValue r =>
Maybe ClassName -> Maybe Doc -> MixedCall r
S.call Maybe ClassName
forall a. Maybe a
Nothing Maybe Doc
forall a. Maybe a
Nothing (ClassName
s ClassName -> ClassName -> ClassName
forall a. [a] -> [a] -> [a]
++ r (Type r) -> ClassName
forall (r :: * -> *). TypeElim r => r (Type r) -> ClassName
getTypeString r (Type r)
t) (r (Type r) -> VSType r
forall a. a -> StateT ValueState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return r (Type r)
t) [SValue r]
vs NamedArgs r
ns

lambda :: (CommonRenderSym r) => ([r (Variable r)] -> r (Value r) -> Doc) -> 
  [SVariable r] -> SValue r -> SValue r
lambda :: forall (r :: * -> *).
CommonRenderSym r =>
([r (Variable r)] -> r (Value r) -> Doc)
-> [SVariable r] -> SValue r -> SValue r
lambda [r (Variable r)] -> r (Value r) -> Doc
f [SVariable r]
ps' SValue r
ex' = do
  [r (Variable r)]
ps <- [SVariable r] -> StateT ValueState Identity [r (Variable r)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [SVariable r]
ps'
  r (Value r)
ex <- SValue r
ex'
  let ft :: VSType r
ft = [VSType r] -> VSType r -> VSType r
forall (r :: * -> *).
TypeSym r =>
[VSType r] -> VSType r -> VSType r
IC.funcType ((r (Variable r) -> VSType r) -> [r (Variable r)] -> [VSType r]
forall a b. (a -> b) -> [a] -> [b]
map (r (Type r) -> VSType r
forall a. a -> StateT ValueState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (r (Type r) -> VSType r)
-> (r (Variable r) -> r (Type r)) -> r (Variable r) -> VSType r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType) [r (Variable r)]
ps) (r (Type r) -> VSType r
forall a. a -> StateT ValueState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (r (Type r) -> VSType r) -> r (Type r) -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
ex)
  Maybe Int -> Maybe Integer -> VSType r -> Doc -> SValue r
forall (r :: * -> *).
RenderValue r =>
Maybe Int -> Maybe Integer -> VSType r -> Doc -> SValue r
valFromData (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0) Maybe Integer
forall a. Maybe a
Nothing VSType r
ft ([r (Variable r)] -> r (Value r) -> Doc
f [r (Variable r)]
ps r (Value r)
ex)

objAccess :: (CommonRenderSym r) => SValue r -> VSFunction r -> SValue r
objAccess :: forall (r :: * -> *).
CommonRenderSym r =>
SValue r -> VSFunction r -> SValue r
objAccess = (r (Value r)
 -> r (Function r) -> StateT ValueState Identity (r (Value r)))
-> StateT ValueState Identity (r (Value r))
-> StateT ValueState Identity (r (Function r))
-> StateT ValueState Identity (r (Value r))
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
on2StateWrapped (\r (Value r)
v r (Function r)
f-> r (Type r) -> Doc -> StateT ValueState Identity (r (Value r))
forall (r :: * -> *).
CommonRenderSym r =>
r (Type r) -> Doc -> SValue r
mkVal (r (Function r) -> r (Type r)
forall (r :: * -> *).
FunctionElim r =>
r (Function r) -> r (Type r)
functionType r (Function r)
f) 
  (Doc -> Doc -> Doc
R.objAccess (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v) (r (Function r) -> Doc
forall (r :: * -> *). FunctionElim r => r (Function r) -> Doc
RC.function r (Function r)
f)))

objMethodCall :: (CommonRenderSym r) => Label -> VSType r -> SValue r -> [SValue r] 
  -> NamedArgs r -> SValue r
objMethodCall :: forall (r :: * -> *).
CommonRenderSym r =>
ClassName
-> VSType r -> SValue r -> [SValue r] -> NamedArgs r -> SValue r
objMethodCall ClassName
f VSType r
t SValue r
ob [SValue r]
vs NamedArgs r
ns = SValue r
ob SValue r -> (r (Value r) -> SValue r) -> SValue r
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\r (Value r)
o -> Maybe ClassName -> Maybe Doc -> MixedCall r
forall (r :: * -> *).
RenderValue r =>
Maybe ClassName -> Maybe Doc -> MixedCall r
S.call Maybe ClassName
forall a. Maybe a
Nothing 
  (Doc -> Maybe Doc
forall a. a -> Maybe a
Just (Doc -> Maybe Doc) -> Doc -> Maybe Doc
forall a b. (a -> b) -> a -> b
$ r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
o Doc -> Doc -> Doc
<> Doc
dot) ClassName
f VSType r
t [SValue r]
vs NamedArgs r
ns)

-- Functions --

func :: (CommonRenderSym r) => Label -> VSType r -> [SValue r] -> VSFunction r
func :: forall (r :: * -> *).
CommonRenderSym r =>
ClassName -> VSType r -> [SValue r] -> VSFunction r
func ClassName
l VSType r
t [SValue r]
vs = PosCall r
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp ClassName
l VSType r
t [SValue r]
vs SValue r
-> (r (Value r) -> StateT ValueState Identity (r (Function r)))
-> StateT ValueState Identity (r (Function r))
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ((Doc -> VSType r -> StateT ValueState Identity (r (Function r))
forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
`funcFromData` VSType r
t) (Doc -> StateT ValueState Identity (r (Function r)))
-> (r (Value r) -> Doc)
-> r (Value r)
-> StateT ValueState Identity (r (Function r))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
R.func (Doc -> Doc) -> (r (Value r) -> Doc) -> r (Value r) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value)

get :: (OORenderSym r) => SValue r -> SVariable r -> SValue r
get :: forall (r :: * -> *).
OORenderSym r =>
SValue r -> SVariable r -> SValue r
get SValue r
v SVariable r
vToGet = SValue r
v SValue r -> VSFunction r -> SValue r
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. SVariable r -> VSFunction r
forall (r :: * -> *).
InternalGetSet r =>
SVariable r -> VSFunction r
S.getFunc SVariable r
vToGet

set :: (OORenderSym r) => SValue r -> SVariable r -> SValue r -> SValue r
set :: forall (r :: * -> *).
OORenderSym r =>
SValue r -> SVariable r -> SValue r -> SValue r
set SValue r
v SVariable r
vToSet SValue r
toVal = SValue r
v SValue r -> VSFunction r -> SValue r
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. VSType r -> SVariable r -> SValue r -> VSFunction r
forall (r :: * -> *).
InternalGetSet r =>
VSType r -> SVariable r -> SValue r -> VSFunction r
S.setFunc ((r (Value r) -> r (Type r)) -> SValue r -> VSType r
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v) SVariable r
vToSet SValue r
toVal

listAdd :: (OORenderSym r) => SValue r -> SValue r -> SValue r -> SValue r
listAdd :: forall (r :: * -> *).
OORenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
listAdd SValue r
v SValue r
i SValue r
vToAdd = SValue r
v SValue r -> VSFunction r -> SValue r
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. SValue r -> SValue r -> SValue r -> VSFunction r
forall (r :: * -> *).
InternalListFunc r =>
SValue r -> SValue r -> SValue r -> VSFunction r
S.listAddFunc SValue r
v (SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.intToIndex SValue r
i) SValue r
vToAdd

listAppend :: (OORenderSym r) => SValue r -> SValue r -> SValue r
listAppend :: forall (r :: * -> *).
OORenderSym r =>
SValue r -> SValue r -> SValue r
listAppend SValue r
v SValue r
vToApp = SValue r
v SValue r -> VSFunction r -> SValue r
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. SValue r -> SValue r -> VSFunction r
forall (r :: * -> *).
InternalListFunc r =>
SValue r -> SValue r -> VSFunction r
S.listAppendFunc SValue r
v SValue r
vToApp

listAccess :: (CommonRenderSym r) => SValue r -> SValue r -> SValue r
listAccess :: forall (r :: * -> *).
CommonRenderSym r =>
SValue r -> SValue r -> SValue r
listAccess SValue r
v SValue r
i = do
  r (Value r)
v' <- SValue r
v
  let i' :: SValue r
i' = SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.intToIndex SValue r
i
      t :: VSType r
t  = VSType r -> VSType r
forall (r :: * -> *). TypeSym r => VSType r -> VSType r
IC.listInnerType (VSType r -> VSType r) -> VSType r -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Type r) -> VSType r
forall a. a -> StateT ValueState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (r (Type r) -> VSType r) -> r (Type r) -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v'
      checkType :: CodeType -> VSFunction r
checkType (List CodeType
_) = VSType r -> SValue r -> VSFunction r
forall (r :: * -> *).
InternalListFunc r =>
VSType r -> SValue r -> VSFunction r
S.listAccessFunc VSType r
t SValue r
i'
      checkType (Set CodeType
_) = VSType r -> SValue r -> VSFunction r
forall (r :: * -> *).
InternalListFunc r =>
VSType r -> SValue r -> VSFunction r
S.listAccessFunc VSType r
t SValue r
i'
      checkType (Array CodeType
_) = SValue r
i' SValue r -> (r (Value r) -> VSFunction r) -> VSFunction r
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= 
                              (\r (Value r)
ix -> Doc -> VSType r -> VSFunction r
forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData (Doc -> Doc
brackets (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
ix)) VSType r
t)
      checkType CodeType
_ = ClassName -> VSFunction r
forall a. HasCallStack => ClassName -> a
error ClassName
"listAccess called on non-list-type value"
  r (Function r)
f <- CodeType -> VSFunction r
checkType (r (Type r) -> CodeType
forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType (r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v'))
  r (Type r) -> Doc -> SValue r
forall (r :: * -> *).
CommonRenderSym r =>
r (Type r) -> Doc -> SValue r
mkVal (r (Function r) -> r (Type r)
forall (r :: * -> *).
FunctionElim r =>
r (Function r) -> r (Type r)
RC.functionType r (Function r)
f) (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v' Doc -> Doc -> Doc
<> r (Function r) -> Doc
forall (r :: * -> *). FunctionElim r => r (Function r) -> Doc
RC.function r (Function r)
f)

listSet :: (CommonRenderSym r) => SValue r -> SValue r -> SValue r -> SValue r
listSet :: forall (r :: * -> *).
CommonRenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
listSet SValue r
v SValue r
i SValue r
toVal = do
  r (Value r)
v' <- SValue r
v
  r (Function r)
f <- SValue r
-> SValue r
-> SValue r
-> StateT ValueState Identity (r (Function r))
forall (r :: * -> *).
InternalListFunc r =>
SValue r -> SValue r -> SValue r -> VSFunction r
S.listSetFunc SValue r
v (SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.intToIndex SValue r
i) SValue r
toVal
  r (Type r) -> Doc -> SValue r
forall (r :: * -> *).
CommonRenderSym r =>
r (Type r) -> Doc -> SValue r
mkVal (r (Function r) -> r (Type r)
forall (r :: * -> *).
FunctionElim r =>
r (Function r) -> r (Type r)
RC.functionType r (Function r)
f) (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v' Doc -> Doc -> Doc
<> r (Function r) -> Doc
forall (r :: * -> *). FunctionElim r => r (Function r) -> Doc
RC.function r (Function r)
f)

getFunc :: (OORenderSym r) => SVariable r -> VSFunction r
getFunc :: forall (r :: * -> *). OORenderSym r => SVariable r -> VSFunction r
getFunc SVariable r
v = SVariable r
v SVariable r
-> (r (Variable r) -> StateT ValueState Identity (r (Function r)))
-> StateT ValueState Identity (r (Function r))
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\r (Variable r)
vr -> ClassName
-> VSType r
-> [SValue r]
-> StateT ValueState Identity (r (Function r))
forall (r :: * -> *).
OOFunctionSym r =>
ClassName -> VSType r -> [SValue r] -> VSFunction r
IG.func (ClassName -> ClassName
getterName (ClassName -> ClassName) -> ClassName -> ClassName
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> ClassName
forall (r :: * -> *). VariableElim r => r (Variable r) -> ClassName
variableName r (Variable r)
vr) 
  (r (Type r) -> VSType r
forall a s. a -> State s a
toState (r (Type r) -> VSType r) -> r (Type r) -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
vr) [])

setFunc :: (OORenderSym r) => VSType r -> SVariable r -> SValue r -> VSFunction r
setFunc :: forall (r :: * -> *).
OORenderSym r =>
VSType r -> SVariable r -> SValue r -> VSFunction r
setFunc VSType r
t SVariable r
v SValue r
toVal = SVariable r
v SVariable r
-> (r (Variable r) -> StateT ValueState Identity (r (Function r)))
-> StateT ValueState Identity (r (Function r))
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\r (Variable r)
vr -> ClassName
-> VSType r
-> [SValue r]
-> StateT ValueState Identity (r (Function r))
forall (r :: * -> *).
OOFunctionSym r =>
ClassName -> VSType r -> [SValue r] -> VSFunction r
IG.func (ClassName -> ClassName
setterName (ClassName -> ClassName) -> ClassName -> ClassName
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> ClassName
forall (r :: * -> *). VariableElim r => r (Variable r) -> ClassName
variableName r (Variable r)
vr) VSType r
t 
  [SValue r
toVal])

listAppendFunc :: (OORenderSym r) => Label -> SValue r -> VSFunction r
listAppendFunc :: forall (r :: * -> *).
OORenderSym r =>
ClassName -> SValue r -> VSFunction r
listAppendFunc ClassName
f SValue r
v = ClassName
-> VSType r
-> [SValue r]
-> StateT ValueState Identity (r (Function r))
forall (r :: * -> *).
OOFunctionSym r =>
ClassName -> VSType r -> [SValue r] -> VSFunction r
IG.func ClassName
f (VSType r -> VSType r
forall (r :: * -> *). TypeSym r => VSType r -> VSType r
IC.listType (VSType r -> VSType r) -> VSType r -> VSType r
forall a b. (a -> b) -> a -> b
$ (r (Value r) -> r (Type r)) -> SValue r -> VSType r
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v) [SValue r
v]

-- Statements --

stmt :: (CommonRenderSym r) => MSStatement r -> MSStatement r
stmt :: forall (r :: * -> *).
CommonRenderSym r =>
MSStatement r -> MSStatement r
stmt MSStatement r
s' = do 
  r (Statement r)
s <- MSStatement r
s'
  Doc -> MSStatement r
forall (r :: * -> *). CommonRenderSym r => Doc -> MSStatement r
mkStmtNoEnd (r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement r (Statement r)
s Doc -> Doc -> Doc
<> Terminator -> Doc
R.getTerm (r (Statement r) -> Terminator
forall (r :: * -> *).
StatementElim r =>
r (Statement r) -> Terminator
statementTerm r (Statement r)
s))

loopStmt :: (CommonRenderSym r) => MSStatement r -> MSStatement r
loopStmt :: forall (r :: * -> *).
CommonRenderSym r =>
MSStatement r -> MSStatement r
loopStmt = MS (r (Statement r)) -> MS (r (Statement r))
forall (r :: * -> *).
RenderStatement r =>
MSStatement r -> MSStatement r
S.stmt (MS (r (Statement r)) -> MS (r (Statement r)))
-> (MS (r (Statement r)) -> MS (r (Statement r)))
-> MS (r (Statement r))
-> MS (r (Statement r))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MS (r (Statement r)) -> MS (r (Statement r))
forall (r :: * -> *).
CommonRenderSym r =>
MSStatement r -> MSStatement r
setEmpty

emptyStmt :: (CommonRenderSym r) => MSStatement r
emptyStmt :: forall (r :: * -> *). CommonRenderSym r => MSStatement r
emptyStmt = Doc -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *). CommonRenderSym r => Doc -> MSStatement r
mkStmtNoEnd Doc
empty

assign :: (CommonRenderSym r) => Terminator -> SVariable r -> SValue r -> 
  MSStatement r
assign :: forall (r :: * -> *).
CommonRenderSym r =>
Terminator -> SVariable r -> SValue r -> MSStatement r
assign Terminator
t SVariable r
vr' SValue r
v' = do 
  r (Variable r)
vr <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Variable r)) ValueState)
-> MethodState -> Focusing Identity (r (Variable r)) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable r
vr'
  r (Value r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Value r)) ValueState)
-> MethodState -> Focusing Identity (r (Value r)) MethodState
Lens' MethodState ValueState
lensMStoVS SValue r
v'
  Doc -> Terminator -> MSStatement r
forall (r :: * -> *).
RenderStatement r =>
Doc -> Terminator -> MSStatement r
stmtFromData (r (Variable r) -> r (Value r) -> Doc
forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Value r) -> Doc
R.assign r (Variable r)
vr r (Value r)
v) Terminator
t

subAssign :: (CommonRenderSym r) => Terminator -> SVariable r -> SValue r -> 
  MSStatement r
subAssign :: forall (r :: * -> *).
CommonRenderSym r =>
Terminator -> SVariable r -> SValue r -> MSStatement r
subAssign Terminator
t SVariable r
vr' SValue r
v' = do 
  r (Variable r)
vr <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Variable r)) ValueState)
-> MethodState -> Focusing Identity (r (Variable r)) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable r
vr'
  r (Value r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Value r)) ValueState)
-> MethodState -> Focusing Identity (r (Value r)) MethodState
Lens' MethodState ValueState
lensMStoVS SValue r
v'
  Doc -> Terminator -> MSStatement r
forall (r :: * -> *).
RenderStatement r =>
Doc -> Terminator -> MSStatement r
stmtFromData (r (Variable r) -> r (Value r) -> Doc
forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Value r) -> Doc
R.subAssign r (Variable r)
vr r (Value r)
v) Terminator
t

increment :: (CommonRenderSym r) => SVariable r -> SValue r -> MSStatement r
increment :: forall (r :: * -> *).
CommonRenderSym r =>
SVariable r -> SValue r -> MSStatement r
increment SVariable r
vr' SValue r
v'= do 
  r (Variable r)
vr <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Variable r)) ValueState)
-> MethodState -> Focusing Identity (r (Variable r)) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable r
vr'
  r (Value r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Value r)) ValueState)
-> MethodState -> Focusing Identity (r (Value r)) MethodState
Lens' MethodState ValueState
lensMStoVS SValue r
v'
  Doc -> MSStatement r
forall (r :: * -> *). CommonRenderSym r => Doc -> MSStatement r
mkStmt (Doc -> MSStatement r) -> Doc -> MSStatement r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> r (Value r) -> Doc
forall (r :: * -> *).
CommonRenderSym r =>
r (Variable r) -> r (Value r) -> Doc
R.addAssign r (Variable r)
vr r (Value r)
v

objDecNew :: (OORenderSym r) => SVariable r -> r (Scope r) -> [SValue r]
  -> MSStatement r
objDecNew :: forall (r :: * -> *).
OORenderSym r =>
SVariable r -> r (Scope r) -> [SValue r] -> MSStatement r
objDecNew SVariable r
v r (Scope r)
scp [SValue r]
vs = SVariable r
-> r (Scope r)
-> SValue r
-> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> r (Scope r) -> SValue r -> MSStatement r
IC.varDecDef SVariable r
v r (Scope r)
scp (PosCtorCall r
forall (r :: * -> *). OOValueExpression r => PosCtorCall r
newObj ((r (Variable r) -> r (Type r))
-> SVariable r -> StateT ValueState Identity (r (Type r))
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType SVariable r
v) [SValue r]
vs)

printList :: (CommonRenderSym r) => Integer -> SValue r -> (SValue r -> MSStatement r)
  -> (String -> MSStatement r) -> (String -> MSStatement r) -> MSStatement r
printList :: forall (r :: * -> *).
CommonRenderSym r =>
Integer
-> SValue r
-> (SValue r -> MSStatement r)
-> (ClassName -> MSStatement r)
-> (ClassName -> MSStatement r)
-> MSStatement r
printList Integer
n SValue r
v SValue r -> MSStatement r
prFn ClassName -> MSStatement r
prStrFn ClassName -> MSStatement r
prLnFn = [MSStatement r] -> MSStatement r
forall (r :: * -> *).
StatementSym r =>
[MSStatement r] -> MSStatement r
multi [ClassName -> MSStatement r
prStrFn ClassName
"[", 
  MSStatement r
-> SValue r -> MSStatement r -> MSBody r -> MSStatement r
forall (r :: * -> *).
ControlStatement r =>
MSStatement r
-> SValue r -> MSStatement r -> MSBody r -> MSStatement r
IC.for (SVariable r -> r (Scope r) -> SValue r -> MSStatement r
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> r (Scope r) -> SValue r -> MSStatement r
IC.varDecDef SVariable r
i r (Scope r)
forall (r :: * -> *). ScopeSym r => r (Scope r)
IC.local (Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0)) 
    (SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< (SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.listSize SValue r
v SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#- Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
1)) (SVariable r
i &++) 
    ([MSStatement r] -> MSBody r
forall (r :: * -> *). BodySym r => [MSStatement r] -> MSBody r
bodyStatements [SValue r -> MSStatement r
prFn (SValue r -> SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
IC.listAccess SValue r
v (SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
i)), ClassName -> MSStatement r
prStrFn ClassName
", "]), 
  [(SValue r, MSBody r)] -> MSStatement r
forall (r :: * -> *).
ControlStatement r =>
[(SValue r, MSBody r)] -> MSStatement r
ifNoElse [(SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.listSize SValue r
v SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?> Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0, MSStatement r -> MSBody r
forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner (MSStatement r -> MSBody r) -> MSStatement r -> MSBody r
forall a b. (a -> b) -> a -> b
$
    SValue r -> MSStatement r
prFn (SValue r -> SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
IC.listAccess SValue r
v (SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.listSize SValue r
v SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#- Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
1)))], 
  ClassName -> MSStatement r
prLnFn ClassName
"]"]
  where l_i :: ClassName
l_i = ClassName
"list_i" ClassName -> ClassName -> ClassName
forall a. [a] -> [a] -> [a]
++ Integer -> ClassName
forall a. Show a => a -> ClassName
show Integer
n
        i :: SVariable r
i = ClassName -> VSType r -> SVariable r
forall (r :: * -> *).
VariableSym r =>
ClassName -> VSType r -> SVariable r
IC.var ClassName
l_i VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.int

printSet :: (CommonRenderSym r) => Integer -> SValue r -> (SValue r -> MSStatement r)
  -> (String -> MSStatement r) -> (String -> MSStatement r) -> VSType r -> MSStatement r
printSet :: forall (r :: * -> *).
CommonRenderSym r =>
Integer
-> SValue r
-> (SValue r -> MSStatement r)
-> (ClassName -> MSStatement r)
-> (ClassName -> MSStatement r)
-> VSType r
-> MSStatement r
printSet Integer
n SValue r
v SValue r -> MSStatement r
prFn ClassName -> MSStatement r
prStrFn ClassName -> MSStatement r
prLnFn VSType r
s = [MSStatement r] -> MSStatement r
forall (r :: * -> *).
StatementSym r =>
[MSStatement r] -> MSStatement r
multi [ClassName -> MSStatement r
prStrFn ClassName
"{ ", 
  SVariable r -> SValue r -> MSBody r -> MSStatement r
forall (r :: * -> *).
ControlStatement r =>
SVariable r -> SValue r -> MSBody r -> MSStatement r
IC.forEach SVariable r
i SValue r
v
    ([MSStatement r] -> MSBody r
forall (r :: * -> *). BodySym r => [MSStatement r] -> MSBody r
bodyStatements [SValue r -> MSStatement r
prFn (SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
i),ClassName -> MSStatement r
prStrFn ClassName
" "]),
  ClassName -> MSStatement r
prLnFn ClassName
"}"]
  where set_i :: ClassName
set_i = ClassName
"set_i" ClassName -> ClassName -> ClassName
forall a. [a] -> [a] -> [a]
++ Integer -> ClassName
forall a. Show a => a -> ClassName
show Integer
n
        i :: SVariable r
i = ClassName -> VSType r -> SVariable r
forall (r :: * -> *).
VariableSym r =>
ClassName -> VSType r -> SVariable r
IC.var ClassName
set_i VSType r
s

printObj :: ClassName -> (String -> MSStatement r) -> MSStatement r
printObj :: forall (r :: * -> *).
ClassName -> (ClassName -> MSStatement r) -> MSStatement r
printObj ClassName
n ClassName -> MSStatement r
prLnFn = ClassName -> MSStatement r
prLnFn (ClassName -> MSStatement r) -> ClassName -> MSStatement r
forall a b. (a -> b) -> a -> b
$ ClassName
"Instance of " ClassName -> ClassName -> ClassName
forall a. [a] -> [a] -> [a]
++ ClassName
n ClassName -> ClassName -> ClassName
forall a. [a] -> [a] -> [a]
++ ClassName
" object"

print :: (CommonRenderSym r) => Bool -> Maybe (SValue r) -> SValue r -> SValue r ->
  MSStatement r
print :: forall (r :: * -> *).
CommonRenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
print Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v = LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Value r)) ValueState)
-> MethodState -> Focusing Identity (r (Value r)) MethodState
Lens' MethodState ValueState
lensMStoVS SValue r
v StateT MethodState Identity (r (Value r))
-> (r (Value r) -> StateT MethodState Identity (r (Statement r)))
-> StateT MethodState Identity (r (Statement r))
forall a b.
StateT MethodState Identity a
-> (a -> StateT MethodState Identity b)
-> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CodeType -> StateT MethodState Identity (r (Statement r))
print' (CodeType -> StateT MethodState Identity (r (Statement r)))
-> (r (Value r) -> CodeType)
-> r (Value r)
-> StateT MethodState Identity (r (Statement r))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Type r) -> CodeType
forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType (r (Type r) -> CodeType)
-> (r (Value r) -> r (Type r)) -> r (Value r) -> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType
  where print' :: CodeType -> StateT MethodState Identity (r (Statement r))
print' (List CodeType
t) = Integer
-> SValue r
-> (SValue r -> StateT MethodState Identity (r (Statement r)))
-> (ClassName -> StateT MethodState Identity (r (Statement r)))
-> (ClassName -> StateT MethodState Identity (r (Statement r)))
-> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
CommonRenderSym r =>
Integer
-> SValue r
-> (SValue r -> MSStatement r)
-> (ClassName -> MSStatement r)
-> (ClassName -> MSStatement r)
-> MSStatement r
printList (Integer -> CodeType -> Integer
getNestDegree Integer
1 CodeType
t) SValue r
v SValue r -> StateT MethodState Identity (r (Statement r))
prFn ClassName -> StateT MethodState Identity (r (Statement r))
prStrFn 
          ClassName -> StateT MethodState Identity (r (Statement r))
prLnFn
        print' (Object ClassName
n) = ClassName
-> (ClassName -> StateT MethodState Identity (r (Statement r)))
-> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
ClassName -> (ClassName -> MSStatement r) -> MSStatement r
printObj ClassName
n ClassName -> StateT MethodState Identity (r (Statement r))
prLnFn
        print' (Set CodeType
t) = Integer
-> SValue r
-> (SValue r -> StateT MethodState Identity (r (Statement r)))
-> (ClassName -> StateT MethodState Identity (r (Statement r)))
-> (ClassName -> StateT MethodState Identity (r (Statement r)))
-> VSType r
-> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
CommonRenderSym r =>
Integer
-> SValue r
-> (SValue r -> MSStatement r)
-> (ClassName -> MSStatement r)
-> (ClassName -> MSStatement r)
-> VSType r
-> MSStatement r
printSet (Integer -> CodeType -> Integer
getNestDegree Integer
1 CodeType
t) SValue r
v SValue r -> StateT MethodState Identity (r (Statement r))
prFn ClassName -> StateT MethodState Identity (r (Statement r))
prStrFn ClassName -> StateT MethodState Identity (r (Statement r))
prLnFn (CodeType -> VSType r
forall (r :: * -> *). TypeSym r => CodeType -> VSType r
convType CodeType
t)
        print' CodeType
_ = Bool
-> Maybe (SValue r)
-> SValue r
-> SValue r
-> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
InternalIOStmt r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
S.printSt Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v
        prFn :: SValue r -> StateT MethodState Identity (r (Statement r))
prFn = (SValue r -> StateT MethodState Identity (r (Statement r)))
-> (SValue r
    -> SValue r -> StateT MethodState Identity (r (Statement r)))
-> Maybe (SValue r)
-> SValue r
-> StateT MethodState Identity (r (Statement r))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SValue r -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *). IOStatement r => SValue r -> MSStatement r
IC.print SValue r
-> SValue r -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
IOStatement r =>
SValue r -> SValue r -> MSStatement r
printFile Maybe (SValue r)
f
        prStrFn :: ClassName -> StateT MethodState Identity (r (Statement r))
prStrFn = (ClassName -> StateT MethodState Identity (r (Statement r)))
-> (SValue r
    -> ClassName -> StateT MethodState Identity (r (Statement r)))
-> Maybe (SValue r)
-> ClassName
-> StateT MethodState Identity (r (Statement r))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ClassName -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *). IOStatement r => ClassName -> MSStatement r
printStr SValue r
-> ClassName -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
IOStatement r =>
SValue r -> ClassName -> MSStatement r
printFileStr Maybe (SValue r)
f
        prLnFn :: ClassName -> StateT MethodState Identity (r (Statement r))
prLnFn = if Bool
newLn then (ClassName -> StateT MethodState Identity (r (Statement r)))
-> (SValue r
    -> ClassName -> StateT MethodState Identity (r (Statement r)))
-> Maybe (SValue r)
-> ClassName
-> StateT MethodState Identity (r (Statement r))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ClassName -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *). IOStatement r => ClassName -> MSStatement r
printStrLn SValue r
-> ClassName -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
IOStatement r =>
SValue r -> ClassName -> MSStatement r
printFileStrLn Maybe (SValue r)
f else (ClassName -> StateT MethodState Identity (r (Statement r)))
-> (SValue r
    -> ClassName -> StateT MethodState Identity (r (Statement r)))
-> Maybe (SValue r)
-> ClassName
-> StateT MethodState Identity (r (Statement r))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe 
          ClassName -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *). IOStatement r => ClassName -> MSStatement r
printStr SValue r
-> ClassName -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *).
IOStatement r =>
SValue r -> ClassName -> MSStatement r
printFileStr Maybe (SValue r)
f 

closeFile :: (OORenderSym r) => Label -> SValue r -> MSStatement r
closeFile :: forall (r :: * -> *).
OORenderSym r =>
ClassName -> SValue r -> MSStatement r
closeFile ClassName
n SValue r
f = SValue r -> MSStatement r
forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
IC.valStmt (SValue r -> MSStatement r) -> SValue r -> MSStatement r
forall a b. (a -> b) -> a -> b
$ VSType r -> SValue r -> ClassName -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> ClassName -> SValue r
objMethodCallNoParams VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.void SValue r
f ClassName
n

returnStmt :: (CommonRenderSym r) => Terminator -> SValue r -> MSStatement r
returnStmt :: forall (r :: * -> *).
CommonRenderSym r =>
Terminator -> SValue r -> MSStatement r
returnStmt Terminator
t SValue r
v' = do 
  r (Value r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Value r)) ValueState)
-> MethodState -> Focusing Identity (r (Value r)) MethodState
Lens' MethodState ValueState
lensMStoVS SValue r
v'
  Doc -> Terminator -> MSStatement r
forall (r :: * -> *).
RenderStatement r =>
Doc -> Terminator -> MSStatement r
stmtFromData ([r (Value r)] -> Doc
forall (r :: * -> *). CommonRenderSym r => [r (Value r)] -> Doc
R.return' [r (Value r)
v]) Terminator
t

valStmt :: (CommonRenderSym r) => Terminator -> SValue r -> MSStatement r
valStmt :: forall (r :: * -> *).
CommonRenderSym r =>
Terminator -> SValue r -> MSStatement r
valStmt Terminator
t SValue r
v' = do 
  r (Value r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Value r)) ValueState)
-> MethodState -> Focusing Identity (r (Value r)) MethodState
Lens' MethodState ValueState
lensMStoVS SValue r
v'
  Doc -> Terminator -> MSStatement r
forall (r :: * -> *).
RenderStatement r =>
Doc -> Terminator -> MSStatement r
stmtFromData (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v) Terminator
t

comment :: (CommonRenderSym r) => Doc -> Label -> MSStatement r
comment :: forall (r :: * -> *).
CommonRenderSym r =>
Doc -> ClassName -> MSStatement r
comment Doc
cs ClassName
c = Doc -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *). CommonRenderSym r => Doc -> MSStatement r
mkStmtNoEnd (ClassName -> Doc -> Doc
R.comment ClassName
c Doc
cs)

throw :: (CommonRenderSym r) => (r (Value r) -> Doc) -> Terminator -> Label -> 
  MSStatement r
throw :: forall (r :: * -> *).
CommonRenderSym r =>
(r (Value r) -> Doc) -> Terminator -> ClassName -> MSStatement r
throw r (Value r) -> Doc
f Terminator
t ClassName
l = do 
  r (Value r)
msg <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> StateT ValueState Identity (r (Value r))
-> StateT MethodState Identity (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Value r)) ValueState)
-> MethodState -> Focusing Identity (r (Value r)) MethodState
Lens' MethodState ValueState
lensMStoVS (ClassName -> StateT ValueState Identity (r (Value r))
forall (r :: * -> *). Literal r => ClassName -> SValue r
IC.litString ClassName
l)
  Doc -> Terminator -> MSStatement r
forall (r :: * -> *).
RenderStatement r =>
Doc -> Terminator -> MSStatement r
stmtFromData (r (Value r) -> Doc
f r (Value r)
msg) Terminator
t

newtype OptionalSpace = OSpace {OptionalSpace -> Doc
oSpace :: Doc}

defaultOptSpace :: OptionalSpace
defaultOptSpace :: OptionalSpace
defaultOptSpace = OSpace {oSpace :: Doc
oSpace = Doc
space}

optSpaceDoc :: OptionalSpace -> Doc
optSpaceDoc :: OptionalSpace -> Doc
optSpaceDoc OSpace {oSpace :: OptionalSpace -> Doc
oSpace = Doc
sp} = Doc
sp

-- ControlStatements --

-- 1st parameter is a Doc function to use on the render of each condition (i.e. parens)
-- 2nd parameter is the syntax for starting a block in an if-condition
-- 3rd parameter is the keyword for an else-if statement
-- 4th parameter is the syntax for ending a block in an if-condition
-- 5th parameter is the syntax for ending an if-statement
ifCond :: (CommonRenderSym r) => (Doc -> Doc) -> Doc -> OptionalSpace -> Doc -> Doc ->
  Doc -> [(SValue r, MSBody r)] -> MSBody r -> MSStatement r
ifCond :: forall (r :: * -> *).
CommonRenderSym r =>
(Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> Doc
-> [(SValue r, MSBody r)]
-> MSBody r
-> MSStatement r
ifCond Doc -> Doc
_ Doc
_ OptionalSpace
_ Doc
_ Doc
_ Doc
_ [] MSBody r
_ = ClassName -> StateT MethodState Identity (r (Statement r))
forall a. HasCallStack => ClassName -> a
error ClassName
"if condition created with no cases"
ifCond Doc -> Doc
f Doc
ifStart OptionalSpace
os Doc
elif Doc
bEnd Doc
ifEnd ((SValue r, MSBody r)
c:[(SValue r, MSBody r)]
cs) MSBody r
eBody =
    let ifSect :: (StateT ValueState Identity (r (Value r)),
 State MethodState (r (Body r)))
-> State MethodState Doc
ifSect (StateT ValueState Identity (r (Value r))
v, State MethodState (r (Body r))
b) = (r (Value r) -> r (Body r) -> Doc)
-> State MethodState (r (Value r))
-> State MethodState (r (Body r))
-> State MethodState Doc
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\r (Value r)
val r (Body r)
bd -> [Doc] -> Doc
vcat [
          Doc
ifLabel Doc -> Doc -> Doc
<+> Doc -> Doc
f (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
val) Doc -> Doc -> Doc
<> OptionalSpace -> Doc
optSpaceDoc OptionalSpace
os Doc -> Doc -> Doc
<> Doc
ifStart,
          Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
bd,
          Doc
bEnd]) (LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> StateT ValueState Identity (r (Value r))
-> State MethodState (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS StateT ValueState Identity (r (Value r))
v) State MethodState (r (Body r))
b
        elseIfSect :: (StateT ValueState Identity (r (Value r)),
 State MethodState (r (Body r)))
-> State MethodState Doc
elseIfSect (StateT ValueState Identity (r (Value r))
v, State MethodState (r (Body r))
b) = (r (Value r) -> r (Body r) -> Doc)
-> State MethodState (r (Value r))
-> State MethodState (r (Body r))
-> State MethodState Doc
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\r (Value r)
val r (Body r)
bd -> [Doc] -> Doc
vcat [
          Doc
elif Doc -> Doc -> Doc
<+> Doc -> Doc
f (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
val) Doc -> Doc -> Doc
<> OptionalSpace -> Doc
optSpaceDoc OptionalSpace
os Doc -> Doc -> Doc
<> Doc
ifStart,
          Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
bd,
          Doc
bEnd]) (LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> StateT ValueState Identity (r (Value r))
-> State MethodState (r (Value r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS StateT ValueState Identity (r (Value r))
v) State MethodState (r (Body r))
b
        elseSect :: State MethodState Doc
elseSect = (r (Body r) -> Doc) -> MSBody r -> State MethodState Doc
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (\r (Body r)
bd -> Doc -> Doc -> Doc
emptyIfEmpty (r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
bd) ([Doc] -> Doc
vcat [
          Doc
elseLabel Doc -> Doc -> Doc
<> OptionalSpace -> Doc
optSpaceDoc OptionalSpace
os Doc -> Doc -> Doc
<> Doc
ifStart,
          Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
bd,
          Doc
bEnd]) Doc -> Doc -> Doc
$+$ Doc
ifEnd) MSBody r
eBody
    in [State MethodState Doc] -> StateT MethodState Identity [Doc]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ((SValue r, MSBody r) -> State MethodState Doc
forall {r :: * -> *} {r :: * -> *}.
(ValueElim r, BodyElim r) =>
(StateT ValueState Identity (r (Value r)),
 State MethodState (r (Body r)))
-> State MethodState Doc
ifSect (SValue r, MSBody r)
c State MethodState Doc
-> [State MethodState Doc] -> [State MethodState Doc]
forall a. a -> [a] -> [a]
: ((SValue r, MSBody r) -> State MethodState Doc)
-> [(SValue r, MSBody r)] -> [State MethodState Doc]
forall a b. (a -> b) -> [a] -> [b]
map (SValue r, MSBody r) -> State MethodState Doc
forall {r :: * -> *} {r :: * -> *}.
(ValueElim r, BodyElim r) =>
(StateT ValueState Identity (r (Value r)),
 State MethodState (r (Body r)))
-> State MethodState Doc
elseIfSect [(SValue r, MSBody r)]
cs [State MethodState Doc]
-> [State MethodState Doc] -> [State MethodState Doc]
forall a. [a] -> [a] -> [a]
++ [State MethodState Doc
elseSect]) 
      StateT MethodState Identity [Doc]
-> ([Doc] -> StateT MethodState Identity (r (Statement r)))
-> StateT MethodState Identity (r (Statement r))
forall a b.
StateT MethodState Identity a
-> (a -> StateT MethodState Identity b)
-> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Doc -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *). CommonRenderSym r => Doc -> MSStatement r
mkStmtNoEnd (Doc -> StateT MethodState Identity (r (Statement r)))
-> ([Doc] -> Doc)
-> [Doc]
-> StateT MethodState Identity (r (Statement r))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
vcat)

tryCatch :: (CommonRenderSym r) => (r (Body r) -> r (Body r) -> Doc) -> MSBody r -> 
  MSBody r -> MSStatement r
tryCatch :: forall (r :: * -> *).
CommonRenderSym r =>
(r (Body r) -> r (Body r) -> Doc)
-> MSBody r -> MSBody r -> MSStatement r
tryCatch r (Body r) -> r (Body r) -> Doc
f = (r (Body r)
 -> r (Body r) -> StateT MethodState Identity (r (Statement r)))
-> StateT MethodState Identity (r (Body r))
-> StateT MethodState Identity (r (Body r))
-> StateT MethodState Identity (r (Statement r))
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
on2StateWrapped (\r (Body r)
tb1 r (Body r)
tb2 -> Doc -> StateT MethodState Identity (r (Statement r))
forall (r :: * -> *). CommonRenderSym r => Doc -> MSStatement r
mkStmtNoEnd (r (Body r) -> r (Body r) -> Doc
f r (Body r)
tb1 r (Body r)
tb2))

-- Methods --

construct :: (CommonRenderSym r) => Label -> MS (r (Type r))
construct :: forall (r :: * -> *).
CommonRenderSym r =>
ClassName -> MS (r (Type r))
construct ClassName
n = LensLike'
  (Zoomed (StateT ValueState Identity) (r (Type r)))
  MethodState
  ValueState
-> StateT ValueState Identity (r (Type r))
-> StateT MethodState Identity (r (Type r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Type r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Type r)) ValueState)
-> MethodState -> Focusing Identity (r (Type r)) MethodState
Lens' MethodState ValueState
lensMStoVS (StateT ValueState Identity (r (Type r))
 -> StateT MethodState Identity (r (Type r)))
-> StateT ValueState Identity (r (Type r))
-> StateT MethodState Identity (r (Type r))
forall a b. (a -> b) -> a -> b
$ CodeType
-> ClassName -> Doc -> StateT ValueState Identity (r (Type r))
forall (r :: * -> *).
RenderType r =>
CodeType -> ClassName -> Doc -> VSType r
typeFromData (ClassName -> CodeType
Object ClassName
n) ClassName
n Doc
empty

param :: (CommonRenderSym r) => (r (Variable r) -> Doc) -> SVariable r -> 
  MSParameter r
param :: forall (r :: * -> *).
CommonRenderSym r =>
(r (Variable r) -> Doc) -> SVariable r -> MSParameter r
param r (Variable r) -> Doc
f SVariable r
v' = do
  r (Variable r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Variable r)) ValueState)
-> MethodState -> Focusing Identity (r (Variable r)) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable r
v'
  let n :: ClassName
n = r (Variable r) -> ClassName
forall (r :: * -> *). VariableElim r => r (Variable r) -> ClassName
variableName r (Variable r)
v
  (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((MethodState -> MethodState) -> StateT MethodState Identity ())
-> (MethodState -> MethodState) -> StateT MethodState Identity ()
forall a b. (a -> b) -> a -> b
$ ClassName -> MethodState -> MethodState
addParameter ClassName
n
  (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((MethodState -> MethodState) -> StateT MethodState Identity ())
-> (MethodState -> MethodState) -> StateT MethodState Identity ()
forall a b. (a -> b) -> a -> b
$ ClassName -> MethodState -> MethodState
useVarName ClassName
n
  SVariable r -> Doc -> MSParameter r
forall (r :: * -> *).
RenderParam r =>
SVariable r -> Doc -> MSParameter r
paramFromData SVariable r
v' (Doc -> MSParameter r) -> Doc -> MSParameter r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> Doc
f r (Variable r)
v

method :: (OORenderSym r) => Label -> r (Visibility r) -> r (Permanence r) -> VSType r 
  -> [MSParameter r] -> MSBody r -> SMethod r
method :: forall (r :: * -> *).
OORenderSym r =>
ClassName
-> r (Visibility r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
method ClassName
n r (Visibility r)
s r (Permanence r)
p VSType r
t = Bool
-> ClassName
-> r (Visibility r)
-> r (Permanence r)
-> MSMthdType r
-> [StateT MethodState Identity (r (Parameter r))]
-> StateT MethodState Identity (r (Body r))
-> StateT MethodState Identity (r (Method r))
forall (r :: * -> *).
OORenderMethod r =>
Bool
-> ClassName
-> r (Visibility r)
-> r (Permanence r)
-> MSMthdType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
intMethod Bool
False ClassName
n r (Visibility r)
s r (Permanence r)
p (VSType r -> MSMthdType r
forall (r :: * -> *). MethodTypeSym r => VSType r -> MSMthdType r
mType VSType r
t)

getMethod :: (OORenderSym r) => SVariable r -> SMethod r
getMethod :: forall (r :: * -> *). OORenderSym r => SVariable r -> SMethod r
getMethod SVariable r
v = LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Variable r)) ValueState)
-> MethodState -> Focusing Identity (r (Variable r)) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable r
v StateT MethodState Identity (r (Variable r))
-> (r (Variable r) -> StateT MethodState Identity (r (Method r)))
-> StateT MethodState Identity (r (Method r))
forall a b.
StateT MethodState Identity a
-> (a -> StateT MethodState Identity b)
-> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\r (Variable r)
vr -> ClassName
-> r (Visibility r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> StateT MethodState Identity (r (Method r))
forall (r :: * -> *).
OOMethodSym r =>
ClassName
-> r (Visibility r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
IG.method (ClassName -> ClassName
getterName (ClassName -> ClassName) -> ClassName -> ClassName
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> ClassName
forall (r :: * -> *). VariableElim r => r (Variable r) -> ClassName
variableName 
  r (Variable r)
vr) r (Visibility r)
forall (r :: * -> *). VisibilitySym r => r (Visibility r)
public r (Permanence r)
forall (r :: * -> *). PermanenceSym r => r (Permanence r)
dynamic (r (Type r) -> VSType r
forall a s. a -> State s a
toState (r (Type r) -> VSType r) -> r (Type r) -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
vr) [] MSBody r
getBody)
  where getBody :: MSBody r
getBody = MSStatement r -> MSBody r
forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner (MSStatement r -> MSBody r) -> MSStatement r -> MSBody r
forall a b. (a -> b) -> a -> b
$ SValue r -> MSStatement r
forall (r :: * -> *).
ControlStatement r =>
SValue r -> MSStatement r
IC.returnStmt (SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf (SVariable r -> SValue r) -> SVariable r -> SValue r
forall a b. (a -> b) -> a -> b
$ SVariable r -> SVariable r
forall (r :: * -> *). OOVariableSym r => SVariable r -> SVariable r
IG.objVarSelf SVariable r
v)

setMethod :: (OORenderSym r) => SVariable r -> SMethod r
setMethod :: forall (r :: * -> *). OORenderSym r => SVariable r -> SMethod r
setMethod SVariable r
v = LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r (Variable r)) ValueState)
-> MethodState -> Focusing Identity (r (Variable r)) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable r
v StateT MethodState Identity (r (Variable r))
-> (r (Variable r) -> StateT MethodState Identity (r (Method r)))
-> StateT MethodState Identity (r (Method r))
forall a b.
StateT MethodState Identity a
-> (a -> StateT MethodState Identity b)
-> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\r (Variable r)
vr -> ClassName
-> r (Visibility r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> StateT MethodState Identity (r (Method r))
forall (r :: * -> *).
OOMethodSym r =>
ClassName
-> r (Visibility r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
IG.method (ClassName -> ClassName
setterName (ClassName -> ClassName) -> ClassName -> ClassName
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> ClassName
forall (r :: * -> *). VariableElim r => r (Variable r) -> ClassName
variableName 
  r (Variable r)
vr) r (Visibility r)
forall (r :: * -> *). VisibilitySym r => r (Visibility r)
public r (Permanence r)
forall (r :: * -> *). PermanenceSym r => r (Permanence r)
dynamic VSType r
forall (r :: * -> *). TypeSym r => VSType r
IC.void [SVariable r -> MSParameter r
forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
IC.param SVariable r
v] MSBody r
setBody)
  where setBody :: MSBody r
setBody = MSStatement r -> MSBody r
forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner (MSStatement r -> MSBody r) -> MSStatement r -> MSBody r
forall a b. (a -> b) -> a -> b
$ SVariable r -> SVariable r
forall (r :: * -> *). OOVariableSym r => SVariable r -> SVariable r
IG.objVarSelf SVariable r
v SVariable r -> SValue r -> MSStatement r
forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
v

initStmts :: (OORenderSym r) => Initializers r -> MSBody r
initStmts :: forall (r :: * -> *). OORenderSym r => Initializers r -> MSBody r
initStmts = [MSStatement r] -> MS (r (Body r))
forall (r :: * -> *). BodySym r => [MSStatement r] -> MSBody r
bodyStatements ([MSStatement r] -> MS (r (Body r)))
-> ([(VS (r (Variable r)), VS (r (Value r)))] -> [MSStatement r])
-> [(VS (r (Variable r)), VS (r (Value r)))]
-> MS (r (Body r))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((VS (r (Variable r)), VS (r (Value r))) -> MSStatement r)
-> [(VS (r (Variable r)), VS (r (Value r)))] -> [MSStatement r]
forall a b. (a -> b) -> [a] -> [b]
map (\(VS (r (Variable r))
vr, VS (r (Value r))
vl) -> VS (r (Variable r)) -> VS (r (Variable r))
forall (r :: * -> *). OOVariableSym r => SVariable r -> SVariable r
IG.objVarSelf VS (r (Variable r))
vr VS (r (Variable r)) -> VS (r (Value r)) -> MSStatement r
forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= VS (r (Value r))
vl)

function :: (OORenderSym r) => Label -> r (Visibility r) -> VSType r -> 
  [MSParameter r] -> MSBody r -> SMethod r
function :: forall (r :: * -> *).
OORenderSym r =>
ClassName
-> r (Visibility r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
function ClassName
n r (Visibility r)
s VSType r
t = Bool
-> ClassName
-> r (Visibility r)
-> r (Permanence r)
-> MSMthdType r
-> [StateT MethodState Identity (r (Parameter r))]
-> StateT MethodState Identity (r (Body r))
-> StateT MethodState Identity (r (Method r))
forall (r :: * -> *).
OORenderMethod r =>
Bool
-> ClassName
-> r (Visibility r)
-> r (Permanence r)
-> MSMthdType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
S.intFunc Bool
False ClassName
n r (Visibility r)
s r (Permanence r)
forall (r :: * -> *). PermanenceSym r => r (Permanence r)
static (VSType r -> MSMthdType r
forall (r :: * -> *). MethodTypeSym r => VSType r -> MSMthdType r
mType VSType r
t)
  
docFuncRepr :: (CommonRenderSym r) => FuncDocRenderer -> String -> [String] -> 
  [String] -> SMethod r -> SMethod r
docFuncRepr :: forall (r :: * -> *).
CommonRenderSym r =>
FuncDocRenderer
-> ClassName
-> [ClassName]
-> [ClassName]
-> SMethod r
-> SMethod r
docFuncRepr FuncDocRenderer
f ClassName
desc [ClassName]
pComms [ClassName]
rComms = MS (r (BlockComment r))
-> StateT MethodState Identity (r (Method r))
-> StateT MethodState Identity (r (Method r))
forall (r :: * -> *).
RenderMethod r =>
MS (r (BlockComment r)) -> SMethod r -> SMethod r
commentedFunc (State MethodState [ClassName] -> MS (r (BlockComment r))
forall a. State a [ClassName] -> State a (r (BlockComment r))
forall (r :: * -> *) a.
BlockCommentSym r =>
State a [ClassName] -> State a (r (BlockComment r))
docComment (State MethodState [ClassName] -> MS (r (BlockComment r)))
-> State MethodState [ClassName] -> MS (r (BlockComment r))
forall a b. (a -> b) -> a -> b
$ ([ClassName] -> [ClassName])
-> State MethodState [ClassName] -> State MethodState [ClassName]
forall a b s. (a -> b) -> State s a -> State s b
onStateValue 
  (\[ClassName]
ps -> FuncDocRenderer
f ClassName
desc ([ClassName] -> [ClassName] -> [(ClassName, ClassName)]
forall a b. [a] -> [b] -> [(a, b)]
zip [ClassName]
ps [ClassName]
pComms) [ClassName]
rComms) State MethodState [ClassName]
getParameters)

docFunc :: (CommonRenderSym r) => FuncDocRenderer -> String -> [String] -> 
  Maybe String -> SMethod r -> SMethod r
docFunc :: forall (r :: * -> *).
CommonRenderSym r =>
FuncDocRenderer
-> ClassName
-> [ClassName]
-> Maybe ClassName
-> SMethod r
-> SMethod r
docFunc FuncDocRenderer
f ClassName
desc [ClassName]
pComms Maybe ClassName
rComm = FuncDocRenderer
-> ClassName
-> [ClassName]
-> [ClassName]
-> StateT MethodState Identity (r (Method r))
-> StateT MethodState Identity (r (Method r))
forall (r :: * -> *).
CommonRenderSym r =>
FuncDocRenderer
-> ClassName
-> [ClassName]
-> [ClassName]
-> SMethod r
-> SMethod r
docFuncRepr FuncDocRenderer
f ClassName
desc [ClassName]
pComms (Maybe ClassName -> [ClassName]
forall a. Maybe a -> [a]
maybeToList Maybe ClassName
rComm)

-- Classes --

buildClass :: (OORenderSym r) =>  Maybe Label -> [CSStateVar r] -> 
  [SMethod r] -> [SMethod r] -> SClass r
buildClass :: forall (r :: * -> *).
OORenderSym r =>
Maybe ClassName
-> [CSStateVar r] -> [SMethod r] -> [SMethod r] -> SClass r
buildClass Maybe ClassName
p [CSStateVar r]
stVars [SMethod r]
constructors [SMethod r]
methods = do 
  ClassName
n <- LensLike'
  (Zoomed (StateT FileState Identity) ClassName) ClassState FileState
-> StateT FileState Identity ClassName
-> StateT ClassState Identity ClassName
forall c.
LensLike'
  (Zoomed (StateT FileState Identity) c) ClassState FileState
-> StateT FileState Identity c -> StateT ClassState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT FileState Identity) ClassName) ClassState FileState
(FileState -> Focusing Identity ClassName FileState)
-> ClassState -> Focusing Identity ClassName ClassState
Lens' ClassState FileState
lensCStoFS StateT FileState Identity ClassName
getModuleName
  ClassName
-> r (Visibility r)
-> r Doc
-> [CSStateVar r]
-> [SMethod r]
-> [SMethod r]
-> SClass r
forall (r :: * -> *).
RenderClass r =>
ClassName
-> r (Visibility r)
-> r Doc
-> [CSStateVar r]
-> [SMethod r]
-> [SMethod r]
-> SClass r
S.intClass ClassName
n r (Visibility r)
forall (r :: * -> *). VisibilitySym r => r (Visibility r)
public (Maybe ClassName -> r Doc
forall (r :: * -> *). RenderClass r => Maybe ClassName -> r Doc
inherit Maybe ClassName
p) [CSStateVar r]
stVars [SMethod r]
constructors [SMethod r]
methods

implementingClass :: (OORenderSym r) => Label -> [Label] -> [CSStateVar r] -> 
  [SMethod r] -> [SMethod r] -> SClass r
implementingClass :: forall (r :: * -> *).
OORenderSym r =>
ClassName
-> [ClassName]
-> [CSStateVar r]
-> [SMethod r]
-> [SMethod r]
-> SClass r
implementingClass ClassName
n [ClassName]
is = ClassName
-> r (Visibility r)
-> r Doc
-> [StateT ClassState Identity (r (StateVar r))]
-> [StateT MethodState Identity (r (Method r))]
-> [StateT MethodState Identity (r (Method r))]
-> StateT ClassState Identity (r (Class r))
forall (r :: * -> *).
RenderClass r =>
ClassName
-> r (Visibility r)
-> r Doc
-> [CSStateVar r]
-> [SMethod r]
-> [SMethod r]
-> SClass r
S.intClass ClassName
n r (Visibility r)
forall (r :: * -> *). VisibilitySym r => r (Visibility r)
public ([ClassName] -> r Doc
forall (r :: * -> *). RenderClass r => [ClassName] -> r Doc
implements [ClassName]
is)

docClass :: (OORenderSym r) => ClassDocRenderer -> String -> SClass r -> SClass r
docClass :: forall (r :: * -> *).
OORenderSym r =>
ClassDocRenderer -> ClassName -> SClass r -> SClass r
docClass ClassDocRenderer
cdr ClassName
d = CS (r (BlockComment r))
-> StateT ClassState Identity (r (Class r))
-> StateT ClassState Identity (r (Class r))
forall (r :: * -> *).
RenderClass r =>
CS (r (BlockComment r)) -> SClass r -> SClass r
S.commentedClass (State ClassState [ClassName] -> CS (r (BlockComment r))
forall a. State a [ClassName] -> State a (r (BlockComment r))
forall (r :: * -> *) a.
BlockCommentSym r =>
State a [ClassName] -> State a (r (BlockComment r))
docComment (State ClassState [ClassName] -> CS (r (BlockComment r)))
-> State ClassState [ClassName] -> CS (r (BlockComment r))
forall a b. (a -> b) -> a -> b
$ [ClassName] -> State ClassState [ClassName]
forall a s. a -> State s a
toState ([ClassName] -> State ClassState [ClassName])
-> [ClassName] -> State ClassState [ClassName]
forall a b. (a -> b) -> a -> b
$ ClassDocRenderer
cdr ClassName
d)

commentedClass :: (OORenderSym r, Monad r) => CS (r (BlockComment r)) -> SClass r 
  -> CS (r Doc)
commentedClass :: forall (r :: * -> *).
(OORenderSym r, Monad r) =>
CS (r (BlockComment r)) -> SClass r -> CS (r Doc)
commentedClass = (r (BlockComment r) -> r (Class r) -> r Doc)
-> StateT ClassState Identity (r (BlockComment r))
-> StateT ClassState Identity (r (Class r))
-> StateT ClassState Identity (r Doc)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\r (BlockComment r)
cmt r (Class r)
cs -> Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc) -> Doc -> r Doc
forall a b. (a -> b) -> a -> b
$ Doc -> Doc -> Doc
R.commentedItem 
  (r (BlockComment r) -> Doc
forall (r :: * -> *).
BlockCommentElim r =>
r (BlockComment r) -> Doc
RC.blockComment' r (BlockComment r)
cmt) (r (Class r) -> Doc
forall (r :: * -> *). ClassElim r => r (Class r) -> Doc
RC.class' r (Class r)
cs))

-- Modules --

modFromData :: Label -> (Doc -> r (Module r)) -> FS Doc -> FSModule r
modFromData :: forall (r :: * -> *).
ClassName -> (Doc -> r (Module r)) -> FS Doc -> FSModule r
modFromData ClassName
n Doc -> r (Module r)
f FS Doc
d = (FileState -> FileState) -> StateT FileState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (ClassName -> FileState -> FileState
setModuleName ClassName
n) StateT FileState Identity ()
-> StateT FileState Identity (r (Module r))
-> StateT FileState Identity (r (Module r))
forall a b.
StateT FileState Identity a
-> StateT FileState Identity b -> StateT FileState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Doc -> r (Module r))
-> FS Doc -> StateT FileState Identity (r (Module r))
forall a b s. (a -> b) -> State s a -> State s b
onStateValue Doc -> r (Module r)
f FS Doc
d

-- Files --

fileDoc :: (OORenderSym r) => String -> (r (Module r) -> r (Block r)) -> 
  r (Block r) -> FSModule r -> SFile r
fileDoc :: forall (r :: * -> *).
OORenderSym r =>
ClassName
-> (r (Module r) -> r (Block r))
-> r (Block r)
-> FSModule r
-> SFile r
fileDoc ClassName
ext r (Module r) -> r (Block r)
topb r (Block r)
botb FSModule r
mdl = do
  r (Module r)
m <- FSModule r
mdl
  ClassName
nm <- StateT FileState Identity ClassName
getModuleName
  let fp :: ClassName
fp = ClassName -> ClassName -> ClassName
addExt ClassName
ext ClassName
nm
      updm :: r (Module r)
updm = (Doc -> Doc) -> r (Module r) -> r (Module r)
forall (r :: * -> *).
RenderMod r =>
(Doc -> Doc) -> r (Module r) -> r (Module r)
updateModuleDoc (\Doc
d -> Doc -> Doc -> Doc
emptyIfEmpty Doc
d 
        (Doc -> Doc -> Doc -> Doc
R.file (r (Block r) -> Doc
forall (r :: * -> *). BlockElim r => r (Block r) -> Doc
RC.block (r (Block r) -> Doc) -> r (Block r) -> Doc
forall a b. (a -> b) -> a -> b
$ r (Module r) -> r (Block r)
topb r (Module r)
m) Doc
d (r (Block r) -> Doc
forall (r :: * -> *). BlockElim r => r (Block r) -> Doc
RC.block r (Block r)
botb))) r (Module r)
m
  ClassName -> FSModule r -> SFile r
forall (r :: * -> *).
RenderFile r =>
ClassName -> FSModule r -> SFile r
S.fileFromData ClassName
fp (r (Module r) -> FSModule r
forall a s. a -> State s a
toState r (Module r)
updm)

-- | Generates a file for a documented module.
--   mdr is a function that takes description, author, and module name and 
--                                                     returns a doc comment
--   e is the file extension
--   d is the description (I think)
--   a is a list of authors
--   dt is the date
--   fl is the file
docMod :: (OORenderSym r) => ModuleDocRenderer -> String -> String -> 
  [String] -> String -> SFile r -> SFile r
docMod :: forall (r :: * -> *).
OORenderSym r =>
ModuleDocRenderer
-> ClassName
-> ClassName
-> [ClassName]
-> ClassName
-> SFile r
-> SFile r
docMod ModuleDocRenderer
mdr ClassName
e ClassName
d [ClassName]
a ClassName
dt SFile r
fl = SFile r -> FS (r (BlockComment r)) -> SFile r
forall (r :: * -> *).
RenderFile r =>
SFile r -> FS (r (BlockComment r)) -> SFile r
commentedMod SFile r
fl (State FileState [ClassName] -> FS (r (BlockComment r))
forall a. State a [ClassName] -> State a (r (BlockComment r))
forall (r :: * -> *) a.
BlockCommentSym r =>
State a [ClassName] -> State a (r (BlockComment r))
docComment (State FileState [ClassName] -> FS (r (BlockComment r)))
-> State FileState [ClassName] -> FS (r (BlockComment r))
forall a b. (a -> b) -> a -> b
$ ModuleDocRenderer
mdr ClassName
d [ClassName]
a ClassName
dt ClassDocRenderer -> (ClassName -> ClassName) -> ClassDocRenderer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClassName -> ClassName -> ClassName
addExt ClassName
e 
  ClassDocRenderer
-> StateT FileState Identity ClassName
-> State FileState [ClassName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StateT FileState Identity ClassName
getModuleName)

fileFromData :: (OORenderSym r) => (FilePath -> r (Module r) -> r (File r)) 
  -> FilePath -> FSModule r -> SFile r
fileFromData :: forall (r :: * -> *).
OORenderSym r =>
(ClassName -> r (Module r) -> r (File r))
-> ClassName -> FSModule r -> SFile r
fileFromData ClassName -> r (Module r) -> r (File r)
f ClassName
fpath FSModule r
mdl' = do
  -- Add this file to list of files as long as it is not empty
  r (Module r)
mdl <- FSModule r
mdl'
  (FileState -> FileState) -> StateT FileState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\FileState
s -> if Doc -> Bool
isEmpty (r (Module r) -> Doc
forall (r :: * -> *). ModuleElim r => r (Module r) -> Doc
RC.module' r (Module r)
mdl) 
    then FileState
s
    else ASetter FileState FileState GOOLState GOOLState
-> (GOOLState -> GOOLState) -> FileState -> FileState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter FileState FileState GOOLState GOOLState
Lens' FileState GOOLState
lensFStoGS (FileType -> ClassName -> GOOLState -> GOOLState
addFile (FileState
s FileState -> Getting FileType FileState FileType -> FileType
forall s a. s -> Getting a s a -> a
^. Getting FileType FileState FileType
Lens' FileState FileType
currFileType) ClassName
fpath) (FileState -> FileState) -> FileState -> FileState
forall a b. (a -> b) -> a -> b
$ 
      -- If this is the main source file, set it as the main module in the state
      if FileState
s FileState -> Getting Bool FileState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool FileState Bool
Lens' FileState Bool
currMain Bool -> Bool -> Bool
&& FileType -> Bool
isSource (FileState
s FileState -> Getting FileType FileState FileType -> FileType
forall s a. s -> Getting a s a -> a
^. Getting FileType FileState FileType
Lens' FileState FileType
currFileType) 
        then ASetter FileState FileState GOOLState GOOLState
-> (GOOLState -> GOOLState) -> FileState -> FileState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter FileState FileState GOOLState GOOLState
Lens' FileState GOOLState
lensFStoGS (ClassName -> GOOLState -> GOOLState
setMainMod ClassName
fpath) FileState
s
        else FileState
s)
  r (File r) -> SFile r
forall a. a -> StateT FileState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (r (File r) -> SFile r) -> r (File r) -> SFile r
forall a b. (a -> b) -> a -> b
$ ClassName -> r (Module r) -> r (File r)
f ClassName
fpath r (Module r)
mdl

-- Helper functions

setEmpty :: (CommonRenderSym r) => MSStatement r -> MSStatement r
setEmpty :: forall (r :: * -> *).
CommonRenderSym r =>
MSStatement r -> MSStatement r
setEmpty MSStatement r
s' = MSStatement r
s' MSStatement r
-> (r (Statement r) -> MSStatement r) -> MSStatement r
forall a b.
StateT MethodState Identity a
-> (a -> StateT MethodState Identity b)
-> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Doc -> MSStatement r
forall (r :: * -> *). CommonRenderSym r => Doc -> MSStatement r
mkStmtNoEnd (Doc -> MSStatement r)
-> (r (Statement r) -> Doc) -> r (Statement r) -> MSStatement r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement