AnalysisStructured.hs revision c1168130136b44bcfa8946dbda76be553aa7344b
c06dd8856a03b72f6b3f69e874f8700f10cb8522Christian Maeder Module : $Header$
75a6279dbae159d018ef812185416cf6df386c10Till Mossakowski Copyright : (c) Till Mossakowski and Uni Bremen 2003
75a6279dbae159d018ef812185416cf6df386c10Till Mossakowski Licence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
ae17d457c2d00d47d65e8cd510c3fd21b9516ccbTill Mossakowski Maintainer : till@tzi.de
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski Stability : provisional
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski Portability : portable
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Analysis of structured specifications
679d3f541f7a9ede4079e045f7758873bb901872Till Mossakowski Follows the verfication semantic rules in Chap. IV:4.7
679d3f541f7a9ede4079e045f7758873bb901872Till Mossakowski of the CASL Reference Manual.
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski analysis of basic specs: use union of sigs
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski analysis of instantiations: if necessary, translate body along inclusion comorphism
82d681fe6950e2a35f28fdefb874d060632faccaTill Mossakowski Improve efficiency by storing local signature fragments only
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Name views in devgraphs?
70e2af8d4bf21bcdfb53e9a0414e27173b577a1eTill Mossakowski spec <name> not found: line number!
2b4130336e941b7d01c78a6da55449a4c6eca609Till Mossakowski Issue warning for unions of non-disjoint signatures
2b4130336e941b7d01c78a6da55449a4c6eca609Till Mossakowski (and offer tool for renaming?)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Check that translations and reductions do not effect local env
82d681fe6950e2a35f28fdefb874d060632faccaTill Mossakowski (Implement new semantics for revealing here)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Should we use institution independent analysis over the Grothendieck logic?
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder abstract syntax + devgraph would have to be changed to homogeneous case
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder logic translations are symbol maps in the Grothendieck logic
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Problem with this approach: symbol functor goes into rel,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder and induced_from_morphism gets difficult to implement
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Unions need inclusion morphisms. Should these play a special role?
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder At least we need a function delivering the inclusion morphism
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder between two (sub)signatures.
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder In most logics, inclusions could be represented specially, such
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder that composition for them becomes fast.
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Should we even identify an inclusion subcategory?
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Then inclusions are represented by pair of signatures
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder (Non-inclusions could be specially displayed in the DG)
c529224e0ec191fbaa87261f05c34f89c17b3f3aTill Mossakowski No optimization of heterogeneous unions!
c529224e0ec191fbaa87261f05c34f89c17b3f3aTill Mossakowski (or use heterogeneous compInclusion in Proofs/Proof.hs)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Treatment of translations and reductions along logic translations
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder (see WADT 02 paper).
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Open question:
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder may local env be translated, and even reduced, along logic translations?
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder if yes: how is local env linked to signature of resulting spec?
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder (important e.g. for checking that local env is not being renamed?)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder does signature+comorphism suffice, such that c(local env)\subseteq sig?
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder if no: this means that only closed specs may be translated
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Revealings without translations: just one arrow
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Pushouts: only admissible within one logic?
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski Instantiations with formal parameter: add no new internal nodes
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski call extend_morphism
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Optimizations:
e3c9174a782e90f965a0b080c22861c3ef5af12dTill Mossakowski Union nodes can be extended by a basic spec directly (no new node needed)
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski no new nodes for trivial translations
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Also: free, cofree nodes
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski Basic specs: if local env node is otherwise unused, overwrite it with
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski local sig+axioms
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Ensure that just_struct option leads to disabling of various dg operations
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (show sig, show mor, proving)
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski local: better error message for the following
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowskispec GenCardinality [sort Subject,Object;
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski pred predicate : Subject * Object] =
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski Set [sort Object fit sort Elem |-> Object]
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder reveal Set[Object], #__, __eps__,
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder Nat,0,1,2,3,4,5,6,7,8,9,__@@__,__>=__,__<=__
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski op toSet : Subject -> Set [Object]
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder forall x : Subject; y : Object
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder . predicate (x,y) <=> y eps toSet(x)
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski pred minCardinality(s: Subject;n: Nat) <=>
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder # toSet(s) >= n;
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder maxCardinality(s: Subject;n: Nat) <=>
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder # toSet(s) <= n;
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder cardinality(s: Subject;n: Nat) <=>
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder # toSet(s) = n
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski%%} hide Pos,toSet,Set[Object],#__,__eps__,__<=__,__>=__
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maedermodule Static.AnalysisStructured (ana_SPEC, ana_GENERICITY,
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder ana_VIEW_TYPE, ana_err, isStructured,
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder ana_RENAMING, ana_RESTRICTION,
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder extendMorphism)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiimport Options
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maederimport Common.Lib.Graph hiding (empty)
0c2a90cbfb63865ff485c3fbe20a14589a5914beTill Mossakowskiimport qualified Common.Lib.Set as Set
c616e681da8c052b62e14247fea522da099ac0e4Christian Maederimport qualified Common.Lib.Map as Map
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maederimport Data.List hiding (union)
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- | analyze a SPEC
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- Parameters: global context, local environment,
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- the SIMPLE_ID may be a name if the specification shall be named,
31c49f2fa23d4ac089f35145d80a224deb6ea7e4Till Mossakowski-- options: here we need the info: shall only the structure be analysed?
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowskiana_SPEC :: LogicGraph -> GlobalContext -> NodeSig -> Maybe SIMPLE_ID ->
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski HetcatsOpts -> SPEC -> Result (SPEC,NodeSig,DGraph)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_SPEC lg gctx@(gannos,genv,dg) nsig name opts sp =
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Basic_spec (G_basic_spec lid bspec) ->
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder do G_sign lid' sigma' <- return (getSig nsig)
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sigma <- mcoerce lid' lid "Analysis of basic spec" sigma'
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder (bspec', _sigma_local, sigma_complete, ax) <-
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder if isStructured opts
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski then return (bspec,empty_signature lid, empty_signature lid,[])
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder else do b <- maybeToMonad
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski ("no basic analysis for logic "
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski ++language_name lid)
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski (basic_analysis lid)
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski b (bspec,sigma,gannos)
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski incl <- ginclusion lg
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski (G_sign lid sigma) (G_sign lid sigma_complete)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = G_sign lid sigma_complete, -- no, not only the delta
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid ax,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGBasic }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder [node] = newNodes 0 dg
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dg' = insNode (node,node_contents) dg
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link = DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGExtension }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dg'' = case nsig of
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder EmptyNode _ -> dg'
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski NodeSig (n,_) -> insEdgeNub (n,node,link) dg'
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Basic_spec (G_basic_spec lid bspec'),
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski NodeSig (node,G_sign lid sigma_complete),
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Translation asp ren ->
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski do let sp1 = item asp
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp1',nsig',dg') <- ana_SPEC lg gctx nsig Nothing opts sp1
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder n' <- maybeToMonad
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: Translation of empty spec" (getNode nsig')
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski let gsigma = getSig nsig'
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski mor <- ana_RENAMING lg gsigma opts ren
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- ??? check that mor is identity on local env
788dd403da4203e895e15892ef7fa48129617d30Till Mossakowski let gsigma' = cod Grothendieck mor
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- ??? too simplistic for non-comorphism inter-logic translations
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski G_sign lid' _ <- return gsigma'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
a938729e277da5c7742bb88946ab2c150416fd5dTill Mossakowski dgn_sign = gsigma',
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid' [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGTranslation }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder [node] = newNodes 0 dg'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link = (n',node,DGLink {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_morphism = mor,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGTranslation })
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski return (Translation (replaceAnnoted sp1' asp) ren,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski NodeSig(node,gsigma'),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node,node_contents) dg')
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Reduction asp restr ->
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski do let sp1 = item asp
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp1',nsig',dg') <- ana_SPEC lg gctx nsig Nothing opts sp1
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let gsigma = getSig nsig
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigma' = getSig nsig'
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder n' <- maybeToMonad
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: Reduction of empty spec" (getNode nsig')
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (hmor,tmor) <- ana_RESTRICTION dg gsigma gsigma' opts restr
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- we treat hiding and revealing differently
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- in order to keep the dg as simple as possible
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski do let gsigma'' = dom Grothendieck hmor
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- ??? too simplistic for non-comorphism inter-logic reductions
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski G_sign lid' _ <- return gsigma''
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma'', -- G_sign lid' (empty_signature lid'),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid' [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGHiding }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder [node] = newNodes 0 dg'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link = (n',node,DGLink {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_morphism = hmor,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = HidingDef,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGHiding })
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski return (Reduction (replaceAnnoted sp1' asp) restr,
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski NodeSig(node,gsigma''),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node,node_contents) dg')
d08907a7832988612fbc0682b216e150d1e738d2Christian Maeder Just tmor' -> do
d08907a7832988612fbc0682b216e150d1e738d2Christian Maeder let gsigma1 = dom Grothendieck tmor'
d08907a7832988612fbc0682b216e150d1e738d2Christian Maeder gsigma'' = cod Grothendieck tmor'
d08907a7832988612fbc0682b216e150d1e738d2Christian Maeder -- ??? too simplistic for non-comorphism inter-logic reductions
d08907a7832988612fbc0682b216e150d1e738d2Christian Maeder G_sign lid1 _ <- return gsigma1
d08907a7832988612fbc0682b216e150d1e738d2Christian Maeder G_sign lid'' _ <- return gsigma''
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- the case with identity translation leads to a simpler dg
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski if tmor' == ide Grothendieck (dom Grothendieck tmor')
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let [node1] = newNodes 0 dg'
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski node_contents1 = DGNode {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma1, --G_sign lid1 (empty_signature lid1),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid1 [],
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_origin = DGRevealing }
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski link1 = (n',node1,DGLink {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_morphism = hmor,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = HidingDef,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_origin = DGRevealing })
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski return (Reduction (replaceAnnoted sp1' asp) restr,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski NodeSig(node1,gsigma1),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link1 $
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski insNode (node1,node_contents1) dg')
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let [node1,node''] = newNodes 1 dg'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder node_contents1 = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = Nothing,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma1, --G_sign lid1 (empty_signature lid1),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid1 [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGRevealing }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link1 = (n',node1,DGLink {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_morphism = hmor,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = HidingDef,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGRevealing })
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder node_contents'' = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma'', -- G_sign lid'' (empty_signature lid''),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid'' [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGRevealTranslation }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link'' = (node1,node'',DGLink {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_morphism = tmor',
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGRevealTranslation })
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski return (Reduction (replaceAnnoted sp1' asp) restr,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski NodeSig(node'',gsigma''),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link'' $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node'',node_contents'') $
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link1 $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node1,node_contents1) dg')
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski Union [] _ -> return (sp,nsig,dg)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Union asps pos ->
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder do let sps = map item asps
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (sps',nsigs,dg') <-
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski let ana r sp' = do
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (sps1,nsigs,dg') <- r
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (sp1,nsig',dg1) <- ana_SPEC lg (gannos,genv,dg')
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski nsig Nothing opts sp'
a205324331077b7d5a2c08fb3f0f57e5c029f9aaTill Mossakowski return (sp1:sps1,nsig':nsigs,dg1)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski in foldl ana (return ([],[],dg)) sps
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let nsigs' = reverse nsigs
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder adj = adjustPos $ headPos pos
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gbigSigma <- adj $ gsigManyUnion lg (map getSig nsigs')
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski G_sign lid' _ <- return gbigSigma
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gbigSigma, -- G_sign lid' (empty_signature lid'),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid' [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGUnion }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder [node] = newNodes 0 dg'
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski insE dgres (n,gsigma) = do
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl <- adj $ ginclusion lg gsigma gbigSigma
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski let link = DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_type = GlobalDef,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_origin = DGUnion }
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski return (insEdgeNub (n,node,link) dg1)
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dg'' <- foldl insE (return (insNode (node,node_contents) dg'))
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski (catMaybes (map getNodeAndSig nsigs'))
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski return (Union (map (uncurry replaceAnnoted)
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski (zip (reverse sps') asps))
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski NodeSig(node,gbigSigma),
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski --Extension [] pos -> return (sp,nsig,dg)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski Extension asps pos -> do
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (sps',nsig1,dg1) <- foldl ana (return ([],nsig,dg)) namedSps
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Extension (map (uncurry replaceAnnoted)
21dae7237ac384abdb94a81e00b3f099873ec623Till Mossakowski (zip (reverse sps') asps))
1a7b7802544aa94828d7f4e7be5788501c572934Till Mossakowski namedSps = zip3 (map (\_ -> Nothing) (tail asps) ++ [name])
1a7b7802544aa94828d7f4e7be5788501c572934Till Mossakowski (nullPos:pos)
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski ana res (name',asp',pos') = do
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (sps',nsig',dg') <- res
1a7b7802544aa94828d7f4e7be5788501c572934Till Mossakowski (sp1',nsig1,dg1) <-
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski ana_SPEC lg (gannos,genv,dg') nsig' name' opts (item asp')
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- insert theorem link for semantic annotations
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- take the first semantic annotation
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski let anno = find isSemanticAnno $ l_annos asp'
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- is the extension going between real nodes?
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski dg2 <- case (anno,getNode nsig',getNode nsig1) of
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski (Just anno0@(Semantic_anno anno1 _),Just n',Just n1) -> do
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- any other semantic annotation? that's an error
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski when (any (\an -> isSemanticAnno an && an/=anno0) $ l_annos asp')
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski (pplain_error () (ptext "Conflicting semantic annotations")
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- %implied should not occur here
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski when (anno1==SA_implied)
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski (pplain_error () (ptext "Annotation %implied should come after a BASIC-ITEM")
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski let sig1 = getSig nsig1
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski sig' = getSig nsig'
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski if anno1==SA_implies then do
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski when (not (is_subgsign sig1 sig')) (pplain_error ()
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski (ptext "Signature must not be extended in presence of %implies")
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- insert a theorem link according to p. 319 of the CASL Reference Manual
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski return $ insEdgeNub (n1,n',DGLink {
1a7b7802544aa94828d7f4e7be5788501c572934Till Mossakowski dgl_morphism = ide Grothendieck sig1,
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski dgl_type = GlobalThm Open Cons Open,
1a7b7802544aa94828d7f4e7be5788501c572934Till Mossakowski dgl_origin = DGExtension }) dg1
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski let anno2 = case anno1 of
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski SA_cons -> Cons
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski SA_def -> Def
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski SA_mono -> Mono
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- insert a theorem link according to p. 319 of the CASL Reference Manual
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- the theorem link is trivally proved by the parallel definition link,
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- but for clarity, we leave it open here
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski -- the interesting open proof obligation is anno2, of course
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski incl <- ginclusion lg sig' sig1
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski return $ insEdgeNub (n',n1,DGLink {
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski dgl_morphism = incl,
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski dgl_type = GlobalThm Open anno2 Open,
c1168130136b44bcfa8946dbda76be553aa7344bTill Mossakowski dgl_origin = DGExtension }) dg1
1a7b7802544aa94828d7f4e7be5788501c572934Till Mossakowski _ -> return dg1
1a7b7802544aa94828d7f4e7be5788501c572934Till Mossakowski return (sp1':sps',nsig1,dg2)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder Free_spec asp poss ->
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski do let sp1 = item asp
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp',nsig',dg') <- ana_SPEC lg gctx nsig Nothing opts sp1
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder n' <- maybeToMonad
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: Free spec over empty spec" (getNode nsig')
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let gsigma' = getSig nsig'
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder pos = headPos poss
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski G_sign lid' _ <- return gsigma'
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl <- adjustPos pos $ ginclusion lg (getSig nsig) gsigma'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma', -- G_sign lid' (empty_signature lid'), -- delta is empty
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid' [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGFree }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder [node] = newNodes 0 dg'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link = (n',node,DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = FreeDef nsig,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGFree })
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder return (Free_spec (replaceAnnoted sp' asp) poss,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski NodeSig(node,gsigma'),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node,node_contents) dg')
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder Cofree_spec asp poss ->
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski do let sp1 = item asp
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp',nsig',dg') <- ana_SPEC lg gctx nsig Nothing opts sp1
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder n' <- maybeToMonad
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski "Internal error: Cofree spec over empty spec" (getNode nsig')
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let gsigma' = getSig nsig'
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder pos = headPos poss
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski G_sign lid' _ <- return gsigma'
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl <- adjustPos pos $ ginclusion lg (getSig nsig) gsigma'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma', -- G_sign lid' (empty_signature lid'), -- delta is empty
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid' [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGCofree }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder [node] = newNodes 0 dg'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link = (n',node,DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = CofreeDef nsig,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGCofree })
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder return (Cofree_spec (replaceAnnoted sp' asp) poss,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski NodeSig(node,gsigma'),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node,node_contents) dg')
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder Local_spec asp asp' poss ->
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski do let sp1 = item asp
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski sp1' = item asp'
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp2,nsig',dg') <- ana_SPEC lg gctx nsig Nothing opts sp1
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp2',nsig'',dg'') <- ana_SPEC lg (gannos,genv,dg') nsig' Nothing opts sp1'
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder n'' <- maybeToMonad
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: Local spec over empty spec" (getNode nsig'')
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let gsigma = getSig nsig
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigma' = getSig nsig'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigma'' = getSig nsig''
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder G_sign lid sigma <- return gsigma
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder G_sign lid' sigma' <- return gsigma'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder G_sign lid'' sigma'' <- return gsigma''
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sigma1 <- mcoerce lid' lid "Analysis of local spec" sigma'
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sigma2 <- mcoerce lid'' lid "Analysis of local spec" sigma''
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let sys = sym_of lid sigma
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder sys1 = sym_of lid sigma1
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder sys2 = sym_of lid sigma2
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder pos = headPos poss
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder mor3 <- if isStructured opts then return (ide lid sigma2)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder else adjustPos pos $ cogenerated_sign lid
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (sys1 `Set.difference` sys) sigma2
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let sigma3 = dom lid mor3
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski -- gsigma2 = G_sign lid sigma2
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigma3 = G_sign lid sigma3
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder sys3 = sym_of lid sigma3
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder when (not( isStructured opts ||
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder sys2 `Set.difference` sys1 `Set.subset` sys3))
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder $ pplain_error () (text
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder "attempt to hide the following symbols from the local environment"
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski $$ printText ((sys2 `Set.difference` sys1) `Set.difference` sys3))
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma3, -- G_sign lid (empty_signature lid), -- delta is empty
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGLocal }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder [node] = newNodes 0 dg''
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link = (n'',node,DGLink {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_morphism = gEmbed (G_morphism lid mor3),
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = HidingDef,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGLocal })
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski return (Local_spec (replaceAnnoted sp2 asp)
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (replaceAnnoted sp2' asp')
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski NodeSig(node,gsigma3),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node,node_contents) dg'')
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Closed_spec asp pos ->
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski do let sp1 = item asp
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder l = getLogic nsig
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski -- analyse spec with empty local env
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp',nsig',dg') <- ana_SPEC lg gctx (EmptyNode l) Nothing opts sp1
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder n' <- maybeToMonad
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: Closed spec over empty spec" (getNode nsig')
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski -- construct union with local env
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let gsigma = getSig nsig
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigma' = getSig nsig'
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder adj = adjustPos $ headPos pos
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigma'' <- adj $ gsigUnion lg gsigma gsigma'
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski G_sign lid'' _ <- return gsigma''
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski incl1 <- adj $ ginclusion lg gsigma gsigma''
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl2 <- adj $ ginclusion lg gsigma' gsigma''
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let [node] = newNodes 0 dg'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma'', -- G_sign lid'' (empty_signature lid''),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid'' [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGClosed }
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski link1 = DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl1,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgl_origin = DGClosedLenv }
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski link2 = (n',node,DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl2,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgl_origin = DGClosed })
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski insLink1 = case (getNode nsig) of
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Nothing -> id
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski Just n -> insEdgeNub (n,node,link1)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Closed_spec (replaceAnnoted sp' asp) pos,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski NodeSig(node,gsigma''),
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski insEdgeNub link2 $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node,node_contents) dg')
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski Qualified_spec (Logic_name ln sublog) asp pos -> do
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder l <- lookupLogic "Static analysis: " (tokStr ln) lg
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski -- analyse spec with empty local env
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski (sp',nsig',dg') <- ana_SPEC lg gctx (EmptyNode l)
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski Nothing opts (item asp)
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder n' <- maybeToMonad
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski "Internal error: Qualified spec over empty spec" (getNode nsig')
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski -- construct union with local env
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski let gsigma = getSig nsig
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigma' = getSig nsig'
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski adj = adjustPos $ headPos pos
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigma'' <- adj $ gsigUnion lg gsigma gsigma'
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski G_sign lid'' _ <- return gsigma''
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski incl1 <- adj $ ginclusion lg gsigma gsigma''
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski incl2 <- adj $ ginclusion lg gsigma' gsigma''
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski let [node] = newNodes 0 dg'
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski node_contents = DGNode {
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgn_name = name,
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgn_sign = gsigma'', -- G_sign lid'' (empty_signature lid''),
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgn_sens = G_l_sentence_list lid'' [],
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgn_origin = DGLogicQual }
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski link1 = DGLink {
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgl_morphism = incl1,
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgl_type = GlobalDef,
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgl_origin = DGLogicQualLenv }
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski link2 = (n',node,DGLink {
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgl_morphism = incl2,
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgl_type = GlobalDef,
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski dgl_origin = DGLogicQual })
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski insLink1 = case (getNode nsig) of
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski Nothing -> id
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski Just n -> insEdgeNub (n,node,link1)
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski return (Qualified_spec (Logic_name ln sublog) (replaceAnnoted sp' asp) pos,
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski NodeSig(node,gsigma''),
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski insEdgeNub link2 $
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski insNode (node,node_contents) dg')
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski Group asp pos -> do
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp',nsig',dg') <- ana_SPEC lg gctx nsig name opts (item asp)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Group (replaceAnnoted sp' asp) pos,nsig',dg')
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder Spec_inst spname afitargs poss -> do
6218c1f87fbce3087d7d013c41a3adac5ade1d9cChristian Maeder let pos = if null poss then tokPos spname else head poss
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder adj = adjustPos pos
c616e681da8c052b62e14247fea522da099ac0e4Christian Maeder case Map.lookup spname genv of
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski Nothing -> plain_error (sp,nsig,dg)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder ("Specification "++ showPretty spname " not found") pos
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Just (ViewEntry _) ->
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski plain_error (sp,nsig,dg)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder (showPretty spname " is a view, not a specification") pos
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Just (ArchEntry _) ->
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski plain_error (sp,nsig,dg)
74e82e43f5787027c5d4e523397525a259d6d001Christian Maeder (showPretty spname
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder " is an architectural, not a structured specification") pos
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Just (UnitEntry _) ->
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski plain_error (sp,nsig,dg)
74e82e43f5787027c5d4e523397525a259d6d001Christian Maeder (showPretty spname
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder " is a unit specification, not a structured specification") pos
95656e84acc96386173c1d6fc068aa2fb8820020Till Mossakowski Just (RefEntry) ->
95656e84acc96386173c1d6fc068aa2fb8820020Till Mossakowski plain_error (sp,nsig,dg)
95656e84acc96386173c1d6fc068aa2fb8820020Till Mossakowski (showPretty spname
95656e84acc96386173c1d6fc068aa2fb8820020Till Mossakowski " is a refinement specification, not a structured specification") pos
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski Just (SpecEntry gs@(imps,params,_,body)) ->
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder case (\x y -> (x,x-y)) (length afitargs) (length params) of
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- the case without parameters leads to a simpler dg
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let gsigmaB = getSig body
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigma <- adj $ gsigUnion lg (getSig nsig) gsigmaB
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski G_sign lid _ <- return gsigma
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nB <- adj $ maybeToMonad
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: empty body spec" (getNode body)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder case (getNode nsig) of
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- the subcase with empty local env leads to an even simpler dg
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- if the node shall not be named and the logic does not change,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski if isNothing name && langNameSig gsigma==langNameSig gsigmaB
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- then just return the body
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski then return (sp,body,dg)
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski -- otherwise, we need to create a new one
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl <- adj $ ginclusion lg gsigmaB gsigma
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski let [node] = newNodes 0 dg
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski node_contents = DGNode {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma, -- G_sign lid (empty_signature lid),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid [],
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgn_origin = DGSpecInst spname}
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski link = (nB,node,DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_type = GlobalDef,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_origin = DGSpecInst spname})
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski NodeSig(node,gsigma),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link $
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski insNode (node,node_contents) dg)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- the subcase with nonempty local env
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl1 <- adj $ ginclusion lg (getSig nsig) gsigma
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl2 <- adj $ ginclusion lg gsigmaB gsigma
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski let [node] = newNodes 0 dg
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski node_contents = DGNode {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigma, -- G_sign lid (empty_signature lid),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lid [],
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgn_origin = DGSpecInst spname}
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski link1 = (n,node,DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl1,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_type = GlobalDef,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_origin = DGSpecInst spname})
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski link2 = (nB,node,DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl2,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_type = GlobalDef,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_origin = DGSpecInst spname})
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski NodeSig(node,gsigma),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link1 $
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link2 $
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski insNode (node,node_contents) dg)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- now the case with parameters
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let fitargs = map item afitargs
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (fitargs',dg',args) <-
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski foldl anaFitArg (return ([],dg,[])) (zip params fitargs)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let actualargs = reverse args
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski (gsigma',morDelta) <- adj $ apply_GS lg gs actualargs
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigmaRes <- adj $ gsigUnion lg (getSig nsig) gsigma'
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski G_sign lidRes _ <- return gsigmaRes
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nB <- adj $ maybeToMonad
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: empty body spec" (getNode body)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl1 <- adj $ ginclusion lg (getSig nsig) gsigmaRes
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let [node] = newNodes 0 dg'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = name,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigmaRes, -- G_sign lid' (empty_signature lid'),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lidRes [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGSpecInst spname}
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link1 = DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl1,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGSpecInst spname}
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insLink1 = case (getNode nsig) of
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Nothing -> id
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski Just n -> insEdgeNub (n,node,link1)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder link2 = (nB,node,DGLink {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_morphism = gEmbed morDelta,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGSpecInst spname})
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski parLinks = catMaybes (map (parLink gsigmaRes node) actualargs)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Spec_inst spname
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (map (uncurry replaceAnnoted)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (zip (reverse fitargs') afitargs))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski NodeSig(node,gsigmaRes),
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski foldr insEdgeNub
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link2 $
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder insNode (node,node_contents) dg')
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski anaFitArg res (nsig',fa) = do
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (fas',dg1,args) <- res
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (fa',dg',arg) <- ana_FIT_ARG lg (gannos,genv,dg1)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski spname imps nsig' opts fa
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (fa':fas',dg',arg:args)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder parLink gsigma' node (_mor_i,nsigA_i) = do
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder nA_i <- getNode nsigA_i
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski incl <- maybeResult $ ginclusion lg (getSig nsigA_i) gsigma'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let link = DGLink {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_morphism = incl,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitSpec }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder return (nA_i,node,link)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- finally the case with conflicting numbers of formal and actual parameters
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski plain_error (sp,nsig,dg)
74e82e43f5787027c5d4e523397525a259d6d001Christian Maeder (showPretty spname " expects "++show (length params)++" arguments"
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder ++" but was given "++show (length afitargs)) pos
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski Data (Logic lidD) (Logic lidP) asp1 asp2 pos ->
e3c9174a782e90f965a0b080c22861c3ef5af12dTill Mossakowski do let sp1 = item asp1
e3c9174a782e90f965a0b080c22861c3ef5af12dTill Mossakowski sp2 = item asp2
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder adj = adjustPos $ headPos pos
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder Comorphism cid <- adj $ logicInclusion lg (Logic lidD) (Logic lidP)
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski let lidD' = sourceLogic cid
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski lidP' = targetLogic cid
21dae7237ac384abdb94a81e00b3f099873ec623Till Mossakowski (sp1',nsig1,dg1) <-
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski ana_SPEC lg gctx (EmptyNode (Logic lidD)) Nothing opts sp1
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder n' <- adj $ maybeToMonad
49b9a9cbf17489cbaf97431247161f42e9fc5ae0Till Mossakowski "Internal error: Data spec over empty spec" (getNode nsig1)
49b9a9cbf17489cbaf97431247161f42e9fc5ae0Till Mossakowski let gsigma' = getSig nsig1
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski G_sign lid' sigma' <- return gsigma'
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder sigmaD <- adj $ mcoerce lid' lidD' "Analysis of data spec" sigma'
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder (sigmaD',sensD') <- adj $ map_sign cid sigmaD
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski let gsigmaD' = G_sign lidP' sigmaD'
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski node_contents = DGNode {
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski dgn_name = Nothing,
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski dgn_sign = gsigmaD',
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski dgn_sens = G_l_sentence_list lidP' sensD',
5b1394673f35f4d23cfe08175841ab414a39678eMarkus Roggenbach dgn_origin = DGData }
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski [node] = newNodes 0 dg1
e3c9174a782e90f965a0b080c22861c3ef5af12dTill Mossakowski link = (n',node,DGLink {
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski dgl_morphism = GMorphism cid sigmaD (ide lidP' sigmaD'),
5b1394673f35f4d23cfe08175841ab414a39678eMarkus Roggenbach dgl_type = GlobalDef,
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski dgl_origin = DGData })
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski dg2 = insEdgeNub link $
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski insNode (node,node_contents) dg1
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski nsig2 = NodeSig (node,gsigmaD')
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski (sp2',nsig3,dg3) <-
1df33829303cbf924aa018ac5ce9a28e69c17d22Till Mossakowski ana_SPEC lg (gannos,genv,dg2) nsig2 name opts sp2
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski return (Data (Logic lidD) (Logic lidP)
21dae7237ac384abdb94a81e00b3f099873ec623Till Mossakowski (replaceAnnoted sp1' asp1)
21dae7237ac384abdb94a81e00b3f099873ec623Till Mossakowski (replaceAnnoted sp2' asp2)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder-- analysis of renamings
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowskiana_ren1 :: LogicGraph -> GMorphism -> (G_mapping,Pos) -> Result GMorphism
c0380b947eef252db81ee562246bb732555427f4Till Mossakowskiana_ren1 _ (GMorphism r sigma mor)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder (G_symb_map (G_symb_map_items_list lid sis),pos) = do
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski let lid2 = targetLogic r
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder adj = adjustPos pos
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sis1 <- adj $ mcoerce lid2 lid "Analysis of renaming" sis
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder rmap <- adj $ stat_symb_map_items lid2 sis1
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder mor1 <- adj $ induced_from_morphism lid2 rmap (cod lid2 mor)
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder mor2 <- adj $ comp lid2 mor mor1
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder return $ GMorphism r sigma mor2
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowskiana_ren1 lg mor (G_logic_translation (Logic_code tok src tar pos1),pos2) = do
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder let adj = adjustPos $ headPos $ pos1 ++ [pos2]
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski G_sign srcLid srcSig <- return (cod Grothendieck mor)
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder c <- adj $ case tok of
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski Just ctok -> do
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski Comorphism cid <- lookupComorphism (tokStr ctok) lg
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski when (isJust src && getLogicStr (fromJust src) /=
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski language_name (sourceLogic cid))
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski (fail (getLogicStr (fromJust src)++"is not the source logic of "
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski ++ language_name cid))
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski when (isJust tar && getLogicStr (fromJust tar) /=
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski language_name (targetLogic cid))
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski (fail (getLogicStr (fromJust tar)++"is not the target logic of "
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski ++ language_name cid))
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski return (Comorphism cid)
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski Nothing -> case tar of
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski Just (Logic_name l _) -> do
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski tarL <- lookupLogic "with logic: " (tokStr l) lg
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski logicInclusion lg (Logic srcLid) tarL
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski Nothing -> fail "with logic: cannot determine comorphism"
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder mor1 <- adj $ gEmbedComorphism c (G_sign srcLid srcSig)
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder adj $ comp Grothendieck mor mor1
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski where getLogicStr (Logic_name l _) = tokStr l
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowskiana_ren :: LogicGraph -> Result GMorphism -> (G_mapping,Pos) -> Result GMorphism
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowskiana_ren lg mor_res ren =
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder do mor <- mor_res
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski ana_ren1 lg mor ren
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowskiana_RENAMING :: LogicGraph -> G_sign -> HetcatsOpts -> RENAMING -> Result GMorphism
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowskiana_RENAMING lg gSigma opts (Renaming ren pos) =
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder if isStructured opts
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski then return (ide Grothendieck gSigma)
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski else foldl (ana_ren lg) (return (ide Grothendieck gSigma)) ren'
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski ren' = zip ren (tail (pos ++ repeat nullPos))
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder-- analysis of restrictions
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maederana_restr1 :: DGraph -> G_sign -> GMorphism -> (G_hiding,Pos)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder -> Result GMorphism
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maederana_restr1 _ (G_sign _lid _sigma) (GMorphism cid sigma1 mor)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder (G_symb_list (G_symb_items_list lid' sis'),pos) = do
4184cb191a9081cb2a9cf3ef5f060f56f0ca5922Till Mossakowski let lid1 = sourceLogic cid
4184cb191a9081cb2a9cf3ef5f060f56f0ca5922Till Mossakowski lid2 = targetLogic cid
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder adj = adjustPos pos
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder sis1 <- adj $ mcoerce lid1 lid' "Analysis of restriction" sis'
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder rsys <- adj $ stat_symb_items lid1 sis1
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let sys = sym_of lid1 sigma1
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let sys' = Set.filter (\sy -> any (\rsy -> matches lid1 sy rsy) rsys)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder-- if sys' `disjoint` () then return ()
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder-- else plain_error () "attempt to hide symbols from the local environment" pos
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder mor1 <- adj $ cogenerated_sign lid1 sys' sigma1
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder mor1' <- adj $ map_morphism cid mor1
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder mor2 <- adj $ comp lid2 mor1' mor
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder return $ GMorphism cid (dom lid1 mor1) mor2
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maederana_restr1 _dg _gSigma _mor
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder (G_logic_projection (Logic_code _tok _src _tar pos1),pos2) =
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder fatal_error "no analysis of logic projections yet" $ headPos $ pos1 ++ [pos2]
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maederana_restr :: DGraph -> G_sign -> Result GMorphism -> (G_hiding,Pos)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -> Result GMorphism
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maederana_restr dg gSigma mor_res restr =
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder do mor <- mor_res
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ana_restr1 dg gSigma mor restr
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_RESTRICTION :: DGraph -> G_sign -> G_sign -> HetcatsOpts -> RESTRICTION
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -> Result (GMorphism, Maybe GMorphism)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_RESTRICTION dg gSigma gSigma' opts restr =
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder ana_RESTRICTION' dg gSigma gSigma' (isStructured opts) restr
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_RESTRICTION' :: DGraph -> G_sign -> G_sign -> Bool -> RESTRICTION
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski -> Result (GMorphism, Maybe GMorphism)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_RESTRICTION' _ _ gSigma True _ =
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski return (ide Grothendieck gSigma,Nothing)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_RESTRICTION' dg gSigma gSigma' False (Hidden restr pos) =
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder do mor <- foldl (ana_restr dg gSigma)
788dd403da4203e895e15892ef7fa48129617d30Till Mossakowski (return (ide Grothendieck gSigma'))
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder return (mor,Nothing)
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski restr' = zip restr (tail (pos ++ repeat nullPos))
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski -- ??? Need to check that local env is not affected !
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_RESTRICTION' _ (G_sign lid sigma) (G_sign lid' sigma')
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski False (Revealed (G_symb_map_items_list lid1 sis) pos) =
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowski do let sys = sym_of lid sigma -- local env
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowski sys' = sym_of lid' sigma' -- "big" signature
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder adj = adjustPos $ headPos pos
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sis' <- adj $ mcoerce lid1 lid' "Analysis of restriction" sis
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder rmap <- adj $ stat_symb_map_items lid' sis'
0c2a90cbfb63865ff485c3fbe20a14589a5914beTill Mossakowski [sy | sy <- Set.toList sys', rsy <- Map.keys rmap, matches lid' sy rsy]
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowski -- domain of rmap intersected with sys'
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowski -- domain of rmap should be checked to match symbols from sys' ???
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sys1 <- adj $ mcoerce lid lid' "Analysis of restriction" sys
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- ??? this is too simple in case that local env is translated
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- to a different logic
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder mor1 <- adj $ generated_sign lid' (sys1 `Set.union` sys'') sigma'
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder mor2 <- adj $ induced_from_morphism lid' rmap (dom lid' mor1)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder return (gEmbed (G_morphism lid' mor1),
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Just (gEmbed (G_morphism lid' mor2)))
c0380b947eef252db81ee562246bb732555427f4Till Mossakowskiana_FIT_ARG :: LogicGraph -> GlobalContext -> SPEC_NAME -> NodeSig -> NodeSig
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski -> HetcatsOpts
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski -> Result (FIT_ARG, DGraph, (G_morphism,NodeSig))
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_FIT_ARG lg gctx spname nsigI nsigP opts
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder fs@(Fit_spec asp gsis poss) = do
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder let pos = getMyPos fs
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder adj = adjustPos pos
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nP <- maybeToResult pos
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: empty parameter spec" (getNode nsigP)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp',nsigA,dg') <- ana_SPEC lg gctx nsigI Nothing opts (item asp)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nA <- maybeToResult pos
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder "Internal error: empty argument spec" (getNode nsigA)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let gsigmaP = getSig nsigP
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigmaA = getSig nsigA
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder-- gsigmaI = getSig nsigI
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder G_sign lidP sigmaP <- return gsigmaP
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder G_sign lidA sigmaA <- return gsigmaA
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder-- G_sign lidI sigmaI <- return gsigmaI
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder G_symb_map_items_list lid sis <- return gsis
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sigmaA' <- adj $ mcoerce lidA lidP "Analysis of fitting argument" sigmaA
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder-- sigmaI' <- adj $ mcoerce lidI lidP "Analysis of fitting argument" sigmaI
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder mor <- adj $ if isStructured opts then return (ide lidP sigmaP)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder rmap <- stat_symb_map_items lid sis
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski rmap' <- if null sis then return Map.empty
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski else mcoerce lid lidP "Analysis of fitting argument" rmap
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder induced_from_to_morphism lidP rmap' sigmaP sigmaA'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let symI = sym_of lidP sigmaI'
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder symmap_mor = symmap_of lidP mor
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- are symbols of the imports left untouched?
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder if Set.all (\sy -> lookupFM symmap_mor sy == Just sy) symI
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder then return ()
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder else plain_error () "Fitting morphism must not affect import" (headPos pos)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -} -- ??? does not work
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- ??? also output some symbol that is affected
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let link = (nP,nA,DGLink {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_morphism = gEmbed (G_morphism lidP mor),
022f4e4f5488defedc48581e87f0222f82d5afe4Jorina Freya Gerken dgl_type = GlobalThm Open None Open,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_origin = DGSpecInst spname})
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder return (Fit_spec (replaceAnnoted sp' asp) gsis poss,
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link dg',
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder (G_morphism lidP mor,nsigA)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_FIT_ARG lg (gannos,genv,dg) spname nsigI nsigP opts
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder fv@(Fit_view vn afitargs poss ans) = do
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder let pos = headPos poss
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder adj = adjustPos pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski case Map.lookup vn genv of
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Nothing -> plain_error (fv,dg,error "no morphism")
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder ("View "++ showPretty vn " not found") pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Just (SpecEntry _) ->
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski plain_error (fv,dg,error "no fit view")
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder (showPretty spname " is a specification, not a view") pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Just (ArchEntry _) ->
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski plain_error (fv,dg,error "no fit view")
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (showPretty spname
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder " is an architectural specification, not a view ") pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Just (UnitEntry _) ->
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski plain_error (fv,dg,error "no fit view")
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (showPretty spname
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder " is a unit specification, not a view") pos
95656e84acc96386173c1d6fc068aa2fb8820020Till Mossakowski Just (RefEntry) ->
a06f7d58d7684e8a9a2fbfee22d365a52f822feeTill Mossakowski plain_error (fv,dg,error "no fit view")
95656e84acc96386173c1d6fc068aa2fb8820020Till Mossakowski (showPretty spname
95656e84acc96386173c1d6fc068aa2fb8820020Till Mossakowski " is a refinement specification, not a view") pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Just (ViewEntry (src,mor,gs@(imps,params,_,target))) -> do
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nSrc <- maybeToResult pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski "Internal error: empty source spec of view" (getNode src)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nTar <- maybeToResult pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski "Internal error: empty target spec of view" (getNode target)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nP <- maybeToResult pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski "Internal error: empty parameter specification" (getNode nsigP)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let gsigmaS = getSig src
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski gsigmaT = getSig target
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski gsigmaP = getSig nsigP
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski gsigmaI = getSig nsigI
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigmaIS <- adj $ gsigUnion lg gsigmaI gsigmaS
d08907a7832988612fbc0682b216e150d1e738d2Christian Maeder when (not (is_subgsign gsigmaP gsigmaIS))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (pplain_error ()
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (ptext "Parameter does not match source of fittig view."
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski $$ ptext "Parameter signature:"
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski $$ printText gsigmaP
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski $$ ptext "Source signature of fitting view (united with import):"
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder $$ printText gsigmaIS) pos)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski GMorphism cid _ morHom <- return mor
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let lid = targetLogic cid
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski when (not (language_name (sourceLogic cid) == language_name lid))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski "heterogeneous fitting views not yet implemented"
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski case (\x y -> (x,x-y)) (length afitargs) (length params) of
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- the case without parameters leads to a simpler dg
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski (0,0) -> case getNode nsigI of
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- the subcase with empty import leads to a simpler dg
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Nothing -> do
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let link = (nP,nSrc,DGLink {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_morphism = ide Grothendieck gsigmaP,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalThm Open None Open,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_origin = DGFitView spname})
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski return (fv,insEdgeNub link dg,(G_morphism lid morHom,target))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- the subcase with nonempty import
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Just nI -> do
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski G_sign lidI sigI1 <- return gsigmaI
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sigI <- adj $ mcoerce lidI lid "Analysis of instantiation with import" sigI1
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski mor_I <- adj $ morphism_union lid morHom $ ide lid sigI
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigmaA <- adj $ gsigUnion lg gsigmaI gsigmaT
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski G_sign lidA _ <- return gsigmaA
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski G_sign lidP _ <- return gsigmaP
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl1 <- adj $ ginclusion lg gsigmaI gsigmaA
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl2 <- adj $ ginclusion lg gsigmaT gsigmaA
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl3 <- adj $ ginclusion lg gsigmaI gsigmaP
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl4 <- adj $ ginclusion lg gsigmaS gsigmaP
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let [nA,n'] = newNodes 1 dg
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski node_contentsA = DGNode {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_name = Nothing,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigmaA,
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lidA [],
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_origin = DGFitViewA spname}
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski node_contents' = DGNode {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_name = Nothing,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigmaP,
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lidP [],
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_origin = DGFitView spname}
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski link = (nP,n',DGLink {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_morphism = ide Grothendieck gsigmaP,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalThm Open None Open,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_origin = DGFitView spname})
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski link1 = (nSrc,n',DGLink {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_morphism = incl4,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalDef,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitView spname})
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski link2 = (nTar,nA,DGLink {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_morphism = incl2,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalDef,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_origin = DGFitViewA spname})
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski link3 = (nI,n',DGLink {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_morphism = incl3,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalDef,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_origin = DGFitViewImp spname})
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski link4 = (nI,nA,DGLink {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_morphism = incl1,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalDef,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitViewAImp spname})
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link $
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link1 $
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link2 $
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link3 $
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski insEdgeNub link4 $
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski insNode (nA,node_contentsA) $
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski insNode (n',node_contents') dg,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (G_morphism lid mor_I,NodeSig (nA,gsigmaA)))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- now the case with parameters
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let fitargs = map item afitargs
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (fitargs',dg',args) <-
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski foldl anaFitArg (return ([],dg,[])) (zip params fitargs)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let actualargs = reverse args
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski (gsigmaA,mor_f) <- adj $ apply_GS lg gs actualargs
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski let gmor_f = gEmbed mor_f
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigmaRes <- adj $ gsigUnion lg gsigmaI gsigmaA
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski G_sign lidRes _ <- return gsigmaRes
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder mor1 <- adj $ comp Grothendieck mor gmor_f
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl1 <- adj $ ginclusion lg gsigmaA gsigmaRes
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder mor' <- adj $ comp Grothendieck gmor_f incl1
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski GMorphism cid1 _ mor1Hom <- return mor1
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski let lid1 = targetLogic cid1
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski when (not (language_name (sourceLogic cid1) == language_name lid1))
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski ("heterogeneous fitting views not yet implemented")
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski G_sign lidI sigI1 <- return gsigmaI
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sigI <- adj $ mcoerce lidI lid1 "Analysis of instantiation with parameters" sigI1
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski theta <- adj $ morphism_union lid1 mor1Hom (ide lid1 sigI)
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl2 <- adj $ ginclusion lg gsigmaI gsigmaRes
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl3 <- adj $ ginclusion lg gsigmaI gsigmaP
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl4 <- adj $ ginclusion lg gsigmaS gsigmaP
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski G_sign lidP _ <- return gsigmaP
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski let [nA,n'] = newNodes 1 dg'
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski node_contentsA = DGNode {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgn_name = Nothing,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgn_sign = gsigmaRes,
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lidRes [],
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgn_origin = DGFitViewA spname}
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski node_contents' = DGNode {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgn_name = Nothing,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgn_sign = gsigmaP,
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lidP [],
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgn_origin = DGFitView spname}
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski link = (nP,n',DGLink {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_morphism = ide Grothendieck gsigmaP,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_type = GlobalThm Open None Open,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitView spname})
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski link1 = (nSrc,n',DGLink {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_morphism = incl4,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalDef,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitView spname})
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski link2 = (nTar,nA,DGLink {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_morphism = mor',
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalDef,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitViewA spname})
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski fitLinks = [link,link1,link2] ++ case getNode nsigI of
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski Nothing -> []
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski Just nI -> let
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski link3 = (nI,n',DGLink {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_morphism = incl3,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_type = GlobalDef,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitViewImp spname})
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski link4 = (nI,nA,DGLink {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_morphism = incl2,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_type = GlobalDef,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitViewAImp spname})
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski in [link3,link4]
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski parLinks = catMaybes (map (parLink gsigmaRes nA) actualargs)
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski return (Fit_view vn
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski (map (uncurry replaceAnnoted)
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski (zip (reverse fitargs') afitargs))
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski foldr insEdgeNub
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski (insNode (nA,node_contentsA) $
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski insNode (n',node_contents') dg')
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski (fitLinks++parLinks),
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski (G_morphism lid1 theta,NodeSig (nA,gsigmaRes)))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski anaFitArg res (nsig',fa) = do
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (fas',dg1,args) <- res
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (fa',dg',arg) <- ana_FIT_ARG lg (gannos,genv,dg1)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski spname imps nsig' opts fa
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski return (fa':fas',dg',arg:args)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder parLink gsigmaRes node (_mor_i,nsigA_i) = do
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski nA_i <- getNode nsigA_i
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski incl <- maybeResult $ ginclusion lg (getSig nsigA_i) gsigmaRes
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let link = DGLink {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_morphism = incl,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgl_type = GlobalDef,
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski dgl_origin = DGFitView spname }
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski return (nA_i,node,link)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- finally the case with conflicting numbers of formal and actual parameters
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski plain_error (fv,dg,error "no fit view")
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (showPretty spname " expects "++show (length params)++" arguments"
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder ++" but was given "++show (length afitargs)) pos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski-- Extension of signature morphisms (for instantitations)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski-- first some auxiliary functions
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski{- not really needed:
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski-- for an Id, compute the list of components that are relevant for extension
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill MossakowskiidComponents :: Id -> Set.Set Id -> [Id]
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill MossakowskiidComponents (Id toks comps pos) ids =
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski foldl (\x y -> y++x) []
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski $ map (\id1 -> if id1 `Set.member` ids
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski else idComponents id1 ids)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill MossakowskicomponentRelation :: Set.Set Id -> Set.Set (Id,[Id])
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill MossakowskicomponentRelation ids =
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Set.image (\id -> (id,idComponents id ids)) ids
3476beb5baf84bef7cc7d627b130de9d48700399Christian MaedermapID :: Map.Map Id (Set.Set Id) -> Id -> Result Id
3476beb5baf84bef7cc7d627b130de9d48700399Christian MaedermapID idmap i@(Id toks comps pos1) =
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder case Map.lookup i idmap of
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Nothing -> do
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder compsnew <- sequence $ map (mapID idmap) comps
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski return (Id toks compsnew pos1)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Just ids -> case Set.size ids of
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder 0 -> return i
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski 1 -> return $ Set.findMin ids
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder _ -> pplain_error i
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder (ptext "Identifier component " <+> printText i
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski <+> ptext "can be mapped in various ways:"
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder <+> printText ids) nullPos
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -> Result (Map.EndoMap Id) -> Result (Map.EndoMap Id)
3476beb5baf84bef7cc7d627b130de9d48700399Christian MaederextID1 idmap i@(Id toks comps pos1) m = do
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder compsnew <- sequence $ map (mapID idmap) comps
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski if comps==compsnew
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski then return m1
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder else return (Map.insert i (Id toks compsnew pos1) m1)
3476beb5baf84bef7cc7d627b130de9d48700399Christian MaederextID :: Set.Set Id -> Map.Map Id (Set.Set Id) -> Result (Map.EndoMap Id)
3476beb5baf84bef7cc7d627b130de9d48700399Christian MaederextID ids idmap = Set.fold (extID1 idmap) (return Map.empty) ids
3476beb5baf84bef7cc7d627b130de9d48700399Christian MaederextendMorphism :: G_sign -- ^ formal parameter
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder -> G_sign -- ^ body
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder -> G_sign -- ^ actual parameter
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder -> G_morphism -- ^ fitting morphism
cf29cb0194d75de2182bfc73fa7da68e90a4a19eMaciek Makowski -> Result(G_sign,G_morphism)
3476beb5baf84bef7cc7d627b130de9d48700399Christian MaederextendMorphism (G_sign lid sigmaP) (G_sign lidB sigmaB1)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (G_sign lidA sigmaA1) (G_morphism lidM fittingMor1) = do
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- for now, only homogeneous instantiations....
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sigmaB <- mcoerce lidB lid "Extension of symbol map" sigmaB1
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski sigmaA <- mcoerce lidA lid "Extension of symbol map" sigmaA1
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski fittingMor <- mcoerce lidM lid "Extension of symbol map" fittingMor1
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let symsP = sym_of lid sigmaP
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski symsB = sym_of lid sigmaB
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski idsB = Set.image (sym_name lid) symsB
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski h = symmap_of lid fittingMor
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski symbMapToRawSymbMap =
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Map.foldWithKey (\sy1 sy2 -> Map.insert (symbol_to_raw lid sy1)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (symbol_to_raw lid sy2))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski rh = symbMapToRawSymbMap h
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (\sy1 sy2 -> Map.setInsert (sym_name lid sy1) (sym_name lid sy2))
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder idhExt <- extID idsB idh
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (\id1 id2 -> Map.insert (id_to_raw lid id1) (id_to_raw lid id2))
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder (foldr (\i -> Map.delete i) idhExt $ Map.keys idh)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski r = rh `Map.union` rIdExt
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski -- do we need combining function catching the clashes???
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski mor <- induced_from_morphism lid r sigmaB
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let hmor = symmap_of lid mor
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski sigmaAD = cod lid mor
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski sigma <- final_union lid sigmaA sigmaAD
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let illShared = (sym_of lid sigmaA `Set.intersection` sym_of lid sigmaAD )
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski when (not (Set.isEmpty illShared))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (pplain_error () (ptext
31c49f2fa23d4ac089f35145d80a224deb6ea7e4Till Mossakowski "Symbols shared between actual parameter and body must be in formal parameter"
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder $$ printText illShared ) nullPos)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski let newIdentifications = Map.kernel hmor Set.\\ Map.kernel h
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski Set.\\ Set.fromList (map (\x -> (x,x)) (Map.keys hmor))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski when (not (Set.isEmpty newIdentifications))
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski (pplain_error () (ptext
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski "Fitting morphism leads to forbidden identifications"
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder $$ printText newIdentifications) nullPos)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski incl <- inclusion lid sigmaAD sigma
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder mor1 <- comp lid mor incl
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski return (G_sign lid sigma, G_morphism lid mor1)
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowskiapply_GS :: LogicGraph -> ExtGenSig -> [(G_morphism,NodeSig)]
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski -> Result(G_sign,G_morphism)
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowskiapply_GS lg (nsigI,_params,gsigmaP,nsigB) args = do
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let mor_i = map fst args
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigmaA_i = map (getSig . snd) args
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigmaB = getSig nsigB
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder gsigmaI = getSig nsigI
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder G_sign lidI sigmaI <- return gsigmaI
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let idI = ide lidI sigmaI
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigmaA <- gsigManyUnion lg gsigmaA_i
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder mor_f <- homogeneousMorManyUnion (G_morphism lidI idI:mor_i)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder extendMorphism gsigmaP gsigmaB gsigmaA mor_f
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- | analyze a GENERICITY
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- Parameters: global context, current logic, just-structure-flag, GENERICITY
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_GENERICITY :: LogicGraph -> GlobalContext -> AnyLogic -> HetcatsOpts
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski -> GENERICITY
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski -> Result (GENERICITY,ExtGenSig,DGraph)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski-- zero parameters,
c0380b947eef252db81ee562246bb732555427f4Till Mossakowskiana_GENERICITY _ (_,_,dg) l@(Logic lid) _
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski gen@(Genericity (Params []) (Imported imps) pos) = do
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski when (not (null imps))
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (plain_error () "Parameterless specifications must not have imports"
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (headPos pos))
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (gen,(EmptyNode l,[],G_sign lid (empty_signature lid),EmptyNode l),dg)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski-- one parameter ...
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_GENERICITY lg gctx@(gannos,genv,_) l opts
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (Genericity (Params [asp]) imps pos) = do
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (imps',nsigI,dg') <- ana_IMPORTS lg gctx l opts imps
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp',nsigP,dg'') <- ana_SPEC lg (gannos,genv,dg') nsigI Nothing opts (item asp)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Genericity (Params [replaceAnnoted sp' asp]) imps' pos,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (nsigI,[nsigP],getSig nsigP,nsigP),
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski-- ... and more parameters
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_GENERICITY lg gctx@(gannos,genv,_) l opts
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (Genericity params imps pos) = do
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder let adj = adjustPos $ headPos pos
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (imps',nsigI,dg') <- ana_IMPORTS lg gctx l opts imps
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (params',nsigPs,dg'') <-
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski ana_PARAMS lg (gannos,genv,dg') l nsigI opts params
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski gsigmaP <- adj $ gsigManyUnion lg (map getSig nsigPs)
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski G_sign lidP _ <- return gsigmaP
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder let node_contents = DGNode {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_name = Nothing,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski dgn_sign = gsigmaP, -- G_sign lidP (empty_signature lidP),
242691238a8d1a89581751d782af87ec5d7470c0Till Mossakowski dgn_sens = G_l_sentence_list lidP [],
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgn_origin = DGFormalParams }
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder [node] = newNodes 0 dg''
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dg''' = insNode (node,node_contents) dg''
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski inslink dgres nsig = do
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder case getNode nsig of
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski Nothing -> return dg
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder incl <- adj $ ginclusion lg (getSig nsig) gsigmaP
f534c0116096e25659ceaa57de030c497ce9345aTill Mossakowski return (insEdgeNub (n,node,DGLink {
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_morphism = incl,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder dgl_type = GlobalDef,
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dgl_origin = DGFormalParams }) dg)
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski dg4 <- foldl inslink (return dg''') nsigPs
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Genericity params' imps' pos,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (nsigI,nsigPs,gsigmaP,NodeSig(node,gsigmaP)),
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_PARAMS :: LogicGraph -> GlobalContext -> AnyLogic -> NodeSig -> HetcatsOpts
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski -> Result (PARAMS,[NodeSig],DGraph)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_PARAMS lg (gannos,genv,dg) _ nsigI opts (Params asps) = do
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (sps',pars,dg') <- foldl ana (return ([],[],dg)) (map item asps)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Params (map (uncurry replaceAnnoted)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (zip (reverse sps') asps)),
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski reverse pars,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ana res sp = do
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski (sps',pars,dg1) <- res
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski (sp',par,dg') <- ana_SPEC lg (gannos,genv,dg1) nsigI Nothing opts sp
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (sp':sps',par:pars,dg')
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_IMPORTS :: LogicGraph -> GlobalContext -> AnyLogic -> HetcatsOpts -> IMPORTED
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski -> Result (IMPORTED,NodeSig,DGraph)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_IMPORTS lg gctx l opts (Imported asps) = do
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski let sp = Union asps (map (const nullPos) asps)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (Union asps' _,nsig',dg') <-
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski ana_SPEC lg gctx (EmptyNode l) Nothing opts sp
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (Imported asps',nsig',dg')
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder -- ??? emptyExplicit stuff needs to be added here
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- | analyze a VIEW_TYPE
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- The first three arguments give the global context
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- The AnyLogic is the current logic
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- The NodeSig is the signature of the parameter of the view
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- flag, whether just the structure shall be analysed
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_VIEW_TYPE:: LogicGraph -> GlobalContext -> AnyLogic -> NodeSig -> HetcatsOpts
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski -> Result (VIEW_TYPE,(NodeSig,NodeSig),DGraph)
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowskiana_VIEW_TYPE lg gctx@(gannos,genv,_) l parSig opts
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder (View_type aspSrc aspTar pos) = do
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (spSrc',srcNsig,dg') <-
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski ana_SPEC lg gctx (EmptyNode l) Nothing opts (item aspSrc)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (spTar',tarNsig,dg'') <-
6a57a555c8ef0a79aa5d20e1d721400dbffa564aMaciek Makowski ana_SPEC lg (gannos,genv,dg') parSig Nothing opts (item aspTar)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski return (View_type (replaceAnnoted spSrc' aspSrc)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (replaceAnnoted spTar' aspTar)
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski (srcNsig,tarNsig),
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder-- | check if structured analysis should be performed
7297175957c5ad3c0498032190b1dee9ec5fb873Christian MaederisStructured :: HetcatsOpts -> Bool
7297175957c5ad3c0498032190b1dee9ec5fb873Christian MaederisStructured a = case analysis a of Structured -> True
1b05bdb88b90d3c947351f262d7ae7d68f0a4a6fTill Mossakowski-- | Auxiliary function for not yet implemented features
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maederana_err :: String -> a
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maederana_err fname =
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder error ("*** Analysis of " ++ fname ++ " is not yet implemented!")