Changeset 11213
- Timestamp:
- 03.01.2009 21:00:05 (11 months ago)
- Files:
-
- 1 modified
-
trunk/CASL/Morphism.hs (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CASL/Morphism.hs
r11203 r11213 79 79 80 80 mapOpTypeK :: Sort_map -> OpKind -> OpType -> OpType 81 mapOpTypeK sorts k t = makeTotal k $ mapOpType sorts t81 mapOpTypeK sorts k = makeTotal k . mapOpType sorts 82 82 83 83 makeTotal :: OpKind -> OpType -> OpType … … 120 120 121 121 symbolToRaw :: Symbol -> RawSymbol 122 symbolToRaw sym = ASymbol sym122 symbolToRaw = ASymbol 123 123 124 124 idToRaw :: Id -> RawSymbol 125 idToRaw x = AKindedSymb Implicit x125 idToRaw = AKindedSymb Implicit 126 126 127 127 rawSymName :: RawSymbol -> Id … … 141 141 in Set.unions [sorts, ops, preds] 142 142 143 checkSymbList :: [SYMB_OR_MAP] -> [Diagnosis] 144 checkSymbList l = case l of 145 Symb (Symb_id a) : Symb (Qual_id b t _) : r -> mkDiag Warning 146 ("profile '" ++ showDoc t "' does not apply to '" 147 ++ showId a "' but only to") b : checkSymbList r 148 _ : r -> checkSymbList r 149 [] -> [] 150 143 151 statSymbMapItems :: [SYMB_MAP_ITEMS] -> Result RawSymbolMap 144 152 statSymbMapItems sl = do 145 let check l = case l of 146 Symb (Symb_id _) : Symb (Qual_id b _ _) : r -> 147 mkDiag Warning "qualification only applies to" b : check r 148 _ : r -> check r 149 [] -> [] 150 st (Symb_map_items kind l _) = do 151 appendDiags $ check l 152 mapM (symbOrMapToRaw kind) l 153 let st (Symb_map_items kind l _) = do 154 appendDiags $ checkSymbList l 155 fmap concat $ mapM (symbOrMapToRaw kind) l 153 156 insertRsys m1 (rsy1, rsy2) = case Map.lookup rsy1 m1 of 154 157 Nothing -> return $ Map.insert rsy1 rsy2 m1 155 Just rsy3 -> 158 Just rsy3 -> if rsy2 == rsy3 then return m1 else 156 159 plain_error m1 ("Symbol " ++ showDoc rsy1 " mapped twice to " 157 160 ++ showDoc rsy2 " and " ++ showDoc rsy3 "") nullRange … … 159 162 foldM insertRsys Map.empty (concat ls) 160 163 161 symbOrMapToRaw :: SYMB_KIND -> SYMB_OR_MAP -> Result (RawSymbol, RawSymbol)164 symbOrMapToRaw :: SYMB_KIND -> SYMB_OR_MAP -> Result [(RawSymbol, RawSymbol)] 162 165 symbOrMapToRaw k sm = do 163 166 case sm of 164 167 Symb s -> do 165 168 v <- symbToRaw k s 166 return (v, v)169 return [(v, v)] 167 170 Symb_map s t _ -> do 168 171 appendDiags $ case (s, t) of … … 172 175 w <- symbToRaw k s 173 176 x <- symbToRaw k t 174 return (w, x) 177 let mkS = AKindedSymb Sorts_kind 178 case (s, t) of 179 (Qual_id _ t1 _, Qual_id _ t2 _) -> case (t1, t2) of 180 (O_type (Op_type k1 args1 res1 _), O_type (Op_type k2 args2 res2 _)) 181 | length args1 == length args2 && k2 <= k1 -> 182 return $ (w, x) : (mkS res1, mkS res2) 183 : zipWith (\ s1 s2 -> (mkS s1, mkS s2)) args1 args2 184 (P_type (Pred_type args1 _), P_type (Pred_type args2 _)) 185 | length args1 == length args2 -> 186 return $ (w, x) 187 : zipWith (\ s1 s2 -> (mkS s1, mkS s2)) args1 args2 188 (O_type (Op_type Partial [] res1 _), A_type s2) -> 189 return [(w, x), (mkS res1, mkS s2)] 190 _ -> fail $ "profiles '" ++ showDoc t1 "' and '" 191 ++ showDoc t2 "' do not match" 192 _ -> return [(w, x)] 175 193 176 194 statSymbItems :: [SYMB_ITEMS] -> Result [RawSymbol] 177 195 statSymbItems sl = 178 let check l = case l of 179 Symb_id _ : Qual_id b _ _ : r -> 180 mkDiag Warning "qualification in list only applies to" b : check r 181 _ : r -> check r 182 [] -> [] 183 st (Symb_items kind l _) = do 184 appendDiags $ check l 196 let st (Symb_items kind l _) = do 197 appendDiags $ checkSymbList $ map Symb l 185 198 mapM (symbToRaw kind) l 186 199 in fmap concat (mapM st sl) … … 226 239 sort_map1 = Set.fold mapMSort Map.empty (sortSet sigma1) 227 240 mapMSort s m = 228 case Map.lookup (Symbol {symName = s, symbType = SortAsItemType})smap241 case Map.lookup Symbol {symName = s, symbType = SortAsItemType} smap 229 242 of Just sym -> let t = symName sym in if s == t then m else 230 243 Map.insert s t m … … 234 247 mapOp i ots m = Set.fold (insOp i) m ots 235 248 insOp i ot m = 236 case Map.lookup (Symbol {symName = i, symbType = OpAsItemType ot})smap249 case Map.lookup Symbol {symName = i, symbType = OpAsItemType ot} smap 237 250 of Just sym -> let j = symName sym in case symbType sym of 238 251 OpAsItemType oty -> let k = opKind oty in … … 243 256 mapPred i pts m = Set.fold (insPred i) m pts 244 257 insPred i pt m = 245 case Map.lookup (Symbol {symName = i, symbType = PredAsItemType pt})smap258 case Map.lookup Symbol {symName = i, symbType = PredAsItemType pt} smap 246 259 of Just sym -> let j = symName sym in case symbType sym of 247 260 PredAsItemType _ -> if i == j then m else Map.insert (i, pt) j m … … 348 361 legalOpType t = legalSort (opRes t) 349 362 && all legalSort (opArgs t) 350 legalPredType t = all legalSort (predArgs t)363 legalPredType = all legalSort . predArgs 351 364 352 365 -- | the image of a signature morphism … … 367 380 368 381 inducedOpMap :: Sort_map -> Op_map -> OpMap -> OpMap 369 inducedOpMap sm fm os= Map.foldWithKey382 inducedOpMap sm fm = Map.foldWithKey 370 383 ( \ i -> flip $ Set.fold ( \ ot -> 371 384 let (j, nt) = mapOpSym sm fm (i, ot) 372 in Rel.setInsert j nt)) Map.empty os385 in Rel.setInsert j nt)) Map.empty 373 386 374 387 inducedPredMap :: Sort_map -> Pred_map -> Map.Map Id (Set.Set PredType) 375 388 -> Map.Map Id (Set.Set PredType) 376 inducedPredMap sm pm ps= Map.foldWithKey389 inducedPredMap sm pm = Map.foldWithKey 377 390 ( \ i -> flip $ Set.fold ( \ ot -> 378 391 let (j, nt) = mapPredSym sm pm (i, ot) 379 in Rel.setInsert j nt)) Map.empty ps392 in Rel.setInsert j nt)) Map.empty 380 393 381 394 legalMor :: Morphism f e m -> Bool