Commit 5c76cb00 authored by Gilles Coremans's avatar Gilles Coremans
Browse files

Fix some bad variable generation

parent 447454b0
......@@ -258,14 +258,6 @@ generatorFunctions (nsd, sd, _, _) =
(VarParam "env" : params, AltExpr (FnCall (sname ++ "UpToSize") (VarExpr "env" : replaceArg (Minus (VarExpr ("n" ++ sname)) (IntExpr 1)) args))
(FnCall (sname ++ "OfSize") (VarExpr "env" : args)))],
Fn (sname ++ "Env") -- Function to 'cast' the contexts of one sort to another by discarding variables not in the target sort's contexts
([([ConstrParam ("S" ++ nsname) [VarParam "next"]],
ConstrInst ("S" ++ nsname) [FnCall (sname ++ "Env") [VarExpr "next"]]) | nsname <- map xnamespace ctxs]
++ [([ConstrParam ("S" ++ nsname) [VarParam "next"]],
FnCall (sname ++ "Env") [VarExpr "next"]) | nsname <- filter (not . flip elem (map xnamespace ctxs)) (map nname nsd)]
++ [([ConstrParam "Z" []],
ConstrInst "Z" [])]),
Fn ("for" ++ sname ++ "WithSize") -- Wrapper for QuickCheck's forAll
[(VarParam "env" : params ++ [VarParam "prop"],
LetExpr [(VarParam "c", FnCall (sname ++ "OfSize") $ VarExpr "env" : args),
......@@ -314,7 +306,7 @@ generatorFunctions (nsd, sd, _, _) =
-- Use the binder and the attributes of a ctor to determine the environment to be passed to subcombles
envFor :: NamespaceName -> (IdenName, SortName) -> [AttributeDef] -> Expression
envFor binder (iden, name) allAttrs = FnCall (name ++ "Env") [envexpr attrs]
envFor binder (iden, name) allAttrs = envexpr attrs
where
envexpr ((_, RightAdd{}):as) = ConstrInst ("S" ++ binder) [VarExpr "env"]
envexpr (_:as) = envexpr as
......@@ -376,23 +368,18 @@ generatorFunctions (nsd, sd, _, _) =
getVarGenFunctions :: Language -> [Function]
getVarGenFunctions (nsd, _, _, _) =
Fn "reverseVar"
(([ConstrParam "Z" [], VarParam "res"], VarExpr "res")
: map (\MkNameSpace{nname=name, nsort=sort} ->
([ConstrParam ("S" ++ name) [VarParam "next"], VarParam "res"], FnCall "reverseVar" [VarExpr "next", ConstrInst ("S" ++ name) [VarExpr "res"]])
) nsd)
: map (\n ->
let constrName = "S" ++ nname n
funName = "get" ++ nname n
in Fn funName $
[([ConstrParam "Z" [] , VarParam "_"] , FnCall "empty" []),
([ConstrParam constrName [VarParam "next"], VarParam "abs"], AltExpr (FnCall "pure" [FnCall "reverseVar" [VarExpr "abs", ConstrInst "Z" []]])
(FnCall funName [VarExpr "next", ConstrInst constrName [VarExpr "abs"]]))]
++ map (\other ->
let otherCName = "S" ++ nname other
in ([ConstrParam otherCName [VarParam "next"], VarParam "abs"], FnCall funName [VarExpr "next", ConstrInst otherCName [VarExpr "abs"]])
) (filter (/= n) nsd)
) nsd
map (\n ->
let constrName = "S" ++ nname n
funName = "get" ++ nname n
in Fn funName $
[([ConstrParam "Z" [] , VarParam "_"] , FnCall "empty" []),
([ConstrParam constrName [VarParam "next"], VarParam "abs"], AltExpr (FnCall "pure" [VarExpr "abs"])
(FnCall funName [VarExpr "next", ConstrInst constrName [VarExpr "abs"]]))]
++ map (\other ->
let otherCName = "S" ++ nname other
in ([ConstrParam otherCName [VarParam "next"], VarParam "abs"], FnCall funName [VarExpr "next", ConstrInst otherCName [VarExpr "abs"]])
) (filter (/= n) nsd)
) nsd
_getCtorParams :: ConstructorDef -> [Parameter]
_getCtorParams (MkVarConstructor consName _) = [ConstrParam consName [VarParam "var"]]
......
Markdown is supported
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