Checks.hs 2.21 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
Björn Peemöller 's avatar
Björn Peemöller committed
32
33
34
35
kindCheck :: [Decl] -> CompilerEnv -> ([Decl], CompilerEnv)
kindCheck decls env = (decls', env)
  where decls' = KC.kindCheck (moduleIdent env) (tyConsEnv env) decls

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

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

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

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

-- |Check for warnings.
58
59
warnCheck :: CompilerEnv -> [ImportDecl] -> [Decl] -> [Message]
warnCheck env = WC.warnCheck (moduleIdent env) (valueEnv env)