5784N/ADescription : the abstract syntax for analysis and final signature instance
5784N/ACopyright : (c) Christian Maeder and Uni Bremen 2003-2005
5784N/AMaintainer : Christian.Maeder@dfki.de
5784N/Aabstract syntax during static analysis
5784N/A-- | store the raw kind and all superclasses of a class identifier
5784N/A-- | mapping class identifiers to their definition
5784N/A-- | data type generatedness indicator
5784N/Adata GenKind = Free | Generated | Loose deriving (Show, Eq, Ord)
5784N/A-- | an analysed alternative with a list of (product) types
5784N/A Construct (Maybe Id) [Type] Partiality [[Selector]]
5784N/A Select (Maybe Id) Type Partiality deriving (Show, Eq, Ord)
5784N/A-- | a mapping of type (and disjoint class) identifiers
5784N/A-- | for data types the morphism needs to be kept as well
5784N/A DataEntry IdMap Id GenKind [TypeArg] RawKind (
Set.Set AltDefn)
5784N/A-- | possible definitions for type identifiers
5784N/A | PreDatatype -- auxiliary entry for DatatypeDefn
5784N/A-- | for type identifiers also store the raw kind, instances and supertypes
5784N/A , superTypes ::
Set.Set Id -- only declared or direct supertypes?
5784N/A t1 == t2 = (typeKind t1, otherTypeKinds t1, superTypes t1)
5784N/A == (typeKind t2, otherTypeKinds t2, superTypes t2)
5784N/A-- | mapping type identifiers to their definition
5784N/A-- | the minimal information for a sort
5784N/A-- | rename the type according to identifier map (for comorphisms)
5784N/AmapType :: IdMap -> Type -> Type
5784N/A { foldTypeName = \ t i k n -> if n /= 0 then t else
5784N/A-- | data types are also special sentences because of their properties
5784N/A | ProgEqSen Id TypeScheme ProgEq
5784N/A-- | type variable are kept separately
5784N/Adata TypeVarDefn = TypeVarDefn Variance VarKind RawKind Int deriving Show
5784N/A-- | mapping type variables to their definition
5784N/A-- | the type of a local variable
5784N/Adata VarDefn = VarDefn Type deriving Show
5784N/A-- | name and scheme of a constructor
5784N/Adata ConstrInfo = ConstrInfo
5784N/A-- | possible definitions of functions
5784N/A | ConstructData Id -- ^ target type
5784N/A | SelectData (
Set.Set ConstrInfo) Id -- ^ constructors of source type
5784N/A-- | scheme, attributes and definition for function identifiers
5784N/A o1 == o2 = compare o1 o2 == EQ
5784N/A compare o1 o2 = compare (opType o1) $ opType o2
5784N/AisConstructor :: OpInfo -> Bool
5784N/AisConstructor o = case opDefn o of
5784N/A-- | mapping operation identifiers to their definition
5784N/A-- * the local environment and final signature
5784N/A-- | the signature is established by the classes, types and assumptions
5784N/A , localTypeVars :: LocalTypeVars
5784N/A , sentences :: [Named Sentence]
5784N/A e1 == e2 = (classMap e1, typeMap e1, assumps e1) ==
5784N/A (classMap e2, typeMap e2, assumps e2)
5784N/A-- | the empty environment (fresh variables start with 1)
5784N/A , globAnnos = emptyGlobalAnnos
5784N/A{- utils for singleton sets that could also be part of "
Data.Set". These
5784N/Awould need to be rewritten for set implementations with a size
5784N/Afunction that is only linear. -}
5784N/A-- | /O(1)/ test if the set's size is one
5784N/A-- | /O(1)/ test if the set's size is greater one
5784N/Adata Constrain = Kinding Type Kind
5784N/A-- * accessing the environment
5784N/A-- | add diagnostic messages
5784N/A-- | store local assumptions
5784N/A-- | converting a result to a state computation
5784N/A-- | store local type variables
5784N/A-- | store a complete type map
5784N/A-- | check uniqueness of variables
5784N/AcheckUniqueVars = addDiags . checkUniqueness . map getVar
5784N/A-- mapping qualified operation identifiers (aka renamings)
5784N/A-- | keep types and class disjoint and use a single identifier map for both
5784N/A-- | construct morphism for subsignatures
5784N/AmkMorphism :: Env -> Env -> Morphism
5784N/A-- | the type or kind of an identifier
5784N/A | TypeAsItemType (AnyKind a)
5784N/A | ClassAsItemType (AnyKind a)
5784N/A-- | symbols with their type and env (to look up type aliases)
5784N/A Symbol {symName :: Id, symType :: SymbolType (), symEnv :: Env}
5784N/A s1 == s2 = compare s1 s2 == EQ
5784N/A compare s1 s2 = compare (symName s1, symType s1) (symName s2, symType s2)
5784N/A-- | mapping symbols to symbols
5784N/AidToTypeSymbol :: Env -> Id -> RawKind -> Symbol
5784N/AidToTypeSymbol e idt k = Symbol idt (TypeAsItemType k) e
5784N/AidToClassSymbol :: Env -> Id -> RawKind -> Symbol
5784N/AidToClassSymbol e idt k = Symbol idt (ClassAsItemType k) e
5784N/A-- | create an operation symbol
5784N/AidToOpSymbol :: Env -> Id -> TypeScheme -> Symbol
5784N/AidToOpSymbol e idt typ = Symbol idt (OpAsItemType typ) e
5784N/A-- | raw symbols where the type of a qualified raw symbol is not yet analysed
5784N/A | AQualId Id (SymbolType Id)
5784N/A-- | mapping raw symbols to raw symbols
5784N/A-- | create a raw symbol from an identifier
5784N/A-- | extract the top identifer from a raw symbol
5784N/ArawSymName :: RawSymbol -> Id
5784N/A-- | convert a symbol type to a symbol kind
5784N/AsymbTypeToKind :: SymbolType a -> SymbKind
5784N/AsymbTypeToKind s = case s of
5784N/A TypeAsItemType _ -> SK_type
5784N/A ClassAsItemType _ -> SK_class
5784N/A-- | wrap a symbol as raw symbol (is 'ASymbol')
5784N/AsymbolToRaw :: Symbol -> RawSymbol
5784N/AsymbolToRaw sym = ASymbol sym
5784N/A-- | create a raw symbol from a symbol kind and an identifier
5784N/AsymbKindToRaw :: SymbKind -> Id -> RawSymbol
5784N/AsymbKindToRaw sk = case sk of
5784N/A _ -> AKindedId $ case sk of
5784N/A where getCompound (Id _ cs _) = cs