@Override public Boolean defaultSMapType(SMapType type, Object other) throws AnalysisException { // return SMapTypeAssistantTC.equals(type, other); other = af.createPTypeAssistant().deBracket(other); if (other.getClass() == type.getClass()) // inmaps too { SMapType mt = (SMapType) other; // return PTypeAssistantTC.equals(type.getFrom(),mt.getFrom()) && PTypeAssistantTC.equals(type.getTo(), // mt.getTo()); return type.getFrom().apply(this, mt.getFrom()) && type.getTo().apply(this, mt.getTo()); } return false; }
@Override public Integer defaultSMapType(SMapType type) throws AnalysisException { SMapType mtype = type; return mtype.getFrom().apply(THIS) + mtype.getTo().apply(THIS); }
public Collection<? extends PDefinition> getDefinitions( AMapletPatternMaplet p, SMapType map, NameScope scope) { List<PDefinition> list = new Vector<PDefinition>(); list.addAll(af.createPPatternAssistant().getDefinitions(p.getFrom(), map.getFrom(), scope)); list.addAll(af.createPPatternAssistant().getDefinitions(p.getTo(), map.getTo(), scope)); return list; } }
@Override public PType defaultSMapType(SMapType type, Context ctxt) throws AnalysisException { return AstFactory.newAMapMapType(type.getLocation(), type.getFrom().apply(this, ctxt), type.getTo().apply(this, ctxt)); }
public PType mapApply(AApplyObjectDesignator node, SMapType map, Environment env, NameScope scope, boolean unique, IQuestionAnswer<TypeCheckInfo, PType> rootVisitor) throws AnalysisException { if (node.getArgs().size() != 1) { TypeCheckerErrors.concern(unique, 3250, "Map application must have one argument", node.getLocation(), node); return AstFactory.newAUnknownType(node.getLocation()); } PType argtype = node.getArgs().get(0).apply(rootVisitor, new TypeCheckInfo(env.af, env, scope)); if (!env.af.getTypeComparator().compatible(map.getFrom(), argtype)) { TypeCheckerErrors.concern(unique, 3251, "Map application argument is incompatible type", node.getLocation(), node); TypeCheckerErrors.detail2(unique, "Map domain", map.getFrom(), "Argument", argtype); } return map.getTo(); }
public PType mapApply(AApplyExp node, boolean isSimple, SMapType map, TypeCheckInfo question) { if (map.getEmpty()) { TypeCheckerErrors.concern(isSimple, 3267, "Empty map cannot be applied", node.getLocation(), node); } if (node.getArgs().size() != 1) { TypeCheckerErrors.concern(isSimple, 3057, "Map application must have one argument", node.getLocation(), node); } else { PType argtype = node.getArgtypes().get(0); if (!question.assistantFactory.getTypeComparator().compatible(map.getFrom(), argtype)) { TypeCheckerErrors.concern(isSimple, 3058, "Map application argument is incompatible type", node.getLocation(), node); TypeCheckerErrors.detail2(isSimple, "Map domain", map.getFrom(), "Argument", argtype); } } return map.getTo(); }
@Override public PType defaultSMapType(SMapType type, Newquestion question) throws AnalysisException { return AstFactory.newAMapMapType(type.getLocation(), af.createPTypeAssistant().polymorph(type.getFrom(), question.pname, question.actualType), af.createPTypeAssistant().polymorph(type.getTo(), question.pname, question.actualType)); }
@Override public void defaultSMapType(SMapType type) throws AnalysisException { if (!type.getResolved()) { return; } else { type.setResolved(false); } if (!type.getEmpty()) { type.getFrom().apply(THIS); type.getTo().apply(THIS); } }
@Override public PType caseAMapEnumMapExp(AMapEnumMapExp node, TypeCheckInfo question) throws AnalysisException { node.setDomTypes(new Vector<PType>()); node.setRngTypes(new Vector<PType>()); if (node.getMembers().isEmpty()) { node.setType(AstFactory.newAMapMapType(node.getLocation())); return node.getType(); } PTypeSet dom = new PTypeSet(question.assistantFactory); PTypeSet rng = new PTypeSet(question.assistantFactory); for (AMapletExp ex : node.getMembers()) { PType mt = ex.apply(THIS, question); if (!question.assistantFactory.createPTypeAssistant().isMap(mt)) { TypeCheckerErrors.report(3121, "Element is not of maplet type", node.getLocation(), node); } else { SMapType maplet = question.assistantFactory.createPTypeAssistant().getMap(mt); dom.add(maplet.getFrom()); node.getDomTypes().add(maplet.getFrom()); rng.add(maplet.getTo()); node.getRngTypes().add(maplet.getTo()); } } node.setType(AstFactory.newAMapMapType(node.getLocation(), dom.getType(node.getLocation()), rng.getType(node.getLocation()))); return question.assistantFactory.createPTypeAssistant().possibleConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType defaultSMapType(SMapType type, Newquestion question) throws AnalysisException { if (type.getResolved()) { return type; } else { type.setResolved(true); } try { if (!type.getEmpty()) { type.setFrom(af.createPTypeAssistant().typeResolve(type.getFrom(), question.root, question.rootVisitor, question.question)); type.setTo(af.createPTypeAssistant().typeResolve(type.getTo(), question.root, question.rootVisitor, question.question)); } return type; } catch (TypeCheckException e) { type.apply(af.getTypeUnresolver()); throw e; } }
@Override public PType caseAMapDomainUnaryExp(AMapDomainUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType etype = exp.apply(THIS, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isMap(etype)) { TypeCheckerErrors.report(3120, "Argument to 'dom' is not a map", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } SMapType mt = question.assistantFactory.createPTypeAssistant().getMap(etype); node.setType(AstFactory.newASetSetType(node.getLocation(), mt.getFrom())); return node.getType(); }
&& question.assistantFactory.createPTypeAssistant().isMap(question.constraint)) PType stype = question.assistantFactory.createPTypeAssistant().getMap(question.constraint).getFrom(); domConstraint = question.newConstraint(AstFactory.newASetSetType(node.getLocation(), stype)); SMapType map = question.assistantFactory.createPTypeAssistant().getMap(node.getRight().getType()); if (!question.assistantFactory.getTypeComparator().compatible(set.getSetof(), map.getFrom())) + map.getFrom(), node.getLocation(), node);
/** * is_(exp, inmap expFromType to expToType) * * @param exp * @param ctxt * @param af * @throws AnalysisException */ public MapInverseObligation(AMapInverseUnaryExp exp, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(exp, POType.MAP_INVERSE, ctxt, exp.getLocation(), af); AIsExp is_Exp = new AIsExp(); is_Exp.setTest(exp.getExp().clone()); AInMapMapType inMap_type = new AInMapMapType(); inMap_type.setFrom(exp.getMapType().getFrom().clone()); inMap_type.setTo(exp.getMapType().getTo().clone()); is_Exp.setBasicType(inMap_type); stitch = is_Exp; valuetree.setPredicate(ctxt.getPredWithContext(is_Exp)); }
@Override public ValueList defaultSMapType(SMapType type, Context ctxt) throws AnalysisException { PTypeList tuple = new PTypeList(); tuple.add(type.getFrom()); tuple.add(type.getTo()); ValueList results = new ValueList(); ValueList tuples = getAllValues(tuple, ctxt); ValueSet set = new ValueSet(); set.addAll(tuples); List<ValueSet> psets = set.powerSet(); for (ValueSet map : psets) { ValueMap result = new ValueMap(); for (Value v : map) { TupleValue tv = (TupleValue) v; result.put(tv.values.get(0), tv.values.get(1)); } results.add(new MapValue(result)); } return results; }
@Override public PType caseAMapletExp(AMapletExp node, TypeCheckInfo question) throws AnalysisException { TypeCheckInfo domConstraint = question; TypeCheckInfo rngConstraint = question; if (question.constraint != null && question.assistantFactory.createPTypeAssistant().isMap(question.constraint)) { PType dtype = question.assistantFactory.createPTypeAssistant().getMap(question.constraint).getFrom(); domConstraint = question.newConstraint(dtype); PType rtype = question.assistantFactory.createPTypeAssistant().getMap(question.constraint).getTo(); rngConstraint = question.newConstraint(rtype); } PType ltype = node.getLeft().apply(THIS, domConstraint); PType rtype = node.getRight().apply(THIS, rngConstraint); node.setType(AstFactory.newAMapMapType(node.getLocation(), ltype, rtype)); return node.getType(); }
@Override protected Value convertValueTo(PType to, Context ctxt, Set<PType> done) throws AnalysisException { if (to instanceof SMapType) { if (to instanceof AInMapMapType && !values.isInjective()) { abort(4062, "Cannot convert non-injective map to an inmap", ctxt); } SMapType mapto = ctxt.assistantFactory.createPTypeAssistant().getMap(to); ValueMap nm = new ValueMap(); for (Value k : values.keySet()) { Value v = values.get(k); Value dom = k.convertValueTo(mapto.getFrom(), ctxt); Value rng = v.convertValueTo(mapto.getTo(), ctxt); Value old = nm.put(dom, rng); if (old != null && !old.equals(rng)) { abort(4063, "Duplicate map keys have different values: " + dom, ctxt); } } return new MapValue(nm); } else { return super.convertValueTo(to, ctxt, done); } }
&& question.assistantFactory.createPTypeAssistant().isMap(question.constraint)) PType stype = question.assistantFactory.createPTypeAssistant().getMap(question.constraint).getFrom(); domConstraint = question.newConstraint(AstFactory.newASetSetType(node.getLocation(), stype)); SMapType map = question.assistantFactory.createPTypeAssistant().getMap(node.getRight().getType()); if (!question.assistantFactory.getTypeComparator().compatible(set.getSetof(), map.getFrom())) + map.getFrom(), node.getLocation(), node);
@Override public PType caseAMapInverseUnaryExp(AMapInverseUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType etype = exp.apply(THIS, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isMap(etype)) { TypeCheckerErrors.report(3111, "Argument to 'inverse' is not a map", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } node.setMapType(question.assistantFactory.createPTypeAssistant().getMap(etype)); AMapMapType mm = AstFactory.newAMapMapType(node.getLocation(), node.getMapType().getTo(), node.getMapType().getFrom()); node.setType(mm); return node.getType(); }
@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(); }