@Override public String toString() { return ff2.type.getParameters() + " -> " + ff1.type.getResult(); }
throws AnalysisException if (type.getResolved()) type.setResolved(true); TypeCheckException problem = null; for (PType ft : type.getParameters()) fixed.add(AstFactory.newAUnknownType(type.getLocation())); type.setParameters(fixed); type.setResult(af.createPTypeAssistant().typeResolve(type.getResult(), question.root, question.rootVisitor, question.question)); fixed.add(AstFactory.newAUnknownType(type.getLocation())); type.apply(af.getTypeUnresolver()); throw problem;
@SuppressWarnings("unchecked") public AFunctionType getPreType(AFunctionType t) { AFunctionType type = AstFactory.newAFunctionType(t.getLocation(), false, (List<PType>) t.getParameters().clone(), AstFactory.newABooleanBasicType(t.getLocation())); type.setDefinitions((List<PDefinition>) t.getDefinitions().clone()); type.setInstantiated(null); return type; }
/** * Creates a new tree field only constructor {@code AFunctionType TAG=function} 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 partial_ the {@link Boolean} node for the {@code partial} child of this {@link AFunctionType} node * @param instantiated_ the {@link Boolean} node for the {@code instantiated} child of this {@link AFunctionType} node */ public AFunctionType(ILexLocation location_, Boolean resolved_, Boolean partial_, Boolean instantiated_) { super(location_,resolved_,null); this.setPartial(partial_); this.setInstantiated(instantiated_); }
public static AFunctionType newAFunctionType(ILexLocation location, boolean partial, List<PType> parameters, PType resultType) { AFunctionType result = new AFunctionType(); initType(result, location); result.setParameters(parameters); result.setResult(resultType); result.setPartial(partial); result.setInstantiated(null); return result; }
List<PDefinition> copy = new ArrayList<PDefinition>(node.getDefinitions()); for( PDefinition e : copy) List<PType> copy = new ArrayList<PType>(node.getParameters()); for( PType e : copy) if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) node.getResult().apply(this, question);
public CompFunctionValue(FunctionValue f1, FunctionValue f2) { super(f1.location, AstFactory.newAFunctionType(f1.location, f1.type.getPartial() || f2.type.getPartial(), f2.type.getParameters(), f1.type.getResult()), "comp"); this.ff1 = f1; this.ff2 = f2; }
@Override public PType caseAFunctionType(AFunctionType type, Context ctxt) throws AnalysisException { type = AstFactory.newAFunctionType(type.getLocation(), type.getPartial(), instantiate(type.getParameters(), ctxt), type.getResult().apply(this, ctxt)); type.setInstantiated(true); return type; }
@Override public LexNameSet caseAFunctionType(AFunctionType node, FreeVarInfo info) throws AnalysisException { LexNameSet names = new LexNameSet(); for (PType p: node.getParameters()) { names.addAll(p.apply(this, info)); } return names; }
@Override public void caseAFunctionType(AFunctionType type) throws AnalysisException { if (!type.getResolved()) { return; } else { type.setResolved(false); } for (PType ft : type.getParameters()) { ft.apply(THIS); } type.getResult().apply(THIS); }
if (type.equals(to) || assistant.isUnknown(to)) if (type.equals(restrictedType)) ff1.type.getPartial(), ff1.type.getParameters(), restrictedType.getResult()); ff2.type.getPartial(), restrictedType.getParameters(), ff2.type.getResult());
ftype.apply(THIS, question); node.getField().setTypeQualifier(ftype.getParameters()); checkArgTypes(type, ftype.getParameters(), atypes, question); // Not node.setType(ftype.getResult()); return question.assistantFactory.createPTypeAssistant().checkReturnType(question.returnType, node.getType(), node.getLocation()); } else
VdmRuntimeError.abort(type.getLocation(), 4052, "Wrong number of arguments passed to " + name, ctxt); Iterator<PType> typeIter = type.getParameters().iterator(); NameValuePairMap args = new NameValuePairMap(); rv = body.apply(VdmRuntime.getExpressionEvaluator(), evalContext).convertTo(type.getResult(), evalContext); if (type.getResult() instanceof AFunctionType) FunctionValue rv = new FunctionValue(location, "curried", (AFunctionType) type.getResult(), paramPatternList.subList(1, paramPatternList.size()), body, newpre, newpost, evalContext, false, argList, measureName, measureValues, result); VdmRuntimeError.abort(type.getLocation(), 4057, "Curried function return type is not a function", ctxt); return null;
if (type.equals(to) || assistant.isUnknown(to)) if (type.equals(restrictedType)) List<PType> domain = tc.narrowest(type.getParameters(), restrictedType.getParameters()); PType range = tc.narrowest(type.getResult(), restrictedType.getResult()); AFunctionType newType = AstFactory.newAFunctionType(location, true, domain, range);
public PType functionApply(AApplyExp node, boolean isSimple, AFunctionType ft, TypeCheckInfo question) List<PType> ptypes = ft.getParameters(); return ft.getResult(); } else if (node.getArgs().size() < ptypes.size()) return ft.getResult(); if (fat.getInstantiated() != null && !fat.getInstantiated()) return ft.getResult();
private FunctionValue curry(Context newFreeVariables) { // Remove first set of parameters, and set the free variables instead. // And adjust the return type to be the result type (a function). return new FunctionValue(location, name, (AFunctionType) type.getResult(), paramPatternList.subList(1, paramPatternList.size()), body, precondition, postcondition, newFreeVariables, false, null, null, null, result); }
&& ((AFunctionType) node.getType()).getResult() instanceof AFunctionType) if (ft.getInstantiated() != null && !ft.getInstantiated())
public static AExplicitFunctionDefinition newAExplicitFunctionDefinition( ILexNameToken name, NameScope scope, List<ILexNameToken> typeParams, AFunctionType type, List<List<PPattern>> parameters, PExp body, PExp precondition, PExp postcondition, boolean typeInvariant, PExp measure) { AExplicitFunctionDefinition result = new AExplicitFunctionDefinition(); // Definition initialization initDefinition(result, Pass.DEFS, name.getLocation(), name, scope); // AExplicitFunctionDefinition initialization result.setTypeParams(typeParams); result.setType(type); result.setParamPatternList(parameters); result.setPrecondition(precondition); result.setPostcondition(postcondition); result.setBody(body); result.setIsTypeInvariant(typeInvariant); result.setMeasure(measure); result.setIsCurried(parameters.size() > 1); result.setRecursive(false); result.setIsUndefined(false); result.setMeasureName(null); List<PDefinition> defsList = new LinkedList<PDefinition>(); defsList.add(result); type.getDefinitions().add(result); type.setInstantiated(typeParams == null || typeParams.isEmpty() ? null : false); return result; }
private PExp generateBody(AExplicitFunctionDefinition postdef, List<PExp> params, PExp body) { // post(params, body) AApplyExp applyExp = new AApplyExp(); applyExp.setType(new ABooleanBasicType()); AVariableExp varExp = getVarExp(postdef.getName()); varExp.setType(postdef.getType().clone()); applyExp.setRoot(varExp); List<PExp> args = params; args.add(body.clone()); applyExp.setArgs(args); return applyExp; }