private AMethodDeclIR consToStringMethod(String name) { SExpIR stringLit = info.getExpAssistant().consStringLiteral("<" + name + ">", false); AReturnStmIR returnStr = new AReturnStmIR(); returnStr.setExp(stringLit); AMethodDeclIR toStringMethod = consToStringSignature(); ABlockStmIR body = new ABlockStmIR(); body.getStatements().add(returnStr); toStringMethod.setBody(body); return toStringMethod; }
/** * Called by the {@link AReturnStmIR} node from {@link AReturnStmIR#apply(IAnalysis)}. * @param node the calling {@link AReturnStmIR} node */ public void caseAReturnStmIR(AReturnStmIR node) throws AnalysisException { _visitedNodes.add(node); inAReturnStmIR(node); if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } outAReturnStmIR(node); }
/** * Returns a deep clone of this {@link AReturnStmIR} node. * @return a deep clone of this {@link AReturnStmIR} node */ public AReturnStmIR clone() { return new AReturnStmIR( _sourceNode, _tag, _metaData, cloneNode(_exp) ); }
@Override public void caseAReturnStmIR(AReturnStmIR node) throws AnalysisException { if (node.getExp() == null) { return; // When the return type of the method is 'void' } if (node.getExp() instanceof ANullExpIR) { return; } node.getExp().apply(this); AMethodDeclIR methodDecl = node.getAncestor(AMethodDeclIR.class); STypeIR expectedType = methodDecl.getMethodType().getResult(); if (expectedType instanceof AUnknownTypeIR) { return; } if (!(expectedType instanceof AUnionTypeIR)) { correctTypes(node.getExp(), expectedType); } }
firstBranch.setRight(methNum); AReturnStmIR ret = new AReturnStmIR(); ABoolLiteralExpIR boolret = new ABoolLiteralExpIR(); boolret.setValue(true); ret.setExp(boolret); ret.setExp(per.getPred()); AReturnStmIR ret = new AReturnStmIR(); ABoolLiteralExpIR boolret = new ABoolLiteralExpIR(); boolret.setValue(true); ret.setExp(boolret); ret.setExp(per.getPred()); newBranch.setThenStm(ret.clone()); AReturnStmIR ret = new AReturnStmIR(); ret.setExp(defaultPer); bodyif.setElseStm(ret.clone());
AReturnStmIR returnStm = new AReturnStmIR(); returnStm.setSourceNode(body.getSourceNode()); returnStm.setExp(body.clone()); method.setBody(returnStm); } else
/** * Creates a new tree field only constructor {@code AReturnStmIR TAG=return} 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 exp_ the {@link SExpIR} node for the {@code exp} child of this {@link AReturnStmIR} node */ public AReturnStmIR(SExpIR exp_) { super(null,null,null); this.setExp(exp_); }
@Override public void inAReturnStmIR(AReturnStmIR node) throws AnalysisException { SExpIR exp = node.getExp(); if (exp != null) { exp.apply(this); } else { return; } AMethodDeclIR method = node.getAncestor(AMethodDeclIR.class); AMethodTypeIR methodType = method.getMethodType(); if (methodType.getResult() instanceof AStringTypeIR) { if (!(exp.getType() instanceof SSeqTypeIR)) { return; } correctExpToString(exp); ; } else if (methodType.getResult() instanceof SSeqTypeIR) { if (!(exp.getType() instanceof AStringTypeIR)) { return; } correctExpToSeq(exp, exp.getType()); } }
/** * Creates a new complete constructor {@code AReturnStmIR} 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 exp_ the {@link SExpIR} node for the {@code exp} child of this {@link AReturnStmIR} node */ public AReturnStmIR(SourceNode sourceNode_, Object tag_, List<? extends ClonableString> metaData_, SExpIR exp_) { super(sourceNode_,tag_,metaData_); this.setExp(exp_); }
@Override public SStmIR caseAReturnStm(AReturnStm node, IRInfo question) throws AnalysisException { PExp exp = node.getExpression(); AExplicitOperationDefinition operation = node.getAncestor(AExplicitOperationDefinition.class); if (operation != null && operation.getIsConstructor()) { if (exp instanceof ASelfExp) { // The expression of the return statement points to 'null' since the OO AST // does not allow constructors to return references to explicitly // created types. Simply 'returning' in a constructor means returning // a reference for the object currently being created. return new AReturnStmIR(); } else { question.addUnsupportedNode(operation, "Unexpected expression returned by constructor: Values expliclty returned by constructors must be 'self'."); return null; } } AReturnStmIR returnStm = new AReturnStmIR(); if (exp != null) { SExpIR expCg = exp.apply(question.getExpVisitor(), question); returnStm.setExp(expCg); } return returnStm; }
/** * Called by the {@link AReturnStmIR} node from {@link AReturnStmIR#apply(IAnalysis)}. * @param node the calling {@link AReturnStmIR} node */ public void caseAReturnStmIR(AReturnStmIR node, Q question) throws AnalysisException { _visitedNodes.add(node); inAReturnStmIR(node, question); if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this, question); } outAReturnStmIR(node, question); }
@Override public void caseAReturnStmIR(AReturnStmIR node) throws AnalysisException SExpIR result = node.getExp(); AMethodDeclIR method = node.getAncestor(AMethodDeclIR.class); AVarDeclIR resultDecl = transAssistant.consDecl(funcResultVarName, method.getMethodType().getResult().clone(), node.getExp().clone()); AIdentifierVarExpIR resultVar = transAssistant.getInfo().getExpAssistant().consIdVar(funcResultVarName, resultDecl.getType().clone()); replacementBlock.getLocalDefs().add(resultDecl); transAssistant.replaceNodeWith(node.getExp(), postCheckCall); transAssistant.replaceNodeWith(node, replacementBlock);
/** * Creates a deep clone of this {@link AReturnStmIR} 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 AReturnStmIR} node */ public AReturnStmIR clone(Map<INode,INode> oldToNewMap) { AReturnStmIR node = new AReturnStmIR( _sourceNode, _tag, _metaData, cloneNode(_exp, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
private AMethodDeclIR consHashcodeMethod() { AIdentifierVarExpIR hashCodeVar = transAssistant.getInfo().getExpAssistant().consIdVar(HASHCODE_FIELD, consFieldType()); AReturnStmIR returnHashCode = new AReturnStmIR(); returnHashCode.setExp(hashCodeVar); AMethodDeclIR hashCodeMethod = consHashcodeMethodSignature(); ABlockStmIR body = new ABlockStmIR(); body.getStatements().add(returnHashCode); hashCodeMethod.setBody(body); return hashCodeMethod; }
/** * Called by the {@link AReturnStmIR} node from {@link AReturnStmIR#apply(IIsaAnalysis)}. * @param node the calling {@link AReturnStmIR} node */ public void caseAReturnStmIR(AReturnStmIR node) throws AnalysisException { _visitedNodes.add(node); inAReturnStmIR(node); if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } outAReturnStmIR(node); }
private AMethodDeclIR makeExecutableInit(AStateDeclIR node) { AMethodDeclIR meth = info.getDeclAssistant().funcToMethod(node.getInitDecl()); AReturnStmIR ret = new AReturnStmIR(); AEqualsBinaryExpIR initExp = (AEqualsBinaryExpIR) node.getInitExp(); ret.setExp(initExp.getRight().clone()); meth.setBody(ret); return meth; } }
/** * Called by the {@link AReturnStmIR} node from {@link AReturnStmIR#apply(IAnalysis)}. * @param node the calling {@link AReturnStmIR} node */ public A caseAReturnStmIR(AReturnStmIR node) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node); mergeReturns(retVal,inAReturnStmIR(node)); if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { mergeReturns(retVal,node.getExp().apply(this)); } mergeReturns(retVal,outAReturnStmIR(node)); return retVal; }
@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); } } }
/** * Called by the {@link AReturnStmIR} node from {@link AReturnStmIR#apply(IAnalysis)}. * @param node the calling {@link AReturnStmIR} node */ public A caseAReturnStmIR(AReturnStmIR node, Q question) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node, question); mergeReturns(retVal,inAReturnStmIR(node, question)); if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { mergeReturns(retVal,node.getExp().apply(this, question)); } mergeReturns(retVal,outAReturnStmIR(node, question)); return retVal; }
public AMethodDeclIR genHashcodeMethod(ARecordDeclIR record) throws AnalysisException { AMethodDeclIR hashcodeMethod = consHashcodeMethodSignature(); AReturnStmIR returnStm = new AReturnStmIR(); if (record.getFields().isEmpty()) { AExternalExpIR zero = new AExternalExpIR(); zero.setType(hashcodeMethod.getMethodType().getResult().clone()); zero.setTargetLangExp("0"); returnStm.setExp(zero); } else { returnStm.setExp(javaFormat.getJavaFormatAssistant().consUtilCallUsingRecFields(record, hashcodeMethod.getMethodType().getResult(), hashcodeMethod.getName())); } hashcodeMethod.setBody(returnStm); return hashcodeMethod; }