1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
module Check.AST.TopLevel.Signatures where
import Text.Pretty
import Curry.SpanInfo
import Curry.Span
import Curry.Position
import Curry.Types
import Curry.Ident
import Types
checkTopLevelSig :: Module a -> Int -> CSM ()
checkTopLevelSig e _ =
case e of
(Module _ _ _ _ _ decls) -> checkTopLevelSig' decls decls
_ -> return ()
checkTopLevelSig' :: [Decl a] -> [Decl a] -> CSM ()
checkTopLevelSig' [] _ = return ()
checkTopLevelSig' (decl:decls) allDecls =
case decl of
(FunctionDecl
(SpanInfo s _)
_ _ _) ->
do
pair <- checkPair decl allDecls
unlessM (pair)
( report (Message
s
( colorizeKey "type signature"
<+> text "missing")
( colorizeKey "top level functions"
<+> text "should have"
<+> colorizeKey "type signatures"
)
)
)
checkTopLevelSig' decls allDecls
_ ->
checkTopLevelSig' decls allDecls
checkPair :: Decl a -> [Decl a] -> CSM Bool
checkPair _ [] = return False
checkPair fD@(FunctionDecl
sIF
_
(Ident _ s _)
_) (decl:decls) =
case decl of
(TypeSig sIT i _) -> if (s == getIdentS (head i))
then do checkPos sIF sIT s
return True
else checkPair fD decls
_ -> checkPair fD decls
checkPos :: SpanInfo -> SpanInfo -> String -> CSM ()
checkPos (SpanInfo (Span (Position lF cF) eP) _)
(SpanInfo (Span _ (Position lT cT)) _)
s =
unlessM (lT == (lF-1))
(report (Message
(Span (Position lF cF) eP)
( colorizeKey "type signature" <+> text "wrong position")
( colorizeKey "type signature"
<+> text "of"
<+> colorizeKey s
<+> text "should be placed directly above its"
<+> colorizeKey "function declaration"
)
)
)
getIdentS :: Ident -> String
getIdentS (Ident _ s _) = s
|