@@ -14,7 +14,7 @@ import Idris.Primitives
14import Idris.Inliner
14import Idris.Inliner
15import Idris.PartialEval
15import Idris.PartialEval
16import Idris.DeepSeq
16import Idris.DeepSeq
17−import Idris.Output (iputStrLn, pshow, iWarn)
17+import Idris.Output (iputStrLn, pshow, iWarn, sendHighlighting)
18import IRTS.Lang
18import IRTS.Lang
20import Idris.ParseExpr (tryFullExpr)
20import Idris.ParseExpr (tryFullExpr)
@@ -37,21 +37,22 @@ elabRecord :: ElabInfo
37 -> (Docstring (Either Err PTerm)) -- ^ The documentation for the whole declaration
37 -> (Docstring (Either Err PTerm)) -- ^ The documentation for the whole declaration
38 -> SyntaxInfo -> FC -> DataOpts
38 -> SyntaxInfo -> FC -> DataOpts
39 -> Name -- ^ The name of the type being defined
39 -> Name -- ^ The name of the type being defined
40+ -> FC -- ^ The precise source location of the tycon name
40 -> [(Name, FC, Plicity, PTerm)] -- ^ Parameters
41 -> [(Name, FC, Plicity, PTerm)] -- ^ Parameters
41 -> [(Name, Docstring (Either Err PTerm))] -- ^ Parameter Docs
42 -> [(Name, Docstring (Either Err PTerm))] -- ^ Parameter Docs
42− -> [((Maybe Name), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -- ^ Fields
43+ -> [(Maybe (Name, FC), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -- ^ Fields
43− -> Maybe Name -- ^ Constructor Name
44+ -> Maybe (Name, FC) -- ^ Constructor Name
44 -> (Docstring (Either Err PTerm)) -- ^ Constructor Doc
45 -> (Docstring (Either Err PTerm)) -- ^ Constructor Doc
45 -> SyntaxInfo -- ^ Constructor SyntaxInfo
46 -> SyntaxInfo -- ^ Constructor SyntaxInfo
46 -> Idris ()
47 -> Idris ()
47−elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
48+elabRecord info doc rsyn fc opts tyn nfc params paramDocs fields cname cdoc csyn
48 = do logLvl 1 $ "Building data declaration for " ++ show tyn
49 = do logLvl 1 $ "Building data declaration for " ++ show tyn
49 -- Type constructor
50 -- Type constructor
50 let tycon = generateTyConType params
51 let tycon = generateTyConType params
51 logLvl 1 $ "Type constructor " ++ showTmImpls tycon
52 logLvl 1 $ "Type constructor " ++ showTmImpls tycon
53 -- Data constructor
54 -- Data constructor
54− dconName <- generateDConName cname
55+ dconName <- generateDConName (fmap fst cname)
55 let dconTy = generateDConType params fieldsWithNameAndDoc
56 let dconTy = generateDConType params fieldsWithNameAndDoc
56 logLvl 1 $ "Data constructor: " ++ showTmImpls dconTy
57 logLvl 1 $ "Data constructor: " ++ showTmImpls dconTy
@@ -62,7 +63,13 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
63 iLOG $ "fieldsWithName " ++ show fieldsWithName
64 iLOG $ "fieldsWithName " ++ show fieldsWithName
64 iLOG $ "fieldsWIthNameAndDoc " ++ show fieldsWithNameAndDoc
65 iLOG $ "fieldsWIthNameAndDoc " ++ show fieldsWithNameAndDoc
65− elabRecordFunctions info rsyn fc tyn [(n, p, t, d) | (n, _, p, t, d) <- paramsAndDoc] fieldsWithNameAndDoc dconName target
66+ elabRecordFunctions info rsyn fc tyn paramsAndDoc fieldsWithNameAndDoc dconName target
69+ [(nfc, AnnName tyn Nothing Nothing Nothing)] ++
70+ maybe [] (\(_, cnfc) -> [(cnfc, AnnName dconName Nothing Nothing Nothing)]) cname ++
71+ [(ffc, AnnBoundName fn False) | (fn, ffc, _, _, _) <- fieldsWithName]
67 -- | Generates a type constructor.
74 -- | Generates a type constructor.
68 generateTyConType :: [(Name, FC, Plicity, PTerm)] -> PTerm
75 generateTyConType :: [(Name, FC, Plicity, PTerm)] -> PTerm
@@ -81,9 +88,9 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
81 Nothing -> return n
88 Nothing -> return n
83 -- | Generates the data constructor type.
90 -- | Generates the data constructor type.
84− generateDConType :: [(Name, FC, Plicity, PTerm)] -> [(Name, Plicity, PTerm, a)] -> PTerm
91+ generateDConType :: [(Name, FC, Plicity, PTerm)] -> [(Name, FC, Plicity, PTerm, a)] -> PTerm
85 generateDConType ((n, nfc, _, t) : ps) as = PPi impl (nsroot n) NoFC t (generateDConType ps as)
92 generateDConType ((n, nfc, _, t) : ps) as = PPi impl (nsroot n) NoFC t (generateDConType ps as)
86− generateDConType [] ((n, p, t, _) : as) = PPi p (nsroot n) NoFC t (generateDConType [] as)
93+ generateDConType [] ((n, _, p, t, _) : as) = PPi p (nsroot n) NoFC t (generateDConType [] as)
87 generateDConType [] [] = target
94 generateDConType [] [] = target
89 -- | The target for the constructor and projection functions. Also the source of the update functions.
96 -- | The target for the constructor and projection functions. Also the source of the update functions.
@@ -104,42 +111,43 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
104 dconsArgDocs :: [(Name, Docstring (Either Err PTerm))]
111 dconsArgDocs :: [(Name, Docstring (Either Err PTerm))]
105 dconsArgDocs = paramDocs ++ (dcad fieldsWithName)
112 dconsArgDocs = paramDocs ++ (dcad fieldsWithName)
107− dcad :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Docstring (Either Err PTerm))]
114+ dcad :: [(Name, FC, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Docstring (Either Err PTerm))]
108− dcad ((n, _, _, (Just d)) : rest) = ((nsroot n), d) : (dcad rest)
115+ dcad ((n, _, _, _, (Just d)) : rest) = ((nsroot n), d) : (dcad rest)
109 dcad (_ : rest) = dcad rest
116 dcad (_ : rest) = dcad rest
110 dcad [] = []
117 dcad [] = []
112− fieldsWithName :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
119+ fieldsWithName :: [(Name, FC, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
113 fieldsWithName = fwn [] fields
120 fieldsWithName = fwn [] fields
115− fwn :: [Name] -> [(Maybe Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
122+ fwn :: [Name] -> [(Maybe (Name, FC), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, FC, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
116 fwn ns ((n, p, t, d) : rest)
123 fwn ns ((n, p, t, d) : rest)
117 = let nn = case n of
124 = let nn = case n of
118 Just n' -> n'
125 Just n' -> n'
119 Nothing -> newName ns baseName
126 Nothing -> newName ns baseName
127+ withNS = expandNS rsyn (fst nn)
120− in (expandNS rsyn $ nn, p, t, d) : (fwn (nn : ns) rest)
128+ in (withNS, snd nn, p, t, d) : (fwn (fst nn : ns) rest)
121 fwn _ _ = []
129 fwn _ _ = []
123− baseName = sUN "__pi_arg"
131+ baseName = (sUN "__pi_arg", NoFC)
125− newName :: [Name] -> Name -> Name
133+ newName :: [Name] -> (Name, FC) -> (Name, FC)
126− newName ns n
134+ newName ns (n, nfc)
127− | n `elem` ns = newName ns (nextName n)
135+ | n `elem` ns = newName ns (nextName n, nfc)
128− | otherwise = n
136+ | otherwise = (n, nfc)
130− fieldsWithNameAndDoc :: [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]
138+ fieldsWithNameAndDoc :: [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))]
131 fieldsWithNameAndDoc = fwnad fieldsWithName
139 fieldsWithNameAndDoc = fwnad fieldsWithName
133− fwnad :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]
141+ fwnad :: [(Name, FC, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))]
134− fwnad ((n, p, t, d) : rest)
142+ fwnad ((n, nfc, p, t, d) : rest)
135 = let doc = fromMaybe emptyDocstring d
143 = let doc = fromMaybe emptyDocstring d
136− in (n, p, t, doc) : (fwnad rest)
144+ in (n, nfc, p, t, doc) : (fwnad rest)
137 fwnad [] = []
145 fwnad [] = []
139elabRecordFunctions :: ElabInfo -> SyntaxInfo -> FC
147elabRecordFunctions :: ElabInfo -> SyntaxInfo -> FC
140 -> Name -- ^ Record type name
148 -> Name -- ^ Record type name
141− -> [(Name, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Parameters
149+ -> [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Parameters
142− -> [(Name, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Fields
150+ -> [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Fields
143 -> Name -- ^ Constructor Name
151 -> Name -- ^ Constructor Name
144 -> PTerm -- ^ Target type
152 -> PTerm -- ^ Target type
145 -> Idris ()
153 -> Idris ()
@@ -164,11 +172,11 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
165 -- The parameters for elaboration with their documentation
173 -- The parameters for elaboration with their documentation
166 -- Parameter functions are all prefixed with "param_".
174 -- Parameter functions are all prefixed with "param_".
167− let paramsForElab = [((nsroot n), (paramName n), impl, t, d) | (n, _, t, d) <- params] -- zipParams i params paramDocs]
175+ let paramsForElab = [((nsroot n), (paramName n), impl, t, d) | (n, _, _, t, d) <- params] -- zipParams i params paramDocs]
169 -- The fields (written by the user) with their documentation.
177 -- The fields (written by the user) with their documentation.
170− let userFieldsForElab = [((nsroot n), n, p, t, d) | (n, p, t, d) <- fields]
178+ let userFieldsForElab = [((nsroot n), n, p, t, d) | (n, nfc, p, t, d) <- fields]
172 -- All things we need to elaborate projection functions for, together with a number denoting their position in the constructor.
180 -- All things we need to elaborate projection functions for, together with a number denoting their position in the constructor.
173 let projectors = [(n, n', p, t, d, i) | ((n, n', p, t, d), i) <- zip (freeFieldsForElab ++ paramsForElab ++ userFieldsForElab) [0..]]
181 let projectors = [(n, n', p, t, d, i) | ((n, n', p, t, d), i) <- zip (freeFieldsForElab ++ paramsForElab ++ userFieldsForElab) [0..]]
174 -- Build and elaborate projection functions
182 -- Build and elaborate projection functions
@@ -189,10 +197,10 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
190 -- | Root names of all fields in the current record declarations
198 -- | Root names of all fields in the current record declarations
191 fieldNames :: [Name]
199 fieldNames :: [Name]
192− fieldNames = [nsroot n | (n, _, _, _) <- fields]
200+ fieldNames = [nsroot n | (n, _, _, _, _) <- fields]
194 paramNames :: [Name]
202 paramNames :: [Name]
195− paramNames = [nsroot n | (n, _, _, _) <- params]
203+ paramNames = [nsroot n | (n, _, _, _, _) <- params]
197 isFieldOrParam :: Name -> Bool
205 isFieldOrParam :: Name -> Bool
198 isFieldOrParam n = n `elem` (fieldNames ++ paramNames)
206 isFieldOrParam n = n `elem` (fieldNames ++ paramNames)
@@ -207,7 +215,7 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
207 isField' (n, _, _, _, _, _) = isField n
215 isField' (n, _, _, _, _, _) = isField n
209 fieldTerms :: [PTerm]
217 fieldTerms :: [PTerm]
210− fieldTerms = [t | (_, _, t, _) <- fields]
218+ fieldTerms = [t | (_, _, _, t, _) <- fields]
212 -- Delabs the TT to PTerm
220 -- Delabs the TT to PTerm
213 -- This is not good.
221 -- This is not good.
@@ -263,7 +271,7 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
264 -- | A map from a field name to the other fields it depends on.
272 -- | A map from a field name to the other fields it depends on.
265 fieldDependencies :: [(Name, [Name])]
273 fieldDependencies :: [(Name, [Name])]
266− fieldDependencies = map (uncurry fieldDep) [(n, t) | (n, _, t, _) <- fields ++ params]
274+ fieldDependencies = map (uncurry fieldDep) [(n, t) | (n, _, _, t, _) <- fields ++ params]
268 fieldDep :: Name -> PTerm -> (Name, [Name])
276 fieldDep :: Name -> PTerm -> (Name, [Name])
269 fieldDep n t = ((nsroot n), paramNames ++ fieldNames `intersect` allNamesIn t)
277 fieldDep n t = ((nsroot n), paramNames ++ fieldNames `intersect` allNamesIn t)