public List<PatternInfo> extractFromParams( List<AFormalParamLocalParamIR> params) { List<PatternInfo> patternInfo = new LinkedList<PatternInfo>(); for (AFormalParamLocalParamIR param : params) { STypeIR type = param.getType(); SPatternIR pattern = param.getPattern(); patternInfo.add(new PatternInfo(type, pattern, null)); } return patternInfo; }
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); }
/** * Creates a new complete constructor {@code AFormalParamLocalParamIR} 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 type_ the {@link STypeIR} node for the {@code type} child of this {@link AFormalParamLocalParamIR} node * @param pattern_ the {@link SPatternIR} node for the {@code pattern} child of this {@link AFormalParamLocalParamIR} node */ public AFormalParamLocalParamIR(SourceNode sourceNode_, Object tag_, List<? extends ClonableString> metaData_, STypeIR type_, SPatternIR pattern_) { super(sourceNode_,tag_,metaData_); this.setType(type_); this.setPattern(pattern_); }
/** * Returns a deep clone of this {@link AFormalParamLocalParamIR} node. * @return a deep clone of this {@link AFormalParamLocalParamIR} node */ public AFormalParamLocalParamIR clone() { return new AFormalParamLocalParamIR( _sourceNode, _tag, _metaData, cloneNode(_type), cloneNode(_pattern) ); }
STypeIR paramType = paramLocalDeclIR.getType(); SPatternIR pattern = paramLocalDeclIR.getPattern(); lambdaDecl.getFormalParams().get(i).setType(paramType.clone()); lambdaDecl.getFormalParams().get(i).setPattern(pattern.clone());
if (!(param.getPattern() instanceof AIdentifierPatternIR)) + param.getPattern()); AFormalParamLocalParamIR nextParam = new AFormalParamLocalParamIR(); nextParam.setPattern(javaGen.getInfo().getPatternAssistant().consIdPattern(consUniqueName(f.getName()))); nextParam.setType(f.getType().clone()); this.paramName = ((AIdentifierPatternIR) param.getPattern()).getName();
public String hackInv(ARecordDeclIR type) { if (type.getInvariant() != null) { AFuncDeclIR invFunc = (AFuncDeclIR) type.getInvariant(); StringBuilder sb = new StringBuilder(); sb.append("inv "); sb.append(invFunc.getFormalParams().get(0).getPattern().toString()); sb.append(" == "); sb.append(invFunc.getName()); sb.append("("); sb.append("&"); sb.append(invFunc.getFormalParams().get(0).getPattern().toString()); sb.append(")"); return sb.toString(); } return ""; }
/** * Called by the {@link ALambdaExpIR} node from {@link ALambdaExpIR#apply(IAnalysis)}. * @param node the calling {@link ALambdaExpIR} node */ public void caseALambdaExpIR(ALambdaExpIR node, Q question) throws AnalysisException { _visitedNodes.add(node); inALambdaExpIR(node, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this, question); } { List<AFormalParamLocalParamIR> copy = new ArrayList<AFormalParamLocalParamIR>(node.getParams()); for( AFormalParamLocalParamIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this, question); } } } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this, question); } outALambdaExpIR(node, question); }
AFormalParamLocalParamIR invParamCopy = invParam.clone(); invParam.setType(new AUnknownTypeIR()); String paramName = util.getName(invParam.getPattern()); invParam.setPattern(util.consInvParamReplacementId(clazz, paramName)); cast.setType(invParamCopy.getType().clone()); cast.setExp(paramVar.clone()); AVarDeclIR decl = javaGen.getInfo().getDeclAssistant().consLocalVarDecl(invParamCopy.getType(), invParamCopy.getPattern(), cast); declStmBlock.setScoped(false); declStmBlock.getLocalDefs().add(decl);
templateType.setName(funcValPrefixes.templateType() + (i + 1)); AFormalParamLocalParamIR formalParam = new AFormalParamLocalParamIR(); formalParam.setType(templateType); formalParam.setPattern(params.get(i).getPattern().clone());
/** * Creates a new tree field only constructor {@code AFormalParamLocalParamIR TAG=formalParam} 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 type_ the {@link STypeIR} node for the {@code type} child of this {@link AFormalParamLocalParamIR} node * @param pattern_ the {@link SPatternIR} node for the {@code pattern} child of this {@link AFormalParamLocalParamIR} node */ public AFormalParamLocalParamIR(STypeIR type_, SPatternIR pattern_) { super(null,null,null); this.setType(type_); this.setPattern(pattern_); }
public String hackInv(ANamedTypeDeclIR type) { ATypeDeclIR tDecl = (ATypeDeclIR) type.parent(); if (tDecl.getInv() != null) { AFuncDeclIR invFunc = (AFuncDeclIR) tDecl.getInv(); StringBuilder sb = new StringBuilder(); sb.append("inv "); sb.append(invFunc.getFormalParams().get(0).getPattern().toString()); sb.append(" == "); sb.append(invFunc.getName()); sb.append("("); sb.append("&"); sb.append(invFunc.getFormalParams().get(0).getPattern().toString()); sb.append(")"); return sb.toString(); } return ""; }
/** * Called by the {@link ALambdaExpIR} node from {@link ALambdaExpIR#apply(IAnalysis)}. * @param node the calling {@link ALambdaExpIR} node */ public void caseALambdaExpIR(ALambdaExpIR node) throws AnalysisException { _visitedNodes.add(node); inALambdaExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } { List<AFormalParamLocalParamIR> copy = new ArrayList<AFormalParamLocalParamIR>(node.getParams()); for( AFormalParamLocalParamIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } outALambdaExpIR(node); }
/** * Creates a deep clone of this {@link AFormalParamLocalParamIR} node while putting all * old node-new node relations in the map {@code oldToNewMap}. * @param oldToNewMap the map filled with the old node-new node relation * @return a deep clone of this {@link AFormalParamLocalParamIR} node */ public AFormalParamLocalParamIR clone(Map<INode,INode> oldToNewMap) { AFormalParamLocalParamIR node = new AFormalParamLocalParamIR( _sourceNode, _tag, _metaData, cloneNode(_type, oldToNewMap), cloneNode(_pattern, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
@Override public void caseAFuncDeclIR(AFuncDeclIR node) throws AnalysisException { super.caseAFuncDeclIR(node); if (!node.getTemplateTypes().isEmpty()) { for(ATemplateTypeIR t : node.getTemplateTypes()) { AFormalParamLocalParamIR param = new AFormalParamLocalParamIR(); param.setType(new AUnknownTypeIR()); param.setPattern(assist.getInfo().getPatternAssistant().consIdPattern(toTypeArgName(t))); node.getFormalParams().add(param); } } }
/** * Called by the {@link AFormalParamLocalParamIR} node from {@link AFormalParamLocalParamIR#apply(IAnalysis)}. * @param node the calling {@link AFormalParamLocalParamIR} node */ public void caseAFormalParamLocalParamIR(AFormalParamLocalParamIR node, Q question) throws AnalysisException { _visitedNodes.add(node); inAFormalParamLocalParamIR(node, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this, question); } if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) { node.getPattern().apply(this, question); } outAFormalParamLocalParamIR(node, question); }
private List<ClonableString> consMethodCond(SDeclIR decl, List<AFormalParamLocalParamIR> parentMethodParams, String jmlAnno) { if (decl instanceof AMethodDeclIR) { AMethodDeclIR cond = (AMethodDeclIR) decl; List<String> fieldNames = new LinkedList<String>(); // The arguments of a function or an operation are passed to the pre/post condition int i; for (i = 0; i < parentMethodParams.size(); i++) { fieldNames.add(util.getMethodCondArgName(parentMethodParams.get(i).getPattern())); } // Now compute the remaining argument names which (possibly) // include the RESULT and the old state passed for (; i < cond.getFormalParams().size(); i++) { fieldNames.add(util.getMethodCondArgName(cond.getFormalParams().get(i).getPattern())); } return annotator.consAnno(jmlAnno, cond.getName(), fieldNames); } else if (decl != null) { log.error("Expected pre/post condition to be a method declaration at this point. Got: " + decl); } return null; }
/** * Called by the {@link ALambdaExpIR} node from {@link ALambdaExpIR#apply(IIsaAnalysis)}. * @param node the calling {@link ALambdaExpIR} node */ public void caseALambdaExpIR(ALambdaExpIR node) throws AnalysisException { _visitedNodes.add(node); inALambdaExpIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } { List<AFormalParamLocalParamIR> copy = new ArrayList<AFormalParamLocalParamIR>(node.getParams()); for( AFormalParamLocalParamIR e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } outALambdaExpIR(node); }
public List<AFormalParamLocalParamIR> consFormalParams( List<APatternListTypePair> params, IRInfo question) throws AnalysisException { List<AFormalParamLocalParamIR> paramsCg = new LinkedList<>(); for (APatternListTypePair patternListPair : params) { STypeIR pairTypeCg = patternListPair.getType().apply(question.getTypeVisitor(), question); for (PPattern p : patternListPair.getPatterns()) { SPatternIR patternCg = p.apply(question.getPatternVisitor(), question); AFormalParamLocalParamIR paramCg = new AFormalParamLocalParamIR(); paramCg.setPattern(patternCg); paramCg.setType(pairTypeCg.clone()); paramsCg.add(paramCg); } } return paramsCg; }
/** * Called by the {@link AFormalParamLocalParamIR} node from {@link AFormalParamLocalParamIR#apply(IAnalysis)}. * @param node the calling {@link AFormalParamLocalParamIR} node */ public void caseAFormalParamLocalParamIR(AFormalParamLocalParamIR node) throws AnalysisException { _visitedNodes.add(node); inAFormalParamLocalParamIR(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) { node.getPattern().apply(this); } outAFormalParamLocalParamIR(node); }