Static.hs revision 4c53fae3e5be041e963bbfeef09f917032fedccb
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova{- --------------------------------------------------------------------------
097b7fb3f8f90e87120d30bf37a1d89fe0ddfaf0Kristina Sojakova Authors: Pascal Schmidt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu-----------------------------------------------------------------------------
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova This modules provides static analysis for the BASIC_SPEC datatype
211c5fb252e0a776baad9a4857ab198659289a4aKristina Sojakova found in AS_Basic_CASL
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova-----------------------------------------------------------------------------
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Speicherzugriffsfehler bei Analyse von
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova preds even: Nat
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova deshalb gibt basic_analysis erstmal nur triviale Werte zur�ck
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-------------------------------------------------------------------------- -}
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova-----------------------------------------------------------------------------
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina Sojakova-- Export declarations
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-----------------------------------------------------------------------------
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovamodule CASL.Static {-( basicAnalysis, statSymbMapItems, statSymbItems,
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova symbolToRaw, idToRaw, symOf, symmapOf, matches,
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova isSubSig, symName )-} where
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova------------------------------------------------------------------------------
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova-- Imports from other modules
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport Control.Monad(foldM) -- instead of foldResult
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport Common.Lib.Map hiding (map, filter)
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakovaimport Prelude hiding (lookup)
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakovaimport qualified Common.Lib.Set as Set
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakovaimport Logic.Logic ( EndoMap )
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova------------------------------------------------------------------------------
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova------------------------------------------------------------------------------
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakovatype Filename = String
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakovadata GlobalVars = Global { global :: [VarDecl] }
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova deriving (Eq,Show)
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakovadata NamedSentence = NamedSen { senName :: String,
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova sentence :: Sentence }
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova deriving (Eq,Show)
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina Sojakovadata Sentences = Sentences { sentences :: [NamedSentence] }
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova deriving (Eq,Show)
81d28e8372831ae5e6054d8d2212f0114b09b79aKristina Sojakovadata LocalEnv = Env { getName :: Filename,
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder getGA :: GlobalAnnos,
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova getSign :: Sign,
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder getPsi :: Sentences,
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina Sojakova getGlobal :: GlobalVars }
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakovadata SigLocalEnv = SigEnv { localEnv :: LocalEnv,
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova selectors :: [Annoted OpItem],
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova w :: Map Symbol [Symbol],
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova flag :: Bool }
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovadata Annotations = Annotations { annosOptPos :: [Pos],
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder annosLeft, annosRight :: [Annotation] }
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakovatype ExtPos = (Pos, TokenKind)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- Helper functions
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder-- helper functions on datatypes
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder------------------------------------------------------------------------------
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatoAnnotations :: Annoted a -> Annotations
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatoAnnotations a = Annotations (opt_pos a) (l_annos a) (r_annos a)
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatoAnnoted :: a ->Annotations -> Annoted a
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatoAnnoted a (Annotations x y z) = Annoted a x y z
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatoSigLocalEnv :: LocalEnv -> SigLocalEnv
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatoSigLocalEnv env = SigEnv env [] empty False
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyGlobal :: GlobalVars
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyGlobal = Global []
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptySentences :: Sentences
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptySentences = Sentences []
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyLocalEnv :: LocalEnv
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyLocalEnv =
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova Env "empty" emptyGlobalAnnos emptySign emptySentences emptyGlobal
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyExtPos :: ExtPos
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyExtPos = (nullPos, Key)
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyAnnotations :: Annotations
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyAnnotations = Annotations [] [] []
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaflattenSentences :: Sentences -> [(String, Sentence)]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaflattenSentences sens = map (\x -> (senName x,sentence x)) (sentences sens)
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaaddNamedSentences :: Sentences -> [NamedSentence] -> Sentences
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaaddNamedSentences (Sentences s) l = Sentences (setAdd s l)
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovamyShowList :: Show a => [a] -> String
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovamyShowList [] = "[]"
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovamyShowList [h] = "'" ++ show h ++ "'"
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovamyShowList (h:t) = "'" ++ (show h) ++ "', " ++ (myShowList t)
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyFilename :: Filename
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyFilename = ""
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovacloneAnnos :: Annoted a -> b -> Annoted b
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovacloneAnnos a b = a { item = b }
12d9bff7c82145a8b68bfb8553688172655c926eKristina SojakovalabelAnno :: String -> b -> Annoted b
12d9bff7c82145a8b68bfb8553688172655c926eKristina SojakovalabelAnno name itm = Annoted itm [] [] [Label [name] []]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovanoAnnos :: a -> Annoted a
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovanoAnnos itm = toAnnoted itm emptyAnnotations
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovaemptyAnnos :: Annoted ()
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovaemptyAnnos = noAnnos ()
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovaannoFilter :: Annotation -> Maybe Annotation
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovaannoFilter x = case x of Label _ _ -> Just x;
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovacloneAnnoFormula :: Annoted a -> b -> Annoted b
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovacloneAnnoFormula a b = Annoted b [] (mapMaybe annoFilter $ l_annos a)
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder (mapMaybe annoFilter $ r_annos a)
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovamergeAnnos :: Annoted a -> Annoted b -> Annoted b
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovamergeAnnos a b = b { opt_pos = setAdd (opt_pos a) (opt_pos b),
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova l_annos = setAdd (l_annos a) (l_annos b),
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova r_annos = setAdd (r_annos a) (r_annos b) }
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova------------------------------------------------------------------------------
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina Sojakova-- special functions to generate token lists from Pos lists
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova------------------------------------------------------------------------------
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovatoExtPos :: Maybe ExtPos -> [Pos] -> ([Pos] -> [TokenKind]) -> [ExtPos]
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovatoExtPos pref p f = let
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova tokens = (zip p (f p))
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova case pref of Nothing -> tokens
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova Just ep -> ep:tokens
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaedertokPos_sort_decl :: [Pos] -> [TokenKind]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatokPos_sort_decl l = replicate (length l) Comma
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatokPos_subsort_decl :: [Pos] -> [TokenKind]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatokPos_subsort_decl [] = []
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovatokPos_subsort_decl (_:t) = (replicate (length t) Comma) ++ [Less]
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovatokPos_subsort_defn :: [Pos] -> [TokenKind]
b470a3e54a4289b4189906e41f0c04578c85619dKristina SojakovatokPos_subsort_defn _ = [Equal,Key,Colon,Comma,Key]
5b84285ea066187061fc123a3b86b1b6433e06b5Kristina SojakovatokPos_iso_decl :: [Pos] -> [TokenKind]
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovatokPos_iso_decl l = replicate (length l) Colon
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_SORT_ITEM :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_SORT_ITEM [] = []
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_SORT_ITEM (_:t) = Key:(replicate (length t) Semi)
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina SojakovatokPos_pred_decl :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_pred_decl [] = []
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_pred_decl (_:t) = (replicate (length t) Comma) ++ [Colon]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_VAR_DECL :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_VAR_DECL = tokPos_pred_decl
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_pred_defn :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_pred_defn _ = [Key]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_ARG_DECL :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_ARG_DECL = tokPos_pred_decl
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina SojakovatokPos_ARG_DECL_list :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_ARG_DECL_list [] = []
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_ARG_DECL_list [_] = []
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina SojakovatokPos_ARG_DECL_list (_:(_:t)) = (Key:(replicate (length t) Semi)) ++ [Key]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_PRED_ITEM :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_PRED_ITEM = tokPos_SORT_ITEM
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina SojakovatokPos_VAR_ITEM :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_VAR_ITEM = tokPos_SORT_ITEM
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_local_var_axioms :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_local_var_axioms [] = []
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_local_var_axioms (_:t) = Key:(replicate (length t) Key)
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina SojakovatokPos_axiom_items :: [Pos] -> [TokenKind]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_axiom_items = tokPos_local_var_axioms
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_select :: [Pos] -> [TokenKind]
345d3dcc9f809776009851c446916fc770aa428dKristina SojakovatokPos_select = tokPos_pred_decl
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovatokPos_construct :: [Pos] -> [TokenKind]
345d3dcc9f809776009851c446916fc770aa428dKristina SojakovatokPos_construct = tokPos_SORT_ITEM
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatokPos_subsorts :: [Pos] -> [TokenKind]
a3a6b6ebe9c2d1dc3554e44779dc7361a90e7617Kristina SojakovatokPos_subsorts [] = []
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina SojakovatokPos_subsorts (_:t) = Key:(replicate (length t) Comma)
cb5d588c4c3b286cc1e7210335d6ef7f584d79bcKristina SojakovatokPos_DATATYPE_DECL :: [Pos] -> [TokenKind]
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovatokPos_DATATYPE_DECL l = replicate (length l) Key
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaedertokPos_datatype_items :: [Pos] -> [TokenKind]
45caf47cd6ed07be0637f6c51e4735512ce9d83aKristina SojakovatokPos_datatype_items = tokPos_SORT_ITEM
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovatokPos_OP_ITEM :: [Pos] -> [TokenKind]
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovatokPos_OP_ITEM = tokPos_SORT_ITEM
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova------------------------------------------------------------------------------
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova-- functions to generate labels
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina Sojakova------------------------------------------------------------------------------
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovasomeLabel :: String -> Annoted a -> String
8b054cade993ef373d564b2d74c9c5a2da48f8b7Kristina SojakovasomeLabel def x =
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina Sojakova labels = filter (\y -> case y of (Label _ _) -> True;
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova ((l_annos x)++(r_annos x))
f2f62e61c66f678b0042d1a772ff89849d8b2113Kristina Sojakova case labels of ((Label s _):_) -> concat s;
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaedertoLabel :: Show a => a -> String
51bbd37b3957f301b2628422e161aac2cbd46f1cKristina SojakovatoLabel x = toASCII $ show x
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- conversion from simple to compound datatypes
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoListPos :: ExtPos -> ListPos
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoListPos (pos,tok) = ListPos tok pos
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoItemPos :: Filename -> ExtPos -> ItemPos
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoItemPos name (pos,tok) = ItemPos name tok [pos]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovafromItemPos :: ItemPos -> ExtPos
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovafromItemPos (ItemPos _ kind []) = (nullPos,kind)
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaederfromItemPos (ItemPos _ kind l) = (head l,kind)
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaedertoVarDecl :: SortId -> ExtPos -> VAR -> VarDecl
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoVarDecl sort pos var = VarDecl var sort (toListPos pos)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoVarDecls :: SortId -> [ExtPos] -> [VAR] -> [VarDecl]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoVarDecls sort p v = map (uncurry (toVarDecl sort))
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (zip (extendList emptyExtPos v p) v)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatypeToVarDecl :: OpType -> [VarDecl]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatypeToVarDecl t = map (\(s,v) -> VarDecl v s (ListPos Key nullPos))
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova $ zip (opArgs t) $ map mkSimpleId $ map (\x -> "x" ++ x)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova $ map show $ [1..(length $ opArgs t)]
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaedertoVarId :: VarDecl -> Term
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoVarId v = VarId (simpleIdToId $ varId v) (varSort v) Inferred []
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaopToApplSentence :: OpItem -> [NamedSentence]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaopToApplSentence itm =
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova name = case (opId itm) of Id [Token n _] [] [] -> n;
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova optype = opType itm
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova vars = typeToVarDecl optype
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova terms = map toVarId vars
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova res = opRes optype
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder [NamedSen name
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (Axiom (noAnnos (AxiomDecl vars (ElemTest (OpAppl (opId itm) optype terms
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian Maeder Inferred []) res []) [])))]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoGenItems :: [OpItem] -> [Pos] -> NamedSentence
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoGenItems ops pos = NamedSen ""
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (GenItems (map (\x -> Symbol (opId x)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (OpAsItemType (opType x))) ops) pos)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoFunKind :: Bool -> FunKind
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoFunKind False = Partial
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoFunKind _ = Total
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovasortToSymbol :: SortId -> Symbol
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovasortToSymbol s = Symbol s CASL.Sign.Sort
fc08da86ea2ef76a631faca30ca30b8ed112d864Christian MaederopTypeIdToSymbol :: OpType -> Id -> Symbol
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaopTypeIdToSymbol typ idt = Symbol idt (OpAsItemType typ)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoNamedSentence :: [VarDecl] -> String -> Annoted Formula -> NamedSentence
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoNamedSentence vars str f =
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (Axiom (cloneAnnos f (AxiomDecl vars (item f) [])))
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- foldTwo: foldResult function over two lists
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- makes sure second list is at least as long as the first
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- add a default element if not
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- foldPos: same for foldl
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova------------------------------------------------------------------------------
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaextendList :: b -> [a] -> [b] -> [b]
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovaextendList def a b = if ((length b) < (length a)) then
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova b ++ replicate ((length a)-(length b)) def
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovafoldTwo :: a -> c -> (a -> b -> c -> Result a) -> [b] -> [c] -> Result a
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina SojakovafoldTwo state def f a b = foldM (\st (x, y) -> f st x y) state
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova (zip a (extendList def a b))
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovafoldlTwo :: c -> (a -> b -> c -> a) -> a -> [b] -> [c] -> a
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovafoldlTwo def f ini a b = foldl (\st (x, y) -> f st x y) ini
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova (zip a (extendList def a b))
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovafoldPos :: (Sign -> a -> ExtPos -> Sign) -> Sign -> [a] -> [ExtPos] -> Sign
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovafoldPos f sigma a pos = foldlTwo emptyExtPos f sigma a pos
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovachainPos :: b -> (b -> a -> ExtPos -> Result b) -> [a] -> [ExtPos] -> [Pos]
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova -> ([Pos] -> [TokenKind]) -> Result b
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovachainPos env f items positions addPos toStrFun =
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova foldTwo env emptyExtPos f items (positions ++ (zip addPos (toStrFun addPos)))
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova-- element test and selector functions for SigItem
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova------------------------------------------------------------------------------
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovahasElem :: Sign -> (Id -> SigItem -> Bool) -> Id -> Bool
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovahasElem sigma f idt =
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova res = lookup idt (getMap sigma)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova if (isJust res) then
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova or $ map (f idt) (fromJust res)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetElem :: Sign -> (Id -> SigItem -> Bool) -> Id -> Maybe SigItem
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetElem sigma f idt =
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova if (hasElem sigma f idt) then
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina Sojakova Just (head $ filter (f idt) $ fromJust $ lookup idt $ getMap sigma)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigSortItem :: Id -> SigItem -> Bool
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigSortItem idt (ASortItem s) = (sortId $ item s)==idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigSortItem _ _ = False
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigOpItem :: Id -> SigItem -> Bool
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigOpItem idt (AnOpItem o) = (opId $ item o)==idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigOpItem _ _ = False
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigPredItem :: Id -> SigItem -> Bool
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigPredItem idt (APredItem p) = (predId $ item p)==idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovaisSigPredItem _ _ = False
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoSortItem :: Maybe SigItem -> Maybe (Annoted SortItem)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoSortItem (Just (ASortItem s)) = Just s
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoSortItem _ = Nothing
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoOpItem :: Maybe SigItem -> Maybe (Annoted OpItem)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoOpItem (Just (AnOpItem o)) = Just o
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoOpItem _ = Nothing
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoPredItem :: Maybe SigItem -> Maybe (Annoted PredItem)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovatoPredItem (Just (APredItem p)) = Just p
887a1999374d1fb3a534e602a8d322de6ef4c8e8Kristina SojakovatoPredItem _ = Nothing
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovahasSort :: Sign -> SortId -> Bool
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovahasSort sigma idt = hasElem sigma isSigSortItem idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovahasOp :: Sign -> Id -> Bool
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovahasOp sigma idt = hasElem sigma isSigOpItem idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovahasPred :: Sign -> Id -> Bool
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovahasPred sigma idt = hasElem sigma isSigPredItem idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovalookupSort :: Sign -> SortId -> Maybe (Annoted SortItem)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovalookupSort sigma idt = toSortItem $ getElem sigma isSigSortItem idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovalookupOp :: Sign -> Id -> Maybe (Annoted OpItem)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovalookupOp sigma idt = toOpItem $ getElem sigma isSigOpItem idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovalookupPred :: Sign -> Id -> Maybe (Annoted PredItem)
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovalookupPred sigma idt = toPredItem $ getElem sigma isSigPredItem idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetSort :: Sign -> SortId -> Annoted SortItem
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetSort sigma idt = fromJust $ lookupSort sigma idt
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetOp :: Sign -> Id -> Annoted OpItem
9d770d1ea15092156d65e2a89b081eeeb8c6b153Kristina SojakovagetOp sigma idt = fromJust $ lookupOp sigma idt
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovagetPred :: Sign -> Id -> Annoted PredItem
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovagetPred sigma idt = fromJust $ lookupPred sigma idt
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova------------------------------------------------------------------------------
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova-- update function for SigItem in Sign
7caaddef0ccffd5528a7cde7cb0b7161250f4e59Kristina Sojakova------------------------------------------------------------------------------
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovaupdateSigItem :: Sign -> Id -> SigItem -> Sign
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina SojakovaupdateSigItem sigma idt itm =
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova res = lookup idt $ getMap sigma
df31d6f25f90e5112184f4eb60c8d3c7b116ca2dKristina Sojakova new = if (isNothing res) then
sig_COMPONENTS (CASL.AS_Basic_CASL.Sort s' ) = [s']
symbTypeToKind (CASL.Sign.Sort) = SortKind
sigItemToSymbol (ASortItem s) = Symbol (sortId $ item s) CASL.Sign.Sort
symOf :: Sign -> Set.Set Symbol
symOf sigma = Set.fromList $ map sigItemToSymbol
idToSortSymbol idt = Symbol idt CASL.Sign.Sort
matches (Symbol idt CASL.Sign.Sort) (AKindedId SortKind di) = idt==di