DevGraph.hs revision 98890889ffb2e8f6f722b00e265a211f13b5a861
License : GPLv2 or higher, see LICENSE.txt
Available from http://www.cofi.info
module Static.DevGraph where
import Syntax.AS_Structured
import Static.GTheory
import Logic.Logic
import Logic.ExtSign
import Logic.Comorphism
import Logic.Grothendieck
import Logic.Prover
import qualified Common.Lib.Rel as Rel
import qualified Common.Lib.Graph as Tree
import qualified Common.Lib.SizedList as SizedList
import qualified Common.OrderedMap as OMap
import Common.AS_Annotation
import Common.GlobalAnnotations
import Common.Id
import Common.Utils (numberSuffix, splitByList)
import Common.LibName
import Common.Consistency
import Control.Concurrent.MVar
import Control.Exception (assert)
import Data.Graph.Inductive.Basic
import Data.Graph.Inductive.Graph as Graph
import Data.List
import Data.Maybe
import qualified Data.Map as Map
import qualified Data.Set as Set
import Common.Result
import Debug.Trace
| DGBasicSpec G_basic_spec (Set.Set G_symbol)
newtype ProofBasis = ProofBasis { proofBasis :: Set.Set EdgeId }
type StUnitCtx = Map.Map SIMPLE_ID ImpUnitSigOrSig
emptyStUnitCtx = Map.empty
type RefSigMap = Map.Map SIMPLE_ID RefSig
type BStContext = Map.Map SIMPLE_ID RefSig
$ Map.toList bst
Map.toList rsm
error $ "getUnitSigFromRef:" ++ show (Map.keys rsm)
type RefStUnitCtx = Map.Map SIMPLE_ID RefSig
emptyRefStUnitCtx = Map.empty
&& namesMatchCtx (Map.keys rsmap) bstc rsmap
case (Map.findWithDefault (error "namesMatchCtx")
case Map.findWithDefault (error "USABS") un rsmap of
_ -> Map.size bstc' == 1 &&
let un1 = head $ Map.keys bstc'
rsmap' = Map.mapKeys (\ x -> if x == un then un1 else x)
Map.insert un (BranchRefSig (trace "1" $ compPointer n1 n2)
Map.insert un
BranchStaticContext $ modifyCtx (Map.keys rsmap') rsmap' bstc'))
_ -> let f = if Map.size bstc' == 1 then
let un1 = head $ Map.keys bstc'
rsmap' = Map.mapKeys
in Map.singleton un $
else Map.empty
in Map.union f $ modifyCtx unitNames rsmap bstc
modifyCtx (Map.keys rsmap) rsmap bstc)
else fail ("Signatures do not match:" ++ show (Map.keys bstc) ++ " "
++ show (Map.keys rsmap))
Map.union rsmap1 rsmap2
type GlobalEnv = Map.Map SIMPLE_ID GlobalEntry
type ProofHistory = SizedList.SizedList HistElem
n = Tree.getNewNode g
f = Map.insert s n $ specRoots dg'
-- n = Map.findWithDefault (error "addNodeRefRT") s $ specRoots dg
n' = Tree.getNewNode g
(g', _) = Tree.insLEdge True orderRT
l = Graph.lab g n
(g', _) = Tree.labelNode (n, newL) g
in dg' {specRoots = Map.insert s n $ specRoots dg}
copySubTree :: DGraph -> Node -> Maybe Node -> (DGraph, Map.Map Node Node)
n' = Tree.getNewNode rTree
in copySubTreeN dg {refTree = rTree'} [n] $ Map.fromList [(n, n')]
copySubTreeN dg [n] $ Map.fromList [(n, y)]
copySubTreeN :: DGraph -> [Node] -> Map.Map Node Node
-> (DGraph, Map.Map Node Node)
pairsN = Map.findWithDefault (error "copy") n pairs
copyNode :: Node -> (DGraph, Map.Map Node Node) -> LNode RTLinkLab
-> (DGraph, Map.Map Node Node)
n' = Tree.getNewNode rTree
Tree.insLEdge True orderRT (s, n', eLab) rTree'
in (dg {refTree = rTree''}, Map.insert n n' nMap)
(g', b) = Tree.insLEdge True orderRT
(g1, b1) = Tree.insLEdge True orderRT
| NPBranch Node (Map.Map SIMPLE_ID RTPointer)
| NPComp (Map.Map SIMPLE_ID RTPointer)
mapRTNodes :: Map.Map Node Node -> RTPointer -> RTPointer
mapRTNodes f rtp = let app = flip $ Map.findWithDefault (error "mapRTNodes")
NPBranch x g -> NPBranch (app f x) (Map.map (mapRTNodes f) g)
NPComp g -> NPComp (Map.map (mapRTNodes f) g)
NPBranch n1 (Map.unionWith (\ _ y -> y) f1 f2 )
NPComp (Map.unionWith (\ _ y -> y) f1 f2)
data RTLeaves = RTLeaf Node | RTLeaves (Map.Map SIMPLE_ID RTLeaves)
refTarget (NPComp f) = RTLeaves $ Map.map refTarget f
refTarget (NPBranch _ f) = RTLeaves $ Map.map refTarget f
diagGraph :: Tree.Gr DiagNodeLab DiagLinkLab,
, dgBody :: Tree.Gr DGNodeLab DGLinkLab -- ^ actual 'DGraph` tree
, refTree :: Tree.Gr RTNodeLab RTLinkLab -- ^ the refinement tree
, specRoots :: Map.Map String Node -- ^ root nodes for named specs
, archSpecDiags :: Map.Map String Diag
, refNodes :: Map.Map Node (LibName, Node) -- ^ unexpanded 'DGRef's
, allRefNodes :: Map.Map (LibName, Node) Node -- ^ all DGRef's
, sigMap :: Map.Map SigId G_sign -- ^ signature map
, thMap :: Map.Map ThId G_theory -- ^ morphism map
, morMap :: Map.Map MorId G_morphism -- ^ theory map
, globalEnv = Map.empty
, dgBody = Graph.empty
, refTree = Graph.empty
, specRoots = Map.empty
, archSpecDiags = Map.empty
, refNodes = Map.empty
, allRefNodes = Map.empty
, sigMap = Map.empty
, thMap = Map.empty
, morMap = Map.empty
, proofHistory = SizedList.empty
, redoHistory = SizedList.empty
type LibEnv = Map.Map LibName DGraph
emptyLibEnv = Map.empty
, dgn_symbolpathlist = G_symbolmap lid Map.empty }
emptyProofBasis = ProofBasis Set.empty
nullProofBasis = Set.null . proofBasis
addEdgeId (ProofBasis s) e = ProofBasis $ Set.insert e s
roughElem (_, _, label) = Set.member (dgl_id label) . proofBasis
setSigMapDG :: Map.Map SigId G_sign -> DGraph -> DGraph
setThMapDG :: Map.Map ThId G_theory -> DGraph -> DGraph
setMorMapDG :: Map.Map MorId G_morphism -> DGraph -> DGraph
lookupSigMapDG i = Map.lookup i . sigMap
lookupThMapDG i = Map.lookup i . thMap
lookupMorMapDG i = Map.lookup i . morMap
sigMapI :: DGraph -> (Map.Map SigId G_sign, SigId)
thMapI :: DGraph -> (Map.Map ThId G_theory, ThId)
morMapI :: DGraph -> (Map.Map MorId G_morphism, MorId)
lookupGlobalEnvDG sid = Map.lookup sid . globalEnv
lookupInRefNodesDG n = Map.lookup n . refNodes
Map.lookup (libn, refn) $ allRefNodes dg
dg { refNodes = Map.insert n (libn, refn) $ refNodes dg
, allRefNodes = Map.insert (libn, refn) n $ allRefNodes dg }
deleteFromRefNodesDG n dg = dg { refNodes = Map.delete n $ refNodes dg }
getNewNodeDG = Tree.getNewNode . dgBody
let (b, l) = Tree.labelNode p $ dgBody g in (g { dgBody = b }, l)
delLNodeDG n dg = dg { dgBody = Tree.delLNode (==) n $ dgBody dg }
{ dgBody = Tree.delLEdge (\ l1 l2 -> compare (dgl_id l1) $ dgl_id l2) e
, dgBody = fst $ Tree.insLEdge True (\ l1 l2 ->
(ng, change) = Tree.insLEdge False (\ l1 l2 ->
lookupDGraph ln = Map.findWithDefault (error $ "lookupDGraph " ++ show ln) ln
getLibDepRel :: LibEnv -> Rel.Rel LibName
getLibDepRel = Rel.transClosure
foldr ((\ x -> if isDGRef x then Set.insert (ln, dgn_libname x) else id)
. snd) s $ labNodesDG dg) Set.empty
topsortedLibsWithImports :: Rel.Rel LibName -> [LibName]
{- | Get imported libs in topological order, i.e. lib(s) without imports first.
in (Map.insert e
maybe Set.empty (\ ts -> case ts of
LeftOpen -> Set.empty
, if b && isLocalEdge (dgl_type l) then Set.insert e es else es))
new = Set.union nxt known
in filter (\ (_, _, l) -> dglPending l /= Set.member (dgl_id l) aPs) ls