@Override public AProductType caseAProductType(AProductType type, Integer size) throws AnalysisException { return size == 0 || type.getTypes().size() == size ? type : null; }
@Override public Boolean caseAProductType(AProductType type, Integer size) throws AnalysisException { return size == 0 || type.getTypes().size() == size; }
private List<PType> productExpand(PType parameters) { List<PType> types = new Vector<PType>(); if (parameters instanceof AProductType) { // Expand unbracketed product types AProductType pt = (AProductType) parameters; types.addAll(pt.getTypes()); } else if (parameters instanceof AVoidType) { // No type } else { // One parameter, including bracketed product types types.add(parameters); } return types; } }
@Override public Boolean caseAProductType(AProductType type, AAccessSpecifierAccessSpecifier accessSpecifier) throws AnalysisException { for (PType t : type.getTypes()) { if (t.apply(this, accessSpecifier)) { return true; } } return false; }
@Override public String caseAProductType(AProductType type) throws AnalysisException { return Utils.listToString("(", type.getTypes(), " * ", ")"); }
@Override public ValueList caseAProductType(AProductType type, Context ctxt) throws AnalysisException { return getAllValues(type.getTypes(), ctxt); }
@Override public String caseAProductType(AProductType node, PrettyPrinterEnv question) throws AnalysisException { List<String> types = new Vector<String>(); for (PType t : node.getTypes()) { types.add(t.apply(this, question)); } return "" + "" + Utils.listToString("(", types, " * ", ")"); }
@Override public Boolean caseAProductType(AProductType type, Object other) throws AnalysisException { other = deBracket((PType) other); if (other instanceof AProductType) { AProductType pother = (AProductType) other; return af.createPTypeAssistant().equals(type.getTypes(), pother.getTypes()); // FIXME: apply method is not applicable here. } return false; }
@Override public Integer caseAProductType(AProductType type) throws AnalysisException { return af.createPTypeAssistant().hashCode(type.getTypes()); }
@Override public PType caseAProductType(AProductType type, Newquestion question) throws AnalysisException { List<PType> polytypes = new Vector<PType>(); for (PType ptype : ((AProductType) type).getTypes()) { polytypes.add(af.createPTypeAssistant().polymorph(ptype, question.pname, question.actualType)); } return AstFactory.newAProductType(type.getLocation(), polytypes); }
private int getLex(AExplicitFunctionDefinition mdef) { AFunctionType ftype = (AFunctionType) mdef.getType(); if (ftype.getResult() instanceof AProductType) { AProductType type = (AProductType)ftype.getResult(); return type.getTypes().size(); } else { return 0; } } }
@Override public LexNameSet caseAProductType(AProductType node, FreeVarInfo info) throws AnalysisException { LexNameSet names = new LexNameSet(); for (PType p: node.getTypes()) { names.addAll(p.apply(this, info)); } return names; }
@Override public PType caseAProductType(AProductType type, Context ctxt) throws AnalysisException { return AstFactory.newAProductType(type.getLocation(), instantiate(type.getTypes(), ctxt)); }
@Override public PTypeList caseAProductType(AProductType node) throws AnalysisException { PTypeList list = new PTypeList(); for (PType ptype : node.getTypes()) { list.addAll(ptype.apply(THIS)); } return list; }
/** * Called by the {@link AProductType} node from {@link AProductType#apply(IPOFAnalysis)}. * @param node the calling {@link AProductType} node */ public void caseAProductType(AProductType node) throws AnalysisException { _visitedNodes.add(node); inAProductType(node); { List<PDefinition> copy = new ArrayList<PDefinition>(node.getDefinitions()); for( PDefinition e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } { List<PType> copy = new ArrayList<PType>(node.getTypes()); for( PType e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } outAProductType(node); }
@Override public void caseAProductType(AProductType type) throws AnalysisException { if (!type.getResolved()) { return; } else { type.setResolved(false); } for (PType t : type.getTypes()) { t.apply(THIS); } }
@Override public STypeIR caseAProductType(AProductType node, IRInfo question) throws AnalysisException { ATupleTypeIR tuple = new ATupleTypeIR(); LinkedList<PType> types = node.getTypes(); for (PType type : types) { STypeIR typeCg = type.apply(question.getTypeVisitor(), question); if (typeCg != null) { tuple.getTypes().add(typeCg); } else { return null; } } return tuple; }
@Override protected Value convertValueTo(PType to, Context ctxt, Set<PType> done) throws AnalysisException { if (to instanceof AProductType) { AProductType pto = (AProductType) to; if (pto.getTypes().size() != values.size()) { abort(4085, "Cannot convert tuple to " + to, ctxt); } ValueList nl = new ValueList(); Iterator<Value> vi = values.iterator(); for (PType pt : pto.getTypes()) { nl.add(vi.next().convertValueTo(pt, ctxt)); } return new TupleValue(nl); } else { return super.convertValueTo(to, ctxt, done); } }
@Override public List<PDefinition> caseATuplePattern(ATuplePattern pattern, NewQuestion question) throws AnalysisException { List<PDefinition> defs = new Vector<PDefinition>(); if (!af.createPTypeAssistant().isProduct(question.ptype, pattern.getPlist().size())) { TypeCheckerErrors.report(3205, "Matching expression is not a product of cardinality " + pattern.getPlist().size(), pattern.getLocation(), pattern); TypeCheckerErrors.detail("Actual", question.ptype); return defs; } AProductType product = af.createPTypeAssistant().getProduct(question.ptype, pattern.getPlist().size()); Iterator<PType> ti = product.getTypes().iterator(); for (PPattern p : pattern.getPlist()) { defs.addAll(af.createPPatternAssistant().getDefinitions(p, ti.next(), question.scope)); } return defs; }
@Override public PType caseAFieldNumberExp(AFieldNumberExp node, TypeCheckInfo question) throws AnalysisException { PExp tuple = node.getTuple(); question.qualifiers = null; PType type = tuple.apply(THIS, question.newConstraint(null)); node.setType(type); if (!question.assistantFactory.createPTypeAssistant().isProduct(type)) { TypeCheckerErrors.report(3094, "Field '#" + node.getField() + "' applied to non-tuple type", tuple.getLocation(), tuple); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } AProductType product = question.assistantFactory.createPTypeAssistant().getProduct(type); long fn = node.getField().getValue(); if (fn > product.getTypes().size() || fn < 1) { TypeCheckerErrors.report(3095, "Field number does not match tuple size", node.getField().getLocation(), node.getField()); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } node.setType(product.getTypes().get((int) fn - 1)); return node.getType(); }