Skip to content

Commit

Permalink
Fix issue with CG of multiple inheritance
Browse files Browse the repository at this point in the history
Related to issue #606
  • Loading branch information
peterwvj committed Oct 13, 2016
1 parent 57e9271 commit b4672d4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
Expand Up @@ -5,10 +5,12 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.BooleanUtils;
import org.overture.ast.definitions.AClassClassDefinition;
import org.overture.ast.definitions.SClassDefinition;
import org.overture.ast.node.INode;
import org.overture.codegen.assistant.AssistantBase;
import org.overture.codegen.ir.IRGeneratedTag;
import org.overture.codegen.ir.PIR;
import org.overture.codegen.ir.analysis.AnalysisException;
import org.overture.codegen.ir.analysis.DepthFirstAnalysisAdaptor;
Expand Down Expand Up @@ -44,6 +46,10 @@ public ClassToInterfaceTrans(TransAssistantIR assist) {
isFullyAbstract.put(c.getName(), assist.getInfo().getDeclAssistant().isFullyAbstract(vdmClazz, assist.getInfo()));
interfaces.put(c.getName(), convertToInterface(c));
}
else
{
isFullyAbstract.put(c.getName(), false);
}
// This transformation is only helpful for IR classes that originate
// from VDM classes. So we simply ignore classes that originate from
// modules since SL does not support inheritance anyway.
Expand All @@ -65,7 +71,7 @@ public void caseACpuClassDeclIR(ACpuClassDeclIR node) throws AnalysisException {
@Override
public void caseADefaultClassDeclIR(ADefaultClassDeclIR node) throws AnalysisException {

if (isFullyAbstract.get(node.getName())) {
if (isFullyAbstract(node.getName())) {

result = interfaces.get(node.getName());

Expand All @@ -76,7 +82,7 @@ public void caseADefaultClassDeclIR(ADefaultClassDeclIR node) throws AnalysisExc
List<ATokenNameIR> toMove = new LinkedList<>();
for (ATokenNameIR s : node.getSuperNames()) {

if (isFullyAbstract.get(s.getName())) {
if (isFullyAbstract(s.getName())) {
toMove.add(s);
}
}
Expand All @@ -98,7 +104,7 @@ private AInterfaceDeclIR convertToInterface(SClassDeclIR c) {
List<AMethodDeclIR> clonedMethods = new LinkedList<>();

for (AMethodDeclIR m : c.getMethods()) {
if (!m.getIsConstructor()) {
if (!m.getIsConstructor() && !(m.getTag() instanceof IRGeneratedTag)) {
clonedMethods.add(m.clone());
}
}
Expand All @@ -118,6 +124,11 @@ private AInterfaceDeclIR convertToInterface(SClassDeclIR c) {

return inter;
}

private boolean isFullyAbstract(String name)
{
return BooleanUtils.isTrue(isFullyAbstract.get(name));
}

@Override
public PIR getResult() {
Expand Down
Expand Up @@ -221,24 +221,6 @@ protected GeneratedData genVdmToTargetLang(List<IRStatus<PIR>> statuses)
}
}

ClassToInterfaceTrans class2interfaceTr = new ClassToInterfaceTrans(transAssistant);

for (IRStatus<PIR> status : statuses)
{
try
{
generator.applyTotalTransformation(status, class2interfaceTr);

} catch (org.overture.codegen.ir.analysis.AnalysisException e)
{
log.error("Error when generating code for module "
+ status.getIrNodeName() + ": " + e.getMessage());
log.error("Skipping module..");
e.printStackTrace();
}
}
List<IRStatus<AInterfaceDeclIR>> interfaceStatuses = IRStatus.extract(statuses, AInterfaceDeclIR.class);

/**
* Note that this will include the system class, whereas the CPU and BUS classes have been filtered out when the
* IR status was generated
Expand Down Expand Up @@ -287,6 +269,26 @@ protected GeneratedData genVdmToTargetLang(List<IRStatus<PIR>> statuses)
}
}
}

ClassToInterfaceTrans class2interfaceTr = new ClassToInterfaceTrans(transAssistant);

List<IRStatus<PIR>> tmp = IRStatus.extract(canBeGenerated);
for (IRStatus<PIR> status : tmp)
{
try
{
generator.applyTotalTransformation(status, class2interfaceTr);

} catch (org.overture.codegen.ir.analysis.AnalysisException e)
{
log.error("Error when generating code for module "
+ status.getIrNodeName() + ": " + e.getMessage());
log.error("Skipping module..");
e.printStackTrace();
}
}
canBeGenerated = IRStatus.extract(tmp, SClassDeclIR.class);
List<IRStatus<AInterfaceDeclIR>> interfaceStatuses = IRStatus.extract(tmp, AInterfaceDeclIR.class);

cleanup(IRStatus.extract(canBeGenerated));

Expand Down

0 comments on commit b4672d4

Please sign in to comment.