Show
Ignore:
Timestamp:
05.01.2009 15:46:06 (11 months ago)
Author:
csliam
Message:

Large commit - improved static analysis of cspcasl and translation of cspcasl to isabelle

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/CspCASL/Trans_CspProver.hs

    r10931 r11215  
    1515module CspCASL.Trans_CspProver where 
    1616 
    17 import CASL.AS_Basic_CASL (SORT, VAR) 
     17import qualified CASL.AS_Basic_CASL as CASL_AS_Basic_CASL 
     18import qualified CASL.Fold as CASL_Fold 
     19import qualified CASL.Sign as CASL_Sign 
    1820 
    1921import Common.Id 
     22 
     23import qualified Comorphisms.CFOL2IsabelleHOL as CFOL2IsabelleHOL 
    2024 
    2125import CspCASL.AS_CspCASL_Process 
     
    2630import Isabelle.IsaConsts 
    2731 
    28 transProcess :: PROCESS -> Term 
    29 transProcess pr = case pr of 
     32transProcess :: CASL_Sign.Sign () () -> PROCESS -> Term 
     33transProcess caslSign pr = case pr of 
    3034    -- precedence 0 
    3135    Skip _ -> cspProver_skipOp 
     
    4145    -- precedence 1 
    4246    ConditionalProcess _ p q _ -> 
    43         cspProver_conditionalOp true (transProcess p) (transProcess q) 
     47        cspProver_conditionalOp true (transProcess caslSign p) 
     48                                     (transProcess caslSign q) 
    4449    -- precedence 2 
    4550    Hiding p es _ -> 
    46         cspProver_hidingOp (transProcess p) (transEventSet es) 
     51        cspProver_hidingOp (transProcess caslSign p) (transEventSet es) 
    4752    RenamingProcess p r _ -> 
    48         cspProver_renamingOp (transProcess p) (transRenaming r) 
     53        cspProver_renamingOp (transProcess caslSign p) (transRenaming r) 
    4954    -- precedence 3 
    5055    Sequential p q _ -> 
    51         cspProver_sequenceOp (transProcess p) (transProcess q) 
     56        cspProver_sequenceOp (transProcess caslSign p) (transProcess caslSign q) 
    5257    PrefixProcess ev p _ -> 
    53         cspProver_action_prefixOp (transEvent ev) (transProcess p) 
     58        cspProver_action_prefixOp (transEvent caslSign ev) 
     59                                  (transProcess caslSign p) 
    5460    InternalPrefixProcess v s p _ -> 
    5561        cspProver_internal_prefix_choiceOp (transVar v) 
    5662                                           (transSort s) 
    57                                            (transProcess p) 
     63                                           (transProcess caslSign p) 
    5864    ExternalPrefixProcess v s p _ -> 
    5965        cspProver_external_prefix_choiceOp (transVar v) 
    6066                                           (transSort s) 
    61                                            (transProcess p) 
     67                                           (transProcess caslSign p) 
    6268    -- precedence 4 
    6369    InternalChoice p q _ -> 
    64         cspProver_internal_choiceOp (transProcess p) (transProcess q) 
     70        cspProver_internal_choiceOp (transProcess caslSign p) 
     71                                    (transProcess caslSign q) 
    6572    ExternalChoice p q _ -> 
    66         cspProver_external_choiceOp (transProcess p) (transProcess q) 
     73        cspProver_external_choiceOp (transProcess caslSign p) 
     74                                    (transProcess caslSign q) 
    6775    -- precedence 5 
    6876    Interleaving p q _ -> 
    69         cspProver_interleavingOp (transProcess p) (transProcess q) 
     77        cspProver_interleavingOp (transProcess caslSign p) 
     78                                 (transProcess caslSign q) 
    7079    SynchronousParallel p q _ -> 
    71         cspProver_synchronousOp (transProcess p) (transProcess q) 
     80        cspProver_synchronousOp (transProcess caslSign p) 
     81                                (transProcess caslSign q) 
    7282    GeneralisedParallel p es q _ -> 
    73         cspProver_general_parallelOp (transProcess p) 
     83        cspProver_general_parallelOp (transProcess caslSign p) 
    7484                                     (transEventSet es) 
    75                                      (transProcess q) 
     85                                     (transProcess caslSign q) 
    7686 
    7787    AlphabetisedParallel p les res q _ -> 
    78         cspProver_alphabetised_parallelOp (transProcess p) 
     88        cspProver_alphabetised_parallelOp (transProcess caslSign p) 
    7989                                          (transEventSet les) 
    8090                                          (transEventSet res) 
    81                                           (transProcess q) 
     91                                          (transProcess caslSign q) 
     92    -- BUG not done right yet 
     93    FQProcess p _ _ -> 
     94        transProcess caslSign p 
    8295 
    8396transEventSet :: EVENT_SET -> Term 
     
    88101         EventSet commTypes _ -> Set $ FixedSet $ map tranCommType commTypes 
    89102 
    90 transEvent :: EVENT -> Term 
    91 transEvent ev = 
     103transEvent :: CASL_Sign.Sign () () -> EVENT -> Term 
     104transEvent caslSign ev = 
    92105    case ev of 
    93       TermEvent _caslTerm _ -> conDouble "not yet done" 
    94       ChanSend _ _ _ -> conDouble "not yet done" 
    95       ChanNonDetSend _ _ _ _ -> conDouble "not yet done" 
    96       ChanRecv _ _ _ _ -> conDouble "not yet done" 
     106      TermEvent caslTerm _ -> transTerm_with_class caslSign caslTerm 
     107      ChanSend _ _ _ -> conDouble "ChanSendNotYetDone" 
     108      ChanNonDetSend _ _ _ _ -> conDouble "ChanNonDetSendNotYetDone" 
     109      ChanRecv _ _ _ _ -> conDouble "ChanRecvNotYetDone" 
    97110 
    98 transVar :: VAR -> Term 
     111transVar :: CASL_AS_Basic_CASL.VAR -> Term 
    99112transVar v = conDouble $ tokStr v 
    100113 
    101 transSort :: SORT -> Term 
     114transSort :: CASL_AS_Basic_CASL.SORT -> Term 
    102115transSort sort = let sortBarString = convertSort2String sort ++ barExtS 
    103116                 in conDouble  sortBarString 
     
    105118transRenaming :: RENAMING -> Term 
    106119transRenaming _ = conDouble "not yet done" 
     120 
     121 
     122 
     123-- BUG - I dont think these functions are correct 
     124transTerm_with_class :: CASL_Sign.Sign () () -> CASL_AS_Basic_CASL.TERM () -> 
     125                        Term 
     126transTerm_with_class caslSign caslTerm = 
     127    case caslTerm of 
     128      -- if the term is just a variable then we just translate the 
     129      -- variable to isabelle 
     130      CASL_AS_Basic_CASL.Qual_var _ _ _ -> transCaslTerm caslSign caslTerm 
     131      -- otherwise we add a classOp around it and translate the inside of 
     132      -- it with the translator that adds a chooseOp 
     133      _ -> classOp (transTerm_with_choose caslSign caslTerm) 
     134 
     135transTerm_with_choose :: CASL_Sign.Sign () () -> CASL_AS_Basic_CASL.TERM () -> 
     136                        Term 
     137transTerm_with_choose caslSign caslTerm = 
     138    case caslTerm of 
     139      -- if the term is just a variable then we need to apply the choose 
     140      -- function 
     141      CASL_AS_Basic_CASL.Qual_var _ _ _ -> termAppl (conDouble "choose") 
     142                                 (transCaslTerm caslSign caslTerm) 
     143      -- otherwise we just translate it to Isabelle 
     144      _ -> transCaslTerm caslSign caslTerm 
     145 
     146-- | Translate a CASL Term to an Isabelle Term using the exact 
     147--   translation as is done in the comorphism composition 
     148--   CASL2PCFOL;defaultCASL2SubCFOL;CFOL2IsabelleHOL 
     149transCaslTerm :: CASL_Sign.Sign () () -> CASL_AS_Basic_CASL.TERM () -> Term 
     150transCaslTerm caslSign caslTerm = 
     151    let tyToks = CFOL2IsabelleHOL.typeToks caslSign 
     152        trForm = CFOL2IsabelleHOL.formTrCASL 
     153        strs = CFOL2IsabelleHOL.getAssumpsToks caslSign 
     154    in CASL_Fold.foldTerm (CFOL2IsabelleHOL.transRecord 
     155                                           caslSign tyToks trForm strs) caslTerm 
     156 
     157 
     158-- My own version of transRecord 
     159-- transRecord_Term :: CASL.Sign.Sign f e -> Set.Set String -> FormulaTranslator f e 
     160--             -> Set.Set String -> Record f Term Term 
     161-- transRecord_Term sign tyToks tr toks = Record 
     162--     { foldSimpleId = error "transRecord_Term: Simple_id" 
     163--     , foldQual_var = \ _ v _ _ -> mkFree $ transVar toks v 
     164--     , foldApplication = \ _ opsymb args _ -> 
     165--           foldl termAppl (con $ transOP_SYMB sign tyToks opsymb) args 
     166--     , foldSorted_term = \ _ t _ _ -> t -- no subsorting assumed 
     167--     , foldCast = \ _ t _ _ -> t -- no subsorting assumed 
     168--     , foldConditional = \ _  t1 phi t2 _ -> -- equal types assumed 
     169--           If phi t1 t2 NotCont 
     170--     , foldMixfix_qual_pred = error "transRecord_Term: Mixfix_qual_pred" 
     171--     , foldMixfix_term = error "transRecord_Term: Mixfix_term" 
     172--     , foldMixfix_token = error "transRecord_Term: Mixfix_token" 
     173--     , foldMixfix_sorted_term = error "transRecord_Term: Mixfix_sorted_term" 
     174--     , foldMixfix_cast = error "transRecord_Term: Mixfix_cast" 
     175--     , foldMixfix_parenthesized = error "transRecord_Term: Mixfix_parenthesized" 
     176--     , foldMixfix_bracketed = error "transRecord_Term: Mixfix_bracketed" 
     177--     , foldMixfix_braced = error "transRecord_Term: Mixfix_braced" 
     178--     } 
     179 
     180-- transVar :: Set.Set String -> VAR -> String 
     181-- transVar toks v = let 
     182--     s = showIsaConstT (simpleIdToId v) baseSign 
     183--     renVar t = if Set.member t toks then renVar $ "X_" ++ t else t 
     184--     in renVar s 
     185