Changeset 11215

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

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

Location:
trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • trunk/Comorphisms/CASL2CspCASL.hs

    r11201 r11215  
    2626-- CspCASL 
    2727import CspCASL.Logic_CspCASL 
    28 import CspCASL.AS_CspCASL (CspBasicSpec (..), CspCASLSentence, emptyCCSentence) 
     28import CspCASL.AS_CspCASL (CspBasicSpec (..)) 
    2929import CspCASL.SignCSP 
    3030 
     
    4141               Symbol RawSymbol ProofTree 
    4242               CspCASL () 
    43                CspBasicSpec CspCASLSentence SYMB_ITEMS SYMB_MAP_ITEMS 
     43               CspBasicSpec CspCASLSen SYMB_ITEMS SYMB_MAP_ITEMS 
    4444               CspCASLSign 
    4545               CspMorphism 
     
    7373  , pred_map = pred_map m } 
    7474 
    75 mapSen :: CASLFORMULA -> CspCASLSentence 
    76 mapSen _ = emptyCCSentence 
     75mapSen :: CASLFORMULA -> CspCASLSen 
     76mapSen _ = emptyCCSen 
  • trunk/Comorphisms/CFOL2IsabelleHOL.hs

    r10903 r11215  
    2020    , SignTranslator 
    2121    , FormulaTranslator 
     22    , getAssumpsToks 
     23    , formTrCASL 
    2224    , quantifyIsa 
    2325    , quantify 
    2426    , transSort 
     27    , transRecord 
    2528    , transOP_SYMB 
    2629    ) where 
  • trunk/Comorphisms/CspCASL2IsabelleHOL.hs

    r10619 r11215  
    2727import qualified Comorphisms.CFOL2IsabelleHOL as CFOL2IsabelleHOL 
    2828import Comorphisms.CFOL2IsabelleHOL(IsaTheory) 
     29import CspCASL.AS_CspCASL_Process (PROCESS_NAME) 
    2930import CspCASL.Logic_CspCASL 
    3031import CspCASL.AS_CspCASL 
     
    4950instance Comorphism CspCASL2IsabelleHOL 
    5051               CspCASL () 
    51                CspBasicSpec CspCASLSentence SYMB_ITEMS SYMB_MAP_ITEMS 
     52               CspBasicSpec CspCASLSen SYMB_ITEMS SYMB_MAP_ITEMS 
    5253               CspCASLSign 
    5354               CspMorphism 
     
    7172 
    7273-- | Translate CspCASL theories to Isabelle 
    73 transCCTheory :: (CspCASLSign, [Named CspCASLSentence]) -> Result IsaTheory 
     74transCCTheory :: (CspCASLSign, [Named CspCASLSen]) -> Result IsaTheory 
    7475transCCTheory ccTheory = 
    7576    let ccSign = fst ccTheory 
    7677        ccSens = snd ccTheory 
     78 
    7779        caslSign = ccSig2CASLSign ccSign 
     80        cspSign = ccSig2CspSign ccSign 
     81 
    7882        casl2pcfol = (map_theory CASL2PCFOL.CASL2PCFOL) 
    7983        pcfol2cfol = (map_theory CASL2SubCFOL.defaultCASL2SubCFOL) 
    8084        cfol2isabelleHol = (map_theory CFOL2IsabelleHOL.CFOL2IsabelleHOL) 
    8185        sortList = Set.toList(CASLSign.sortSet caslSign) 
    82         --fakeType = Type {typeId = "Fake_Type" , typeSort = [], typeArgs =[]} 
     86        fakeType = Type {typeId = "Fake_Type" , typeSort = [], typeArgs =[]} 
    8387    in do -- Remove Subsorting from the CASL part of the CspCASL specification 
    8488          translation1 <- casl2pcfol (caslSign,[]) 
     
    8791          -- Next Translate to IsabelleHOL code 
    8892          translation3 <- cfol2isabelleHol translation2 
    89           -- Next add the preAlpabet construction to the IsabelleHOL code 
    90           return $ addCspCaslSentences ccSens 
     93          -- Next add the preAlphabet construction to the IsabelleHOL code 
     94          return $ addProcMap ccSens caslSign 
     95                 $ addProcNameDatatype cspSign 
    9196                 $ addAllIntegrationTheorems sortList ccSign 
    9297                 $ addAllChooseFunctions sortList 
     
    99104                 $ addPreAlphabet sortList 
    100105                 $ addWarning 
     106                 -- hack: show the casl sentences 
     107                 --  addConst (show(ccSens)) fakeType 
    101108                 $ translation3 
    102109 
    103 -- This is not implemented in a sensible way yet and is not used 
    104 transCCSentence :: CspCASLSign -> CspCASLSentence -> Result IsaSign.Sentence 
    105 transCCSentence _ (CspCASLSentence pn _ _) = 
     110-- BUG This is not implemented in a sensible way yet and is not used 
     111transCCSentence :: CspCASLSign -> CspCASLSen -> Result IsaSign.Sentence 
     112transCCSentence _ (ProcessEq pn _ _ _) = 
    106113    do return (mkSen (Const (mkVName (show pn)) 
    107114                                (Disp (Type "byeWorld" [] []) TFun Nothing))) 
    108115 
    109 -- | Add a list of CspCASL sentences to an Isabelle theory 
    110 addCspCaslSentences :: [Named CspCASLSentence] -> IsaTheory -> IsaTheory 
    111 addCspCaslSentences namedSens isaTh = 
    112     -- Create datatype for process names 
    113     -- crate constant 
    114     -- create primrec 
    115       -- create list of equations -- one for each sentence 
    116     foldl addCspCaslSentence isaTh namedSens 
    117  
    118 -- | Add a single CspCASL sentence to an Isabelle theory 
    119 addCspCaslSentence :: IsaTheory -> Named CspCASLSentence -> IsaTheory 
    120 addCspCaslSentence isaTh namedSen = 
    121     let sen = sentence namedSen 
    122     in case sen of 
    123          CspCASLSentence pn _ proc -> 
    124              let name = show pn 
    125                  t1 = conDouble name 
    126                  t2 = transProcess proc 
    127              in addDef name t1 t2 isaTh 
    128  
    129 -- Functions for adding the PreAlphabet datatype to an Isabelle theory 
     116-------------------------------------------------------------------------- 
     117-- Functions for adding the process name datatype to an Isabelle theory -- 
     118-------------------------------------------------------------------------- 
     119 
     120-- | Add process name datatype which has a constructor for each 
     121--   process name (along with the arguments for the process) in the 
     122--   CspCASL Signature to an Isabelle theory 
     123addProcNameDatatype  :: CspSign -> IsaTheory -> IsaTheory 
     124addProcNameDatatype cspSign isaTh = 
     125    let -- Create a list of pairs of process names and thier profiles 
     126        procSetList = Map.toList (procSet cspSign) 
     127        procNameDomainEntry = mkProcNameDE procSetList 
     128    in updateDomainTab procNameDomainEntry isaTh 
     129 
     130 
     131-- | Make a proccess name Domain Entry from ... 
     132mkProcNameDE :: [(PROCESS_NAME, ProcProfile)] -> DomainEntry 
     133mkProcNameDE processes = 
     134    let -- The a list of pairs of constructors and their arguments 
     135        constructors = map mk_cons processes 
     136        -- Take a proccess name and its argument sorts (also its 
     137        -- commAlpha - thrown away) and make a pair representing the 
     138        -- constructor and the argument types 
     139        mk_cons (procName, (ProcProfile sorts _)) = 
     140            (mkVName (mkProcNameConstructor procName), map sortToTyp sorts) 
     141        -- Turn a sort in to a Typ suitable for the domain entry The 
     142        -- processes need to have arguments of the bar variants of 
     143        -- the sorts not the original sorts 
     144        sortToTyp sort = Type {typeId = mkSortBarString sort, 
     145                               typeSort = [isaTerm], 
     146                               typeArgs = []} 
     147    in 
     148    (procNameType, constructors) 
     149 
     150------------------------------------------------------------------------- 
     151-- Functions adding the process map fucntion to an Isabelle theory     -- 
     152------------------------------------------------------------------------- 
     153 
     154-- | Add the fucction procMap to an Isabelle theory. This function 
     155--   maps process names to real processes build using the same names 
     156--   and the alphabet i.e., ProcName => (ProcName, Alphabet) proc. We 
     157--   need to know the CspCASL sentences and the casl signature (data 
     158--   part) 
     159addProcMap :: [Named CspCASLSen] -> CASLSign.Sign () () -> IsaTheory -> 
     160              IsaTheory 
     161addProcMap namedSens caslSign isaTh = 
     162    let 
     163        -- Build new Isabelle theory with additional constant 
     164        isaThWithConst = addConst procMapS  procMapType isaTh 
     165        -- Get the plain sentences from the named senetences 
     166        sens = map (\namedsen -> sentence namedsen) namedSens 
     167        -- Filter so we only have proccess equations and no CASL senetences 
     168        processEqs = filter isProcessEq sens 
     169        -- the term representing the procMap that tajes a term as a 
     170        -- parameter 
     171        procMapTerm = termAppl (conDouble procMapS) 
     172        -- Make a single equation for the primrec from a process equation 
     173        -- BUG HERE - this next part is not right - underscore is bad 
     174        mkEq (ProcessEq procName vars _ proc) = 
     175            let -- Make the name (string) for this process 
     176                procNameString = convertProcessName2String procName 
     177                -- Change the name to a term 
     178                procNameTerm = conDouble procNameString 
     179                -- Turn the list of variables into a list of Isabelle 
     180                -- free variables 
     181                varTerms = [] -- BUG - should be somehting like map (\x -> mkFree (show x)) vars 
     182                 -- Make a lhs term built of termAppl applied to the 
     183                 -- proccess name and the variables 
     184                lhs = procMapTerm (foldl termAppl (procNameTerm) varTerms) 
     185                rhs = transProcess caslSign proc 
     186             in binEq lhs rhs 
     187        -- Build equations for primrec using process equations 
     188        eqs = map mkEq processEqs 
     189    in addPrimRec eqs isaThWithConst 
     190 
     191------------------------------------------------------------------------- 
     192-- Functions for adding the PreAlphabet datatype to an Isabelle theory -- 
     193------------------------------------------------------------------------- 
    130194 
    131195-- | Add the PreAlphabet (built from a list of sorts) to an Isabelle theory 
     
    142206                  (mkVName (mkPreAlphabetConstructor sort), 
    143207                               [Type {typeId = convertSort2String sort, 
    144                                                typeSort = [isaTerm], 
    145                                                           typeArgs = []}]) 
     208                                      typeSort = [isaTerm], 
     209                                      typeArgs = []}]) 
    146210             ) sorts 
    147211    ) 
    148212 
    149 -- Functions for adding the eq functions and the compare_with 
    150 -- functions to an Isabelle theory 
     213---------------------------------------------------------------- 
     214-- Functions for adding the eq functions and the compare_with -- 
     215-- functions to an Isabelle theory                            -- 
     216---------------------------------------------------------------- 
    151217 
    152218-- | Add the eq function to an Isabelle theory using a list of sorts 
    153219addEqFun :: [SORT] -> IsaTheory -> IsaTheory 
    154220addEqFun sortList isaTh = 
    155     let preAlphabetType = Type {typeId = preAlphabetS, 
    156                                 typeSort = [], 
    157                                 typeArgs =[]} 
    158         eqtype = mkFunType preAlphabetType $ mkFunType preAlphabetType boolType 
     221    let eqtype = mkFunType preAlphabetType $ mkFunType preAlphabetType boolType 
    159222        isaThWithConst = addConst eq_PreAlphabetS eqtype isaTh 
    160223        mkEq sort = 
     
    183246addCompareWithFun ccSign isaTh sort = 
    184247    let sortList = Set.toList(CASLSign.sortSet ccSign) 
    185         preAlphabetType = Type {typeId = preAlphabetS, 
    186                                 typeSort = [], 
    187                                 typeArgs =[]} 
    188248        sortType = Type {typeId = convertSort2String sort, typeSort = [], 
    189249                                  typeArgs =[]} 
     
    232292    in  addPrimRec eqs isaThWithConst 
    233293 
    234 -- Functions for producing the Justification theorems 
     294-------------------------------------------------------- 
     295-- Functions for producing the Justification theorems -- 
     296-------------------------------------------------------- 
    235297 
    236298-- | Add all justification theorems to an Isabelle Theory. We need to 
     
    409471    in addThreomWithProof name thmConds thmConcl proof' isaTh 
    410472 
     473-------------------------------------------------------------- 
     474-- Functions for producing instances of equivalence classes -- 
     475-------------------------------------------------------------- 
     476 
    411477-- | Function to add preAlphabet as an equivalence relation to an 
    412478--   Isabelle theory 
     
    434500       $ isaTh 
    435501 
     502------------------------------------------------------------- 
     503-- Functions for producing the alphabet type and bar types -- 
     504------------------------------------------------------------- 
     505 
    436506-- | Function to add the Alphabet type (type synonym) to an Isabelle theory 
    437507addAlphabetType :: IsaTheory -> IsaTheory 
    438508addAlphabetType  isaTh = 
    439     let preAlphabetType = Type {typeId = preAlphabetS, 
    440                                 typeSort = [], 
    441                                 typeArgs =[]} 
    442         preAlphabetQuotType = Type {typeId = quotS, 
    443                              typeSort = [], 
    444                              typeArgs =[preAlphabetType]} 
    445         isaTh_sign = fst isaTh 
     509    let isaTh_sign = fst isaTh 
    446510        isaTh_sign_tsig = tsig isaTh_sign 
    447511        myabbrs = abbrs isaTh_sign_tsig 
     
    460524addBarType :: IsaTheory -> SORT -> IsaTheory 
    461525addBarType isaTh sort = 
    462     let sortBarString = convertSort2String sort ++ barExtS 
     526    let sortBarString = mkSortBarString sort 
    463527        barType = Type {typeId = sortBarString, typeSort = [], typeArgs =[]} 
    464         alphabetType = Type {typeId = alphabetS, 
    465                              typeSort = [], 
    466                              typeArgs =[]} 
    467528        isaTh_sign = fst isaTh 
    468529        isaTh_sen = snd isaTh 
     
    538599                           Apply (SubgoalTac subgoalTacTerm), 
    539600                           Apply(Simp), 
    540                            Apply(Other ("unfold " ++ quotEqualityS)), 
     601                           Apply(SimpAdd Nothing [quotEqualityS]), 
    541602                           Apply(Other ("unfold "++ preAlphabetSimS 
    542603                                           ++ "_def")), 
     
    544605                           Done 
    545606    in  addThreomWithProof chooseFunName thmConds thmConcl proof' isaTh 
     607 
     608------------------------------------------------------ 
     609-- Functions for producing the integration theorems -- 
     610------------------------------------------------------ 
    546611 
    547612-- | Add all the integration theorems. We need to know all the sorts 
     
    573638              then false 
    574639              else 
    575                   -- pick any common sort - we should pick the top most one. 
     640                  -- BUG pick any common sort for now (this does hold 
     641                  -- and is valid) we should pick the top most one. 
    576642                  let s' = head commonSuperList 
    577643                  in binEq (mkInjection s1 s' x) (mkInjection s2 s' y) 
     
    589655    in  addThreomWithProof "IntegrationTheorem_A" thmConds thmConcl proof' isaTh 
    590656 
    591 -- Function to help keep strings consistent 
    592  
     657---------------------------------------------- 
     658-- Function to help keep strings consistent -- 
     659---------------------------------------------- 
     660 
     661-- | String of the name of the function to compare eqaulity of two 
     662--   elements of the PreAlphabet 
    593663eq_PreAlphabetS :: String 
    594664eq_PreAlphabetS = "eq_PreAlphabet" 
     
    603673quotEqualityS :: String 
    604674quotEqualityS = "quot_equality" 
    605  
    606 preAlphabetS :: String 
    607 preAlphabetS = "PreAlphabet" 
    608  
    609 quotS :: String 
    610 quotS = "quot" 
    611675 
    612676reflexivityTheoremS :: String 
     
    769833-- Function that returns the constructor of PreAlphabet for a given sort 
    770834mkPreAlphabetConstructor :: SORT -> String 
    771 mkPreAlphabetConstructor sort = "C_" ++ (show sort) 
     835mkPreAlphabetConstructor sort = "C_" ++ (convertSort2String sort) 
     836 
     837mkProcNameConstructor :: PROCESS_NAME -> String 
     838mkProcNameConstructor pn = show pn 
    772839 
    773840-- Function that takes a sort and outputs a the function name for the 
     
    781848mkChooseFunName sort = ("choose_" ++ (mkPreAlphabetConstructor sort)) 
    782849 
    783 -- Functions for manipulating an Isabelle theory 
     850 
     851 
     852-- Converts a SORT in to the corresponding bar sort represented as a 
     853-- string 
     854mkSortBarString :: SORT -> String 
     855mkSortBarString s = convertSort2String s ++ barExtS 
     856--------------------------------------------------- 
     857-- Functions for manipulating an Isabelle theory -- 
     858--------------------------------------------------- 
    784859 
    785860-- Add a single constant to the signature of an Isabelle theory 
     
    845920    in (isaTh_sign, isaTh_sen ++ [namedSen]) 
    846921 
    847 -- Code below this line is junk 
     922---------------------------------- 
     923-- Code below this line is junk -- 
     924---------------------------------- 
    848925 
    849926-- Add a warning to an Isabelle theory 
  • trunk/Comorphisms/CspCASL2Modal.hs

    r11201 r11215  
    2828import CspCASL.Logic_CspCASL 
    2929import CspCASL.SignCSP 
    30 import CspCASL.AS_CspCASL (CspBasicSpec (..), CspCASLSentence) 
     30import CspCASL.AS_CspCASL (CspBasicSpec (..)) 
    3131 
    3232-- ModalCASL 
     
    4242instance Comorphism CspCASL2Modal 
    4343               CspCASL () 
    44                CspBasicSpec CspCASLSentence SYMB_ITEMS SYMB_MAP_ITEMS 
     44               CspBasicSpec CspCASLSen SYMB_ITEMS SYMB_MAP_ITEMS 
    4545               CspCASLSign 
    4646               CspMorphism 
     
    8282 
    8383 
    84 mapSen :: CspCASLSentence -> ModalFORMULA 
     84mapSen :: CspCASLSen -> ModalFORMULA 
    8585mapSen _f = True_atom nullRange 
    8686 
  • trunk/CspCASL/AS_CspCASL.der.hs

    r10471 r11215  
    1414module CspCASL.AS_CspCASL where 
    1515 
     16import Common.Doc 
     17import Common.DocUtils 
    1618import Common.Id 
    1719 
    18 import CASL.AS_Basic_CASL (SORT, VAR) 
     20import CASL.AS_Basic_CASL (SORT, VAR, FORMULA) 
    1921 
    2022import CspCASL.AS_CspCASL_Process (CHANNEL_NAME, COMM_TYPE, PROCESS(..), 
    2123                                   PROCESS_NAME) 
    22  
    23 import Common.Id 
    2424 
    2525-- DrIFT command 
     
    3434                    deriving Show 
    3535 
     36data PROC_ALPHABET = ProcAlphabet [COMM_TYPE] Range 
     37                     deriving (Show,Ord, Eq) 
     38 
    3639data PROC_ITEM = Proc_Decl PROCESS_NAME PROC_ARGS PROC_ALPHABET 
    3740               | Proc_Eq PARM_PROCNAME PROCESS 
     
    4245data PARM_PROCNAME = ParmProcname PROCESS_NAME [VAR] 
    4346                     deriving Show 
    44  
    45 data PROC_ALPHABET = ProcAlphabet [COMM_TYPE] Range 
    46                      deriving Show 
    47  
    48 -- Sentences 
    49  
    50 data CspCASLSentence = CspCASLSentence PROCESS_NAME [VAR] PROCESS 
    51                deriving (Show, Eq, Ord) 
    52  
    53 emptyProcName :: PROCESS_NAME 
    54 emptyProcName = mkSimpleId "empty" 
    55  
    56 emptyCCSentence :: CspCASLSentence 
    57 emptyCCSentence = CspCASLSentence emptyProcName [] 
    58                       (NamedProcess emptyProcName [] nullRange) 
  • trunk/CspCASL/AS_CspCASL_Process.der.hs

    r10428 r11215  
    2121    PROCESS_NAME, 
    2222    RENAMING, 
     23    CommAlpha(..), 
     24    CommType(..), 
     25    TypedChanName(..) 
    2326) where 
    2427 
    2528import CASL.AS_Basic_CASL (FORMULA, SORT, TERM, VAR) 
    2629import Common.Id 
     30import qualified Data.Set as Set 
    2731 
    2832-- DrIFT command 
     
    4751type RENAMING = [Id] 
    4852 
    49  
    5053type CHANNEL_NAME = SIMPLE_ID 
    5154 
     
    5457type COMM_TYPE = SIMPLE_ID 
    5558 
     59-- | A process communication alphabet consists of a set of sort names 
     60-- and typed channel names. 
     61data TypedChanName = TypedChanName CHANNEL_NAME SORT 
     62                     deriving (Eq, Ord, Show) 
     63 
     64data CommType = CommTypeSort SORT 
     65              | CommTypeChan TypedChanName 
     66                deriving (Eq, Ord) 
     67 
     68instance Show CommType where 
     69    show (CommTypeSort s) = show s 
     70    show (CommTypeChan (TypedChanName c s)) = show (c, s) 
     71 
     72type CommAlpha = Set.Set CommType 
    5673 
    5774-- |CSP-CASL process expressions. 
     
    96113    -- | Named process 
    97114    | NamedProcess PROCESS_NAME [TERM ()] Range 
     115    -- | Fully qualified process. The range here shall be the same as 
     116    -- | in the process. 
     117    | FQProcess PROCESS CommAlpha Range 
    98118    deriving (Eq, Ord, Show) 
  • trunk/CspCASL/Logic_CspCASL.hs

    r10910 r11215  
    7272-- | Instance of Sentences for CspCASL (missing) 
    7373instance Sentences CspCASL 
    74     AS_CspCASL.CspCASLSentence -- sentence (missing) 
    75     SignCSP.CspCASLSign         -- signature 
     74    SignCSP.CspCASLSen  -- sentence (missing) 
     75    SignCSP.CspCASLSign     -- signature 
    7676    SignCSP.CspMorphism     -- morphism 
    7777    ()                      -- symbol (?) 
     
    102102    ()                      -- Sublogics (missing) 
    103103    AS_CspCASL.CspBasicSpec -- basic_spec 
    104     AS_CspCASL.CspCASLSentence -- sentence (missing) 
     104    SignCSP.CspCASLSen  -- sentence (missing) 
    105105    SYMB_ITEMS              -- symb_items 
    106106    SYMB_MAP_ITEMS          -- symb_map_items 
     
    118118instance StaticAnalysis CspCASL 
    119119    AS_CspCASL.CspBasicSpec -- basic_spec 
    120     AS_CspCASL.CspCASLSentence -- sentence (missing) 
     120    SignCSP.CspCASLSen  -- sentence (missing) 
    121121    SYMB_ITEMS              -- symb_items 
    122122    SYMB_MAP_ITEMS          -- symb_map_items 
  • trunk/CspCASL/Print_CspCASL.hs

    r10428 r11215  
    2424import CspCASL.CspCASL_Keywords 
    2525 
    26 instance Pretty CspCASLSentence where 
    27     pretty _ = empty 
     26import qualified Data.Set as S 
     27 
    2828 
    2929instance Pretty CspBasicSpec where 
     
    145145         alpar_close <+> (glue pr q) 
    146146        ) 
     147    FQProcess p commAlpha _ -> 
     148        let commAlphaList = S.toList commAlpha 
     149            prettyComms cs = sepByCommas (map pretty cs) 
     150        in brackets(pretty p) <> text "_" <> braces (prettyComms commAlphaList) 
     151 
     152instance Pretty CommType where 
     153    pretty (CommTypeSort s) = pretty s 
     154    pretty (CommTypeChan (TypedChanName c s)) =  parens (sepByCommas [pretty c, pretty s]) 
     155 
    147156 
    148157-- glue and prec_comp decide whether the child in the parse tree needs 
  • trunk/CspCASL/SignCSP.hs

    r10827 r11215  
    1717module CspCASL.SignCSP where 
    1818 
    19 import CspCASL.AS_CspCASL_Process (CHANNEL_NAME, PROCESS_NAME) 
    20  
    21 import CASL.AS_Basic_CASL (SORT) 
     19import CspCASL.AS_CspCASL_Process (CHANNEL_NAME, PROCESS_NAME, 
     20    PROCESS(..), CommAlpha(..), CommType(..), TypedChanName(..)) 
     21 
     22import CspCASL.AS_CspCASL () 
     23import CspCASL.Print_CspCASL 
     24 
     25import CASL.AS_Basic_CASL (FORMULA, SORT) 
    2226import CASL.Sign (emptySign, Sign, extendedInfo, sortRel) 
    2327import CASL.Morphism (Morphism) 
    2428 
    25 import qualified Common.Doc as Doc 
    26 import qualified Common.DocUtils as DocUtils 
    27 import Common.Id (Id, SIMPLE_ID) 
     29import Common.AS_Annotation (Named) 
     30 
     31import Common.Doc 
     32import Common.DocUtils 
     33 
     34import Common.Id (Id, SIMPLE_ID, mkSimpleId, nullRange) 
    2835import Common.Lib.Rel (predecessors) 
    2936import Common.Result 
     
    3845                   deriving (Eq, Show) 
    3946 
    40 -- | A process communication alphabet consists of a set of sort names 
    41 -- and typed channel names. 
    42 data TypedChanName = TypedChanName CHANNEL_NAME SORT 
    43                      deriving (Eq, Ord, Show) 
    44 data CommType = CommTypeSort SORT 
    45               | CommTypeChan TypedChanName 
    46                 deriving (Eq, Ord) 
    47 instance Show CommType where 
    48     show (CommTypeSort s) = show s 
    49     show (CommTypeChan (TypedChanName c s)) = show (c, s) 
    50  
    51 type CommAlpha = Set.Set CommType 
    52  
    5347type ChanNameMap = Map.Map CHANNEL_NAME SORT 
    5448type ProcNameMap = Map.Map PROCESS_NAME ProcProfile 
    5549type ProcVarMap = Map.Map SIMPLE_ID SORT 
     50type ProcVarList = [(SIMPLE_ID, SORT)] 
    5651 
    5752-- Close a communication alphabet under CASL subsort 
     
    9994    { chans :: ChanNameMap 
    10095    , procSet :: ProcNameMap 
     96    -- | Added for uniformity to the CASL static analysis. After 
     97    --   static analysis this is the empty list. 
     98    , ccSentences :: [Named CspCASLSen] 
    10199    } deriving (Eq, Show) 
    102100 
     
    107105ccSig2CASLSign :: CspCASLSign -> Sign () () 
    108106ccSig2CASLSign sigma = sigma { extendedInfo = () } 
     107 
     108ccSig2CspSign :: CspCASLSign -> CspSign 
     109ccSig2CspSign sigma = extendedInfo sigma 
    109110 
    110111-- | Empty CspCASL signature. 
     
    117118    { chans = Map.empty 
    118119    , procSet = Map.empty 
     120    , ccSentences =[] 
    119121    } 
    120122 
     
    170172 
    171173-- dummy instances, need to be elaborated! 
    172 instance DocUtils.Pretty CspSign where 
    173   pretty = Doc.text . show 
    174 instance DocUtils.Pretty CspAddMorphism where 
    175   pretty = Doc.text . show 
     174instance Pretty CspSign where 
     175  pretty = text . show 
     176instance Pretty CspAddMorphism where 
     177  pretty = text . show 
     178 
     179-- Sentences 
     180 
     181-- A CspCASl senetence is either a CASL formula or a Procsses 
     182-- equation. A process equation has on the LHS a process name, a list 
     183-- of parameters which are qualified variables (which are terms), a 
     184-- constituent communication alphabet and finally on the RHS a fully 
     185-- qualified process. 
     186data CspCASLSen = CASLSen (FORMULA ()) 
     187                | ProcessEq PROCESS_NAME ProcVarList CommAlpha PROCESS 
     188                  deriving (Show, Eq, Ord) 
     189 
     190instance Pretty CspCASLSen where 
     191    -- Not implemented yet - the pretty printing of the casl sentences 
     192    pretty(CASLSen _) = text "Pretty printing for CASLSen not implemented yet" 
     193    pretty(ProcessEq pn varList alpha proc) = 
     194        let varDoc = if (null varList) 
     195                     then empty 
     196                     else parens $ sepByCommas $ map pretty (map fst varList) 
     197        in pretty pn <+> varDoc <+> equals <+> pretty proc 
     198 
     199emptyCCSen :: CspCASLSen 
     200emptyCCSen = 
     201    let emptyProcName = mkSimpleId "empty" 
     202        emptyVarList = [] 
     203        emptyAlphabet = Set.empty 
     204        emptyProc = Skip nullRange 
     205    in ProcessEq emptyProcName emptyVarList emptyAlphabet emptyProc 
     206 
     207isCASLSen :: CspCASLSen -> Bool 
     208isCASLSen (CASLSen _) = True 
     209isCASLSen _           = False 
     210 
     211isProcessEq :: CspCASLSen -> Bool 
     212isProcessEq (ProcessEq _ _ _ _) = True 
     213isProcessEq _ = False 
     214 
  • trunk/CspCASL/StatAnaCSP.hs

    r11201 r11215  
    2121import qualified Data.Maybe as Maybe 
    2222import qualified Data.Set as S 
    23  
     23-- liam added the following, they should be deleted from imports when 
     24-- liams temp code is removed: Op_name mkSimpleId mkInfix OP_SYMB(..), 
     25-- OP_TYPE(..) 
    2426import CASL.AS_Basic_CASL (FORMULA(..), OpKind(..), SORT, TERM(..), VAR, 
    2527                           VAR_DECL(..)) 
     
    3436import Common.ConvertGlobalAnnos 
    3537import qualified Common.Lib.Rel as Rel 
    36 import Common.Id (getRange, Id, simpleIdToId, nullRange, mkSimpleId) 
     38import Common.Id (getRange, Id, simpleIdToId, nullRange) 
    3739import Common.Lib.State 
    3840import Common.ExtSign 
     
    4446import CspCASL.SignCSP 
    4547 
     48import qualified Data.Set as Set 
     49 
    4650basicAnalysisCspCASL :: (CspBasicSpec, CspCASLSign, GlobalAnnos) 
    4751        -> Result (CspBasicSpec, ExtSign CspCASLSign (), 
    48                    [Named CspCASLSentence]) 
    49 basicAnalysisCspCASL (cc, sigma, ga) = do 
     52                   [Named CspCASLSen]) 
     53basicAnalysisCspCASL (cc, sigma, ga) = 
    5054    let Result es mga = mergeGlobalAnnos ga $ globAnnos sigma 
    5155        (_, accSig) = runState (ana_BASIC_CSP cc) $ case mga of 
     
    5357              Just nga -> sigma { globAnnos = nga } 
    5458        ds = reverse $ envDiags accSig 
    55     Result (es ++ ds) (Just ()) -- insert diagnostics 
    56     return (cc, mkExtSign accSig, [makeNamed "empty_sentence" emptyCCSentence, 
    57                                    makeNamed "StopProcSen"  stopProc, 
    58                                    makeNamed "GParProcSen"  gParProc, 
    59                                    makeNamed "AParProcSen"  aParProc, 
    60                                    makeNamed "StopProcSen"  seqProc]) 
    61     where 
    62       stopProc = CspCASLSentence (mkSimpleId "stopProc") [] (Stop nullRange) 
    63       seqProc = CspCASLSentence (mkSimpleId "seqProc") [] 
    64                                        (Sequential (Stop nullRange) 
    65                                         (Stop nullRange) nullRange) 
    66       gParProc = CspCASLSentence (mkSimpleId "gParProc") [] 
    67                                        (GeneralisedParallel (Stop nullRange) 
    68                                         (EventSet [mkSimpleId "S"] nullRange) 
    69                                         (Skip nullRange) nullRange) 
    70       aParProc = CspCASLSentence (mkSimpleId "gParProc") [] 
    71                                      (AlphabetisedParallel (Stop nullRange) 
    72                                       (EventSet [mkSimpleId "T"] nullRange) 
    73                                       (EventSet [mkSimpleId "U"] nullRange) 
    74                                       (Skip nullRange) nullRange) 
     59        -- Extract process equations only. 
     60        ext = extendedInfo accSig 
     61        ccsents = reverse $ ccSentences ext 
     62        -- Clean signature here 
     63        cleanSig = accSig 
     64                   { extendedInfo = ext { ccSentences = []}} 
     65    in Result (es ++ ds) $ 
     66      Just (cc, mkExtSign cleanSig, ccsents) 
    7567 
    7668ana_BASIC_CSP :: CspBasicSpec -> State CspCASLSign () 
     
    10294 
    10395-- | Statically analyse a CspCASL channel declaration. 
    104 anaChanDecl :: CHANNEL_DECL -> State CspCASLSign CHANNEL_DECL 
     96anaChanDecl :: CHANNEL_DECL -> State CspCASLSign () 
    10597anaChanDecl (ChannelDecl chanNames chanSort) = do 
    10698    checkSorts [chanSort] -- check channel sort is known 
     
    113105            , envDiags = vds 
    114106            } 
    115     return (ChannelDecl chanNames chanSort) 
     107    return () 
    116108 
    117109-- | Statically analyse a CspCASL channel name. 
     
    178170    sig <- get 
    179171    let ext = extendedInfo sig 
     172        ccsens = ccSentences ext 
    180173        procDecls = procSet ext 
    181174        prof = pn `Map.lookup` procDecls 
    182175    case prof of 
    183       -- Only analyse a process if its name (and thus profile) is known 
    184       Just (ProcProfile procArgs procAlpha) -> 
    185         do gVars <- anaProcVars pn procArgs vs -- compute global vars 
    186            termAlpha <- anaProcTerm proc gVars Map.empty 
    187            checkCommAlphaSub termAlpha procAlpha proc "process equation" 
    188            return () 
    189       Nothing -> 
    190         do addDiags [mkDiag Error "process equation for unknown process" pn] 
    191            return () 
    192     vds <- gets envDiags 
    193     put sig { envDiags = vds } 
     176         -- Only analyse a process if its name (and thus profile) is known 
     177         Just (ProcProfile procArgs procAlpha) -> 
     178             do  gVars <- anaProcVars pn procArgs vs -- compute global vars 
     179                 (termAlpha, fqProc) <- anaProcTerm proc (Map.fromList gVars) Map.empty 
     180                 checkCommAlphaSub termAlpha procAlpha proc "process equation" 
     181                 -- Save the diags from the checkCommAlphaSub 
     182                 vds <- gets envDiags 
     183                 -- put CspCASL Sentences back in to the state with new sentence 
     184                 put sig {envDiags = vds, extendedInfo = 
     185                          ext { ccSentences = 
     186                                -- BUG - What should the constituent 
     187                                -- alphabet be for this process? 
     188                                -- probably the same as the inner one! 
     189                                (makeNamed ("ProcHugo") 
     190                                               (ProcessEq pn gVars 
     191                                                          Set.empty 
     192                                                          fqProc)):ccsens 
     193                              } 
     194                         } 
     195                 return () 
     196         Nothing -> 
     197             do addDiags [mkDiag Error "process equation for unknown process" pn] 
     198                return () 
    194199    return () 
    195200 
    196201-- | Statically analyse a CspCASL process equation's global variable 
    197202-- names. 
    198 anaProcVars :: PROCESS_NAME -> [SORT] -> [VAR] -> State CspCASLSign ProcVarMap 
     203anaProcVars :: PROCESS_NAME -> [SORT] -> [VAR] -> State CspCASLSign ProcVarList 
    199204anaProcVars pn ss vs = do 
    200205    case (compare (length ss) (length vs)) of 
    201206       LT -> do addDiags [mkDiag Error "too many process arguments" pn] 
    202                 return Map.empty 
     207                return [] 
    203208       GT -> do addDiags [mkDiag Error "not enough process arguments" pn] 
    204                 return Map.empty 
    205        EQ -> Monad.foldM anaProcVar Map.empty (zip vs ss) 
     209                return [] 
     210       EQ -> Monad.foldM anaProcVar [] (zip vs ss) 
    206211 
    207212-- | Statically analyse a CspCASL process-global variable name. 
    208 anaProcVar :: ProcVarMap -> (VAR, SORT) -> State CspCASLSign ProcVarMap 
     213anaProcVar :: ProcVarList -> (VAR, SORT) -> State CspCASLSign ProcVarList 
    209214anaProcVar old (v, s) = do 
    210     if v `Map.member` old 
    211        then do addDiags [mkDiag Error "process arg declared more than once" v] 
     215    if v `elem` (map fst old) 
     216       then do addDiags [mkDiag Error "process argument declared more than once" v] 
    212217               return old 
    213        else return (Map.insert v s old) 
     218       else return (old ++ [(v, s)]) 
    214219 
    215220-- Static analysis of process terms 
    216221 
     222-- BUG in fucntion below 
     223-- not returing FQProcesses 
    217224-- | Statically analyse a CspCASL process term. 
     225--   The process that is returned is a fully qualified process. 
    218226anaProcTerm :: PROCESS -> ProcVarMap -> ProcVarMap -> 
    219                State CspCASLSign CommAlpha 
     227               State CspCASLSign (CommAlpha, PROCESS) 
    220228anaProcTerm proc gVars lVars = case proc of 
    221     NamedProcess name args _ -> 
     229    NamedProcess name args range -> 
    222230        do addDiags [mkDiag Debug "Named process" proc] 
    223231           al <- anaNamedProc proc name args (lVars `Map.union` gVars) 
    224            return al 
    225     Skip _ -> 
     232           return (al, 
     233                   FQProcess (NamedProcess name args range) al range) 
     234    Skip range -> 
    226235        do addDiags [mkDiag Debug "Skip" proc] 
    227            return S.empty 
    228     Stop _ -> 
     236           return (S.empty, 
     237                   FQProcess (Skip range) S.empty range) 
     238    Stop range -> 
    229239        do addDiags [mkDiag Debug "Stop" proc] 
    230            return S.empty 
    231     Div _ -> 
     240           return (S.empty, 
     241                   FQProcess (Stop range) S.empty range) 
     242    Div range -> 
    232243        do addDiags [mkDiag Debug "Div" proc] 
    233            return S.empty 
    234     Run es _ -> 
     244           return (S.empty, 
     245                   FQProcess (Div range) S.empty range) 
     246    Run es range -> 
    235247        do addDiags [mkDiag Debug "Run" proc] 
    236248           comms <- anaEventSet es 
    237            return comms 
    238     Chaos es _ -> 
     249           return (comms, 
     250                   FQProcess (Run es range) comms range) 
     251    Chaos es range -> 
    239252        do addDiags [mkDiag Debug "Chaos" proc] 
    240253           comms <- anaEventSet es 
    241            return comms 
    242     PrefixProcess e p _ -> 
     254           return (comms, 
     255                   FQProcess (Chaos es range) comms range) 
     256    PrefixProcess e p range -> 
    243257        do addDiags [mkDiag Debug "Prefix" proc] 
    244258           (evComms, rcvMap) <- anaEvent e (lVars `Map.union` gVars) 
    245            comms <- anaProcTerm p gVars (rcvMap `Map.union` lVars) 
    246            return (comms `S.union` evComms) 
    247     InternalPrefixProcess v s p _ -> 
     259           (comms, pFQTerm) <- anaProcTerm p gVars (rcvMap `Map.union` lVars) 
     260           return (comms `S.union` evComms, 
     261                   FQProcess (PrefixProcess e pFQTerm range) (comms `S.union` evComms) range) 
     262    InternalPrefixProcess v s p range -> 
    248263        do addDiags [mkDiag Debug "Internal prefix" proc] 
    249264           checkSorts [s] -- check sort is known 
    250            comms <- anaProcTerm p gVars (Map.insert v s lVars) 
    251            return (S.insert (CommTypeSort s) comms) 
    252     ExternalPrefixProcess v s p _ -> 
     265           (comms, pFQTerm) <- anaProcTerm p gVars (Map.insert v s lVars) 
     266           return (S.insert (CommTypeSort s) comms, 
     267                   FQProcess (InternalPrefixProcess v s pFQTerm range) (S.insert (CommTypeSort s) comms) range) 
     268    ExternalPrefixProcess v s p range -> 
    253269        do addDiags [mkDiag Debug "External prefix" proc] 
    254270           checkSorts [s] -- check sort is known 
    255            comms <- anaProcTerm p gVars (Map.insert v s lVars) 
    256            return (S.insert (CommTypeSort s) comms) 
    257     Sequential p q _ -> 
     271           (comms, pFQTerm) <- anaProcTerm p gVars (Map.insert v s lVars) 
     272           return (S.insert (CommTypeSort s) comms, 
     273                   FQProcess (ExternalPrefixProcess v s pFQTerm range) (S.insert (CommTypeSort s) comms) range) 
     274    Sequential p q range -> 
    258275        do addDiags [mkDiag Debug "Sequential" proc] 
    259            pComms <- anaProcTerm p gVars lVars 
    260            qComms <- anaProcTerm q gVars Map.empty 
    261            return (pComms `S.union` qComms) 
    262     InternalChoice p q _ -> 
     276           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
     277           (qComms, qFQTerm) <- anaProcTerm q gVars Map.empty 
     278           return (pComms `S.union` qComms, 
     279                   FQProcess (Sequential pFQTerm qFQTerm range) (pComms `S.union` qComms) range) 
     280    InternalChoice p q range -> 
    263281        do addDiags [mkDiag Debug "InternalChoice" proc] 
    264            pComms <- anaProcTerm p gVars lVars 
    265            qComms <- anaProcTerm q gVars lVars 
    266            return (pComms `S.union` qComms) 
    267     ExternalChoice p q _ -> 
     282           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
     283           (qComms, qFQTerm) <- anaProcTerm q gVars lVars 
     284           return (pComms `S.union` qComms, 
     285                   FQProcess (InternalChoice pFQTerm qFQTerm range) (pComms `S.union` qComms) range) 
     286    ExternalChoice p q range -> 
    268287        do addDiags [mkDiag Debug "ExternalChoice" proc] 
    269            pComms <- anaProcTerm p gVars lVars 
    270            qComms <- anaProcTerm q gVars lVars 
    271            return (pComms `S.union` qComms) 
    272     Interleaving p q _ -> 
     288           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
     289           (qComms, qFQTerm) <- anaProcTerm q gVars lVars 
     290           return (pComms `S.union` qComms, 
     291                   FQProcess (ExternalChoice pFQTerm qFQTerm range) (pComms `S.union` qComms) range) 
     292    Interleaving p q range -> 
    273293        do addDiags [mkDiag Debug "Interleaving" proc] 
    274            pComms <- anaProcTerm p gVars lVars 
    275            qComms <- anaProcTerm q gVars lVars 
    276            return (pComms `S.union` qComms) 
    277     SynchronousParallel p q _ -> 
     294           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
     295           (qComms, qFQTerm) <- anaProcTerm q gVars lVars 
     296           return (pComms `S.union` qComms, 
     297                   FQProcess (Interleaving pFQTerm qFQTerm range) (pComms `S.union` qComms) range) 
     298    SynchronousParallel p q range -> 
    278299        do addDiags [mkDiag Debug "Synchronous" proc] 
    279            pComms <- anaProcTerm p gVars lVars 
    280            qComms <- anaProcTerm q gVars lVars 
    281            return (pComms `S.union` qComms) 
    282     GeneralisedParallel p es q _ -> 
     300           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
     301           (qComms, qFQTerm) <- anaProcTerm q gVars lVars 
     302           return (pComms `S.union` qComms, 
     303                   FQProcess (SynchronousParallel pFQTerm qFQTerm range) (pComms `S.union` qComms) range) 
     304    GeneralisedParallel p es q range -> 
    283305        do addDiags [mkDiag Debug "Generalised parallel" proc] 
    284            pComms <- anaProcTerm p gVars lVars 
     306           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
    285307           synComms <- anaEventSet es 
    286            qComms <- anaProcTerm q gVars lVars 
    287            return (S.unions [pComms, qComms, synComms]) 
    288     AlphabetisedParallel p esp esq q _ -> 
     308           (qComms, qFQTerm) <- anaProcTerm q gVars lVars 
     309           return (S.unions [pComms, qComms, synComms], 
     310                   FQProcess (GeneralisedParallel pFQTerm es qFQTerm range) (S.unions [pComms, qComms, synComms]) range) 
     311    AlphabetisedParallel p esp esq q range -> 
    289312        do addDiags [mkDiag Debug "Alphabetised parallel" proc] 
    290            pComms <- anaProcTerm p gVars lVars 
     313           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
    291314           pSynComms <- anaEventSet esp 
    292315           checkCommAlphaSub pSynComms pComms proc 
    293316                                 "alphabetised parallel, left" 
    294317           qSynComms <- anaEventSet esq 
    295            qComms <- anaProcTerm q gVars lVars 
     318           (qComms, qFQTerm) <- anaProcTerm q gVars lVars 
    296319           checkCommAlphaSub qSynComms qComms proc 
    297320                                 "alphabetised parallel, right" 
    298            return (pComms `S.union` qComms) 
    299     Hiding p es _ -> 
     321           return (pComms `S.union` qComms, 
     322                   FQProcess (AlphabetisedParallel pFQTerm esp esq qFQTerm range) (pComms `S.union` qComms) range) 
     323    Hiding p es range -> 
    300324        do addDiags [mkDiag Debug "Hiding" proc] 
    301            pComms <- anaProcTerm p gVars lVars 
     325           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
    302326           hidComms <- anaEventSet es 
    303            return (pComms `S.union` hidComms) 
    304     RenamingProcess p r _ -> 
     327           return (pComms `S.union` hidComms, 
     328                   FQProcess (Hiding pFQTerm es range) (pComms `S.union` hidComms) range) 
     329    RenamingProcess p r range -> 
    305330        do addDiags [mkDiag Debug "Renaming" proc] 
    306            pComms <- anaProcTerm p gVars lVars 
     331           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
    307332           renAlpha <- anaRenaming r 
    308            return (pComms `S.union` renAlpha) 
    309     ConditionalProcess f p q _ -> 
     333           return (pComms `S.union` renAlpha, 
     334                   FQProcess (RenamingProcess pFQTerm r range) (pComms `S.union` renAlpha) range) 
     335    ConditionalProcess f p q range -> 
    310336        do addDiags [mkDiag Debug "Conditional" proc] 
    311            pComms <- anaProcTerm p gVars lVars 
    312            qComms <- anaProcTerm q gVars lVars 
     337           (pComms, pFQTerm) <- anaProcTerm p gVars lVars 
     338           (qComms, qFQTerm) <- anaProcTerm q gVars lVars 
     339           -- mfs is the fully qualified formula version of f 
    313340           mfs <- anaFormulaCspCASL (gVars `Map.union` lVars) f 
     341           addDiags [mkDiag Debug "Formula" f] 
     342           addDiags [mkDiag Debug "FQFormula" (Maybe.fromJust mfs)] 
    314343           let fComms = case mfs of 
    315344                          Nothing -> S.empty 
    316345                          Just fs -> formulaComms fs 
    317            return (S.unions [pComms, qComms, fComms]) 
     346           return (S.unions [pComms, qComms, fComms], 
     347                   FQProcess (ConditionalProcess (Maybe.fromJust mfs) pFQTerm qFQTerm range) 
     348                                 (S.unions [pComms, qComms, fComms]) range) 
    318349 
    319350-- | Statically analyse a CspCASL "named process" term. 
     
    582613        ga = globAnnos sig 
    583614        mix = emptyMix { mixRules = makeRules ga allIds } 
    584     resF <- resolveFormula (putParen mix) (mixResolve mix) 
    585                  ga (mixRules mix) frm 
     615    resF <- resolveFormula (putParen mix) (mixResolve mix) ga (mixRules mix) frm 
    586616    minExpFORMULA (const return) sig resF 
    587617 
  • trunk/CspCASL/Trans_Consts.hs

    r10619 r11215  
    1919 
    2020import CASL.AS_Basic_CASL 
     21import CspCASL.AS_CspCASL_Process (PROCESS_NAME) 
    2122import Isabelle.IsaConsts 
    2223import Isabelle.IsaSign 
     24import Isabelle.Translate(showIsaTypeT) 
    2325 
     26-- Name for the PreAlphabet 
     27preAlphabetS :: String 
     28preAlphabetS = "PreAlphabet" 
     29 
     30-- Type for the PreAlphabet 
     31preAlphabetType :: Typ 
     32preAlphabetType = Type {typeId = preAlphabetS, 
     33                        typeSort = [], 
     34                        typeArgs =[]} 
     35 
     36-- Name for the Alphabet 
    2437alphabetS :: String 
    2538alphabetS = "Alphabet" 
    2639 
     40-- Type for the Alphabet 
     41alphabetType :: Typ 
     42alphabetType = Type {typeId = alphabetS, 
     43                     typeSort = [], 
     44                     typeArgs =[]} 
     45 
     46-- Name for IsabelleHOL quot type 
     47quotS :: String 
     48quotS = "quot" 
     49 
     50-- Type for preAlphabet quot 
     51preAlphabetQuotType :: Typ 
     52preAlphabetQuotType = Type {typeId = quotS, 
     53                            typeSort = [], 
     54                            typeArgs =[preAlphabetType]} 
     55 
     56-- Name for the datatype of process names 
     57procNameS :: String 
     58procNameS = "ProcName" 
     59 
     60-- Type for the datatype of process names 
     61procNameType :: Typ 
     62procNameType = Type {typeId = procNameS, 
     63                     typeSort = [], 
     64                     typeArgs =[]} 
     65 
     66-- name for CspProvers ('pn, 'a) proc type 
     67procS :: String 
     68procS = "proc" 
     69 
     70-- Type for (ProcName,Alpahbet) proc 
     71cCProverProcType :: Typ 
     72cCProverProcType = Type {typeId = procS, 
     73                         typeSort = [], 
     74                         typeArgs =[procNameType, alphabetType]} 
     75 
     76-- Name for the function for mapping process names to real processes 
     77procMapS :: String 
     78procMapS = "ProcMap" 
     79 
     80-- Type for the function for mapping process names to real processes 
     81procMapType :: Typ 
     82procMapType = mkFunType procNameType cCProverProcType 
     83 
    2784barExtS :: String 
    2885barExtS = "_Bar" 
     86 
     87baseSign :: BaseSig 
     88baseSign = Main_thy 
    2989 
    3090classS :: String 
     
    3696-- Convert a SORT to a string 
    3797convertSort2String :: SORT -> String 
    38 convertSort2String s = show s 
     98convertSort2String s = showIsaTypeT s baseSign 
     99 
     100convertProcessName2String :: PROCESS_NAME -> String 
     101convertProcessName2String pn = (show pn) 
  • 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