{- |
Module      :  ./COL/StatAna.hs
Description :  Static analysis for COL
Copyright   :  (c) Christian Maeder, Uni Bremen 2004
License     :  GPLv2 or higher, see LICENSE.txt

Maintainer  :  till@informatik.uni-bremen.de
Stability   :  provisional
Portability :  portable

static analysis of COL parts
-}

module COL.StatAna where

import COL.AS_COL
import COL.COLSign

import CASL.StaticAna

import Common.AS_Annotation
import qualified Data.Set as Set
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
import Common.Id
import Common.Result

addConstructor :: Id -> COLSign -> Result COLSign
addConstructor :: Id -> COLSign -> Result COLSign
addConstructor i :: Id
i m :: COLSign
m = COLSign -> Result COLSign
forall (m :: * -> *) a. Monad m => a -> m a
return
       COLSign
m { constructors :: Set Id
constructors = Id -> Set Id -> Set Id
forall a. Ord a => a -> Set a -> Set a
Set.insert Id
i (Set Id -> Set Id) -> Set Id -> Set Id
forall a b. (a -> b) -> a -> b
$ COLSign -> Set Id
constructors COLSign
m }

addObserver :: (Id, Maybe Int) -> COLSign -> Result COLSign
addObserver :: (Id, Maybe Int) -> COLSign -> Result COLSign
addObserver (i :: Id
i, v :: Maybe Int
v) m :: COLSign
m = COLSign -> Result COLSign
forall (m :: * -> *) a. Monad m => a -> m a
return
       COLSign
m { observers :: Map Id Int
observers = Id -> Int -> Map Id Int -> Map Id Int
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert Id
i (Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe 0 Maybe Int
v) (Map Id Int -> Map Id Int) -> Map Id Int -> Map Id Int
forall a b. (a -> b) -> a -> b
$ COLSign -> Map Id Int
observers COLSign
m }

ana_COL_SIG_ITEM :: Ana COL_SIG_ITEM () COL_SIG_ITEM () COLSign
ana_COL_SIG_ITEM :: Ana COL_SIG_ITEM () COL_SIG_ITEM () COLSign
ana_COL_SIG_ITEM _ mi :: COL_SIG_ITEM
mi =
    case COL_SIG_ITEM
mi of
    Constructor_items al :: [Annoted Id]
al ps :: Range
ps -> do
        (Annoted Id -> State (Sign () COLSign) ())
-> [Annoted Id] -> State (Sign () COLSign) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((COLSign -> Result COLSign) -> State (Sign () COLSign) ()
forall e f. (e -> Result e) -> State (Sign f e) ()
updateExtInfo ((COLSign -> Result COLSign) -> State (Sign () COLSign) ())
-> (Annoted Id -> COLSign -> Result COLSign)
-> Annoted Id
-> State (Sign () COLSign) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Id -> COLSign -> Result COLSign
addConstructor (Id -> COLSign -> Result COLSign)
-> (Annoted Id -> Id) -> Annoted Id -> COLSign -> Result COLSign
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Annoted Id -> Id
forall a. Annoted a -> a
item) [Annoted Id]
al
        COL_SIG_ITEM -> State (Sign () COLSign) COL_SIG_ITEM
forall (m :: * -> *) a. Monad m => a -> m a
return (COL_SIG_ITEM -> State (Sign () COLSign) COL_SIG_ITEM)
-> COL_SIG_ITEM -> State (Sign () COLSign) COL_SIG_ITEM
forall a b. (a -> b) -> a -> b
$ [Annoted Id] -> Range -> COL_SIG_ITEM
Constructor_items [Annoted Id]
al Range
ps
    Observer_items al :: [Annoted (Id, Maybe Int)]
al ps :: Range
ps -> do
        (Annoted (Id, Maybe Int) -> State (Sign () COLSign) ())
-> [Annoted (Id, Maybe Int)] -> State (Sign () COLSign) ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((COLSign -> Result COLSign) -> State (Sign () COLSign) ()
forall e f. (e -> Result e) -> State (Sign f e) ()
updateExtInfo ((COLSign -> Result COLSign) -> State (Sign () COLSign) ())
-> (Annoted (Id, Maybe Int) -> COLSign -> Result COLSign)
-> Annoted (Id, Maybe Int)
-> State (Sign () COLSign) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Id, Maybe Int) -> COLSign -> Result COLSign
addObserver ((Id, Maybe Int) -> COLSign -> Result COLSign)
-> (Annoted (Id, Maybe Int) -> (Id, Maybe Int))
-> Annoted (Id, Maybe Int)
-> COLSign
-> Result COLSign
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Annoted (Id, Maybe Int) -> (Id, Maybe Int)
forall a. Annoted a -> a
item) [Annoted (Id, Maybe Int)]
al
        COL_SIG_ITEM -> State (Sign () COLSign) COL_SIG_ITEM
forall (m :: * -> *) a. Monad m => a -> m a
return (COL_SIG_ITEM -> State (Sign () COLSign) COL_SIG_ITEM)
-> COL_SIG_ITEM -> State (Sign () COLSign) COL_SIG_ITEM
forall a b. (a -> b) -> a -> b
$ [Annoted (Id, Maybe Int)] -> Range -> COL_SIG_ITEM
Observer_items [Annoted (Id, Maybe Int)]
al Range
ps