Logic_Haskell.hs revision 3c9599ef78f74b178d97b53e58cb385299ccc08e
0N/A{-# OPTIONS -fno-warn-missing-methods #-}
624N/A{-|
0N/AModule : $Header$
0N/ACopyright : (c) Christian Maeder, Sonja Groening, Uni Bremen 2002-2004
0N/ALicence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
0N/A
0N/AMaintainer : hets@tzi.de
0N/AStability : provisional
0N/APortability : non-portable(Logic)
0N/A
0N/A Here is the place where the class Logic is instantiated for Haskell.
0N/A Also the instances for Syntax an Category.
0N/A
0N/A todo:
0N/A - writing real functions
0N/A
0N/A-}
0N/A
0N/Amodule Haskell.Logic_Haskell (Haskell(..), empty_signature) where
0N/A
0N/Aimport Logic.ParsecInterface (toParseFun)
0N/Aimport Logic.Logic {-(Language,
0N/A Category,
0N/A Syntax,
0N/A Sentences,
0N/A StaticAnalysis,
0N/A Logic,
0N/A parse_basic_spec,
0N/A parse_symb_items,
0N/A parse_symb_map_items,
0N/A basic_analysis,
0N/A empty_signature,
0N/A signature_union,
0N/A data_logic,
0N/A sublogic_names,
0N/A inclusion)-}
0N/Aimport Data.Dynamic
0N/Aimport Haskell.ATC_Haskell -- generated ATerm conversions
0N/A
0N/Aimport System.IO.Unsafe (unsafePerformIO)
0N/Aimport Haskell.Hatchet.MultiModule (readModuleInfo)
0N/Aimport Haskell.Hatchet.MultiModuleBasics (ModuleInfo (..),
0N/A joinModuleInfo,
113N/A getTyconsMembers,
0N/A getInfixDecls,
0N/A emptyModuleInfo)
0N/Aimport Haskell.Hatchet.TIHetsModule (tiModule)
0N/Aimport Haskell.Hatchet.AnnotatedHsSyn (AHsDecl (..),
0N/A AModule (..))
0N/Aimport Haskell.Hatchet.Env (listToEnv,
0N/A emptyEnv)
0N/Aimport Haskell.Hatchet.HaskellPrelude (preludeDefs,
0N/A tyconsMembersHaskellPrelude,
0N/A preludeDataCons,
0N/A preludeClasses,
0N/A preludeTyconAndClassKinds,
0N/A preludeInfixDecls,
0N/A preludeSynonyms)
0N/Aimport Haskell.Hatchet.SynConvert (toAHsModule)
0N/Aimport Haskell.Hatchet.Type (assumpToPair)
0N/Aimport Haskell.Hatchet.Utils (getAModuleName)
0N/Aimport Haskell.Hatchet.HsParsePostProcess (fixFunBindsInModule)
0N/Aimport Haskell.Hatchet.HsSyn (HsModule (..), HsDecl,
0N/A Module (..))
0N/Aimport Haskell.HatParser (HsDecls,
0N/A hatParser)
0N/Aimport Haskell.HaskellUtils (extractSentences)
113N/Aimport Common.Result (Result (..))
0N/Aimport Common.Lib.Pretty
0N/Aimport Common.PrettyPrint
0N/A
0N/Aimport Haskell.ExtHaskellCvrt (cvrtHsModule)
0N/A
0N/AmoduleInfoTc, hsDeclTc, aHsDeclTc :: TyCon
0N/AmoduleInfoTc = mkTyCon "Haskell.Hatchet.MultiModuleBasics.ModuleInfo"
0N/AhsDeclTc = mkTyCon "Haskell.Hatchet.HsSyn.HsDecl"
0N/AaHsDeclTc = mkTyCon "Haskell.Hatchet.AnnotatedHsSyn.AHsDecl"
0N/A
0N/Ainstance Typeable ModuleInfo where
0N/A typeOf _ = mkAppTy moduleInfoTc []
0N/Ainstance Typeable HsDecl where
0N/A typeOf _ = mkAppTy hsDeclTc []
0N/Ainstance Typeable AHsDecl where
0N/A typeOf _ = mkAppTy aHsDeclTc []
0N/A
0N/A
0N/Ainstance PrettyPrint ModuleInfo where
0N/A printText0 _ modInfo = text "Module name"
0N/A <+> text (show (moduleName modInfo))
0N/A <> comma
0N/A $+$ text "Variable Assumptions"
0N/A <+> text (show (varAssumps modInfo))
0N/A <> comma
0N/A $+$ text "Data Constructor Assumptions"
0N/A <+> text (show (dconsAssumps modInfo))
0N/A <> comma
0N/A $+$ text "Class Hierarchy"
0N/A <+> text (show (classHierarchy modInfo))
0N/A <> comma
0N/A $+$ text "Kinds"
0N/A <+> text (show (kinds modInfo))
0N/A <> comma
0N/A $+$ text "Synonyms"
0N/A <+> text (show (synonyms modInfo))
0N/A <> comma
0N/A $+$ text "Infix Declarations"
0N/A <+> text (show (infixDecls modInfo))
0N/A <> comma
0N/A $+$ text "Type Constructor Members"
0N/A <+> text (show (tyconsMembers modInfo))
0N/A <> comma
0N/A
0N/A
0N/Ainstance PrintLaTeX ModuleInfo where
0N/A printLatex0 = printText0
0N/Ainstance PrintLaTeX HsDecls where
0N/A printLatex0 = printText0
0N/A
0N/A-- a dummy datatype for the LogicGraph and for identifying the right
0N/A-- instances
0N/A
0N/Adata Haskell = Haskell deriving (Show)
0N/Ainstance Language Haskell -- default definition is okay
0N/A
0N/Atype Sign = ModuleInfo
0N/Atype Morphism = ()
0N/A
0N/Ainstance Category Haskell Sign Morphism where
0N/A dom Haskell _ = empty_signature Haskell
0N/A
0N/A-- abstract syntax, parsing (and printing)
0N/A
0N/Atype SYMB_ITEMS = ()
0N/Atype SYMB_MAP_ITEMS = ()
0N/A
0N/Ainstance Syntax Haskell HsDecls
0N/A SYMB_ITEMS SYMB_MAP_ITEMS
0N/A where
0N/A parse_basic_spec Haskell = Just(toParseFun hatParser ())
0N/A parse_symb_items Haskell = Nothing
0N/A parse_symb_map_items Haskell = Nothing
0N/A
0N/Atype Haskell_Sublogics = ()
0N/A
0N/Atype Sentence = AHsDecl
0N/Ainstance Ord AHsDecl where
0N/A compare x y = undefined
0N/A
0N/Ainstance PrettyPrint Sentence where
0N/A printText0 _ = ptext . show
0N/A
0N/Atype Symbol = ()
0N/Atype RawSymbol = ()
0N/A
0N/Ainstance Sentences Haskell Sentence () Sign Morphism Symbol
0N/A
0N/ApreludeSign :: ModuleInfo
0N/ApreludeSign = ModuleInfo {
0N/A moduleName = AModule "Prelude",
0N/A varAssumps = (listToEnv $ map assumpToPair preludeDefs),
0N/A tyconsMembers = tyconsMembersHaskellPrelude,
0N/A dconsAssumps = (listToEnv $ map assumpToPair preludeDataCons),
0N/A classHierarchy = listToEnv preludeClasses,
0N/A kinds = (listToEnv preludeTyconAndClassKinds),
0N/A infixDecls = preludeInfixDecls,
0N/A synonyms = preludeSynonyms
0N/A }
0N/A
0N/A
0N/A{- basic_analysis :: lid ->
0N/A Maybe((basic_spec, -- abstract syntax tree
0N/A sign, -- signature of imported
0N/A modules
0N/A GlobalAnnos) -> -- global annotations
0N/A Result (basic_spec, -- renamed module
0N/A sign,sign, -- (total, delta)
0N/A -- delta = deklarations in the modul
0N/A -- total = imported + delta
0N/A [Named sentence] -- programdefinitions))
0N/A
0N/A basic_analysis calculates from the abstract syntax tree the types of
0N/A all functions and tests wether all used identifiers are declared
0N/A
0N/A-}
0N/A
0N/Ainstance StaticAnalysis Haskell HsDecls
0N/A Sentence ()
0N/A SYMB_ITEMS SYMB_MAP_ITEMS
0N/A Sign
0N/A Morphism
0N/A Symbol RawSymbol
0N/A
113N/A
163N/A where
163N/A empty_signature Haskell
113N/A = ModuleInfo { varAssumps = emptyEnv,
0N/A moduleName = AModule "EmptyModule",-- error "Unspecified module name",
0N/A dconsAssumps = emptyEnv,
0N/A classHierarchy = emptyEnv,
0N/A tyconsMembers = [],
0N/A kinds = emptyEnv,
0N/A infixDecls = [],
0N/A synonyms = [] }
0N/A-- empty_signature Haskell = emptyModuleInfo
0N/A signature_union Haskell sig1 sig2 = return (joinModuleInfo sig1 sig2)
0N/A inclusion Haskell _ _ = return ()
0N/A-- sublogic_names Haskell _ = ["Haskell"]
0N/A basic_analysis Haskell = Just(basicAnalysis)
0N/A where basicAnalysis (basicSpec, sig, _) =
0N/A let basicMod = cvrtHsModule (HsModule (Module "Anonymous")
0N/A Nothing [] basicSpec)
0N/A
113N/A -- re-group matches into their associated funbinds
113N/A -- (patch up the output from the parser)
163N/A moduleSyntaxFixedFunBinds = fixFunBindsInModule basicMod
163N/A
113N/A -- map the abstract syntax into the annotated abstract syntax
113N/A annotatedSyntax = toAHsModule moduleSyntaxFixedFunBinds
113N/A
113N/A (moduleEnv,
113N/A dataConEnv,
113N/A newClassHierarchy,
113N/A newKindInfoTable,
113N/A moduleIds,
0N/A moduleRenamed,
0N/A moduleSynonyms) = tiModule [] annotatedSyntax sig
0N/A modInfo = ModuleInfo {
221N/A varAssumps = moduleEnv,
221N/A moduleName = getAModuleName annotatedSyntax,
221N/A dconsAssumps = dataConEnv,
221N/A classHierarchy = newClassHierarchy,
221N/A kinds = newKindInfoTable,
221N/A tyconsMembers = getTyconsMembers moduleRenamed,
0N/A infixDecls = getInfixDecls moduleRenamed,
0N/A synonyms = moduleSynonyms }
0N/A in
0N/A Result {diags = [],
0N/A maybeResult = Just(basicSpec, modInfo,
0N/A (joinModuleInfo sig modInfo),
0N/A (extractSentences annotatedSyntax)) }
0N/A
0N/Ainstance Logic Haskell Haskell_Sublogics
0N/A HsDecls Sentence SYMB_ITEMS SYMB_MAP_ITEMS
0N/A Sign
0N/A Morphism
0N/A Symbol RawSymbol ()
0N/A where data_logic Haskell = Nothing
0N/A