AnalysisStructured.hs revision 7bf4436b6f9987b070033a323757b206c898c1be
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski Module : $Header$
2725abe920f91de62ae5c0b7230c1627cccf5fabChristian Maeder Copyright : (c) Till Mossakowski and Uni Bremen 2003-2005
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder License : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
3f69b6948966979163bdfe8331c38833d5d90ecdChristian Maeder Maintainer : till@tzi.de
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Stability : provisional
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Portability : non-portable
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederAnalysis of structured specifications
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Follows the verfication semantic rules in Chap. IV:4.7
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder of the CASL Reference Manual.
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder analysis of basic specs: use union of sigs
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder analysis of instantiations: if necessary, translate body along inclusion comorphism
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder Improve efficiency by storing local signature fragments only
85e1d54a475bfc30b3eac5ae6c5e42a2d7e93f10Christian Maeder Name views in devgraphs?
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder spec <name> not found: line number!
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder Issue warning for unions of non-disjoint signatures
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder (and offer tool for renaming?)
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder Check that translations and reductions do not effect local env
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder (Implement new semantics for revealing here)
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder Should we use institution independent analysis over the Grothendieck logic?
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder abstract syntax + devgraph would have to be changed to homogeneous case
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder logic translations are symbol maps in the Grothendieck logic
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder Problem with this approach: symbol functor goes into rel,
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder and induced_from_morphism gets difficult to implement
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder Unions need inclusion morphisms. Should these play a special role?
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder At least we need a function delivering the inclusion morphism
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder between two (sub)signatures.
109a53dbf4c9233f869f63ba7a7f3fece49973c3Christian Maeder In most logics, inclusions could be represented specially, such
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder that composition for them becomes fast.
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Should we even identify an inclusion subcategory?
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder Then inclusions are represented by pair of signatures
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (Non-inclusions could be specially displayed in the DG)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder No optimization of heterogeneous unions!
7f7460e7095628f3437b116ee78d3043d11f8febChristian Maeder (or use heterogeneous compInclusion in Proofs/Proof.hs)
3a9d784341454573b50b32fa1b494e7418df3086Christian Maeder (or perhaps abandon optimized unions at all and
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder replace compHomInclusion with comp Grothendieck? is this more efficient?)
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder Treatment of translations and reductions along logic translations
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (see WADT 02 paper).
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Open question:
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder may local env be translated, and even reduced, along logic translations?
7f7460e7095628f3437b116ee78d3043d11f8febChristian Maeder if yes: how is local env linked to signature of resulting spec?
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (important e.g. for checking that local env is not being renamed?)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder does signature+comorphism suffice, such that c(local env)\subseteq sig?
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder if no: this means that only closed specs may be translated
38c817b94e0a5b1ae94178b1075c187e07bcc5e1Christian Maeder Revealings without translations: just one arrow
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Pushouts: only admissible within one logic?
2353f65833a3da763392f771223250cd50b8d873Christian Maeder Instantiations with formal parameter: add no new internal nodes
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder call extend_morphism
ea38cad7e4f09060750da5d0b8ebc426628c4d88Christian Maeder Optimizations:
cb2044812811d66efe038d914966e04290be93faChristian Maeder Union nodes can be extended by a basic spec directly (no new node needed)
966519955f5f7111abac20118563132b9dd41165Christian Maeder no new nodes for trivial translations
d81905a5b924415c524d702df26204683c82c12eChristian Maeder Also: free, cofree nodes
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Basic specs: if local env node is otherwise unused, overwrite it with
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder local sig+axioms
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Ensure that just_struct option leads to disabling of various dg operations
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (show sig, show mor, proving)
cb2044812811d66efe038d914966e04290be93faChristian Maeder local: better error message for the following
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederspec GenCardinality [sort Subject,Object;
083bc1972a66d73749760eab3a90bf4eb9ca7951Christian Maeder pred predicate : Subject * Object] =
6352f3c31da3043783a13be6594aacb2147378baRazvan Pascanu Set [sort Object fit sort Elem |-> Object]
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu reveal Set[Object], #__, __eps__,
b324cda6178c49ddeead3ce62b832ccf644cbcabRazvan Pascanu Nat,0,1,2,3,4,5,6,7,8,9,__@@__,__>=__,__<=__
966519955f5f7111abac20118563132b9dd41165Christian Maeder op toSet : Subject -> Set [Object]
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder forall x : Subject; y : Object
8865728716566f42fa73e7e0bc080ba3225df764Christian Maeder . predicate (x,y) <=> y eps toSet(x)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder pred minCardinality(s: Subject;n: Nat) <=>
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder # toSet(s) >= n;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder maxCardinality(s: Subject;n: Nat) <=>
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulz # toSet(s) <= n;
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder cardinality(s: Subject;n: Nat) <=>
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder # toSet(s) = n
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder%%} hide Pos,toSet,Set[Object],#__,__eps__,__<=__,__>=__
a9e804dbec424ec36e34bab955cbe90edac5baa6Christian Maedermodule Static.AnalysisStructured (ana_SPEC, ana_GENERICITY,
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulz ana_VIEW_TYPE, ana_err, isStructured,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ana_RENAMING, ana_RESTRICTION,
b76d27eba526ecac2a20400fa505ec5c642ae7d2Dominik Luecke homogenizeGM, extendMorphism)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederimport qualified Common.Lib.Set as Set
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederimport qualified Common.Lib.Map as Map
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederimport qualified Common.Lib.Rel as Rel(image, setInsert)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederimport Data.List hiding (union)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian MaederinsEdgeNub :: LEdge DGLinkLab -> DGraph -> DGraph
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian MaederinsEdgeNub (v, w, l) g =
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if (l, w) `elem` s then g
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder else (p, v, l', (l, w) : s) & g'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder where (Just (p, _, l', s), g') = match v g
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder-- | analyze a SPEC
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder-- Parameters: global context, local environment,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder-- the SIMPLE_ID may be a name if the specification shall be named,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder-- options: here we need the info: shall only the structure be analysed?
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederana_SPEC :: LogicGraph -> GlobalContext -> MaybeNode -> NODE_NAME ->
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder HetcatsOpts -> SPEC -> Result (SPEC,NodeSig,DGraph)
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maederana_SPEC lg gctx@(gannos,genv,dg) nsig name opts sp =
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Basic_spec (G_basic_spec lid bspec) ->
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder do G_sign lid' sigma' <- return (getMaybeSig nsig)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder sigma <- coerceSign lid' lid "Analysis of basic spec" sigma'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (bspec', _sigma_local, sigma_complete, ax) <-
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder if isStructured opts
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder then return (bspec,empty_signature lid, empty_signature lid,[])
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder else do b <- maybeToMonad
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ("no basic analysis for logic "
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ++language_name lid)
cb2044812811d66efe038d914966e04290be93faChristian Maeder (basic_analysis lid)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder b (bspec,sigma,gannos)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder incl <- ginclusion lg
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (G_sign lid sigma) (G_sign lid sigma_complete)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let node_contents = DGNode {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_name = name,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_theory = G_theory lid sigma_complete $ toThSens ax,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- no, not only the delta
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_nf = Nothing,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_sigma = Nothing,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_origin = DGBasic }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder node = getNewNode dg
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dg' = insNode (node,node_contents) dg
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder link = DGLink {
966519955f5f7111abac20118563132b9dd41165Christian Maeder dgl_morphism = incl,
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder dgl_type = GlobalDef,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_origin = DGExtension }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dg'' = case nsig of
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder EmptyNode _ -> dg'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder JustNode (NodeSig n _) -> insEdgeNub (n,node,link) dg'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return (Basic_spec (G_basic_spec lid bspec'),
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder NodeSig node $ G_sign lid sigma_complete,
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder Translation asp ren ->
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder do let sp1 = item asp
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (sp1', NodeSig n' gsigma, dg') <-
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ana_SPEC lg gctx nsig (inc name) opts sp1
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder mor <- ana_RENAMING lg gsigma opts ren
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- ??? check that mor is identity on local env
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let gsigma' = cod Grothendieck mor
8bb80c9684e905de8dcfcfb1291542677e7d77b6Christian Maeder -- ??? too simplistic for non-comorphism inter-logic translations
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder G_sign lid' gsig <- return gsigma'
966519955f5f7111abac20118563132b9dd41165Christian Maeder let node_contents = DGNode {
8bb80c9684e905de8dcfcfb1291542677e7d77b6Christian Maeder dgn_name = name,
8bb80c9684e905de8dcfcfb1291542677e7d77b6Christian Maeder dgn_theory = G_theory lid' gsig noSens,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_nf = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGTranslation }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder node = getNewNode dg'
8bb80c9684e905de8dcfcfb1291542677e7d77b6Christian Maeder link = (n',node,DGLink {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_morphism = mor,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_type = GlobalDef,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_origin = DGTranslation })
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return (Translation (replaceAnnoted sp1' asp) ren,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder NodeSig node gsigma',
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder insEdgeNub link $
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder insNode (node,node_contents) dg')
966519955f5f7111abac20118563132b9dd41165Christian Maeder Reduction asp restr ->
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder do let sp1 = item asp
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (sp1', NodeSig n' gsigma',dg') <-
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ana_SPEC lg gctx nsig (inc name) opts sp1
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let gsigma = getMaybeSig nsig
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (hmor,tmor) <- ana_RESTRICTION dg gsigma gsigma' opts restr
cb2044812811d66efe038d914966e04290be93faChristian Maeder -- we treat hiding and revealing differently
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- in order to keep the dg as simple as possible
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder do let gsigma'' = dom Grothendieck hmor
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- ??? too simplistic for non-comorphism inter-logic reductions
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder G_sign lid' gsig <- return gsigma''
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let node_contents = DGNode {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_name = name,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_theory = G_theory lid' gsig noSens,
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder dgn_nf = Nothing,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGHiding }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder node = getNewNode dg'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder link = (n',node,DGLink {
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder dgl_morphism = hmor,
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder dgl_type = HidingDef,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_origin = DGHiding })
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu return (Reduction (replaceAnnoted sp1' asp) restr,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder NodeSig node gsigma'',
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder insEdgeNub link $
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder insNode (node,node_contents) dg')
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder Just tmor' -> do
cb2044812811d66efe038d914966e04290be93faChristian Maeder let gsigma1 = dom Grothendieck tmor'
d81905a5b924415c524d702df26204683c82c12eChristian Maeder gsigma'' = cod Grothendieck tmor'
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder -- ??? too simplistic for non-comorphism inter-logic reductions
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder G_sign lid1 gsig <- return gsigma1
0ae7a79e865d4a6022d705d160530682b3c1f825Christian Maeder G_sign lid'' gsig'' <- return gsigma''
966519955f5f7111abac20118563132b9dd41165Christian Maeder -- the case with identity translation leads to a simpler dg
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder if tmor' == ide Grothendieck (dom Grothendieck tmor')
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder let node1 = getNewNode dg'
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder node_contents1 = DGNode {
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder dgn_name = name,
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder dgn_theory = G_theory lid1 gsig noSens,
5b5f3190cc8d51a7942dda33a1ec45345cca5028Thiemo Wiedemeyer dgn_nf = Nothing,
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder dgn_sigma = Nothing,
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder dgn_origin = DGRevealing }
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder link1 = (n',node1,DGLink {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_morphism = hmor,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_type = HidingDef,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGRevealing })
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return (Reduction (replaceAnnoted sp1' asp) restr,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder NodeSig node1 gsigma1,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder insEdgeNub link1 $
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder insNode (node1,node_contents1) dg')
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let [node1,node''] = newNodes 2 dg'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder node_contents1 = DGNode {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_name = extName "T" name,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_theory = G_theory lid1 gsig noSens,
d56ece59c372cb887355825901222b9f3377f7e6Thiemo Wiedemeyer dgn_nf = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGRevealing }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder link1 = (n',node1,DGLink {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_morphism = hmor,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_type = HidingDef,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGRevealing })
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder node_contents'' = DGNode {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_name = name,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_theory = G_theory lid'' gsig'' noSens,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_nf = Nothing,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_sigma = Nothing,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_origin = DGRevealTranslation }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder link'' = (node1,node'',DGLink {
76d027be764e2ff61bef959efb3ac8f56499e646Christian Maeder dgl_morphism = tmor',
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_type = GlobalDef,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_origin = DGRevealTranslation })
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return (Reduction (replaceAnnoted sp1' asp) restr,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder NodeSig node'' gsigma'',
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder insEdgeNub link'' $
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder insNode (node'',node_contents'') $
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder insEdgeNub link1 $
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder insNode (node1,node_contents1) dg')
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Union [] pos -> adjustPos pos $ fail $ "empty union"
59aa5703ac7f3b99e97cd5926e77088b256c5f40Christian Maeder Union asps pos ->
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder do let sps = map item asps
76d027be764e2ff61bef959efb3ac8f56499e646Christian Maeder (sps',nsigs,dg',_) <-
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let ana r sp' = do
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (sps1,nsigs,dg',n) <- r
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (sp1,nsig',dg1) <- ana_SPEC lg (gannos,genv,dg')
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder nsig n opts sp'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return (sp1:sps1,nsig':nsigs,dg1,inc n)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder in foldl ana (return ([],[],dg,extName "U" name)) sps
2353f65833a3da763392f771223250cd50b8d873Christian Maeder let nsigs' = reverse nsigs
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder adj = adjustPos pos
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder gbigSigma <- adj $ gsigManyUnion lg (map getSig nsigs')
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder G_sign lid' gsig <- return gbigSigma
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder let node_contents = DGNode {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_name = name,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_theory = G_theory lid' gsig noSens,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_nf = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGUnion }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder node = getNewNode dg'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder insE dgres (NodeSig n gsigma) = do
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder incl <- adj $ ginclusion lg gsigma gbigSigma
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let link = DGLink {
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder dgl_morphism = incl,
76d027be764e2ff61bef959efb3ac8f56499e646Christian Maeder dgl_type = GlobalDef,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGUnion }
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return (insEdgeNub (n,node,link) dg1)
818b228955ef40dd5a253bd942dd6ab8779ed713Christian Maeder dg'' <- foldl insE (return (insNode (node,node_contents) dg')) nsigs'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return (Union (map (uncurry replaceAnnoted)
7ebcceae3d34771cae3bbb8c8060bef0b894376eChristian Maeder (zip (reverse sps') asps))
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich NodeSig node gbigSigma,
7ebcceae3d34771cae3bbb8c8060bef0b894376eChristian Maeder Extension asps pos -> do
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich (sps',nsig1',dg1) <- foldl ana (return ([],nsig,dg)) namedSps
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich case nsig1' of
7ebcceae3d34771cae3bbb8c8060bef0b894376eChristian Maeder EmptyNode _ -> fail "empty extension"
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich JustNode nsig1 -> return (Extension (map (uncurry replaceAnnoted)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (zip (reverse sps') asps))
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder pos, nsig1,dg1)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder namedSps = zip (reverse (name: tail (take (length asps)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (iterate inc (extName "E" name)))))
59aa5703ac7f3b99e97cd5926e77088b256c5f40Christian Maeder ana res (name',asp') = do
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (sps', nsig', dg') <- res
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulz (sp1', nsig1@(NodeSig n1 sig1), dg1) <-
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ana_SPEC lg (gannos,genv,dg') nsig' name' opts (item asp')
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- insert theorem link for semantic annotations
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- take the first semantic annotation
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let anno = find isSemanticAnno $ l_annos asp'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- is the extension going between real nodes?
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dg2 <- case (anno, nsig') of
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (Just anno0@(Semantic_anno anno1 _), JustNode (NodeSig n' sig')) -> do
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder -- any other semantic annotation? that's an error
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder when (any (\an -> isSemanticAnno an && an/=anno0) $ l_annos asp')
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (pplain_error () (ptext "Conflicting semantic annotations")
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- %implied should not occur here
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder when (anno1==SA_implied)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (pplain_error () (ptext
59aa5703ac7f3b99e97cd5926e77088b256c5f40Christian Maeder "Annotation %implied should come after a BASIC-ITEM")
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulz if anno1==SA_implies then do
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder when (not (is_subgsign sig1 sig')) (pplain_error ()
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (ptext "Signature must not be extended in presence of %implies")
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder -- insert a theorem link according to p. 319 of the CASL Reference Manual
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return $ insEdgeNub (n1,n',DGLink {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_morphism = ide Grothendieck sig1,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_type = GlobalThm LeftOpen None LeftOpen,
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder dgl_origin = DGExtension }) dg1
59aa5703ac7f3b99e97cd5926e77088b256c5f40Christian Maeder let anno2 = case anno1 of
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulz SA_cons -> Cons
f8cc2399c16fcda7e3bf9d901a0de0cc8a455f86Ewaryst Schulz SA_def -> Def
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder SA_mono -> Mono
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder _ -> error "Static.AnalysisStructured: this cannot happen"
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder -- insert a theorem link according to p. 319 of the CASL Reference Manual
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder -- the theorem link is trivally proved by the parallel definition link,
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder -- but for clarity, we leave it open here
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder -- the interesting open proof obligation is anno2, of course
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder incl <- ginclusion lg sig' sig1
8a5c05062ef501bf725a86a370a5145a198e81fdKlaus Luettich return $ insEdgeNub (n',n1,DGLink {
b76d27eba526ecac2a20400fa505ec5c642ae7d2Dominik Luecke dgl_morphism = incl,
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder dgl_type = GlobalThm LeftOpen anno2 LeftOpen,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGExtension }) dg1
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder _ -> return dg1
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder return (sp1':sps', JustNode nsig1, dg2)
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder Free_spec asp poss ->
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder do let sp1 = item asp
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder (sp', NodeSig n' gsigma'@(G_sign lid' gsig), dg') <-
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ana_SPEC lg gctx nsig (inc name) opts sp1
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let pos = poss
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder incl <- adjustPos pos $ ginclusion lg (getMaybeSig nsig) gsigma'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let node_contents = DGNode {
2353f65833a3da763392f771223250cd50b8d873Christian Maeder dgn_name = name,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_theory = G_theory lid' gsig noSens, -- delta is empty
f6bb0076b79286b0251c1b2745ed8019b6c80252Christian Maeder dgn_nf = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGFree }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder node = getNewNode dg'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder link = (n',node,DGLink {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_morphism = incl,
f6bb0076b79286b0251c1b2745ed8019b6c80252Christian Maeder dgl_type = FreeDef nsig,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGFree })
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return (Free_spec (replaceAnnoted sp' asp) poss,
f6bb0076b79286b0251c1b2745ed8019b6c80252Christian Maeder NodeSig node gsigma',
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder insEdgeNub link $
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder insNode (node,node_contents) dg')
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Cofree_spec asp poss ->
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder do let sp1 = item asp
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (sp', NodeSig n' gsigma'@(G_sign lid' gsig), dg') <-
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder ana_SPEC lg gctx nsig (inc name) opts sp1
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder let pos = poss
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder incl <- adjustPos pos $ ginclusion lg (getMaybeSig nsig) gsigma'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let node_contents = DGNode {
8865728716566f42fa73e7e0bc080ba3225df764Christian Maeder dgn_name = name,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_theory = G_theory lid' gsig noSens, -- delta is empty
2353f65833a3da763392f771223250cd50b8d873Christian Maeder dgn_nf = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGCofree }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder node = getNewNode dg'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder link = (n',node,DGLink {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_morphism = incl,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_type = CofreeDef nsig,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_origin = DGCofree })
8bb80c9684e905de8dcfcfb1291542677e7d77b6Christian Maeder return (Cofree_spec (replaceAnnoted sp' asp) poss,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder NodeSig node gsigma',
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder insEdgeNub link $
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder insNode (node,node_contents) dg')
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder Local_spec asp asp' poss ->
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder do let sp1 = item asp
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder sp1' = item asp'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (sp2, nsig'@(NodeSig _ (G_sign lid' sigma')), dg') <-
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder ana_SPEC lg gctx nsig (extName "L" name) opts sp1
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder (sp2', NodeSig n'' (G_sign lid'' sigma''), dg'') <-
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder ana_SPEC lg (gannos,genv,dg') (JustNode nsig') (inc name) opts sp1'
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder let gsigma = getMaybeSig nsig
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder G_sign lid sigma <- return gsigma
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder sigma1 <- coerceSign lid' lid "Analysis of local spec" sigma'
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder sigma2 <- coerceSign lid'' lid "Analysis of local spec" sigma''
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder let sys = sym_of lid sigma
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder sys1 = sym_of lid sigma1
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder sys2 = sym_of lid sigma2
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder mor3 <- if isStructured opts then return (ide lid sigma2)
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder else adjustPos pos $ cogenerated_sign lid
cb2044812811d66efe038d914966e04290be93faChristian Maeder (sys1 `Set.difference` sys) sigma2
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder let sigma3 = dom lid mor3
d81905a5b924415c524d702df26204683c82c12eChristian Maeder -- gsigma2 = G_sign lid sigma2
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder gsigma3 = G_sign lid sigma3
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder sys3 = sym_of lid sigma3
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder when (not( isStructured opts ||
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder sys2 `Set.difference` sys1 `Set.isSubsetOf` sys3))
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder $ pplain_error () (text
91ba5d95b2472cb075646b6120a559dc6581a867Christian Maeder "attempt to hide the following symbols from the local environment"
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder $$ printText ((sys2 `Set.difference` sys1) `Set.difference` sys3))
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let node_contents = DGNode {
818b228955ef40dd5a253bd942dd6ab8779ed713Christian Maeder dgn_name = name,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgn_theory = G_theory lid sigma3 noSens,
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder dgn_nf = Nothing,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGLocal }
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder node = getNewNode dg''
4a2f7efdf67dfcda0946f1b6373f41976ddea7a4Christian Maeder link = (n'',node,DGLink {
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder dgl_morphism = gEmbed (G_morphism lid mor3),
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder dgl_type = HidingDef,
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder dgl_origin = DGLocal })
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder return (Local_spec (replaceAnnoted sp2 asp)
3490b73f69b58ab742417b0867d0e2d4a7778cc0Christian Maeder (replaceAnnoted sp2' asp')
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder NodeSig node gsigma3,
ab2f38d9cd1249f6bc9cc5b838dc2fcd76189c0fChristian Maeder insEdgeNub link $
974b0baababf2878820de073b8fad8db68bef08aDominik Luecke insNode (node,node_contents) dg'')
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder Closed_spec asp pos ->
966519955f5f7111abac20118563132b9dd41165Christian Maeder do let sp1 = item asp
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder l = getLogic nsig
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder -- analyse spec with empty local env
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder (sp', NodeSig n' gsigma', dg') <-
0ae7a79e865d4a6022d705d160530682b3c1f825Christian Maeder ana_SPEC lg gctx (EmptyNode l) (inc name) opts sp1
27b988cb88bfa05fe6f35a853d76ef04f61293efChristian Maeder let gsigma = getMaybeSig nsig
0ae7a79e865d4a6022d705d160530682b3c1f825Christian Maeder adj = adjustPos pos
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder gsigma'' <- adj $ gsigUnion lg gsigma gsigma'
2353f65833a3da763392f771223250cd50b8d873Christian Maeder G_sign lid'' gsig'' <- return gsigma''
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder incl1 <- adj $ ginclusion lg gsigma gsigma''
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder incl2 <- adj $ ginclusion lg gsigma' gsigma''
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let node = getNewNode dg'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder node_contents = DGNode {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_name = name,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_theory = G_theory lid'' gsig'' noSens,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_nf = Nothing,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_sigma = Nothing,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_origin = DGClosed }
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder link1 = DGLink {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_morphism = incl1,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_type = GlobalDef,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgl_origin = DGClosedLenv }
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder link2 = (n',node,DGLink {
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgl_morphism = incl2,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgl_type = GlobalDef,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgl_origin = DGClosed })
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder insLink1 = case nsig of
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu EmptyNode _ -> id
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu JustNode (NodeSig n _) -> insEdgeNub (n, node, link1)
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu return (Closed_spec (replaceAnnoted sp' asp) pos,
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu NodeSig node gsigma'',
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu insEdgeNub link2 $
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu insNode (node,node_contents) dg')
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu Qualified_spec (Logic_name ln sublog) asp pos -> do
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu l <- lookupLogic "Static analysis: " (tokStr ln) lg
66a774f13272fde036481edd2298081ab3d04678Razvan Pascanu -- analyse spec with empty local env
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu (sp', NodeSig n' gsigma', dg') <-
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu ana_SPEC lg gctx (EmptyNode l) (inc name) opts (item asp)
66a774f13272fde036481edd2298081ab3d04678Razvan Pascanu -- construct union with local env
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let gsigma = getMaybeSig nsig
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder adj = adjustPos pos
9dd71ac51c9a6e72bcb126224f9c64131698b636Christian Maeder gsigma'' <- adj $ gsigUnion lg gsigma gsigma'
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder G_sign lid'' gsig'' <- return gsigma''
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder incl1 <- adj $ ginclusion lg gsigma gsigma''
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder incl2 <- adj $ ginclusion lg gsigma' gsigma''
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder let node = getNewNode dg'
0ea2cddb8715a770e646895e16b7b8085f49167cChristian Maeder node_contents = DGNode {
0ea2cddb8715a770e646895e16b7b8085f49167cChristian Maeder dgn_name = name,
7245138e91992b96b153b8ac527e263d9dc8ff5bChristian Maeder dgn_theory = G_theory lid'' gsig'' noSens,
7245138e91992b96b153b8ac527e263d9dc8ff5bChristian Maeder dgn_nf = Nothing,
7245138e91992b96b153b8ac527e263d9dc8ff5bChristian Maeder dgn_sigma = Nothing,
7245138e91992b96b153b8ac527e263d9dc8ff5bChristian Maeder dgn_origin = DGLogicQual }
7245138e91992b96b153b8ac527e263d9dc8ff5bChristian Maeder link1 = DGLink {
0ea2cddb8715a770e646895e16b7b8085f49167cChristian Maeder dgl_morphism = incl1,
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder dgl_type = GlobalDef,
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder dgl_origin = DGLogicQualLenv }
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder link2 = (n',node,DGLink {
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder dgl_morphism = incl2,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_type = GlobalDef,
3bcd9d942601d59dd55a6069d8b2d1c33d7ced0eChristian Maeder dgl_origin = DGLogicQual })
3bcd9d942601d59dd55a6069d8b2d1c33d7ced0eChristian Maeder insLink1 = case nsig of
3bcd9d942601d59dd55a6069d8b2d1c33d7ced0eChristian Maeder EmptyNode _ -> id
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder JustNode (NodeSig n _) -> insEdgeNub (n, node, link1)
beff4152e9f0fe90885458d1a1733b183a2a8816Christian Maeder return (Qualified_spec (Logic_name ln sublog) (replaceAnnoted sp' asp) pos,
44f3fc84d88cc5f364e152606779c99e3b8cb895Christian Maeder NodeSig node gsigma'',
3bcd9d942601d59dd55a6069d8b2d1c33d7ced0eChristian Maeder insEdgeNub link2 $
3bcd9d942601d59dd55a6069d8b2d1c33d7ced0eChristian Maeder insNode (node,node_contents) dg')
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder Group asp pos -> do
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (sp',nsig',dg') <- ana_SPEC lg gctx nsig name opts (item asp)
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder return (Group (replaceAnnoted sp' asp) pos,nsig',dg')
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder Spec_inst spname afitargs pos -> do
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder let adj = adjustPos pos
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder case Map.lookup spname genv of
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder Nothing -> fatal_error
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder ("Specification "++ showPretty spname " not found") pos
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder Just (ViewEntry _) ->
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder (showPretty spname " is a view, not a specification") pos
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder Just (ArchEntry _) ->
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder (showPretty spname
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder " is an architectural, not a structured specification") pos
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder Just (UnitEntry _) ->
daec53c285f692c56db0cefe16061b46ba602cf0Christian Maeder (showPretty spname
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder " is a unit specification, not a structured specification") pos
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Just (RefEntry) ->
2353f65833a3da763392f771223250cd50b8d873Christian Maeder (showPretty spname
7245138e91992b96b153b8ac527e263d9dc8ff5bChristian Maeder " is a refinement specification, not a structured specification") pos
7245138e91992b96b153b8ac527e263d9dc8ff5bChristian Maeder Just (SpecEntry gs@(imps,params,_,body@(NodeSig nB gsigmaB))) ->
3bcd9d942601d59dd55a6069d8b2d1c33d7ced0eChristian Maeder case (\x y -> (x,x-y)) (length afitargs) (length params) of
0a64bfd28dff15bc93e1f7a86e0a8052e879636dChristian Maeder -- the case without parameters leads to a simpler dg
0a64bfd28dff15bc93e1f7a86e0a8052e879636dChristian Maeder gsigma@(G_sign lid gsig) <-
0a64bfd28dff15bc93e1f7a86e0a8052e879636dChristian Maeder adj $ gsigUnion lg (getMaybeSig nsig) gsigmaB
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder -- the subcase with empty local env leads to an even simpler dg
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder EmptyNode _ ->
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder -- if the node shall not be named and the logic does not change,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if isInternal name && langNameSig gsigma==langNameSig gsigmaB
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder -- then just return the body
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder then return (sp,body,dg)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder -- otherwise, we need to create a new one
2353f65833a3da763392f771223250cd50b8d873Christian Maeder incl <- adj $ ginclusion lg gsigmaB gsigma
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let node = getNewNode dg
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder node_contents = DGNode {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_name = name,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_theory = G_theory lid gsig noSens,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_nf = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGSpecInst spname}
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder link = (nB,node,DGLink {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_morphism = incl,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_type = GlobalDef,
2353f65833a3da763392f771223250cd50b8d873Christian Maeder dgl_origin = DGSpecInst spname})
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder NodeSig node gsigma,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder insEdgeNub link $
f39b8dd9651dfcc38b06191cda23cacbfc298323Christian Maeder insNode (node,node_contents) dg)
0ae7a79e865d4a6022d705d160530682b3c1f825Christian Maeder -- the subcase with nonempty local env
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder JustNode (NodeSig n sigma) -> do
0ae7a79e865d4a6022d705d160530682b3c1f825Christian Maeder incl1 <- adj $ ginclusion lg sigma gsigma
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder incl2 <- adj $ ginclusion lg gsigmaB gsigma
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let node = getNewNode dg
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder node_contents = DGNode {
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_name = name,
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder dgn_theory = G_theory lid gsig noSens,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_nf = Nothing,
59a10395caff224b2ec541f94dac5082a506c00fChristian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGSpecInst spname}
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder link1 = (n,node,DGLink {
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgl_morphism = incl1,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgl_type = GlobalDef,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGSpecInst spname})
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder link2 = (nB,node,DGLink {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_morphism = incl2,
2353f65833a3da763392f771223250cd50b8d873Christian Maeder dgl_type = GlobalDef,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGSpecInst spname})
2353f65833a3da763392f771223250cd50b8d873Christian Maeder NodeSig node gsigma,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder insEdgeNub link1 $
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder insEdgeNub link2 $
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder insNode (node,node_contents) dg)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder -- now the case with parameters
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let fitargs = map item afitargs
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (fitargs',dg',args,_) <-
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder foldl anaFitArg (return ([],dg,[],extName "A" name))
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (zip params fitargs)
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder let actualargs = reverse args
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (gsigma',morDelta) <- adj $ apply_GS lg gs actualargs
964ee9fff06b8c821e1d00207f6f185301371be8Christian Maeder gsigmaRes <- adj $ gsigUnion lg (getMaybeSig nsig) gsigma'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder G_sign lidRes gsigRes <- return gsigmaRes
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder incl1 <- adj $ ginclusion lg (getMaybeSig nsig) gsigmaRes
964ee9fff06b8c821e1d00207f6f185301371be8Christian Maeder incl2 <- adj $ ginclusion lg gsigma' gsigmaRes
964ee9fff06b8c821e1d00207f6f185301371be8Christian Maeder morDelta' <- comp Grothendieck (gEmbed morDelta) incl2
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu let node = getNewNode dg'
fefee7e1dee1ee5f0768a03a4abae88d1ca2c3fdRazvan Pascanu node_contents = DGNode {
964ee9fff06b8c821e1d00207f6f185301371be8Christian Maeder dgn_name = name,
964ee9fff06b8c821e1d00207f6f185301371be8Christian Maeder dgn_theory = G_theory lidRes gsigRes noSens,
964ee9fff06b8c821e1d00207f6f185301371be8Christian Maeder dgn_nf = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_sigma = Nothing,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgn_origin = DGSpecInst spname}
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder link1 = DGLink {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_morphism = incl1,
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder dgl_type = GlobalDef,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGSpecInst spname}
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder insLink1 = case nsig of
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder EmptyNode _ -> id
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder JustNode (NodeSig n _) -> insEdgeNub (n, node, link1)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder link2 = (nB,node,DGLink {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_morphism = morDelta',
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_type = GlobalDef,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_origin = DGSpecInst spname})
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder parLinks = catMaybes (map (parLink gsigmaRes node) actualargs)
2353f65833a3da763392f771223250cd50b8d873Christian Maeder return (Spec_inst spname
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (map (uncurry replaceAnnoted)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (zip (reverse fitargs') afitargs))
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder NodeSig node gsigmaRes ,
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder foldr insEdgeNub
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder insEdgeNub link2 $
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder insNode (node,node_contents) dg')
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder anaFitArg res (nsig',fa) = do
0a64bfd28dff15bc93e1f7a86e0a8052e879636dChristian Maeder (fas',dg1,args,name') <- res
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder (fa',dg',arg) <- ana_FIT_ARG lg (gannos,genv,dg1)
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder spname imps nsig' opts name' fa
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder return (fa':fas',dg',arg:args,inc name')
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder parLink gsigma' node (_mor_i, NodeSig nA_i sigA_i) = do
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder incl <- maybeResult $ ginclusion lg sigA_i gsigma'
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let link = DGLink {
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder dgl_morphism = incl,
2353f65833a3da763392f771223250cd50b8d873Christian Maeder dgl_type = GlobalDef,
4b1833c7d3af466e6bcba24f16304e0a78e8da87Christian Maeder dgl_origin = DGFitSpec }
12aef5992d3af07dee81a4e02cf4be65a83f28bcChristian Maeder return (nA_i,node,link)
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder -- finally the case with conflicting numbers of formal and actual parameters
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (showPretty spname " expects "++show (length params)++" arguments"
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ++" but was given "++show (length afitargs)) pos
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder Data (Logic lidD) (Logic lidP) asp1 asp2 pos ->
2353f65833a3da763392f771223250cd50b8d873Christian Maeder do let sp1 = item asp1
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder sp2 = item asp2
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder adj = adjustPos pos
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder Comorphism cid <- adj $ logicInclusion lg (Logic lidD) (Logic lidP)
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder let lidD' = sourceLogic cid
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder lidP' = targetLogic cid
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder (sp1', NodeSig n' (G_sign lid' sigma'), dg1) <-
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder ana_SPEC lg gctx (EmptyNode (Logic lidD)) (inc name) opts sp1
2353f65833a3da763392f771223250cd50b8d873Christian Maeder sigmaD <- adj $ coerceSign lid' lidD' "Analysis of data spec" sigma'
dbc98cd8a9a829e020cfa0a9f3aff89de75caaa9Christian Maeder (sigmaD',sensD') <- adj $ map_sign cid sigmaD
2353f65833a3da763392f771223250cd50b8d873Christian Maeder let gsigmaD' = G_sign lidP' sigmaD'
cb2044812811d66efe038d914966e04290be93faChristian Maeder node_contents = DGNode {
cb2044812811d66efe038d914966e04290be93faChristian Maeder dgn_name = name,
9d6562465b41f17c7967d4e5678f34811d958cb2Christian Maeder dgn_theory = G_theory lidP' sigmaD' $ toThSens sensD',
cb2044812811d66efe038d914966e04290be93faChristian Maeder dgn_nf = Nothing,
2353f65833a3da763392f771223250cd50b8d873Christian Maeder dgn_sigma = Nothing,
cb2044812811d66efe038d914966e04290be93faChristian Maeder dgn_origin = DGData }
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder node = getNewNode dg1
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder link = (n',node,DGLink {
cb2044812811d66efe038d914966e04290be93faChristian Maeder dgl_morphism = GMorphism cid sigmaD (ide lidP' sigmaD'),
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgl_type = GlobalDef,
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dgl_origin = DGData })
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder dg2 = insEdgeNub link $
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder insNode (node,node_contents) dg1
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder nsig2 = NodeSig node gsigmaD'
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder (sp2',nsig3,dg3) <-
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder ana_SPEC lg (gannos,genv,dg2) (JustNode nsig2) name opts sp2
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder return (Data (Logic lidD) (Logic lidP)
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder (replaceAnnoted sp1' asp1)
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder (replaceAnnoted sp2' asp2)
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder-- analysis of renamings
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederana_ren1 :: LogicGraph -> GMorphism -> G_mapping -> Result GMorphism
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederana_ren1 _ (GMorphism r sigma mor)
cb2044812811d66efe038d914966e04290be93faChristian Maeder (G_symb_map (G_symb_map_items_list lid sis)) = do
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder let lid2 = targetLogic r
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder sis1 <- coerceSymbMapItemsList lid lid2 "Analysis of renaming" sis
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder rmap <- stat_symb_map_items lid2 sis1
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder mor1 <- induced_from_morphism lid2 rmap (cod lid2 mor)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder mor2 <- comp lid2 mor mor1
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder return $ GMorphism r sigma mor2
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederana_ren1 lg mor (G_logic_translation (Logic_code tok src tar pos1)) = do
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let adj = adjustPos pos1
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder G_sign srcLid srcSig <- return (cod Grothendieck mor)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder c <- adj $ case tok of
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Just ctok -> do
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Comorphism cid <- lookupComorphism (tokStr ctok) lg
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder when (isJust src && getLogicStr (fromJust src) /=
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder language_name (sourceLogic cid))
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (fail (getLogicStr (fromJust src)++"is not the source logic of "
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ++ language_name cid))
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder when (isJust tar && getLogicStr (fromJust tar) /=
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder language_name (targetLogic cid))
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder (fail (getLogicStr (fromJust tar)++"is not the target logic of "
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ++ language_name cid))
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return (Comorphism cid)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder Nothing -> case tar of
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder Just (Logic_name l _) -> do
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder tarL <- lookupLogic "with logic: " (tokStr l) lg
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder logicInclusion lg (Logic srcLid) tarL
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder Nothing -> fail "with logic: cannot determine comorphism"
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder mor1 <- adj $ gEmbedComorphism c (G_sign srcLid srcSig)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder adj $ comp Grothendieck mor mor1
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maeder where getLogicStr (Logic_name l _) = tokStr l
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederana_ren :: LogicGraph -> Result GMorphism -> G_mapping -> Result GMorphism
c5a4c5f506ea34fa527065b4187127a18c6e2418Christian Maederana_ren lg mor_res ren =
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder do mor <- mor_res
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder ana_ren1 lg mor ren
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederana_RENAMING :: LogicGraph -> G_sign -> HetcatsOpts -> RENAMING
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder -> Result GMorphism
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maederana_RENAMING lg gSigma opts (Renaming ren _) =
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder if isStructured opts
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder then return (ide Grothendieck gSigma)
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder else foldl (ana_ren lg) (return (ide Grothendieck gSigma)) ren
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder-- analysis of restrictions
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederana_restr1 :: DGraph -> G_sign -> GMorphism -> G_hiding -> Result GMorphism
b53688bfed888214b485cf76439d57262d80e0a7Christian Maederana_restr1 _ (G_sign _lid _sigma) (GMorphism cid sigma1 mor)
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder (G_symb_list (G_symb_items_list lid' sis')) = do
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder let lid1 = sourceLogic cid
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder lid2 = targetLogic cid
bbba6dd86153aacb0f662b182b128df0eb09fd54Christian Maeder sis1 <- coerceSymbItemsList lid' lid1 "Analysis of restriction" sis'
be43c3fa0292555bd126784ae27ff5c1d23438cbChristian Maeder rsys <- stat_symb_items lid1 sis1
7968d3a131e5a684ec1ff0c6d88aae638549153dChristian Maeder let sys = sym_of lid1 sigma1
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder let sys' = Set.filter (\sy -> any (\rsy -> matches lid1 sy rsy) rsys)
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder-- if sys' `disjoint` () then return ()
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder-- else plain_error () "attempt to hide symbols from the local environment" pos
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder mor1 <- cogenerated_sign lid1 sys' sigma1
b53688bfed888214b485cf76439d57262d80e0a7Christian Maeder mor1' <- map_morphism cid mor1
7f7460e7095628f3437b116ee78d3043d11f8febChristian Maeder mor2 <- comp lid2 mor1' mor
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder return $ GMorphism cid (dom lid1 mor1) mor2
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maederana_restr1 _dg _gSigma _mor
5941ba0b9a99ac98f78a89a9f3303102657e36ccChristian Maeder (G_logic_projection (Logic_code _tok _src _tar pos1)) =
a3a7d8b3cdf05c8040c62dbcf9a15dc5042cd721Christian Maeder fatal_error "no analysis of logic projections yet" pos1
5941ba0b9a99ac98f78a89a9f3303102657e36ccChristian Maederana_restr :: DGraph -> G_sign -> Result GMorphism -> G_hiding
5941ba0b9a99ac98f78a89a9f3303102657e36ccChristian Maeder -> Result GMorphism
mor1 <- adj $ generated_sign lid' (sys1 `Set.union` sys'') sigma'
rmap' <- if null sis then return Map.empty
if Set.all (\sy -> lookupFM symmap_mor sy == Just sy) symI
case Map.lookup vn genv of
idComponents :: Id -> Set.Set Id -> [Id]
$ map (\id1 -> if id1 `Set.member` ids
Set.map (\id -> (id,idComponents id ids)) ids
case Map.lookup i idmap of
Just ids -> case Set.size ids of
1 -> return $ Set.findMin ids
else return (Map.insert i (Id toks compsnew pos1) m1)
idsB = Set.map (sym_name lid) symsB
idh = Map.foldWithKey
(\sy1 sy2 -> Rel.setInsert (sym_name lid sy1) (sym_name lid sy2))
let rIdExt = Map.foldWithKey
(\id1 id2 -> Map.insert (id_to_raw lid id1) (id_to_raw lid id2))
r = rh `Map.union` rIdExt
let illShared = (sym_of lid sigmaA `Set.intersection` sym_of lid sigmaAD )
Set.\\ Rel.image h symsP
when (not (Set.null illShared))
when (not (Set.null newIdentifications))
-> [Syntax.AS_Structured.G_mapping] -> Result G_symb_map_items_list
(Syntax.AS_Structured.G_symb_map (G_symb_map_items_list lid1 sis1)) = do