93cd42c036c9ef3fed58d4872bab5d72371d80d1Jonathan von Schroeder Nat,0,1,2,3,4,5,6,7,8,9,__@@__,__>=__,__<=__
dg' = insNode (node,node_contents) dg
dgl_origin = DGExtension }
NodeSig (n,_) -> insEdgeNub (n,node,link) dg'
return (Basic_spec (G_basic_spec lid bspec'),
NodeSig (node,G_sign lid sigma_complete),
(sp1',nsig',dg') <- ana_SPEC lg gctx nsig (inc name) opts sp1
"Internal error: Translation of empty spec" (getNode nsig')
let gsigma = getSig nsig'
mor <- ana_RENAMING lg gsigma opts ren
-- ??? check that mor is identity on local env
let gsigma' = cod Grothendieck mor
-- ??? too simplistic for non-comorphism inter-logic translations
G_sign lid' gsig <- return gsigma'
let node_contents = DGNode {
dgn_theory = G_theory lid' gsig [],
dgn_origin = DGTranslation }
dgl_origin = DGTranslation })
return (Translation (replaceAnnoted sp1' asp) ren,
insNode (node,node_contents) dg')
(sp1',nsig',dg') <- ana_SPEC lg gctx nsig (inc name) opts sp1
"Internal error: Reduction of empty spec" (getNode nsig')
(hmor,tmor) <- ana_RESTRICTION dg gsigma gsigma' opts restr
-- we treat hiding and revealing differently
-- in order to keep the dg as simple as possible
do let gsigma'' = dom Grothendieck hmor
-- ??? too simplistic for non-comorphism inter-logic reductions
G_sign lid' gsig <- return gsigma''
let node_contents = DGNode {
dgn_theory = G_theory lid' gsig [],
return (Reduction (replaceAnnoted sp1' asp) restr,
insNode (node,node_contents) dg')
let gsigma1 = dom Grothendieck tmor'
gsigma'' = cod Grothendieck tmor'
-- ??? too simplistic for non-comorphism inter-logic reductions
G_sign lid1 gsig <- return gsigma1
G_sign lid'' gsig'' <- return gsigma''
-- the case with identity translation leads to a simpler dg
if tmor' == ide Grothendieck (dom Grothendieck tmor')
let node1 = getNewNode dg'
node_contents1 = DGNode {
dgn_theory = G_theory lid1 gsig [],
dgn_origin = DGRevealing }
link1 = (n',node1,DGLink {
dgl_origin = DGRevealing })
return (Reduction (replaceAnnoted sp1' asp) restr,
insNode (node1,node_contents1) dg')
let [node1,node''] = newNodes 2 dg'
node_contents1 = DGNode {
dgn_name = extName "T" name,
dgn_theory = G_theory lid1 gsig [],
dgn_origin = DGRevealing }
link1 = (n',node1,DGLink {
dgl_origin = DGRevealing })
node_contents'' = DGNode {
dgn_theory = G_theory lid'' gsig'' [],
dgn_origin = DGRevealTranslation }
link'' = (node1,node'',DGLink {
dgl_origin = DGRevealTranslation })
return (Reduction (replaceAnnoted sp1' asp) restr,
NodeSig(node'',gsigma''),
insNode (node'',node_contents'') $
insNode (node1,node_contents1) dg')
Union [] _ -> return (sp,nsig,dg)
do let sps = map item asps
(sp1,nsig',dg1) <- ana_SPEC lg (gannos,genv,dg')
return (sp1:sps1,nsig':nsigs,dg1,inc n)
in foldl ana (return ([],[],dg,extName "U" name)) sps
let nsigs' = reverse nsigs
gbigSigma <- adj $ gsigManyUnion lg (map getSig nsigs')
G_sign lid' gsig <- return gbigSigma
let node_contents = DGNode {
dgn_theory = G_theory lid' gsig [],
insE dgres (n,gsigma) = do
incl <- adj $ ginclusion lg gsigma gbigSigma
return (insEdgeNub (n,node,link) dg1)
dg'' <- foldl insE (return (insNode (node,node_contents) dg'))
(catMaybes (map getNodeAndSig nsigs'))
return (Union (map (uncurry replaceAnnoted)
(zip (reverse sps') asps))
--Extension [] pos -> return (sp,nsig,dg)
(sps',nsig1,dg1) <- foldl ana (return ([],nsig,dg)) namedSps
return (Extension (map (uncurry replaceAnnoted)
(zip (reverse sps') asps))
namedSps = zip (reverse (name: tail (take (length asps)
(iterate inc (extName "E" name)))))
ana res (name',asp') = do
ana_SPEC lg (gannos,genv,dg') nsig' name' opts (item asp')
-- insert theorem link for semantic annotations
-- take the first semantic annotation
let anno = find isSemanticAnno $ l_annos asp'
-- is the extension going between real nodes?
dg2 <- case (anno,getNode nsig',getNode nsig1) of
(Just anno0@(Semantic_anno anno1 _),Just n',Just n1) -> do
-- any other semantic annotation? that's an error
when (any (\an -> isSemanticAnno an && an/=anno0) $ l_annos asp')
(pplain_error () (ptext "Conflicting semantic annotations")
-- %implied should not occur here
(pplain_error () (ptext "Annotation %implied should come after a BASIC-ITEM")
if anno1==SA_implies then do
when (not (is_subgsign sig1 sig')) (pplain_error ()
(ptext "Signature must not be extended in presence of %implies")
-- insert a theorem link according to p. 319 of the CASL Reference Manual
return $ insEdgeNub (n1,n',DGLink {
dgl_morphism = ide Grothendieck sig1,
dgl_type = GlobalThm Open None Open,
dgl_origin = DGExtension }) dg1
let anno2 = case anno1 of
-- insert a theorem link according to p. 319 of the CASL Reference Manual
-- the theorem link is trivally proved by the parallel definition link,
-- but for clarity, we leave it open here
-- the interesting open proof obligation is anno2, of course
incl <- ginclusion lg sig' sig1
return $ insEdgeNub (n',n1,DGLink {
dgl_type = GlobalThm Open anno2 Open,
dgl_origin = DGExtension }) dg1
return (sp1':sps',nsig1,dg2)
(sp',nsig',dg') <- ana_SPEC lg gctx nsig (inc name) opts sp1
"Internal error: Free spec over empty spec" (getNode nsig')
let gsigma' = getSig nsig'
G_sign lid' gsig <- return gsigma'
incl <- adjustPos pos $ ginclusion lg (getSig nsig) gsigma'
let node_contents = DGNode {
dgn_theory = G_theory lid' gsig [], -- delta is empty
return (Free_spec (replaceAnnoted sp' asp) poss,
insNode (node,node_contents) dg')
(sp',nsig',dg') <- ana_SPEC lg gctx nsig (inc name) opts sp1
"Internal error: Cofree spec over empty spec" (getNode nsig')
let gsigma' = getSig nsig'
G_sign lid' gsig <- return gsigma'
incl <- adjustPos pos $ ginclusion lg (getSig nsig) gsigma'
let node_contents = DGNode {
dgn_theory = G_theory lid' gsig [], -- delta is empty
dgl_type = CofreeDef nsig,
return (Cofree_spec (replaceAnnoted sp' asp) poss,
insNode (node,node_contents) dg')
Local_spec asp asp' poss ->
(sp2,nsig',dg') <- ana_SPEC lg gctx nsig (extName "L" name) opts sp1
(sp2',nsig'',dg'') <- ana_SPEC lg (gannos,genv,dg') nsig' (inc name) opts sp1'
"Internal error: Local spec over empty spec" (getNode nsig'')
G_sign lid sigma <- return gsigma
G_sign lid' sigma' <- return gsigma'
G_sign lid'' sigma'' <- return gsigma''
sigma1 <- mcoerce lid' lid "Analysis of local spec" sigma'
sigma2 <- mcoerce lid'' lid "Analysis of local spec" sigma''
let sys = sym_of lid sigma
mor3 <- if isStructured opts then return (ide lid sigma2)
else adjustPos pos $ cogenerated_sign lid
let sigma3 = dom lid mor3
-- gsigma2 = G_sign lid sigma2
gsigma3 = G_sign lid sigma3
when (not( isStructured opts ||
"attempt to hide the following symbols from the local environment"
let node_contents = DGNode {
dgn_theory = G_theory lid sigma3 [],
link = (n'',node,DGLink {
dgl_morphism = gEmbed (G_morphism lid mor3),
return (Local_spec (replaceAnnoted sp2 asp)
(replaceAnnoted sp2' asp')
insNode (node,node_contents) dg'')
-- analyse spec with empty local env
(sp',nsig',dg') <- ana_SPEC lg gctx (EmptyNode l) (inc name) opts sp1
"Internal error: Closed spec over empty spec" (getNode nsig')
-- construct union with local env
gsigma'' <- adj $ gsigUnion lg gsigma gsigma'
G_sign lid'' gsig'' <- return gsigma''
incl1 <- adj $ ginclusion lg gsigma gsigma''
incl2 <- adj $ ginclusion lg gsigma' gsigma''
let node = getNewNode dg'
dgn_theory = G_theory lid'' gsig'' [],
dgl_origin = DGClosedLenv }
link2 = (n',node,DGLink {
insLink1 = case (getNode nsig) of
Just n -> insEdgeNub (n,node,link1)
return (Closed_spec (replaceAnnoted sp' asp) pos,
insNode (node,node_contents) dg')
Qualified_spec (Logic_name ln sublog) asp pos -> do
l <- lookupLogic "Static analysis: " (tokStr ln) lg
-- analyse spec with empty local env
(sp',nsig',dg') <- ana_SPEC lg gctx (EmptyNode l)
(inc name) opts (item asp)
"Internal error: Qualified spec over empty spec" (getNode nsig')
-- construct union with local env
gsigma'' <- adj $ gsigUnion lg gsigma gsigma'
G_sign lid'' gsig'' <- return gsigma''
incl1 <- adj $ ginclusion lg gsigma gsigma''
incl2 <- adj $ ginclusion lg gsigma' gsigma''
let node = getNewNode dg'
dgn_theory = G_theory lid'' gsig'' [],
dgn_origin = DGLogicQual }
dgl_origin = DGLogicQualLenv }
link2 = (n',node,DGLink {
dgl_origin = DGLogicQual })
insLink1 = case (getNode nsig) of
Just n -> insEdgeNub (n,node,link1)
return (Qualified_spec (Logic_name ln sublog) (replaceAnnoted sp' asp) pos,
insNode (node,node_contents) dg')
(sp',nsig',dg') <- ana_SPEC lg gctx nsig name opts (item asp)
return (Group (replaceAnnoted sp' asp) pos,nsig',dg')
Spec_inst spname afitargs pos -> do
("Specification "++ showPretty spname " not found") pos
(showPretty spname " is a view, not a specification") pos
" is an architectural, not a structured specification") pos
" is a unit specification, not a structured specification") pos
" is a refinement specification, not a structured specification") pos
Just (SpecEntry gs@(imps,params,_,body)) ->
case (\x y -> (x,x-y)) (length afitargs) (length params) of
-- the case without parameters leads to a simpler dg
let gsigmaB = getSig body
gsigma <- adj $ gsigUnion lg (getSig nsig) gsigmaB
G_sign lid gsig <- return gsigma
"Internal error: empty body spec" (getNode body)
-- the subcase with empty local env leads to an even simpler dg
-- if the node shall not be named and the logic does not change,
if isInternal name && langNameSig gsigma==langNameSig gsigmaB
-- then just return the body
-- otherwise, we need to create a new one
incl <- adj $ ginclusion lg gsigmaB gsigma
dgn_theory = G_theory lid gsig [],
dgn_origin = DGSpecInst spname}
dgl_origin = DGSpecInst spname})
insNode (node,node_contents) dg)
-- the subcase with nonempty local env
incl1 <- adj $ ginclusion lg (getSig nsig) gsigma
incl2 <- adj $ ginclusion lg gsigmaB gsigma
dgn_theory = G_theory lid gsig [],
dgn_origin = DGSpecInst spname}
dgl_origin = DGSpecInst spname})
link2 = (nB,node,DGLink {
dgl_origin = DGSpecInst spname})
insNode (node,node_contents) dg)
-- now the case with parameters
let fitargs = map item afitargs
foldl anaFitArg (return ([],dg,[],extName "A" name))
let actualargs = reverse args
(gsigma',morDelta) <- adj $ apply_GS lg gs actualargs
gsigmaRes <- adj $ gsigUnion lg (getSig nsig) gsigma'
G_sign lidRes gsigRes <- return gsigmaRes
"Internal error: empty body spec" (getNode body)
incl1 <- adj $ ginclusion lg (getSig nsig) gsigmaRes
incl2 <- adj $ ginclusion lg gsigma' gsigmaRes
morDelta' <- comp Grothendieck (gEmbed morDelta) incl2
let node = getNewNode dg'
dgn_theory = G_theory lidRes gsigRes [],
dgn_origin = DGSpecInst spname}
dgl_origin = DGSpecInst spname}
insLink1 = case (getNode nsig) of
Just n -> insEdgeNub (n,node,link1)
link2 = (nB,node,DGLink {
dgl_morphism = morDelta',
dgl_origin = DGSpecInst spname})
parLinks = catMaybes (map (parLink gsigmaRes node) actualargs)
(map (uncurry replaceAnnoted)
(zip (reverse fitargs') afitargs))
insNode (node,node_contents) dg')
anaFitArg res (nsig',fa) = do
(fas',dg1,args,name') <- res
(fa',dg',arg) <- ana_FIT_ARG lg (gannos,genv,dg1)
spname imps nsig' opts name' fa
return (fa':fas',dg',arg:args,inc name')
parLink gsigma' node (_mor_i,nsigA_i) = do
incl <- maybeResult $ ginclusion lg (getSig nsigA_i) gsigma'
-- finally the case with conflicting numbers of formal and actual parameters
(showPretty spname " expects "++show (length params)++" arguments"
++" but was given "++show (length afitargs)) pos
Data (Logic lidD) (Logic lidP) asp1 asp2 pos ->
Comorphism cid <- adj $ logicInclusion lg (Logic lidD) (Logic lidP)
let lidD' = sourceLogic cid
ana_SPEC lg gctx (EmptyNode (Logic lidD)) (inc name) opts sp1
"Internal error: Data spec over empty spec" (getNode nsig1)
let gsigma' = getSig nsig1
G_sign lid' sigma' <- return gsigma'
sigmaD <- adj $ mcoerce lid' lidD' "Analysis of data spec" sigma'
(sigmaD',sensD') <- adj $ map_sign cid sigmaD
let gsigmaD' = G_sign lidP' sigmaD'
dgn_theory = G_theory lidP' sigmaD' sensD',
dgl_morphism = GMorphism cid sigmaD (ide lidP' sigmaD'),
insNode (node,node_contents) dg1
nsig2 = NodeSig (node,gsigmaD')
ana_SPEC lg (gannos,genv,dg2) nsig2 name opts sp2
return (Data (Logic lidD) (Logic lidP)
(replaceAnnoted sp1' asp1)
(replaceAnnoted sp2' asp2)
ana_ren1 :: LogicGraph -> GMorphism -> G_mapping -> Result GMorphism
ana_ren1 _ (GMorphism r sigma mor)
(G_symb_map (G_symb_map_items_list lid sis)) = do
sis1 <- mcoerce lid2 lid "Analysis of renaming" sis
rmap <- stat_symb_map_items lid2 sis1
mor1 <- induced_from_morphism lid2 rmap (cod lid2 mor)
mor2 <- comp lid2 mor mor1
return $ GMorphism r sigma mor2
ana_ren1 lg mor (G_logic_translation (Logic_code tok src tar pos1)) = do
G_sign srcLid srcSig <- return (cod Grothendieck mor)
Comorphism cid <- lookupComorphism (tokStr ctok) lg
when (isJust src && getLogicStr (fromJust src) /=
language_name (sourceLogic cid))
(fail (getLogicStr (fromJust src)++"is not the source logic of "
when (isJust tar && getLogicStr (fromJust tar) /=
language_name (targetLogic cid))
(fail (getLogicStr (fromJust tar)++"is not the target logic of "
Just (Logic_name l _) -> do
tarL <- lookupLogic "with logic: " (tokStr l) lg
logicInclusion lg (Logic srcLid) tarL
Nothing -> fail "with logic: cannot determine comorphism"
mor1 <- adj $ gEmbedComorphism c (G_sign srcLid srcSig)
adj $ comp Grothendieck mor mor1
where getLogicStr (Logic_name l _) = tokStr l
ana_ren :: LogicGraph -> Result GMorphism -> G_mapping -> Result GMorphism
ana_RENAMING :: LogicGraph -> G_sign -> HetcatsOpts -> RENAMING
ana_RENAMING lg gSigma opts (Renaming ren _) =
then return (ide Grothendieck gSigma)
else foldl (ana_ren lg) (return (ide Grothendieck gSigma)) ren
-- analysis of restrictions
ana_restr1 :: DGraph -> G_sign -> GMorphism -> G_hiding -> Result GMorphism
ana_restr1 _ (G_sign _lid _sigma) (GMorphism cid sigma1 mor)
(G_symb_list (G_symb_items_list lid' sis')) = do
let lid1 = sourceLogic cid
sis1 <- mcoerce lid1 lid' "Analysis of restriction" sis'
rsys <- stat_symb_items lid1 sis1
let sys = sym_of lid1 sigma1
let sys' =
Set.filter (\sy -> any (\rsy -> matches lid1 sy rsy) rsys)
-- if sys' `disjoint` () then return ()
-- else plain_error () "attempt to hide symbols from the local environment" pos
mor1 <- cogenerated_sign lid1 sys' sigma1
mor1' <- map_morphism cid mor1
mor2 <- comp lid2 mor1' mor
return $ GMorphism cid (dom lid1 mor1) mor2
ana_restr1 _dg _gSigma _mor
(G_logic_projection (Logic_code _tok _src _tar pos1)) =
fatal_error "no analysis of logic projections yet" pos1
ana_restr :: DGraph -> G_sign -> Result GMorphism -> G_hiding
ana_restr dg gSigma mor_res restr =
ana_restr1 dg gSigma mor restr
ana_RESTRICTION :: DGraph -> G_sign -> G_sign -> HetcatsOpts -> RESTRICTION
-> Result (GMorphism, Maybe GMorphism)
ana_RESTRICTION dg gSigma gSigma' opts restr =
ana_RESTRICTION' dg gSigma gSigma' (isStructured opts) restr
ana_RESTRICTION' :: DGraph -> G_sign -> G_sign -> Bool -> RESTRICTION
-> Result (GMorphism, Maybe GMorphism)
ana_RESTRICTION' _ _ gSigma True _ =
return (ide Grothendieck gSigma,Nothing)
ana_RESTRICTION' dg gSigma gSigma' False (Hidden restr _) =
do mor <- foldl (ana_restr dg gSigma)
(return (ide Grothendieck gSigma'))
-- ??? Need to check that local env is not affected !
ana_RESTRICTION' _ (G_sign lid sigma) (G_sign lid' sigma')
False (Revealed (G_symb_map_items_list lid1 sis) pos) =
do let sys = sym_of lid sigma -- local env
sys' = sym_of lid' sigma' -- "big" signature
sis' <- adj $ mcoerce lid1 lid' "Analysis of restriction" sis
rmap <- adj $ stat_symb_map_items lid' sis'
-- domain of rmap intersected with sys'
-- domain of rmap should be checked to match symbols from sys' ???
sys1 <- adj $ mcoerce lid lid' "Analysis of restriction" sys
-- ??? this is too simple in case that local env is translated
mor1 <- adj $ generated_sign lid' (sys1 `
Set.union` sys'') sigma'
mor2 <- adj $ induced_from_morphism lid' rmap (dom lid' mor1)
return (gEmbed (G_morphism lid' mor1),
Just (gEmbed (G_morphism lid' mor2)))
ana_FIT_ARG :: LogicGraph -> GlobalContext -> SPEC_NAME -> NodeSig -> NodeSig
-> Result (FIT_ARG, DGraph, (G_morphism,NodeSig))
ana_FIT_ARG lg gctx spname nsigI nsigP opts name
(Fit_spec asp gsis pos) = do
"Internal error: empty parameter spec" (getNode nsigP)
(sp',nsigA,dg') <- ana_SPEC lg gctx nsigI name opts (item asp)
"Internal error: empty argument spec" (getNode nsigA)
let gsigmaP = getSig nsigP
-- gsigmaI = getSig nsigI
G_sign lidP sigmaP <- return gsigmaP
G_sign lidA sigmaA <- return gsigmaA
-- G_sign lidI sigmaI <- return gsigmaI
G_symb_map_items_list lid sis <- homogenizeGM (Logic lidP) gsis
sigmaA' <- adj $ mcoerce lidA lidP "Analysis of fitting argument" sigmaA
-- sigmaI' <- adj $ mcoerce lidI lidP "Analysis of fitting argument" sigmaI
mor <- adj $ if isStructured opts then return (ide lidP sigmaP)
rmap <- stat_symb_map_items lid sis
else mcoerce lid lidP "Analysis of fitting argument" rmap
induced_from_to_morphism lidP rmap' sigmaP sigmaA'
let symI = sym_of lidP sigmaI'
symmap_mor = symmap_of lidP mor
-- are symbols of the imports left untouched?
if
Set.all (\sy -> lookupFM symmap_mor sy == Just sy) symI
else plain_error () "Fitting morphism must not affect import" ( pos)
-- ??? also output some symbol that is affected
let link = (nP,nA,DGLink {
dgl_morphism = gEmbed (G_morphism lidP mor),
dgl_type = GlobalThm Open None Open,
dgl_origin = DGSpecInst spname})
return (Fit_spec (replaceAnnoted sp' asp) gsis pos,
(G_morphism lidP mor,nsigA)
ana_FIT_ARG lg (gannos,genv,dg) spname nsigI nsigP opts name
fv@(Fit_view vn afitargs pos) = do
("View "++ showPretty vn " not found") pos
(showPretty spname " is a specification, not a view") pos
" is an architectural specification, not a view ") pos
" is a unit specification, not a view") pos
" is a refinement specification, not a view") pos
Just (ViewEntry (src,mor,gs@(imps,params,_,target))) -> do
nSrc <- maybeToResult pos
"Internal error: empty source spec of view" (getNode src)
nTar <- maybeToResult pos
"Internal error: empty target spec of view" (getNode target)
"Internal error: empty parameter specification" (getNode nsigP)
gsigmaIS <- adj $ gsigUnion lg gsigmaI gsigmaS
when (not (is_subgsign gsigmaP gsigmaIS))
(ptext "Parameter does not match source of fittig view."
$$ ptext "Parameter signature:"
$$ ptext "Source signature of fitting view (united with import):"
$$ printText gsigmaIS) pos)
GMorphism cid _ morHom <- return mor
let lid = targetLogic cid
when (not (language_name (sourceLogic cid) == language_name lid))
"heterogeneous fitting views not yet implemented"
case (\x y -> (x,x-y)) (length afitargs) (length params) of
-- the case without parameters leads to a simpler dg
(0,0) -> case getNode nsigI of
-- the subcase with empty import leads to a simpler dg
let link = (nP,nSrc,DGLink {
dgl_morphism = ide Grothendieck gsigmaP,
dgl_type = GlobalThm Open None Open,
dgl_origin = DGFitView spname})
return (fv,insEdgeNub link dg,(G_morphism lid morHom,target))
-- the subcase with nonempty import
G_sign lidI sigI1 <- return gsigmaI
sigI <- adj $ mcoerce lidI lid "Analysis of instantiation with import" sigI1
mor_I <- adj $ morphism_union lid morHom $ ide lid sigI
gsigmaA <- adj $ gsigUnion lg gsigmaI gsigmaT
G_sign lidA gsigA <- return gsigmaA
G_sign lidP gsigP <- return gsigmaP
incl1 <- adj $ ginclusion lg gsigmaI gsigmaA
incl2 <- adj $ ginclusion lg gsigmaT gsigmaA
incl3 <- adj $ ginclusion lg gsigmaI gsigmaP
incl4 <- adj $ ginclusion lg gsigmaS gsigmaP
let [nA,n'] = newNodes 2 dg
node_contentsA = DGNode {
dgn_theory = G_theory lidA gsigA [],
dgn_origin = DGFitViewA spname}
node_contents' = DGNode {
dgn_theory = G_theory lidP gsigP [],
dgn_origin = DGFitView spname}
dgl_morphism = ide Grothendieck gsigmaP,
dgl_type = GlobalThm Open None Open,
dgl_origin = DGFitView spname})
link1 = (nSrc,n',DGLink {
dgl_origin = DGFitView spname})
link2 = (nTar,nA,DGLink {
dgl_origin = DGFitViewA spname})
dgl_origin = DGFitViewImp spname})
dgl_origin = DGFitViewAImp spname})
insNode (nA,node_contentsA) $
insNode (n',node_contents') dg,
(G_morphism lid mor_I,NodeSig (nA,gsigmaA)))
-- now the case with parameters
let fitargs = map item afitargs
foldl anaFitArg (return ([],dg,[],extName "A" name))
let actualargs = reverse args
(gsigmaA,mor_f) <- adj $ apply_GS lg gs actualargs
let gmor_f = gEmbed mor_f
gsigmaRes <- adj $ gsigUnion lg gsigmaI gsigmaA
G_sign lidRes gsigRes <- return gsigmaRes
mor1 <- adj $ comp Grothendieck mor gmor_f
incl1 <- adj $ ginclusion lg gsigmaA gsigmaRes
mor' <- adj $ comp Grothendieck gmor_f incl1
GMorphism cid1 _ mor1Hom <- return mor1
let lid1 = targetLogic cid1
when (not (language_name (sourceLogic cid1) == language_name lid1))
("heterogeneous fitting views not yet implemented")
G_sign lidI sigI1 <- return gsigmaI
sigI <- adj $ mcoerce lidI lid1 "Analysis of instantiation with parameters" sigI1
theta <- adj $ morphism_union lid1 mor1Hom (ide lid1 sigI)
incl2 <- adj $ ginclusion lg gsigmaI gsigmaRes
incl3 <- adj $ ginclusion lg gsigmaI gsigmaP
incl4 <- adj $ ginclusion lg gsigmaS gsigmaP
G_sign lidP gsigP <- return gsigmaP
let [nA,n'] = newNodes 2 dg'
node_contentsA = DGNode {
dgn_theory = G_theory lidRes gsigRes [],
dgn_origin = DGFitViewA spname}
node_contents' = DGNode {
dgn_name = extName "V" name,
dgn_theory = G_theory lidP gsigP [],
dgn_origin = DGFitView spname}
dgl_morphism = ide Grothendieck gsigmaP,
dgl_type = GlobalThm Open None Open,
dgl_origin = DGFitView spname})
link1 = (nSrc,n',DGLink {
dgl_origin = DGFitView spname})
link2 = (nTar,nA,DGLink {
dgl_origin = DGFitViewA spname})
fitLinks = [link,link1,link2] ++ case getNode nsigI of
dgl_origin = DGFitViewImp spname})
dgl_origin = DGFitViewAImp spname})
parLinks = catMaybes (map (parLink gsigmaRes nA) actualargs)
(map (uncurry replaceAnnoted)
(zip (reverse fitargs') afitargs))
(insNode (nA,node_contentsA) $
insNode (n',node_contents') dg')
(G_morphism lid1 theta,NodeSig (nA,gsigmaRes)))
anaFitArg res (nsig',fa) = do
(fas',dg1,args,name') <- res
(fa',dg',arg) <- ana_FIT_ARG lg (gannos,genv,dg1)
spname imps nsig' opts name' fa
return (fa':fas',dg',arg:args,inc name')
parLink gsigmaRes node (_mor_i,nsigA_i) = do
incl <- maybeResult $ ginclusion lg (getSig nsigA_i) gsigmaRes
dgl_origin = DGFitView spname }
-- finally the case with conflicting numbers of formal and actual parameters
(showPretty spname " expects "++show (length params)++" arguments"
++" but was given "++show (length afitargs)) pos
-- Extension of signature morphisms (for instantitations)
-- first some auxiliary functions
-- for an Id, compute the list of components that are relevant for extension
idComponents :: Id ->
Set.Set Id -> [Id]
idComponents (Id toks comps pos) ids =
else idComponents id1 ids)
Set.map (\id -> (id,idComponents id ids)) ids
mapID idmap i@(Id toks comps pos1) =
compsnew <- sequence $ map (mapID idmap) comps
return (Id toks compsnew pos1)
(ptext "Identifier component " <+> printText i
<+> ptext "can be mapped in various ways:"
<+> printText ids) nullRange
-> Result (EndoMap Id) -> Result (EndoMap Id)
extID1 idmap i@(Id toks comps pos1) m = do
compsnew <- sequence $ map (mapID idmap) comps
else return (
Map.insert i (Id toks compsnew pos1) m1)
extendMorphism :: G_sign -- ^ formal parameter
-> G_sign -- ^ actual parameter
-> G_morphism -- ^ fitting morphism
-> Result(G_sign,G_morphism)
extendMorphism (G_sign lid sigmaP) (G_sign lidB sigmaB1)
(G_sign lidA sigmaA1) (G_morphism lidM fittingMor1) = do
-- for now, only homogeneous instantiations....
sigmaB <- mcoerce lidB lid "Extension of symbol map" sigmaB1
sigmaA <- mcoerce lidA lid "Extension of symbol map" sigmaA1
fittingMor <- mcoerce lidM lid "Extension of symbol map" fittingMor1
let symsP = sym_of lid sigmaP
symsB = sym_of lid sigmaB
idsB =
Set.map (sym_name lid) symsB
h = symmap_of lid fittingMor
rh = symbMapToRawSymbMap h
(\sy1 sy2 ->
Rel.setInsert (sym_name lid sy1) (sym_name lid sy2))
(\id1 id2 ->
Map.insert (id_to_raw lid id1) (id_to_raw lid id2))
-- do we need combining function catching the clashes???
mor <- induced_from_morphism lid r sigmaB
let hmor = symmap_of lid mor
sigma <- final_union lid sigmaA sigmaAD
"Symbols shared between actual parameter and body must be in formal parameter"
$$ printText illShared ) nullRange)
comb2 p qs [] ++ comb1 qs
comb2 p@(a, b) ((c, d) : qs) rs =
comb2 p qs $ if b == d then (a, c) : rs else rs
newIdentifications = myKernel hmor Set.\\ myKernel h
when (not (
Set.null newIdentifications))
"Fitting morphism leads to forbidden identifications"
$$ printText newIdentifications) nullRange)
incl <- inclusion lid sigmaAD sigma
mor1 <- comp lid mor incl
return (G_sign lid sigma, G_morphism lid mor1)
apply_GS :: LogicGraph -> ExtGenSig -> [(G_morphism,NodeSig)]
-> Result(G_sign,G_morphism)
apply_GS lg (nsigI,_params,gsigmaP,nsigB) args = do
gsigmaA_i = map (getSig . snd) args
G_sign lidI sigmaI <- return gsigmaI
let idI = ide lidI sigmaI
gsigmaA <- gsigManyUnion lg gsigmaA_i
mor_f <- homogeneousMorManyUnion (G_morphism lidI idI:mor_i)
extendMorphism gsigmaP gsigmaB gsigmaA mor_f
-- | analyze a GENERICITY
-- Parameters: global context, current logic, just-structure-flag, GENERICITY
ana_GENERICITY :: LogicGraph -> GlobalContext -> AnyLogic -> HetcatsOpts
-> NODE_NAME -> GENERICITY
-> Result (GENERICITY,ExtGenSig,DGraph)
ana_GENERICITY _ (_,_,dg) l@(Logic lid) _ _
gen@(Genericity (Params []) (Imported imps) pos) = do
(plain_error () "Parameterless specifications must not have imports"
return (gen,(EmptyNode l,[],G_sign lid (empty_signature lid),EmptyNode l),dg)
ana_GENERICITY lg gctx@(gannos,genv,_) l opts name
(Genericity (Params [asp]) imps pos) = do
(imps',nsigI,dg') <- ana_IMPORTS lg gctx l opts (extName "I" name) imps
(sp',nsigP,dg'') <- ana_SPEC lg (gannos,genv,dg') nsigI name opts (item asp)
return (Genericity (Params [replaceAnnoted sp' asp]) imps' pos,
(nsigI,[nsigP],getSig nsigP,nsigP),
-- ... and more parameters
ana_GENERICITY lg gctx@(gannos,genv,_) l opts name
(Genericity params imps pos) = do
(imps',nsigI,dg') <- ana_IMPORTS lg gctx l opts (extName "I" name) imps
ana_PARAMS lg (gannos,genv,dg') l nsigI opts (inc name) params
gsigmaP <- adj $ gsigManyUnion lg (map getSig nsigPs)
G_sign lidP gsigP <- return gsigmaP
let node_contents = DGNode {
dgn_theory = G_theory lidP gsigP [],
dgn_origin = DGFormalParams }
dg''' = insNode (node,node_contents) dg''
incl <- adj $ ginclusion lg (getSig nsig) gsigmaP
return (insEdgeNub (n,node,DGLink {
dgl_origin = DGFormalParams }) dg)
dg4 <- foldl inslink (return dg''') nsigPs
return (Genericity params' imps' pos,
(nsigI,nsigPs,gsigmaP,NodeSig(node,gsigmaP)),
ana_PARAMS :: LogicGraph -> GlobalContext -> AnyLogic -> NodeSig -> HetcatsOpts
-> Result (PARAMS,[NodeSig],DGraph)
ana_PARAMS lg (gannos,genv,dg) _ nsigI opts name (Params asps) = do
(sps',pars,dg',_) <- foldl ana (return ([],[],dg,name)) (map item asps)
return (Params (map (uncurry replaceAnnoted)
(zip (reverse sps') asps)),
(sp',par,dg') <- ana_SPEC lg (gannos,genv,dg1) nsigI n opts sp
return (sp':sps',par:pars,dg',inc n)
ana_IMPORTS :: LogicGraph -> GlobalContext -> AnyLogic -> HetcatsOpts
-> Result (IMPORTED,NodeSig,DGraph)
ana_IMPORTS lg gctx l opts name (Imported asps) = do
let sp = Union asps nullRange
(Union asps' _,nsig',dg') <-
ana_SPEC lg gctx (EmptyNode l) name opts sp
return (Imported asps',nsig',dg')
-- ??? emptyExplicit stuff needs to be added here
-- The first three arguments give the global context
-- The AnyLogic is the current logic
-- The NodeSig is the signature of the parameter of the view
-- flag, whether just the structure shall be analysed
ana_VIEW_TYPE:: LogicGraph -> GlobalContext -> AnyLogic -> NodeSig -> HetcatsOpts
-> NODE_NAME -> VIEW_TYPE
-> Result (VIEW_TYPE,(NodeSig,NodeSig),DGraph)
ana_VIEW_TYPE lg gctx@(gannos,genv,_) l parSig opts name
(View_type aspSrc aspTar pos) = do
ana_SPEC lg gctx (EmptyNode l) (extName "S" name) opts (item aspSrc)
ana_SPEC lg (gannos,genv,dg') parSig (extName "T" name) opts (item aspTar)
return (View_type (replaceAnnoted spSrc' aspSrc)
(replaceAnnoted spTar' aspTar)
homogenizeGM (Logic lid) gsis =
foldl homogenize1 (return (G_symb_map_items_list lid [])) gsis
(G_symb_map_items_list lid2 sis) <- res
sis1' <- rcoerce lid1 lid2 nullRange sis1
return (G_symb_map_items_list lid2 (sis++sis1'))
-- | check if structured analysis should be performed
isStructured :: HetcatsOpts -> Bool
isStructured a = case analysis a of Structured -> True
-- | Auxiliary function for not yet implemented features
error ("*** Analysis of " ++ fname ++ " is not yet implemented!")