-
Notifications
You must be signed in to change notification settings - Fork 21
Rigid casl #1845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Rigid casl #1845
Changes from all commits
8d79d48
b7bf3cf
b2e91a6
36b782c
a9a3a5a
39961e8
cd51df4
b5c0683
03b904d
c75dcab
ac440ad
985eaa6
56cb8d8
2e33122
286c44e
7f7a727
b40bd6e
8165faa
ba8aa45
75b0e77
50ce830
fdbaf1e
53009fc
5ad946f
6b05a92
097ee15
e28bd7c
c02dfe7
e679808
e33cb01
a0d100c
c8da879
1c09dde
10eca5a
496d409
31f3b92
2ad6c9d
ae008d7
eb33124
7b1b640
6df4af0
64ba88c
61f36a8
a547a9a
84272ef
6cf1945
45da381
ca94f27
0afafa0
51d8256
b58b23e
a582b79
6167989
7db9a2f
f9c9ff1
bb06f8c
f0e5728
68851f0
b0fdcdd
9ac66b6
7fcbb3c
c6e5ee0
8dd9855
515af0d
493f693
226e6fb
6211fd2
68ecbb6
32c0310
16ccc5e
bffde05
3776d95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ import Common.DocUtils | |
| import Data.Data | ||
| import Data.Maybe (fromMaybe) | ||
| import Data.List (isPrefixOf) | ||
| import Control.Monad (when, unless) | ||
| import Control.Monad (when, unless, foldM) | ||
|
|
||
| -- constants have empty argument lists | ||
| data OpType = OpType {opKind :: OpKind, opArgs :: [SORT], opRes :: SORT} | ||
|
|
@@ -81,6 +81,15 @@ symbolKind t = case t of | |
| PredAsItemType _ -> Preds_kind | ||
| _ -> Sorts_kind | ||
|
|
||
| extSymbolKind :: SymbType -> String | ||
| extSymbolKind t = case t of | ||
| OpAsItemType (OpType k l _) -> | ||
| case (k, l) of | ||
| (Total, []) -> "const" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about partial constants? Should they really lead to "op"? |
||
| _ -> "op" | ||
| PredAsItemType _ -> "pred" | ||
| _ -> "sort" | ||
|
|
||
| data Symbol = Symbol {symName :: Id, symbType :: SymbType} | ||
| deriving (Show, Eq, Ord, Typeable, Data) | ||
|
|
||
|
|
@@ -591,8 +600,16 @@ addSymbToSign sig sy = | |
| PredAsItemType pt -> return $ addPred' sig' n pt | ||
| OpAsItemType ot -> return $ addOp' sig' n ot | ||
|
|
||
| addNomsToSign :: Sign e f -> Set.Set Id -> Result (Sign e f) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment documenting the function (I won' repeat this comment for other functions). |
||
| addNomsToSign sig noms = do | ||
| -- add a fake sort for nominals | ||
| sig0 <- addSymbToSign sig $ Symbol (genName "ST") SortAsItemType | ||
| sig' <- foldM (\aSig nom -> addSymbToSign aSig $ Symbol nom $ | ||
| PredAsItemType $ PredType []) | ||
| sig0 $ Set.toList noms | ||
| return sig' | ||
|
|
||
| -- The function below belong in a different file. But I put them here for now. | ||
| -- TODO: The function below belong in a different file. But I put them here for now. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the TODO should be resolved |
||
| -- dual of a quantifier | ||
|
|
||
| dualQuant :: QUANTIFIER -> QUANTIFIER | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,8 @@ import qualified Data.Set as Set | |
| import Data.Maybe | ||
| import Data.List | ||
|
|
||
| import Logic.SemConstr | ||
|
|
||
| checkPlaces :: [SORT] -> Id -> [Diagnosis] | ||
| checkPlaces args i = let n = placeCount i in | ||
| [mkDiag Error "wrong number of places" i | n > 0 && n /= length args ] | ||
|
|
@@ -869,6 +871,14 @@ anaTerm mef mixIn sign msrt pos t = do | |
| (\ srt -> Sorted_term resT srt pos) msrt | ||
| return (resT, anaT) | ||
|
|
||
| getAllIds :: (FormExtension f, TermExtension f) => | ||
| BASIC_SPEC b s f -> Mix b s f e -> Sign f e -> IdSets | ||
| getAllIds bs mix inSig = | ||
| unite $ ids_BASIC_SPEC (getBaseIds mix) (getSigIds mix) bs | ||
| : getExtIds mix (extendedInfo inSig) : | ||
| [mkIdSets (allConstIds inSig) (allOpIds inSig) | ||
| $ allPredIds inSig] | ||
|
|
||
| basicAnalysis :: (FormExtension f, TermExtension f) | ||
| => Min f e -- ^ type analysis of f | ||
| -> Ana b b s f e -- ^ static analysis of basic item b | ||
|
|
@@ -879,10 +889,7 @@ basicAnalysis :: (FormExtension f, TermExtension f) | |
| {- ^ (BS with analysed mixfix formulas for pretty printing, | ||
| differences to input Sig,accumulated Sig,analysed Sentences) -} | ||
| basicAnalysis mef anab anas mix (bs, inSig, ga) = | ||
| let allIds = unite $ ids_BASIC_SPEC (getBaseIds mix) (getSigIds mix) bs | ||
| : getExtIds mix (extendedInfo inSig) : | ||
| [mkIdSets (allConstIds inSig) (allOpIds inSig) | ||
| $ allPredIds inSig] | ||
| let allIds = getAllIds bs mix inSig | ||
| (newBs, accSig) = runState (ana_BASIC_SPEC mef anab anas | ||
| mix { mixRules = makeRules ga allIds } | ||
| bs) inSig { globAnnos = addAssocs inSig ga } | ||
|
|
@@ -908,15 +915,161 @@ basicCASLAnalysis = basicAnalysis (const return) (const return) | |
|
|
||
| -- | extra | ||
| cASLsen_analysis :: | ||
| (BASIC_SPEC () () (), Sign () (), FORMULA ()) -> Result (FORMULA ()) | ||
| (BASIC_SPEC () () (), Sign () (), FORMULA ()) -> | ||
| Result (FORMULA (), FORMULA ()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please document the purpose of returning two formulas |
||
| cASLsen_analysis (bs, s, f) = let | ||
| mix = emptyMix | ||
| allIds = unite $ | ||
| ids_BASIC_SPEC (getBaseIds mix) | ||
| (getSigIds mix) bs | ||
| : getExtIds mix (extendedInfo s) : | ||
| [mkIdSets (allConstIds s) (allOpIds s) | ||
| $ allPredIds s] | ||
| allIds = getAllIds bs mix s | ||
| mix' = mix { mixRules = makeRules emptyGlobalAnnos | ||
| allIds } | ||
| in liftM fst $ anaForm (const return) mix' s f | ||
| in anaForm (const return) mix' s f | ||
|
|
||
| -- | convert theory | ||
|
|
||
| convertCASLTheory :: (Sign f e, [Named (FORMULA f)]) -> BASIC_SPEC b s f | ||
| convertCASLTheory (sig, nsens) = | ||
| case (sig, nsens) of | ||
| (_, []) -> Basic_spec [] -- TODO: the sig should be empty | ||
| _ -> error "convert theory nyi for CASL logic" | ||
|
|
||
| -- | test nominal sen | ||
|
|
||
| isNominalSen :: Set.Set Id -> FORMULA f -> (Bool, Maybe Id) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it a good idea to represent nominals as mixfix formulas, which are usually only used in an intermediate stage an eliminated by static analysis? |
||
| isNominalSen noms aSen = | ||
| case aSen of | ||
| Mixfix_formula (Mixfix_token p) -> | ||
| let pId = simpleIdToId p | ||
| in if Set.member pId noms then (True, Just pId) else (False, Nothing) | ||
| _ -> (False, Nothing) | ||
|
|
||
| -- | CASL hybridization: constraints to CASL sentences | ||
|
|
||
| constrToSens :: Sign () () -> String -> SemanticConstraint -> | ||
| Result [Named (FORMULA ())] | ||
| constrToSens sig cname sc = | ||
| let | ||
| st = genName $ "ST_" ++ cname | ||
| domain = genName $ "domain_" ++ cname | ||
| defined = genName "defined" | ||
| (totals, partials) = partition (\(_, ot) -> opKind ot == Total) $ | ||
| MapSet.toPairList $ opMap sig | ||
| in | ||
| case sc of | ||
| SameInterpretation "sort" -> | ||
| return $ | ||
| map (\s -> makeNamed ("ga_sem_constr_"++show s) | ||
| $ mkForall [mkVarDecl (genToken "w1") st, | ||
| mkVarDecl (genToken "w2") st, | ||
| mkVarDecl (genToken "x") s] | ||
| $ mkEqv | ||
| (mkPredication | ||
| (mkQualPred domain $ Pred_type [st, s] nullRange) | ||
| [Qual_var (genToken "w1") st nullRange, | ||
| Qual_var (genToken "x") s nullRange]) | ||
| (mkPredication | ||
| (mkQualPred domain $ Pred_type [st, s] nullRange) | ||
| [Qual_var (genToken "w2") st nullRange, | ||
| Qual_var (genToken "x") s nullRange]) | ||
| ) | ||
| $ Set.toList $ sortSet sig | ||
| SameInterpretation "const" -> error "nyi for const" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo? |
||
| SameInterpretation "op" -> | ||
| let | ||
| xs ot = zip (opArgs ot) [1::Int ..] | ||
| extOt i ot = Qual_op_name | ||
| i | ||
| (Op_type Total (st:opArgs ot) (opRes ot) nullRange) | ||
| nullRange | ||
| in return $ | ||
| map (\(i,ot) -> makeNamed ("ga_sem_constr_" ++ show i) | ||
| $ mkForall | ||
| ( [mkVarDecl (genToken "w1") st, | ||
| mkVarDecl (genToken "w2") st] | ||
| ++ | ||
| (map (\(si, ii) -> | ||
| mkVarDecl (genToken $ "x" ++ show ii) si) $ xs ot) | ||
| ) | ||
| $ mkStEq | ||
| (mkAppl (extOt i ot) $ map (\(a,b) -> mkVarTerm a b) $ | ||
| (genToken "w1", st): | ||
| (map (\(si, ii) -> (genToken $ "x" ++ show ii, si)) $ | ||
| xs ot)) | ||
| (mkAppl (extOt i ot) $ map (\(a,b) -> mkVarTerm a b) $ | ||
| (genToken "w2", st): | ||
| (map (\(si, ii) -> (genToken $ "x" ++ show ii, si)) $ | ||
| xs ot)) | ||
| ) totals | ||
| SameInterpretation "pred" -> | ||
| let | ||
| xs pt = zip (predArgs pt) [1::Int ..] | ||
| extPt (Pred_type ss r) = Pred_type (st:ss) r | ||
| in return $ | ||
| map (\(i, pt) -> makeNamed ("ga_sem_constr_" ++ show i) $ | ||
| mkForall | ||
| ( [mkVarDecl (genToken "w1") st, | ||
| mkVarDecl (genToken "w2") st] | ||
| ++ | ||
| (map (\(si, ii) -> | ||
| mkVarDecl (genToken $ "x" ++ show ii) si) | ||
| $ xs pt) | ||
| ) | ||
| $ mkEqv | ||
| (mkPredication | ||
| (mkQualPred i $ extPt $ toPRED_TYPE pt) $ | ||
| map (\(a,b) -> mkVarTerm a b) $ | ||
| (genToken "w1", st): | ||
| (map (\(si, ii) -> | ||
| (genToken $ "x" ++ show ii, si)) | ||
| $ xs pt)) | ||
| (mkPredication | ||
| (mkQualPred i $ extPt $ toPRED_TYPE pt) $ | ||
| map (\(a,b) -> mkVarTerm a b) $ | ||
| (genToken "w2", st): | ||
| (map (\(si, ii) -> | ||
| (genToken $ "x" ++ show ii, si)) | ||
| $ xs pt)) | ||
| ) $ MapSet.toPairList $ predMap sig | ||
| SameDomain False -> let | ||
| xs ot = zip (opArgs ot) [1::Int ..] | ||
| extOt i ot = Qual_op_name | ||
| i | ||
| (Op_type Total (st:opArgs ot) (opRes ot) nullRange) | ||
| nullRange | ||
| in return $ | ||
| map (\(i,ot) -> makeNamed ("ga_sem_constr_" ++ show i) | ||
| $ mkForall | ||
| ( [mkVarDecl (genToken "w1") st, | ||
| mkVarDecl (genToken "w2") st] | ||
| ++ | ||
| (map (\(si, ii) -> | ||
| mkVarDecl (genToken $ "x" ++ show ii) si) | ||
| $ xs ot) | ||
| ) | ||
| $ mkEqv | ||
| (mkPredication | ||
| (mkQualPred defined $ | ||
| Pred_type [st, opRes ot] nullRange) $ | ||
| [mkVarTerm (genToken "w1") st, | ||
| mkAppl (extOt i ot) $ | ||
| map (\(a,b) -> mkVarTerm a b) $ | ||
| (genToken "w1", st): | ||
| (map (\(si, ii) -> | ||
| (genToken $ "x" ++ show ii, si)) | ||
| $ xs ot) | ||
| ] | ||
| ) | ||
| (mkPredication | ||
| (mkQualPred defined $ | ||
| Pred_type [st, opRes ot] nullRange) $ | ||
| [mkVarTerm (genToken "w2") st, | ||
| mkAppl (extOt i ot) $ | ||
| map (\(a,b) -> mkVarTerm a b) $ | ||
| (genToken "w2", st): | ||
| (map (\(si, ii) -> | ||
| (genToken $ "x" ++ show ii, si)) | ||
| $ xs ot) | ||
| ] | ||
| ) | ||
| ) | ||
| partials | ||
| _ -> error $ "Constraint not supported for CASL logic:" ++ show sc | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is kind
sortassumed here?