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; }
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; } }
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; }
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; }
lambdaDecl.setBody(lambdaBody);
toStringMethod.setBody(body);
public AMethodDeclIR consDefaultContructor(String name) { AMethodDeclIR constructor = new AMethodDeclIR(); AClassTypeIR classType = new AClassTypeIR(); classType.setName(name); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(classType); constructor.setMethodType(methodType); constructor.setAccess(IRConstants.PUBLIC); constructor.setAbstract(false); constructor.setIsConstructor(true); constructor.setName(name); constructor.setImplicit(false); constructor.setBody(new ABlockStmIR()); return constructor; }
evalMethod.setAbstract(true); evalMethod.setAccess(IRConstants.PUBLIC); evalMethod.setBody(null); evalMethod.setIsConstructor(false); evalMethod.setMethodType(methodType.clone());
@Override public SDeclIR caseAImplicitOperationDefinition( AImplicitOperationDefinition node, IRInfo question) throws AnalysisException { AMethodDeclIR method = question.getDeclAssistant().initMethod(node, question); if (method == null) { question.addUnsupportedNode(node, "Expected method type for explicit operation. Got: " + node.getType()); return null; } // The curent IR construction does not include: // // Name of result and its type: // APatternTypePair res = node.getResult(); // Ext clauses (read and write): // LinkedList<AExternalClause> externals = node.getExternals(); // Exceptions thrown: // LinkedList<AErrorCase> errors = node.getErrors(); if(method.getBody() == null) { method.setBody(new ANotImplementedStmIR()); } method.setFormalParams(question.getDeclAssistant().consFormalParams(node.getParameterPatterns(), question)); return method; }
protected AMethodDeclIR consExecuteMethod(SStmIR stm) { AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(new AObjectTypeIR()); AMethodDeclIR execMethod = new AMethodDeclIR(); execMethod.setImplicit(false); execMethod.setAbstract(false); execMethod.setAccess(IRConstants.PUBLIC); execMethod.setAsync(false); execMethod.setIsConstructor(false); execMethod.setMethodType(methodType); execMethod.setName(traceTrans.getTracePrefixes().callStmExecMethodNamePrefix()); execMethod.setStatic(false); ABlockStmIR body = new ABlockStmIR(); body.getStatements().add(makeInstanceCall(stm)); ensureStoreLookups(body); execMethod.setBody(body); return execMethod; }
this.setImplicit(implicit_); this.setRaises(raises_); this.setBody(body_);
toStringMethod.setBody(returnStm);
private AMethodDeclIR consTraceMethod(ANamedTraceDeclIR node) throws AnalysisException { AClassTypeIR testAccType = transAssistant.consClassType(tracePrefixes.testAccumulatorClassName()); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(new AVoidTypeIR()); methodType.getParams().add(testAccType); AFormalParamLocalParamIR instanceParam = new AFormalParamLocalParamIR(); instanceParam.setType(testAccType.clone()); instanceParam.setPattern(transAssistant.getInfo().getPatternAssistant().consIdPattern(tracePrefixes.traceMethodParamName())); AMethodDeclIR traceMethod = new AMethodDeclIR(); traceMethod.setTag(new TraceMethodTag()); traceMethod.getFormalParams().add(instanceParam); traceMethod.setImplicit(false); traceMethod.setAbstract(false); traceMethod.setAccess(IRConstants.PUBLIC); traceMethod.setBody(consTraceMethodBody(node)); traceMethod.setIsConstructor(false); traceMethod.setStatic(Settings.dialect == Dialect.VDM_SL); traceMethod.setMethodType(methodType); traceMethod.setName(getTraceName(node) + "_" + tracePrefixes.runTraceMethodName()); return traceMethod; }
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; }
method.setBody(body);
private AMethodDeclIR consSetter(AFieldDeclIR f) { AMethodDeclIR setter = new AMethodDeclIR(); setter.setAbstract(false); setter.setAccess(IRConstants.PUBLIC); setter.setAsync(false); setter.setImplicit(false); setter.setIsConstructor(false); setter.setName(consSetCallName(f.getName())); setter.setStatic(false); setter.setSourceNode(f.getSourceNode()); String paramName = consParamName(f); AFormalParamLocalParamIR param = new AFormalParamLocalParamIR(); param.setType(f.getType().clone()); param.setPattern(jmlGen.getJavaGen().getInfo().getPatternAssistant().consIdPattern(paramName)); setter.getFormalParams().add(param); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(new AVoidTypeIR()); methodType.getParams().add(f.getType().clone()); setter.setMethodType(methodType); AAssignToExpStmIR fieldUpdate = new AAssignToExpStmIR(); fieldUpdate.setTarget(jmlGen.getJavaGen().getInfo().getExpAssistant().consIdVar(f.getName(), f.getType().clone())); fieldUpdate.setExp(jmlGen.getJavaGen().getInfo().getExpAssistant().consIdVar(paramName, f.getType().clone())); setter.setBody(fieldUpdate); return setter; }
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; }
ctor.setBody(body);