/** * 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); }
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; } }
@Override public void inAMethodTypeIR(AMethodTypeIR node) throws AnalysisException if (node.parent() instanceof AMethodDeclIR) if (node.parent() instanceof SVarExpIR) if (node.parent() instanceof AMethodInstantiationExpIR) PType vdmType = node.getEquivalent();
/** * 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_); }
/** * Returns a deep clone of this {@link AMethodTypeIR} node. * @return a deep clone of this {@link AMethodTypeIR} node */ public AMethodTypeIR clone() { return new AMethodTypeIR( _sourceNode, _tag, _metaData, _optional, cloneNode(_namedInvType), cloneList(_params), cloneNode(_result), _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 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 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 boolean hasReturn(AMethodTypeIR node) { return !(node.getResult() instanceof AVoidTypeIR); }
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; }
public AInterfaceDeclIR findInterface(AMethodTypeIR methodType) { for (AInterfaceDeclIR functionValueInterface : funcValInterfaces) { if (1 + methodType.getParams().size() == functionValueInterface.getTemplateTypes().size()) { return functionValueInterface; } } return null; } }
node.getMethodType().apply(this, question);
/** * Sets the {@code _methodType} child of this {@link AMethodDeclIR} node. * @param value the new {@code _methodType} child of this {@link AMethodDeclIR} node */ public void setMethodType(AMethodTypeIR value) { if (this._methodType != null) { this._methodType.parent(null); } if (value != null) { if (value.parent() != null) { value.parent().removeChild(value); } value.parent(this); } this._methodType = value; }
invMethod.getFormalParams().clear(); AMethodTypeIR newMethodType = new AMethodTypeIR(); newMethodType.setResult(new ABoolBasicTypeIR()); invMethod.setMethodType(newMethodType); newMethodType.getParams().add(f.getType().clone());
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; }
private void checkRunReturnType(ADefaultClassDeclIR classCg) { isVoidRun = false; for (AMethodDeclIR m : classCg.getMethods()) { if (m.getName().equals("Run") && m.getMethodType().getResult() instanceof AVoidTypeIR) { isVoidRun = true; } } }