e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerDescription : apply xupdate changes to a development graph
e071fb22ea9923a2a4ff41184d80ca46b55ee932Till MossakowskiCopyright : (c) Christian Maeder, DFKI GmbH 2010
881f43de18aeae879886be203cd32e90051799c0Till MossakowskiLicense : GPLv2 or higher, see LICENSE.txt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuMaintainer : Christian.Maeder@dfki.de
881f43de18aeae879886be203cd32e90051799c0Till MossakowskiStability : provisional
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian MaederPortability : non-portable(Grothendieck)
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederadjust development graph according to xupdate information
881f43de18aeae879886be203cd32e90051799c0Till Mossakowskimodule Static.ApplyChanges (dgXUpdateMods, dgXUpdate) where
7857a35e3af533dfbd0f0e18638ebd211e6358a0Christian Maederimport Static.History (undoAllChanges, changeDGH, clearHistory)
881f43de18aeae879886be203cd32e90051799c0Till Mossakowskiimport Driver.ReadFn (libNameToFile)
881f43de18aeae879886be203cd32e90051799c0Till Mossakowskiimport Driver.WriteFn (writeVerbFile)
881f43de18aeae879886be203cd32e90051799c0Till Mossakowskiimport Comorphisms.LogicGraph (logicGraph)
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederimport Data.Graph.Inductive.Graph (Node, match, lab)
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederimport qualified Data.List as List (nub)
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederimport qualified Data.Set as Set
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederimport qualified Data.Map as Map
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederimport Text.XML.Light hiding (Node)
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder{- incorporate a previous session (diff) upon an exising dgraph. The structure
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maederis as follows:
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder - roll back the current dg to it's initial state
2bbf88585fe313af8585da0288880310cc1b027dChristian Maeder - apply diff to initial dg
a65c6747c9acbbebc93baba7bae94d2e3d8cdafbTill Mossakowski - create xgraph from dg'
e85b224577b78d08ba5c39fe9dcc2e53995454a2Christian Maeder - incorporate changes into current dg; the xgraph serves for structuring.
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian MaederNOTE: The data-type NodeMod holds information about the changes upon a node.
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian MaederHowever, with the current usage, a Boolean value would do since the module only
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederknows update or don't-update. We kept the NodeMod-approach since proper usage
cd6e5706893519bfcf24539afa252fcbed5097ddKlaus Luettichof the NodeMod data type might allow more precise updating.
2bbf88585fe313af8585da0288880310cc1b027dChristian MaederNOTE(2): If any element changes, ALL elements that lie underneath in terms of
a64026be6c3fd217259aab4ee0a5934192255e88mscodescusignature-hierachy will receive updating as well (even if two subsequent
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederchanges would lead to an unchanged signature further down). -}
2bbf88585fe313af8585da0288880310cc1b027dChristian Maeder-- | recieves diff as a string and current dg and prepares those for processing
da955132262baab309a50fdffe228c9efe68251dCui JiandgXUpdate :: HetcatsOpts -> String -> LibEnv -> LibName -> DGraph
881f43de18aeae879886be203cd32e90051799c0Till Mossakowski -> ResultT IO (LibName, LibEnv)
e85b224577b78d08ba5c39fe9dcc2e53995454a2Christian MaederdgXUpdate opts xs le ln dg = case parseXMLDoc xs of
e85b224577b78d08ba5c39fe9dcc2e53995454a2Christian Maeder Nothing -> fail "dgXUpdate: cannot parse xupdate file"
881f43de18aeae879886be203cd32e90051799c0Till Mossakowski Just diff -> let
e85b224577b78d08ba5c39fe9dcc2e53995454a2Christian Maeder -- we assume that the diff refers to an unchanged dg..
e85b224577b78d08ba5c39fe9dcc2e53995454a2Christian Maeder dgOld = undoAllChanges dg
eca4db63ed0bdbd93b62678feea6e3eb80aa47bbChristian Maeder oldLId = getNewEdgeId dgOld
d6c6b2543c509ec7f6213e4cba675d96304a7fd6Christian Maeder xorig = dGraph opts le ln dgOld
d6c6b2543c509ec7f6213e4cba675d96304a7fd6Christian Maeder in dgXUpdateMods opts xorig oldLId diff le ln dg
2bbf88585fe313af8585da0288880310cc1b027dChristian Maeder{- | updates a dgraph partially in accordance with changelist data from a .diff
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederapplication. an xgraph is created and used as a guideline for signature-
2bbf88585fe313af8585da0288880310cc1b027dChristian Maederhierachy and for retrieving required new data. -}
e85b224577b78d08ba5c39fe9dcc2e53995454a2Christian MaederdgXUpdateMods :: HetcatsOpts -> Element -> EdgeId -> Element -> LibEnv
2bbf88585fe313af8585da0288880310cc1b027dChristian Maeder -> LibName -> DGraph -> ResultT IO (LibName, LibEnv)
fbf1cdad9a9775bd7332e85f01b6a307d7dbb1cfChristian MaederdgXUpdateMods opts xorig oldLId diff le ln dg = do
fbf1cdad9a9775bd7332e85f01b6a307d7dbb1cfChristian Maeder -- dg with changes incorporated (diff only) and listing of these changes
7857a35e3af533dfbd0f0e18638ebd211e6358a0Christian Maeder (xml, chL) <- liftR $ changeXmlMod xorig diff
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian Maeder lift $ writeVerbFile opts (libNameToFile ln ++ ".xml")
a7be28e157e9ceeec73a8fd0e642c36ea29d4218Christian Maeder $ ppTopElement $ cleanUpElem xml
a7be28e157e9ceeec73a8fd0e642c36ea29d4218Christian Maeder xgr <- liftR $ xGraph xml
a7be28e157e9ceeec73a8fd0e642c36ea29d4218Christian Maeder -- the changes will now be incorporated in the so-far unchanged session-dg.
a7be28e157e9ceeec73a8fd0e642c36ea29d4218Christian Maeder (dg0, chL') <- liftR $ deleteElements dg chL
fbf1cdad9a9775bd7332e85f01b6a307d7dbb1cfChristian Maeder let newLId = max (nextLinkId xgr) $ getNewEdgeId dg
e85b224577b78d08ba5c39fe9dcc2e53995454a2Christian Maeder -- to anticipate multiple use of link-ids
9eb39c7a0e7a1ddad1eec1d23c6d4e3a99c54023Christian Maeder dg1 = renumberDGLinks oldLId newLId dg0
2bbf88585fe313af8585da0288880310cc1b027dChristian Maeder dg2 = dg1 { globalAnnos = globAnnos xgr
2bbf88585fe313af8585da0288880310cc1b027dChristian Maeder -- TODO as of now, ALL nodes will be removed from globalEnv!
2bbf88585fe313af8585da0288880310cc1b027dChristian Maeder , globalEnv = Map.empty }
e85b224577b78d08ba5c39fe9dcc2e53995454a2Christian Maeder (dg3, le', chL'') <- iterateXgBody opts xgr le dg2 chL'
2bbf88585fe313af8585da0288880310cc1b027dChristian Maeder -- for any leftover theorem link updates, the respective links are deleted
cd6e5706893519bfcf24539afa252fcbed5097ddKlaus Luettich dgFin <- fmap clearHistory $ deleteLeftoverChanges dg3 chL''
cd6e5706893519bfcf24539afa252fcbed5097ddKlaus Luettich return (ln, computeLibEnvTheories $ Map.insert ln dgFin le')
deleteLeftoverChanges dg chL = let lIds = Map.keys $ changeLinks chL in do
unless (emptyChangeList == chL { changeLinks = Map.empty })
case Map.lookup (edgeId xl) $ changeLinks chL of
-- make insertion using DGChange.InsertNode object
-- make update using DGChange.SetNodeLab object
(dg1, targets) <- foldM deleteLinkAux (dg, []) $ Set.toList $ deleteLinks chL
dg2 <- foldM (\ dg' -> liftM snd . deleteNode dg') dg1 $ Set.toList
chL' <- foldM (flip $ markNodeUpdates dg2) chL $ List.nub targets