public boolean hasReturn(AMethodTypeIR node) { return !(node.getResult() instanceof AVoidTypeIR); }
private void checkRunReturnType(ADefaultClassDeclIR classCg) { isVoidRun = false; for (AMethodDeclIR m : classCg.getMethods()) { if (m.getName().equals("Run") && m.getMethodType().getResult() instanceof AVoidTypeIR) { isVoidRun = true; } } }
/** * 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(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); }
/** * 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(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; }
argType = argMethodType.getResult();
@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()); } }
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; }
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; }
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; } }
&& m.getMethodType().getResult() instanceof ARecordTypeIR)
@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); } }
call.setSourceNode(m.getBody().getSourceNode()); call.setTag(m.getBody().getTag()); call.setType(m.getMethodType().getResult().clone());
AVarDeclIR resultDecl = transAssistant.consDecl(funcResultVarName, method.getMethodType().getResult().clone(), node.getExp().clone()); AIdentifierVarExpIR resultVar = transAssistant.getInfo().getExpAssistant().consIdVar(funcResultVarName, resultDecl.getType().clone());
STypeIR strType = toStringMethod.getMethodType().getResult(); emptyRecStr.setType(strType.clone());
@SuppressWarnings("unchecked") @Override public SExpIR caseAApplyObjectDesignatorIR(AApplyObjectDesignatorIR node) throws AnalysisException { SObjectDesignatorIR object = node.getObject(); SourceNode sourceNode = node.getSourceNode(); LinkedList<SExpIR> args = node.getArgs(); SExpIR root = object.apply(this); STypeIR rootType = root.getType(); STypeIR applyType = null; if (rootType instanceof SSeqTypeIR) { applyType = ((SSeqTypeIR) rootType).getSeqOf(); } else if (rootType instanceof SMapTypeIR) { applyType = ((SMapTypeIR) rootType).getTo(); } else if (rootType instanceof AMethodTypeIR) { applyType = ((AMethodTypeIR) rootType).getResult(); } applyType = applyType.clone(); AApplyExpIR applyExp = new AApplyExpIR(); applyExp.setArgs((List<? extends SExpIR>) args.clone()); applyExp.setRoot(root); applyExp.setType(applyType); applyExp.setSourceNode(sourceNode); return applyExp; }
public void handleReturn(AReturnStmIR node) throws AnalysisException { /** * The idea is to extract the return value to variable and return that variable. Then it becomes the * responsibility of the variable declaration case to assert if the named invariant type is violated. */ SExpIR exp = node.getExp(); AMethodDeclIR encMethod = decorator.getJmlGen().getUtil().getEnclosingMethod(node); if (encMethod == null) { return; } STypeIR returnType = encMethod.getMethodType().getResult(); AbstractTypeInfo typeInfo = util.findTypeInfo(returnType); if (!proceed(typeInfo)) { return; } String name = getInfo().getTempVarNameGen().nextVarName(RET_VAR_NAME_PREFIX); AIdentifierPatternIR id = getInfo().getPatternAssistant().consIdPattern(name); AIdentifierVarExpIR varExp = getInfo().getExpAssistant().consIdVar(name, returnType.clone()); getTransAssist().replaceNodeWith(exp, varExp); AVarDeclIR varDecl = getInfo().getDeclAssistant().consLocalVarDecl(returnType.clone(), id, exp.clone()); ABlockStmIR replBlock = new ABlockStmIR(); replBlock.getLocalDefs().add(varDecl); getTransAssist().replaceNodeWith(node, replBlock); replBlock.getStatements().add(node); varDecl.apply(decorator); }