Skip to content

Commit

Permalink
Merge pull request #65 from phischu/v0.5.3
Browse files Browse the repository at this point in the history
V0.5.3
  • Loading branch information
phischu committed Jun 28, 2015
2 parents f44eba9 + 494a30c commit 5986b61
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion haskell-names.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: haskell-names
Version: 0.5.2
Version: 0.5.3
License: BSD3
Author: Philipp Schuster, Roman Cheplyaka, Lennart Augustsson
Maintainer: Philipp Schuster
Expand Down
2 changes: 1 addition & 1 deletion hs-gen-iface/hs-gen-iface.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: hs-gen-iface
Version: 0.5.2
Version: 0.5.3
License: MIT
License-file: LICENSE
Author: Roman Cheplyaka
Expand Down
40 changes: 31 additions & 9 deletions src/Language/Haskell/Names/ModuleSymbols.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,10 @@ getTopDeclSymbols impTbl modulename d = (case d of
TypeFamDecl _ dh _ -> [declHeadSymbol TypeFam dh]

DataDecl _ dataOrNew _ dh qualConDecls _ -> declHeadSymbol (dataOrNewCon dataOrNew) dh : infos where
cons :: [(Name l,[Name l])]
cons = do -- list monad
QualConDecl _ _ _ conDecl <- qualConDecls
case conDecl of
ConDecl _ n _ -> return (n, [])
InfixConDecl _ _ n _ -> return (n, [])
RecDecl _ n fields ->
return (n , [f | FieldDecl _ fNames _ <- fields, f <- fNames])

dq = getDeclHeadName dh

infos = constructorsToInfos modulename dq cons
infos = constructorsToInfos modulename dq (qualConDeclNames qualConDecls)

GDataDecl _ dataOrNew _ dh _ gadtDecls _ -> declHeadSymbol (dataOrNewCon dataOrNew) dh : infos where
-- FIXME: We shouldn't create selectors for fields with existential type variables!
Expand Down Expand Up @@ -99,6 +91,15 @@ getTopDeclSymbols impTbl modulename d = (case d of

ForImp _ _ _ _ fn _ -> [ Value (sModuleName modulename) (sName fn)]

DataInsDecl _ _ typ qualConDecls _ -> constructorsToInfos modulename (typeOuterName typ) (qualConDeclNames qualConDecls)

GDataInsDecl _ _ typ _ gadtDecls _ -> constructorsToInfos modulename (typeOuterName typ) cons where
-- FIXME: We shouldn't create selectors for fields with existential type variables!
cons :: [(Name l,[Name l])]
cons = do -- list monad
GadtDecl _ cn (fromMaybe [] -> fields) _ty <- gadtDecls
return (cn , [f | FieldDecl _ fNames _ <- fields, f <- fNames])

_ -> [])
where
declHeadSymbol c dh = c (sModuleName modulename) (sName (getDeclHeadName dh))
Expand All @@ -122,5 +123,26 @@ constructorsToInfos modulename typename constructors = conInfos ++ selInfos wher
constructornames <- maybeToList (Map.lookup (nameToString selectorname) selectorsMap)
return (Selector (sModuleName modulename) (sName selectorname) (sName typename) (map sName constructornames))

typeOuterName :: Type l -> Name l
typeOuterName t = case t of
TyForall _ _ _ typ -> typeOuterName typ
TyApp _ typ _ -> typeOuterName typ
TyCon _ qname -> qNameToName qname
TyParen _ typ -> typeOuterName typ
TyInfix _ _ qname _ -> qNameToName qname
TyKind _ typ _ -> typeOuterName typ
TyBang _ _ typ -> typeOuterName typ
_ -> error "illegal data family in data instance"

qualConDeclNames :: [QualConDecl l] -> [(Name l,[Name l])]
qualConDeclNames qualConDecls = do
QualConDecl _ _ _ conDecl <- qualConDecls
case conDecl of
ConDecl _ n _ -> return (n, [])
InfixConDecl _ _ n _ -> return (n, [])
RecDecl _ n fields ->
return (n , [f | FieldDecl _ fNames _ <- fields, f <- fNames])


dataOrNewCon :: Syntax.DataOrNew l -> UnAnn.ModuleName -> UnAnn.Name -> Symbol
dataOrNewCon dataOrNew = case dataOrNew of DataType {} -> Data; Syntax.NewType {} -> NewType
2 changes: 2 additions & 0 deletions tests/exports/DataFamilies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ data family Vector a
class ListLike a where
type I a
h :: a -> I a

newtype instance Vector () = U_Vector ()
5 changes: 5 additions & 0 deletions tests/exports/DataFamilies.hs.golden
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
, symbolName = Ident "h"
, className = Ident "ListLike"
}
, Constructor
{ symbolModule = ModuleName "DataFamilies"
, symbolName = Ident "U_Vector"
, typeName = Ident "Vector"
}
]
2 changes: 1 addition & 1 deletion tests/run.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- vim:fdm=marker:foldtext=foldtext()
{-# LANGUAGE FlexibleInstances, OverlappingInstances, ImplicitParams,
MultiParamTypeClasses, FlexibleContexts #-}
MultiParamTypeClasses, FlexibleContexts, GADTs #-}
-- GHC 7.8 fails with the default context stack size of 20
{-# OPTIONS_GHC -fcontext-stack=50 #-}
-- Imports {{{
Expand Down

0 comments on commit 5986b61

Please sign in to comment.