public AInterfaceDeclIR findInterface(AMethodTypeIR methodType) { for (AInterfaceDeclIR functionValueInterface : funcValInterfaces) { if (1 + methodType.getParams().size() == functionValueInterface.getTemplateTypes().size()) { return functionValueInterface; } } return null; } }
private AInterfaceDeclIR consInterface(AMethodTypeIR methodType) { List<AFormalParamLocalParamIR> params = new LinkedList<AFormalParamLocalParamIR>(); List<STypeIR> paramTypes = methodType.getParams(); for (int i = 0; i < paramTypes.size(); i++) { STypeIR paramType = paramTypes.get(i); AFormalParamLocalParamIR param = new AFormalParamLocalParamIR(); String nextParamName = funcValPrefixes.param() + (i + 1); AIdentifierPatternIR idPattern = new AIdentifierPatternIR(); idPattern.setName(nextParamName); param.setType(paramType.clone()); param.setPattern(idPattern); params.add(param); } return consInterface(methodType, params); }
/** * Called by the {@link AMethodTypeIR} node from {@link AMethodTypeIR#apply(IAnalysis)}. * @param node the calling {@link AMethodTypeIR} node */ public void caseAMethodTypeIR(AMethodTypeIR node) throws AnalysisException { _visitedNodes.add(node); inAMethodTypeIR(node); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { node.getNamedInvType().apply(this); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getParams()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) { node.getResult().apply(this); } outAMethodTypeIR(node); }
/** * Called by the {@link AMethodTypeIR} node from {@link AMethodTypeIR#apply(IAnalysis)}. * @param node the calling {@link AMethodTypeIR} node */ public void caseAMethodTypeIR(AMethodTypeIR node, Q question) throws AnalysisException { _visitedNodes.add(node); inAMethodTypeIR(node, question); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { node.getNamedInvType().apply(this, question); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getParams()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this, question); } } } if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) { node.getResult().apply(this, question); } outAMethodTypeIR(node, question); }
/** * Called by the {@link AMethodTypeIR} node from {@link AMethodTypeIR#apply(IIsaAnalysis)}. * @param node the calling {@link AMethodTypeIR} node */ public void caseAMethodTypeIR(AMethodTypeIR node) throws AnalysisException { _visitedNodes.add(node); inAMethodTypeIR(node); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { node.getNamedInvType().apply(this); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getParams()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) { node.getResult().apply(this); } outAMethodTypeIR(node); }
public AApplyExpIR consUtilCopyCall() { ATemplateTypeIR copyType = new ATemplateTypeIR(); copyType.setName("T"); AApplyExpIR copyCall = consUtilCall(copyType, COPY); SExpIR member = copyCall.getRoot(); if (member instanceof AExplicitVarExpIR && ((AExplicitVarExpIR) member).getType() instanceof AMethodTypeIR) { AMethodTypeIR methodType = (AMethodTypeIR) member.getType(); methodType.getParams().add(member.getType().clone()); } else { log.error("Expected type of call expression to be a method type at this point. Got: " + copyCall.getType()); } return copyCall; }
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 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 String format(AMethodTypeIR methodType) throws AnalysisException { final String OBJ = "Object"; if (funcValAssist == null) { return OBJ; } AInterfaceDeclIR methodTypeInterface = funcValAssist.findInterface(methodType); if (methodTypeInterface == null) { return OBJ; // Should not happen } AInterfaceTypeIR methodClass = new AInterfaceTypeIR(); methodClass.setName(methodTypeInterface.getName()); LinkedList<STypeIR> params = methodType.getParams(); for (STypeIR param : params) { methodClass.getTypes().add(param.clone()); } methodClass.getTypes().add(methodType.getResult().clone()); return methodClass != null ? format(methodClass) : OBJ; }
/** * Called by the {@link AMethodTypeIR} node from {@link AMethodTypeIR#apply(IAnalysis)}. * @param node the calling {@link AMethodTypeIR} node */ public A caseAMethodTypeIR(AMethodTypeIR node, Q question) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node, question); mergeReturns(retVal,inAMethodTypeIR(node, question)); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { mergeReturns(retVal,node.getNamedInvType().apply(this, question)); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getParams()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { mergeReturns(retVal,e.apply(this, question)); } } } if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) { mergeReturns(retVal,node.getResult().apply(this, question)); } mergeReturns(retVal,outAMethodTypeIR(node, question)); return retVal; }
/** * Called by the {@link AMethodTypeIR} node from {@link AMethodTypeIR#apply(IAnalysis)}. * @param node the calling {@link AMethodTypeIR} node */ public A caseAMethodTypeIR(AMethodTypeIR node) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node); mergeReturns(retVal,inAMethodTypeIR(node)); if(node.getNamedInvType() != null && !_visitedNodes.contains(node.getNamedInvType())) { mergeReturns(retVal,node.getNamedInvType().apply(this)); } { List<STypeIR> copy = new ArrayList<STypeIR>(node.getParams()); for( STypeIR e : copy) { if(!_visitedNodes.contains(e)) { mergeReturns(retVal,e.apply(this)); } } } if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) { mergeReturns(retVal,node.getResult().apply(this)); } mergeReturns(retVal,outAMethodTypeIR(node)); return retVal; }
private void handleCallStm(SCallStmIR node, String className) throws AnalysisException { for (SExpIR arg : node.getArgs()) { arg.apply(this); } String fieldName = node.getName(); LinkedList<SExpIR> args = node.getArgs(); TypeAssistantIR typeAssistant = transAssistant.getInfo().getAssistantManager().getTypeAssistant(); AMethodTypeIR methodType = typeAssistant.getMethodType(transAssistant.getInfo(), className, fieldName, args); if (methodType != null) { correctArgTypes(args, methodType.getParams(), true); } }
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; }
LinkedList<STypeIR> params = method.getMethodType().getParams();
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; }
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; }
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; }
if (correctArgTypes(args, method.getMethodType().getParams(), true))