private AIfStmIR consMismatchCheck(AIdentifierVarExpIR successVar, SStmIR noMatchStm) { AIfStmIR ifCheck = new AIfStmIR(); ifCheck.setIfExp(transAssistant.consBoolCheck(successVar.getName(), true)); ifCheck.setThenStm(noMatchStm); return ifCheck; }
inAIfStmIR(node); if(node.getIfExp() != null && !_visitedNodes.contains(node.getIfExp())) node.getIfExp().apply(this); if(node.getThenStm() != null && !_visitedNodes.contains(node.getThenStm())) node.getThenStm().apply(this); List<AElseIfStmIR> copy = new ArrayList<AElseIfStmIR>(node.getElseIf()); for( AElseIfStmIR e : copy) if(node.getElseStm() != null && !_visitedNodes.contains(node.getElseStm())) node.getElseStm().apply(this);
/** * Creates a new complete constructor {@code AIfStmIR} node with the given nodes as children. * @deprecated This method should not be used, use AstFactory instead. * The basic child nodes are removed from their previous parents. * @param ifExp_ the {@link SExpIR} node for the {@code ifExp} child of this {@link AIfStmIR} node * @param thenStm_ the {@link SStmIR} node for the {@code thenStm} child of this {@link AIfStmIR} node * @param elseIf_ the {@link NodeList} node for the {@code elseIf} child of this {@link AIfStmIR} node * @param elseStm_ the {@link SStmIR} node for the {@code elseStm} child of this {@link AIfStmIR} node */ public AIfStmIR(SourceNode sourceNode_, Object tag_, List<? extends ClonableString> metaData_, SExpIR ifExp_, SStmIR thenStm_, List<? extends AElseIfStmIR> elseIf_, SStmIR elseStm_) { super(sourceNode_,tag_,metaData_); this.setIfExp(ifExp_); this.setThenStm(thenStm_); this.setElseIf(elseIf_); this.setElseStm(elseStm_); }
@Override public void inATernaryIfExpIR(ATernaryIfExpIR node) throws AnalysisException { INode parent = node.parent(); if (parent instanceof AReturnStmIR) { AIfStmIR ifStm = new AIfStmIR(); ifStm.setSourceNode(node.getSourceNode()); ifStm.setIfExp(node.getCondition().clone()); AReturnStmIR thenStm = new AReturnStmIR(); thenStm.setExp(node.getTrueValue().clone()); ifStm.setThenStm(thenStm); AReturnStmIR elseStm = new AReturnStmIR(); elseStm.setExp(node.getFalseValue().clone()); ifStm.setElseStm(elseStm); baseAssistant.replaceNodeWithRecursively(parent, ifStm, this); } } }
@Override public void inAIfStmIR(AIfStmIR node) throws AnalysisException { ABoolBasicTypeIR expectedType = new ABoolBasicTypeIR(); correctTypes(node.getIfExp(), expectedType); LinkedList<AElseIfStmIR> elseIfs = node.getElseIf(); for (AElseIfStmIR currentElseIf : elseIfs) { correctTypes(currentElseIf.getElseIf(), expectedType); } }
AIfStmIR ifChecks = new AIfStmIR(); ifChecks.setIfExp(cond); ifChecks.setThenStm(castFieldObj); } else elseIf.setThenStm(castFieldObj); ifChecks.getElseIf().add(elseIf); ifChecks.setElseStm(consRaiseStm(MISSING_MEMBER, field.getMemberName())); ifChecks.apply(this);
/** * Creates a deep clone of this {@link AIfStmIR} node while putting all * old node-new node relations in the map {@code oldToNewMap}. * @param oldToNewMap the map filled with the old node-new node relation * @return a deep clone of this {@link AIfStmIR} node */ public AIfStmIR clone(Map<INode,INode> oldToNewMap) { AIfStmIR node = new AIfStmIR( _sourceNode, _tag, _metaData, cloneNode(_ifExp, oldToNewMap), cloneNode(_thenStm, oldToNewMap), cloneList(_elseIf, oldToNewMap), cloneNode(_elseStm, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
AIfStmIR enclosingIf = elseIf.getAncestor(AIfStmIR.class); LinkedList<AElseIfStmIR> elseIfList = new LinkedList<AElseIfStmIR>(enclosingIf.getElseIf()); for (int i = 0; i < elseIfList.size(); i++) if (elseIf == currentElseIf) enclosingIf.getElseIf().remove(currentElseIf); AIfStmIR elsePart = new AIfStmIR(); elsePart.setIfExp(currentElseIf.getElseIf()); elsePart.setThenStm(currentElseIf.getThenStm()); enclosingIf.getElseIf().remove(elseIfList.get(j)); elsePart.getElseIf().add(elseIfList.get(j)); block.getStatements().add(elsePart); elsePart.setElseStm(enclosingIf.getElseStm()); enclosingIf.setElseStm(block);
protected List<SStmIR> consConditionalAdd(AIdentifierVarExpIR compResult, SStmIR collectionAdd) { if (predicate != null) { AIfStmIR condCollectionUnion = new AIfStmIR(); condCollectionUnion.setIfExp(predicate.clone()); condCollectionUnion.setThenStm(collectionAdd); return packStm(condCollectionUnion); } else { return packStm(collectionAdd); } }
inAIfStmIR(node, question); if(node.getIfExp() != null && !_visitedNodes.contains(node.getIfExp())) node.getIfExp().apply(this, question); if(node.getThenStm() != null && !_visitedNodes.contains(node.getThenStm())) node.getThenStm().apply(this, question); List<AElseIfStmIR> copy = new ArrayList<AElseIfStmIR>(node.getElseIf()); for( AElseIfStmIR e : copy) if(node.getElseStm() != null && !_visitedNodes.contains(node.getElseStm())) node.getElseStm().apply(this, question);
/** * Creates a new tree field only constructor {@code AIfStmIR TAG=if} node with the given nodes as children. * @deprecated This method should not be used, use AstFactory instead. * The basic child nodes are removed from their previous parents. * @param ifExp_ the {@link SExpIR} node for the {@code ifExp} child of this {@link AIfStmIR} node * @param thenStm_ the {@link SStmIR} node for the {@code thenStm} child of this {@link AIfStmIR} node * @param elseIf_ the {@link NodeList} node for the {@code elseIf} child of this {@link AIfStmIR} node * @param elseStm_ the {@link SStmIR} node for the {@code elseStm} child of this {@link AIfStmIR} node */ public AIfStmIR(SExpIR ifExp_, SStmIR thenStm_, List<? extends AElseIfStmIR> elseIf_, SStmIR elseStm_) { super(null,null,null); this.setIfExp(ifExp_); this.setThenStm(thenStm_); this.setElseIf(elseIf_); this.setElseStm(elseStm_); }
protected SStmIR consOrExpCheck(AOrBoolBinaryExpIR node, String orResultVarName) { SExpIR left = node.getLeft().clone(); SExpIR right = node.getRight().clone(); AIfStmIR leftCheck = new AIfStmIR(); leftCheck.setIfExp(left); AAssignToExpStmIR setOrResultVarTrue = new AAssignToExpStmIR(); setOrResultVarTrue.setTarget(transAssistant.consBoolCheck(orResultVarName, false)); setOrResultVarTrue.setExp(transAssistant.getInfo().getAssistantManager().getExpAssistant().consBoolLiteral(true)); leftCheck.setThenStm(setOrResultVarTrue); AAssignToExpStmIR setOrResultVarToRightExp = new AAssignToExpStmIR(); setOrResultVarToRightExp.setTarget(transAssistant.consBoolCheck(orResultVarName, false)); setOrResultVarToRightExp.setExp(right); leftCheck.setElseStm(setOrResultVarToRightExp); return leftCheck; }
protected AIfStmIR consAndExpCheck(AAndBoolBinaryExpIR node, String andResultVarName) { SExpIR left = node.getLeft().clone(); SExpIR right = node.getRight().clone(); AIfStmIR leftCheck = new AIfStmIR(); leftCheck.setIfExp(left); AIfStmIR rightCheck = new AIfStmIR(); rightCheck.setIfExp(right); AAssignToExpStmIR assignAndVar = new AAssignToExpStmIR(); assignAndVar.setTarget(transAssistant.consBoolCheck(andResultVarName, false)); assignAndVar.setExp(transAssistant.getInfo().getAssistantManager().getExpAssistant().consBoolLiteral(true)); rightCheck.setThenStm(assignAndVar); leftCheck.setThenStm(rightCheck); return leftCheck; }
inAIfStmIR(node); if(node.getIfExp() != null && !_visitedNodes.contains(node.getIfExp())) node.getIfExp().apply(this); if(node.getThenStm() != null && !_visitedNodes.contains(node.getThenStm())) node.getThenStm().apply(this); List<AElseIfStmIR> copy = new ArrayList<AElseIfStmIR>(node.getElseIf()); for( AElseIfStmIR e : copy) if(node.getElseStm() != null && !_visitedNodes.contains(node.getElseStm())) node.getElseStm().apply(this);
@Override public SStmIR caseAIfStm(AIfStm node, IRInfo question) throws AnalysisException { SExpIR ifExp = node.getIfExp().apply(question.getExpVisitor(), question); SStmIR thenStm = node.getThenStm().apply(question.getStmVisitor(), question); AIfStmIR ifStm = new AIfStmIR(); ifStm.setIfExp(ifExp); ifStm.setThenStm(thenStm); LinkedList<AElseIfStm> elseIfs = node.getElseIf(); for (AElseIfStm stm : elseIfs) { ifExp = stm.getElseIf().apply(question.getExpVisitor(), question); thenStm = stm.getThenStm().apply(question.getStmVisitor(), question); AElseIfStmIR elseIfStm = new AElseIfStmIR(); elseIfStm.setElseIf(ifExp); elseIfStm.setThenStm(thenStm); ifStm.getElseIf().add(elseIfStm); } if (node.getElseStm() != null) { SStmIR elseStm = node.getElseStm().apply(question.getStmVisitor(), question); ifStm.setElseStm(elseStm); } return ifStm; }
@Override public List<SStmIR> getPostOuterBlockStms(AIdentifierVarExpIR setVar, List<SPatternIR> patterns) { ALetBeStNoBindingRuntimeErrorExpIR noBinding = new ALetBeStNoBindingRuntimeErrorExpIR(); noBinding.setType(new AErrorTypeIR()); ARaiseErrorStmIR raise = new ARaiseErrorStmIR(); raise.setError(noBinding); AIfStmIR ifStm = new AIfStmIR(); ifStm.setIfExp(transAssist.consBoolCheck(successVarName, true)); ifStm.setThenStm(raise); return packStm(ifStm); } }
mergeReturns(retVal,inAIfStmIR(node, question)); if(node.getIfExp() != null && !_visitedNodes.contains(node.getIfExp())) mergeReturns(retVal,node.getIfExp().apply(this, question)); if(node.getThenStm() != null && !_visitedNodes.contains(node.getThenStm())) mergeReturns(retVal,node.getThenStm().apply(this, question)); List<AElseIfStmIR> copy = new ArrayList<AElseIfStmIR>(node.getElseIf()); for( AElseIfStmIR e : copy) if(node.getElseStm() != null && !_visitedNodes.contains(node.getElseStm())) mergeReturns(retVal,node.getElseStm().apply(this, question));
AIfStmIR ifStm = new AIfStmIR(); ABlockStmIR enclosingIf = new ABlockStmIR(); enclosingIf.getStatements().add(ifStm); replacementBlock.getStatements().add(enclosingIf); ifStm.setIfExp(notSuccess); ifStm.setElseStm(nodeCases.get(0).getResult().clone()); nextCase = new AIfStmIR(); ifStm.setThenStm(enclosingIf); enclosingIf.getStatements().add(nextCase); nextCase.setIfExp(notSuccess.clone()); nextCase.setElseStm(currentCase.getResult().clone()); AIfStmIR tmp = new AIfStmIR(); enclosingIf.getStatements().add(tmp); nextCase.setThenStm(enclosingIf); nextCase = tmp; ifStm.setElseStm(noMatchStm); nextCase.setIfExp(patternData.getSuccessVar().clone()); nextCase.setThenStm(nodeCases.get(nodeCases.size() - 1).getResult().clone());
public AIfStmIR consConditionalIncrement(String counterName, SExpIR predicate) { AIdentifierVarExpIR col = new AIdentifierVarExpIR(); col.setType(new AIntNumericBasicTypeIR()); col.setIsLambda(false); col.setIsLocal(true); col.setName(counterName); AIncrementStmIR inc = new AIncrementStmIR(); inc.setVar(col); AIfStmIR ifStm = new AIfStmIR(); ifStm.setIfExp(predicate); ifStm.setThenStm(inc); return ifStm; }