Line No. | Rev | Author | Line |
---|---|---|---|
1 | 1 | paulosilva | |
2 | {-# LANGUAGE FlexibleContexts #-} | ||
3 | {-# OPTIONS_GHC -Wall #-} | ||
4 | |||
5 | ------------------------------------------------------------------------------- | ||
6 | |||
7 | {- | | ||
8 | Module : Language.Module.Verify | ||
9 | Description : Validation of the uniqueness of definitions and the existence | ||
10 | of references. | ||
11 | Copyright : (c) Paulo Silva | ||
12 | License : LGPL | ||
13 | |||
14 | Maintainer : paufil@di.uminho.pt | ||
15 | Stability : experimental | ||
16 | Portability : portable | ||
17 | |||
18 | -} | ||
19 | |||
20 | ------------------------------------------------------------------------------- | ||
21 | |||
22 | module Language.Module.Verify ( | ||
23 | verify | ||
24 | ) where | ||
25 | |||
26 | import Control.GalcError | ||
27 | import Control.Monad.Error | ||
28 | import Control.Monad.Reader | ||
29 | import Data.Env | ||
30 | import Language.Law.SyntaxADT | ||
31 | import qualified Language.Law.Verify as L | ||
32 | import Language.Module.SyntaxADT | ||
33 | import qualified Language.R.Verify as R | ||
34 | |||
35 | ------------------------------------------------------------------------------- | ||
36 | |||
37 | verify :: MonadError GalcError m => ModuleS -> m ModuleS | ||
38 | verify (ModuleS nm laws gcs defs) = let | ||
39 | defs' = concatMap R.getDefs defs | ||
40 | defg = concatMap R.getDefs gcs | ||
41 | defl = concatMap L.getDefs laws | ||
42 | intEnv = defs' ++ defg ++ defl | ||
43 | lname = R.reps . map getName $ laws | ||
44 | ids = R.reps . map fst $ intEnv | ||
45 | in if null ids && null lname | ||
46 | then runReaderT (do | ||
47 | lawsR <- mapM L.replaceDefs laws | ||
48 | gcsR <- mapM R.replaceDefs gcs | ||
49 | defsR <- mapM R.replaceDefs defs | ||
50 | return $ ModuleS nm lawsR gcsR defsR) $ | ||
51 | R.Env' {R.internal = fromListEnv intEnv, R.external = emptyEnv} | ||
52 | else if null lname then throwError $ aux ids | ||
53 | else throwError $ aux lname | ||
54 | where | ||
55 | aux = MultiDefError . concatMap ((++"\n") . show) | ||
56 | |||
57 | ------------------------------------------------------------------------------- |