Navigation Menu

Skip to content

Commit

Permalink
Undo commit that removes vdmClone calls
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwvj committed Oct 11, 2016
1 parent be69ff0 commit dab8c97
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
Expand Up @@ -3,11 +3,13 @@
import org.overture.cgc.extast.analysis.DepthFirstAnalysisCAdaptor;
import org.overture.codegen.ir.analysis.AnalysisException;
import org.overture.codegen.ir.declarations.AVarDeclIR;
import org.overture.codegen.ir.expressions.AApplyExpIR;
import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
import org.overture.codegen.ir.patterns.AIdentifierPatternIR;
import org.overture.codegen.ir.statements.ABlockStmIR;
import org.overture.codegen.ir.statements.AReturnStmIR;
import org.overture.codegen.trans.assistants.TransAssistantIR;
import org.overture.codegen.vdm2c.utils.CTransUtil;

//Extract return value to local variable and return that.
public class ExtractRetValTrans extends DepthFirstAnalysisCAdaptor
Expand Down Expand Up @@ -42,10 +44,8 @@ public void caseAReturnStmIR(AReturnStmIR node) throws AnalysisException
retVar.setPattern(id);
retVar.setSourceNode(node.getExp().getSourceNode());

if(node.getExp() != null)
{
retVar.setExp(node.getExp().clone());
}
AApplyExpIR applyexpr = CTransUtil.newApply("vdmClone", node.getExp());
retVar.setExp(applyexpr);

AIdentifierVarExpIR retVarOcc = new AIdentifierVarExpIR();
retVarOcc.setType(retVar.getType().clone());
Expand Down
Expand Up @@ -112,7 +112,7 @@ else if(vdm instanceof AIdentifierStateDesignator)

// process right side of assignment
node.getExp().apply(THIS);
AVarDeclIR retVar = newDeclarationAssignment(name, node.getExp().getType().clone(), node.getExp().clone(), node.getExp().getSourceNode());
AVarDeclIR retVar = newDeclarationAssignment(name, node.getExp().getType().clone(), CTransUtil.newApply("vdmClone", node.getExp().clone()), node.getExp().getSourceNode());

ABlockStmIR replBlock = new ABlockStmIR();
replBlock.setScoped(true);
Expand Down Expand Up @@ -179,7 +179,7 @@ else if(node.getTarget() instanceof AExplicitVarExpIR)
NameConverter.getCName(fieldUtil.lookupField(cDef, node.getTarget().toString())), null),
newIdentifier(name, null));

AVarDeclIR retVar = newDeclarationAssignment(name, node.getExp().getType().clone(), node.getExp().clone(), node.getExp().getSourceNode());
AVarDeclIR retVar = newDeclarationAssignment(name, node.getExp().getType().clone(), CTransUtil.newApply("vdmClone", node.getExp().clone()), node.getExp().getSourceNode());

ABlockStmIR replBlock = new ABlockStmIR();
replBlock.setScoped(true);
Expand Down Expand Up @@ -232,7 +232,7 @@ else if(node.getTarget() instanceof AFieldExpIR)
NameConverter.getCName(fieldUtil.lookupField(cDef, fieldName)), null),
newIdentifier(name, null));

AVarDeclIR retVar = newDeclarationAssignment(name, node.getExp().getType().clone(), node.getExp().clone(), node.getExp().getSourceNode());
AVarDeclIR retVar = newDeclarationAssignment(name, node.getExp().getType().clone(), CTransUtil.newApply("vdmClone", node.getExp().clone()), node.getExp().getSourceNode());

ABlockStmIR replBlock = new ABlockStmIR();
replBlock.setScoped(true);
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.overture.codegen.ir.types.AExternalTypeIR;
import org.overture.codegen.trans.assistants.TransAssistantIR;
import org.overture.codegen.vdm2c.extast.statements.ALocalVariableDeclarationStmIR;
import org.overture.codegen.vdm2c.utils.CTransUtil;
import org.overture.codegen.vdm2c.utils.IApplyAssistant;

public class FreeLocalBlockDeclsTrans extends DepthFirstAnalysisAdaptor implements IApplyAssistant
Expand Down Expand Up @@ -107,5 +108,21 @@ public void caseABlockStmIR(ABlockStmIR node) throws AnalysisException
}
}
}

//Phase to change assignments to vdmClone. This is the brutal
//way to deal with the problem of pointer aliasing.
for(SStmIR stm : ((ABlockStmIR) node).getStatements())
{
if (stm instanceof ALocalVariableDeclarationStmIR)
{
if(!(((ALocalVariableDeclarationStmIR) stm).getDecleration().getType() instanceof AExternalTypeIR))
{
CTransUtil.rewriteToApply(this,
((ALocalVariableDeclarationStmIR) stm).getDecleration().getExp(),
"vdmClone",
((ALocalVariableDeclarationStmIR) stm).getDecleration().getExp());
}
}
}
}
}
Expand Up @@ -7,6 +7,7 @@
import org.overture.codegen.ir.STypeIR;
import org.overture.codegen.ir.declarations.AFieldDeclIR;
import org.overture.codegen.ir.declarations.SClassDeclIR;
import org.overture.codegen.ir.expressions.AApplyExpIR;
import org.overture.codegen.ir.expressions.AExplicitVarExpIR;
import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
import org.overture.codegen.ir.expressions.SVarExpIR;
Expand Down Expand Up @@ -84,7 +85,9 @@ public void replaceWithStaticReference(SClassDeclIR classDef, String name,
AIdentifierVarExpIR newIdentifier = newIdentifier(NameConverter.getCName(field), node.getSourceNode());
newIdentifier.setType(node.getType().clone());
newIdentifier.setIsLocal(false);
assist.replaceNodeWith(node, newIdentifier);
AApplyExpIR vdmCloneApply = CTransUtil.newApply("vdmClone", newIdentifier);
vdmCloneApply.setType(node.getType().clone());
assist.replaceNodeWith(node, vdmCloneApply);
}

public String lookupFieldClass(SClassDeclIR node, String name)
Expand Down

0 comments on commit dab8c97

Please sign in to comment.