public PType getPossibleType(LinkedList<PPattern> plist, ILexLocation location) { switch (plist.size()) { case 0: return AstFactory.newAUnknownType(location); case 1: return af.createPPatternAssistant().getPossibleType(plist.get(0)); default: PTypeSet list = new PTypeSet(af); for (PPattern p : plist) { list.add(af.createPPatternAssistant().getPossibleType(p)); } return list.getType(location); // NB. a union of types } }
@Override public Boolean caseAUnionType(AUnionType type, Object other) throws AnalysisException { other = deBracket((PType) other); PTypeSet types = new PTypeSet(type.getTypes(), af); if (other instanceof AUnionType) { AUnionType uother = (AUnionType) other; for (PType t : uother.getTypes()) { if (!types.contains(t)) { return false; } } return true; } return types.contains(other); }
@Override public SMapType caseAUnionType(AUnionType type) throws AnalysisException { ILexLocation location = type.getLocation(); if (!type.getMapDone()) { type.setMapDone(true); // Mark early to avoid recursion. // type.setMapType(PTypeAssistantTC.getMap(AstFactory.newAUnknownType(location))); // Rewritten in an none static form. type.setMapType(af.createPTypeAssistant().getMap(AstFactory.newAUnknownType(location))); PTypeSet from = new PTypeSet(af); PTypeSet to = new PTypeSet(af); for (PType t : type.getTypes()) { if (af.createPTypeAssistant().isMap(t)) { // from.add(PTypeAssistantTC.getMap(t).getFrom()); //Original Code from.add(t.apply(THIS).getFrom()); // My change George. // to.add(PTypeAssistantTC.getMap(t).getTo());//Original code. to.add(t.apply(THIS).getTo());// My change George. } } type.setMapType(from.isEmpty() ? null : AstFactory.newAMapMapType(location, from.getType(location), to.getType(location))); } return type.getMapType(); }
public PType getType(IRInfo question, AUnionType unionType, PPattern pattern) PTypeSet possibleTypes = new PTypeSet(question.getTcFactory()); PType patternType = question.getTcFactory().createPPatternAssistant().getPossibleType(pattern); TypeComparator comp = question.getTcFactory().getTypeComparator(); possibleTypes.add(t); if (possibleTypes.isEmpty()) } else if (possibleTypes.size() == 1) return possibleTypes.pollFirst(); } else
@Override public PTypeSet defaultPStm(PStm statement) throws AnalysisException { return new PTypeSet(af); }
@Override public PType caseATixeStm(ATixeStm node, TypeCheckInfo question) throws AnalysisException { PType rt = node.getBody().apply(THIS, question); PTypeSet extypes = exitCheck(node.getBody(), question); if (!extypes.isEmpty()) { PType union = extypes.getType(node.getLocation()); for (ATixeStmtAlternative tsa : node.getTraps()) { tsa.setExp(union); tsa.apply(THIS, question); } } node.setType(rt); return rt; }
if (contains(st)) ASeq1SeqType s1t = AstFactory.newASeq1SeqType(st.getLocation(), st.getSeqof()); if (contains(s1t)) remove(s1t); // Replace seq with seq1 ASetSetType st = AstFactory.newASetSetType(s1t.getLocation(), s1t.getSetof()); if (contains(st)) ASet1SetType s1t = AstFactory.newASet1SetType(st.getLocation(), st.getSetof()); if (contains(s1t)) remove(s1t); // Replace set1 with set remove(x); break; } else if (!(opt.getType() instanceof AUnknownType) && contains(opt.getType())) remove(opt.getType()); // Because T | [T] = [T]
public PTypeSet(List<PType> types, IAstAssistantFactory af) { super(new PTypeComparator()); assistantFactory = af; addAll(types); }
@Override public SSetType caseAUnionType(AUnionType type) throws AnalysisException { ILexLocation location = type.getLocation(); if (!type.getSetDone()) { type.setSetDone(true); // Mark early to avoid recursion. // type.setSetType(PTypeAssistantTC.getSet(AstFactory.newAUnknownType(location))); type.setSetType(af.createPTypeAssistant().getSet(AstFactory.newAUnknownType(location))); PTypeSet set = new PTypeSet(af); for (PType t : type.getTypes()) { if (af.createPTypeAssistant().isSet(t)) { // set.add(PTypeAssistantTC.getSet(t).getSetof()); set.add(t.apply(THIS).getSetof()); } } type.setSetType(set.isEmpty() ? null : AstFactory.newASetSetType(location, set.getType(location))); } return type.getSetType(); }
@Override public PType caseAUnionType(AUnionType type, Newquestion question) throws AnalysisException { // return AUnionTypeAssistantTC.polymorph(type, question.pname, question.actualType); PTypeSet polytypes = new PTypeSet(af); for (PType ptype : ((AUnionType) type).getTypes()) { polytypes.add(af.createPTypeAssistant().polymorph(ptype, question.pname, question.actualType)); } // TODO: Types in unionType should be a SET PTypeList result = new PTypeList(); result.addAll(polytypes); return AstFactory.newAUnionType(type.getLocation(), result); }