/** * 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_); }
/** * 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_); }
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; }
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; }
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; }
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; } }
@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); } } }
protected SStmIR handleVoidValueReturn(SStmIR stm) { AExternalTypeIR traceNodeClassType = new AExternalTypeIR(); traceNodeClassType.setName(traceTrans.getTracePrefixes().voidValueEnclosingClassName()); AExplicitVarExpIR voidValue = new AExplicitVarExpIR(); voidValue.setType(new AObjectTypeIR()); voidValue.setClassType(traceNodeClassType); voidValue.setIsLambda(false); voidValue.setIsLocal(true); voidValue.setName(traceTrans.getTracePrefixes().voidValueFieldName()); AReturnStmIR returnVoidVal = new AReturnStmIR(); returnVoidVal.setExp(voidValue); ABlockStmIR block = new ABlockStmIR(); block.getStatements().add(stm); block.getStatements().add(returnVoidVal); return block; }
@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; }
private ACatchClauseDeclIR consTcFailHandling() { AExternalTypeIR externalType = new AExternalTypeIR(); externalType.setName(ASSERTION_ERROR_TYPE); ACatchClauseDeclIR catchClause = new ACatchClauseDeclIR(); catchClause.setType(externalType); catchClause.setName(ASSERTION_ERROR_PARAM); AReturnStmIR retFalse = new AReturnStmIR(); retFalse.setExp(traceTrans.getTransAssist().getInfo().getExpAssistant().consBoolLiteral(false)); catchClause.setStm(retFalse); return catchClause; } }
private AMethodDeclIR consEqualsMethod(String name) { AIdentifierVarExpIR paramVar = transAssistant.getInfo().getExpAssistant().consIdVar(EQUALS_METHOD_PARAM, new AObjectTypeIR()); AClassTypeIR quoteClass = new AClassTypeIR(); quoteClass.setName(name); AIsOfClassExpIR instanceCheck = new AIsOfClassExpIR(); instanceCheck.setType(new ABoolBasicTypeIR()); instanceCheck.setExp(paramVar); instanceCheck.setCheckedType(quoteClass); AReturnStmIR checkReturned = new AReturnStmIR(); checkReturned.setExp(instanceCheck); AMethodDeclIR equalsMethod = consEqualMethodSignature(EQUALS_METHOD_PARAM); ABlockStmIR body = new ABlockStmIR(); body.getStatements().add(checkReturned); equalsMethod.setBody(body); return equalsMethod; }
lambdaReturn.setExp(node.getExp().clone());
public AMethodDeclIR genInvMethod(ADefaultClassDeclIR clazz, ANamedTypeDeclIR namedTypeDecl) { AReturnStmIR body = new AReturnStmIR(); body.setExp(jmlGen.getJavaGen().getInfo().getExpAssistant().consBoolLiteral(true)); STypeIR paramType = namedTypeDecl.getType(); AMethodTypeIR invMethodType = new AMethodTypeIR(); invMethodType.setResult(new ABoolBasicTypeIR()); invMethodType.getParams().add(paramType.clone()); String formalParamName = new NameGen(clazz).getName(JmlGenerator.GEN_INV_METHOD_PARAM_NAME); AFormalParamLocalParamIR formalParam = new AFormalParamLocalParamIR(); formalParam.setType(paramType.clone()); formalParam.setPattern(jmlGen.getJavaGen().getInfo().getPatternAssistant().consIdPattern(formalParamName)); AMethodDeclIR method = new AMethodDeclIR(); method.setImplicit(false); method.setAbstract(false); method.setAccess(IRConstants.PUBLIC); method.setAsync(false); method.setBody(body); method.getFormalParams().add(formalParam); method.setIsConstructor(false); method.setMethodType(invMethodType); method.setName("inv_" + namedTypeDecl.getName()); method.setStatic(true); return method; }
public AMethodDeclIR consValidMethod() { AMethodDeclIR validMethod = new AMethodDeclIR(); validMethod.setAbstract(false); validMethod.setAccess(IRConstants.PUBLIC); validMethod.setAsync(false); validMethod.setImplicit(false); validMethod.setIsConstructor(false); validMethod.setName(JmlGenerator.REC_VALID_METHOD_NAMEVALID); validMethod.setStatic(false); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(new ABoolBasicTypeIR()); validMethod.setMethodType(methodType); AReturnStmIR body = new AReturnStmIR(); body.setExp(jmlGen.getJavaGen().getInfo().getExpAssistant().consBoolLiteral(true)); validMethod.setBody(body); jmlGen.getAnnotator().makePure(validMethod); return validMethod; }
body.setExp(newExp); method.setBody(body);
private AMethodDeclIR consGetter(AFieldDeclIR f) { AMethodDeclIR getter = new AMethodDeclIR(); getter.setAbstract(false); getter.setAccess(IRConstants.PUBLIC); getter.setAsync(false); getter.setImplicit(false); getter.setIsConstructor(false); getter.setName(consGetCallName(f.getName())); getter.setStatic(false); getter.setSourceNode(f.getSourceNode()); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(f.getType().clone()); getter.setMethodType(methodType); AReturnStmIR returnField = new AReturnStmIR(); returnField.setExp(jmlGen.getJavaGen().getInfo().getExpAssistant().consIdVar(f.getName(), f.getType().clone())); getter.setBody(returnField); jmlGen.getAnnotator().makePure(getter); return getter; }
returnInstance.setExp(instanceVar.clone());