Checks.hs 2.29 KB
Newer Older
Björn Peemöller 's avatar
Björn Peemöller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
{- |
    Module      :  $Header$
    Description :  Different checks on a Curry module
    Copyright   :  (c) 2011, Björn Peemöller (bjp@informatik.uni-kiel.de)
    License     :  OtherLicense

    Maintainer  :  bjp@informatik.uni-kiel.de
    Stability   :  experimental
    Portability :  portable

    This module subsumes the different checks to be performed on a Curry
    module during compilation, e.g. type checking.
-}
Björn Peemöller 's avatar
Björn Peemöller committed
14
15
16
17
18
module Checks where

import Curry.Base.MessageMonad (Message)
import Curry.Syntax

Björn Peemöller 's avatar
Björn Peemöller committed
19
20
21
22
23
import qualified Checks.KindCheck   as KC (kindCheck)
import qualified Checks.PrecCheck   as PC (precCheck)
import qualified Checks.SyntaxCheck as SC (syntaxCheck)
import qualified Checks.TypeCheck   as TC (typeCheck)
import qualified Checks.WarnCheck   as WC (warnCheck)
Björn Peemöller 's avatar
Björn Peemöller committed
24
25
26
27

import CompilerEnv
import CompilerOpts

Björn Peemöller 's avatar
Björn Peemöller committed
28
29
30
31
-- TODO: More documentation

-- |Check the kinds of type definitions and signatures.
-- In addition, nullary type constructors and type variables are dinstiguished
32
33
34
kindCheck :: Module -> CompilerEnv -> (Module, CompilerEnv)
kindCheck (Module m es is ds) env = (Module m es is ds', env)
  where ds' = KC.kindCheck (moduleIdent env) (tyConsEnv env) ds
Björn Peemöller 's avatar
Björn Peemöller committed
35

Björn Peemöller 's avatar
Björn Peemöller committed
36
37
-- |Apply the precendences of infix operators.
-- This function reanrranges the AST.
38
39
40
precCheck :: Module -> CompilerEnv -> (Module, CompilerEnv)
precCheck (Module m es is ds) env = (Module m es is ds', env { opPrecEnv = pEnv' })
  where (pEnv', ds') = PC.precCheck (moduleIdent env) (opPrecEnv env) ds
Björn Peemöller 's avatar
Björn Peemöller committed
41

Björn Peemöller 's avatar
Björn Peemöller committed
42
-- |Apply the syntax check.
43
44
45
46
syntaxCheck :: Options -> Module -> CompilerEnv -> (Module, CompilerEnv)
syntaxCheck opts (Module m es is ds) env = (Module m es is ds', env)
  where ds'     = SC.syntaxCheck withExt (moduleIdent env) (aliasEnv env)
                   (arityEnv env) (valueEnv env) (tyConsEnv env) ds
Björn Peemöller 's avatar
Björn Peemöller committed
47
48
        withExt = BerndExtension `elem` optExtensions opts

Björn Peemöller 's avatar
Björn Peemöller committed
49
-- |Apply the type check.
50
51
typeCheck :: Module -> CompilerEnv -> (Module, CompilerEnv)
typeCheck mdl@(Module _ _ _ ds) env = (mdl, env { tyConsEnv = tcEnv', valueEnv = tyEnv' })
Björn Peemöller 's avatar
Björn Peemöller committed
52
  where (tcEnv', tyEnv') = TC.typeCheck (moduleIdent env)
53
                              (tyConsEnv env) (valueEnv env) ds
Björn Peemöller 's avatar
Björn Peemöller committed
54

55
-- TODO: Which kind of warnings?
Björn Peemöller 's avatar
Björn Peemöller committed
56
57

-- |Check for warnings.
58
59
60
warnCheck :: Module -> CompilerEnv -> [Message]
warnCheck (Module _ _ is ds) env
  = WC.warnCheck (moduleIdent env) (valueEnv env) is ds