@@ -15,7 +15,7 @@ import Idris.Primitives
1515import Idris.Inliner
1616import Idris.PartialEval
1717import Idris.DeepSeq
18−import Idris.Output (iputStrLn, pshow, iWarn)
18+import Idris.Output (iputStrLn, pshow, iWarn, sendHighlighting)
1919import IRTS.Lang
2020
2121import Idris.Elab.Type
@@ -54,18 +54,22 @@ data MArgTy = IA Name | EA Name | CA deriving Show
5454
5555elabClass :: ElabInfo -> SyntaxInfo -> Docstring (Either Err PTerm) ->
5656 FC -> [(Name, PTerm)] ->
57− Name -> [(Name, PTerm)] -> [(Name, Docstring (Either Err PTerm))] ->
58− [Name] -> [PDecl] ->
59− Maybe Name {- ^ instance ctor name -} ->
57+ Name -> FC -> [(Name, FC, PTerm)] -> [(Name, Docstring (Either Err PTerm))] ->
58+ [(Name, FC)] {- ^ determining params -} ->
59+ [PDecl] {- ^ class body -} ->
60+ Maybe (Name, FC) {- ^ instance ctor name and location -} ->
6061 Docstring (Either Err PTerm) {- ^ instance ctor docs -} ->
6162 Idris ()
62−elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
63− = do let cn = fromMaybe (SN (InstanceCtorN tn)) mcn
64− let tty = pibind ps (PType fc)
63+elabClass info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
64+ = do let cn = fromMaybe (SN (InstanceCtorN tn)) (fst <$> mcn)
65+ let tty = pibind (map (\(n, _, ty) -> (n, ty)) ps) (PType fc)
6566 let constraint = PApp fc (PRef fc tn)
66− (map (pexp . PRef fc) (map fst ps))
67+ (map (pexp . PRef fc) (map (\(n, _, _) -> n) ps))
6768
68− let syn = syn_in { using = addToUsing (using syn_in) ps }
69+ let syn =
70+ syn_in { using = addToUsing (using syn_in)
71+ [(pn, pt) | (pn, _, pt) <- ps]
72+ }
6973
7074 -- build data declaration
7175 let mdecls = filter tydecl ds -- method declarations
@@ -77,10 +81,10 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
7781 defs <- mapM (defdecl (map (\ (x,y,z) -> z) ims) constraint)
7882 (filter clause ds)
7983 let (methods, imethods)
80− = unzip (map (\ ( x,y,z) -> (x, y)) ims)
84+ = unzip (map (\ (x, y, z) -> (x, y)) ims)
8185 let defaults = map (\ (x, (y, z)) -> (x,y)) defs
8286 -- build instance constructor type
83− let cty = impbind ps $ conbind constraints
87+ let cty = impbind [(pn, pt) | (pn, _, pt) <- ps] $ conbind constraints
8488 $ pibind (map (\ (n, ty) -> (nsroot n, ty)) methods)
8589 constraint
8690
@@ -91,8 +95,8 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
9195 -- Elaborate the data declaration
9296 elabData info (syn { no_imp = no_imp syn ++ mnames,
9397 imp_methods = mnames }) doc pDocs fc [] ddecl
94− dets <- findDets cn fds
95− addClass tn (CI cn (map nodoc imethods) defaults idecls (map fst ps) [] dets)
98+ dets <- findDets cn (map fst fds)
99+ addClass tn (CI cn (map nodoc imethods) defaults idecls (map (\(n, _, _) -> n) ps) [] dets)
96100
97101 -- for each constraint, build a top level function to chase it
98102 cfns <- mapM (cfun cn constraint syn (map fst imethods)) constraints
@@ -108,8 +112,16 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
108112 -- add the default definitions
109113 mapM_ (rec_elabDecl info EAll info) (concat (map (snd.snd) defs))
110114 addIBC (IBCClass tn)
115+
116+ sendHighlighting $
117+ [(tnfc, AnnName tn Nothing Nothing Nothing)] ++
118+ [(pnfc, AnnBoundName pn False) | (pn, pnfc, _) <- ps] ++
119+ [(fdfc, AnnBoundName fc False) | (fc, fdfc) <- fds] ++
120+ maybe [] (\(conN, conNFC) -> [(conNFC, AnnName conN Nothing Nothing Nothing)]) mcn
121+
111122 where
112− nodoc (n, (_, o, t)) = (n, (o, t))
123+ nodoc (n, (_, _, o, t)) = (n, (o, t))
124+
113125 pibind [] x = x
114126 pibind ((n, ty): ns) x = PPi expl n NoFC ty (pibind ns (chkUniq ty x))
115127
@@ -127,7 +139,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
127139
128140 -- TODO: probably should normalise
129141 checkDefaultSuperclassInstance :: PDecl -> Idris ()
130− checkDefaultSuperclassInstance (PInstance _ _ _ fc cs n ps _ _ _)
142+ checkDefaultSuperclassInstance (PInstance _ _ _ fc cs n _ ps _ _ _)
131143 = do when (not $ null cs) . tclift
132144 $ tfail (At fc (Msg $ "Default superclass instances can't have constraints."))
133145 i <- getIState
@@ -147,23 +159,24 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
147159
148160 getMName (PTy _ _ _ _ _ n nfc _) = nsroot n
149161 tdecl allmeths (PTy doc _ syn _ o n nfc t)
150− = do t' <- implicit' info syn (map fst ps ++ allmeths) n t
162+ = do t' <- implicit' info syn (map (\(n, _, _) -> n) ps ++ allmeths) n t
151163 logLvl 2 $ "Method " ++ show n ++ " : " ++ showTmImpls t'
152− return ( (n, (toExp (map fst ps) Exp t')),
153− (n, (doc, o, (toExp (map fst ps)
154− (\ l s p -> Imp l s p Nothing) t'))),
155− (n, (syn, o, t) ) )
164+ return ( (n, (toExp (map (\(pn, _, _) -> pn) ps) Exp t')),
165+ (n, (nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
166+ (\ l s p -> Imp l s p Nothing) t'))),
167+ (n, (nfc, syn, o, t) ) )
156168 tdecl _ _ = ifail "Not allowed in a class declaration"
157169
158170 -- Create default definitions
159171 defdecl mtys c d@(PClauses fc opts n cs) =
160172 case lookup n mtys of
161− Just (syn, o, ty) -> do let ty' = insertConstraint c ty
162− let ds = map (decorateid defaultdec)
163− [PTy emptyDocstring [] syn fc [] n NoFC ty',
164− PClauses fc (o ++ opts) n cs]
165− iLOG (show ds)
166− return (n, ((defaultdec n, ds!!1), ds))
173+ Just (nfc, syn, o, ty) ->
174+ do let ty' = insertConstraint c ty
175+ let ds = map (decorateid defaultdec)
176+ [PTy emptyDocstring [] syn fc [] n nfc ty',
177+ PClauses fc (o ++ opts) n cs]
178+ iLOG (show ds)
179+ return (n, ((defaultdec n, ds!!1), ds))
167180 _ -> ifail $ show n ++ " is not a method"
168181 defdecl _ _ _ = ifail "Can't happen (defdecl)"
169182
@@ -172,7 +185,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
172185
173186 tydecl (PTy _ _ _ _ _ _ _ _) = True
174187 tydecl _ = False
175− instdecl (PInstance _ _ _ _ _ _ _ _ _ _) = True
188+ instdecl (PInstance _ _ _ _ _ _ _ _ _ _ _) = True
176189 instdecl _ = False
177190 clause (PClauses _ _ _ _) = True
178191 clause _ = False
@@ -204,7 +217,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
204217
205218 -- Generate a top level function which looks up a method in a given
206219 -- dictionary (this is inlinable, always)
207− tfun cn c syn all (m, (doc, o, ty))
220+ tfun cn c syn all (m, (mfc, doc, o, ty))
208221 = do let ty' = expandMethNS syn (insertConstraint c ty)
209222 let mnames = take (length all) $ map (\x -> sMN x "meth") [0..]
210223 let capp = PApp fc (PRef fc cn) (map (pexp . PRef fc) mnames)
@@ -215,7 +228,7 @@ elabClass info syn_in doc fc constraints tn ps pDocs fds ds mcn cd
215228 logLvl 2 ("Top level type: " ++ showTmImpls ty')
216229 iLOG (show (m, ty', capp, margs))
217230 logLvl 2 ("Definition: " ++ showTmImpls lhs ++ " = " ++ showTmImpls rhs)
218− return [PTy doc [] syn fc o m NoFC ty',
231+ return [PTy doc [] syn fc o m mfc ty',
219232 PClauses fc [Inlinable] m [PClause fc m lhs [] rhs []]]
220233
221234 getMArgs (PPi (Imp _ _ _ _) n _ ty sc) = IA n : getMArgs sc
@@ -253,7 +266,7 @@ memberDocs (PTy d _ _ _ _ n _ _) = Just (basename n, d)
253266memberDocs (PPostulate _ d _ _ _ n _) = Just (basename n, d)
254267memberDocs (PData d _ _ _ _ pdata) = Just (basename $ d_name pdata, d)
255268memberDocs (PRecord d _ _ _ n _ _ _ _ _ _ _ ) = Just (basename n, d)
256−memberDocs (PClass d _ _ _ n _ _ _ _ _ _) = Just (basename n, d)
269+memberDocs (PClass d _ _ _ n _ _ _ _ _ _ _) = Just (basename n, d)
257270memberDocs _ = Nothing
258271
259272