Sign.hs revision eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst SchulzModule : $Header$
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst SchulzDescription : CSMOF signature and sentences
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst SchulzCopyright : (c) Daniel Calegari Universidad de la Republica, Uruguay 2013
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst SchulzLicense : GPLv2 or higher, see LICENSE.txt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuMaintainer : dcalegar@fing.edu.uy
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst SchulzStability : provisional
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst SchulzPortability : portable
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzimport qualified Common.Lib.Rel as Rel
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzimport qualified Data.Map as Map
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzimport qualified Data.Set as Set
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzdata TypeKind = DataTypeKind | ClassKind deriving (Show, Eq, Ord)
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzinstance Pretty TypeKind where
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz pretty DataTypeKind = text "datatype"
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz pretty ClassKind = text "class"
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzdata TypeClass = TypeClass { name :: String, kind :: TypeKind } deriving (Show, Eq, Ord)
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzinstance Pretty TypeClass where
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz pretty (TypeClass nam _) = text nam
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulztype Role = String
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzdata PropertyT = PropertyT { sourceRole :: Role
905f3b47b556b438c9cc283743725cbbf85b4c7eEwaryst Schulz , sourceType :: TypeClass
905f3b47b556b438c9cc283743725cbbf85b4c7eEwaryst Schulz , targetRole :: Role
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz , targetType :: TypeClass
2747c08c70e4819273caf474946ff8e31d422cd4Ewaryst Schulz } deriving (Show, Eq, Ord)
2747c08c70e4819273caf474946ff8e31d422cd4Ewaryst Schulzinstance Pretty PropertyT where
2747c08c70e4819273caf474946ff8e31d422cd4Ewaryst Schulz pretty (PropertyT souR souT tarR tarT) = text "property" <> lparen <> text souR <+> colon <+> (pretty souT)
2747c08c70e4819273caf474946ff8e31d422cd4Ewaryst Schulz <+> comma <+> text tarR <+> colon <+> (pretty tarT) <> rparen
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzdata LinkT = LinkT { sourceVar :: Role
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz , targetVar :: Role
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz , property :: PropertyT
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz } deriving (Show, Eq, Ord)
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzinstance Pretty LinkT where
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz pretty (LinkT souV tarV pro) = text "link" <> lparen <> text souV <+> colon <+>
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz text (sourceRole pro) <+> colon <+> pretty (sourceType pro) <+> comma
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz <+> text tarV <+> colon <+> text (targetRole pro) <+> colon <+> (pretty (targetType pro)) <+> rparen
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulzdata Sign = Sign { types :: Set.Set TypeClass
e5cc7e9f8d96cdfe6126109bc8ab276f54c98590Ewaryst Schulz , typeRel :: Rel.Rel TypeClass
, abstractClasses :: Set.Set TypeClass
, roles :: Set.Set Role
, properties :: Set.Set PropertyT
, instances :: Map.Map String TypeClass
, links :: Set.Set LinkT
Set.fold (($+$) . (toType abst)) empty typ
foldr (($+$) . toSubRel) empty (Rel.toList tyR)
Set.fold (($+$) . text . ("role "++)) empty rol
Set.fold (($+$) . pretty) empty pro
foldr (($+$) . toInstance) empty (Map.toList ins)
Set.fold (($+$) . pretty) empty lin
toType :: Set.Set TypeClass -> TypeClass -> Doc
if Set.member (TypeClass nam ki) setTC then
emptySign = Sign { types = Set.empty
, typeRel = Rel.empty
, abstractClasses = Set.empty
, roles = Set.empty
, properties = Set.empty
, instances = Map.empty
, links = Set.empty
-- , isas = Rel.union (isas s1) (isas s2) }