Skip to content

Commit

Permalink
Use transformation to emit "is" checks
Browse files Browse the repository at this point in the history
Currently, only is_nat is supported

Addresses #108
  • Loading branch information
peterwvj committed Oct 2, 2017
1 parent 31dc1ac commit c10cef4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public List<DepthFirstAnalysisAdaptor> consAnalyses()
*/
transformations.add(new NumericTrans(transAssistant));
transformations.add(new LogicTrans(transAssistant));
transformations.add(new IsCheckTrans(transAssistant));
transformations.add(new ColTrans(transAssistant));
transformations.add(new TupleTrans(transAssistant));
transformations.add(new LiteralInstantiationRewriteTrans(transAssistant));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public void initNames()
gcNames.put(NumericTrans.VDM_REM, "vdmRemGC");
gcNames.put(NumericTrans.VDM_MOD, "vdmModGC");
gcNames.put(NumericTrans.VDM_POW, "vdmPowerGC");


// "is" checks
gcNames.put(IsCheckTrans.VDM_IS_NAT, "isNatGC");

// Numeric comparison
gcNames.put(NumericTrans.VDM_GREATER_THAN, "vdmGreaterThanGC");
gcNames.put(NumericTrans.VDM_GREATER_OR_EQUAL, "vdmGreaterOrEqualGC");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.overture.codegen.vdm2c.transformations;

import org.overture.cgc.extast.analysis.DepthFirstAnalysisCAdaptor;
import org.overture.codegen.ir.analysis.AnalysisException;
import org.overture.codegen.ir.analysis.intf.IAnalysis;
import org.overture.codegen.ir.expressions.AGeneralIsExpIR;
import org.overture.codegen.ir.expressions.ANatIsExpIR;
import org.overture.codegen.trans.assistants.TransAssistantIR;
import org.overture.codegen.vdm2c.utils.CTransUtil;
import org.overture.codegen.vdm2c.utils.IApplyAssistant;

public class IsCheckTrans extends DepthFirstAnalysisCAdaptor implements IApplyAssistant {

public static final String VDM_IS_NAT = "isNat";

private TransAssistantIR assist;

public IsCheckTrans(TransAssistantIR assist)
{
this.assist = assist;
}

@Override
public void caseANatIsExpIR(ANatIsExpIR node) throws AnalysisException {
CTransUtil.rewriteToApply(this, node, VDM_IS_NAT, node.getExp());
}

@Override
public TransAssistantIR getAssist() {
return assist;
}

@Override
public IAnalysis getAnalyzer() {
return THIS;
}
}

0 comments on commit c10cef4

Please sign in to comment.