module Helium.Main.PhaseTypeInferencer (phaseTypeInferencer) where
import Helium.Main.CompileUtils
import Helium.StaticAnalysis.Messages.Warnings(Warning)
import Helium.StaticAnalysis.Inferencers.TypeInferencing(typeInferencing)
import Helium.ModuleSystem.DictionaryEnvironment (DictionaryEnvironment)
import Helium.StaticAnalysis.Messages.TypeErrors
import Helium.StaticAnalysis.Messages.Information (showInformation)
import System.FilePath.Posix
phaseTypeInferencer ::
String -> String -> Module -> ImportEnvironment -> ImportEnvironment -> [Option] ->
Phase TypeError (DictionaryEnvironment, ImportEnvironment, TypeEnvironment, [Warning])
phaseTypeInferencer basedir fullName module_ localEnv completeEnv options = do
enterNewPhase "Type inferencing" options
let newOptions = (if AlgorithmW `elem` options
then filter (/= NoSpreading) . ([TreeWalkInorderTopLastPost, SolverGreedy]++)
else id)
. (if AlgorithmM `elem` options
then filter (/= NoSpreading) . ([TreeWalkInorderTopFirstPre, SolverGreedy]++)
else id)
$ options
(debugIO, dictionaryEnv, toplevelTypes, typeErrors, warnings) =
typeInferencing newOptions completeEnv module_
finalEnv = addToTypeEnvironment toplevelTypes completeEnv
when (DumpTypeDebug `elem` options) debugIO
showInformation True options finalEnv
case typeErrors of
_:_ ->
do when (DumpInformationForAllModules `elem` options) $
putStr (show completeEnv)
return (Left typeErrors)
[] ->
do
when (DumpInformationForAllModules `elem` options) $
print finalEnv
when (HFullQualification `elem` options) $
writeFile (combinePathAndFile basedir (dropExtension $ takeFileName fullName) ++ ".fqn")
(holmesShowImpEnv module_ finalEnv)
when ( DumpInformationForThisModule `elem` options
&& DumpInformationForAllModules `notElem` options
)
$ print (addToTypeEnvironment toplevelTypes localEnv)
return (Right (dictionaryEnv, finalEnv, toplevelTypes, warnings))