{-# LANGUAGE TypeSynonymInstances #-}
{- |
Module      :  ./Maude/Meta/HasName.hs
Description :  Accessing the names of Maude data types
Copyright   :  (c) Martin Kuehl, Uni Bremen 2008-2009
License     :  GPLv2 or higher, see LICENSE.txt

Maintainer  :  mkhl@informatik.uni-bremen.de
Stability   :  experimental
Portability :  portable

Accessing the names of Maude data types.

Defines a type class 'HasName' that lets us access the names of Maude
data types as 'Qid's.

Consider importing "Maude.Meta" instead of this module.
-}

module Maude.Meta.HasName (
    -- * The HasName type class
    HasName (..)
) where

import Maude.AS_Maude

-- * The HasName type class

-- | Represents something that has a name (as a 'Qid').
class HasName a where
    -- | Extract the name of the input.
    getName :: a -> Qid
    -- | Map the name of the input.
    mapName :: (Qid -> Qid) -> a -> a

-- * Predefined instances

instance HasName Qid where
    getName :: Qid -> Qid
getName = Qid -> Qid
forall a. a -> a
id
    mapName :: (Qid -> Qid) -> Qid -> Qid
mapName = (Qid -> Qid) -> Qid -> Qid
forall a. a -> a
id

instance HasName Type where
    getName :: Type -> Qid
getName typ :: Type
typ = case Type
typ of
        TypeSort sort :: Sort
sort -> Sort -> Qid
forall a. HasName a => a -> Qid
getName Sort
sort
        TypeKind kind :: Kind
kind -> Kind -> Qid
forall a. HasName a => a -> Qid
getName Kind
kind
    mapName :: (Qid -> Qid) -> Type -> Type
mapName mp :: Qid -> Qid
mp typ :: Type
typ = case Type
typ of
        TypeSort sort :: Sort
sort -> Sort -> Type
TypeSort (Sort -> Type) -> Sort -> Type
forall a b. (a -> b) -> a -> b
$ (Qid -> Qid) -> Sort -> Sort
forall a. HasName a => (Qid -> Qid) -> a -> a
mapName Qid -> Qid
mp Sort
sort
        TypeKind kind :: Kind
kind -> Kind -> Type
TypeKind (Kind -> Type) -> Kind -> Type
forall a b. (a -> b) -> a -> b
$ (Qid -> Qid) -> Kind -> Kind
forall a. HasName a => (Qid -> Qid) -> a -> a
mapName Qid -> Qid
mp Kind
kind

instance HasName Sort where
    getName :: Sort -> Qid
getName (SortId name :: Qid
name) = Qid
name
    mapName :: (Qid -> Qid) -> Sort -> Sort
mapName mp :: Qid -> Qid
mp (SortId name :: Qid
name) = Qid -> Sort
SortId (Qid -> Sort) -> Qid -> Sort
forall a b. (a -> b) -> a -> b
$ Qid -> Qid
mp Qid
name

instance HasName Kind where
    getName :: Kind -> Qid
getName (KindId name :: Qid
name) = Qid
name
    mapName :: (Qid -> Qid) -> Kind -> Kind
mapName mp :: Qid -> Qid
mp (KindId name :: Qid
name) = Qid -> Kind
KindId (Qid -> Kind) -> Qid -> Kind
forall a b. (a -> b) -> a -> b
$ Qid -> Qid
mp Qid
name

instance HasName ParamId where
    getName :: ParamId -> Qid
getName (ParamId name :: Qid
name) = Qid
name
    mapName :: (Qid -> Qid) -> ParamId -> ParamId
mapName mp :: Qid -> Qid
mp (ParamId name :: Qid
name) = Qid -> ParamId
ParamId (Qid -> ParamId) -> Qid -> ParamId
forall a b. (a -> b) -> a -> b
$ Qid -> Qid
mp Qid
name

instance HasName ModId where
    getName :: ModId -> Qid
getName (ModId name :: Qid
name) = Qid
name
    mapName :: (Qid -> Qid) -> ModId -> ModId
mapName mp :: Qid -> Qid
mp (ModId name :: Qid
name) = Qid -> ModId
ModId (Qid -> ModId) -> Qid -> ModId
forall a b. (a -> b) -> a -> b
$ Qid -> Qid
mp Qid
name

instance HasName ViewId where
    getName :: ViewId -> Qid
getName (ViewId name :: Qid
name) = Qid
name
    mapName :: (Qid -> Qid) -> ViewId -> ViewId
mapName mp :: Qid -> Qid
mp (ViewId name :: Qid
name) = Qid -> ViewId
ViewId (Qid -> ViewId) -> Qid -> ViewId
forall a b. (a -> b) -> a -> b
$ Qid -> Qid
mp Qid
name

instance HasName LabelId where
    getName :: LabelId -> Qid
getName (LabelId name :: Qid
name) = Qid
name
    mapName :: (Qid -> Qid) -> LabelId -> LabelId
mapName mp :: Qid -> Qid
mp (LabelId name :: Qid
name) = Qid -> LabelId
LabelId (Qid -> LabelId) -> Qid -> LabelId
forall a b. (a -> b) -> a -> b
$ Qid -> Qid
mp Qid
name

instance HasName OpId where
    getName :: OpId -> Qid
getName (OpId name :: Qid
name) = Qid
name
    mapName :: (Qid -> Qid) -> OpId -> OpId
mapName mp :: Qid -> Qid
mp (OpId name :: Qid
name) = Qid -> OpId
OpId (Qid -> OpId) -> Qid -> OpId
forall a b. (a -> b) -> a -> b
$ Qid -> Qid
mp Qid
name

instance HasName Operator where
    getName :: Operator -> Qid
getName (Op name :: OpId
name _ _ _) = OpId -> Qid
forall a. HasName a => a -> Qid
getName OpId
name
    mapName :: (Qid -> Qid) -> Operator -> Operator
mapName mp :: Qid -> Qid
mp (Op name :: OpId
name dom :: [Type]
dom cod :: Type
cod as :: [Attr]
as) = OpId -> [Type] -> Type -> [Attr] -> Operator
Op ((Qid -> Qid) -> OpId -> OpId
forall a. HasName a => (Qid -> Qid) -> a -> a
mapName Qid -> Qid
mp OpId
name) [Type]
dom Type
cod [Attr]
as

instance HasName Module where
    getName :: Module -> Qid
getName (Module name :: ModId
name _ _) = ModId -> Qid
forall a. HasName a => a -> Qid
getName ModId
name
    mapName :: (Qid -> Qid) -> Module -> Module
mapName mp :: Qid -> Qid
mp (Module name :: ModId
name ps :: [Parameter]
ps ss :: [Statement]
ss) = ModId -> [Parameter] -> [Statement] -> Module
Module ((Qid -> Qid) -> ModId -> ModId
forall a. HasName a => (Qid -> Qid) -> a -> a
mapName Qid -> Qid
mp ModId
name) [Parameter]
ps [Statement]
ss

instance HasName View where
    getName :: View -> Qid
getName (View name :: ModId
name _ _ _) = ModId -> Qid
forall a. HasName a => a -> Qid
getName ModId
name
    mapName :: (Qid -> Qid) -> View -> View
mapName mp :: Qid -> Qid
mp (View name :: ModId
name from :: ModExp
from to :: ModExp
to rnms :: [Renaming]
rnms) = ModId -> ModExp -> ModExp -> [Renaming] -> View
View ((Qid -> Qid) -> ModId -> ModId
forall a. HasName a => (Qid -> Qid) -> a -> a
mapName Qid -> Qid
mp ModId
name) ModExp
from ModExp
to [Renaming]
rnms

instance HasName Spec where
    getName :: Spec -> Qid
getName spec :: Spec
spec = case Spec
spec of
        SpecMod modul :: Module
modul -> Module -> Qid
forall a. HasName a => a -> Qid
getName Module
modul
        SpecTh theory :: Module
theory -> Module -> Qid
forall a. HasName a => a -> Qid
getName Module
theory
        SpecView view :: View
view -> View -> Qid
forall a. HasName a => a -> Qid
getName View
view
    mapName :: (Qid -> Qid) -> Spec -> Spec
mapName mp :: Qid -> Qid
mp spec :: Spec
spec = case Spec
spec of
        SpecMod modul :: Module
modul -> Module -> Spec
SpecMod (Module -> Spec) -> Module -> Spec
forall a b. (a -> b) -> a -> b
$ (Qid -> Qid) -> Module -> Module
forall a. HasName a => (Qid -> Qid) -> a -> a
mapName Qid -> Qid
mp Module
modul
        SpecTh theory :: Module
theory -> Module -> Spec
SpecTh (Module -> Spec) -> Module -> Spec
forall a b. (a -> b) -> a -> b
$ (Qid -> Qid) -> Module -> Module
forall a. HasName a => (Qid -> Qid) -> a -> a
mapName Qid -> Qid
mp Module
theory
        SpecView view :: View
view -> View -> Spec
SpecView (View -> Spec) -> View -> Spec
forall a b. (a -> b) -> a -> b
$ (Qid -> Qid) -> View -> View
forall a. HasName a => (Qid -> Qid) -> a -> a
mapName Qid -> Qid
mp View
view