AnalysisStructured.hs revision 53ea24e19dbd4ca72fd75ab3a3105dc9f99e4f81
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian MaederModule : $Header$
e6d40133bc9f858308654afb1262b8b483ec5922Till MossakowskiDescription : static analysis of heterogeneous structured specifications
1549f3abf73c1122acff724f718b615c82fa3648Till MossakowskiCopyright : (c) Till Mossakowski and Uni Bremen 2003-2006
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian MaederMaintainer : till@informatik.uni-bremen.de
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederStability : provisional
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian MaederPortability : non-portable (imports Logic.Grothendieck)
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederStatic analysis of CASL (heterogeneous) structured specifications
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski Follows the verfication semantic rules in Chap. IV:4.7
1549f3abf73c1122acff724f718b615c82fa3648Till Mossakowski of the CASL Reference Manual.
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder , getSpecAnnos
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder , isStructured
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski , anaRenaming
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang , anaRestriction
23a00c966f2aa8da525d7a7c51933c99964426c0Christian Maeder , partitionGmaps
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder , homogenizeGM
8c63cd89ef840cd7a3d3b75f0207dc800388c800Christian Maeder , extendMorphism
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maederimport Common.AS_Annotation hiding (isAxiom, isDef)
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maederimport Common.Lib.MapSet (imageSet, setInsert)
9eb39c7a0e7a1ddad1eec1d23c6d4e3a99c54023Christian Maederimport Data.Graph.Inductive.Graph as Graph (Node)
9eb39c7a0e7a1ddad1eec1d23c6d4e3a99c54023Christian Maederimport qualified Data.Set as Set
9eb39c7a0e7a1ddad1eec1d23c6d4e3a99c54023Christian Maederimport qualified Data.Map as Map
9eb39c7a0e7a1ddad1eec1d23c6d4e3a99c54023Christian MaedercoerceMaybeNode :: LogicGraph -> DGraph -> MaybeNode -> NodeName -> AnyLogic
9eb39c7a0e7a1ddad1eec1d23c6d4e3a99c54023Christian Maeder -> Result (MaybeNode, DGraph)
9eb39c7a0e7a1ddad1eec1d23c6d4e3a99c54023Christian MaedercoerceMaybeNode lg dg mn nn l2 = case mn of
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder EmptyNode _ -> return (EmptyNode l2, dg)
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder JustNode ns -> do
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder (ms, dg2) <- coerceNode lg dg ns nn l2
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder return (JustNode ms, dg2)
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian MaedercoerceNode :: LogicGraph -> DGraph -> NodeSig -> NodeName -> AnyLogic
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder -> Result (NodeSig, DGraph)
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian MaedercoerceNode lg dg ns@(NodeSig _ (G_sign lid1 _ _)) nn l2@(Logic lid2) =
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder if language_name lid1 == language_name lid2 then return (ns, dg)
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder c <- logicInclusion lg (Logic lid1) l2
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder coerceNodeByComorph c dg ns nn
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian MaedercoerceNodeByComorph :: AnyComorphism -> DGraph -> NodeSig -> NodeName
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski -> Result (NodeSig, DGraph)
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian MaedercoerceNodeByComorph c dg (NodeSig n s) nn = do
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder gmor <- gEmbedComorphism c s
fa167e362877db231378e17ba49c66fbb84862fcChristian Maeder case find (\ (_, _, l) -> dgl_origin l == SeeTarget
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder && dgl_type l == globalDef
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder && dgl_morphism l == gmor) $ outDG dg n of
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder Nothing -> do
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder let (ms@(NodeSig m _), dg2) =
6a22b2854c3bc9cb4877cb7d29049d6559238639Christian Maeder insGSig dg (extName "XCoerced" nn) DGLogicCoercion $ cod gmor
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder dg3 = insLink dg2 gmor globalDef SeeTarget n m
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder return (ms, dg3)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Just (_, t, _) ->
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder return (NodeSig t $ signOf $ dgn_theory $ labDG dg t, dg)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill MossakowskiinsGTheory :: DGraph -> NodeName -> DGOrigin -> G_theory -> (NodeSig, DGraph)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill MossakowskiinsGTheory dg name orig (G_theory lid sig ind sens tind) =
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder let (sgMap, s) = sigMapI dg
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder (tMap, t) = thMapI dg
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder nind = if ind == startSigId then succ s else ind
4b6aa93c12e4db86ccc7694a48a73e9cf7262d06Christian Maeder tb = tind == startThId && not (Map.null sens)
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder ntind = if tb then succ t else tind
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder nsig = G_sign lid sig nind
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder nth = G_theory lid sig nind sens ntind
4601edb679f0ba530bbb085b25d82a411cd070aaChristian Maeder node_contents = newNodeLab name orig nth
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder node = getNewNodeDG dg
26d11a256b1433604a3dbc69913b520fff7586acChristian Maeder in (NodeSig node nsig,
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder (if tb then setThMapDG $ Map.insert (succ t) nth tMap else id) $
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder (if ind == startSigId
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder then setSigMapDG $ Map.insert (succ s) nsig sgMap else id)
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder $ insNodeDG (node, node_contents) dg)
03136b84a0c70d877e227444f0875e209506b9e4Christian MaederinsGSig :: DGraph -> NodeName -> DGOrigin -> G_sign -> (NodeSig, DGraph)
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian MaederinsGSig dg name orig (G_sign lid sig ind) =
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder insGTheory dg name orig $ noSensGTheory lid sig ind
aea143fff7a50aceb809845fbc42698b0b3f545aChristian MaederinsLink :: DGraph -> GMorphism -> DGLinkType -> DGLinkOrigin -> Node -> Node
aea143fff7a50aceb809845fbc42698b0b3f545aChristian MaederinsLink dg (GMorphism cid sign si mor mi) ty orig n t =
6a22b2854c3bc9cb4877cb7d29049d6559238639Christian Maeder let (sgMap, s) = sigMapI dg
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder (mrMap, m) = morMapI dg
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder nsi = if si == startSigId then succ s else si
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder nmi = if mi == startMorId then succ m else mi
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder nmor = GMorphism cid sign nsi mor nmi
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder link = defDGLink nmor ty orig
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder in (if mi == startMorId then setMorMapDG $ Map.insert (succ m)
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder (toG_morphism nmor) mrMap else id) $
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder (if si == startSigId then setSigMapDG $ Map.insert (succ s)
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder (G_sign (sourceLogic cid) sign nsi) sgMap else id)
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder $ insLEdgeNubDG (n, t, link) dg
5e46b572ed576c0494768998b043d9d340594122Till MossakowskicreateConsLink :: LinkKind -> Conservativity -> LogicGraph -> DGraph
74d9a385499bf903b24848dff450a153f525bda7Christian Maeder -> MaybeNode -> NodeSig -> DGLinkOrigin -> Result DGraph
03136b84a0c70d877e227444f0875e209506b9e4Christian MaedercreateConsLink lk conser lg dg nsig (NodeSig node gsig) orig = case nsig of
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder EmptyNode _ | conser == None -> return dg
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder _ -> case nsig of
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder JustNode (NodeSig n sig) -> do
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder incl <- ginclusion lg sig gsig
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder return $ insLink dg incl
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder (ScopedLink Global lk $ mkConsStatus conser) orig n node
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder EmptyNode _ -> -- add conservativity to the target node
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder return $ let lbl = labDG dg node
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder in if isDGRef lbl then dg else
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder fst $ labelNodeDG
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder (nodeInfo lbl)
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder { node_cons_status = case getNodeConsStatus lbl of
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder ConsStatus c d th -> ConsStatus (max c conser) d th }}) dg
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian MaederanaSpecTop :: Conservativity -> Bool -> LogicGraph -> LibName -> DGraph
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -> MaybeNode -> NodeName -> HetcatsOpts -> SPEC
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -> Result (SPEC, NodeSig, DGraph)
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian MaederanaSpecTop conser addSyms lg ln dg nsig name opts sp =
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder if conser == None || case sp of
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder -- for these cases def-links are re-used
8c63cd89ef840cd7a3d3b75f0207dc800388c800Christian Maeder Basic_spec _ _ -> True
8c63cd89ef840cd7a3d3b75f0207dc800388c800Christian Maeder Closed_spec _ _ -> True
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder Spec_inst _ _ _ -> True
8c63cd89ef840cd7a3d3b75f0207dc800388c800Christian Maeder Group _ _ -> True -- in this case we recurse
8c63cd89ef840cd7a3d3b75f0207dc800388c800Christian Maeder then anaSpecAux conser addSyms lg ln dg nsig name opts sp else do
8c63cd89ef840cd7a3d3b75f0207dc800388c800Christian Maeder let provenThmLink =
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski ThmLink $ Proven (DGRule "static analysis") emptyProofBasis
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder (rsp, ns, rdg) <- anaSpec addSyms lg ln dg nsig name opts sp
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder ndg <- createConsLink provenThmLink conser lg rdg nsig ns SeeTarget
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder return (rsp, ns, ndg)
99476ac2689c74251219db4782e57fe713a24a52Christian MaederanaFreeOrCofreeSpec :: Bool -> LogicGraph -> HetcatsOpts -> LibName -> DGraph
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder -> MaybeNode -> NodeName -> FreeOrCofree -> Annoted SPEC -> Range
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder -> Result (Annoted SPEC, NodeSig, DGraph)
99476ac2689c74251219db4782e57fe713a24a52Christian MaederanaFreeOrCofreeSpec addSyms lg opts ln dg nsig name dglType asp pos =
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder adjustPos pos $ do
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder (sp', NodeSig n' gsigma, dg') <-
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder anaSpec addSyms lg ln dg nsig (extName (show dglType) name) opts
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder let (ns@(NodeSig node _), dg2) =
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder insGSig dg' name (DGFreeOrCofree dglType) gsigma
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder nsigma = case nsig of
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder EmptyNode cl -> emptyG_sign cl
88124ca824f94153b0a2a24ea1e4b089fff7011fChristian Maeder JustNode nds -> getSig nds
88124ca824f94153b0a2a24ea1e4b089fff7011fChristian Maeder incl <- ginclusion lg nsigma gsigma
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder return (replaceAnnoted sp' asp, ns,
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder insLink dg2 incl (FreeOrCofreeDefLink dglType nsig)
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder SeeTarget n' node)
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder{- | analyze a SPEC. The Bool Parameter determines if incoming symbols shall
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maederbe ignored. The options are needed to check: shall only the structure be
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian MaederanaSpec :: Bool -> LogicGraph -> LibName -> DGraph -> MaybeNode -> NodeName
88124ca824f94153b0a2a24ea1e4b089fff7011fChristian Maeder -> HetcatsOpts -> SPEC -> Result (SPEC, NodeSig, DGraph)
88124ca824f94153b0a2a24ea1e4b089fff7011fChristian MaederanaSpec = anaSpecAux None
88124ca824f94153b0a2a24ea1e4b089fff7011fChristian MaederanaSpecAux :: Conservativity -> Bool -> LogicGraph -> LibName -> DGraph
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder -> MaybeNode -> NodeName -> HetcatsOpts -> SPEC
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder -> Result (SPEC, NodeSig, DGraph)
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian MaederanaSpecAux conser addSyms lg ln dg nsig name opts sp = case sp of
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder Basic_spec (G_basic_spec lid bspec) pos -> adjustPos pos $ do
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder let curLogic = Logic lid
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder (nsig', dg0) <- coerceMaybeNode lg dg nsig name curLogic
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder G_sign lid' sigma' _ <- return $ case nsig' of
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder EmptyNode cl -> emptyG_sign cl
8c63cd89ef840cd7a3d3b75f0207dc800388c800Christian Maeder JustNode ns -> getSig ns
8c63cd89ef840cd7a3d3b75f0207dc800388c800Christian Maeder ExtSign sig sys <-
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder coerceSign lid' lid "Analysis of basic spec" sigma'
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (bspec', ExtSign sigma_complete sysd, ax) <-
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder if isStructured opts
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder then return (bspec, mkExtSign $ empty_signature lid, [])
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let res@(Result ds mb) = extBasicAnalysis lid (getName name)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (getLibId ln) bspec sig $ globalAnnos dg0
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder in case mb of
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder Nothing | null ds ->
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder fail "basic analysis failed without giving a reason"
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder diffSig <- case signatureDiff lid sigma_complete sig of
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder Result _ (Just ds) -> return ds
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder _ -> warning sigma_complete
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder "signature difference could not be computed using full one" pos
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder let gsysd = Set.map (G_symbol lid) sysd
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder (ns, dg') = insGTheory dg0 name
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder (DGBasicSpec (Just $ G_basic_spec lid bspec')
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder (G_sign lid (mkExtSign diffSig) startSigId) gsysd)
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder $ G_theory lid (ExtSign sigma_complete
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder (if addSyms then Set.union sys sysd else sysd)
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder $ symset_of lid sigma_complete)
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder startSigId (toThSens ax) startThId
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder dg'' <- createConsLink DefLink conser lg dg' nsig' ns DGLinkExtension
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder return (Basic_spec (G_basic_spec lid bspec') pos, ns, dg'')
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder EmptySpec pos -> case nsig of
99476ac2689c74251219db4782e57fe713a24a52Christian Maeder EmptyNode _ -> do
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder warning () "empty spec" pos
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder let (ns, dg') = insGSig dg name DGEmpty (getMaybeSig nsig)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder return (sp, ns, dg')
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder {- anaSpec should be changed to return a MaybeNode!
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder Then this duplicate dummy node could be avoided.
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder Also empty unions could be treated then -}
6a22b2854c3bc9cb4877cb7d29049d6559238639Christian Maeder JustNode ns -> return (sp, ns , dg)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Translation asp ren ->
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder do let sp1 = item asp
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder (sp1', ns'@(NodeSig n' gsigma), dg') <-
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder anaSpec addSyms lg ln dg nsig (extName "Translation" name) opts sp1
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder mor <- anaRenaming lg nsig gsigma opts ren
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder -- ??? check that mor is identity on local env
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder when (isIdentity mor) $ warning ()
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder ("nothing renamed by:\n" ++ showDoc ren "") $ getRange ren
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder (fs, dgf) <- if isIdentity mor && isInternal name then return (ns', dg')
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder let (ns@(NodeSig node _), dg'') =
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder insGSig dg' name (DGTranslation $ Renamed ren) $ cod mor
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder -- ??? too simplistic for non-comorphism inter-logic translations
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder return (ns, insLink dg'' mor globalDef SeeTarget n' node)
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder return (Translation (replaceAnnoted sp1' asp) ren, fs, dgf)
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder Reduction asp restr ->
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder do let sp1 = item asp
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder rname = extName "Restriction" name
6a22b2854c3bc9cb4877cb7d29049d6559238639Christian Maeder (sp1', ns0, dg0) <- anaSpec addSyms lg ln dg nsig rname opts sp1
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder rLid <- getRestrLogic restr
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder p1@(NodeSig n' gsigma', dg') <- coerceNode lg dg0 ns0 rname rLid
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder (hmor, tmor) <- anaRestriction lg (getMaybeSig nsig) gsigma' opts restr
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder let noRename = maybe True isIdentity tmor
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder noHide = isIdentity hmor
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder when noHide $ (if noRename then warning else hint) ()
0b6f6d3eeb7b3b36292e60f1b3da5a5ce42eef1aChristian Maeder ("nothing hidden by:\n" ++ showDoc restr "") $ getRange restr
200849122a9c65773e5b2ba8084ac3490d0490b5Christian Maeder p2@(NodeSig node1 _, dg2) <- if noHide && isInternal name then return p1
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder let trgSg = dom hmor
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder hidSyms = Set.difference (symsOfGsign gsigma')
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder $ symsOfGsign trgSg
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder orig = DGRestriction (Restricted restr) hidSyms
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder (ns@(NodeSig node _), dg'') = insGSig dg'
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder (if noRename then name else extName "Hiding" name)
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder -- ??? too simplistic for non-comorphism inter-logic reductions
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder return (ns, insLink dg'' hmor HidingDefLink SeeTarget n' node)
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder {- we treat hiding and revealing differently
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder in order to keep the dg as simple as possible -}
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder (fs, dgf) <- case tmor of
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder Just tmor' | not noRename -> do
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder let (ns@(NodeSig node2 _), dg3) =
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder insGSig dg2 name DGRevealTranslation $ cod tmor'
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder return (ns, insLink dg3 tmor' globalDef SeeTarget node1 node2)
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder Nothing -> return p2
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder _ -> hint p2 ("nothing renamed by:\n" ++ showDoc restr "")
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder $ getRange restr
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder return (Reduction (replaceAnnoted sp1' asp) restr, fs, dgf)
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder Union asps pos -> do
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder (newAsps, _, ns, dg') <- adjustPos pos $ anaUnion addSyms lg ln dg nsig
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder name opts asps
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder return (Union newAsps pos, ns, dg')
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder Extension asps pos -> do
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder let namedSps = map (\ (asp, n) ->
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder let nn = incBy n (extName "Extension" name) in
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder if n < length asps then (nn, asp)
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder else (name { xpath = xpath nn }, asp)) $ number asps
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder (sps', nsig1', dg1, _, _) <- foldM (anaExtension lg opts ln pos)
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder ([], nsig, dg, conser, addSyms) namedSps
2561b4bfc45d280ee2be8a7870314670e4e682e4Christian Maeder case nsig1' of
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder EmptyNode _ -> fail "empty extension"
01aafb6a9520f05df5ff467b591ecb5474dcfc86Christian Maeder JustNode nsig1 -> return (Extension (zipWith replaceAnnoted
fa167e362877db231378e17ba49c66fbb84862fcChristian Maeder (reverse sps') asps)
fa167e362877db231378e17ba49c66fbb84862fcChristian Maeder pos, nsig1, dg1)
fa167e362877db231378e17ba49c66fbb84862fcChristian Maeder Free_spec asp poss -> do
fa167e362877db231378e17ba49c66fbb84862fcChristian Maeder (nasp, nsig', dg') <- anaFreeOrCofreeSpec addSyms lg opts ln dg nsig
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder name Free asp poss
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder return (Free_spec nasp poss, nsig', dg')
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder Cofree_spec asp poss -> do
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder (nasp, nsig', dg') <- anaFreeOrCofreeSpec addSyms lg opts ln dg nsig
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder name Cofree asp poss
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder return (Cofree_spec nasp poss, nsig', dg')
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski Local_spec asp asp' poss -> adjustPos poss $ do
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder let sp1 = item asp
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder sp1' = item asp'
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder lname = extName "Local" name
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder (sp2, nsig'@(NodeSig _ gsig1), dg') <-
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder anaSpec False lg ln dg nsig (extName "Spec" lname) opts sp1
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder (sp2', NodeSig n'' gsig2@(G_sign lid2 sigma2 _), dg'') <- anaSpec False lg
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder ln dg' (JustNode nsig') (extName "Within" lname) opts sp1'
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder let gSigN = getMaybeSig nsig
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder (G_sign lid sigmaN _, _) <- gSigCoerce lg gSigN (Logic lid2)
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder sigma <- coerceSign lid lid2 "Analysis of local spec1" sigmaN
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder (G_sign lid' sigma' _, _) <- gSigCoerce lg gsig1 (Logic lid2)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder sigma1 <- coerceSign lid' lid2 "Analysis of local spec2" sigma'
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder let sys = ext_sym_of lid2 sigma
e01299e9b22b96b31b720ca1e9f9f5f25af9b024Christian Maeder sys1 = ext_sym_of lid2 sigma1
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder sys2 = ext_sym_of lid2 sigma2
44d2a211a352759ee988ed8353026f5fa9511209Christian Maeder mor3 <- if isStructured opts then return (ext_ide sigma2)
44d2a211a352759ee988ed8353026f5fa9511209Christian Maeder else ext_cogenerated_sign lid2
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder (sys1 `Set.difference` sys) sigma2
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder let sigma3 = dom mor3
4fc727afa544a757d1959ce77c02208f8bf330dcChristian Maeder gsigma3 = G_sign lid2 (makeExtSign lid2 sigma3) startSigId
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder sys3 = symset_of lid2 sigma3
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder unless (isStructured opts
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder || sys2 `Set.difference` sys1 `Set.isSubsetOf` sys3)
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder $ plain_error () (
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder "illegal use of locally declared symbols: "
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder ++ showDoc ((sys2 `Set.intersection` sys1) `Set.difference` sys3) "")
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder let hidSyms = Set.difference (symsOfGsign gsig2) $ symsOfGsign gsigma3
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder orig = DGRestriction NoRestriction hidSyms
4fc727afa544a757d1959ce77c02208f8bf330dcChristian Maeder (ns@(NodeSig node _), dg2) = insGSig dg'' name orig gsigma3
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder return (Local_spec (replaceAnnoted sp2 asp)
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder (replaceAnnoted sp2' asp')
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder insLink dg2 (gEmbed2 gsigma3 $ mkG_morphism lid2 mor3)
68138d26bcddf5e89c30206aa83ab5ec006d170dChristian Maeder HidingDefLink SeeTarget n'' node)
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder Closed_spec asp pos -> adjustPos pos $ do
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder let sp1 = item asp
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder l = getLogic nsig
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder -- analyse spec with empty local env
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder (sp', NodeSig n' gsigma', dg') <- anaSpec False lg ln dg
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder (EmptyNode l) (extName "Closed" name) opts sp1
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder gsigma2 <- gsigUnionMaybe lg nsig gsigma'
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder let (ns@(NodeSig node _), dg2) = insGSig dg' name DGClosed gsigma2
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski incl2 <- ginclusion lg gsigma' gsigma2
74d9a385499bf903b24848dff450a153f525bda7Christian Maeder let dg3 = insLink dg2 incl2 globalDef SeeTarget n' node
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski dg4 <- createConsLink DefLink conser lg dg3 nsig ns DGLinkClosedLenv
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder return (Closed_spec (replaceAnnoted sp' asp) pos, ns, dg4)
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder Qualified_spec lognm asp pos -> adjustPos pos $ do
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski let newLG = setLogicName lognm lg
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder l <- lookupCurrentLogic "Qualified_spec" newLG
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski let newNSig = case nsig of
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder EmptyNode _ -> EmptyNode l
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski qname = extName "Qualified" name
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski (sp', ns', dg') <- anaSpec addSyms newLG ln dg newNSig qname opts
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder (ns, dg2) <- coerceNode lg dg' ns' qname l
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder return (Qualified_spec lognm asp { item = sp' } pos, ns, dg2)
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski Group asp pos -> do
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder (sp', nsig', dg') <-
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder anaSpecTop conser addSyms lg ln dg nsig name opts (item asp)
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder return (Group (replaceAnnoted sp' asp) pos, nsig', dg')
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder Spec_inst spname afitargs pos0 -> let
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder pos = if null afitargs then tokPos spname else pos0
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder in adjustPos pos $ case lookupGlobalEnvDG spname dg of
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder Just (SpecEntry gs@(ExtGenSig (GenSig _ params _)
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder body@(NodeSig nB gsigmaB))) ->
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder case (length afitargs, length params) of
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder -- the case without parameters leads to a simpler dg
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder (0, 0) -> case nsig of
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder -- if the node shall not be named and the logic does not change,
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder EmptyNode _ | isInternal name -> do
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder dg2 <- createConsLink DefLink conser lg dg nsig body SeeTarget
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder -- then just return the body
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder return (sp, body, dg2)
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder -- otherwise, we need to create a new one
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder gsigma <- gsigUnionMaybe lg nsig gsigmaB
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder let (fsig@(NodeSig node _), dg2) =
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder insGSig dg name (DGInst spname) gsigma
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder incl <- ginclusion lg gsigmaB gsigma
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder let dg3 = case nsig of
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder JustNode (NodeSig nI _) | nI == nB -> dg2
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder _ -> insLink dg2 incl globalDef (DGLinkMorph spname) nB node
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder dg4 <- createConsLink DefLink conser lg dg3 nsig fsig SeeTarget
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder return (sp, fsig, dg4)
ebc51e8081f6f1fe2f3d39ceff81d8dd0169c0b0Christian Maeder -- now the case with parameters
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder (la, lp) | la == lp -> do
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder (ffitargs, dg', (morDelta, gsigmaA, ns@(NodeSig nA gsigmaRes))) <-
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski anaAllFitArgs lg opts ln dg nsig name spname gs afitargs
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder GMorphism cid _ _ _ _ <- return morDelta
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder morDelta' <- case nsig of
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder | logicOfGsign gsigmaA == logicOfGsign gsigmaRes
03136b84a0c70d877e227444f0875e209506b9e4Christian Maeder -> return morDelta
5a9a06d23910b9521e1d1cd39865ac7912ccee4bChristian Maeder _ -> ginclusion lg gsigmaA gsigmaRes >>= comp morDelta
5a9a06d23910b9521e1d1cd39865ac7912ccee4bChristian Maeder (_, imor) <- gSigCoerce lg gsigmaB $ Logic $ sourceLogic cid
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder tmor <- gEmbedComorphism imor gsigmaB
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder morDelta'' <- comp tmor morDelta'
329d1810c6d5a5a0827e1d07503d94431578d176Christian Maeder let dg4 = case nsig of
5e46b572ed576c0494768998b043d9d340594122Till Mossakowski JustNode (NodeSig nI _) | nI == nB -> dg'
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder _ -> insLink dg' morDelta'' globalDef (DGLinkMorph spname) nB nA
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder dg5 <- createConsLink DefLink conser lg dg4 nsig ns SeeTarget
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder return (Spec_inst spname ffitargs pos, ns, dg5)
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder | otherwise -> instMismatchError spname lp la pos
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder _ -> notFoundError "Structured specification" spname pos
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder -- analyse "data SPEC1 SPEC2"
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder Data lD@(Logic lidD) lP asp1 asp2 pos -> adjustPos pos $ do
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder let sp1 = item asp1
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder sp2 = item asp2
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder {- look for the inclusion comorphism from the current logic's data logic
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder into the current logic itself -}
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder c <- logicInclusion lg lD lP
27b37f8e6b165f7abb653a54b45ffcdb81cec561Christian Maeder let dname = extName "Data" name
86b1d0c80abdd4ca36491cf7025b718a5fea5080Christian Maeder -- analyse SPEC1
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder (sp1', ns', dg') <- anaSpec False (setCurLogic (language_name lidD) lg)
27b37f8e6b165f7abb653a54b45ffcdb81cec561Christian Maeder ln dg (EmptyNode lD) dname opts sp1
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder -- force the result to be in the data logic
27b37f8e6b165f7abb653a54b45ffcdb81cec561Christian Maeder (ns'', dg'') <- coerceNode lg dg' ns' (extName "Qualified" dname) lD
27b37f8e6b165f7abb653a54b45ffcdb81cec561Christian Maeder -- translate SPEC1's signature along the comorphism
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder (nsig2@(NodeSig node gsigmaD), dg2) <-
27b37f8e6b165f7abb653a54b45ffcdb81cec561Christian Maeder coerceNodeByComorph c dg'' ns'' dname
27b37f8e6b165f7abb653a54b45ffcdb81cec561Christian Maeder (usig, udg) <- case nsig of
27b37f8e6b165f7abb653a54b45ffcdb81cec561Christian Maeder EmptyNode _ -> return (nsig2, dg2)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski JustNode ns2 -> do
32562a567baac248a00782d2727716c13117dc4aChristian Maeder gsigma2 <- gsigUnion lg (getSig ns2) gsigmaD
32562a567baac248a00782d2727716c13117dc4aChristian Maeder let (ns@(NodeSig node2a _), dg2a) =
32562a567baac248a00782d2727716c13117dc4aChristian Maeder insGSig dg2 (extName "Union" name) DGUnion gsigma2
32562a567baac248a00782d2727716c13117dc4aChristian Maeder incl2 <- ginclusion lg gsigmaD gsigma2
32562a567baac248a00782d2727716c13117dc4aChristian Maeder let dg3 = insLink dg2a incl2 globalDef SeeTarget node node2a
32562a567baac248a00782d2727716c13117dc4aChristian Maeder dg4 <- createConsLink DefLink conser lg dg3 nsig ns SeeTarget
0e2ae85e2453466d03c1fc5884a3d693235bb9d9Christian Maeder return (ns, dg4)
4601edb679f0ba530bbb085b25d82a411cd070aaChristian Maeder -- analyse SPEC2
32562a567baac248a00782d2727716c13117dc4aChristian Maeder (sp2', nsig3, udg3) <-
32562a567baac248a00782d2727716c13117dc4aChristian Maeder anaSpec addSyms lg ln udg (JustNode usig) name opts sp2
32562a567baac248a00782d2727716c13117dc4aChristian Maeder return (Data lD lP
32562a567baac248a00782d2727716c13117dc4aChristian Maeder (replaceAnnoted sp1' asp1)
32562a567baac248a00782d2727716c13117dc4aChristian Maeder (replaceAnnoted sp2' asp2)
32562a567baac248a00782d2727716c13117dc4aChristian Maeder pos, nsig3, udg3)
32562a567baac248a00782d2727716c13117dc4aChristian MaederinstMismatchError :: SIMPLE_ID -> Int -> Int -> Range -> Result a
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian MaederinstMismatchError spname lp la = fatal_error $ tokStr spname ++ " expects "
7a47fbe6b987bd69a5056ce5d00fc8710f6c5e8aChristian Maeder ++ show lp ++ " arguments" ++ " but was given " ++ show la
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaedernotFoundError :: String -> SIMPLE_ID -> Range -> Result a
e68f45f355ed9d4026ee9baff5aa75aa7c911cc2Christian MaedernotFoundError str sid = fatal_error $ str ++ " " ++ tokStr sid ++ " not found"
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian MaedergsigUnionMaybe :: LogicGraph -> MaybeNode -> G_sign -> Result G_sign
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian MaedergsigUnionMaybe lg mn gsig = case mn of
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder EmptyNode _ -> return gsig
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder JustNode ns -> gsigUnion lg (getSig ns) gsig
fa167e362877db231378e17ba49c66fbb84862fcChristian MaederanaUnion :: Bool -> LogicGraph -> LibName -> DGraph -> MaybeNode -> NodeName
4aa35aadcb28f8a962096efc70d3bdb58ab7d9faChristian Maeder -> HetcatsOpts -> [Annoted SPEC]
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder -> Result ([Annoted SPEC], [NodeSig], NodeSig, DGraph)
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaederanaUnion addSyms lg ln dg nsig name opts asps = case asps of
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder [] -> fail "empty union"
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder let sps = map item asps
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder (sps', nsigs, dg', _) <-
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder let ana (sps1, nsigs, dg', n) sp' = do
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder let n1 = inc n
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder (sp1, nsig', dg1) <- anaSpec addSyms lg ln dg' nsig n1 opts sp'
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder return (sp1 : sps1, nsig' : nsigs, dg1, n1)
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder in foldM ana ([], [], dg, extName "Union" name) sps
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder let newAsps = zipWith replaceAnnoted (reverse sps') asps
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder case nsigs of
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder [ns] -> return (newAsps, nsigs, ns, dg')
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder let nsigs' = reverse nsigs
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder gbigSigma <- gsigManyUnion lg (map getSig nsigs')
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder let (ns@(NodeSig node _), dg2) = insGSig dg' name DGUnion gbigSigma
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder insE dgl (NodeSig n gsigma) = do
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder incl <- ginclusion lg gsigma gbigSigma
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder return $ insLink dgl incl globalDef SeeTarget n node
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder dg3 <- foldM insE dg2 nsigs'
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder return (newAsps, nsigs', ns, dg3)
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder-- analysis of renamings
6a22b2854c3bc9cb4877cb7d29049d6559238639Christian MaederanaRen :: LogicGraph -> HetcatsOpts -> MaybeNode -> Range -> GMorphism
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder -> G_mapping -> Result GMorphism
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian MaederanaRen lg opts lenv pos gmor@(GMorphism r sigma ind1 mor _) gmap =
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder adjustPos pos $ case gmap of
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder G_symb_map (G_symb_map_items_list lid sis) ->
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder let lid2 = targetLogic r in
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder if language_name lid2 == language_name lid then
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder if isStructured opts then return gmor else do
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder sis1 <- coerceSymbMapItemsList lid lid2 "Analysis of renaming" sis
575a55eadc8dcab8ee350324b417cbd9e52e69c0Christian Maeder src@(ExtSign sig _) <- return $ makeExtSign lid2 $ cod mor
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder rmap <- stat_symb_map_items lid2 sig Nothing sis1
d79a4d0d842c212f82f9507fff178ffe4ba2e214Christian Maeder mor1 <- ext_induced_from_morphism lid2 rmap src
32562a567baac248a00782d2727716c13117dc4aChristian Maeder EmptyNode _ -> return ()
32562a567baac248a00782d2727716c13117dc4aChristian Maeder JustNode (NodeSig _ sigLenv) -> do
32562a567baac248a00782d2727716c13117dc4aChristian Maeder -- needs to be changed for logic translations
32562a567baac248a00782d2727716c13117dc4aChristian Maeder (G_sign lid1 sigmaLenv1 _, _) <-
32562a567baac248a00782d2727716c13117dc4aChristian Maeder gSigCoerce lg sigLenv (Logic lid2)
32562a567baac248a00782d2727716c13117dc4aChristian Maeder sigmaLenv' <- coerceSign lid1 lid2 "" sigmaLenv1
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder let sysLenv = ext_sym_of lid2 sigmaLenv'
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder m = symmap_of lid2 mor1
32562a567baac248a00782d2727716c13117dc4aChristian Maeder isChanged sy = case Map.lookup sy m of
32562a567baac248a00782d2727716c13117dc4aChristian Maeder Just sy' -> sy /= sy'
32562a567baac248a00782d2727716c13117dc4aChristian Maeder Nothing -> False
32562a567baac248a00782d2727716c13117dc4aChristian Maeder forbiddenSys = Set.filter isChanged sysLenv
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski unless (Set.null forbiddenSys) $ plain_error () (
3b70d8ee5c2927f843d5d907e6ef724f867f1b40Till Mossakowski "attempt to rename the following symbols from " ++
a001917177db7ae636853b37c0d0f9f4e90a83ffChristian Maeder "the local environment:\n" ++ showDoc forbiddenSys "") pos
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder mor2 <- comp mor mor1
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder return $ GMorphism r sigma ind1 mor2 startMorId
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder comor <- logicInclusion lg (Logic lid2) (Logic lid)
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder gmorTrans <- gEmbedComorphism comor $ cod gmor
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder newMor <- comp gmor gmorTrans
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder anaRen lg opts lenv pos newMor gmap
ca732bc259f74cb4f3f725daab7fe80fc7e1d9a0Till Mossakowski G_logic_translation (Logic_code tok src tar pos1) ->
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder let adj1 = adjustPos $ if pos1 == nullRange then pos else pos1
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder G_sign srcLid srcSig ind <- return (cod gmor)
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder c <- case tok of
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder Just ctok -> lookupComorphism (tokStr ctok) lg
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder Nothing -> case tar of
2766ec926fcf3faf72248b10c3305b715b8c3249Christian Maeder Just (Logic_name l _ _) ->
ca732bc259f74cb4f3f725daab7fe80fc7e1d9a0Till Mossakowski lookupLogic "with logic: " (tokStr l) lg
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang >>= logicInclusion lg (Logic srcLid)
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang Nothing -> fail "with logic: cannot determine comorphism"
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang checkSrcOrTarLogic True c src
aea143fff7a50aceb809845fbc42698b0b3f545aChristian Maeder checkSrcOrTarLogic False c tar
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski mor1 <- gEmbedComorphism c (G_sign srcLid srcSig ind)
2561b4bfc45d280ee2be8a7870314670e4e682e4Christian Maeder comp gmor mor1
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun WangcheckSrcOrTarLogic :: Bool -> AnyComorphism -> Maybe Logic_name -> Result ()
2b2f3b72e82e28b34db9c69af2d1ec38f228272eChristian MaedercheckSrcOrTarLogic b (Comorphism cid) ml = case ml of
2b2f3b72e82e28b34db9c69af2d1ec38f228272eChristian Maeder Nothing -> return ()
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder Just (Logic_name l _ _) -> let s = tokStr l in
d79e02625778d20a5458078f979ff74aac67db61Christian Maeder when (s /= if b then language_name $ sourceLogic cid
2b2f3b72e82e28b34db9c69af2d1ec38f228272eChristian Maeder else language_name $ targetLogic cid)
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder $ plain_error () (s ++ " is is not the "
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder ++ (if b then "source" else "target") ++ " logic of "
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder ++ language_name cid) (tokPos l)
2b2f3b72e82e28b34db9c69af2d1ec38f228272eChristian MaederanaRenaming :: LogicGraph -> MaybeNode -> G_sign -> HetcatsOpts -> RENAMING
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder -> Result GMorphism
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian MaederanaRenaming lg lenv gSigma opts (Renaming ren pos) =
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian Maeder foldM (anaRen lg opts lenv pos) (ide gSigma) ren
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian MaedergetRestrLogic :: RESTRICTION -> Result AnyLogic
40d15f6c5f4d15866e085c588f8b5130dfd6cf63Christian MaedergetRestrLogic restr = case restr of
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian Maeder Revealed (G_symb_map_items_list lid _) _ -> return $ Logic lid
e82587ca2892d246aa4405c2f5b9f30f287f9ebfChristian Maeder Hidden l _ -> case l of
2b2f3b72e82e28b34db9c69af2d1ec38f228272eChristian Maeder [] -> error "getRestrLogic"
2b2f3b72e82e28b34db9c69af2d1ec38f228272eChristian Maeder h : _ -> case h of
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang G_symb_list (G_symb_items_list lid _) -> return $ Logic lid
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang G_logic_projection (Logic_code _ _ _ pos1) ->
db453fe9625a9dab5d108f7a5e464598814144b8Jian Chun Wang fatal_error "no analysis of logic projections yet" pos1
sys' = Set.filter (\ sy -> any (matches lid1 sy) rsys) sys
forbiddenSys = sys' `Set.intersection` sysLenv
unless (Set.null forbiddenSys)
return $ GMorphism cid (ExtSign (dom mor1) $ Set.fold (\ sy ->
case Map.lookup sy $ symmap_of lid1 mor1 of
let sys'' = Set.fromList
[sy | sy <- Set.toList sys', rsy <-
Map.keys rmap, matches lid1 sy rsy]
mor1 <- ext_generated_sign lid1 (sys `Set.union` sys'') sigma1
ext_induced_from_to_morphism lidP' Map.empty sigmaP' sigmaA'
if Set.all (\sy -> lookupFM symmap_mor sy == Just sy) symI
case Map.lookup i idmap of
Just ids -> case Set.toList ids of
Map.insert i (Id toks compsnew pos1) m1
idsB = Set.map (sym_name lid) symsB
idh = Map.foldWithKey
r = rh `Map.union` rIdExt
sigmaAD = ExtSign (cod mor) $ Set.map (\ sy ->
Map.findWithDefault sy sy hmor) sysB
let illShared = (ext_sym_of lid sigmaA `Set.intersection`
unless (Set.null illShared)
unless (Set.null newIdentifications)