/** * 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 AFunctionType getType(AExplicitFunctionDefinition efd, List<PType> actualTypes) { Iterator<PType> ti = actualTypes.iterator(); AFunctionType ftype = (AFunctionType) efd.getType(); if (efd.getTypeParams() != null) { for (ILexNameToken pname : efd.getTypeParams()) { PType ptype = ti.next(); ftype = (AFunctionType) af.createPTypeAssistant().polymorph(ftype, pname, ptype); } ftype.setInstantiated(true); } return ftype; }
public AFunctionType getType(AImplicitFunctionDefinition impdef, List<PType> actualTypes) { Iterator<PType> ti = actualTypes.iterator(); AFunctionType ftype = (AFunctionType) impdef.getType(); if (impdef.getTypeParams() != null) { for (ILexNameToken pname : impdef.getTypeParams()) { PType ptype = ti.next(); // AFunctionTypeAssistent. ftype = (AFunctionType) af.createPTypeAssistant().polymorph(ftype, pname, ptype); } ftype.setInstantiated(true); } return ftype; }
/** * Creates a new complete constructor {@code AFunctionType} 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 parameters_ the {@link GraphNodeList} <b>graph</a> node for the {@code parameters} child of this {@link AFunctionType} node. * <i>The parent of this {@code parameters } will not be changed by adding it to this node.</i> * @param result_ the {@link PType} <b>graph</a> node for the {@code result} child of this {@link AFunctionType} node. * <i>The parent of this {@code result } will not be changed by adding it to this node.</i> * @param instantiated_ the {@link Boolean} node for the {@code instantiated} child of this {@link AFunctionType} node */ public AFunctionType(ILexLocation location_, Boolean resolved_, List<? extends PDefinition> definitions_, Boolean partial_, List<? extends PType> parameters_, PType result_, Boolean instantiated_) { super(location_,resolved_,definitions_); this.setPartial(partial_); this.setParameters(parameters_); this.setResult(result_); 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; }
@Override public PType caseAFunctionType(AFunctionType type, Newquestion question) throws AnalysisException { // return AFunctionTypeAssistantTC.polymorph(type, question.pname, question.actualType); List<PType> polyparams = new Vector<PType>(); for (PType ptype : type.getParameters()) { polyparams.add(af.createPTypeAssistant().polymorph(ptype, question.pname, question.actualType)); } // PType polyresult = PTypeAssistantTC.polymorph(type.getResult(), question.pname, question.actualType); PType polyresult = type.getResult().apply(this, question); AFunctionType ftype = AstFactory.newAFunctionType(type.getLocation(), false, polyparams, polyresult); ftype.setDefinitions(type.getDefinitions()); ftype.setInstantiated(true); return ftype; }
@SuppressWarnings("unchecked") public AFunctionType getPostType(AFunctionType t) { List<PType> params = new PTypeList(); params.addAll((List<PType>) t.getParameters().clone()); params.add(t.getResult().clone()); AFunctionType type = AstFactory.newAFunctionType(t.getLocation(), false, params, AstFactory.newABooleanBasicType(t.getLocation())); type.setDefinitions((List<? extends PDefinition>) t.getDefinitions().clone()); type.setInstantiated(null); return type; }
@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; }
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; }
@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; }
type.setInstantiated(typeParams == null || typeParams.isEmpty() ? null : false);
@SuppressWarnings("unchecked") public AFunctionType getCurriedPostType(AFunctionType type, Boolean isCurried) { if (isCurried && type.getResult() instanceof AFunctionType) { AFunctionType ft = (AFunctionType) type.getResult().clone(); AFunctionType t = AstFactory.newAFunctionType(type.getLocation(), false, ((List<PType>) type.getParameters().clone()), getCurriedPostType(ft, isCurried)); t.setDefinitions(type.getDefinitions()); t.setInstantiated(null); return t; } else { return getPostType(type); } }
@SuppressWarnings("unchecked") public AFunctionType getCurriedPreType(AFunctionType t, Boolean isCurried) { if (isCurried && t.getResult() instanceof AFunctionType) { AFunctionType ft = (AFunctionType) t.getResult().clone(); AFunctionType type = AstFactory.newAFunctionType(t.getLocation(), false, (List<PType>) t.getParameters().clone(), getCurriedPreType(ft, isCurried)); type.setDefinitions((List<PDefinition>) t.getDefinitions().clone()); type.setInstantiated(null); return type; } else { return getPreType(t); } }