/** * Creates a new tree field only constructor {@code AMethodTypeIR TAG=method} 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 params_ the {@link NodeList} node for the {@code params} child of this {@link AMethodTypeIR} node * @param result_ the {@link STypeIR} node for the {@code result} child of this {@link AMethodTypeIR} node * @param equivalent_ the {@link PType} node for the {@code equivalent} child of this {@link AMethodTypeIR} node */ public AMethodTypeIR(Boolean optional_, ANamedTypeDeclIR namedInvType_, List<? extends STypeIR> params_, STypeIR result_, PType equivalent_) { super(null,null,null,optional_,namedInvType_); this.setParams(params_); this.setResult(result_); this.setEquivalent(equivalent_); }
/** * Creates a new complete constructor {@code AMethodTypeIR} 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 params_ the {@link NodeList} node for the {@code params} child of this {@link AMethodTypeIR} node * @param result_ the {@link STypeIR} node for the {@code result} child of this {@link AMethodTypeIR} node * @param equivalent_ the {@link PType} node for the {@code equivalent} child of this {@link AMethodTypeIR} node */ public AMethodTypeIR(SourceNode sourceNode_, Object tag_, List<? extends ClonableString> metaData_, Boolean optional_, ANamedTypeDeclIR namedInvType_, List<? extends STypeIR> params_, STypeIR result_, PType equivalent_) { super(sourceNode_,tag_,metaData_,optional_,namedInvType_); this.setParams(params_); this.setResult(result_); this.setEquivalent(equivalent_); }
public AMethodTypeIR consMethodType(PType node, List<PType> paramTypes, PType resultType, IRInfo question) throws AnalysisException { AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setEquivalent(node.clone()); STypeIR resultCg = resultType.apply(question.getTypeVisitor(), question); methodType.setResult(resultCg); LinkedList<STypeIR> paramsCg = methodType.getParams(); for (PType paramType : paramTypes) { paramsCg.add(paramType.apply(question.getTypeVisitor(), question)); } return methodType; }
public AMethodDeclIR consToStringSignature() { AMethodDeclIR toStringMethod = new AMethodDeclIR(); toStringMethod.setTag(new IRGeneratedTag(getClass().getName())); toStringMethod.setIsConstructor(false); toStringMethod.setAccess(IJavaConstants.PUBLIC); toStringMethod.setStatic(false); toStringMethod.setName(IJavaConstants.TO_STRING); toStringMethod.setAbstract(false); AStringTypeIR returnType = new AStringTypeIR(); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(returnType); toStringMethod.setMethodType(methodType); return toStringMethod; }
public AApplyExpIR consPostCheckCall(AMethodDeclIR method, AApplyExpIR postCondCall, AIdentifierVarExpIR resultVar, AStringLiteralExpIR methodName) { AExternalTypeIR externalType = new AExternalTypeIR(); externalType.setName(JavaFormat.UTILS_FILE); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(new ABoolBasicTypeIR()); methodType.getParams().add(method.getMethodType().getResult().clone()); methodType.getParams().add(new ABoolBasicTypeIR()); methodType.getParams().add(new AStringTypeIR()); AExplicitVarExpIR explicitVar = new AExplicitVarExpIR(); explicitVar.setType(methodType); explicitVar.setIsLambda(false); explicitVar.setIsLocal(false); explicitVar.setName(postCheckMethodName); explicitVar.setClassType(externalType); AApplyExpIR utilsCall = new AApplyExpIR(); utilsCall.setRoot(explicitVar); utilsCall.setType(methodType.getResult().clone()); utilsCall.getArgs().add(resultVar); utilsCall.getArgs().add(postCondCall); utilsCall.getArgs().add(methodName); return utilsCall; } }
public AMethodDeclIR consHashcodeMethodSignature() { AMethodDeclIR hashcodeMethod = new AMethodDeclIR(); hashcodeMethod.setImplicit(false); hashcodeMethod.setIsConstructor(false); hashcodeMethod.setAccess(IJavaConstants.PUBLIC); hashcodeMethod.setName(IJavaConstants.HASH_CODE); String intTypeName = IJavaConstants.INT; AExternalTypeIR intBasicType = new AExternalTypeIR(); intBasicType.setName(intTypeName); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(intBasicType); hashcodeMethod.setMethodType(methodType); return hashcodeMethod; }
protected AMethodDeclIR initPredDecl(String name) { AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(new ABoolBasicTypeIR()); AMethodDeclIR meetsPredMethod = new AMethodDeclIR(); meetsPredMethod.setImplicit(false); meetsPredMethod.setAbstract(false); meetsPredMethod.setAccess(IRConstants.PUBLIC); meetsPredMethod.setAsync(false); meetsPredMethod.setIsConstructor(false); meetsPredMethod.setMethodType(methodType); meetsPredMethod.setStatic(false); meetsPredMethod.setName(name); return meetsPredMethod; }
+ (methodType.getParams().size() + 1)); methodTypeInterface.getTemplateTypes().add(templateTypeResult); evalMethodType.setResult(templateTypeResult.clone());
public AMethodDeclIR consEqualMethodSignature(String paramName) { AMethodDeclIR equalsMethod = new AMethodDeclIR(); equalsMethod.setImplicit(false); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.getParams().add(new AObjectTypeIR()); AExternalTypeIR returnType = new AExternalTypeIR(); returnType.setInfo(null); returnType.setName(IJavaConstants.BOOLEAN); methodType.setResult(returnType); equalsMethod.setAccess(IJavaConstants.PUBLIC); equalsMethod.setIsConstructor(false); equalsMethod.setName(IJavaConstants.EQUALS); equalsMethod.setMethodType(methodType); // Add the formal parameter "Object obj" to the method AFormalParamLocalParamIR formalParam = new AFormalParamLocalParamIR(); AIdentifierPatternIR idPattern = new AIdentifierPatternIR(); idPattern.setName(paramName); formalParam.setPattern(idPattern); AObjectTypeIR paramType = new AObjectTypeIR(); formalParam.setType(paramType); equalsMethod.getFormalParams().add(formalParam); return equalsMethod; }
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; }
public SExpIR consInstanceCall(STypeIR instanceType, String instanceName, STypeIR returnType, String memberName, SExpIR... args) { AIdentifierVarExpIR instance = new AIdentifierVarExpIR(); instance.setType(instanceType.clone()); instance.setName(instanceName); instance.setIsLocal(true); AFieldExpIR fieldExp = new AFieldExpIR(); fieldExp.setMemberName(memberName); fieldExp.setObject(instance); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(returnType.clone()); AApplyExpIR instanceCall = new AApplyExpIR(); instanceCall.setType(returnType.clone()); if (args != null) { for (SExpIR arg : args) { methodType.getParams().add(arg.getType().clone()); instanceCall.getArgs().add(arg); } } fieldExp.setType(methodType.clone()); instanceCall.setRoot(fieldExp); return instanceCall; }
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; }
public AApplyExpIR consUtilCall(STypeIR returnType, String memberName) { AExplicitVarExpIR member = new AExplicitVarExpIR(); AMethodTypeIR methodType = new AMethodTypeIR(); methodType.setResult(returnType.clone()); member.setType(methodType); member.setIsLambda(false); member.setIsLocal(false); AExternalTypeIR classType = new AExternalTypeIR(); classType.setName(JavaFormat.UTILS_FILE); member.setClassType(classType); member.setName(memberName); AApplyExpIR call = new AApplyExpIR(); call.setType(returnType.clone()); call.setRoot(member); return call; }
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; }
methodType.setResult(returnType);
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; }
@Override public void caseAFieldExpIR(AFieldExpIR node) throws AnalysisException { node.getObject().apply(this); if (node.getObject().getType() instanceof ARecordTypeIR && !(node.parent() instanceof AApplyExpIR)) { AMethodTypeIR getterType = new AMethodTypeIR(); getterType.setResult(node.getType().clone()); AFieldExpIR getterField = node.clone(); getterField.setType(getterType); AApplyExpIR getCall = new AApplyExpIR(); getCall.setRoot(getterField); getCall.setType(node.getType().clone()); getCall.setSourceNode(node.getSourceNode()); getterField.setMemberName(consGetCallName(node.getMemberName())); /** * The getters added to the record classes do not copy object references representing values. Therefore we * need to take it into account when we do the field read call */ if (cloneFieldRead(node)) { getCall = makeCopy(getCall); } jmlGen.getJavaGen().getTransAssistant().replaceNodeWith(node, getCall); } }