protected void handleLogicExp(SBoolBinaryExpIR node, SStmIR enclosingStm, SStmIR checkBlock, String resultName) throws AnalysisException { AVarDeclIR andResultDecl = transAssistant.consBoolVarDecl(resultName, false); ABlockStmIR declBlock = new ABlockStmIR(); declBlock.getLocalDefs().add(andResultDecl); ABlockStmIR replacementBlock = new ABlockStmIR(); transAssistant.replaceNodeWith(enclosingStm, replacementBlock); transAssistant.replaceNodeWith(node, transAssistant.consBoolCheck(resultName, false)); replacementBlock.getStatements().add(declBlock); replacementBlock.getStatements().add(checkBlock); replacementBlock.getStatements().add(enclosingStm); replacementBlock.apply(this); }
public void caseALetDefExpIR(ALetDefExpIR node) throws AnalysisException { SStmIR enclosingStm = transAssistant.getEnclosingStm(node, "let def expression"); SExpIR exp = node.getExp(); transAssistant.replaceNodeWith(node, exp); ABlockStmIR topBlock = new ABlockStmIR(); ABlockStmIR current = topBlock; for (AVarDeclIR local : node.getLocalDefs()) { ABlockStmIR tmp = new ABlockStmIR(); tmp.getLocalDefs().add(local.clone()); current.getStatements().add(tmp); current = tmp; } transAssistant.replaceNodeWith(enclosingStm, topBlock); topBlock.getStatements().add(enclosingStm); exp.apply(this); topBlock.apply(this); topBlock.setScoped(transAssistant.getInfo().getStmAssistant().isScoped(topBlock)); }
newBody.getStatements().add(oldBody); newBody.apply(this); } else
@Override public void caseACompSetExpIR(ACompSetExpIR node) throws AnalysisException { SStmIR enclosingStm = transAssistant.getEnclosingStm(node, "set comprehension"); SExpIR first = node.getFirst(); SExpIR predicate = node.getPredicate(); STypeIR type = node.getType(); ITempVarGen tempVarNameGen = transAssistant.getInfo().getTempVarNameGen(); String var = tempVarNameGen.nextVarName(prefixes.setComp()); ComplexCompStrategy strategy = consSetCompStrategy(first, predicate, type, tempVarNameGen, var); List<SMultipleBindIR> bindings = filterBindList(node, node.getBindings()); ABlockStmIR block = transAssistant.consComplexCompIterationBlock(bindings, tempVarNameGen, strategy, iteVarPrefixes); if (block.getStatements().isEmpty()) { // In case the block has no statements the result of the set comprehension is the empty set AEnumSetExpIR emptySet = new AEnumSetExpIR(); emptySet.setType(type.clone()); // Replace the set comprehension with the empty set transAssistant.replaceNodeWith(node, emptySet); } else { replaceCompWithTransformation(enclosingStm, block, type, var, node); } block.apply(this); }
block.apply(this);
@Override public void caseACompMapExpIR(ACompMapExpIR node) throws AnalysisException { SStmIR enclosingStm = transAssistant.getEnclosingStm(node, "map comprehension"); AMapletExpIR first = node.getFirst(); SExpIR predicate = node.getPredicate(); STypeIR type = node.getType(); ITempVarGen tempVarNameGen = transAssistant.getInfo().getTempVarNameGen(); String var = tempVarNameGen.nextVarName(prefixes.mapComp()); ComplexCompStrategy strategy = consMapCompStrategy(first, predicate, type, tempVarNameGen, var); List<SMultipleBindIR> bindings = filterBindList(node, node.getBindings()); ABlockStmIR block = transAssistant.consComplexCompIterationBlock(bindings, tempVarNameGen, strategy, iteVarPrefixes); if (block.getStatements().isEmpty()) { // In case the block has no statements the result of the map comprehension is the empty map AEnumMapExpIR emptyMap = new AEnumMapExpIR(); emptyMap.setType(type.clone()); // Replace the map comprehension with the empty map transAssistant.replaceNodeWith(node, emptyMap); } else { replaceCompWithTransformation(enclosingStm, block, type, var, node); } block.apply(this); }
@Override public void caseAExistsQuantifierExpIR(AExistsQuantifierExpIR node) throws AnalysisException { SStmIR enclosingStm = transAssistant.getEnclosingStm(node, "exists expression"); SExpIR predicate = node.getPredicate(); ITempVarGen tempVarNameGen = transAssistant.getInfo().getTempVarNameGen(); String var = tempVarNameGen.nextVarName(prefixes.exists()); OrdinaryQuantifierStrategy strategy = consOrdinaryQuantifierStrategy(predicate, tempVarNameGen, var, transAssistant, OrdinaryQuantifier.EXISTS, langIterator, iteVarPrefixes); List<SMultipleBindIR> multipleSetBinds = filterBindList(node, node.getBindList()); ABlockStmIR block = transAssistant.consComplexCompIterationBlock(multipleSetBinds, tempVarNameGen, strategy, iteVarPrefixes); if (multipleSetBinds.isEmpty()) { ABoolLiteralExpIR existsResult = transAssistant.getInfo().getExpAssistant().consBoolLiteral(false); transAssistant.replaceNodeWith(node, existsResult); } else { AIdentifierVarExpIR existsResult = new AIdentifierVarExpIR(); existsResult.setIsLocal(true); existsResult.setType(new ABoolBasicTypeIR()); existsResult.setName(var); transform(enclosingStm, block, existsResult, node); block.apply(this); } }
@Override public void caseAForAllQuantifierExpIR(AForAllQuantifierExpIR node) throws AnalysisException { SStmIR enclosingStm = transAssistant.getEnclosingStm(node, "forall expression"); SExpIR predicate = node.getPredicate(); ITempVarGen tempVarNameGen = transAssistant.getInfo().getTempVarNameGen(); String var = tempVarNameGen.nextVarName(prefixes.forAll()); OrdinaryQuantifierStrategy strategy = consOrdinaryQuantifierStrategy(predicate, tempVarNameGen, var, transAssistant, OrdinaryQuantifier.FORALL, langIterator, iteVarPrefixes); List<SMultipleBindIR> multipleSetBinds = filterBindList(node, node.getBindList()); ABlockStmIR block = transAssistant.consComplexCompIterationBlock(multipleSetBinds, tempVarNameGen, strategy, iteVarPrefixes); if (multipleSetBinds.isEmpty()) { ABoolLiteralExpIR forAllResult = transAssistant.getInfo().getExpAssistant().consBoolLiteral(true); transAssistant.replaceNodeWith(node, forAllResult); } else { AIdentifierVarExpIR forAllResult = new AIdentifierVarExpIR(); forAllResult.setIsLocal(true); forAllResult.setType(new ABoolBasicTypeIR()); forAllResult.setName(var); transform(enclosingStm, block, forAllResult, node); block.apply(this); } }
@Override public void caseAIotaExpIR(AIotaExpIR node) throws AnalysisException { SStmIR enclosingStm = transAssistant.getEnclosingStm(node, "iota expression"); SExpIR predicate = node.getPredicate(); ITempVarGen tempVarNameGen = transAssistant.getInfo().getTempVarNameGen(); String resVarName = tempVarNameGen.nextVarName(prefixes.iota()); String counterName = tempVarNameGen.nextVarName(prefixes.iotaCounter()); IotaStrategy strategy = consIotaStrategy(predicate, tempVarNameGen, resVarName, counterName, node.getPredicate()); List<SMultipleBindIR> multipleSetBinds = filterBindList(node, node.getBindList()); ABlockStmIR block = transAssistant.consComplexCompIterationBlock(multipleSetBinds, tempVarNameGen, strategy, iteVarPrefixes); if (multipleSetBinds.isEmpty()) { transAssistant.replaceNodeWith(node, transAssistant.getInfo().getExpAssistant().consUndefinedExp()); } else { AIdentifierVarExpIR iotaResult = new AIdentifierVarExpIR(); iotaResult.setIsLocal(true); iotaResult.setType(node.getType().clone()); iotaResult.setName(resVarName); transform(enclosingStm, block, iotaResult, node); block.apply(this); } }
outerBlock.apply(this);
@Override public void caseAExists1QuantifierExpIR(AExists1QuantifierExpIR node) throws AnalysisException { SStmIR enclosingStm = transAssistant.getEnclosingStm(node, "exists1 expression"); SExpIR predicate = node.getPredicate(); ITempVarGen tempVarNameGen = transAssistant.getInfo().getTempVarNameGen(); String var = tempVarNameGen.nextVarName(prefixes.exists1()); Exists1QuantifierStrategy strategy = consExists1QuantifierStrategy(predicate, tempVarNameGen, var); List<SMultipleBindIR> multipleSetBinds = filterBindList(node, node.getBindList()); ABlockStmIR block = transAssistant.consComplexCompIterationBlock(multipleSetBinds, tempVarNameGen, strategy, iteVarPrefixes); if (multipleSetBinds.isEmpty()) { ABoolLiteralExpIR exists1Result = transAssistant.getInfo().getExpAssistant().consBoolLiteral(false); transAssistant.replaceNodeWith(node, exists1Result); } else { AIdentifierVarExpIR counter = new AIdentifierVarExpIR(); counter.setType(new AIntNumericBasicTypeIR()); counter.setIsLocal(true); counter.setName(var); AEqualsBinaryExpIR exists1Result = new AEqualsBinaryExpIR(); exists1Result.setType(new ABoolBasicTypeIR()); exists1Result.setLeft(counter); exists1Result.setRight(transAssistant.getInfo().getExpAssistant().consIntLiteral(1)); transform(enclosingStm, block, exists1Result, node); block.apply(this); } }
replacementBlock.apply(this);