Changeset 11213

Show
Ignore:
Timestamp:
03.01.2009 21:00:05 (11 months ago)
Author:
maeder
Message:

extended static symbol map checking

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/CASL/Morphism.hs

    r11203 r11213  
    7979 
    8080mapOpTypeK :: Sort_map -> OpKind -> OpType -> OpType 
    81 mapOpTypeK sorts k t = makeTotal k $ mapOpType sorts t 
     81mapOpTypeK sorts k = makeTotal k . mapOpType sorts 
    8282 
    8383makeTotal :: OpKind -> OpType -> OpType 
     
    120120 
    121121symbolToRaw :: Symbol -> RawSymbol 
    122 symbolToRaw sym = ASymbol sym 
     122symbolToRaw = ASymbol 
    123123 
    124124idToRaw :: Id -> RawSymbol 
    125 idToRaw x = AKindedSymb Implicit x 
     125idToRaw = AKindedSymb Implicit 
    126126 
    127127rawSymName :: RawSymbol -> Id 
     
    141141    in Set.unions [sorts, ops, preds] 
    142142 
     143checkSymbList :: [SYMB_OR_MAP] -> [Diagnosis] 
     144checkSymbList 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 
    143151statSymbMapItems :: [SYMB_MAP_ITEMS] -> Result RawSymbolMap 
    144152statSymbMapItems 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 
    153156      insertRsys m1 (rsy1, rsy2) = case Map.lookup rsy1 m1 of 
    154157          Nothing -> return $ Map.insert rsy1 rsy2 m1 
    155           Just rsy3 -> 
     158          Just rsy3 -> if rsy2 == rsy3 then return m1 else 
    156159              plain_error m1 ("Symbol " ++ showDoc rsy1 " mapped twice to " 
    157160                ++ showDoc rsy2 " and " ++ showDoc rsy3 "") nullRange 
     
    159162  foldM insertRsys Map.empty (concat ls) 
    160163 
    161 symbOrMapToRaw :: SYMB_KIND -> SYMB_OR_MAP -> Result (RawSymbol, RawSymbol) 
     164symbOrMapToRaw :: SYMB_KIND -> SYMB_OR_MAP -> Result [(RawSymbol, RawSymbol)] 
    162165symbOrMapToRaw k sm = do 
    163166  case sm of 
    164167    Symb s -> do 
    165168      v <- symbToRaw k s 
    166       return (v, v) 
     169      return [(v, v)] 
    167170    Symb_map s t _ -> do 
    168171      appendDiags $ case (s, t) of 
     
    172175      w <- symbToRaw k s 
    173176      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)] 
    175193 
    176194statSymbItems :: [SYMB_ITEMS] -> Result [RawSymbol] 
    177195statSymbItems 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 
    185198        mapM (symbToRaw kind) l 
    186199  in fmap concat (mapM st sl) 
     
    226239  sort_map1 = Set.fold mapMSort Map.empty (sortSet sigma1) 
    227240  mapMSort s m = 
    228     case Map.lookup (Symbol {symName = s, symbType = SortAsItemType}) smap 
     241    case Map.lookup Symbol {symName = s, symbType = SortAsItemType} smap 
    229242    of Just sym -> let t = symName sym in if s == t then m else 
    230243                           Map.insert s t m 
     
    234247  mapOp i ots m = Set.fold (insOp i) m ots 
    235248  insOp i ot m = 
    236     case Map.lookup (Symbol {symName = i, symbType = OpAsItemType ot}) smap 
     249    case Map.lookup Symbol {symName = i, symbType = OpAsItemType ot} smap 
    237250    of Just sym -> let j = symName sym in case symbType sym of 
    238251         OpAsItemType oty -> let k = opKind oty in 
     
    243256  mapPred i pts m = Set.fold (insPred i) m pts 
    244257  insPred i pt m = 
    245     case Map.lookup (Symbol {symName = i, symbType = PredAsItemType pt}) smap 
     258    case Map.lookup Symbol {symName = i, symbType = PredAsItemType pt} smap 
    246259    of Just sym -> let j = symName sym in  case symbType sym of 
    247260         PredAsItemType _ -> if i == j then m else Map.insert (i, pt) j m 
     
    348361        legalOpType t = legalSort (opRes t) 
    349362                        && all legalSort (opArgs t) 
    350         legalPredType t = all legalSort (predArgs t) 
     363        legalPredType = all legalSort . predArgs 
    351364 
    352365-- | the image of a signature morphism 
     
    367380 
    368381inducedOpMap :: Sort_map -> Op_map -> OpMap -> OpMap 
    369 inducedOpMap sm fm os = Map.foldWithKey 
     382inducedOpMap sm fm = Map.foldWithKey 
    370383  ( \ i -> flip $ Set.fold ( \ ot -> 
    371384      let (j, nt) = mapOpSym sm fm (i, ot) 
    372       in Rel.setInsert j nt)) Map.empty os 
     385      in Rel.setInsert j nt)) Map.empty 
    373386 
    374387inducedPredMap :: Sort_map -> Pred_map -> Map.Map Id (Set.Set PredType) 
    375388               -> Map.Map Id (Set.Set PredType) 
    376 inducedPredMap sm pm ps = Map.foldWithKey 
     389inducedPredMap sm pm = Map.foldWithKey 
    377390  ( \ i -> flip $ Set.fold ( \ ot -> 
    378391      let (j, nt) = mapPredSym sm pm (i, ot) 
    379       in Rel.setInsert j nt)) Map.empty ps 
     392      in Rel.setInsert j nt)) Map.empty 
    380393 
    381394legalMor :: Morphism f e m -> Bool