Commit 59fed1ca authored by marton bognar's avatar marton bognar
Browse files

Fix the way of determining necessary substitution calls

parent 5b963923
......@@ -83,3 +83,9 @@ attrsByIden ctor = [
-- | Drops the third element from each tuple in a list
dropFold :: [(String, String, String)] -> [(String, String)]
dropFold = map (\(a, b, _) -> (a, b))
-- | Determines if a given sort has a context for another sort
sortHasCtxForSort :: SortName -> SortName -> [NamespaceDef] -> [(SortName, [Context])] -> Bool
sortHasCtxForSort sortName ctxSort nsd ctxsBySname
= let ctxs = [INH x y | INH x y <- fromJust (lookup sortName ctxsBySname)]
in any (\ctx -> sortNameForNamespaceName (xnamespace ctx) nsd == ctxSort) ctxs
......@@ -8,6 +8,7 @@ import Utility
import Data.Maybe
import Data.List
import Debug.Trace
getFunctions :: ConvertFunctions
getFunctions
......@@ -190,7 +191,7 @@ substFunctionsC (nsd, sd, _, _) =
-- | Construct a mapping function call for an identifier
substCallForIden :: (IdenName, [AttributeDef]) -> Expression
substCallForIden (iden, idenAttrs)
| sortHasCtxForSort (sortNameForIden iden ctor) sortName
| sortHasCtxForSort (sortNameForIden iden ctor) sortOfCtxNamespace nsd ctxsBySname
= if fromJust (lookup sortNameOfIden varAccessBySname)
then if iden `elem` map fst folds
then FnCall "fmap" [FnCall fnName substParams, idenExpr]
......@@ -206,8 +207,3 @@ substFunctionsC (nsd, sd, _, _) =
else varReplaceCall ctor [VarExpr "b", head binder] iden
substParams = [VarExpr "orig", VarExpr "sub"]
sortNameOfIden = sortNameForIden iden ctor
sortHasCtxForSort :: SortName -> SortName -> Bool
sortHasCtxForSort sortName ctxSort
= let ctxs = [INH x y | INH x y <- fromJust (lookup sortName ctxsBySname)]
in any (\ctx -> sortNameForNamespaceName (xnamespace ctx) nsd == ctxSort) ctxs
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment