VSEBasicSpec Sentence SYMB_ITEMS SYMB_MAP_ITEMS
Symbol RawSymbol () where
sourceLogic CASL2VSERefine = CASL
sourceSublogic CASL2VSERefine =
SL.cFol targetLogic CASL2VSERefine = VSE
mapSublogic CASL2VSERefine _ = Just ()
map_theory CASL2VSERefine = mapCASLTheory
map_morphism CASL2VSERefine = return . mapMor
map_sentence CASL2VSERefine _ = error "map sen nyi" --return. mapCASSen
map_symbol CASL2VSERefine = error "map symbol nyi"
has_model_expansion CASL2VSERefine = True
--check these 3, but should be fine
is_weakly_amalgamable CASL2VSERefine = True
isInclusionComorphism CASL2VSERefine = False
mapCASLTheory :: (CASLSign, [Named CASLFORMULA]) ->
Result (VSESign, [Named Sentence])
mapCASLTheory (sig, n_sens) =
let (tsig, genAx) = mapSig sig
tsens = map mapNamedSen n_sens
in if null $ checkCases tsig allSens then return (tsig, allSens) else
fail "case error in signature"
mapSig :: CASLSign -> (VSESign, [Named Sentence])
let wrapSort (procsym, axs) s = let
restrName = gnRestrName s
sProcs = [(restrName, Profile [Procparam In s] Nothing),
Profile [Procparam In s, Procparam In s]
varx = Qual_var (genToken "x") s nullRange
vary = Qual_var (genToken "y") s nullRange
varz = Qual_var (genToken "z") s nullRange
varb = Qual_var (genToken "b")
varb1 = Qual_var (genToken "b1")
varb2 = Qual_var (genToken "b2")
sSens = [ makeNamed ("ga_termination_eq_" ++ show s) $
Quantification Universal [Var_decl [genToken "x",
genToken "y"] s nullRange
, Var_decl [genToken "b"]
(Predication (Qual_pred_name restrName
(Pred_type [s] nullRange) nullRange)
(True_atom nullRange) ) nullRange,
(Predication (Qual_pred_name restrName
(Pred_type [s] nullRange) nullRange)
(True_atom nullRange) ) nullRange
(Op_type Partial [s,s] uBoolean nullRange)
(True_atom nullRange) ) nullRange)
True nullRange) nullRange ,
makeNamed ("ga_refl_eq_" ++ show s) $
Quantification Universal [Var_decl [genToken "x"] s nullRange
(Predication (Qual_pred_name restrName
(Pred_type [s] nullRange ) nullRange)
(True_atom nullRange) ) nullRange)
(Op_type Partial [s,s] uBoolean nullRange)
(Application (Qual_op_name uTrue
True nullRange) nullRange
, makeNamed ("ga_sym_eq_" ++ show s) $
Quantification Universal [Var_decl [genToken "x",
genToken "y"] s nullRange
,Var_decl [genToken "b1",
(Predication (Qual_pred_name restrName
(Pred_type [s] nullRange) nullRange)
(True_atom nullRange) ) nullRange,
(Predication (Qual_pred_name restrName
(Pred_type [s] nullRange) nullRange)
(True_atom nullRange) ) nullRange,
(Op_type Partial [s,s] uBoolean nullRange)
(Strong_equation varb1 aTrue nullRange
(Op_type Partial [s,s] uBoolean nullRange)
True nullRange) nullRange
, makeNamed ("ga_trans_eq_" ++ show s) $
Quantification Universal [Var_decl [genToken "x",
genToken "z"] s nullRange
,Var_decl [genToken "b1",
(Predication (Qual_pred_name restrName
(Pred_type [s] nullRange) nullRange)
(True_atom nullRange) ) nullRange,
(Predication (Qual_pred_name restrName
(Pred_type [s] nullRange ) nullRange)
(True_atom nullRange) ) nullRange,
(Predication (Qual_pred_name restrName
(Pred_type [s] nullRange ) nullRange)
(True_atom nullRange) ) nullRange,
(Op_type Partial [s,s] uBoolean nullRange)
(Op_type Partial [s,s] uBoolean nullRange)
(Op_type Partial [s,s] uBoolean nullRange)
True nullRange) nullRange ]
(sProcs ++ procsym, sSens ++ axs)
(sortProcs, sortSens) = foldl wrapSort ([],[]) $
wrapOp (procsym, axs) (i, opTypes) = let
fProcs = map (\profile ->
(map (Procparam In) $ opArgs profile)
(Just $ opRes profile))) opTypes
opTypeSens (OpType _ w s) = let
xtokens = map (\(_,ii) -> genNumVar "x" ii) $
Qual_var (genNumVar "x" ii )
Qual_var (genNumVar "y" ii )
ytokens = map (\(_,ii) -> genNumVar "y" ii) $
btokens = map (\(_,ii) -> genNumVar "b" ii) $
xvar = Qual_var (genToken "x")
yvar = Qual_var (genToken "y")
bvar = Qual_var (genToken "b")
Quantification Universal ([Var_decl [xtoken, ytoken] s
,Var_decl (btoken:btokens)
(zip (zip xtokens ytokens) w)
(concatMap (\(si,ii) -> let
xv = (Qual_var (genNumVar "x" ii)
yv = (Qual_var (genNumVar "y" ii)
bi1 = (Qual_var (genNumVar "b" ii)
[ExtFORMULA $ Ranged ( Dlformula Diamond
(Pred_type [si] nullRange) nullRange )
(True_atom nullRange) ) nullRange ,
ExtFORMULA $ Ranged ( Dlformula Diamond
(Pred_type [si] nullRange) nullRange)
(True_atom nullRange) ) nullRange ,
ExtFORMULA $ mkRanged $ Dlformula Diamond
(Op_type Partial [si,si] uBoolean nullRange)
(Op_type Partial w s nullRange)
(Op_type Partial w s nullRange)
(Op_type Partial [s,s] uBoolean nullRange)
) nullRange) --conclusion
termF = if not $ null w then
[ makeNamed "" $ Quantification Universal
(Var_decl [xtoken] s nullRange
: map (\ (t1, si) -> Var_decl [t1] si nullRange)
(concatMap (\ (si, ii) -> let
xv = Qual_var (genNumVar "x" ii) si nullRange in
[ExtFORMULA $ Ranged ( Dlformula Diamond
(Pred_type (w ++ [s]) nullRange) nullRange)
(True_atom nullRange) ) nullRange
(Op_type Partial w s nullRange)
(Dlformula Diamond (Ranged
(Call (Predication (Qual_pred_name
(Pred_type [s] nullRange) nullRange)
[makeNamed "" $ Quantification Universal
[Var_decl [xtoken] s nullRange]
(Op_type Partial [] s nullRange)
(Dlformula Diamond (Ranged
(Call (Predication (Qual_pred_name
(Pred_type [s] nullRange) nullRange)
if null w then termF else congrF ++ termF
fSens = concatMap opTypeSens opTypes
(procsym ++ fProcs, axs ++ fSens)
(opProcs, opSens) = foldl wrapOp ([],[]) $
wrapPred (procsym, axs) (i, predTypes) = let
pProcs = map (\profile -> (procName,
(map (Procparam In) $ predArgs profile)
(Just uBoolean))) predTypes
predTypeSens (PredType w) = let
xtokens = map (\(_,ii) -> genNumVar "x" ii) $
Qual_var (genNumVar "x" ii )
ytokens = map (\(_,ii) -> genNumVar "y" ii) $
btokens = map (\(_,ii) -> genNumVar "b" ii) $
rvar1 = Qual_var (genToken "r1")
rvar2 = Qual_var (genToken "r2")
congrP = [makeNamed "" $ Quantification Universal
(Var_decl (btoken : r1 : r2 : btokens) uBoolean nullRange
: map (\ ((t1, t2), si) -> Var_decl [t1, t2] si nullRange)
(zip (zip xtokens ytokens) w))
(concatMap (\(si,ii) -> let
xv = (Qual_var (genNumVar "x" ii)
yv = (Qual_var (genNumVar "y" ii)
bi1 = (Qual_var (genNumVar "b" ii)
[ExtFORMULA $ Ranged ( Dlformula Diamond
(Pred_type [si] nullRange) nullRange)
(True_atom nullRange) ) nullRange ,
ExtFORMULA $ Ranged ( Dlformula Diamond
(Pred_type [si] nullRange) nullRange)
(True_atom nullRange) ) nullRange ,
ExtFORMULA $ mkRanged $ Dlformula Diamond
(Assign (genNumVar "b" ii)
(Op_type Partial [si,si] uBoolean nullRange)
(Ranged (Call (Predication
(Qual_pred_name (mkGenName i)
(Pred_type (w ++ [uBoolean]) nullRange)
Qual_var (genNumVar "x" ii )
(number w) ++ [rvar1]) nullRange)) nullRange)
(Ranged (Call (Predication
(Qual_pred_name (mkGenName i)
(Pred_type (w ++ [uBoolean]) nullRange)
Qual_var (genNumVar "y" ii )
(number w) ++ [rvar2]) nullRange)) nullRange)
) nullRange) --conclusion
termP = [ makeNamed "" $ Quantification Universal
(concatMap (\(si,ii) -> let
xv = (Qual_var (genNumVar "x" ii)
[ExtFORMULA $ Ranged ( Dlformula Diamond
(Pred_type [si] nullRange) nullRange)
(True_atom nullRange) ) nullRange
(Call (Predication (Qual_pred_name (mkGenName i)
(Pred_type (w ++ [uBoolean]) nullRange)
pSens = concatMap predTypeSens predTypes
(procsym ++ pProcs, axs ++ pSens)
(predProcs, predSens) = foldl wrapPred ([],[]) $
procs = Procs $
Map.fromList (sortProcs ++ opProcs ++ predProcs)
newPreds = procsToPredMap procs
newOps = procsToOpMap procs
in(sign { opMap = newOps,
sentences = [] }, sortSens ++ opSens ++ predSens)
mapNamedSen :: Named CASLFORMULA -> Named Sentence
mapMor :: CASLMor -> VSEMor
{ msource = fst $ mapSig $ msource m
, mtarget = fst $ mapSig $ mtarget m
, extended_map = emptyMorExt
mapCASLSen :: CASLFORMULA -> Sentence
(sen, (_i, vars)) = runState (mapCASLSenAux f) (0,
Set.empty)
_ -> addQuantifiers vars sen
addQuantifiers :: VarSet -> Sentence -> Sentence
addQuantifiers vars sen =
(map (\(v,s) -> Var_decl [v] s nullRange) $
Set.toList vars) sen nullRange
mapCASLSenAux :: CASLFORMULA -> State (Int, VarSet) Sentence
mapCASLSenAux f = case f of
Sort_gen_ax constrs isFree -> do
(genSorts, _, _ ) = recover_Sort_gen_ax constrs
toProcs (Op_name _, _) = error "must be qual names"
toProcs (Qual_op_name op (Op_type _fkind args res _range) _, l) =
( Qual_op_name (mkGenName op)
(Op_type Partial args res nullRange) nullRange,
opsToProcs (Constraint nSort syms oSort) =
Constraint nSort (map toProcs syms) oSort
return $ ExtFORMULA $ Ranged
True_atom _ps -> return $ True_atom nullRange
False_atom _ps -> return $ False_atom nullRange
Strong_equation t1 t2 _ps -> do
let sort1 = sortOfTerm t1
n1 <- freshIndex sort1 -- (typeof t1)
prg1 <- mapCASLTerm n1 t1
n2 <- freshIndex sort1 -- (typeof t2)
prg2 <- mapCASLTerm n2 t2
return $ ExtFORMULA $ Ranged
(Seq (Ranged (Seq prg1 prg2) nullRange)
(Op_type Partial [sort1,sort1] uBoolean nullRange)
[Qual_var (genNumVar "x" n1) sort1 nullRange,
Qual_var (genNumVar "x" n2) sort1 nullRange]
(Strong_equation (Qual_var (genNumVar "x" n) uBoolean nullRange)
-- here i have to return smth like
-- xn := gn_eq_s(xn1,xn2) :> xn = True "
Predication pn as _qs -> do
indexes <- mapM (freshIndex . sortOfTerm) as
prgs <- mapM (\(ti, i) -> mapCASLTerm i ti) $ zip as indexes
let xvars = map (\(ti,i) ->
Qual_var (genNumVar "x" i)
(sortOfTerm ti) nullRange ) $ zip as indexes
let asgn = if not $ null prgs then
foldr1 (\p1 p2 -> Ranged (Seq p1 p2) nullRange) prgs
else Ranged Skip nullRange
Pred_name _ -> fail "must be qualified"
Qual_pred_name pname (Pred_type ptype _)_ -> return $ ExtFORMULA $ Ranged
(Ranged (Assign (genNumVar "x" n)
(Op_type Partial ptype uBoolean nullRange) nullRange)
(Qual_var (genNumVar "x" n) uBoolean nullRange)
-- x:= gn_p(x1,..,xn):> x = True
mapFs <- mapM mapCASLSenAux fs
return $ Conjunction mapFs nullRange
mapFs <- mapM mapCASLSenAux fs
return $ Disjunction mapFs nullRange
Implication f1 f2 flag _r -> do
return $ Implication trf1 trf2 flag nullRange
Equivalence f1 f2 _r -> do
return $ Equivalence trf1 trf2 nullRange
return $ Negation trf nullRange
Quantification q vars sen _ ->
trSen <- mapCASLSenAux sen
let h = map (\ (Var_decl varS s _) -> let
restrs = map (\v -> ExtFORMULA $ Ranged (
(Pred_type [s] nullRange)
(True_atom nullRange)) nullRange)
Conjunction restrs nullRange)
(foldr1 (\ sen1 sen2 -> Conjunction [sen1,sen2] nullRange) h)
return $ Quantification q vars sen' nullRange
trSen <- mapCASLSenAux sen
let h = map (\ (Var_decl varS s _) -> let
restrs = map (\v -> ExtFORMULA $ Ranged (
(Pred_type [s] nullRange)
(True_atom nullRange)) nullRange)
Conjunction restrs nullRange)
[foldr1 (\ sen1 sen2 -> Conjunction [sen1,sen2] nullRange) h,
return $ Quantification q vars sen' nullRange
Unique_existential -> fail "nyi Unique_existential"
mapCASLTerm :: Int -> TERM () -> State (Int, VarSet) Program
mapCASLTerm n t = case t of
Qual_var v s _ps -> return $
Ranged (Assign (genNumVar "x" n)
(Qual_var v s nullRange)) nullRange
Application opsym as _qs -> do
indexes <- mapM (freshIndex . sortOfTerm) as
let xvars = map (\(ti,i) ->
Qual_var (genNumVar "x" i)
(sortOfTerm ti) nullRange ) $ zip as indexes
prgs <- mapM (\(ti, i) -> mapCASLTerm i ti) $ zip as indexes
let asgn = if not $ null prgs then
foldr1 (\p1 p2 -> Ranged (Seq p1 p2) nullRange) prgs
else Ranged Skip nullRange
Op_name _ -> fail "must be qualified"
Qual_op_name oName (Op_type _ args res _) _ ->
[] -> return $ Ranged (Assign (genNumVar "x" n)
(Op_type Partial args res nullRange)
(Ranged (Assign (genNumVar "x" n)
(Op_type Partial args res nullRange)
freshIndex :: SORT -> State (Int, VarSet) Int