@Override public String toString() { return ff2.type.getParameters() + " -> " + ff1.type.getResult(); }
private List<PType> calculateTypes(AFunctionType ftype, boolean curried) { List<PType> r = new LinkedList<PType>(); for (PType t : ftype.getParameters()) { r.add(t.clone()); } if (curried) { r.addAll(handleCurries(ftype.getResult())); } return r; }
private Collection<? extends PType> handleCurries(PType result) { List<PType> r = new LinkedList<PType>(); if (result instanceof AFunctionType) { AFunctionType ft = (AFunctionType) result; for (PType p : ft.getParameters()) { r.add(p.clone()); } r.addAll(handleCurries(ft.getResult())); } return r; }
@Override public String caseAFunctionType(AFunctionType type) throws AnalysisException { List<PType> parameters = type.getParameters(); String params = parameters.isEmpty() ? "()" : Utils.listToString(parameters, " * "); return "(" + params + (type.getPartial() ? " -> " : " +> ") + type.getResult() + ")"; }
@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 STypeIR caseAFunctionType(AFunctionType node, IRInfo question) throws AnalysisException { return question.getTypeAssistant().consMethodType(node, node.getParameters(), node.getResult(), question); }
@Override public Boolean caseAFunctionType(AFunctionType type, AAccessSpecifierAccessSpecifier accessSpecifier) throws AnalysisException { for (PType t : type.getParameters()) { if (t.apply(this, accessSpecifier)) // (PTypeAssistantTC.narrowerThan(t, accessSpecifier)) { return true; } } return type.getResult().apply(this, accessSpecifier); // PTypeAssistantTC.narrowerThan(type.getResult(),accessSpecifier); }
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 Boolean caseAFunctionType(AFunctionType type, Object other) throws AnalysisException { other = deBracket((PType) other); if (!(other instanceof AFunctionType)) { return false; } AFunctionType fo = (AFunctionType) other; return type.getPartial() == fo.getPartial() && type.getResult().apply(this, fo.getResult()) && af.createPTypeAssistant().equals(type.getParameters(), fo.getParameters()); }
@Override public Integer caseAFunctionType(AFunctionType type) throws AnalysisException { return af.createPTypeAssistant().hashCode(type.getParameters()) + af.createPTypeAssistant().hashCode(type.getResult()); }
@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); }
@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; }
@Override public PTypeList caseAFunctionType(AFunctionType node) throws AnalysisException { PTypeList list = new PTypeList(); for (PType ptype : node.getParameters()) { list.addAll(ptype.apply(THIS)); } list.addAll(node.getResult().apply(THIS)); return list; }
@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; }
@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; }
public ParameterPatternObligation(AExplicitFunctionDefinition def, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(def, POType.FUNC_PATTERNS, ctxt, def.getLocation(), af); this.assistantFactory = af; // valuetree.setContext(ctxt.getContextNodeList()); // cannot clone getPredef as it can be null. We protect the ast in // the generate method where it's used stitch = generate(def.getPredef(), cloneListPatternList(def.getParamPatternList()), cloneListType(((AFunctionType) def.getType()).getParameters()), ((AFunctionType) def.getType()).getResult().clone()); valuetree.setPredicate(ctxt.getPredWithContext(stitch)); }
@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); } }
public ParameterPatternObligation(AImplicitFunctionDefinition def, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(def, POType.FUNC_PATTERNS, ctxt, def.getLocation(), af); this.assistantFactory = af; stitch = generate(def.getPredef(), cloneListPatternList(assistantFactory.createAImplicitFunctionDefinitionAssistant().getParamPatternList(def)), cloneListType(((AFunctionType) def.getType()).getParameters()), ((AFunctionType) def.getType()).getResult().clone()); valuetree.setPredicate(ctxt.getPredWithContext(stitch)); }
@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); } }