Skip to content

Commit

Permalink
Support map composition #108
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwvj committed Oct 18, 2017
1 parent 6c440d7 commit d45fd36
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ColTrans extends DepthFirstAnalysisCAdaptor implements IApplyAssist
public static final String MAP_RES_RNG_TO = "vdmMapRngRestrictTo";
public static final String MAP_RES_RNG_BY = "vdmMapRngRestrictBy";
public static final String MAP_ITERATE = "vdmMapIterate";
public static final String MAP_COMP = "vdmMapCompose";

private TransAssistantIR assist;

Expand Down Expand Up @@ -292,6 +293,12 @@ public void caseAMapIterationBinaryExpIR(AMapIterationBinaryExpIR node) throws A
rewriteToApply(this, node, MAP_ITERATE, node.getLeft(), node.getRight());
}

@Override
public void caseACompBinaryExpIR(ACompBinaryExpIR node) throws AnalysisException {

rewriteToApply(this, node, MAP_COMP, node.getLeft(), node.getRight());
}

private void rewriteColEnumToApply(SExpIR node, String seqVar, List<SExpIR> members)
throws AnalysisException {
AExternalTypeIR extType = new AExternalTypeIR();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public void initNames()
gcNames.put(ColTrans.MAP_RES_RNG_TO, "vdmMapRngRestrictToGC");
gcNames.put(ColTrans.MAP_RES_RNG_BY, "vdmMapRngRestrictByGC");
gcNames.put(ColTrans.MAP_ITERATE, "vdmMapIterateGC");
gcNames.put(ColTrans.MAP_COMP, "vdmMapComposeGC");

// Tuples
gcNames.put(TupleTrans.TUPLE_EXP, "newProductVarGC");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ TEST_F(TestFlowFunctions, mapIterate)
{
CHECK(CLASS_ExpressionMap__Z12mapIterationEV);
}

TEST_F(TestFlowFunctions, mapComp)
{
CHECK(CLASS_ExpressionMap__Z7mapCompEV);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ mapRestrictRngBy () == {1 |-> 2, 2 |-> 3} :-> {3} = {1 |-> 2};
public mapIteration : () -> bool
mapIteration () == {1 |-> 2, 2 |-> 1, 3 |-> 4, 4 |-> 3} ** 2 = {1 |-> 1, 2 |-> 2, 3 |-> 3, 4 |-> 4};

public mapComp : () -> bool
mapComp () == ({2 |-> 20, 4 |-> 40, 6 |-> 60} comp {1 |-> 2, 3 |-> 4, 5 |-> 6}) = {1 |-> 20, 3 |-> 40, 5 |-> 60};

end ExpressionMap

0 comments on commit d45fd36

Please sign in to comment.