Le.hs revision facf15c975d25ca5d31d8f84bf48f09d1d951ad6
66267bcb678a9c341272c323b299337bcfdb7cc5Christian Maeder{- |
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian MaederModule : $Header$
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederDescription : the abstract syntax for analysis and final signature instance
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederCopyright : (c) Christian Maeder and Uni Bremen 2003-2005
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
66267bcb678a9c341272c323b299337bcfdb7cc5Christian Maeder
ffd01020a4f35f434b912844ad6e0d6918fadffdChristian MaederMaintainer : Christian.Maeder@dfki.de
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederStability : experimental
66267bcb678a9c341272c323b299337bcfdb7cc5Christian MaederPortability : portable
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maeder
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maederabstract syntax during static analysis
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder-}
fb69cd512eab767747f109e40322df7cae2f7bdfChristian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maedermodule HasCASL.Le where
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport HasCASL.As
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport HasCASL.AsUtils
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maederimport qualified Data.Map as Map
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maederimport qualified Data.Set as Set
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport qualified Common.Lib.State as State
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maederimport Common.Result
ad270004874ce1d0697fb30d7309f180553bb315Christian Maederimport Common.Id
ad270004874ce1d0697fb30d7309f180553bb315Christian Maederimport Common.AS_Annotation (Named)
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.GlobalAnnotations
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederimport Common.Prec
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- * class info
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | store the raw kind and all superclasses of a class identifier
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata ClassInfo = ClassInfo
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder { rawKind :: RawKind
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder , classKinds :: Set.Set Kind
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder } deriving (Show, Eq)
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder-- | mapping class identifiers to their definition
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maedertype ClassMap = Map.Map Id ClassInfo
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
024621f43239cfe9629e35d35a8669fad7acbba2Christian Maeder-- * type info
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | data type generatedness indicator
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maederdata GenKind = Free | Generated | Loose deriving (Show, Eq, Ord)
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder
27912d626bf179b82fcb337077e5cd9653bb71cfChristian Maeder-- | an analysed alternative with a list of (product) types
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata AltDefn =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Construct (Maybe Id) [Type] Partiality [[Selector]]
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder -- only argument types
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder deriving (Show, Eq, Ord)
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder
8c81b727b788d90ff3b8cbda7b0900c9009243bbChristian Maeder-- | an analysed component
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata Selector =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Select (Maybe Id) Type Partiality deriving (Show, Eq, Ord)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder -- only result type
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | a mapping of type (and disjoint class) identifiers
07b1bf56f3a486f26d69514d05b73100abb25a0eChristian Maedertype IdMap = Map.Map Id Id
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | for data types the morphism needs to be kept as well
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata DataEntry =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder DataEntry IdMap Id GenKind [TypeArg] RawKind (Set.Set AltDefn)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq, Ord)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | possible definitions for type identifiers
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata TypeDefn =
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder NoTypeDefn
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder | PreDatatype -- auxiliary entry for DatatypeDefn
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | DatatypeDefn DataEntry
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | AliasTypeDefn Type
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | for type identifiers also store the raw kind, instances and supertypes
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata TypeInfo = TypeInfo
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder { typeKind :: RawKind
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , otherTypeKinds :: Set.Set Kind
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , superTypes :: Set.Set Id -- only declared or direct supertypes?
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , typeDefn :: TypeDefn
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder } deriving Show
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Eq TypeInfo where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder t1 == t2 = (typeKind t1, otherTypeKinds t1, superTypes t1)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder == (typeKind t2, otherTypeKinds t2, superTypes t2)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder-- | mapping type identifiers to their definition
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maedertype TypeMap = Map.Map Id TypeInfo
36c6cc568751e4235502cfee00ba7b597dae78dcChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | the minimal information for a sort
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederstarTypeInfo :: TypeInfo
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederstarTypeInfo = TypeInfo rStar (Set.singleton universe) Set.empty NoTypeDefn
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | rename the type according to identifier map (for comorphisms)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedermapType :: IdMap -> Type -> Type
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaedermapType m ty = if Map.null m then ty else
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder rename ( \ i k n ->
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder let t = TypeName i k n in
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder if n == 0 then
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder case Map.lookup i m of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder Just j -> TypeName j k 0
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder _ -> t
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder else t) ty
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- * sentences
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maeder-- | data types are also special sentences because of their properties
5c933f3c61d2cfa7e76e4eb610a4b0bac988be47Christian Maederdata Sentence =
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder Formula Term
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | DatatypeSen [DataEntry]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | ProgEqSen Id TypeScheme ProgEq
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq, Ord)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- * variables
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | type variable are kept separately
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata TypeVarDefn = TypeVarDefn Variance VarKind RawKind Int deriving Show
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | mapping type variables to their definition
76647324ed70f33b95a881b536d883daccf9568dChristian Maedertype LocalTypeVars = Map.Map Id TypeVarDefn
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder-- | the type of a local variable
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maederdata VarDefn = VarDefn Type deriving Show
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder
c438c79d00fc438f99627e612498744bdc0d0c89Christian Maeder-- * assumptions
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | name and scheme of a constructor
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maederdata ConstrInfo = ConstrInfo
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder { constrId :: Id
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , constrType :: TypeScheme
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder } deriving (Show, Eq, Ord)
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder
8aea46773664711e0910accc5cf80ef9ee1bcfbfChristian Maeder-- | possible definitions of functions
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata OpDefn =
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder NoOpDefn OpBrand
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | ConstructData Id -- ^ target type
61091743da1a9ed6dfd5e077fdcc972553358962Christian Maeder | SelectData (Set.Set ConstrInfo) Id -- ^ constructors of source type
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder | Definition OpBrand Term
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder deriving (Show, Eq)
08b724e8dcbba5820d80f0974b9a5385140815baChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | scheme, attributes and definition for function identifiers
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maederdata OpInfo = OpInfo
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder { opType :: TypeScheme
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , opAttrs :: Set.Set OpAttr
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maeder , opDefn :: OpDefn
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder } deriving Show
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maeder
5d7e4bf173534e7eb3fc84dce7bb0151079d3f8aChristian Maederinstance Eq OpInfo where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder o1 == o2 = compare o1 o2 == EQ
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Ord OpInfo where
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder compare o1 o2 = compare (opType o1) $ opType o2
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder-- | test for constructor
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisConstructor :: OpInfo -> Bool
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian MaederisConstructor o = case opDefn o of
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder ConstructData _ -> True
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder _ -> False
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder
405b95208385572f491e1e0207d8d14e31022fa6Christian Maeder-- | mapping operation identifiers to their definition
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maedertype Assumps = Map.Map Id (Set.Set OpInfo)
8c81b727b788d90ff3b8cbda7b0900c9009243bbChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- * the local environment and final signature
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | the signature is established by the classes, types and assumptions
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederdata Env = Env
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder { classMap :: ClassMap
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , typeMap :: TypeMap
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , localTypeVars :: LocalTypeVars
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , assumps :: Assumps
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , localVars :: Map.Map Id VarDefn
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , sentences :: [Named Sentence]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , envDiags :: [Diagnosis]
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , preIds :: (PrecMap, Set.Set Id)
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder , globAnnos :: GlobalAnnos
05e2a3161e4589a717c6fe5c7306820273a473c5Christian Maeder , counter :: Int
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder } deriving Show
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maederinstance Eq Env where
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder e1 == e2 = (classMap e1, typeMap e1, assumps e1) ==
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder (classMap e2, typeMap e2, assumps e2)
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder-- | the empty environment (fresh variables start with 1)
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaederinitialEnv :: Env
341d00318de2d0ea9b6f0ab43f7e4d10ee4fb454Christian MaederinitialEnv = Env
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder { classMap = Map.empty
5a13581acc5a76d392c1dec01657bb3efd4dcf2dChristian Maeder , typeMap = Map.empty
, localTypeVars = Map.empty
, assumps = Map.empty
, localVars = Map.empty
, sentences = []
, envDiags = []
, preIds = (emptyPrecMap, Set.empty)
, globAnnos = emptyGlobalAnnos
, counter = 1 }
{- utils for singleton sets that could also be part of "Data.Set". These
functions rely on 'Data.Set.size' being computable in constant time and
would need to be rewritten for set implementations with a size
function that is only linear. -}
-- | /O(1)/ test if the set's size is one
isSingleton :: Set.Set a -> Bool
isSingleton s = Set.size s == 1
-- | /O(1)/ test if the set's size is greater one
hasMany :: Set.Set a -> Bool
hasMany s = Set.size s > 1
data Constrain = Kinding Type Kind
| Subtyping Type Type
deriving (Eq, Ord, Show)
-- * accessing the environment
-- | add diagnostic messages
addDiags :: [Diagnosis] -> State.State Env ()
addDiags ds = do
e <- State.get
State.put $ e {envDiags = reverse ds ++ envDiags e}
-- | add sentences
appendSentences :: [Named Sentence] -> State.State Env ()
appendSentences fs = do
e <- State.get
State.put $ e {sentences = reverse fs ++ sentences e}
-- | store a class map
putClassMap :: ClassMap -> State.State Env ()
putClassMap ce = do
e <- State.get
State.put e { classMap = ce }
-- | store local assumptions
putLocalVars :: Map.Map Id VarDefn -> State.State Env ()
putLocalVars vs = do
e <- State.get
State.put e { localVars = vs }
-- | converting a result to a state computation
fromResult :: (Env -> Result a) -> State.State Env (Maybe a)
fromResult f = do
e <- State.get
let Result ds mr = f e
addDiags ds
return mr
-- | store local type variables
putLocalTypeVars :: LocalTypeVars -> State.State Env ()
putLocalTypeVars tvs = do
e <- State.get
State.put e { localTypeVars = tvs }
-- | store a complete type map
putTypeMap :: TypeMap -> State.State Env ()
putTypeMap tm = do
e <- State.get
State.put e { typeMap = tm }
-- | store assumptions
putAssumps :: Assumps -> State.State Env ()
putAssumps ops = do
e <- State.get
State.put e { assumps = ops }
-- | get the variable
getVar :: VarDecl -> Id
getVar(VarDecl v _ _ _) = v
-- | check uniqueness of variables
checkUniqueVars :: [VarDecl] -> State.State Env ()
checkUniqueVars = addDiags . checkUniqueness . map getVar
-- * morphisms
-- mapping qualified operation identifiers (aka renamings)
type FunMap = Map.Map (Id, TypeScheme) (Id, TypeScheme)
-- | keep types and class disjoint and use a single identifier map for both
data Morphism = Morphism
{ msource :: Env
, mtarget :: Env
, typeIdMap :: IdMap
, funMap :: FunMap
} deriving Show
-- | construct morphism for subsignatures
mkMorphism :: Env -> Env -> Morphism
mkMorphism e1 e2 = Morphism
{ msource = e1
, mtarget = e2
, typeIdMap = Map.empty
, funMap = Map.empty }
-- * symbol stuff
-- | the type or kind of an identifier
data SymbolType a =
OpAsItemType TypeScheme
| TypeAsItemType (AnyKind a)
| ClassAsItemType (AnyKind a)
deriving (Show, Eq, Ord)
-- | symbols with their type and env (to look up type aliases)
data Symbol =
Symbol {symName :: Id, symType :: SymbolType (), symEnv :: Env}
deriving Show
instance Eq Symbol where
s1 == s2 = compare s1 s2 == EQ
instance Ord Symbol where
compare s1 s2 = compare (symName s1, symType s1) (symName s2, symType s2)
-- | mapping symbols to symbols
type SymbolMap = Map.Map Symbol Symbol
-- | a set of symbols
type SymbolSet = Set.Set Symbol
-- | create a type symbol
idToTypeSymbol :: Env -> Id -> RawKind -> Symbol
idToTypeSymbol e idt k = Symbol idt (TypeAsItemType k) e
-- | create a class symbol
idToClassSymbol :: Env -> Id -> RawKind -> Symbol
idToClassSymbol e idt k = Symbol idt (ClassAsItemType k) e
-- | create an operation symbol
idToOpSymbol :: Env -> Id -> TypeScheme -> Symbol
idToOpSymbol e idt typ = Symbol idt (OpAsItemType typ) e
-- | raw symbols where the type of a qualified raw symbol is not yet analysed
data RawSymbol =
AnID Id
| AKindedId SymbKind Id
| AQualId Id (SymbolType Id)
| ASymbol Symbol
deriving (Show, Eq, Ord)
-- | mapping raw symbols to raw symbols
type RawSymbolMap = Map.Map RawSymbol RawSymbol
-- | create a raw symbol from an identifier
idToRaw :: Id -> RawSymbol
idToRaw x = AnID x
-- | extract the top identifer from a raw symbol
rawSymName :: RawSymbol -> Id
rawSymName r = case r of
AnID i -> i
AKindedId _ i -> i
AQualId i _ -> i
ASymbol s -> symName s
-- | convert a symbol type to a symbol kind
symbTypeToKind :: SymbolType a -> SymbKind
symbTypeToKind s = case s of
OpAsItemType _ -> SK_op
TypeAsItemType _ -> SK_type
ClassAsItemType _ -> SK_class
-- | wrap a symbol as raw symbol (is 'ASymbol')
symbolToRaw :: Symbol -> RawSymbol
symbolToRaw sym = ASymbol sym
-- | create a raw symbol from a symbol kind and an identifier
symbKindToRaw :: SymbKind -> Id -> RawSymbol
symbKindToRaw sk = case sk of
Implicit -> AnID
_ -> AKindedId $ case sk of
SK_pred -> SK_op
SK_fun -> SK_op
SK_sort -> SK_type
_ -> sk