Changeset 11985

Show
Ignore:
Timestamp:
23.07.2009 16:40:58 (8 months ago)
Author:
maeder
Message:

allowed to derive more symbol maps

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/CASL/SymbolMapAnalysis.hs

    r11824 r11985  
    357357        pos = concatMapRange getRange $ Map.keys rmap 
    358358    in if isOk res then res else 
    359        let filt = Set.filter $ (== SortAsItemType) . symbType 
    360            ss2 = filt sy2 
    361            ss1 = Set.filter (\ s -> not $ any (matches s) $ Map.keys rmap) 
    362                  $ Set.difference (filt sy1) ss2 
    363            prod = Set.size ss1 * Set.size ss2 
     359       let ss1 = Set.filter (\ s -> Set.null $ Set.filter (\ s2 -> 
     360                   compatibleSymbols True (s, s2)) sy2) 
     361             $ Set.filter (\ s -> not $ any (matches s) $ Map.keys rmap) 
     362                 $ sy1 
     363           prod = Set.size ss1 * Set.size sy2 
    364364       in if prod < 19 then 
    365365          case filter (isOk . fst) $ map (iftm . Map.union rmap . Map.fromList) 
     366            $ filter (all compatibleRawSymbs) 
    366367            $ combine (map ASymbol $ Set.toList ss1) 
    367             $ map ASymbol $ Set.toList ss2 of 
     368            $ map ASymbol $ Set.toList sy2 of 
    368369            [(r, m)] -> (if prod > 1 && Map.size m > 1 then warning else hint) 
    369370              () ("derived symbol map:\n" ++ showDoc m "") pos >> r 
     
    373374            [] -> res 
    374375          else warning () "too many possibilities for symbol maps" pos >> res 
     376 
     377compatibleSymbTypes :: (SymbType, SymbType) -> Bool 
     378compatibleSymbTypes p = case p of 
     379  (SortAsItemType, SortAsItemType) -> True 
     380  (OtherTypeKind s1, OtherTypeKind s2) -> s1 == s2 
     381  (OpAsItemType t1, OpAsItemType t2) -> 
     382     length (opArgs t1) == length (opArgs t2) 
     383  (PredAsItemType p1, PredAsItemType p2) -> 
     384      length (predArgs p1) == length (predArgs p2) 
     385  _ -> False 
     386 
     387compatibleSymbols :: Bool -> (Symbol, Symbol) -> Bool 
     388compatibleSymbols alsoId (Symbol i1 k1, Symbol i2 k2) = 
     389  compatibleSymbTypes (k1, k2) && (not alsoId || i1 == i2) 
     390 
     391compatibleRawSymbs :: (RawSymbol, RawSymbol) -> Bool 
     392compatibleRawSymbs p = case p of 
     393  (ASymbol s1, ASymbol s2) -> compatibleSymbols False (s1, s2) 
     394  _ -> False -- irrelevant 
    375395 
    376396combine :: [a] -> [a] -> [[(a, a)]]