module FreeC.Pass.DefineDeclPass ( defineTypeDeclsPass, defineFuncDeclsPass ) where
import Data.Maybe ( fromJust )
import FreeC.Environment.Entry
import FreeC.Environment.Renamer
import FreeC.IR.DependencyGraph
import qualified FreeC.IR.Syntax as IR
import FreeC.Monad.Converter
import FreeC.Pass.DependencyAnalysisPass
defineTypeDeclsPass :: DependencyAwarePass IR.TypeDecl
defineTypeDeclsPass component = do
mapComponentM_ (mapM defineTypeDecl) component
return component
defineFuncDeclsPass :: DependencyAwarePass IR.FuncDecl
defineFuncDeclsPass component = do
mapComponentM_ (mapM defineFuncDecl) component
return component
defineTypeDecl :: IR.TypeDecl -> Converter ()
defineTypeDecl (IR.TypeSynDecl srcSpan declIdent typeArgs typeExpr) = do
_ <- renameAndAddEntry TypeSynEntry
{ entrySrcSpan = srcSpan
, entryArity = length typeArgs
, entryTypeArgs = map IR.typeVarDeclIdent typeArgs
, entryTypeSyn = typeExpr
, entryName = IR.declIdentName declIdent
, entryIdent = undefined
, entryAgdaIdent = undefined
}
return ()
defineTypeDecl (IR.DataDecl srcSpan declIdent typeArgs conDecls) = do
_ <- renameAndAddEntry DataEntry
{ entrySrcSpan = srcSpan
, entryArity = length typeArgs
, entryName = IR.declIdentName declIdent
, entryConsNames = map IR.conDeclQName conDecls
, entryIdent = undefined
, entryAgdaIdent = undefined
}
mapM_ defineConDecl conDecls
where
returnType :: IR.Type
returnType = IR.typeConApp srcSpan (IR.declIdentName declIdent)
(map IR.typeVarDeclToType typeArgs)
defineConDecl :: IR.ConDecl -> Converter ()
defineConDecl (IR.ConDecl conSrcSpan conDeclIdent argTypes) = do
_ <- renameAndAddEntry ConEntry
{ entrySrcSpan = conSrcSpan
, entryArity = length argTypes
, entryTypeArgs = map IR.typeVarDeclIdent typeArgs
, entryArgTypes = argTypes
, entryReturnType = returnType
, entryName = IR.declIdentName conDeclIdent
, entryIdent = undefined
, entryAgdaIdent = undefined
, entrySmartIdent = undefined
, entryAgdaSmartIdent = undefined
}
return ()
defineFuncDecl :: IR.FuncDecl -> Converter ()
defineFuncDecl funcDecl = do
_ <- renameAndAddEntry FuncEntry
{ entrySrcSpan = IR.funcDeclSrcSpan funcDecl
, entryArity = length (IR.funcDeclArgs funcDecl)
, entryTypeArgs = map IR.typeVarDeclIdent
(IR.funcDeclTypeArgs funcDecl)
, entryArgTypes = map (fromJust . IR.varPatType)
(IR.funcDeclArgs funcDecl)
, entryStrictArgs = map IR.varPatIsStrict
(IR.funcDeclArgs funcDecl)
, entryReturnType = fromJust (IR.funcDeclReturnType funcDecl)
, entryNeedsFreeArgs = True
, entryEncapsulatesEffects = False
, entryEffects = []
, entryName = IR.funcDeclQName funcDecl
, entryIdent = undefined
, entryAgdaIdent = undefined
}
return ()