Maude2DG.hs revision 3a37d6d85722c0630b2f7f9e3f5020717cb4edf7
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maederimport qualified Maude.Meta.HasName as HasName
ca010363454de207082dfaa4b753531ce2a34551Christian Maederimport qualified Data.Map as Map
ca010363454de207082dfaa4b753531ce2a34551Christian Maederimport qualified Data.Set as Set
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder-- Borrar despues de las pruebas
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maedermaude_cmd :: String
53301de22afd7190981b363b57c48df86fcb50f7Christian Maedermaude_cmd = "/Applications/maude-darwin/maude.intelDarwin -interactive -no-banner"
975642b989852fc24119c59cf40bc1af653608ffChristian Maederdata ImportType = Pr | Ex | Inc
53301de22afd7190981b363b57c48df86fcb50f7Christian Maedertype ModExpProc = (Token, TokenInfoMap, Morphism, [ParamSort], DGraph)
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maedertype ImportProc = (ImportType, Token, TokenInfoMap, Morphism, [ParamSort], DGraph)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maedertype TokenInfoMap = Map.Map Token ProcInfo
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maedertype ProcInfo = (Node, Sign, [Token], [(Token, Token, [Token])], [ParamSort])
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maedertype ParamInfo = ([(Token, Token, [Token])], TokenInfoMap, [Morphism], DGraph)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder-- | Map from view identifiers to tuples containing the target node of the
fc8c6570c7b4ee13f375eb607bed2290438573bfChristian Maeder-- view, the morphism, and a Boolean value indicating if the view instantiates
83cc27e4ca7cf1a4bb5f4a8df17d3e6d44e6f1eaChristian Maeder-- all the values
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maedertype ViewMap = Map.Map Token (Node, Morphism, [Renaming], Bool)
53301de22afd7190981b363b57c48df86fcb50f7Christian Maedertype InsSpecRes = (TokenInfoMap, ViewMap, [Token], DGraph)
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder-- | Pair of tokens and parameters contained by the token
53301de22afd7190981b363b57c48df86fcb50f7Christian Maedertype ParamSort = (Token, [Token])
da2b959c50c95309d8eb8b24174249c2847e74b5Christian MaederinsertSpecs :: [Spec] -> TokenInfoMap -> ViewMap -> [Token] -> DGraph -> DGraph
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederinsertSpecs [] _ _ _ dg = dg
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederinsertSpecs (s : ss) tim vm ths dg = insertSpecs ss tim' vm' ths' dg'
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder where (tim', vm', ths', dg') = insertSpec s tim vm ths dg
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederinsertSpec :: Spec -> TokenInfoMap -> ViewMap -> [Token] -> DGraph -> InsSpecRes
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederinsertSpec (SpecMod sp_mod) tim vm ths dg = (tim4, vm, ths, dg5)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder where ps = getParams sp_mod
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder (pl, tim1, morphs, dg1) = processParameters ps tim dg
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder paramSorts = getSortsParameterizedBy (paramNames ps) (Set.toList $ sorts top_sg)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder (il, _) = getImportsSorts sp_mod
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder ips = processImports tim1 vm dg1 il
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder (tim2, dg2) = last_da ips (tim1, dg1)
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder sg = sign_union_morphs morphs $ sign_union top_sg ips
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder ext_sg = makeExtSign Maude sg
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder nm_sns = map (makeNamed "") $ Maude.Sentence.fromSpec sp_mod
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder sens = toThSens nm_sns
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder gt = G_theory Maude ext_sg startSigId sens startThId
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder name = makeName tok
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian Maeder (ns, dg3) = insGTheory dg2 name DGBasic gt
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder tim3 = Map.insert tok (getNode ns, sg, [], pl, paramSorts) tim2
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder (tim4, dg4) = createEdgesImports tok ips sg tim3 dg3
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder dg5 = createEdgesParams tok pl morphs sg tim4 dg4
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederinsertSpec (SpecTh sp_th) tim vm ths dg = (tim3, vm, tok : ths, dg3)
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder where (il, ss1) = getImportsSorts sp_th
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder ips = processImports tim vm dg il
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder ss2 = getThSorts ips
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (tim1, dg1) = last_da ips (tim, dg)
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder sg = sign_union (Maude.Sign.fromSpec sp_th) ips
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder ext_sg = makeExtSign Maude sg
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder nm_sns = map (makeNamed "") $ Maude.Sentence.fromSpec sp_th
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder sens = toThSens nm_sns
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder gt = G_theory Maude ext_sg startSigId sens startThId
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder name = makeName tok
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (ns, dg2) = insGTheory dg1 name DGBasic gt
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder tim2 = Map.insert tok (getNode ns, sg, ss1 ++ ss2, [], []) tim1
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (tim3, dg3) = createEdgesImports tok ips sg tim2 dg2
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaederinsertSpec (SpecView sp_v) tim vm ths dg = (tim2, vm', ths, dg4)
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder where View name from to rnms = sp_v
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder inst = isInstantiated ths to
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (tok1, tim1, morph1, _, dg1) = processModExp tim vm dg from
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (tok2, tim2, morph2, _, dg2) = processModExp tim1 vm dg1 to
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (n1, _, _, _, _) = fromJust $ Map.lookup tok1 tim2
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (n2, _, _, _, _) = fromJust $ Map.lookup tok2 tim2
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder morph = fromSignsRenamings (target morph1) (target morph2) rnms
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder morph' = fromJust $ maybeResult $ compose morph1 morph
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (new_sign, new_sens) = sign4renamings (target morph1) (sortMap morph) rnms
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder (n3, dg3) = insertInnerNode n2 (makeName tok2) morph2 new_sign new_sens dg2
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder vm' = Map.insert (HasName.getName name) (n3, morph', rnms, inst) vm
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder dg4 = insertThmEdgeMorphism tok_name n3 n1 morph' dg3
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder-- | compute the union of the signatures obtained from the importation list
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maedersign_union :: Sign -> [ImportProc] -> Sign
369454f9b2dbea113cbb40544a9b0f31425b2c69Christian Maedersign_union sign = foldr (Maude.Sign.union . get_sign) sign
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder-- | extract the target signature from the morphism in an importation tuple
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maederget_sign :: ImportProc -> Sign
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maederget_sign (_, _, _, morph, _, _) = target morph
d48085f765fca838c1d972d2123601997174583dChristian Maeder-- | compute the union of the target signatures of a list of morphisms
53301de22afd7190981b363b57c48df86fcb50f7Christian Maedersign_union_morphs :: [Morphism] -> Sign -> Sign
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maedersign_union_morphs morphs sg = foldr (Maude.Sign.union . target) sg morphs
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder-- | extracts the last (newest) data structures from a list of importation
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder-- tuples, using the second argument as default value if the list is empty
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maederlast_da :: [ImportProc] -> (TokenInfoMap, DGraph) -> (TokenInfoMap, DGraph)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maederlast_da [(_, _, tim, _, _, dg)] _ = (tim, dg)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maederlast_da (_ : ips) p = last_da ips p
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maederlast_da _ p = p
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder-- | generate the edges required by a parameter list in a module instantiation
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaedercreateEdgesParams :: Token -> [(Token, Token, [Token])] -> [Morphism] -> Sign
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -> TokenInfoMap -> DGraph -> DGraph
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaedercreateEdgesParams tok1 ((_, tok2, _) : toks) (morph : morphs) sg tim dg =
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder createEdgesParams tok1 toks morphs sg tim dg'
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder where morph' = setTarget sg morph
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder (n1, _, _, _, _) = fromJust $ Map.lookup tok1 tim
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder (n2, _, _, _, _) = fromJust $ Map.lookup tok2 tim
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder dg' = insertDefEdgeMorphism n1 n2 morph' dg
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaedercreateEdgesParams _ _ _ _ _ dg = dg
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder-- | generate the edges required by the importations
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedercreateEdgesImports :: Token -> [ImportProc] -> Sign -> TokenInfoMap -> DGraph
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder -> (TokenInfoMap, DGraph)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedercreateEdgesImports _ [] _ tim dg = (tim, dg)
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedercreateEdgesImports tok (ip : ips) sg tim dg = createEdgesImports tok ips sg tim' dg'
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder where (tim', dg') = createEdgeImport tok ip sg tim dg
9d75ab580dbf51b7ca60903fb32e7f38d939d326Christian Maeder-- | generate the edge for a concrete importation
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian MaedercreateEdgeImport :: Token -> ImportProc -> Sign -> TokenInfoMap -> DGraph
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder -> (TokenInfoMap, DGraph)
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedercreateEdgeImport tok1 (Pr, tok2, _, morph, _, _) sg tim dg = (tim', dg'')
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder where morph' = setTarget sg morph
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (tok2', tim', dg') = insertFreeNode tok2 tim dg
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder (n1, _, _, _, _) = fromJust $ Map.lookup tok1 tim'
1eb10c0c30323eed3cc21082fd242cd09a612dc5Christian Maeder (n2, _, _, _, _) = fromJust $ Map.lookup tok2' tim'
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder dg'' = insertDefEdgeMorphism n1 n2 morph' dg'
9d75ab580dbf51b7ca60903fb32e7f38d939d326Christian MaedercreateEdgeImport tok1 (Ex, tok2, _, morph, _, _) sg tim dg = (tim, dg')
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder where morph' = setTarget sg morph
fe5dbb45b6a8abf34375b4bc5f2a81cda664c0e4Christian Maeder (n1, _, _, _, _) = fromJust $ Map.lookup tok1 tim
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder (n2, _, _, _, _) = fromJust $ Map.lookup tok2 tim
fe5dbb45b6a8abf34375b4bc5f2a81cda664c0e4Christian Maeder dg' = insertConsEdgeMorphism n1 n2 morph' dg
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedercreateEdgeImport tok1 (Inc, tok2, _, morph, _, _) sg tim dg = (tim, dg')
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder where morph' = setTarget sg morph
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder (n1, _, _, _, _) = fromJust $ Map.lookup tok1 tim
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder (n2, _, _, _, _) = fromJust $ Map.lookup tok2 tim
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder dg' = insertDefEdgeMorphism n1 n2 morph' dg
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder-- | extract the sorts provided by the theories
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedergetThSorts :: [ImportProc] -> [Token]
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedergetThSorts [] = []
fe5dbb45b6a8abf34375b4bc5f2a81cda664c0e4Christian MaedergetThSorts (ip : ips) = getThSortsAux ip ++ getThSorts ips
369454f9b2dbea113cbb40544a9b0f31425b2c69Christian MaedergetThSortsAux :: ImportProc -> [Token]
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedergetThSortsAux (_, tok, tim, _, _, _) = srts
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder where (_, _, srts, _, _) = fromJust $ Map.lookup tok tim
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder-- | generate the extra signature needed when using term to term renaming in views
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maedersign4renamings :: Sign -> Map.Map Token Token -> [Renaming] -> (Sign, [Sentence])
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maedersign4renamings sg mtt ((TermMap t1 t2) : rnms) = (new_sg, (Equation eq) : sens)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder where (op_top, ss) = getOpSorts t1
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder sg' = newOp sg op_top ss mtt
369454f9b2dbea113cbb40544a9b0f31425b2c69Christian Maeder (sg'', sens) = sign4renamings sg mtt rnms
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder eq = Eq (applyRenamingTerm mtt t1) t2 [] []
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder new_sg = Maude.Sign.union sg' sg''
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maedersign4renamings sg mtt (_ : rnms) = sign4renamings sg mtt rnms
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maedersign4renamings sg _ [] = (sg, [])
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder-- | given the identifier of an operator in the given signature, the function
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder-- generates a new signature with this operator and a renamed profile computed
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder-- from the renaming given in the mapping
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedernewOp :: Sign -> Token -> [Token] -> Map.Map Token Token -> Sign
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedernewOp sg op ss mtt = Maude.Sign.empty {ops = Map.singleton op $ Set.singleton od}
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder where om = ops sg
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder ods = fromJust $ Map.lookup op om
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder od = getOpDecl ods ss mtt
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder-- | rename the profile with the given map
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedergetOpDecl :: OpDeclSet -> [Token] -> Map.Map Token Token -> OpDecl
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedergetOpDecl ods ss mtt = od'
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder where f = \ (x, _, _) -> x == ss
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder od' = applyRenamingOD od mtt
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder-- | apply the renaming in the map to the operator declaration
53301de22afd7190981b363b57c48df86fcb50f7Christian MaederapplyRenamingOD :: OpDecl -> Map.Map Token Token -> OpDecl
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederapplyRenamingOD (ar, co, ats) mtt = (ar', co', ats)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder where f = \ x -> if Map.member x mtt
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder then fromJust $ Map.lookup co mtt
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder ar' = map f ar
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder co' = if Map.member co mtt
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder then fromJust $ Map.lookup co mtt
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder-- | rename the sorts in a term
fe5dbb45b6a8abf34375b4bc5f2a81cda664c0e4Christian MaederapplyRenamingTerm :: Map.Map Token Token -> Term -> Term
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaederapplyRenamingTerm mtt (Apply q ts ty) = Apply q (map (applyRenamingTerm mtt) ts)
369454f9b2dbea113cbb40544a9b0f31425b2c69Christian Maeder (applyRenamingType mtt ty)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederapplyRenamingTerm mtt (Const q s) = Const q s'
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder where s' = applyRenamingType mtt s
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaederapplyRenamingTerm mtt (Var q s) = Var q s'
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder where s' = applyRenamingType mtt s
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder-- | rename a type
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederapplyRenamingType :: Map.Map Token Token -> Type -> Type
53301de22afd7190981b363b57c48df86fcb50f7Christian MaederapplyRenamingType mtt (TypeSort s) = TypeSort $ SortId q'
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder where SortId q = s
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder then fromJust $ Map.lookup q mtt
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederapplyRenamingType mtt (TypeKind k) = TypeKind $ KindId q'
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian Maeder where KindId q = k
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder then fromJust $ Map.lookup q mtt
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder-- | extract the top operator of a term and the names of its sorts
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder-- if it is applicated to some arguments
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedergetOpSorts :: Term -> (Token, [Token])
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedergetOpSorts (Const q _) = (q, [])
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedergetOpSorts (Var q _) = (q, [])
fe5dbb45b6a8abf34375b4bc5f2a81cda664c0e4Christian MaedergetOpSorts (Apply q ls _) = (q, getTypes ls)
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaedergetTypes :: [Term] -> [Token]
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedergetTypes ((Var _ s) : ts) = HasName.getName s : getTypes ts
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaedergetTypes _ = []
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian MaederprocessImports :: TokenInfoMap -> ViewMap -> DGraph -> [Import] -> [ImportProc]
669e21946b6f90785fc3cb44e7cf4f38c3f6493dChristian MaederprocessImports _ _ _ [] = []
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill MossakowskiprocessImports tim vm dg (i : il) = ip : processImports tim' vm dg' il
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder where ip@(_, _, tim', _, _, dg') = processImport tim vm dg i
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederprocessImport :: TokenInfoMap -> ViewMap -> DGraph -> Import -> ImportProc
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederprocessImport tim vm dg (Protecting modExp) = (Pr, tok, tim', morph, ps, dg')
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder where (tok, tim', morph, ps, dg') = processModExp tim vm dg modExp
53301de22afd7190981b363b57c48df86fcb50f7Christian MaederprocessImport tim vm dg (Extending modExp) = (Ex, tok, tim', morph, ps, dg')
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder where (tok, tim', morph, ps, dg') = processModExp tim vm dg modExp
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederprocessImport tim vm dg (Including modExp) = (Inc, tok, tim', morph, ps, dg')
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder where (tok, tim', morph, ps, dg') = processModExp tim vm dg modExp
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederprocessParameters :: [Parameter] -> TokenInfoMap -> DGraph -> ParamInfo
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederprocessParameters ps tim dg = foldr processParameter ([], tim, [], dg) ps
09249711700a6acbc40a2e337688b434d7aafa28Christian MaederprocessParameter :: Parameter -> ParamInfo -> ParamInfo
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederprocessParameter (Parameter sort modExp) (toks, tim, morphs, dg) = (toks', tim', morphs', dg')
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder where (tok, tim', morph, _, dg') = processModExp tim Map.empty dg modExp
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder (_, _, fs, _, _) = fromJust $ Map.lookup tok tim'
2fc11b362b9242202bda207e7c7ecc7771f1a5e3Christian Maeder fs' = renameSorts morph fs
909ce57d58a9cec1d214f0ecbdb1dadddad2e6d9Christian Maeder morph' = extendMorphismSorts morph (HasName.getName sort) fs'
f8a03685d9184046e88e1d76aabdab4f714db440Christian Maeder toks' = (HasName.getName sort, tok, fs') : toks
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder morphs' = morph' : morphs
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederprocessModExp :: TokenInfoMap -> ViewMap -> DGraph -> ModExp -> ModExpProc
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederprocessModExp tim _ dg (ModExp modId) = (tok, tim, morph, ps, dg)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder where tok = HasName.getName modId
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder (_, sg, _, _, ps) = fromJust $ Map.lookup tok tim
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder morph = createInclMorph sg sg
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederprocessModExp tim vm dg (SummationModExp modExp1 modExp2) = (tok, tim3, morph, ps', dg5)
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder where (tok1, tim1, morph1, ps1, dg1) = processModExp tim vm dg modExp1
fcfed328fae6266214ee61ee7a16fd263fd3cb70Christian Maeder (tok2, tim2, morph2, ps2, dg2) = processModExp tim1 vm dg1 modExp2
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder ps' = deleteRepeated $ ps1 ++ ps2
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder tok = mkSimpleId $ "{" ++ show tok1 ++ " + " ++ show tok2 ++ "}"
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder (n1, _, ss1, _, _) = fromJust $ Map.lookup tok1 tim2
46d766efdf8beaaadf3f34d99c305738064e9216Christian Maeder (n2, _, ss2, _, _) = fromJust $ Map.lookup tok2 tim2
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder ss1' = renameSorts morph1 ss1
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder ss2' = renameSorts morph1 ss2
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder sg1 = target morph1
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder sg2 = target morph2
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder morph = createInclMorph sg sg
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder morph1' = setTarget sg morph1
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder morph2' = setTarget sg morph2
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder (tim3, dg3) = insertNode tok sg tim2 (ss1' ++ ss2') [] dg2
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder (n3, _, _, _, _) = fromJust $ Map.lookup tok tim3
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder dg4 = insertDefEdgeMorphism n3 n1 morph1' dg3
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder dg5 = insertDefEdgeMorphism n3 n2 morph2' dg4
962036a37b92afb04ac0725cde9f20e599c04c5fChristian MaederprocessModExp tim vm dg (RenamingModExp modExp rnms) = (tok, tim', comp_morph, ps', dg')
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder where (tok, tim', morph, ps, dg') = processModExp tim vm dg modExp
e68f45f355ed9d4026ee9baff5aa75aa7c911cc2Christian Maeder morph' = fromSignRenamings (target morph) rnms
da2b959c50c95309d8eb8b24174249c2847e74b5Christian Maeder ps' = applyRenamingParamSorts (sortMap morph') ps
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder comp_morph = fromJust $ maybeResult $ compose morph morph'
b603f34b79bc0992e5d74f484e5bdc9f9c2346c6Christian MaederprocessModExp tim vm dg (InstantiationModExp modExp views) = (tok'', tim'', final_morph, new_param_sorts, dg'')
962036a37b92afb04ac0725cde9f20e599c04c5fChristian Maeder where (tok, tim', morph, paramSorts, dg') = processModExp tim vm dg modExp
53301de22afd7190981b363b57c48df86fcb50f7Christian Maeder (_, _, _, ps, _) = fromJust $ Map.lookup tok tim'
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder param_names = map (fstTern) ps
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder view_names = map HasName.getName views
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder (new_param_sorts, ps_morph) = instantiateSorts param_names view_names vm morph paramSorts
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder (tok', morph1, ns, deps) = processViews views (mkSimpleId "") tim' vm ps (ps_morph, [], [])
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder tok'' = mkSimpleId $ show tok ++ "{" ++ show tok' ++ "}"
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder sg2 = target morph1
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder final_morph = createInclMorph sg2 sg2
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder (tim'', dg'') = if Map.member tok'' tim
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder then (tim', dg')
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder else updateGraphViews tok tok'' sg2 morph1 ns tim' deps dg'
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederupdateGraphViews :: Token -> Token -> Sign -> Morphism -> [(Node, Sign)] -> TokenInfoMap
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -> [(Token, Token, [Token])] -> DGraph -> (TokenInfoMap, DGraph)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederupdateGraphViews tok1 tok2 sg morph views tim deps dg = (tim', dg''')
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder where (n1, _, _, _, _) = fromJust $ Map.lookup tok1 tim
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder morph' = setTarget sg morph
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -- TODO: if the parameter is another theory, the empty list
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -- must be replaced by the corresponding list of sorts
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder (tim', dg') = insertNode tok2 sg tim [] deps dg
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder (n2, _, _, _, _) = fromJust $ Map.lookup tok2 tim'
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder dg'' = insertDefEdgeMorphism n2 n1 morph' dg'
13b24998210d193b38cae06485da6f06c61d7f62Christian Maeder dg''' = insertDefEdgesMorphism n2 views sg dg''
53301de22afd7190981b363b57c48df86fcb50f7Christian MaederprocessViews :: [ViewId] -> Token -> TokenInfoMap -> ViewMap -> [(Token, Token, [Token])]
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder -> (Morphism, [(Node, Sign)], [(Token, Token, [Token])])
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -> (Token, Morphism, [(Node, Sign)], [(Token, Token, [Token])])
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaederprocessViews (vi : vis) tok tim vm (p : ps) (morph, lp, dep) =
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder Just n -> processViews vis tok'' tim vm ps (morph', lp ++ [(n, target morph')], dep ++ new_dep)
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder Nothing -> processViews vis tok'' tim vm ps (morph', lp, dep)
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder where (tok', morph', mn, new_dep) = processView vi tok tim vm p morph
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder tok'' = mkSimpleId $ show tok ++ "," ++ show tok'
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederprocessViews _ tok _ _ _ (morph, nds, deps) = (tok', morph, nds, deps)
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder where tok' = mkSimpleId $ drop 1 $ show tok
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederprocessView :: ViewId -> Token -> TokenInfoMap -> ViewMap -> (Token, Token, [Token]) ->
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder Morphism -> (Token, Morphism, Maybe Node, [(Token, Token, [Token])])
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederprocessView vi tok tim vm (p, _, ss) morph =
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder then morphismView name p ss (fromJust $ Map.lookup name vm) morph
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder else paramBinding name p ss morph
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian MaedermorphismView :: Token -> Token -> [Token] -> (Node, Morphism, [Renaming], Bool)
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder -> Morphism -> (Token, Morphism, Maybe Node, [(Token, Token, [Token])])
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian MaedermorphismView name p _ (n, _, rnms, True) morph = (name, morph', Just n, [])
ac142c1b088711f911018d8108a64be80b2f2a58Christian Maeder where rnms' = qualifyRenamings p rnms
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder morph' = applyRenamings morph rnms'
ac142c1b088711f911018d8108a64be80b2f2a58Christian MaedermorphismView name p ss (n, morph, rnms, False) morph1 =
f1ef1c750f805c1732b01001f2b157c0077b808eChristian Maeder (name, morph2, Just n, [(p, mkSimpleId "", renameSorts morph ss)])
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder where rnms' = qualifyRenamings2 p rnms
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder morph2 = applyRenamings morph1 rnms'
59a2f25e7d71b91b4eda6fa4da753473ad629619Christian Maeder-- parameter instantiated -> parameter binding -> sorts bound -> current morph
975642b989852fc24119c59cf40bc1af653608ffChristian MaederparamBinding :: Token -> Token -> [Token] -> Morphism -> (Token, Morphism, Maybe Node, [(Token, Token, [Token])])
975642b989852fc24119c59cf40bc1af653608ffChristian MaederparamBinding view p ss morph = (view, morph', Nothing, [])
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder where rnms = createQualifiedSortRenaming p view ss
4561227a776bdf0ab679b19fb92f1eaaed8786f7Christian Maeder morph' = applyRenamings morph rnms
ab0f35d8b9012e459417e086773049ce33dda2a0Christian MaederinsertNode :: Token -> Sign -> TokenInfoMap -> [Token] -> [(Token, Token, [Token])] -> DGraph -> (TokenInfoMap, DGraph)
dcb9ff0e2c2379735acce7073196508d455e0b01Christian MaederinsertNode tok sg tim ss deps dg = if Map.member tok tim
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder then (tim, dg)
09249711700a6acbc40a2e337688b434d7aafa28Christian Maeder ext_sg = makeExtSign Maude sg
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder gt = G_theory Maude ext_sg startSigId noSens startThId
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder name = makeName tok
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder (ns, dg') = insGTheory dg name DGBasic gt
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder tim' = Map.insert tok (getNode ns, sg, ss, deps, []) tim
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder in (tim', dg')
975642b989852fc24119c59cf40bc1af653608ffChristian MaederinsertInnerNode :: Node -> NodeName -> Morphism -> Sign -> [Sentence] -> DGraph
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder -> (Node, DGraph)
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian MaederinsertInnerNode nod nm morph sg sens dg =
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder if (isIdentity morph) && (sens == [])
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder then (nod, dg)
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder th_sens = toThSens $ map (makeNamed "") sens
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder sg' = Maude.Sign.union sg $ target morph
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder ext_sg = makeExtSign Maude sg'
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder gt = G_theory Maude ext_sg startSigId th_sens startThId
dcb9ff0e2c2379735acce7073196508d455e0b01Christian Maeder (ns, dg') = insGTheory dg (inc nm) DGBasic gt
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder nod2 = getNode ns
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder morph' = setTarget sg' morph
49fc18b4bb1d4a8d3ec05e0cffd5f0475b289592Christian Maeder dg'' = insertDefEdgeMorphism nod2 nod morph' dg'
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder in (nod2, dg'')
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder-- | insert the list of definition edges, building for each node the inclusion morphism
975642b989852fc24119c59cf40bc1af653608ffChristian Maeder-- between the signatures
where (n1, sg1, _, _, _) = fromJust $ Map.lookup tok1 tim
(n2, sg2, _, _, _) = fromJust $ Map.lookup tok2 tim
b = Map.member t' tim
else insertFreeNode2 t' tim (fromJust $ Map.lookup t tim) dg
tim' = Map.insert t (getNode ns, sg, [], [], []) tim
getImportsSortsStmnts stmts (is, (HasName.getName s) : ss)
hPutStrLn hIn "in Maude/hets.prj"
Map.singleton (Lib_id (Direct_link "" nullRange)) dg ))
where f = \ (Parameter s _) -> HasName.getName s
isInstantiated ths (ModExp modExp) = notElem (HasName.getName modExp) ths
applyRenamingParamSorts :: Map.Map Token Token -> [ParamSort] -> [ParamSort]
applyRenamingParamSort :: Map.Map Token Token -> ParamSort -> [ParamSort]
applyRenamingParamSort mtt (tok, params) acc = case Map.member tok mtt of
tok' = fromJust $ Map.lookup tok mtt
newParamers4sorts (param : ps) (view : vs) vm = case Map.member view vm of
(_, _, _, inst) = fromJust $ Map.lookup view vm